Skip to content

Commit

Permalink
Merge pull request #945 from KratosMultiphysics/migrate-geomechanics-…
Browse files Browse the repository at this point in the history
…to-geometries

Advances in Geomechanics write
  • Loading branch information
jginternational authored Sep 15, 2023
2 parents 7462bef + a3f5ab3 commit b2d81d9
Show file tree
Hide file tree
Showing 42 changed files with 1,003 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ dist

*.zip
*.tgz
null
null
__pycache__
8 changes: 4 additions & 4 deletions kratos.gid/apps/Common/xml/Parallelism.spd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<container n="ParallelType" pn="Parallel configuration" un="Parallelization" help="Parallel type" icon="parallel" open_window="1">
<value n="ParallelSolutionType" pn="Parallelization" un="ParallelType" v="OpenMP" values="OpenMP,MPI" help="Parallelization type" actualize="1" />
<value n="MPINumberOfProcessors" pn="Number of nodes" v="1" help="Number of processors" state="[checkStateByUniqueName ParallelType MPI]"/>
<value n="OpenMPNumberOfThreads" pn="Number of processors" v="1" help="Number of threads" state="[checkStateByUniqueName ParallelType OpenMP]"/>
</container>
<value n="ParallelSolutionType" pn="Parallelization" un="ParallelType" v="OpenMP" values="OpenMP,MPI" help="Parallelization type" actualize="1" />
<value n="MPINumberOfProcessors" pn="Number of nodes" v="1" help="Number of processors" state="[getStateFromXPathValue {string(../value[@n='ParallelSolutionType']/@v)} MPI]"/>
<value n="OpenMPNumberOfThreads" pn="Number of processors" v="1" help="Number of threads" state="[getStateFromXPathValue {string(../value[@n='ParallelSolutionType']/@v)} OpenMP]"/>
</container>
1 change: 1 addition & 0 deletions kratos.gid/apps/Examples/xml/examples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
<link path="apps/PfemThermic/examples/examples.xml"/>
<link path="apps/ShallowWater/examples/examples.xml"/>
<link path="apps/FreeSurface/examples/examples.xml"/>
<link path="apps/GeoMechanics/examples/examples.xml"/>
</examples>
45 changes: 45 additions & 0 deletions kratos.gid/apps/GeoMechanics/MainKratos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys
import time
import importlib

import KratosMultiphysics

def CreateAnalysisStageWithFlushInstance(cls, global_model, parameters):
class AnalysisStageWithFlush(cls):

def __init__(self, model,project_parameters, flush_frequency=10.0):
super().__init__(model,project_parameters)
self.flush_frequency = flush_frequency
self.last_flush = time.time()
sys.stdout.flush()

def Initialize(self):
super().Initialize()
sys.stdout.flush()

def FinalizeSolutionStep(self):
super().FinalizeSolutionStep()

if self.parallel_type == "OpenMP":
now = time.time()
if now - self.last_flush > self.flush_frequency:
sys.stdout.flush()
self.last_flush = now

return AnalysisStageWithFlush(global_model, parameters)

if __name__ == "__main__":

with open("ProjectParameters.json", 'r') as parameter_file:
parameters = KratosMultiphysics.Parameters(parameter_file.read())

analysis_stage_module_name = parameters["stages"]["Stage 1"]["analysis_stage"].GetString()
analysis_stage_class_name = analysis_stage_module_name.split('.')[-1]
analysis_stage_class_name = ''.join(x.title() for x in analysis_stage_class_name.split('_'))

analysis_stage_module = importlib.import_module(analysis_stage_module_name)
analysis_stage_class = getattr(analysis_stage_module, analysis_stage_class_name)

global_model = KratosMultiphysics.Model()
simulation = CreateAnalysisStageWithFlushInstance(analysis_stage_class, global_model, parameters)
simulation.Run()
16 changes: 10 additions & 6 deletions kratos.gid/apps/GeoMechanics/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"controllers/Toolbar.tcl",
"write/write.tcl",
"write/writeProjectParameters.tcl",
"controllers/Python.tcl"
"controllers/Python.tcl",
"controllers/PhreaticLine.tcl",
"examples/examples.tcl",
"examples/FirstExample.tcl"
],
"start_script": "::GeoMechanics::Init",
"requirements": {
Expand All @@ -43,11 +46,12 @@
"coordinates": "all",
"materials_file": "Materials.json",
"properties_location": "json",
"model_part_name": "ModelPart",
"model_part_name": "PorousDomain",
"output_model_part_name": "computational_model_part",
"multistage_write_mdpa_mode": "different_files",
"multistage_write_json_mode": "single_file"
"write_mdpa_mode": "geometries",
"multistage_write_json_mode": "single_file",
"multistage_write_mdpa_file_mode": "single_file"
},
"main_launch_file": "../../exec/MainKratos.py",
"main_launch_file": "MainKratos.py",
"description": ""
}
}
139 changes: 139 additions & 0 deletions kratos.gid/apps/GeoMechanics/controllers/PhreaticLine.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@

proc ::GeoMechanics::PhreaticButton { } {
variable curr_stage
variable state_phreatic_line

# Get the current active stage
set stages [::GeoMechanics::xml::GetStages]
set stage [lindex $stages $curr_stage]

# If the state is none, the user clicked because he wants to create a phreatic line
if {$state_phreatic_line eq "none"} {

# Get the current stage phreatic points
set current_phreatic_points [::GeoMechanics::xml::GetPhreaticPoints $stage]
# If there are no phreatic points, create a new line
if {[llength $current_phreatic_points] eq 0} {
set state_phreatic_line creating
::GeoMechanics::CreatePhreaticLine $stage
} else {
# If there are phreatic points, display it somehow
::GeoMechanics::DisplayPhreaticLine
}
} elseif {$state_phreatic_line in [list "creating" "displaying"]} {
::GeoMechanics::EndCreatePhreaticLine
}
}

proc ::GeoMechanics::DeletePhreaticButton { } {
variable curr_stage

# Get the current active stage
set stages [::GeoMechanics::xml::GetStages]
set stage [lindex $stages $curr_stage]

::GeoMechanics::xml::DeletePhreaticPoints $stage
::GeoMechanics::EndCreatePhreaticLine
}

proc ::GeoMechanics::CreatePhreaticLine {stage} {
variable state_phreatic_line
variable creating_phreatic_previous_layer
set creating_phreatic_previous_layer [GiD_Layers get to_use]
set stage_name [$stage @name]
if {[GiD_Layers exists PhreaticLine_$stage_name]} {
GiD_Layers delete PhreaticLine_$stage_name
}
GiD_Layers create PhreaticLine_$stage_name
GiD_Layers edit to_use PhreaticLine_$stage_name
GiD_RegisterEvent GiD_Event_AfterCreateLine ::GeoMechanics::AfterCreatePhreaticLine PROBLEMTYPE Kratos
GiD_Process MEscape Mescape Geometry Create Line
}

proc ::GeoMechanics::AfterCreatePhreaticLine { line } {
variable curr_stage
variable state_phreatic_line
if {$state_phreatic_line eq "creating"} {

# Get the current active stage
set stages [::GeoMechanics::xml::GetStages]
set stage [lindex $stages $curr_stage]

# Get line points
lassign [GiD_Geometry get line $line] a b p1 p2
# Get point coordinates
lassign [GiD_Geometry get point $p1] a x1 y1 z1
lassign [GiD_Geometry get point $p2] a x2 y2 z2
# Add coordinates to xml
if {[llength [::GeoMechanics::xml::GetPhreaticPoints $stage]] == 0} {
::GeoMechanics::xml::AddPhreaticPoint $stage $x1 $y1 $z1
}
::GeoMechanics::xml::AddPhreaticPoint $stage $x2 $y2 $z2
} else {

}

# TODO: at this moment we only allow 2 points, in the future, will see
set num [llength [::GeoMechanics::xml::GetPhreaticPoints $stage]]
if {$num >= 2} {
::GeoMechanics::EndCreatePhreaticLine
::GeoMechanics::DisplayPhreaticLine
}
}
proc ::GeoMechanics::EndCreatePhreaticLine { } {
variable state_phreatic_line
set state_phreatic_line none

# Delete the phreatic line
::GeoMechanics::DeleteVisiblePhreaticLine

# Delete the lines from the variable list
variable creating_phreatic_previous_layer
GiD_Layers edit to_use $creating_phreatic_previous_layer
catch {GiD_UnRegisterEvent GiD_Event_AfterCreateLine ::GeoMechanics::AfterCreatePhreaticLine PROBLEMTYPE Kratos}
spdAux::RequestRefresh
}

proc ::GeoMechanics::DeleteVisiblePhreaticLine { } {
variable curr_stage

# Get the current active stage
set stages [::GeoMechanics::xml::GetStages]
set stage [lindex $stages $curr_stage]

set stage_name [$stage @name]
# Delete the lines from the variable list
if {[GiD_Layers exists PhreaticLine_$stage_name]} {GiD_Layers delete PhreaticLine_$stage_name}
GiD_Process MEscape 'Redraw escape
}

proc ::GeoMechanics::DisplayPhreaticLine {} {
variable state_phreatic_line
set state_phreatic_line displaying

# Get the current active stage
variable curr_stage
set stages [::GeoMechanics::xml::GetStages]
set stage [lindex $stages $curr_stage]

set stage_name [$stage @name]
set layer_name PhreaticLine_$stage_name
if {[GiD_Layers exists $layer_name]} {
GiD_Layers delete $layer_name
}
GiD_Layers create $layer_name
# GiD_Layers edit to_use $layer_name
set current_phreatic_points [::GeoMechanics::xml::GetPhreaticPoints $stage]
set point_list [list ]
foreach point $current_phreatic_points {
lassign $point x y
lappend point_list [GiD_Geometry -v2 create point append $layer_name $x $y 0.0]
}
# set coordinates ""
set ini [lindex $point_list 0]
foreach end [lrange $point_list 1 end] {
GiD_Geometry -v2 create line append stline $layer_name $ini $end
set ini $end
}
GiD_Process MEscape 'Redraw escape
}
10 changes: 10 additions & 0 deletions kratos.gid/apps/GeoMechanics/controllers/Python.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@ proc ::GeoMechanics::PythonButton { } {
GiD_Python_Source [file join $::GeoMechanics::dir controllers geomechanics_script.py]
set result_python [GiD_Python_Call geomechanics_script.my_python_procedure $param1]
W $result_python
}

proc ::GeoMechanics::PythonButtonImportPlaxis { } {
set directory [MessageBoxGetFilename directory read [_ "Select Plaxis model to import"]]
if {$directory == ""} {
return
}
GiD_Python_Source [file join $::GeoMechanics::dir controllers geomechanics_import_plaxis.py]
set result_python [GiD_Python_Call geomechanics_import_plaxis.import_plaxis_procedure $directory]
W $result_python
}
26 changes: 26 additions & 0 deletions kratos.gid/apps/GeoMechanics/controllers/SplashWindow.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Create the main window
set mainWindow .gid.maingui
toplevel $mainWindow
wm title $mainWindow "Two Sections Window"
wm geometry $mainWindow 400x200

# Create the first section with two big square buttons
frame $mainWindow.section1 -background white
button $mainWindow.section1.button1 -text "Button 1" -width 10 -height 10
button $mainWindow.section1.button2 -text "Button 2" -width 10 -height 10
grid $mainWindow.section1.button1 -row 0 -column 0 -padx 20 -pady 20
grid $mainWindow.section1.button2 -row 0 -column 1 -padx 20 -pady 20

# Create the second section with text and a small button
frame $mainWindow.section2 -background white
text $mainWindow.section2.text -width 30 -height 5
button $mainWindow.section2.button -text "Small Button" -width 10
grid $mainWindow.section2.text -row 0 -column 0 -padx 20 -pady 20
grid $mainWindow.section2.button -row 1 -column 0 -padx 20 -pady 10

# Place the sections in the main window
grid $mainWindow.section1 -row 0 -column 0 -sticky news
grid $mainWindow.section2 -row 0 -column 1 -sticky news

# Start the event loop
tkwait window $mainWindow
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import tohil

# To create functions and variables for all tcl available ones
tcl=tohil.import_tcl()


def import_plaxis_procedure(directory):

tcl.W(f"Importing Plaxi model from: {directory}")

# Print evertying that is known by the tcl object
# object_info = tcl.__dict__
# for object_function in object_info:
# tcl.W(object_function)

tcl.W("Found files to import")
for filename in os.listdir(directory):
file = os.path.join(directory, filename)
tcl.W(file)

p1 = tcl.GiD_Geometry("create", "point", "append", "Layer0", "-8.87755","3.26531","0")
tcl.W(p1)
p2 = tcl.GiD_Geometry("create", "point", "append", "Layer0", "4.95465","3.44671","0")
result = tcl.GiD_Geometry("create", "line", "append", "stline", "Layer0", p1, p2)

# Force redraw otherwise it triggers much later than end of script
tcl.GiD_Redraw()

return "Done importing model"
Loading

0 comments on commit b2d81d9

Please sign in to comment.