-
Notifications
You must be signed in to change notification settings - Fork 247
Manipulating solution values
This tutorial session is intended to illustrate how the Kratos' data structure, when accessed form Python, can be used to manipulate and set custom boundary conditions, solutions over the computational domain in a given problem. The following explanation builds upon the previous sessions of Data management and Solving strategies.
Here the CFD problem described in the first tutorial of Running an example from GiD is used as the working example. The setup files (mdpa, MainKratos.py and the JSON) of this problem can be downloaded from here. Please extract the zip file and make it ready for the next task.
As the first step of this tutorial, we understand the CFD example problem setup and run the simulation to observe the initial result. The CFD problem setup is illustrated below
As illustrated, a no slip condition is applied on the top and bottom walls of the 2D fluid domain. A uniform and constant velocity inlet is applied on the left hand side and a pressure outlet (0 pressure) is applied on the right hand side of the domain. These boundary condition are defined in the ProjectParameters.json. The following lines from the ProjectPrameters.json reflect the same
"boundary_conditions_process_list" : [{
"python_module" : "apply_inlet_process",
"kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
"Parameters" : {
"model_part_name" : "FluidModelPart.AutomaticInlet2D_Inlet",
"variable_name" : "VELOCITY",
"modulus" : "25.0",
"direction" : "automatic_inwards_normal",
"interval" : [0,10.0]
}
},{
"python_module" : "apply_inlet_process",
"kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
"Parameters" : {
"model_part_name" : "FluidModelPart.AutomaticInlet2D_Inlet",
"variable_name" : "VELOCITY",
"modulus" : 25.0,
"direction" : "automatic_inwards_normal",
"interval" : [10.0,"End"]
}
},{
"python_module" : "apply_outlet_process",
"kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
"Parameters" : {
"model_part_name" : "FluidModelPart.Outlet2D_Outlet",
"variable_name" : "PRESSURE",
"constrained" : true,
"value" : 0.0,
"hydrostatic_outlet" : false,
"h_top" : 0.0
}
},{
"python_module" : "apply_noslip_process",
"kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
"Parameters" : {
"model_part_name" : "FluidModelPart.NoSlip2D_InterfaceFluid"
}
},{
"python_module" : "apply_slip_process",
"kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
"process_name" : "ApplySlipProcess",
"Parameters" : {
"model_part_name" : "FluidModelPart.Slip2D"
}
}]
Please run the example by using the method described in the previous tutorials. That is by using the runkratos
executable. Once the simulation is finished (should take about 4 minutes) we load the result (.bin) file into GiD to view the following result
This is the script that instantiates the fluid dynamics analysis and calls the Run
function of the solver class to solve the CFD problem with applied boundary conditions.
from __future__ import print_function, absolute_import, division #makes KratosMultiphysics backward compatible with python 2.6 and 2.7
import KratosMultiphysics
from KratosMultiphysics.FluidDynamicsApplication.fluid_dynamics_analysis import FluidDynamicsAnalysis
import sys
import time
class CustomFluidDynamicsAnalysis(FluidDynamicsAnalysis):
def __init__(self,model,project_parameters,flush_frequency=10.0):
super(CustomFluidDynamicsAnalysis,self).__init__(model,project_parameters)
self.flush_frequency = flush_frequency
self.last_flush = time.time()
def FinalizeSolutionStep(self):
super(CustomFluidDynamicsAnalysis,self).FinalizeSolutionStep()
if self.parallel_type == "OpenMP":
now = time.time()
if now - self.last_flush > self.flush_frequency:
sys.stdout.flush()
self.last_flush = now
if __name__ == "__main__":
with open("ProjectParameters.json",'r') as parameter_file:
parameters = KratosMultiphysics.Parameters(parameter_file.read())
model = KratosMultiphysics.Model()
simulation = CustomFluidDynamicsAnalysis(model,parameters)
simulation.Run()
As we see here, a custom fluid dynamics analysis is derived from the actual FluidDynamicsAnalysis
to make a CustomFluidDynamicsAnalysis
class and uses it for the simulation.
This CustomFluidDynamicsAnalysis
can be used to modify the properties of the simulation, even those specified in the JSON file.
- 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