Skip to content

Commit

Permalink
Cleanup: Print Commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Sep 29, 2023
1 parent 3e42184 commit dcc9b18
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 104 deletions.
53 changes: 1 addition & 52 deletions examples/expanding_beam/run_expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

pp_amr = amr.ParmParse("amr")
pp_amr.add("max_level", 1)
pp_amr.addarr("n_cell", [56, 56, 48])

sim = ImpactX()

# set numerical parameters and IO control
# sim.n_cell = [56, 56, 48]
sim.n_cell = [56, 56, 48]
sim.particle_shape = 2 # B-spline order
sim.space_charge = True
sim.dynamic_size = True
Expand Down Expand Up @@ -59,56 +58,6 @@
# run simulation
sim.evolve()

# visualize
import numpy as np

rho = sim.rho(lev=0)
rs = rho.sum_unique(comp=0, local=False)

gm = sim.Geom(lev=0)
dr = gm.data().CellSize()
dV = np.prod(dr)

half_z = sim.n_cell[2] // 2 # order: x,y,z

import matplotlib.pyplot as plt

f = plt.figure()
ax = f.gca()
ng = rho.nGrowVect
for mfi in rho:
bx = mfi.validbox()
rbx = amr.RealBox(bx, dr, gm.ProbLo())

arr = rho.array(mfi)
arr_np = np.array(arr, copy=False) # indices: comp, z, y, x

# shift box to zero-based local mfi index space
half_z_local = half_z - bx.lo_vect[2]
bx.shift(bx.lo_vect * -1)
# check if the current tile contains the half-z plane
if half_z_local < 0 or half_z_local > arr_np.shape[2]:
continue

comp = 0
mu = 1.0e6 # m->mu
im = ax.imshow(
# arr_np[comp, half_z, ...] * dV, # including guard
arr_np[comp, half_z_local, ng[1] : -ng[1], ng[0] : -ng[0]] * dV, # w/o guard
origin="lower",
aspect="auto",
extent=[rbx.lo(0) * mu, rbx.hi(0) * mu, rbx.lo(1) * mu, rbx.hi(1) * mu],
)
cb = f.colorbar(im)
cb.set_label(r"charge density [C/m$^3$]")
ax.set_xlabel(r"$x$ [$\mu$m]")
ax.set_ylabel(r"$y$ [$\mu$m]")
save_png = False
if save_png:
plt.savefig("charge_deposition.png")
else:
plt.show()

# clean shutdown
del sim
amr.finalize()
1 change: 0 additions & 1 deletion src/ImpactX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ namespace impactx
// the particles are in x, y, z coordinates.

// Resize the mesh, based on `m_particle_container` extent
amrex::Print() << " ++++ calling ResizeMesh\n";
ResizeMesh();

// Redistribute particles in the new mesh in x, y, z
Expand Down
53 changes: 3 additions & 50 deletions src/initialization/InitMeshRefinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ namespace detail
pp_geometry.query("dynamic_size", dynamic_size);

amrex::Vector<amrex::RealBox> rb(this->finestLevel() + 1); // extent per level
amrex::Print() << " ++++ dynamic_size=" << dynamic_size << "\n";
if (dynamic_size)
{
// The coarsest level is expanded (or reduced) relative the min and max of particles.
Expand All @@ -280,55 +279,14 @@ namespace detail

amrex::RealVect const beam_padding = beam_width * (frac - 1.0) / 2.0;
// added to the beam extent --^ ^-- box half above/below the beam

// In AMReX, all levels have the same problem domain, that of the
// coarsest level, even if only partly covered.
for (int lev = 0; lev <= this->finestLevel(); ++lev)
{
rb[lev].setLo(beam_min - beam_padding);
rb[lev].setHi(beam_max + beam_padding);
}

/*
// Coarser levels are NOT simply the rb[0] size scaled with prob_relative.
// The reason for that is that the cell tagging for refinement in ErrorEst
// will be founded up to full AMReX blocks of cells.
for (int lev = 1; lev <= this->finestLevel(); ++lev)
{
// covered index space of the current level and coarser level
amrex::Box const cov_box = boxArray(lev).minimalBox();
amrex::Box const cov_box_crs = boxArray(lev - 1).minimalBox();
// edge lengths of the covered box on current and coarser level
auto const r_cell_n = amrex::RealVect(cov_box.size());
auto const r_cell_crs = amrex::RealVect(cov_box_crs.size());
amrex::Print() << "lev=" << lev << " r_cell_n=" << r_cell_n << "\n";
amrex::Print() << "lev=" << lev << " r_cell_crs=" << r_cell_crs << "\n";
// based on the refinement ratio and the actual index space (domain) per level,
// we can calculate the size difference of the block-wise covered ProbDomains
amrex::RealVect const r_ref_ratio = ref_ratio[lev - 1];
amrex::Print() << "lev=" << lev << " r_ref_ratio=" << r_ref_ratio << "\n";
// difference in covered domain between levels (<=1)
amrex::RealVect const r_cell_ratio = (r_cell_n / r_ref_ratio) / r_cell_crs;
amrex::Print() << "lev=" << lev << " r_cell_ratio=" << r_cell_ratio << "\n";
amrex::RealVect const lo_crs(rb[lev - 1].lo());
amrex::RealVect const hi_crs(rb[lev - 1].hi());
amrex::RealVect const size_crs = hi_crs - lo_crs;
amrex::Print() << "lev=" << lev << " lo_crs=" << lo_crs << "\n";
amrex::Print() << "lev=" << lev << " hi_crs=" << hi_crs << "\n";
amrex::Print() << "lev=" << lev << " size_crs=" << size_crs << "\n";
amrex::RealVect const size = size_crs * r_cell_ratio; // wrong?!
amrex::RealVect const size_diff = size_crs - size;
amrex::Print() << "lev=" << lev << " size_crs=" << size_crs << "\n";
amrex::Print() << "lev=" << lev << " size=" << size << "\n";
amrex::Print() << "lev=" << lev << " size_diff=" << size_diff << "\n";
rb[lev].setLo(lo_crs + size_diff / 2.0);
rb[lev].setHi(hi_crs - size_diff / 2.0);
}
*/
}
else
{
Expand All @@ -351,9 +309,6 @@ namespace detail
pp_geometry.addarr("prob_lo", prob_lo);
pp_geometry.addarr("prob_hi", prob_hi);

amrex::Print() << "lev=0 prob_lo=" << prob_lo[0] << " " << prob_lo[1] << " " << prob_lo[2] << "\n";
amrex::Print() << "lev=0 prob_hi=" << prob_hi[0] << " " << prob_hi[1] << " " << prob_hi[2] << "\n";

// Resize the domain size
amrex::Geometry::ResetDefaultProbDomain(rb[0]);

Expand All @@ -363,8 +318,6 @@ namespace detail
g.ProbDomain(rb[lev]);
SetGeometry(lev, g);

amrex::Print() << "lev=" << lev << " g.CellSize()=" << g.CellSize(0) << " " << g.CellSize(1) << " " << g.CellSize(2) << "\n";

m_particle_container->SetParticleGeometry(lev, g);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/particles/ChargeDeposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ namespace impactx

// cell size of the mesh to deposit to
std::array<amrex::Real, 3> const & AMREX_RESTRICT dx = {gm.CellSize(0), gm.CellSize(1), gm.CellSize(2)};
amrex::Print() << "lev=" << lev << ": dx before charge depos=" << dx << "\n";

// RZ modes (unused)
int const n_rz_azimuthal_modes = 0;
Expand Down

0 comments on commit dcc9b18

Please sign in to comment.