Skip to content

Commit 0837a3c

Browse files
authored
Merge pull request #842 from KratosMultiphysics/shallow-water-ptype
Add shallow water problemtype
2 parents 4a93b9f + d0b36ad commit 0837a3c

37 files changed

Lines changed: 963 additions & 0 deletions

kratos.gid/apps/Examples/xml/examples.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
<link path="apps/MPM/examples/examples.xml"/>
2222
<link path="apps/PfemFluid/examples/examples.xml"/>
2323
<link path="apps/PfemThermic/examples/examples.xml"/>
24+
<link path="apps/ShallowWater/examples/examples.xml"/>
2425
</examples>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"id": "ShallowWater",
3+
"name": "Shallow water",
4+
"prefix": "SW",
5+
"themed": false,
6+
"kratos_name": "ShallowWaterApplication",
7+
"dimensions": [
8+
"2D"
9+
],
10+
"script_files": [
11+
"start.tcl",
12+
"xml/XmlController.tcl",
13+
"write/write.tcl",
14+
"write/writeProjectParameters.tcl",
15+
"examples/examples.tcl",
16+
"examples/DamBreak.tcl",
17+
"examples/HydraulicJump.tcl"
18+
],
19+
"start_script":"::ShallowWater::Init",
20+
"requirements":{},
21+
"permissions": {
22+
"open_tree": true,
23+
"show_toolbar": true,
24+
"intervals": true,
25+
"wizard": false
26+
},
27+
"unique_names": {
28+
"parts": "SWParts",
29+
"materials": "SWMaterials",
30+
"topography_data": "SWTopographicData",
31+
"initial_conditions": "SWInitialConditions",
32+
"conditions": "SWConditions",
33+
"gravity": "SWGravity",
34+
"time_parameters": "SWTimeParameters"
35+
},
36+
"write": {
37+
"coordinates": "all",
38+
"materials_file": "TopographyMaterials.json",
39+
"properties_location": "json",
40+
"model_part_name": "main_model_part",
41+
"output_model_part_name": "main_model_part"
42+
},
43+
"main_launch_file": "python/MainKratos.py",
44+
"description": "Tools for the simulation of free surface flows under the shallow water assumptions."
45+
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
namespace eval ::ShallowWater::examples::DamBreak {
2+
namespace path ::ShallowWater::examples
3+
Kratos::AddNamespace [namespace current]
4+
}
5+
6+
proc ::ShallowWater::examples::DamBreak::Init {args} {
7+
if {![Kratos::IsModelEmpty]} {
8+
set txt "We are going to draw the example geometry.\nDo you want to lose your previous work?"
9+
set retval [tk_messageBox -default ok -icon question -message $txt -type okcancel]
10+
if { $retval == "cancel" } { return }
11+
}
12+
DrawGeometry
13+
AssignGroups
14+
TreeAssignation
15+
16+
GiD_Process 'Redraw
17+
GidUtils::UpdateWindow GROUPS
18+
GidUtils::UpdateWindow LAYER
19+
GiD_Process 'Zoom Frame
20+
}
21+
22+
proc ::ShallowWater::examples::DamBreak::DrawGeometry {args} {
23+
Kratos::ResetModel
24+
GiD_Layers create main_layer
25+
GiD_Layers edit to_use main_layer
26+
27+
# Geometry creation
28+
## Points ##
29+
set coordinates_left [list 0 0 0 5 0 0 5 1 0 0 1 0]
30+
set geom_points_left [list ]
31+
foreach {x y z} $coordinates_left {
32+
lappend geom_points_left [GiD_Geometry create point append main_layer $x $y $z]
33+
}
34+
35+
set coordinates_right [list 5 0 0 10 0 0 10 1 0 5 1 0]
36+
set geom_points_right [list ]
37+
foreach {x y z} $coordinates_right {
38+
lappend geom_points_right [GiD_Geometry create point append main_layer $x $y $z]
39+
}
40+
41+
## Lines ##
42+
set geom_lines_left [list ]
43+
set initial [lindex $geom_points_left 0]
44+
foreach point [lrange $geom_points_left 1 end] {
45+
lappend geom_lines_left [GiD_Geometry create line append stline main_layer $initial $point]
46+
set initial $point
47+
}
48+
lappend geom_lines_left [GiD_Geometry create line append stline main_layer $initial [lindex $geom_points_left 0]]
49+
50+
set geom_lines_right [list ]
51+
set initial [lindex $geom_points_right 0]
52+
foreach point [lrange $geom_points_right 1 end] {
53+
lappend geom_lines_right [GiD_Geometry create line append stline main_layer $initial $point]
54+
set initial $point
55+
}
56+
lappend geom_lines_right [GiD_Geometry create line append stline main_layer $initial [lindex $geom_points_right 0]]
57+
58+
## Surface ##
59+
GiD_Process Mescape Geometry Create NurbsSurface {*}$geom_lines_left escape escape
60+
GiD_Process Mescape Geometry Create NurbsSurface {*}$geom_lines_right escape escape
61+
62+
## Remove the duplicated line
63+
GiD_Process Mescape Utilities Collapse model Yes
64+
}
65+
66+
proc ::ShallowWater::examples::DamBreak::AssignGroups {args} {
67+
# Create and assign the groups
68+
GiD_Groups create Body
69+
GiD_Groups edit color Body "#26d1a8ff"
70+
GiD_EntitiesGroups assign Body surfaces {1 2}
71+
72+
GiD_Groups create Reservoir
73+
GiD_Groups edit color Reservoir "#26d1a8ff"
74+
GiD_EntitiesGroups assign Reservoir surfaces 1
75+
76+
GiD_Groups create Channel
77+
GiD_Groups edit color Channel "#26d1a8ff"
78+
GiD_EntitiesGroups assign Channel surfaces 2
79+
80+
GiD_Groups create Walls
81+
GiD_Groups edit color Walls "#3b3b3bff"
82+
GiD_EntitiesGroups assign Walls lines {1 3 5 7}
83+
84+
GiD_Groups create Left
85+
GiD_Groups edit color Left "#3b3b3bff"
86+
GiD_EntitiesGroups assign Left lines 4
87+
88+
GiD_Groups create Right
89+
GiD_Groups edit color Right "#3b3b3bff"
90+
GiD_EntitiesGroups assign Right lines 6
91+
}
92+
93+
proc ::ShallowWater::examples::DamBreak::TreeAssignation {args} {
94+
95+
# Parts
96+
set parts [spdAux::getRoute "SWParts"]
97+
set part_node [customlib::AddConditionGroupOnXPath $parts Body]
98+
set props [list Element GENERIC_ELEMENT Material Concrete]
99+
spdAux::SetValuesOnBaseNode $part_node $props
100+
101+
# Topography data
102+
set topography_conditions [spdAux::getRoute "SWTopographicData"]
103+
set topography_cond "$topography_conditions/condition\[@n='Topography'\]"
104+
set topography_node [customlib::AddConditionGroupOnXPath $topography_cond Body]
105+
$topography_node setAttribute ov surface
106+
set props [list value 0.0]
107+
spdAux::SetValuesOnBaseNode $topography_node $props
108+
109+
# Initial conditions
110+
set initial_conditions [spdAux::getRoute "SWInitialConditions"]
111+
set initial_cond "$initial_conditions/condition\[@n='InitialWaterLevel'\]"
112+
spdAux::AddIntervalGroup Reservoir "Reservoir//Initial"
113+
set initial_node [customlib::AddConditionGroupOnXPath $initial_cond "Reservoir//Initial"]
114+
$initial_node setAttribute ov surface
115+
set props [list value 1.0 Interval Initial]
116+
spdAux::SetValuesOnBaseNode $initial_node $props
117+
118+
spdAux::AddIntervalGroup Channel "Channel//Initial"
119+
set initial_node [customlib::AddConditionGroupOnXPath $initial_cond "Channel//Initial"]
120+
$initial_node setAttribute ov surface
121+
set props [list value 0.8 Interval Initial]
122+
spdAux::SetValuesOnBaseNode $initial_node $props
123+
124+
# Conditions
125+
set boundary_conditions [spdAux::getRoute "SWConditions"]
126+
set flow_rate_cond "$boundary_conditions/condition\[@n='ImposedFlowRate'\]"
127+
spdAux::AddIntervalGroup Walls "Walls//Total"
128+
set flow_rate_node [customlib::AddConditionGroupOnXPath $flow_rate_cond "Walls//Total"]
129+
$flow_rate_node setAttribute ov line
130+
set props [list selector_component_X Not value_component_Y 0.0 selector_component_Z Not Interval Total]
131+
spdAux::SetValuesOnBaseNode $flow_rate_node $props
132+
133+
spdAux::AddIntervalGroup Right "Right//Total"
134+
set flow_rate_node [customlib::AddConditionGroupOnXPath $flow_rate_cond "Right//Total"]
135+
$flow_rate_node setAttribute ov line
136+
set props [list value_component_X 0.0 selector_component_Y Not selector_component_Z Not Interval Total]
137+
spdAux::SetValuesOnBaseNode $flow_rate_node $props
138+
139+
spdAux::AddIntervalGroup Left "Left//Total"
140+
set flow_rate_node [customlib::AddConditionGroupOnXPath $flow_rate_cond "Left//Total"]
141+
$flow_rate_node setAttribute ov line
142+
set props [list value_component_X 0.0 selector_component_Y Not selector_component_Z Not Interval Total]
143+
spdAux::SetValuesOnBaseNode $flow_rate_node $props
144+
145+
# Time parameters
146+
set parameters [list EndTime 2.0]
147+
set xpath [spdAux::getRoute "SWTimeParameters"]
148+
spdAux::SetValuesOnBasePath $xpath $parameters
149+
150+
# Output
151+
set parameters [list OutputControlType time OutputDeltaTime 0.1]
152+
set xpath "[spdAux::getRoute Results]/container\[@n='GiDOutput'\]/container\[@n='GiDOptions'\]"
153+
spdAux::SetValuesOnBasePath $xpath $parameters
154+
155+
# Refresh
156+
spdAux::RequestRefresh
157+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
namespace eval ::ShallowWater::examples::HydraulicJump {
2+
namespace path ::ShallowWater::examples
3+
Kratos::AddNamespace [namespace current]
4+
}
5+
6+
proc ::ShallowWater::examples::HydraulicJump::Init {args} {
7+
if {![Kratos::IsModelEmpty]} {
8+
set txt "We are going to draw the example geometry.\nDo you want to lose your previous work?"
9+
set retval [tk_messageBox -default ok -icon question -message $txt -type okcancel]
10+
if { $retval == "cancel" } { return }
11+
}
12+
DrawGeometry
13+
AssignGroups
14+
TreeAssignation
15+
16+
GiD_Process 'Redraw
17+
GidUtils::UpdateWindow GROUPS
18+
GidUtils::UpdateWindow LAYER
19+
GiD_Process 'Zoom Frame
20+
}
21+
22+
proc ::ShallowWater::examples::HydraulicJump::DrawGeometry {args} {
23+
Kratos::ResetModel
24+
GiD_Layers create main_layer
25+
GiD_Layers edit to_use main_layer
26+
27+
# Geometry creation
28+
## Points ##
29+
set coordinates [list 0 0 0 100 0 0 100 4 0 0 4 0]
30+
set geom_points [list ]
31+
foreach {x y z} $coordinates {
32+
lappend geom_points [GiD_Geometry create point append main_layer $x $y $z]
33+
}
34+
35+
## Lines ##
36+
set geom_lines [list ]
37+
set initial [lindex $geom_points 0]
38+
foreach point [lrange $geom_points 1 end] {
39+
lappend geom_lines [GiD_Geometry create line append stline main_layer $initial $point]
40+
set initial $point
41+
}
42+
lappend geom_lines [GiD_Geometry create line append stline main_layer $initial [lindex $geom_points 0]]
43+
44+
## Surface ##
45+
GiD_Process Mescape Geometry Create NurbsSurface {*}$geom_lines escape escape
46+
}
47+
48+
proc ::ShallowWater::examples::HydraulicJump::AssignGroups {args} {
49+
# Create and assign the groups
50+
GiD_Groups create Channel
51+
GiD_Groups edit color Channel "#26d1a8ff"
52+
GiD_EntitiesGroups assign Channel surfaces 1
53+
54+
GiD_Groups create Walls
55+
GiD_Groups edit color Walls "#3b3b3bff"
56+
GiD_EntitiesGroups assign Walls lines {1 3}
57+
58+
GiD_Groups create Upstream
59+
GiD_Groups edit color Upstream "#3b3b3bff"
60+
GiD_EntitiesGroups assign Upstream lines 4
61+
62+
GiD_Groups create Downstream
63+
GiD_Groups edit color Downstream "#3b3b3bff"
64+
GiD_EntitiesGroups assign Downstream lines 2
65+
}
66+
67+
proc ::ShallowWater::examples::HydraulicJump::TreeAssignation {args} {
68+
69+
# Parts
70+
set parts [spdAux::getRoute "SWParts"]
71+
set part_node [customlib::AddConditionGroupOnXPath $parts Channel]
72+
set props [list Element GENERIC_ELEMENT Material Concrete]
73+
spdAux::SetValuesOnBaseNode $part_node $props
74+
75+
# Topography data
76+
set topography_conditions [spdAux::getRoute "SWTopographicData"]
77+
set topography_cond "$topography_conditions/condition\[@n='Topography'\]"
78+
set topography_node [customlib::AddConditionGroupOnXPath $topography_cond Channel]
79+
$topography_node setAttribute ov surface
80+
set props [list ByFunction Yes function_value "2.45135310e-07*x**4 -4.82230477e-05*x**3 +2.54997185e-03*x**2 -4.57311854e-02*x +2.73225488e+00"]
81+
spdAux::SetValuesOnBaseNode $topography_node $props
82+
83+
# Initial conditions
84+
set initial_conditions [spdAux::getRoute "SWInitialConditions"]
85+
set initial_cond "$initial_conditions/condition\[@n='InitialWaterLevel'\]"
86+
spdAux::AddIntervalGroup Channel "Channel//Initial"
87+
set initial_node [customlib::AddConditionGroupOnXPath $initial_cond "Channel//Initial"]
88+
$initial_node setAttribute ov surface
89+
set props [list variable_name FREE_SURFACE_ELEVATION value 2.8 Interval Initial set_minimum_height 1 minimum_height_value 1]
90+
spdAux::SetValuesOnBaseNode $initial_node $props
91+
92+
# Conditions
93+
set boundary_conditions [spdAux::getRoute "SWConditions"]
94+
set flow_rate_cond "$boundary_conditions/condition\[@n='ImposedFlowRate'\]"
95+
set water_height_cond "$boundary_conditions/condition\[@n='ImposedFreeSurface'\]"
96+
97+
spdAux::AddIntervalGroup Walls "Walls//Total"
98+
set flow_rate_node [customlib::AddConditionGroupOnXPath $flow_rate_cond "Walls//Total"]
99+
$flow_rate_node setAttribute ov line
100+
set props [list selector_component_X Not value_component_Y 0.0 selector_component_Z Not Interval Total]
101+
spdAux::SetValuesOnBaseNode $flow_rate_node $props
102+
103+
spdAux::AddIntervalGroup Upstream "Upstream//Total"
104+
set flow_rate_node [customlib::AddConditionGroupOnXPath $flow_rate_cond "Upstream//Total"]
105+
$flow_rate_node setAttribute ov line
106+
set props [list value_component_X 2.0 selector_component_Y 0.0 selector_component_Z Not Interval Total]
107+
spdAux::SetValuesOnBaseNode $flow_rate_node $props
108+
109+
spdAux::AddIntervalGroup Downstream "Downstream//Total"
110+
set free_surface_node [customlib::AddConditionGroupOnXPath $water_height_cond "Downstream//Total"]
111+
$free_surface_node setAttribute ov line
112+
set props [list value 2.8 Interval Total]
113+
spdAux::SetValuesOnBaseNode $free_surface_node $props
114+
115+
# Time parameters
116+
set parameters [list EndTime 50.0]
117+
set xpath [spdAux::getRoute "SWTimeParameters"]
118+
spdAux::SetValuesOnBasePath $xpath $parameters
119+
120+
# Output
121+
set parameters [list OutputControlType time OutputDeltaTime 1.0]
122+
set xpath "[spdAux::getRoute Results]/container\[@n='GiDOutput'\]/container\[@n='GiDOptions'\]"
123+
spdAux::SetValuesOnBasePath $xpath $parameters
124+
125+
# Refresh
126+
spdAux::RequestRefresh
127+
}

0 commit comments

Comments
 (0)