Add openfoam postprocessing read to pickle
This commit is contained in:
parent
a6d2041666
commit
4e89266237
2 changed files with 22 additions and 9 deletions
|
@ -9,6 +9,7 @@ class OFModel:
|
|||
def __init__(self, root):
|
||||
self._root = root
|
||||
self._fields = {}
|
||||
self._post_fields = {}
|
||||
|
||||
def read_mesh(self):
|
||||
self._x, self._y, self._z = readof.readmesh(str(self._root))
|
||||
|
@ -51,6 +52,22 @@ class OFModel:
|
|||
self.fields[field] = _field
|
||||
return _field
|
||||
|
||||
def read_post(self, func, field):
|
||||
_ft = lambda _d: self._root.joinpath("postProcessing", func, _d, f"line_{field}.xy")
|
||||
_res_0 = np.loadtxt(_ft(self._t_dirs[0]))
|
||||
_x = _res_0[:, 0]
|
||||
_res = np.empty((self._t.size, _x.size))
|
||||
_res[0] = _res_0[:, 1]
|
||||
for _r, _dir in zip(_res[1:], self._t_dirs[1:]):
|
||||
_r[:] = np.loadtxt(_ft(_dir))[:, 1]
|
||||
_dict = {
|
||||
f"x_{field}": _x,
|
||||
field: _res,
|
||||
}
|
||||
if func not in self._post_fields.keys(): self._post_fields[func] = {}
|
||||
self._post_fields[func] |= _dict
|
||||
return _dict
|
||||
|
||||
def write_field(self, field, values):
|
||||
with open(self._root.joinpath("0", field), "r") as aw_file:
|
||||
aw_raw = aw_file.read()
|
||||
|
@ -106,12 +123,5 @@ class OFModel:
|
|||
return self._fields
|
||||
|
||||
@property
|
||||
def X(self):
|
||||
return self._X
|
||||
|
||||
@property
|
||||
def Z(self):
|
||||
return self._Z
|
||||
|
||||
def FIELD(self, field):
|
||||
return np.where(self._C > 0, field[:, C], np.nan)
|
||||
def post_fields(self):
|
||||
return self._post_fields
|
||||
|
|
|
@ -31,11 +31,14 @@ olaflow_root = args.output
|
|||
model = OFModel(olaflow_root)
|
||||
model.read_mesh()
|
||||
model.read_time()
|
||||
|
||||
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")
|
||||
|
||||
with gzip.open(out.joinpath("pickle.gz"), "wb") as f:
|
||||
pickle.dump(model, f)
|
||||
|
|
Loading…
Reference in a new issue