-
Notifications
You must be signed in to change notification settings - Fork 248
Using processes to customize a simulation
Kratos offers many ways of customizing the behavior of simulations. One way is to use Kratos::Process
, either from
- KratosCore
- Kratos-Application
- user defined
Adding a process in a simulation is straight-forward, it has to be added to the list of processes in the ProjectParameters.json
.
In the following it is shown how to add processes from different locations (KratosCore, Kratos-Application or user-defined) to a simulation in ProjectParameters.json
. Further information can be found in the description of the AnalysisStage.
"processes" : {
"from_kratos_core" : [{
"python_module" : "assign_vector_variable_process",
"kratos_module" : "KratosMultiphysics",
"Parameters" : {
# ...
}
}],
"from_kratos_application" : [{
"python_module" : "compute_body_fitted_drag_process",
"kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
"Parameters" : {
# ...
}
}],
"user_defined" : [{
"python_module" : "user_defined_process_script",
"Parameters" : {
# ...
}
}]
}
Note: In order for the user-defined process to work, it has to be available on the PYTHONPATH
of the system. This can e.g. be the current working directory.
Following is an example containing the functions a python-process can implement. This can be used as a basis for implementing a user-defined process.
In order to see where the functions are being called, one can check the AnalysisStage.
Since most applications have adapted the AnalysisStage from the KratosCore, it is very easy to use a different application, one does not have to re-learn how the things are working.
import KratosMultiphysics as KM
def Factory(settings, model):
if not isinstance(settings, KM.Parameters):
raise Exception("expected input shall be a Parameters object, encapsulating a json string")
return DummyPythonProcess(model, settings["Parameters"])
## All the processes python should be derived from "Process"
class DummyPythonProcess(KM.Process):
"""This class is a dummy-process that shows how the functions that can be implemented
in order to customize the behavior
Public member variables:
model -- the container of the different model parts.
settings -- Kratos parameters containing process settings.
"""
def __init__(self, model, settings):
""" The default constructor of the class
Keyword arguments:
self -- It signifies an instance of a class.
Model -- the container of the different model parts.
settings -- Kratos parameters containing process settings.
"""
KM.Process.__init__(self) # calling the baseclass constructor
default_settings = KM.Parameters("""{
"default_setting_bool" : true,
"default_setting_int" : 5,
"default_setting_double" : -1.45,
"default_setting_string" : "dummy",
"default_setting_array" : [1.0, 2.5, 4.8],
"default_setting_subparam" : {
"level_1" : 123
}
}""")
# Add missing settings that the user did not provide but that
# are necessary for this process
settings.ValidateAndAssignDefaults(default_settings)
# Alternative:
# settings.RecursivelyValidateAndAssignDefaults(default_settings)
def ExecuteInitialize(self):
""" This method is executed at the begining to initialize the process
Keyword arguments:
self -- It signifies an instance of a class.
"""
pass
def Check(self):
""" This method verifies that the input is correct
Keyword arguments:
self -- It signifies an instance of a class.
"""
pass
def ExecuteBeforeSolutionLoop(self):
""" This method is executed just before the solution-loop
Keyword arguments:
self -- It signifies an instance of a class.
"""
pass
def ExecuteInitializeSolutionStep(self):
""" This method is executed in order to initialize the current step
Keyword arguments:
self -- It signifies an instance of a class.
"""
pass
def ExecuteBeforeOutputStep(self):
""" This method is executed before writing the output (if output
is being written in this step)
Keyword arguments:
self -- It signifies an instance of a class.
"""
pass
def ExecuteAfterOutputStep(self):
""" This method is executed after writing the output (if output
is being written in this step)
Keyword arguments:
self -- It signifies an instance of a class.
"""
pass
def ExecuteFinalizeSolutionStep(self):
""" This method is executed in order to finalize the current step
Keyword arguments:
self -- It signifies an instance of a class.
"""
pass
def ExecuteFinalize(self):
""" This method is executed after the computations, at the end of the solution-loop
Keyword arguments:
self -- It signifies an instance of a class.
"""
pass
Note: Unused functions can be deleted, it is not necessary to have an empty implementation.
- Getting Kratos (Last compiled Release)
- Compiling Kratos
- Running an example from GiD
- Kratos input files and I/O
- Data management
- Solving strategies
- Manipulating solution values
- Multiphysics
- Video tutorials
- Style Guide
- Authorship of Kratos files
- Configure .gitignore
- How to configure clang-format
- How to use smart pointer in Kratos
- How to define adjoint elements and response functions
- Visibility and Exposure
- Namespaces and Static Classes
Kratos structure
Conventions
Solvers
Debugging, profiling and testing
- Compiling Kratos in debug mode
- Debugging Kratos using GDB
- Cross-debugging Kratos under Windows
- Debugging Kratos C++ under Windows
- Checking memory usage with Valgind
- Profiling Kratos with MAQAO
- Creating unitary tests
- Using ThreadSanitizer to detect OMP data race bugs
- Debugging Memory with ASAN
HOW TOs
- How to create applications
- Python Tutorials
- Kratos For Dummies (I)
- List of classes and variables accessible via python
- How to use Logger
- How to Create a New Application using cmake
- How to write a JSON configuration file
- How to Access DataBase
- How to use quaternions in Kratos
- How to do Mapping between nonmatching meshes
- How to use Clang-Tidy to automatically correct code
- How to use the Constitutive Law class
- How to use Serialization
- How to use GlobalPointerCommunicator
- How to use PointerMapCommunicator
- How to use the Geometry
- How to use processes for BCs
- How to use Parallel Utilities in futureproofing the code
- Porting to Pybind11 (LEGACY CODE)
- Porting to AMatrix
- How to use Cotire
- Applications: Python-modules
- How to run multiple cases using PyCOMPSs
- How to apply a function to a list of variables
- How to use Kratos Native sparse linear algebra
Utilities
Kratos API
Kratos Structural Mechanics API