Skip to content

Commit 900a7c2

Browse files
Merge pull request #870 from KratosMultiphysics/enable-docker-run
Enable docker run
2 parents 725c35d + 55b7556 commit 900a7c2

13 files changed

Lines changed: 124 additions & 22 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ https://www.youtube.com/watch?v=zZq7ypDdudo
2727
In Kratos preferences, select the execution mode:
2828
* Pip packages: Kratos will be installed via `pip install`
2929
* local compiled: If you are a developer and build your applications, use this one
30+
* docker: If you do not want to install any dependency, just run via docker!
31+
* The default image is [fjgarate/kratos-run](https://hub.docker.com/repository/docker/fjgarate/kratos-run)
3032

3133
## Usage
3234
* Run GiD

dockers/dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM python:3.9
2+
3+
RUN pip install KratosMultiphysics-all numpy
4+
WORKDIR "/model"
5+
ENTRYPOINT [ "python3", "MainKratos.py" ]
6+
7+
# docker build --tag="kratos-run:latest" -t kratos-run .
8+
# docker tag kratos-run:latest fjgarate/kratos-run:latest
9+
# docker push fjgarate/kratos-run:0.0.1

kratos.gid/exec/docker.unix.bat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# OutputFile: "$2/$1.info"
3+
# ErrorFile: "$2/$1.err"
4+
#delete previous result file
5+
rm -f "$2/$1*.post.bin"
6+
rm -f "$2/$1*.post.res"
7+
rm -f "$2/$1*.post.msh"
8+
rm -f "$2/$1.info"
9+
rm -f "$2/$1.err"
10+
rm -f "$2/$1.flavia.dat"
11+
12+
# Run Python using the script MainKratos.py
13+
docker run -v "$2:/model" --rm --name "$1" $kratos_docker_image > "$2/$1.info" 2> "$2/$1.err"
14+
# docker run -v "%2:/model" --rm --name "%1" %kratos_docker_image% > "%2\\%1.info" 2> "%2\\%1.err"

kratos.gid/exec/docker.win.bat

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
REM @ECHO OFF
2+
REM Identification for arguments
3+
REM basename = %1
4+
REM Project directory = %2
5+
REM Problem directory = %3
6+
7+
REM OutputFile: "%2\%1.info"
8+
REM ErrorFile: "%2\%1.err"
9+
10+
REM Remove previous calculation files and results
11+
DEL "%2\%1.info"
12+
DEL "%2\%1.err"
13+
DEL "%2\%1*.post.bin"
14+
DEL "%2\%1*.post.res"
15+
DEL "%2\%1*.post.msh"
16+
17+
@REM Calculate!
18+
docker run -v "%2:/model" --rm --name "%1" %kratos_docker_image% > "%2\\%1.info" 2> "%2\\%1.err"

kratos.gid/exec/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
{
2121
"name": "Docker",
22-
"script": "",
22+
"script": "docker",
2323
"dependency_check": "Kratos::CheckDependenciesDockerMode"
2424
}
2525
]

kratos.gid/exec/pip.unix.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ rm -f "$2/$1.err"
1010
rm -f "$2/$1.flavia.dat"
1111

1212
# Run Python using the script MainKratos.py
13-
python3 MainKratos.py > "$2/$1.info" 2> "$2/$1.err"
13+
$kratos_python_exe MainKratos.py > "$2/$1.info" 2> "$2/$1.err"

kratos.gid/exec/pip.win.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ DEL "%2\%1*.post.res"
1515
DEL "%2\%1*.post.msh"
1616

1717
@REM Calculate!
18-
python MainKratos.py > "%2\\%1.info" 2> "%2\\%1.err"
18+
%kratos_python_exe% MainKratos.py > "%2\\%1.info" 2> "%2\\%1.err"

kratos.gid/kratos.tcl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ proc Kratos::RegisterGiDEvents { } {
6969
GiD_RegisterEvent GiD_Event_SelectGIDBatFile Kratos::Event_SelectGIDBatFile PROBLEMTYPE Kratos
7070

7171
# Postprocess
72+
GiD_RegisterEvent GiD_Event_BeforeInitGIDPostProcess Kratos::BeforeInitGIDPostProcess PROBLEMTYPE Kratos
7273
GiD_RegisterEvent GiD_Event_InitGIDPostProcess Kratos::Event_InitGIDPostProcess PROBLEMTYPE Kratos
7374
GiD_RegisterEvent GiD_Event_EndGIDPostProcess Kratos::Event_EndGIDPostProcess PROBLEMTYPE Kratos
7475

@@ -475,6 +476,19 @@ proc Kratos::Event_InitGIDPostProcess {} {
475476
gid_groups_conds::open_post check_default
476477
}
477478

479+
proc Kratos::BeforeInitGIDPostProcess {} {
480+
# In docker run, rename lst file
481+
if {[info exists Kratos::kratos_private(launch_configuration)]} {
482+
set launch_mode $Kratos::kratos_private(launch_configuration)
483+
if {$launch_mode eq "Docker"} {
484+
set list_file [file join [GidUtils::GetDirectoryModel] model.post.lst]
485+
if {[file exists $list_file]} {
486+
file copy -force $list_file [GidUtils::GetFilenameInsideProject [file rootname [GidUtils::GetDirectoryModel]] .post.lst]
487+
}
488+
}
489+
}
490+
}
491+
478492
proc Kratos::Event_EndGIDPostProcess {} {
479493
# Close all postprocess windows
480494
gid_groups_conds::close_all_windows

kratos.gid/scripts/Controllers/Preferences.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
<option value='2' label='2'/>
2020
</combobox>
2121
<entrywithbutton name="debug_folder" label="Debug path" variable="debug_folder" buttonimage="folder.png" variablemanager='Kratos::ManagePreferences' buttonfunction="OpenBrowserForDirectory" help='Path to the kratos debug folder. This is placed in the launch.json file for debugging' />
22-
<combobox name="launch_configuration" label="Launch configuration" variable="launch_configuration" variablemanager='Kratos::ManagePreferences' help='' >
23-
<option value='Launch via pip' label='Launch via pip'/>
24-
<!-- <option value='Launch via pip with local packages' label='Launch via pip with local packages'/> -->
25-
<option value='Launch local compiled version' label='Launch local compiled version'/>
26-
<!-- <option value='Docker' label='Docker'/> -->
27-
<!-- <option value='Custom...' label='Custom...'/> -->
28-
</combobox>
22+
<comboboxframe name="launch_configuration" label="Launch configuration" variable="launch_configuration" variablemanager='Kratos::ManagePreferences' help='' >
23+
<option value='Launch via pip' label='Launch via pip' setactivate="python_path"/>
24+
<option value='Launch local compiled version' label='Launch local compiled version (kratos.gid/exec/Kratos/runkratos)'/>
25+
<option value='Docker' label='Docker' setactivate="docker_image" />
26+
27+
<entrywithbutton name="python_path" variable="python_path" label="Python path (exe)" variablemanager='Kratos::ManagePreferences' help='Path to python.exe' buttonimage="folder.png" buttonfunction="GetPythonPath"/>
28+
<entry name="docker_image" variable="docker_image" label="Docker image" variablemanager='Kratos::ManagePreferences' help='Name of the Kratos Docker image'/>
29+
</comboboxframe>
2930
</labelframe>
3031
</group>
3132

kratos.gid/scripts/Controllers/PreferencesWindow.tcl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ proc Kratos::ManagePreferences { cmd name {value ""}} {
3535
"launch_configuration" {
3636
set ret "local"
3737
}
38+
"docker_image" {
39+
set ret "fjgarate/kratos-run"
40+
}
41+
"python_path" {
42+
set ret [file join [Kratos::GetDefaultPythonPath] [Kratos::GetPythonExeName] ]
43+
}
44+
default {
45+
set ret 0
46+
}
3847
}
3948
}
4049
}

0 commit comments

Comments
 (0)