Skip to content

Commit

Permalink
add functionality for custom pkl file
Browse files Browse the repository at this point in the history
  • Loading branch information
MBueschelberger committed Sep 12, 2023
1 parent 76df6fb commit 095748b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions osp/models/catalytic/co_catalyticfoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion osp/wrappers/simcatalyticfoam/catalyticfoam_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions osp/wrappers/simcatalyticfoam/simcatalyticfoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 095748b

Please sign in to comment.