From 2fea19158fcd69b95334983c20872d32edab8fea Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Tue, 3 May 2022 11:13:27 +0200 Subject: [PATCH] Updated pickle with input output arguments --- olaflow/processing/pickle.py | 28 ++++++++++++++++++++-------- olaflow/run_ola.sh | 16 +++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/olaflow/processing/pickle.py b/olaflow/processing/pickle.py index e8a18ec..4a05cd9 100644 --- a/olaflow/processing/pickle.py +++ b/olaflow/processing/pickle.py @@ -1,6 +1,5 @@ import argparse import gzip -import configparser import logging import pathlib import pickle @@ -14,20 +13,29 @@ from .olaflow import OFModel parser = argparse.ArgumentParser(description="Post-process olaflow results") parser.add_argument("-v", "--verbose", action="count", default=0) -parser.add_argument("-c", "--config", default="config.ini") -parser.add_argument("-o", "--output", type=pathlib.Path) +parser.add_argument( + "-i", "--input", type=pathlib.Path, help="Olaflow output directory", required=True +) +parser.add_argument( + "-o", + "--output", + type=pathlib.Path, + help="Output directory for pickled data", + required=True, +) +parser.add_argument( + "-z", "--compress", action="store_true", help="Enable gzip compression" +) args = parser.parse_args() logging.basicConfig(level=max((10, 20 - 10 * args.verbose))) log = logging.getLogger("ola_post") log.info("Starting sws -> olaFlow converter") -config = configparser.ConfigParser() -config.read(args.config) -out = pathlib.Path(config.get("post", "out")) +out = args.output out.mkdir(parents=True, exist_ok=True) -olaflow_root = args.output +olaflow_root = args.input model = OFModel(olaflow_root) model.read_mesh() model.read_time() @@ -40,5 +48,9 @@ model.read_field_all("U") model.read_post("graphUniform", "alpha.water") -with gzip.open(out.joinpath("pickle.gz"), "wb") as f: +with ( + gzip.open(out.joinpath("pickle.gz"), "wb") + if args.compress + else out.joinpath("pickle").open("wb") +) as f: pickle.dump(model, f) diff --git a/olaflow/run_ola.sh b/olaflow/run_ola.sh index 8a10c8b..32d4c4a 100755 --- a/olaflow/run_ola.sh +++ b/olaflow/run_ola.sh @@ -1,10 +1,12 @@ #!/usr/bin/env sh echo START export inp="of" -read -p "Output: " out +read -p "Case: " out +export out_of="out_of_$out" +export out_post="out_post_$out" -cp -r --reflink $inp $out -pushd $out +cp -r --reflink $inp $out_of +pushd $out_of source /opt/OpenFOAM/OpenFOAM-9/etc/bashrc mkdir log echo Generating mesh @@ -17,10 +19,10 @@ setFields > log/setFields.log popd echo Converting swash output to initial condition -python -m processing.sws_ola -o $out +python -m processing.sws_ola -o $out_of echo Converting swash output to boundary condition -python -m processing.sws_wavedict_paddle -o $out -pushd $out +python -m processing.sws_wavedict_paddle -o $out_of +pushd $out_of echo Generating parallel cases decomposePar > log/decomposePar.log @@ -36,6 +38,6 @@ postProcess -func graphUniform > log/postProcess.log popd echo Pickling Olaflow output -python -m processing.pickle -o $out +python -m processing.pickle -i $out_of -o $out_post echo END