Python Script Tutorial: ModelPart Elements and Conditions

From KratosWiki
Jump to: navigation, search

The elements and conditions are the main extension points of the Kratos. In input script accessing them improves the flexibility in dealing with complex problems.


Starting

First of all we need to create a python file with following code to import the Kratos, create a ModelPart and read it from input as described in the here :

from KratosMultiphysics import *
from KratosMultiphysics.StructuralApplication import *

structure_model_part = ModelPart("StructurePart")

structure_model_part.AddNodalSolutionStepVariable(DISPLACEMENT)
structure_model_part.AddNodalSolutionStepVariable(FORCE)
structure_model_part.AddNodalSolutionStepVariable(TEMPERATURE )
 
model_part_io_structure = ModelPartIO("path/to/file/example")
model_part_io_structure.ReadModelPart(structure_model_part)


Accessing Elements

The elements stored in the ModelPart can be accessed using the Elements parameter:

 model_part_elements = structure_model_part.Elements

Iteration over all elements in a model part is very similar to the nodes. For example writing the elements in a model part can be done as follow:

  for element in structure_model_part.Elements:
      print element

and printing the ID for all of the elements:

  for element in structure_model_part.Elements:
      print element.Id


Accessing Conditions

Conditions parameter of model part provides access to the conditions it stores:
 model_part_conditions = structure_model_part.Conditions

Iteration over conditions is very similar to the elements. In the same way printing conditions is as follow:

  for condition in structure_model_part.Condition:
      print condition

and printing the ID for all of the conditions:

  for condition in structure_model_part.Condition:
      print condition.Id


Next Tutorial : Python Script Tutorial: Using Kratos Solvers

Previous Tutorial : Python Script Tutorial: ModelPart Nodes and Nodal Data

All Tutorials : Kratos Tutorials

Personal tools
Categories