Skip to content

Commit

Permalink
add comments, cleanup, and add user-defined var for ubound of rel_dif…
Browse files Browse the repository at this point in the history
…f, and lbound of ndens for magnetization comp
  • Loading branch information
RevathiJambunathan committed May 18, 2022
1 parent d5b0cd1 commit 47e1f2f
Showing 1 changed file with 0 additions and 102 deletions.
102 changes: 0 additions & 102 deletions Source/Particles/PulsarParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1398,105 +1398,3 @@ Pulsar::PrintInjectedCellValues ()
amrex::AllPrintToFile(ss.str()) << "\n";
}
}

amrex::Real
Pulsar::SumInjectionFlag ()
{
return m_injection_flag[0]->sum();
}

void
Pulsar::PrintInjectedCellValues ()
{
auto& warpx = WarpX::GetInstance();
std::vector species_names = warpx.GetPartContainer().GetSpeciesNames();
const int nspecies = species_names.size();
int total_injected_cells = static_cast<int>(SumInjectionFlag());
// x, y, z, r, theta, phi, injection_flag, magnetization, ndens_p, ndens_e, Bx, By, Bz, Bmag, rho
int total_diags = 15;
amrex::Gpu::DeviceVector<amrex::Real> InjectedCellDiag(total_injected_cells*total_diags,0.0);
amrex::Real * InjectedCellDiagData = InjectedCellDiag.data();
const int lev = 0;
const auto dx_lev = warpx.Geom(lev).CellSizeArray();
const amrex::RealBox real_box = warpx.Geom(lev).ProbDomain();
const amrex::MultiFab& Bx_mf = warpx.getBfield(lev,0);
const amrex::MultiFab& By_mf = warpx.getBfield(lev,1);
const amrex::MultiFab& Bz_mf = warpx.getBfield(lev,2);
const amrex::MultiFab& injectionflag_mf = *m_injection_flag[lev];
const amrex::MultiFab& magnetization_mf = *m_magnetization[lev];
const amrex::MultiFab& ndens_mf = *m_plasma_number_density[lev];
GpuArray<amrex::Real, AMREX_SPACEDIM> center_star_arr;
for (int idim = 0; idim < 3; ++idim) {
center_star_arr[idim] = m_center_star[idim];
}
std::unique_ptr<amrex::MultiFab> rho;
auto& mypc = warpx.GetPartContainer();
rho = mypc.GetChargeDensity(lev, true);
amrex::MultiFab & rho_mf = *rho;

Gpu::DeviceScalar<int> cell_counter(0);
int* cell_counter_d = cell_counter.dataPtr();
for (MFIter mfi(injectionflag_mf, TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
const amrex::Box & bx = mfi.tilebox();
amrex::Array4<const amrex::Real> const& Bx = Bx_mf[mfi].array();
amrex::Array4<const amrex::Real> const& By = By_mf[mfi].array();
amrex::Array4<const amrex::Real> const& Bz = Bz_mf[mfi].array();
amrex::Array4<const amrex::Real> const& ndens = ndens_mf[mfi].array();
amrex::Array4<const amrex::Real> const& injection = injectionflag_mf[mfi].array();
amrex::Array4<const amrex::Real> const& mag = magnetization_mf[mfi].array();
amrex::Array4<const amrex::Real> const& rho_arr = rho_mf[mfi].array();
amrex::LoopOnCpu( bx,
[=] (int i, int j, int k)
{
if (injection(i,j,k) == 1) {
// Cartesian Coordinates
amrex::Real x = i * dx_lev[0] + real_box.lo(0) + 0.5_rt * dx_lev[0];
amrex::Real y = j * dx_lev[1] + real_box.lo(1) + 0.5_rt * dx_lev[1];
amrex::Real z = k * dx_lev[2] + real_box.lo(2) + 0.5_rt * dx_lev[2];
// convert cartesian to spherical coordinates
amrex::Real r, theta, phi;
ConvertCartesianToSphericalCoord(x, y, z, center_star_arr,
r, theta, phi);
amrex::Real Bx_cc = (Bx(i,j,k) + Bx(i+1, j, k)) / 2.0;
amrex::Real By_cc = (By(i,j,k) + By(i, j+1, k)) / 2.0;
amrex::Real Bz_cc = (Bz(i,j,k) + Bz(i, j, k+1)) / 2.0;
// magnitude of magnetic field
amrex::Real B_mag = std::sqrt( Bx_cc * Bx_cc
+ By_cc * By_cc
+ Bz_cc * Bz_cc );
int counter = *cell_counter_d;
InjectedCellDiagData[counter*total_diags+0] = x;
InjectedCellDiagData[counter*total_diags+1] = y;
InjectedCellDiagData[counter*total_diags+2] = z;
InjectedCellDiagData[counter*total_diags+3] = r;
InjectedCellDiagData[counter*total_diags+4] = theta;
InjectedCellDiagData[counter*total_diags+5] = phi;
InjectedCellDiagData[counter*total_diags+6] = injection(i, j, k);
InjectedCellDiagData[counter*total_diags+7] = mag(i, j, k);
InjectedCellDiagData[counter*total_diags+8] = ndens(i, j, k, 0);
InjectedCellDiagData[counter*total_diags+9] = ndens(i, j, k, 1);
InjectedCellDiagData[counter*total_diags+10] = Bx_cc;
InjectedCellDiagData[counter*total_diags+11] = By_cc;
InjectedCellDiagData[counter*total_diags+12] = Bz_cc;
InjectedCellDiagData[counter*total_diags+13] = B_mag;
InjectedCellDiagData[counter*total_diags+14] = rho_arr(i, j, k);
const int unity = 1;
amrex::HostDevice::Atomic::Add(cell_counter_d, unity);
}
});
}
amrex::Print() << " counter : " << cell_counter.dataValue() << " total cells injected " << total_injected_cells << "\n";
std::stringstream ss;
ss << Concatenate("InjectionCellData", warpx.getistep(0), 5);
amrex::AllPrintToFile(ss.str()) << " cell_index x y z r theta phi injection magnetization ndens_p ndens_e Bx By Bz Bmag rho \n" ;
for (int icell = 0; icell < total_injected_cells; ++icell ) {
if (InjectedCellDiagData[icell*total_diags + 6] == 1) {
amrex::AllPrintToFile(ss.str()) << icell << " ";
for (int idata = 0; idata < total_diags; ++idata) {
amrex::AllPrintToFile(ss.str()) << InjectedCellDiagData[icell * total_diags + idata] << " ";
}
}
amrex::AllPrintToFile(ss.str()) << "\n";
}
}

0 comments on commit 47e1f2f

Please sign in to comment.