diff --git a/osp/models/catalytic/co_catalyticfoam.py b/osp/models/catalytic/co_catalyticfoam.py index 184794f..8a5b6c3 100755 --- a/osp/models/catalytic/co_catalyticfoam.py +++ b/osp/models/catalytic/co_catalyticfoam.py @@ -248,6 +248,9 @@ def __post_init_post_parse__(self): calc.add(self._make_species(species), rel=emmo.hasCalculationInput) calc.add(self._make_continuum_model(), rel=emmo.hasCalculationInput) calc.add(self._make_catalyist_amount(), rel=emmo.hasCalculationInput) + if self.species_from_upload: + pkl = emmo.PKLFile(uid=self.species_from_upload) + calc.add(pkl, rel=emmo.hasCalculationInput) file = tempfile.NamedTemporaryFile(suffix=".ttl") export_cuds(session, file.name) self._uuid = get_upload(file) diff --git a/osp/wrappers/simcatalyticfoam/catalyticfoam_engine.py b/osp/wrappers/simcatalyticfoam/catalyticfoam_engine.py index bd11e1d..e3ee02b 100755 --- a/osp/wrappers/simcatalyticfoam/catalyticfoam_engine.py +++ b/osp/wrappers/simcatalyticfoam/catalyticfoam_engine.py @@ -3,7 +3,7 @@ import shutil import subprocess # nosec import tempfile -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Optional import osp.dictionaries.catalyticFoam as case @@ -37,6 +37,7 @@ def __init__(self, case: str, config: dict = {}): directory=runtime, filename=tar, ) + self._pkl: Optional[str] = None self._parse_files = dict() self._config: dict = config self._current_process: subprocess.Popen = None @@ -66,6 +67,12 @@ def run(self) -> None: with open(path, "w+") as file: file_content = serialize(content) file.write(file_content) + if self._pkl: + logger.info("Will use custom PKL for catalytic wall: `%s`", self._pkl) + dest_pkl = os.path.join( + self._config["directory"], "ml_ExtraTrees_forCFD.pkl" + ) + shutil.copy(self._pkl, dest_pkl) for command in self._config["commands"]: cmd = self._prepare_command(command) logger.info( @@ -221,3 +228,7 @@ def exit_code(cls): @property def tarball(cls): return f"{cls._config['filename']}.tar" + + @property + def pkl(cls): + return cls._pkl diff --git a/osp/wrappers/simcatalyticfoam/simcatalyticfoam.py b/osp/wrappers/simcatalyticfoam/simcatalyticfoam.py index 145c573..792072e 100755 --- a/osp/wrappers/simcatalyticfoam/simcatalyticfoam.py +++ b/osp/wrappers/simcatalyticfoam/simcatalyticfoam.py @@ -5,6 +5,7 @@ from osp.core.namespaces import emmo from osp.core.session import SimWrapperSession from osp.models.catalytic.utils import check_arcp, wrap_arcp +from osp.models.utils.general import get_download from .catalyticfoam_engine import CatalyticFoamEngine, settings @@ -68,6 +69,8 @@ def _wrap(self, cuds: "Cuds") -> None: self._check_for_value(cuds) elif cuds.is_a(emmo.AdjustableSimulationTimeStep): self._wrap_arcp(cuds, "yes") + elif cuds.is_a(emmo.PKLFile): + self._engine.pkl = get_download(str(cuds.uid), as_file=True) def _make_new_chemical(self, composition: "Cuds") -> None: species = composition.get(oclass=emmo.ChemicalSpecies)