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

53 lines
1.4 KiB
Python

import re
from fluidfoam import readof
class OFModel:
def __init__(self, root):
self._root = root
def read_mesh(self):
self._x, self._y, self._z = readof.readmesh(str(self._root))
def write_field(self, field, values):
with open(self._root.joinpath("0", field), "r") as aw_file:
aw_raw = aw_file.read()
with open(self._root.joinpath("0", field), "w") as aw_file:
aw_file.write(
re.sub(
r"(?<=\(\n).*?(?=\n\))",
"\n".join(values.astype(str)),
aw_raw,
count=1,
flags=re.S,
)
)
def write_vector_field(self, field, values):
with open(self._root.joinpath("0", field), "r") as aw_file:
aw_raw = aw_file.read()
with open(self._root.joinpath("0", field), "w") as aw_file:
aw_file.write(
re.sub(
r"(?<=\(\n).*?(?=\n\))",
"\n".join(map(lambda x: f"({' '.join(x.astype('str'))})", values)),
aw_raw,
count=1,
flags=re.S,
)
)
@property
def x(self):
return self._x
@property
def y(self):
return self._y
@property
def z(self):
return self._z