How to Add a New Variable

From KratosWiki
(Difference between revisions)
Jump to: navigation, search
m
 
(18 intermediate revisions by 4 users not shown)
Line 1: Line 1:
If you need to add a new varaiable to Kratos which doesn`t exist 3 passes are needed
+
If you need to add a new variable NEW_VARIABLE to Kratos which does not exist 4 steps are needed:
  
1. '''define''' the varaiable
+
 
 +
'''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'.
 +
[[Category:How To]]

Latest revision as of 18:25, 22 December 2014

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