diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-05-19 12:06:06 +0400 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-05-19 12:06:06 +0400 |
commit | 21d6de57fae7ee2e9950390a7b72e6a27fb26d44 (patch) | |
tree | 9a732776fdc143c52c4b53fa4300ee6a5fd110fc | |
parent | e031b6708ce491976e28d76e5ea81c3ea0c92bed (diff) | |
download | CFD-SIMPLE-21d6de57fae7ee2e9950390a7b72e6a27fb26d44.tar.gz |
feat: allow saving progress
-rw-r--r-- | src/simple.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/simple.py b/src/simple.py index 5ffe690..e0ee6a7 100644 --- a/src/simple.py +++ b/src/simple.py @@ -174,7 +174,7 @@ class SIMPLE: def avg_error(self): return np.absolute(self.b).sum() - def plot(self, normalize=False, density=False): + def plot(self, normalize=True, density=False, save_path=''): if self.patch: self.patch.remove() if self.colorbar: @@ -182,7 +182,7 @@ class SIMPLE: if self.plt: self.plt.remove() - self.patch = axes.add_patch(Rectangle((0, 0), *reversed(self.bfs_size))) + self.patch = axes.add_patch(Rectangle((0, 0), *reversed(self.bfs_size), color='gray')) axes.set_title('Velocity field (normalized)') plt.suptitle(f'Avg mass source per grid point = {self.avg_error()}') plt.xlabel('X') @@ -207,4 +207,21 @@ class SIMPLE: ) self.colorbar = plt.colorbar(label='Pressure') - plt.pause(0.0001) + if len(save_path): + plt.savefig(save_path, dpi=300) + else: + plt.pause(0.0001) + + def save(self, path): + with open(path, 'wb') as file: + np.save(file, self.u) + np.save(file, self.v) + np.save(file, self.p) + np.save(file, self.b) + + def load(self, path): + with open(path, 'rb') as file: + self.u = np.load(file) + self.v = np.load(file) + self.p = np.load(file) + self.n = np.load(file) |