Kratos Course 2013
Before we start
Usually, the Python interpreter can be called from command line. To execute the commands in a file, lets say script.py, we can use the instruction
Exceptionally, for this course, we are using a non-standard python installation so, for today, download the following file  and copy it to your problem’s folder (for example, inside cylinder.gid)
To run a python script, on a command window, go to the model’s folder and type
First, we will create a new Python file to work on. To do this, we create a copyuse the default script (KratosOpenMP.py) to use as a starting point:
cp KratosOpenMP.py script.py
Open script.py on a text editor.
A first Python example
The following function defines a parabolic velocity profile, with different values depending on the Y coordinate (we are assuming that the Y coordinates vary from 0 to h)
def get_boundary_velocity(y,u_max,h): return (1-y/h)*(y/h)*u_max
we can use it as an initial condition by assigning it to all nodes in the model (correct the value of h if your model has a different size)
u_max = 0.01 h = 2.0 for node in fluid_model_part.Nodes: u_node = get_boundary_velocity(node.Y,u_max,h) node.SetSolutionStepValue(VELOCITY_X,0,u_node)
Paste the last two pieces of code into script.py (just before the **while** solution loop is a fine place) and run your script.
Alternatively, we could use it as an inlet boundary condition by asigning it only to the leftmost nodes (I’m assuming here that the inlet boundary is defined by x=0)
u_max = 0.01 h = 2.0 for node in fluid_model_part.Nodes: if node.X == 0.0: u_node = get_boundary_velocity(node.Y,u_max,h) node.SetSolutionStepValue(VELOCITY_X,0,u_node) node.Fix(VELOCITY_X)