Skip to content

ModelPart and SubModelPart

Riccardo Rossi edited this page Jun 5, 2018 · 20 revisions

In the previous part of the tutorial, we already saw how the ModelPart is the object containing Element, Conditions, Nodes and Properties.

A fundamental feature is that it can also hierarchically contain "SubModelParts" intended as other ModelParts which belong to the same parent. This relation can be repeated recursively, so that each "root" ModelPart can actually own a tree of SubModelParts.

Data Ownership

The parent-son relation is such that anything that belongs to a given SubModelPart also belongs to the parent ModelPart. This implies that the ultimate "owner" of any Node, Element, etc, will be the "root" ModelPart. The consistency of the tree is ensured by the ModelPart API, which provides the tools needed for creating or removing anything any of the contained objects.

Let's try to make an example to explain this better.

    #create a ModelPart root
    model_part = ModelPart("Main")

    #now create a SubModelPart
    model_part.CreateSubModelPart("Inlets")

    #let's output what is there:
    print(model_part)

the output is:

we could now verify if a given submodelpart exists, or how many SubModelParts exist as

    model_part.HasSubModelPart("Inlets") #returns True
    model_part.NumberOfSubModelParts() #returns 1
    model_part.GetSubModelPart("Inlets").Name #returns the name --> Inlets

let's now create some other SubModelParts

    #on the first level
    model_part.CreateSubModelPart("Temp")
    model_part.CreateSubModelPart("Outlet")

    #on the second level --> "sub-sub modelparts"
    sub_model_part_1 = model_part.GetSubModelPart("Inlets")
    sub_model_part_1.CreateSubModelPart("Inlet1")
    sub_model_part_1.CreateSubModelPart("Inlet2")

    #output
    print(model_part)

each modelpart is only directly aware of its first level siblings. that is

    model_part.HasSubmodelPart("Inlet1") --> returns False

however

    model_part.GetSubModelPart("Inlets").HasSubmodelPart("Inlet1") --> returns True
    

    self.assertEqual(model_part.NumberOfSubModelParts(), 3)
    self.assertEqual(model_part.GetSubModelPart("Inlets").Name, "Inlets")
    self.assertEqual(model_part.GetSubModelPart("Outlet").Name, "Outlet")

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