Closed Xiangyu-Hu closed 10 months ago
`
template <typename GlobalVariableType>
void BaseParticles::
registerGlobalVariable(const std::string &variable_name, GlobalVariableType initial_value)
{
constexpr int type_index = DataTypeIndex<GlobalVariableType>::value;
UniquePtrsKeeper<GlobalVariable<GlobalVariableType>>& container = std::get<type_index>(all_global_data_);
bool isRegistered = false;
//attention: ptr_keepers_ is changed here to public property temporarily!
for (size_t i = 0; i < container.ptr_keepers_.size(); ++i)
{
const GlobalVariable<GlobalVariableType> variable = container[i]; //wrong, container[i] is UniquePtrsKeeper
if (variable.getName() == variable_name)
{
isRegistered = true;
std::cout << "\n Error: the variable '" << variable_name << "' has already been registered!" << std::endl;
std::cout << __FILE__ << ':' << __LINE__ << std::endl;
exit(1);
}
}
if (!isRegistered)
{
container.template createPtr<GlobalVariable<GlobalVariableType>>(variable_name, initial_value);
}
}`
base_particles.hpp:83 const GlobalVariable
I do not know how to obtain GlobalVariable
You can learn the usage of UniquePtrsKeeper form the binary shape class https://github.com/Xiangyu-Hu/SPHinXsys/blob/f1a6c9f5e05845d4cb33627bb14b420220faa992/src/shared/geometries/base_geometry.h#L100. Basically, you need work with one keeper and another vector. This suggests that my idea of using single UniquePtrsKeeper assemble is wrong. You the the extra assemble Like this; https://github.com/Xiangyu-Hu/SPHinXsys/blob/f1a6c9f5e05845d4cb33627bb14b420220faa992/src/shared/common/base_data_package.h#L52 also we may consider how to managing discrete and global variables that they has same name, for example temperature.
We will treat discrete and gloabl variables separately now,
ok, I will try
https://github.com/ChenxiZhaoTUM/SPHinXsys-learning/blob/d434332c90cf61a93f2b4a6c58a3762110577e39/src/shared/particles/base_particles.h#L116-L117 Using UniquePtrsKeeper and AddressAssemble has been achieved.
https://github.com/ChenxiZhaoTUM/SPHinXsys-learning/blob/d434332c90cf61a93f2b4a6c58a3762110577e39/tests/user_examples/ExtraSources/extra_sources_share/particle_dynamics_diffusion_reaction_with_boundary.hpp#LL75C3-L75C71 But Tinfinity cannot be passed as an initial value in registerGlobalVariable without its address https://github.com/ChenxiZhaoTUM/SPHinXsys-learning/blob/d434332c90cf61a93f2b4a6c58a3762110577e39/src/shared/particles/base_particles.hpp#LL73C99-L73C99
There is no "Reference in new issue" in the files in my branch. Sorry for the way I labelled the code.
You have the address for the global variable, so the value of the variable.
The Robin case is tested successfully. I am running ctest on Linux.
We need a mechanism to register arbitrary number global variables with different types. Similar to discrete variables, such global variable will registered for physical models defined by particle dynamics class. Another objective is to decrease the number of control parameters in the constructor of a method class.