Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyphare/pyphare/pharein/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def population_in_model(population):
class FluidDiagnostics_(Diagnostics):
fluid_quantities = [
"density",
"charge_density",
"mass_density",
"flux",
"bulkVelocity",
Expand Down
55 changes: 35 additions & 20 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 @@ -363,35 +365,48 @@ def plot_2d_patches(self, ilvl, collections, **kwargs):
level_domain_box = self.level_domain_box(ilvl)
mi, ma = level_domain_box.lower.min(), level_domain_box.upper.max()

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

color = 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the unused local variable color.

The local variable color is assigned a value but never used in the method. As indicated by the static analysis hints, it's best to remove this unused variable to improve code quality and cleanliness.

Apply this diff to remove the unused variable:

-        color = 1
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
color = 1
Tools
Ruff

370-370: Local variable color is assigned to but never used

Remove assignment to unused variable color

(F841)

GitHub Check: CodeQL

[notice] 370-370: Unused local variable
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, 5)
ax.set_xticks(major_ticks)
ax.set_yticks(major_ticks)

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

ax.grid(which="both")
if "xlim" in kwargs:
ax.set_xlim(kwargs["xlim"])
if "ylim" in kwargs:
ax.set_ylim(kwargs["ylim"])

return fig

Expand Down
1 change: 1 addition & 0 deletions pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"momentum_tensor_zz": "Mzz",
"density": "rho",
"mass_density": "rho",
"charge_density": "rho",
"tags": "tags",
}

Expand Down
2 changes: 1 addition & 1 deletion pyphare/pyphare/pharesee/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def finest_field_plot(run_path, qty, **kwargs):
time = times[0]
interpolator, finest_coords = r.GetVi(time, merged=True, interp=interp)[qty]
elif qty == "rho":
file = os.path.join(run_path, "ions_density.h5")
file = os.path.join(run_path, "ions_charge_density.h5")
if time is None:
times = get_times_from_h5(file)
time = times[0]
Expand Down
6 changes: 3 additions & 3 deletions pyphare/pyphare/pharesee/run/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"EM_B": "B",
"EM_E": "E",
"ions_bulkVelocity": "Vi",
"ions_density": "Ni",
"ions_charge_density": "Ni",
"particle_count": "nppc",
}

Expand Down Expand Up @@ -116,7 +116,7 @@ def GetMassDensity(self, time, merged=False, interp="nearest", **kwargs):
return ScalarField(self._get(hier, time, merged, interp))

def GetNi(self, time, merged=False, interp="nearest", **kwargs):
hier = self._get_hierarchy(time, "ions_density.h5", **kwargs)
hier = self._get_hierarchy(time, "ions_charge_density.h5", **kwargs)
return ScalarField(self._get(hier, time, merged, interp))

def GetN(self, time, pop_name, merged=False, interp="nearest", **kwargs):
Expand Down Expand Up @@ -153,7 +153,7 @@ def GetPi(self, time, merged=False, interp="nearest", **kwargs):
return self._get(Pi, time, merged, interp) # should later be a TensorField

def GetPe(self, time, merged=False, interp="nearest", all_primal=True):
hier = self._get_hierarchy(time, "ions_density.h5")
hier = self._get_hierarchy(time, "ions_charge_density.h5")

Te = hier.sim.electrons.closure.Te

Expand Down
2 changes: 1 addition & 1 deletion pyphare/pyphare_tests/test_pharesee/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def vthz(x, y):
for quantity in ["E", "B"]:
ph.ElectromagDiagnostics(quantity=quantity, write_timestamps=timestamps)

for quantity in ["density", "bulkVelocity"]:
for quantity in ["charge_density", "bulkVelocity"]:
ph.FluidDiagnostics(quantity=quantity, write_timestamps=timestamps)

return sim
Expand Down
2 changes: 1 addition & 1 deletion src/amr/level_initializer/hybrid_level_initializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace solver
core::depositParticles(ions, layout, interpolate_, core::LevelGhostDeposit{});
}

ions.computeDensity();
ions.computeChargeDensity();
ions.computeBulkVelocity();
}

Expand Down
11 changes: 6 additions & 5 deletions src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,20 +385,21 @@ namespace amr
{
// first thing to do is to project patchGhostParitcles moments
auto& patchGhosts = pop.patchGhostParticles();
auto& density = pop.density();
auto& particleDensity = pop.particleDensity();
auto& chargeDensity = pop.chargeDensity();
auto& flux = pop.flux();

interpolate_(makeRange(patchGhosts), density, flux, layout);
interpolate_(makeRange(patchGhosts), particleDensity, chargeDensity, flux, layout);

if (level.getLevelNumber() > 0) // no levelGhost on root level
{
// then grab levelGhostParticlesOld and levelGhostParticlesNew
// and project them with alpha and (1-alpha) coefs, respectively
auto& levelGhostOld = pop.levelGhostParticlesOld();
interpolate_(makeRange(levelGhostOld), density, flux, layout, 1. - alpha);
interpolate_(makeRange(levelGhostOld), particleDensity, chargeDensity, flux, layout, 1. - alpha);

auto& levelGhostNew = pop.levelGhostParticlesNew();
interpolate_(makeRange(levelGhostNew), density, flux, layout, alpha);
interpolate_(makeRange(levelGhostNew), particleDensity, chargeDensity, flux, layout, alpha);
}
}
}
Expand Down Expand Up @@ -538,7 +539,7 @@ namespace amr

auto& J = hybridModel.state.J;
auto& Vi = hybridModel.state.ions.velocity();
auto& Ni = hybridModel.state.ions.density();
auto& Ni = hybridModel.state.ions.chargeDensity();

Jold_.copyData(J);
ViOld_.copyData(Vi);
Expand Down
2 changes: 1 addition & 1 deletion src/amr/physical_models/hybrid_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void HybridModel<GridLayoutT, Electromag, Ions, Electrons, AMR_Types, Grid_t>::f

hybridInfo.modelMagnetic = core::VecFieldNames{state.electromag.B};
hybridInfo.modelElectric = core::VecFieldNames{state.electromag.E};
hybridInfo.modelIonDensity = state.ions.densityName();
hybridInfo.modelIonDensity = state.ions.chargeDensityName();
hybridInfo.modelIonBulkVelocity = core::VecFieldNames{state.ions.velocity()};
hybridInfo.modelCurrent = core::VecFieldNames{state.J};

Expand Down
2 changes: 1 addition & 1 deletion src/amr/tagging/default_hybrid_tagger_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void DefaultHybridTaggerStrategy<HybridModel>::tag(HybridModel& model,
auto& By = model.state.electromag.B.getComponent(PHARE::core::Component::Y);
auto& Bz = model.state.electromag.B.getComponent(PHARE::core::Component::Z);

auto& N = model.state.ions.density();
auto& N = model.state.ions.chargeDensity();

Check notice

Code scanning / CodeQL

Unused local variable

Variable N is not used.

// we loop on cell indexes for all qties regardless of their centering
auto const& [start_x, _]
Expand Down
16 changes: 8 additions & 8 deletions src/core/data/electrons/electrons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class StandardHybridElectronFluxComputer
{
if (isUsable())
{
return ions_.density();
return ions_.chargeDensity();
}
else
{
Expand All @@ -78,7 +78,7 @@ class StandardHybridElectronFluxComputer
{
if (isUsable())
{
return ions_.density();
return ions_.chargeDensity();
}
else
{
Expand Down Expand Up @@ -112,23 +112,23 @@ class StandardHybridElectronFluxComputer
auto const& Vix = ions_.velocity()(Component::X);
auto const& Viy = ions_.velocity()(Component::Y);
auto const& Viz = ions_.velocity()(Component::Z);
auto const& Ni = ions_.density();
auto const& Ne = ions_.chargeDensity();

auto& Vex = Ve_(Component::X);
auto& Vey = Ve_(Component::Y);
auto& Vez = Ve_(Component::Z);

// from Ni because all components defined on primal
layout.evalOnBox(Ni, [&](auto const&... args) {
layout.evalOnBox(Ne, [&](auto const&... args) {
auto arr = std::array{args...};

auto const JxOnVx = GridLayout::project(Jx, arr, GridLayout::JxToMoments());
auto const JyOnVy = GridLayout::project(Jy, arr, GridLayout::JyToMoments());
auto const JzOnVz = GridLayout::project(Jz, arr, GridLayout::JzToMoments());

Vex(arr) = Vix(arr) - JxOnVx / Ni(arr);
Vey(arr) = Viy(arr) - JyOnVy / Ni(arr);
Vez(arr) = Viz(arr) - JzOnVz / Ni(arr);
Vex(arr) = Vix(arr) - JxOnVx / Ne(arr);
Vey(arr) = Viy(arr) - JyOnVy / Ne(arr);
Vez(arr) = Viz(arr) - JzOnVz / Ne(arr);
});
}

Expand Down Expand Up @@ -211,7 +211,7 @@ class IsothermalElectronPressureClosure
if (!Pe_.isUsable())
throw std::runtime_error("Error - isothermal closure pressure not usable");

auto const& Ne_ = ions_.density();
auto const& Ne_ = ions_.chargeDensity();
std::transform(std::begin(Ne_), std::end(Ne_), std::begin(Pe_),
[this](auto n) { return n * Te_; });
}
Expand Down
26 changes: 14 additions & 12 deletions src/core/data/ions/ion_population/ion_population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace core
, mass_{initializer["mass"].template to<double>()}
, flux_{name_ + "_flux", HybridQuantity::Vector::V}
, momentumTensor_{name_ + "_momentumTensor", HybridQuantity::Tensor::M}
, rho_{name_ + "_rho", HybridQuantity::Scalar::rho}
, particleDensity_{name_ + "_particleDensity", HybridQuantity::Scalar::rho}
, chargeDensity_{name_ + "_chargeDensity", HybridQuantity::Scalar::rho}
, particles_{name_}
, particleInitializerInfo_{initializer["particle_initializer"]}
{
Expand All @@ -45,21 +46,18 @@ namespace core

NO_DISCARD std::string const& name() const { return name_; }


NO_DISCARD auto const& particleInitializerInfo() const { return particleInitializerInfo_; }



NO_DISCARD bool isUsable() const
{
return particles_.isUsable() && rho_.isUsable() && flux_.isUsable()
&& momentumTensor_.isUsable();
return particles_.isUsable() && particleDensity_.isUsable() && chargeDensity_.isUsable()
&& flux_.isUsable() && momentumTensor_.isUsable();
}


NO_DISCARD bool isSettable() const
{
return particles_.isSettable() && rho_.isSettable() && flux_.isSettable()
return particles_.isSettable() && particleDensity_.isSettable()
&& chargeDensity_.isSettable() && flux_.isSettable()
&& momentumTensor_.isSettable();
}

Expand All @@ -84,9 +82,11 @@ namespace core
return particles_.levelGhostParticlesNew();
}

NO_DISCARD field_type const& particleDensity() const { return particleDensity_; }
NO_DISCARD field_type& particleDensity() { return particleDensity_; }

NO_DISCARD field_type const& density() const { return rho_; }
NO_DISCARD field_type& density() { return rho_; }
NO_DISCARD field_type const& chargeDensity() const { return chargeDensity_; }
NO_DISCARD field_type& chargeDensity() { return chargeDensity_; }

NO_DISCARD VecField const& flux() const { return flux_; }
NO_DISCARD VecField& flux() { return flux_; }
Expand All @@ -105,7 +105,8 @@ namespace core

NO_DISCARD auto getCompileTimeResourcesViewList()
{
return std::forward_as_tuple(flux_, momentumTensor_, rho_, particles_);
return std::forward_as_tuple(flux_, momentumTensor_, particleDensity_, chargeDensity_,
particles_);
}


Expand All @@ -129,7 +130,8 @@ namespace core
double mass_;
VecField flux_;
TensorField momentumTensor_;
field_type rho_;
field_type particleDensity_;
field_type chargeDensity_;
ParticlesPack<ParticleArray> particles_;
initializer::PHAREDict const& particleInitializerInfo_;
};
Expand Down
Loading