Xiangyu-Hu / SPHinXsys

SPHinXsys provides C++ APIs for engineering simulation and optimization. It aims at complex systems driven by fluid, structure, multi-body dynamics and beyond. The multi-physics library is based on a unique and unified computational framework by which strong coupling has been achieved for all involved physics.

Home Page:https://www.sphinxsys.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduce generalized global variables in particles

Xiangyu-Hu opened this issue · comments

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.

`

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 variable = container[I];

I do not know how to obtain GlobalVariable in DataContainerUniquePtrAssemble

You can learn the usage of UniquePtrsKeeper form the binary shape class

class BinaryShapes : public Shape
.
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;
template <template <typename DataType> typename DataContainerType>

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

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.