Skip to content

Python Script Tutorial: ModelPart Elements and Conditions

Carlos Roig edited this page May 28, 2018 · 13 revisions

Python Script Tutorial: ModelPart Elements and Conditions 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

Project information

Getting Started

Tutorials

Developers

Kratos structure

Conventions

Solvers

Debugging, profiling and testing

HOW TOs

Utilities

Kratos API

Kratos Structural Mechanics API

Clone this wiki locally