2022-03-02 14:25:53 +01:00
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
2022-03-04 10:21:02 +01:00
|
|
|
class ReadSwash:
|
|
|
|
def __init__(self):
|
|
|
|
self._n_x = None
|
|
|
|
self._n_t = None
|
|
|
|
self._t = None
|
|
|
|
self._x = None
|
2022-03-04 10:22:38 +01:00
|
|
|
self._data = {}
|
2022-03-04 10:21:02 +01:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def read_nohead(cls, path):
|
|
|
|
with open(path) as file:
|
|
|
|
return np.asarray(file.read().split(), dtype=np.float64)
|
|
|
|
|
|
|
|
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_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_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)
|
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def t(self):
|
|
|
|
return self._t
|
|
|
|
|
|
|
|
@property
|
|
|
|
def x(self):
|
|
|
|
return self._x
|
|
|
|
|
|
|
|
@property
|
|
|
|
def data(self):
|
|
|
|
return self._data
|