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

fluidsimfoam-multi-region-snappy: tasks

parent a0161338
No related branches found
No related tags found
1 merge request!90fluidsimfoam-multi-region-snappy: tasks
Pipeline #68249 passed
SHELL := /bin/bash
test:
time pytest tests doc/examples
time pytest tests doc/examples -v
bench_parser:
time pytest tests/test_parser_saved_cases.py
......
from fluidsimfoam.tasks import clean, run
import subprocess
from pathlib import Path
from fluidsimfoam.tasks import clean, polymesh, run, task
@task
def split_mesh_regions(ctx):
ctx.run_appl("splitMeshRegions -cellZones -overwrite")
polymesh.pre.append(split_mesh_regions)
@task(polymesh)
def init_run(ctx):
process = subprocess.run(
"foamListRegions solid".split(), capture_output=True, text=True
)
regions_solid = process.stdout.split()
# Remove fluid fields from solid regions (important for post-processing)
for region in regions_solid:
bases = [Path("0")]
bases.extend(Path(".").glob("processor*/0"))
for base in bases:
for name in ["nut", "alphat", "epsilon", "k", "U", "p_rgh"]:
(base / region / name).unlink(missing_ok=True)
process = subprocess.run("foamListRegions", capture_output=True, text=True)
regions = process.stdout.split()
for region in regions:
ctx.run_appl(f"changeDictionary -region {region}", suffix_log=region)
......@@ -14,11 +14,11 @@
check_saved_case(here / "saved_cases/case0", sim.path_run)
# @skipif_executable_not_available("interFoam")
# 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
# ...
# sim = Simul(params)
# sim.make.exec("run")
@skipif_executable_not_available("interFoam")
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)
sim.make.exec("run")
......@@ -5,9 +5,10 @@
from subprocess import Popen
from time import sleep, time
import invoke.context
from invoke import task
from fluiddyn.util import time_as_str
from fluidsimfoam.foam_input_files import parse
......@@ -8,9 +9,28 @@
from invoke import task
from fluiddyn.util import time_as_str
from fluidsimfoam.foam_input_files import parse
class Context(invoke.context.Context):
time_as_str = time_as_str()
def run_appl(self, command, suffix_log=None):
name_log = f"log.{command.split()[0]}"
if suffix_log is not None:
name_log += suffix_log
path_log = Path(f"logs{self.time_as_str}/{name_log}")
path_log.parent.mkdir(exist_ok=True)
with open(path_log, "w") as file:
self.run(command, echo=True, out_stream=file, err_stream=file)
invoke.tasks.Context = Context
@task
def clean(context):
context.run("foamCleanTutorials", warn=True)
......@@ -22,6 +42,6 @@
Path("system/blockMeshDict").exists()
and not Path("constant/polyMesh").is_dir()
):
context.run("blockMesh")
context.run_appl("blockMesh")
......@@ -26,6 +46,18 @@
@task(block_mesh)
@task
def surface_feature_extract(context):
if Path("system/surfaceFeatureExtractDict").exists():
context.run_appl("surfaceFeatureExtract")
@task
def snappy_hex_mesh(context):
if Path("system/snappyHexMeshDict").exists():
context.run_appl("snappyHexMesh -overwrite")
@task(pre=[block_mesh, surface_feature_extract, snappy_hex_mesh])
def polymesh(context):
"""Create the polymesh directory"""
......@@ -40,7 +72,7 @@
context.run("setFields")
@task(polymesh, set_fields)
@task(pre=[polymesh, set_fields])
def run(context):
"""Main target to launch a simulation"""
with open("system/controlDict") as file:
......@@ -70,7 +102,7 @@
else:
command = application
path_log = path_run / f"log_{time_as_str()}.txt"
path_log = path_run / f"log_{context.time_as_str}.txt"
print(f"Starting simulation in \n{path_run}")
with open(path_log, "w") as file_log:
file_log.write(f"{start_time = }\n{end_time = }\n")
......
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