Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particle generation breaks restart feature #145

Open
FabienPean-Virtonomy opened this issue Aug 24, 2022 · 1 comment
Open

Particle generation breaks restart feature #145

FabienPean-Virtonomy opened this issue Aug 24, 2022 · 1 comment
Assignees

Comments

@FabienPean-Virtonomy
Copy link
Collaborator

FabienPean-Virtonomy commented Aug 24, 2022

template <class ParticleGeneratorType, typename... ConstructorArgs>
void generateParticles(ConstructorArgs &&...args)
{
ParticleGeneratorType particle_generator(*this, std::forward<ConstructorArgs>(args)...);
particle_generator.initializeGeometricVariables();
base_particles_->initializeOtherVariables();
base_material_->assignBaseParticles(base_particles_);
};

Restart is inherently broken with new particle generation approach. For any particle generator, initializeOtherVariables happens after the function implemented by the user, the initialization of extra variable based on a function such as

registerVariable(n0_, "InitialNormalDirection",
[&](size_t i) -> Vecd
{ return n_[i]; });

is (1) crashing if the variable was registered by the user inadvertently (avoidable and ok, requires removing some lines), and (2) overriding any user/file loaded values (more problematic from design POV). See the sources of problems in base_particles.hpp

if (all_variable_maps_[type_index].find(variable_name) == all_variable_maps_[type_index].end())
{
variable_addrs.resize(real_particles_bound_, initial_value);
std::get<type_index>(all_particle_data_).push_back(&variable_addrs);
all_variable_maps_[type_index].insert(make_pair(variable_name, std::get<type_index>(all_particle_data_).size() - 1));
}
else
{
std::cout << "\n Error: the variable '" << variable_name << "' has already been registered!" << std::endl;
std::cout << __FILE__ << ':' << __LINE__ << std::endl;
exit(1);
}

and

template <typename VariableType, class InitializationFunction>
void BaseParticles::
registerVariable(StdLargeVec<VariableType> &variable_addrs,
const std::string &variable_name, const InitializationFunction &initialization)
{
constexpr int type_index = DataTypeIndex<VariableType>::value;
registerVariable(variable_addrs, variable_name);
for (size_t i = 0; i != real_particles_bound_; ++i)
{
variable_addrs[i] = initialization(i);
}
}

@Xiangyu-Hu
Copy link
Owner

Yes. This issue is very relevant to that a variable is only allowed once. The other Variable are only those in particle classes. Any new variable will be defined in method will be initialized in the specific method class. My original design is separate geometric model variable, physical model variables and dynamics relevant variables. The first two are defined in particles, the third in method classes. However, the clear separation between the three is not very obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants