1
Fork 0
internship/olaflow/processing/pickle.py

60 lines
1.4 KiB
Python
Raw Normal View History

2022-04-13 14:08:55 +02:00
import argparse
2022-04-14 12:37:42 +02:00
import gzip
2022-04-13 14:08:55 +02:00
import logging
import pathlib
import pickle
2022-04-14 12:37:42 +02:00
from time import time
2022-04-13 14:08:55 +02:00
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
from .olaflow import OFModel
parser = argparse.ArgumentParser(description="Post-process olaflow results")
parser.add_argument("-v", "--verbose", action="count", default=0)
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"
)
2022-04-13 14:08:55 +02:00
args = parser.parse_args()
logging.basicConfig(level=max((10, 20 - 10 * args.verbose)))
log = logging.getLogger("ola_post")
2022-05-09 20:22:40 +02:00
log.info("Starting pickling")
out = args.output
2022-04-14 12:37:42 +02:00
out.mkdir(parents=True, exist_ok=True)
2022-04-13 14:08:55 +02:00
olaflow_root = args.input
2022-04-13 14:08:55 +02:00
model = OFModel(olaflow_root)
model.read_mesh()
model.read_time()
2022-04-13 14:08:55 +02:00
model.read_field_all("alpha.water")
model.read_field_all("porosity")
model.read_field_all("p")
model.read_field_all("p_rgh")
model.read_field_all("U")
model.read_post("graphUniform", "alpha.water")
model.read_post("graphUniform", "U")
model.read_post("graphUniform2", "alpha.water")
model.read_post("graphUniform2", "U")
with (
gzip.open(out.joinpath("pickle.gz"), "wb")
if args.compress
else out.joinpath("pickle").open("wb")
) as f:
2022-04-13 14:08:55 +02:00
pickle.dump(model, f)