Skip to content

Commit 1c6e2ac

Browse files
committed
Script to start/stop fluent for CI run
1 parent 03fffb0 commit 1c6e2ac

File tree

8 files changed

+96
-80
lines changed

8 files changed

+96
-80
lines changed

.ci/start_fluent.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import subprocess
3+
import sys
4+
import tempfile
5+
import time
6+
7+
from ansys.fluent.core import EXAMPLES_PATH
8+
9+
10+
def start_fluent_container(args):
11+
fd, sifile = tempfile.mkstemp(
12+
suffix=".txt", prefix="serverinfo-", dir=EXAMPLES_PATH
13+
)
14+
os.close(fd)
15+
timeout = 100
16+
license_server = os.environ["ANSYSLMD_LICENSE_FILE"]
17+
port = os.environ["PYFLUENT_FLUENT_PORT"]
18+
19+
subprocess.run(["docker", "run", "--name", "fluent_server", "-d", "--rm",
20+
"-p", f"{port}:{port}",
21+
"-v", f"{EXAMPLES_PATH}:{EXAMPLES_PATH}",
22+
"-e", f"ANSYSLMD_LICENSE_FILE={license_server}",
23+
"-e", f"REMOTING_PORTS={port}/portspan=2",
24+
"-e", "FLUENT_LAUNCHED_FROM_PYFLUENT=1",
25+
"ghcr.io/pyansys/pyfluent",
26+
"-g", f"-sifile={sifile}"] + args)
27+
28+
sifile_last_mtime = os.stat(sifile).st_mtime
29+
while True:
30+
if os.stat(sifile).st_mtime > sifile_last_mtime:
31+
time.sleep(1)
32+
break
33+
if timeout == 0:
34+
break
35+
time.sleep(1)
36+
timeout -= 1
37+
if os.path.exists(sifile):
38+
os.remove(sifile)
39+
40+
41+
if __name__ == "__main__":
42+
start_fluent_container(sys.argv[1:])

.ci/stop_fluent.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import subprocess
2+
3+
4+
def stop_fluent_container():
5+
subprocess.run(["docker", "stop", "fluent_server"])
6+
7+
8+
if __name__ == "__main__":
9+
stop_fluent_container()

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ jobs:
140140
touch doc/_build/html/.nojekyll
141141
echo "fluentdocs.pyansys.com" >> doc/_build/html/CNAME
142142
env:
143-
LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
144-
PYFLUENT_RUN_EXAMPLES_WITH_DOCKER: "1"
143+
ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER) }}
144+
PYFLUENT_FLUENT_PORT: 63084
145145

146146
- name: Upload HTML Documentation
147147
uses: actions/upload-artifact@v2

doc/source/conf.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""Sphinx documentation configuration file."""
22
from datetime import datetime
3+
import os
4+
import subprocess
5+
import sys
36

47
from pyansys_sphinx_theme import pyansys_logo_black
58
from sphinx_gallery.sorting import FileNameSortKey
@@ -93,6 +96,25 @@
9396
copybutton_prompt_is_regexp = True
9497

9598

99+
_THIS_DIR = os.path.dirname(__file__)
100+
_START_FLUENT_FILE = os.path.normpath(
101+
os.path.join(_THIS_DIR, "..", "..", ".ci", "start_fluent.py")
102+
)
103+
_STOP_FLUENT_FILE = os.path.normpath(
104+
os.path.join(_THIS_DIR, "..", "..", ".ci", "stop_fluent.py")
105+
)
106+
107+
108+
def _start_or_stop_fluent_container(gallery_conf, fname, when):
109+
if when == "before":
110+
if fname in ["mixing_elbow_settings_api.py",
111+
"mixing_elbow_tui_api.py"]:
112+
args = ["3ddp", "-t4", "-meshing"]
113+
subprocess.run([sys.executable, _START_FLUENT_FILE] + args)
114+
elif when == "after":
115+
subprocess.run([sys.executable, _STOP_FLUENT_FILE])
116+
117+
96118
# -- Sphinx Gallery Options ---------------------------------------------------
97119
sphinx_gallery_conf = {
98120
# convert rst to md for ipynb
@@ -113,6 +135,8 @@
113135
"doc_module": "ansys-fluent-core",
114136
"ignore_pattern": "flycheck*",
115137
"thumbnail_size": (350, 350),
138+
'reset_modules_order': 'both',
139+
'reset_modules': (_start_or_stop_fluent_container),
116140
}
117141

118142

-518 KB
Binary file not shown.
-90.8 KB
Binary file not shown.

examples/00-fluent/mixing_elbow_settings_api.py

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,16 @@
3939

4040
###############################################################################
4141

42-
# First, start Fluent as a service with Meshing Mode, Double Precision, Number
43-
# of Processors 4
44-
import os
45-
import subprocess
46-
from time import sleep
42+
# First, connect with a Fluent server
4743

4844
import ansys.fluent.core as pyfluent
4945
from ansys.fluent.core import examples
5046

51-
with_docker = "PYFLUENT_RUN_EXAMPLES_WITH_DOCKER" in os.environ
5247

53-
if with_docker:
54-
examples.download_file("mixing_elbow.pmdb", "pyfluent/mixing_elbow")
55-
examples.download_file("mixing_elbow.scdoc", "pyfluent/mixing_elbow")
56-
57-
license_server = os.getenv("LICENSE_SERVER", "leblnxlic64.ansys.com")
58-
subprocess.run(["docker", "run", "-d", "--rm", "-p", "63074:63074",
59-
"-v", f"{pyfluent.EXAMPLES_PATH}:/examples",
60-
"-e", f"ANSYSLMD_LICENSE_FILE=1055@{license_server}",
61-
"-e", "REMOTING_PORTS=63074/portspan=2",
62-
"-e", "FLUENT_LAUNCHED_FROM_PYFLUENT=1",
63-
"ghcr.io/pyansys/pyfluent",
64-
"3ddp", "-t4", "-meshing", "-g", "-sifile=server.txt"])
65-
sleep(60)
66-
67-
s = pyfluent.launch_fluent(
68-
start_instance=False, ip="localhost", port=63074
69-
)
70-
else:
71-
s = pyfluent.launch_fluent(
72-
meshing_mode=True, precision="double", processor_count="4"
73-
)
48+
import_filename = examples.download_file(
49+
"mixing_elbow.pmdb", "pyfluent/mixing_elbow"
50+
)
51+
s = pyfluent.launch_fluent(start_instance=False)
7452

7553
###############################################################################
7654

@@ -83,12 +61,8 @@
8361
# Import the CAD geometry. For Length Units, select "in".
8462
# Execute the Import Geometry task.
8563

86-
if "PYFLUENT_RUN_EXAMPLES_WITH_DOCKER" in os.environ:
87-
filename = "/examples/mixing_elbow.pmdb"
88-
else:
89-
filename = "mixing_elbow.pmdb"
9064
s.workflow.TaskObject["Import Geometry"].Arguments = dict(
91-
FileName=filename, LengthUnit="in"
65+
FileName=import_filename, LengthUnit="in"
9266
)
9367

9468
s.workflow.TaskObject["Import Geometry"].Execute()
@@ -467,8 +441,7 @@
467441
root.results.graphics.contour["contour-vel"].surfaces_list = [
468442
"symmetry-xyplane"
469443
]
470-
if not with_docker:
471-
root.results.graphics.contour["contour-vel"].display()
444+
# root.results.graphics.contour["contour-vel"].display()
472445

473446
###############################################################################
474447

@@ -483,8 +456,7 @@
483456
root.results.graphics.contour["contour-temp"].surfaces_list = [
484457
"symmetry-xyplane"
485458
]
486-
if not with_docker:
487-
root.results.graphics.contour["contour-temp"].display()
459+
# root.results.graphics.contour["contour-temp"].display()
488460

489461
###############################################################################
490462

@@ -498,8 +470,7 @@
498470
root.results.graphics.vector["vector-vel"].surfaces_list = ["symmetry-xyplane"]
499471
root.results.graphics.vector["vector-vel"].scale.scale_f = 4
500472
root.results.graphics.vector["vector-vel"].style = "arrow"
501-
if not with_docker:
502-
root.results.graphics.vector["vector-vel"].display()
473+
# root.results.graphics.vector["vector-vel"].display()
503474

504475
###############################################################################
505476

@@ -516,8 +487,7 @@
516487
root.results.graphics.contour["contour-z_0_outlet"].surfaces_list = [
517488
"z=0_outlet"
518489
]
519-
if not with_docker:
520-
root.results.graphics.contour["contour-z_0_outlet"].display()
490+
# root.results.graphics.contour["contour-z_0_outlet"].display()
521491

522492
###############################################################################
523493
# s.tui.solver.file.write_case_data("mixing_elbow1_set.cas.h5").result()

examples/00-fluent/mixing_elbow_tui_api.py

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,16 @@
3838

3939
###############################################################################
4040

41-
# First, start Fluent as a service with Meshing Mode, Double Precision, Number
42-
# of Processors 4
43-
import os
44-
import subprocess
45-
from time import sleep
41+
# First, connect with a Fluent server
4642

4743
import ansys.fluent.core as pyfluent
4844
from ansys.fluent.core import examples
4945

50-
with_docker = "PYFLUENT_RUN_EXAMPLES_WITH_DOCKER" in os.environ
5146

52-
if with_docker:
53-
examples.download_file("mixing_elbow.pmdb", "pyfluent/mixing_elbow")
54-
examples.download_file("mixing_elbow.scdoc", "pyfluent/mixing_elbow")
55-
56-
license_server = os.getenv("LICENSE_SERVER", "leblnxlic64.ansys.com")
57-
subprocess.run(["docker", "run", "-d", "--rm", "-p", "63084:63084",
58-
"-v", f"{pyfluent.EXAMPLES_PATH}:/examples",
59-
"-e", f"ANSYSLMD_LICENSE_FILE=1055@{license_server}",
60-
"-e", "REMOTING_PORTS=63084/portspan=2",
61-
"-e", "FLUENT_LAUNCHED_FROM_PYFLUENT=1",
62-
"ghcr.io/pyansys/pyfluent",
63-
"3ddp", "-t4", "-meshing", "-g", "-sifile=server.txt"])
64-
sleep(60)
65-
66-
s = pyfluent.launch_fluent(
67-
start_instance=False, ip="localhost", port=63084
68-
)
69-
else:
70-
s = pyfluent.launch_fluent(
71-
meshing_mode=True, precision="double", processor_count="4"
72-
)
47+
import_filename = examples.download_file(
48+
"mixing_elbow.pmdb", "pyfluent/mixing_elbow"
49+
)
50+
s = pyfluent.launch_fluent(start_instance=False)
7351

7452
###############################################################################
7553

@@ -82,12 +60,8 @@
8260
# Import the CAD geometry. For Length Units, select "in".
8361
# Execute the Import Geometry task.
8462

85-
if "PYFLUENT_RUN_EXAMPLES_WITH_DOCKER" in os.environ:
86-
filename = "/examples/mixing_elbow.pmdb"
87-
else:
88-
filename = "mixing_elbow.pmdb"
8963
s.workflow.TaskObject["Import Geometry"].Arguments = dict(
90-
FileName=filename, LengthUnit="in"
64+
FileName=import_filename, LengthUnit="in"
9165
)
9266

9367
s.workflow.TaskObject["Import Geometry"].Execute()
@@ -461,8 +435,7 @@
461435
"banded",
462436
"quit",
463437
).result()
464-
if not with_docker:
465-
s.tui.solver.display.objects.display("contour-vel").result()
438+
# s.tui.solver.display.objects.display("contour-vel").result()
466439

467440
###############################################################################
468441

@@ -487,8 +460,7 @@
487460
"smooth",
488461
"quit",
489462
)
490-
if not with_docker:
491-
s.tui.solver.display.objects.display("contour-temp").result()
463+
# s.tui.solver.display.objects.display("contour-temp").result()
492464

493465
###############################################################################
494466

@@ -513,8 +485,7 @@
513485
"2",
514486
"quit",
515487
).result()
516-
if not with_docker:
517-
s.tui.solver.display.objects.display("vector-vel").result()
488+
# s.tui.solver.display.objects.display("vector-vel").result()
518489

519490
###############################################################################
520491

0 commit comments

Comments
 (0)