Changed swash reading procedure to read time and space data from output

This commit is contained in:
Edgar P. Burkhart 2022-03-04 10:21:02 +01:00
parent 2a2793f92e
commit 868e34777e
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
2 changed files with 59 additions and 32 deletions

View file

@ -1,28 +1,55 @@
import numpy as np
def read_nohead(path):
with open(path) as file:
return file.read()
class ReadSwash:
def __init__(self):
self._n_x = None
self._n_t = None
self._t = None
self._x = None
self._data = None
@classmethod
def read_nohead(cls, path):
with open(path) as file:
return np.asarray(file.read().split(), dtype=np.float64)
def read_reshape(path, shape):
return np.asarray(read_nohead(path).split(), dtype=np.float64).reshape(
shape
)
def read_time(self, path):
self._t = np.unique(self.read_nohead(path))
self._n_t = self._t.size
def read_x(self, path):
self._x = np.unique(self.read_nohead(path))
self._n_x = self._x.size
def read_nohead_scalar(path, n):
return read_reshape(path, (-1, n))
def read_scalar(self, path):
self._data[path.stem] = self.read_nohead(path).reshape(
(self._n_t, self._n_x)
)
def read_vector(self, path):
self._data[path.stem] = self.read_nohead(path).reshape(
(self._n_t, 2, self._n_x)
)
def read_nohead_k(path, n, k):
return read_reshape(path, (-1, n, k))
def read_scalar_lay(self, path):
self._data[path.stem] = self.read_nohead(path).reshape(
(self._n_t, -1, self._n_x)
)
def read_vector_lay(self, path):
self._data[path.stem] = self.read_nohead(path).reshape(
(self._n_t, 2, -1, self._n_x)
)
def read_nohead_vect(path, n):
return read_reshape(path, (-1, 2, n))
@property
def t(self):
return self._t
@property
def x(self):
return self._x
def read_nohead_vect_k(path, n):
return read_reshape(path, (-1, 2, n, k))
@property
def data(self):
return self._data