Skip to content

Commit

Permalink
Update eval
Browse files Browse the repository at this point in the history
  • Loading branch information
s9latimm committed Oct 18, 2024
1 parent 7f64393 commit 2ea6acc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
14 changes: 5 additions & 9 deletions src/base/view/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ def plot_history(

class Plot(plt.Figure):

def __init__(self,
x: np.ndarray[np.ndarray[float]],
y: np.ndarray[np.ndarray[float]],
path: Path = None,
n: int = 1) -> None:
def __init__(self, x: np.ndarray, y: np.ndarray, path: Path = None, n: int = 1) -> None:
self.__x = x
self.__y = y
self.__path = path
Expand Down Expand Up @@ -258,18 +254,18 @@ def plot_stream(
ax = fig.add_subplot()
fig.setup(ax, title, boundary, figure)

speed = np.sqrt(np.square(u) + np.square(v))
speed = 1 + 4 * speed / np.nanmax(speed)
# speed = np.sqrt(np.square(u) + np.square(v))
# speed = 4 * speed / np.nanmax(speed)

ax.streamplot(
x.transpose(),
y.transpose(),
u.transpose(),
v.transpose(),
broken_streamlines=False,
arrowsize=1,
arrowsize=.5,
color=COLORS[1],
density=.5,
density=.4,
linewidth=1,
)

Expand Down
30 changes: 27 additions & 3 deletions src/nse/model/experiments/foam.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import re
from pathlib import Path

import numpy as np

from src import OUTPUT_DIR, FOAM_DIR
from src.base.model.mesh import Grid, Axis, Coordinate, arrange
from src.base.model.shape import Figure, Rectangle
from src.base.view.plot import plot_seismic
from src.base.view.plot import plot_seismic, plot_arrows, plot_stream
from src.nse.model.experiments.experiment import Experiment
from src.nse.model.record import Record

Expand Down Expand Up @@ -107,7 +109,7 @@ def __blockify(self) -> None:

for c in self.__grid:
if c not in self._knowledge:
self._knowledge.insert(c, Record(0, 0, 0))
self._knowledge.insert(c, Record(np.nan, np.nan, np.nan))

@staticmethod
def __dir(path: Path) -> int | None:
Expand All @@ -133,7 +135,7 @@ def main():
f = Foam(
name,
m,
.1,
step,
Figure(Rectangle((0, 0), (10, 2))),
Figure(Rectangle((0, 0), (1, 1))),
)
Expand All @@ -155,4 +157,26 @@ def main():
figure=f.obstruction,
)

plot_stream(
'OpenFOAM Streamlines',
m.x,
m.y,
d.u,
d.v,
path=OUTPUT_DIR / 'foam' / 'foam_str.pdf',
boundary=f.boundary,
figure=f.obstruction,
)

plot_arrows(
'OpenFOAM Arrows',
m.x,
m.y,
d.u,
d.v,
path=OUTPUT_DIR / 'foam' / 'foam_arw.pdf',
boundary=f.boundary,
figure=f.obstruction,
)

main()
5 changes: 2 additions & 3 deletions src/nse/model/experiments/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(
foam = Foam(
f'step-{step:.3f}-{nu:.3f}-{flow:.3f}'.replace('.', '_'),
grid,
.1,
step,
Figure(Line((0, 0), (10, 0)), Line((0, 2), (10, 2))),
Figure(Rectangle((0, 0), (1, 1))),
0.08,
Expand Down Expand Up @@ -62,9 +62,8 @@ def __init__(
self._knowledge.emplace((1, y), u=0, v=0)

# training
grid = Grid(self.x.arrange(t), self.y.arrange(t))
for c in grid:
if c not in self._knowledge and c not in self._learning and c not in self.obstruction:
if c not in self._knowledge and c not in self.obstruction:
self._learning.emplace(c)

if supervised:
Expand Down
6 changes: 4 additions & 2 deletions src/nse/view/grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def plot_setup(experiment: Experiment, identifier: str):
grid = Grid(experiment.x.arrange(1), experiment.y.arrange(1))
grid = Grid([0, 10], [0, 2])
x, y = grid.x, grid.y

mesh = Mesh[Record]()
Expand All @@ -31,6 +31,8 @@ def plot_setup(experiment: Experiment, identifier: str):
x,
y,
[('u', data.u), ('v', data.u), ('p', data.u)],
mesh=mesh,
marker=experiment.learning.keys(),
path=OUTPUT_DIR / identifier / 'setup.pdf',
boundary=experiment.boundary,
figure=experiment.obstruction,
Expand All @@ -51,7 +53,7 @@ def plot_foam(experiment: Experiment, identifier: str):
[
('u', u),
('v', v),
('p', p - p.min()),
('p', p - np.nanmin(p)),
],
path=OUTPUT_DIR / identifier / 'grading' / 'foam_uvp.pdf',
boundary=experiment.boundary,
Expand Down

0 comments on commit 2ea6acc

Please sign in to comment.