How to Add a New Variable

From KratosWiki
Jump to: navigation, search

If you need to add a new variable NEW_VARIABLE to Kratos which does not exist 4 steps are needed:


1. Define the variable in .../kratos/includes/variables.h (if you want to share the variable with different applications) or in .../applications/your_application/your_application.h (if the variable will be used by your application only)

KRATOS_DEFINE_VARIABLE(double, NEW_VARIABLE)

or for a vectorial variable:

KRATOS_DEFINE_3D_VARIABLE_WITH_COMPONENTS(NEW_VARIABLE)


2. Create & Register in .../kratos/sources/variables.cpp (if you want to share the variable with different applications) or in .../applications/your_application/your_application.cpp (if the variable will be used by your application only)

KRATOS_CREATE_VARIABLE(double, NEW_VARIABLE)
KRATOS_REGISTER_VARIABLE( NEW_VARIABLE)

or for a vectorial variable:

KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(NEW_VARIABLE)
KRATOS_REGISTER_3D_VARIABLE_WITH_COMPONENTS(NEW_VARIABLE)


3. Now, it is also necessary to make python aware of its existence by inserting in .../kratos/kratos/python/add_containers_to_python.cpp (if you want to share the variable with different applications) or in .../applications/your_application/custom_python/your_application_python_application.cpp (if the variable will be used by your application only):

KRATOS_REGISTER_IN_PYTHON_VARIABLE( NEW_VARIABLE)

or for a vectorial variable:

KRATOS_REGISTER_IN_PYTHON_3D_VARIABLE_WITH_COMPONENTS( NEW_VARIABLE)


4. In your python script, remember to allocate memory for your new variable:

   AddVariables(model_part)
   model_part.AddNodalSolutionStepVariable( NEW_VARIABLE)

Steps 3 and 4 are not necessary if you are going to use this variable by the order 'GetValue'.

Personal tools
Categories