Python Script Tutorial: Reading ModelPart From Input File
(→Reading ModelPart File) |
(→Reading ModelPart File) |
||
Line 81: | Line 81: | ||
Begin Conditions PointLoadCondition2D1N | Begin Conditions PointLoadCondition2D1N | ||
− | 1 1 3 <span style="color:red"> //pos1:condition ID | + | 1 1 3 <span style="color:red"> //pos1:condition ID ; pos2:cond Property ( = 1 in this case) ; pos3:node to apply the condition. </span> |
End Conditions | End Conditions | ||
+ | |||
+ | Begin SubModelPart BaseNodes // Note that this would be a sub sub modelpart | ||
+ | Begin SubModelPartNodes | ||
+ | 1 | ||
+ | 2 | ||
+ | End SubModelPartNodes | ||
+ | End SubModelPart | ||
which represents the following 2D problem: | which represents the following 2D problem: |
Latest revision as of 08:16, 1 June 2016
The ModelPart represents an arbitrary part of the model to be simulated and stores the mesh and additional data for it. Most of the Kratos routines take a ModelPart as their argument. So always is necessary to create and fill a ModelPart. In this tutorial we will describe how to create and fill a model part from given input file.
Contents |
Starting
First of all we need to create a python file with following code to import the Kratos:
from KratosMultiphysics import * from KratosMultiphysics.SolidMechanicsApplication import *
Creating a ModelPart
To create a ModelPart, one has to call its constructor passing the ModelPart`s name as its argument:
structure_model_part = ModelPart("StructurePart")
You can print the fluid_model_part:
>>> print structure_model_part StructurePart model part Buffer Size : 1 Number of tables : 0 Current solution step index : 0 Mesh 0 : Number of Nodes : 0 Number of Properties : 0 Number of Elements : 0 Number of Conditions : 0
It can be seen that the ModelPart is empty and has the buffer size equal to 1. This means that no history of the nodal solution steps variables will be saved.
The next step is to define the variables we want to store as historical variables in nodes of this ModelPart as follow:
structure_model_part.AddNodalSolutionStepVariable(DISPLACEMENT) structure_model_part.AddNodalSolutionStepVariable(FORCE)
Reading ModelPart File
The input file of the Kratos has .mdpa (stand for ModelPart) and contains the properties, nodes, elements, conditions and initial values. A convenient way to create this file is to use the interface prepared for GiD pre and post processor. Here you can find more information about the input file. Here we assume that the example.mdpa input file is already created as follow:
example.mdpa
Begin ModelPartData // nothing here End ModelPartData Begin Properties 1 DENSITY 2700.000000 YOUNG_MODULUS 7000000.000000 POISSON_RATIO 0.300000 BODY_FORCE [3] (0.000000,0.000000,0.000000) THICKNESS 1.000000 End Properties Begin Nodes 1 0.0 0.0 0.0 //node number, coord x, cord y, coord z 2 1.0 0.0 0.0 //node number, coord x, cord y, coord z 3 1.0 1.0 0.0 //node number, coord x, cord y, coord z 4 0.0 1.0 0.0 //node number, coord x, cord y, coord z End Nodes Begin Elements TotalLagrangianElement2D3N 1 1 1 2 4 //the first column is the property 2 1 3 4 2 End Elements Begin NodalData DISPLACEMENT_X //be careful, variables are case sensitive! 1 1 100.0 // pos1 is the node, pos2 (a 1) means that the DOF is fixed, then (position 3) we write the fixed displacement (in this case, temperature) End NodalData Begin NodalData DISPLACEMENT_Y 1 1 100.0 End NodalData Begin NodalData FORCE_Y 3 0 5.0 //fixing it or not does not change anything since it is not a degree of freedom, it's just info that will be used by the condition End NodalData Begin Conditions PointLoadCondition2D1N 1 1 3 //pos1:condition ID ; pos2:cond Property ( = 1 in this case) ; pos3:node to apply the condition. End Conditions Begin SubModelPart BaseNodes // Note that this would be a sub sub modelpart Begin SubModelPartNodes 1 2 End SubModelPartNodes End SubModelPart
which represents the following 2D problem:
For reading the .mdpa file first we have to create a ModelPartIO object passing the input file path/name to its constructor:
model_part_io_structure = ModelPartIO("path/to/file/example")
the file name is used without the .mdpa extension! |
Then use this io object to read the file and store the mesh and data in ModelPart:
model_part_io_structure.ReadModelPart(structure_model_part)
And printing again the ModelPart:
>>> print structure_model_part StructurePart model part Buffer Size : 1 Number of tables : 0 Current solution step index : 0 Mesh 0 : Number of Nodes : 4 Number of Properties : 1 Number of Elements : 2 Number of Conditions : 1
Setting the Buffer Size
If we need to store the values of the nodal solution step variables in previous time steps, we must modify the buffer size AFTER defining the historical variables:
structure_model_part.SetBufferSize(3)
This would store the values for two previous steps in addition to the current ones.
Next Tutorial : Python Script Tutorial: Writing Output File
Previous Tutorial : Python Script Tutorial: Hello Kratos
All Tutorials : Kratos Tutorials