Skip to content

Commit 0492dd6

Browse files
Merge pull request #845 from KratosMultiphysics/add-mdpa-generator
Add mdpa generator app
2 parents 1e79fe5 + 571ea2d commit 0492dd6

11 files changed

Lines changed: 218 additions & 14 deletions

File tree

kratos.gid/apps/Fluid/write/write.tcl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace eval ::Fluid::write {
22
namespace path ::Fluid
33
Kratos::AddNamespace [namespace current]
4-
4+
55
# Namespace variables declaration
66
variable writeCoordinatesByGroups
77
variable writeAttributes
@@ -20,7 +20,7 @@ proc ::Fluid::write::Init { } {
2020
SetAttribute results_un [::Fluid::GetUniqueName results]
2121
SetAttribute drag_un [::Fluid::GetUniqueName drag]
2222
SetAttribute time_parameters_un [::Fluid::GetUniqueName time_parameters]
23-
23+
2424
SetAttribute writeCoordinatesByGroups [::Fluid::GetWriteProperty coordinates]
2525
SetAttribute validApps [list "Fluid"]
2626
SetAttribute main_launch_file [::Fluid::GetAttribute main_launch_file]
@@ -59,8 +59,8 @@ proc ::Fluid::write::writeModelPartEvent { } {
5959

6060
# Custom SubmodelParts
6161
variable last_condition_iterator
62-
write::writeBasicSubmodelPartsByUniqueId $Fluid::write::FluidConditionMap $last_condition_iterator
63-
62+
write::writeBasicSubmodelPartsByUniqueId $Fluid::write::FluidConditionMap $last_condition_iterator
63+
6464
# SubmodelParts
6565
writeMeshes
6666

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"id": "MdpaGenerator",
3+
"name": "Mdpa Generator",
4+
"script_files": [
5+
"start.tcl",
6+
"xml/XmlController.tcl",
7+
"write/write.tcl"
8+
],
9+
"dimensions": [
10+
"3D"
11+
],
12+
"start_script":"::MdpaGenerator::Init",
13+
"requeriments":{
14+
"minimum_gid_version":"15.1.3d"
15+
},
16+
"permissions": {
17+
"open_tree": true,
18+
"show_toolbar": true,
19+
"intervals": false,
20+
"wizard": false
21+
},
22+
"main_launch_file": null,
23+
"description": "MDPA generator \n-Useful tool to generate modelparts"
24+
}
3.63 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace eval ::MdpaGenerator {
2+
Kratos::AddNamespace [namespace current]
3+
4+
# Variable declaration
5+
variable _app
6+
variable dir
7+
}
8+
9+
10+
proc ::MdpaGenerator::Init { app } {
11+
12+
# Variable initialization
13+
variable _app
14+
variable dir
15+
16+
set _app $app
17+
set dir [apps::getMyDir "MdpaGenerator"]
18+
19+
::MdpaGenerator::xml::Init
20+
::MdpaGenerator::write::Init
21+
}
22+
23+
proc ::MdpaGenerator::BreakRunCalculation {} {
24+
return true
25+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
namespace eval ::MdpaGenerator::write {
2+
namespace path ::MdpaGenerator
3+
Kratos::AddNamespace [namespace current]
4+
5+
# Namespace variables declaration
6+
variable writeCoordinatesByGroups
7+
variable writeAttributes
8+
variable ConditionMap
9+
# after regular conditions are written, we need this number in order to print the custom submodelpart conditions
10+
# only if are applied over things that are not in the skin
11+
variable last_condition_iterator
12+
}
13+
14+
proc ::MdpaGenerator::write::Init { } {
15+
# Namespace variables inicialization
16+
17+
variable last_condition_iterator
18+
set last_condition_iterator 0
19+
20+
variable writeAttributes
21+
set writeAttributes [dict create ]
22+
}
23+
24+
# MDPA write event
25+
proc ::MdpaGenerator::write::writeModelPartEvent { } {
26+
# Validation
27+
set err [Validate]
28+
if {$err ne ""} {error $err}
29+
30+
InitConditionsMap
31+
writeProperties
32+
33+
# Init data
34+
write::initWriteConfiguration [GetAttributes]
35+
36+
# Headers
37+
write::writeModelPartData
38+
39+
# Nodal coordinates
40+
write::writeNodalCoordinates
41+
42+
# Custom SubmodelParts
43+
set conditions_mode [write::getValue SMP_write_options condition_write_mode]
44+
variable last_condition_iterator
45+
set last_condition_iterator [expr [write::getValue SMP_write_options conditions_start_id] -1]
46+
switch $conditions_mode {
47+
"unique" {write::writeBasicSubmodelPartsByUniqueId $MdpaGenerator::write::ConditionMap $last_condition_iterator}
48+
"norepeat" {write::writeBasicSubmodelParts $last_condition_iterator}
49+
"gid-id" {}
50+
default {}
51+
}
52+
53+
54+
# Clean
55+
unset ::MdpaGenerator::write::ConditionMap
56+
}
57+
58+
proc ::MdpaGenerator::write::writeCustomFilesEvent { } {
59+
}
60+
61+
62+
proc ::MdpaGenerator::write::Validate {} {
63+
set err ""
64+
65+
return $err
66+
}
67+
68+
# MDPA Blocks
69+
proc ::MdpaGenerator::write::writeProperties { } {
70+
# Begin Properties
71+
write::WriteString "Begin Properties 0"
72+
write::WriteString "End Properties"
73+
write::WriteString ""
74+
}
75+
76+
proc ::MdpaGenerator::write::InitConditionsMap { {map "" } } {
77+
78+
variable ConditionMap
79+
if {$map eq ""} {
80+
set ConditionMap [objarray new intarray [expr [GiD_Info Mesh MaxNumElements] +1] 0]
81+
} {
82+
set ConditionMap $map
83+
}
84+
}
85+
proc ::MdpaGenerator::write::FreeConditionsMap { } {
86+
87+
variable ConditionMap
88+
unset ConditionMap
89+
}
90+
91+
proc ::MdpaGenerator::write::GetAttribute {att} {
92+
variable writeAttributes
93+
return [dict get $writeAttributes $att]
94+
}
95+
96+
proc ::MdpaGenerator::write::GetAttributes {} {
97+
variable writeAttributes
98+
return $writeAttributes
99+
}
100+
101+
proc ::MdpaGenerator::write::SetAttribute {att val} {
102+
variable writeAttributes
103+
dict set writeAttributes $att $val
104+
}
105+
106+
proc ::MdpaGenerator::write::AddAttribute {att val} {
107+
variable writeAttributes
108+
dict lappend writeAttributes $att $val
109+
}
110+
111+
proc ::MdpaGenerator::write::AddAttributes {configuration} {
112+
variable writeAttributes
113+
set writeAttributes [dict merge $writeAttributes $configuration]
114+
}
115+
116+
proc ::MdpaGenerator::write::writeParametersEvent { } {
117+
118+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container n="MdpaGenerator" pn="MdpaGenerator" icon="app" prefix="MDPAGen_" tree_state="open" open_window="0">
3+
<container n="WriteOptions" pn="Write options" tree_state="open" un="SMP_write_options">
4+
<value n="condition_write_mode" pn="Condition mode" v='unique' values="unique,norepeat,gid-id" dict="unique,Unique ids,norepeat,No repeat ids"
5+
help="Ids policy for conditions applied over the same entity more than one time.\nUnique ids means that if we apply more than one time a condition over an entity, the id will be the same everytime.\nNo repeat means that every time we apply a condition over an entity, it will generate a different id.">
6+
<dependencies value='unique' node="../value[@n='conditions_start_id']" att1='state' v1='normal' />
7+
<dependencies value='norepeat' node="../value[@n='conditions_start_id']" att1='state' v1='normal' />
8+
<dependencies value='gid-id' node="../value[@n='conditions_start_id']" att1='state' v1='hidden' />
9+
</value>
10+
<value n="nodes_start_id" pn="Nodes start id" v="1" state="disabled"/>
11+
<value n="elements_start_id" pn="Elements start id" v="1" state="disabled"/>
12+
<value n="conditions_start_id" pn="Conditions start id" v="1"/>
13+
</container>
14+
<include n="GenericSubModelPart" active="1" path="apps/Common/xml/GenericSubModelPart.spd"/>
15+
</container>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<container n="procs" pn="procs" includeContainer="No">
3+
</container>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace eval ::MdpaGenerator::xml {
2+
namespace path ::MdpaGenerator
3+
Kratos::AddNamespace [namespace current]
4+
5+
# Namespace variables declaration
6+
variable dir
7+
}
8+
9+
proc ::MdpaGenerator::xml::Init { } {
10+
# Namespace variables inicialization
11+
variable dir
12+
Model::InitVariables dir $::MdpaGenerator::dir
13+
14+
}

kratos.gid/kratos.tcl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ proc Kratos::InitGlobalVariables {dir} {
151151
# Allow logs -> 0 No | 1 Only local | 2 Share with dev team
152152
set Kratos::kratos_private(allow_logs) 1
153153
# git hash of the problemtype
154-
set Kratos::kratos_private(problemtype_git_hash) 0
154+
set Kratos::kratos_private(problemtype_git_hash) 0
155155
# Place were the logs will be placed
156156
set Kratos::kratos_private(model_log_folder) ""
157157

@@ -282,7 +282,7 @@ proc Kratos::Event_EndProblemtype { } {
282282
}
283283
if {[array exists ::Kratos::kratos_private]} {
284284
# Close the log and moves them to the folder
285-
Kratos::FlushLog
285+
Kratos::FlushLog
286286

287287
# Restore GiD variables that were modified by kratos and must be restored (maybe mesher)
288288
Kratos::RestoreVariables
@@ -307,7 +307,7 @@ proc Kratos::Event_EndProblemtype { } {
307307

308308
}
309309
Drawer::UnregisterAll
310-
310+
311311
# Clear namespaces
312312
Kratos::DestroyNamespaces
313313
}
@@ -471,6 +471,8 @@ proc Kratos::Event_BeforeRunCalculation { batfilename basename dir problemtypedi
471471
if {!$run} {
472472
return [list "-cancel-" [= "You have selected MPI parallelism system.\nInput files have been written.\nRun the MPILauncher.sh script" ]]
473473
}
474+
set app_run_brake [apps::ExecuteOnCurrentApp BreakRunCalculation]
475+
if {[write::isBooleanTrue $app_run_brake]} {return "-cancel-"}
474476
}
475477

476478
proc Kratos::Event_AfterWriteCalculationFile { filename errorflag } {

kratos.gid/kratos_default.spd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<appLink n="DEMPFEM" public="0" pn="DEM+PFEM" active="0" appid="DEMPFEM" prefix="DEMPFEM"/>
3131
<appLink n="CDEM" public="0" pn="Cohesive DEM" active="0" appid="CDEM" prefix="CDEM"/>
3232
<appLink n="ShallowWater" public="1" pn="Shallow water" active="0" appid="ShallowWater" prefix="SW"/>
33+
<appLink n="MdpaGenerator" public="1" pn="Mdpa Generator" active="0" appid="MdpaGenerator" prefix="MDPAGen_" is_tool="1"/>
3334
<appLink n="Examples" public="1" pn="Examples" active="0" appid="Examples" prefix="EXA_" is_tool="1"/>
3435
<blockdata n="units" pn="Units" icon="units" open_window="0">
3536
<value n='units_mesh' pn='Mesh units' unit_mesh_definition="1"/>

0 commit comments

Comments
 (0)