Skip to content
Snippets Groups Projects
Commit ba18e488 authored by Pierre Augier's avatar Pierre Augier
Browse files

fluidsimfoam-multi-region-snappy run in sequential

parent 307cb321
No related branches found
No related tags found
1 merge request!90fluidsimfoam-multi-region-snappy: tasks
Pipeline #68270 passed
......@@ -6,7 +6,9 @@
@task
def split_mesh_regions(ctx):
ctx.run_appl("splitMeshRegions -cellZones -overwrite")
ctx.run_appl_once(
"splitMeshRegions -cellZones -overwrite", check_dict_file=False
)
polymesh.pre.append(split_mesh_regions)
......@@ -31,4 +33,11 @@
regions = process.stdout.split()
for region in regions:
ctx.run_appl(f"changeDictionary -region {region}", suffix_log=region)
ctx.run_appl_once(
f"changeDictionary -region {region}",
suffix_log=region,
check_dict_file=False,
)
run.pre = [polymesh, init_run]
......@@ -14,10 +14,10 @@
check_saved_case(here / "saved_cases/case0", sim.path_run)
@skipif_executable_not_available("interFoam")
@skipif_executable_not_available("chtMultiRegionFoam")
def test_run():
params = Simul.create_default_params()
params.output.sub_directory = "tests_fluidsimfoam/multi-region-snappy"
# change parameters to get a very short and small simulations
params.control_dict.end_time = 0.002
sim = Simul(params)
......@@ -18,7 +18,9 @@
def test_run():
params = Simul.create_default_params()
params.output.sub_directory = "tests_fluidsimfoam/multi-region-snappy"
# change parameters to get a very short and small simulations
params.control_dict.end_time = 0.002
sim = Simul(params)
# for now we remove decomposeParDict to run in sequential
(sim.path_run / "system/decomposeParDict").unlink()
sim.make.exec("run")
......@@ -24,1 +26,2 @@
sim.make.exec("run")
sim.make.exec("clean")
"""Invoke tasks to be used from the ``tasks.py`` file in the solvers"""
import hashlib
import re
from pathlib import Path
from subprocess import Popen
......@@ -7,8 +8,9 @@
import invoke.context
from invoke import task
from invoke.exceptions import Exit
from fluiddyn.util import time_as_str
from fluidsimfoam.foam_input_files import parse
......@@ -10,8 +12,13 @@
from fluiddyn.util import time_as_str
from fluidsimfoam.foam_input_files import parse
def make_hex(src):
"""Produce a hash from a string"""
return hashlib.md5(src.encode("utf8")).hexdigest()
class Context(invoke.context.Context):
time_as_str = time_as_str()
......@@ -27,6 +34,34 @@
with open(path_log, "w") as file:
self.run(command, echo=True, out_stream=file, err_stream=file)
def run_appl_once(
self,
command,
suffix_log=None,
dict_file=None,
check_dict_file=True,
force=False,
):
command_name = command.split()[0]
if check_dict_file and not force:
if dict_file is None:
dict_file = "system/" + command_name + "Dict"
path_dict_file = Path(dict_file)
if not path_dict_file.exists():
return
lock_name = f"{command_name}_called"
if command_name != command:
lock_name += make_hex(command)
path_command_called = Path(f".data_fluidsim/{lock_name}")
path_command_called.parent.mkdir(exist_ok=True)
if force or not path_command_called.exists():
path_command_called.touch()
self.run_appl(command, suffix_log=suffix_log)
invoke.tasks.Context = Context
......@@ -34,7 +69,9 @@
@task
def clean(context):
context.run("foamCleanTutorials", warn=True)
for path in Path(".").glob(".data_fluidsim/*_called*"):
path.unlink()
@task
def block_mesh(context):
......@@ -37,13 +74,9 @@
@task
def block_mesh(context):
if (
Path("system/blockMeshDict").exists()
and not Path("constant/polyMesh").is_dir()
):
context.run_appl("blockMesh")
context.run_appl_once("blockMesh")
@task
def surface_feature_extract(context):
......@@ -46,10 +79,9 @@
@task
def surface_feature_extract(context):
if Path("system/surfaceFeatureExtractDict").exists():
context.run_appl("surfaceFeatureExtract")
context.run_appl_once("surfaceFeatureExtract")
@task
def snappy_hex_mesh(context):
......@@ -52,9 +84,8 @@
@task
def snappy_hex_mesh(context):
if Path("system/snappyHexMeshDict").exists():
context.run_appl("snappyHexMesh -overwrite")
context.run_appl_once("snappyHexMesh -overwrite")
@task(pre=[block_mesh, surface_feature_extract, snappy_hex_mesh])
......@@ -64,12 +95,7 @@
@task
def set_fields(context, force=False):
if Path("system/setFieldsDict").exists():
path_setFields_called = Path(".data_fluidsim/setFields_called")
path_setFields_called.parent.mkdir(exist_ok=True)
if force or not path_setFields_called.exists():
path_setFields_called.touch()
context.run("setFields")
context.run_appl_once("setFields")
@task(pre=[polymesh, set_fields])
......@@ -132,3 +158,5 @@
)
print(f"Simulation done. path_run:\n{path_run}")
if process.returncode:
Exit(process.returncode)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment