Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasaunai committed Sep 17, 2024
1 parent 5d6062d commit 2191e39
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 35 deletions.
53 changes: 30 additions & 23 deletions pyphare/pyphare/pharesee/hierarchy/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ def box_to_Rectangle(self, box):
return Rectangle(box.lower, *box.shape)

def plot_2d_patches(self, ilvl, collections, **kwargs):
from matplotlib.patches import Rectangle

if isinstance(collections, list) and all(
[isinstance(el, Box) for el in collections]
):
Expand All @@ -365,37 +367,42 @@ def plot_2d_patches(self, ilvl, collections, **kwargs):

fig, ax = kwargs.get("subplot", plt.subplots(figsize=(16, 16)))

color = 1

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable color is not used.
i0, j0 = level_domain_box.lower
i1, j1 = level_domain_box.upper
ij = np.zeros((i1 - i0 + 1, j1 - j0 + 1)) + np.nan
ix = np.arange(i0, i1 + 1)
iy = np.arange(j0, j1 + 1)

for collection in collections:
facecolor = collection.get("facecolor", "none")
edgecolor = collection.get("edgecolor", "purple")
alpha = collection.get("alpha", 1)
rects = [self.box_to_Rectangle(box) for box in collection["boxes"]]

ax.add_collection(
PatchCollection(
rects, facecolor=facecolor, alpha=alpha, edgecolor=edgecolor
)
)
facecolor = collection.get("facecolor", np.nan)
for box in collection["boxes"]:
if isinstance(box, Box):
i0, j0 = box.lower
i1, j1 = box.upper
ij[i0 : i1 + 1, j0 : j1 + 1] = facecolor
else:
ij[box] = facecolor

ax.pcolormesh(ix, iy, ij.T, edgecolors="k", cmap="jet")
ax.set_xticks(ix)
ax.set_yticks(iy)

for patch in self.level(ilvl).patches:
box = patch.box
r = Rectangle(box.lower - 0.5, *(box.upper + 0.5))

r.set_edgecolor("r")
r.set_facecolor("none")
r.set_linewidth(2)
ax.add_patch(r)

if "title" in kwargs:
from textwrap import wrap

xfigsize = int(fig.get_size_inches()[0] * 10) # 10 characters per inch
ax.set_title("\n".join(wrap(kwargs["title"], xfigsize)))

major_ticks = np.arange(mi - 5, ma + 5 + 5, 1)
ax.set_xticks(major_ticks)
ax.set_yticks(major_ticks)

minor_ticks = np.arange(mi - 4.5, ma + 5 + 5, 1)
ax.set_xticks(minor_ticks, minor=True)
ax.set_yticks(minor_ticks, minor=True)

# Align the minor tick label
for label in ax.get_xticklabels(minor=True):
label.set_horizontalalignment("center")

ax.grid(which="both")
if "xlim" in kwargs:
ax.set_xlim(kwargs["xlim"])
if "ylim" in kwargs:
Expand Down
17 changes: 9 additions & 8 deletions src/core/numerics/interpolator/interpolator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,9 @@ class Interpolator : private Weighter<interpOrder>
* onto the particle.
*/
template<typename ParticleRange, typename VecField, typename GridLayout, typename Field>
inline void operator()(ParticleRange& particleRange, Field& particleDensity, Field& chargeDensity, VecField& flux,
GridLayout const& layout, double coef = 1.)
inline void operator()(ParticleRange& particleRange, Field& particleDensity,
Field& chargeDensity, VecField& flux, GridLayout const& layout,
double coef = 1.)
{
auto begin = particleRange.begin();
auto end = particleRange.end();
Expand All @@ -487,11 +488,11 @@ class Interpolator : private Weighter<interpOrder>
currPart->delta);

particleToMesh_(
particleDensity, *currPart, [](auto const& part) { return 1.; }, startIndex_, weights_,
coef);
particleDensity, *currPart, [](auto const& part) { return 1.; }, startIndex_,
weights_, coef);
particleToMesh_(
chargeDensity, *currPart, [](auto const& part) { return part.charge; }, startIndex_, weights_,
coef);
chargeDensity, *currPart, [](auto const& part) { return part.charge; }, startIndex_,
weights_, coef);
particleToMesh_(
xFlux, *currPart, [](auto const& part) { return part.v[0]; }, startIndex_, weights_,
coef);
Expand All @@ -505,8 +506,8 @@ class Interpolator : private Weighter<interpOrder>
PHARE_LOG_STOP(3, "ParticleToMesh::operator()");
}
template<typename ParticleRange, typename VecField, typename GridLayout, typename Field>
inline void operator()(ParticleRange&& range, Field& particleDensity, Field& chargeDensity, VecField& flux,
GridLayout const& layout, double coef = 1.)
inline void operator()(ParticleRange&& range, Field& particleDensity, Field& chargeDensity,
VecField& flux, GridLayout const& layout, double coef = 1.)
{
(*this)(range, particleDensity, chargeDensity, flux, layout, coef);
}
Expand Down
11 changes: 7 additions & 4 deletions tests/simulator/test_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,18 @@ def base_test_overlaped_fields_are_equal(self, datahier, coarsest_time):
checks += 1
except AssertionError as e:
print("AssertionError", pd1.name, e)
print(
np.where(~np.isclose(slice1, slice2, atol=2.5e-14, rtol=0))
errors = np.where(
~np.isclose(slice1, slice2, atol=2.5e-14, rtol=0)
)
errors[0][:] += loc_b1.lower[0] + pd1.ghost_box.lower[0]
errors[1][:] += loc_b1.lower[1] + pd1.ghost_box.lower[1]

fig = datahier.plot_2d_patches(
ilvl,
collections=[
{"boxes": [pd1.box], "facecolor": "red"},
{"boxes": [pd2.box], "facecolor": "blue"},
{"boxes": [pd1.box], "facecolor": 1},
{"boxes": [pd2.box], "facecolor": 2},
{"boxes": [errors], "facecolor": 3},
],
xlim=(-5, 50),
ylim=(-5, 50),
Expand Down

0 comments on commit 2191e39

Please sign in to comment.