From 47e1f2fb0332a0422c75c203435f8acf2f07245d Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 16 May 2022 10:25:38 -0700 Subject: [PATCH] add comments, cleanup, and add user-defined var for ubound of rel_diff, and lbound of ndens for magnetization comp --- Source/Particles/PulsarParameters.cpp | 102 -------------------------- 1 file changed, 102 deletions(-) diff --git a/Source/Particles/PulsarParameters.cpp b/Source/Particles/PulsarParameters.cpp index 6443a2d8f5e..83f17c29791 100644 --- a/Source/Particles/PulsarParameters.cpp +++ b/Source/Particles/PulsarParameters.cpp @@ -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(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 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 center_star_arr; - for (int idim = 0; idim < 3; ++idim) { - center_star_arr[idim] = m_center_star[idim]; - } - std::unique_ptr rho; - auto& mypc = warpx.GetPartContainer(); - rho = mypc.GetChargeDensity(lev, true); - amrex::MultiFab & rho_mf = *rho; - - Gpu::DeviceScalar 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& Bx = Bx_mf[mfi].array(); - amrex::Array4 const& By = By_mf[mfi].array(); - amrex::Array4 const& Bz = Bz_mf[mfi].array(); - amrex::Array4 const& ndens = ndens_mf[mfi].array(); - amrex::Array4 const& injection = injectionflag_mf[mfi].array(); - amrex::Array4 const& mag = magnetization_mf[mfi].array(); - amrex::Array4 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"; - } -}