User:Jcotela

From KratosWiki
(Difference between revisions)
Jump to: navigation, search
(A first Python example)
Line 21: Line 21:
 
== A first Python example ==
 
== 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)
  
 
= Older stuff =
 
= Older stuff =

Revision as of 16:54, 18 September 2013

Contents

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

 python script.py

Exceptionally, for this course, we are using a non-standard python installation so, for today, download the following file [1] 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

  ./run.sh script.py

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)

Older stuff

Required components How to refine an existing triangular or tetrahedral mesh

Kratos Structure

Personal tools
Categories