Skip to content

Commit b2d81d9

Browse files
Merge pull request #945 from KratosMultiphysics/migrate-geomechanics-to-geometries
Advances in Geomechanics write
2 parents 7462bef + a3f5ab3 commit b2d81d9

42 files changed

Lines changed: 1003 additions & 57 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ dist
1313

1414
*.zip
1515
*.tgz
16-
null
16+
null
17+
__pycache__
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<container n="ParallelType" pn="Parallel configuration" un="Parallelization" help="Parallel type" icon="parallel" open_window="1">
3-
<value n="ParallelSolutionType" pn="Parallelization" un="ParallelType" v="OpenMP" values="OpenMP,MPI" help="Parallelization type" actualize="1" />
4-
<value n="MPINumberOfProcessors" pn="Number of nodes" v="1" help="Number of processors" state="[checkStateByUniqueName ParallelType MPI]"/>
5-
<value n="OpenMPNumberOfThreads" pn="Number of processors" v="1" help="Number of threads" state="[checkStateByUniqueName ParallelType OpenMP]"/>
6-
</container>
3+
<value n="ParallelSolutionType" pn="Parallelization" un="ParallelType" v="OpenMP" values="OpenMP,MPI" help="Parallelization type" actualize="1" />
4+
<value n="MPINumberOfProcessors" pn="Number of nodes" v="1" help="Number of processors" state="[getStateFromXPathValue {string(../value[@n='ParallelSolutionType']/@v)} MPI]"/>
5+
<value n="OpenMPNumberOfThreads" pn="Number of processors" v="1" help="Number of threads" state="[getStateFromXPathValue {string(../value[@n='ParallelSolutionType']/@v)} OpenMP]"/>
6+
</container>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
<link path="apps/PfemThermic/examples/examples.xml"/>
2525
<link path="apps/ShallowWater/examples/examples.xml"/>
2626
<link path="apps/FreeSurface/examples/examples.xml"/>
27+
<link path="apps/GeoMechanics/examples/examples.xml"/>
2728
</examples>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import sys
2+
import time
3+
import importlib
4+
5+
import KratosMultiphysics
6+
7+
def CreateAnalysisStageWithFlushInstance(cls, global_model, parameters):
8+
class AnalysisStageWithFlush(cls):
9+
10+
def __init__(self, model,project_parameters, flush_frequency=10.0):
11+
super().__init__(model,project_parameters)
12+
self.flush_frequency = flush_frequency
13+
self.last_flush = time.time()
14+
sys.stdout.flush()
15+
16+
def Initialize(self):
17+
super().Initialize()
18+
sys.stdout.flush()
19+
20+
def FinalizeSolutionStep(self):
21+
super().FinalizeSolutionStep()
22+
23+
if self.parallel_type == "OpenMP":
24+
now = time.time()
25+
if now - self.last_flush > self.flush_frequency:
26+
sys.stdout.flush()
27+
self.last_flush = now
28+
29+
return AnalysisStageWithFlush(global_model, parameters)
30+
31+
if __name__ == "__main__":
32+
33+
with open("ProjectParameters.json", 'r') as parameter_file:
34+
parameters = KratosMultiphysics.Parameters(parameter_file.read())
35+
36+
analysis_stage_module_name = parameters["stages"]["Stage 1"]["analysis_stage"].GetString()
37+
analysis_stage_class_name = analysis_stage_module_name.split('.')[-1]
38+
analysis_stage_class_name = ''.join(x.title() for x in analysis_stage_class_name.split('_'))
39+
40+
analysis_stage_module = importlib.import_module(analysis_stage_module_name)
41+
analysis_stage_class = getattr(analysis_stage_module, analysis_stage_class_name)
42+
43+
global_model = KratosMultiphysics.Model()
44+
simulation = CreateAnalysisStageWithFlushInstance(analysis_stage_class, global_model, parameters)
45+
simulation.Run()

kratos.gid/apps/GeoMechanics/app.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
"controllers/Toolbar.tcl",
1717
"write/write.tcl",
1818
"write/writeProjectParameters.tcl",
19-
"controllers/Python.tcl"
19+
"controllers/Python.tcl",
20+
"controllers/PhreaticLine.tcl",
21+
"examples/examples.tcl",
22+
"examples/FirstExample.tcl"
2023
],
2124
"start_script": "::GeoMechanics::Init",
2225
"requirements": {
@@ -43,11 +46,12 @@
4346
"coordinates": "all",
4447
"materials_file": "Materials.json",
4548
"properties_location": "json",
46-
"model_part_name": "ModelPart",
49+
"model_part_name": "PorousDomain",
4750
"output_model_part_name": "computational_model_part",
48-
"multistage_write_mdpa_mode": "different_files",
49-
"multistage_write_json_mode": "single_file"
51+
"write_mdpa_mode": "geometries",
52+
"multistage_write_json_mode": "single_file",
53+
"multistage_write_mdpa_file_mode": "single_file"
5054
},
51-
"main_launch_file": "../../exec/MainKratos.py",
55+
"main_launch_file": "MainKratos.py",
5256
"description": ""
53-
}
57+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
2+
proc ::GeoMechanics::PhreaticButton { } {
3+
variable curr_stage
4+
variable state_phreatic_line
5+
6+
# Get the current active stage
7+
set stages [::GeoMechanics::xml::GetStages]
8+
set stage [lindex $stages $curr_stage]
9+
10+
# If the state is none, the user clicked because he wants to create a phreatic line
11+
if {$state_phreatic_line eq "none"} {
12+
13+
# Get the current stage phreatic points
14+
set current_phreatic_points [::GeoMechanics::xml::GetPhreaticPoints $stage]
15+
# If there are no phreatic points, create a new line
16+
if {[llength $current_phreatic_points] eq 0} {
17+
set state_phreatic_line creating
18+
::GeoMechanics::CreatePhreaticLine $stage
19+
} else {
20+
# If there are phreatic points, display it somehow
21+
::GeoMechanics::DisplayPhreaticLine
22+
}
23+
} elseif {$state_phreatic_line in [list "creating" "displaying"]} {
24+
::GeoMechanics::EndCreatePhreaticLine
25+
}
26+
}
27+
28+
proc ::GeoMechanics::DeletePhreaticButton { } {
29+
variable curr_stage
30+
31+
# Get the current active stage
32+
set stages [::GeoMechanics::xml::GetStages]
33+
set stage [lindex $stages $curr_stage]
34+
35+
::GeoMechanics::xml::DeletePhreaticPoints $stage
36+
::GeoMechanics::EndCreatePhreaticLine
37+
}
38+
39+
proc ::GeoMechanics::CreatePhreaticLine {stage} {
40+
variable state_phreatic_line
41+
variable creating_phreatic_previous_layer
42+
set creating_phreatic_previous_layer [GiD_Layers get to_use]
43+
set stage_name [$stage @name]
44+
if {[GiD_Layers exists PhreaticLine_$stage_name]} {
45+
GiD_Layers delete PhreaticLine_$stage_name
46+
}
47+
GiD_Layers create PhreaticLine_$stage_name
48+
GiD_Layers edit to_use PhreaticLine_$stage_name
49+
GiD_RegisterEvent GiD_Event_AfterCreateLine ::GeoMechanics::AfterCreatePhreaticLine PROBLEMTYPE Kratos
50+
GiD_Process MEscape Mescape Geometry Create Line
51+
}
52+
53+
proc ::GeoMechanics::AfterCreatePhreaticLine { line } {
54+
variable curr_stage
55+
variable state_phreatic_line
56+
if {$state_phreatic_line eq "creating"} {
57+
58+
# Get the current active stage
59+
set stages [::GeoMechanics::xml::GetStages]
60+
set stage [lindex $stages $curr_stage]
61+
62+
# Get line points
63+
lassign [GiD_Geometry get line $line] a b p1 p2
64+
# Get point coordinates
65+
lassign [GiD_Geometry get point $p1] a x1 y1 z1
66+
lassign [GiD_Geometry get point $p2] a x2 y2 z2
67+
# Add coordinates to xml
68+
if {[llength [::GeoMechanics::xml::GetPhreaticPoints $stage]] == 0} {
69+
::GeoMechanics::xml::AddPhreaticPoint $stage $x1 $y1 $z1
70+
}
71+
::GeoMechanics::xml::AddPhreaticPoint $stage $x2 $y2 $z2
72+
} else {
73+
74+
}
75+
76+
# TODO: at this moment we only allow 2 points, in the future, will see
77+
set num [llength [::GeoMechanics::xml::GetPhreaticPoints $stage]]
78+
if {$num >= 2} {
79+
::GeoMechanics::EndCreatePhreaticLine
80+
::GeoMechanics::DisplayPhreaticLine
81+
}
82+
}
83+
proc ::GeoMechanics::EndCreatePhreaticLine { } {
84+
variable state_phreatic_line
85+
set state_phreatic_line none
86+
87+
# Delete the phreatic line
88+
::GeoMechanics::DeleteVisiblePhreaticLine
89+
90+
# Delete the lines from the variable list
91+
variable creating_phreatic_previous_layer
92+
GiD_Layers edit to_use $creating_phreatic_previous_layer
93+
catch {GiD_UnRegisterEvent GiD_Event_AfterCreateLine ::GeoMechanics::AfterCreatePhreaticLine PROBLEMTYPE Kratos}
94+
spdAux::RequestRefresh
95+
}
96+
97+
proc ::GeoMechanics::DeleteVisiblePhreaticLine { } {
98+
variable curr_stage
99+
100+
# Get the current active stage
101+
set stages [::GeoMechanics::xml::GetStages]
102+
set stage [lindex $stages $curr_stage]
103+
104+
set stage_name [$stage @name]
105+
# Delete the lines from the variable list
106+
if {[GiD_Layers exists PhreaticLine_$stage_name]} {GiD_Layers delete PhreaticLine_$stage_name}
107+
GiD_Process MEscape 'Redraw escape
108+
}
109+
110+
proc ::GeoMechanics::DisplayPhreaticLine {} {
111+
variable state_phreatic_line
112+
set state_phreatic_line displaying
113+
114+
# Get the current active stage
115+
variable curr_stage
116+
set stages [::GeoMechanics::xml::GetStages]
117+
set stage [lindex $stages $curr_stage]
118+
119+
set stage_name [$stage @name]
120+
set layer_name PhreaticLine_$stage_name
121+
if {[GiD_Layers exists $layer_name]} {
122+
GiD_Layers delete $layer_name
123+
}
124+
GiD_Layers create $layer_name
125+
# GiD_Layers edit to_use $layer_name
126+
set current_phreatic_points [::GeoMechanics::xml::GetPhreaticPoints $stage]
127+
set point_list [list ]
128+
foreach point $current_phreatic_points {
129+
lassign $point x y
130+
lappend point_list [GiD_Geometry -v2 create point append $layer_name $x $y 0.0]
131+
}
132+
# set coordinates ""
133+
set ini [lindex $point_list 0]
134+
foreach end [lrange $point_list 1 end] {
135+
GiD_Geometry -v2 create line append stline $layer_name $ini $end
136+
set ini $end
137+
}
138+
GiD_Process MEscape 'Redraw escape
139+
}

kratos.gid/apps/GeoMechanics/controllers/Python.tcl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,14 @@ proc ::GeoMechanics::PythonButton { } {
33
GiD_Python_Source [file join $::GeoMechanics::dir controllers geomechanics_script.py]
44
set result_python [GiD_Python_Call geomechanics_script.my_python_procedure $param1]
55
W $result_python
6+
}
7+
8+
proc ::GeoMechanics::PythonButtonImportPlaxis { } {
9+
set directory [MessageBoxGetFilename directory read [_ "Select Plaxis model to import"]]
10+
if {$directory == ""} {
11+
return
12+
}
13+
GiD_Python_Source [file join $::GeoMechanics::dir controllers geomechanics_import_plaxis.py]
14+
set result_python [GiD_Python_Call geomechanics_import_plaxis.import_plaxis_procedure $directory]
15+
W $result_python
616
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Create the main window
2+
set mainWindow .gid.maingui
3+
toplevel $mainWindow
4+
wm title $mainWindow "Two Sections Window"
5+
wm geometry $mainWindow 400x200
6+
7+
# Create the first section with two big square buttons
8+
frame $mainWindow.section1 -background white
9+
button $mainWindow.section1.button1 -text "Button 1" -width 10 -height 10
10+
button $mainWindow.section1.button2 -text "Button 2" -width 10 -height 10
11+
grid $mainWindow.section1.button1 -row 0 -column 0 -padx 20 -pady 20
12+
grid $mainWindow.section1.button2 -row 0 -column 1 -padx 20 -pady 20
13+
14+
# Create the second section with text and a small button
15+
frame $mainWindow.section2 -background white
16+
text $mainWindow.section2.text -width 30 -height 5
17+
button $mainWindow.section2.button -text "Small Button" -width 10
18+
grid $mainWindow.section2.text -row 0 -column 0 -padx 20 -pady 20
19+
grid $mainWindow.section2.button -row 1 -column 0 -padx 20 -pady 10
20+
21+
# Place the sections in the main window
22+
grid $mainWindow.section1 -row 0 -column 0 -sticky news
23+
grid $mainWindow.section2 -row 0 -column 1 -sticky news
24+
25+
# Start the event loop
26+
tkwait window $mainWindow
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import tohil
3+
4+
# To create functions and variables for all tcl available ones
5+
tcl=tohil.import_tcl()
6+
7+
8+
def import_plaxis_procedure(directory):
9+
10+
tcl.W(f"Importing Plaxi model from: {directory}")
11+
12+
# Print evertying that is known by the tcl object
13+
# object_info = tcl.__dict__
14+
# for object_function in object_info:
15+
# tcl.W(object_function)
16+
17+
tcl.W("Found files to import")
18+
for filename in os.listdir(directory):
19+
file = os.path.join(directory, filename)
20+
tcl.W(file)
21+
22+
p1 = tcl.GiD_Geometry("create", "point", "append", "Layer0", "-8.87755","3.26531","0")
23+
tcl.W(p1)
24+
p2 = tcl.GiD_Geometry("create", "point", "append", "Layer0", "4.95465","3.44671","0")
25+
result = tcl.GiD_Geometry("create", "line", "append", "stline", "Layer0", p1, p2)
26+
27+
# Force redraw otherwise it triggers much later than end of script
28+
tcl.GiD_Redraw()
29+
30+
return "Done importing model"

0 commit comments

Comments
 (0)