Skip to content

Commit

Permalink
fixed double call to qdsmc_hybrid_electron_pc->InitParticles and adde…
Browse files Browse the repository at this point in the history
…d missing particle weight to HybridInitializeKe and HybridUpdateTe methods.
  • Loading branch information
marcoacc95 committed Nov 25, 2024
1 parent 8db795f commit 277dafd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Source/Fluids/QdsmcParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "QdsmcParticleContainer_fwd.H"

/**
* This enumerated struct is used to index the field probe particle
* values that are being stored as SoA data. Nattribs
* This enumerated struct is used to index the qdsmc fictitious
* particle values that are being stored as SoA data. Nattribs
* is enumerated to give the number of attributes stored.
*/
struct QdsmcPIdx
Expand Down
10 changes: 3 additions & 7 deletions Source/Fluids/QdsmcParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ QdsmcParticleContainer::QdsmcParticleContainer (AmrCore* amr_core)
: ParticleContainerPureSoA<QdsmcPIdx::nattribs, 0>(amr_core->GetParGDB())
{
SetParticleSize();
InitParticles(0); // only level 0 is used in HybridSolver
//InitParticles(0); // only level 0 is used in HybridSolver, commented since this is already called in WarpX.cpp
}


Expand Down Expand Up @@ -214,10 +214,6 @@ QdsmcParticleContainer::SetV (int lev,
auto const np = pti.numParticles();
auto& attribs = pti.GetStructOfArrays().GetRealData();

// making box cell centered
// amrex::Box box = pti.tilebox();
// box.grow(Ux.nGrowVect());

amrex::Box box = pti.tilebox();
const amrex::XDim3 xyzmin = WarpX::LowerCorner(box, lev, 0._rt);

Expand All @@ -233,8 +229,8 @@ QdsmcParticleContainer::SetV (int lev,
const auto &arrUyfield = Uy[pti].array();
const auto &arrUzfield = Uz[pti].array();

// Gather drift velocity directly from nodes
// since particles are located at the node positions before PushX
// Gather drift velocity directly from nodes since
// particles are located at the node positions before PushX
amrex::ParallelFor( np, [=] AMREX_GPU_DEVICE (long ip)
{
amrex::Real vxp;
Expand Down
13 changes: 8 additions & 5 deletions Source/Fluids/Qdsmc_K.H
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@


/**
* Qdsmc particles x0,y0,z0 positions should be cell centered
* Qdsmc particles x0,y0,z0 positions should at nodes positions
* at the beginning of every step, so the field gathering
* does not require any interpolation, it only needs to read
* the values from the cell centered nodes.
* the values from the nodes.
*/
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void gather_density_entropy(const amrex::ParticleReal x0p,
Expand Down Expand Up @@ -48,9 +48,10 @@ void gather_density_entropy(const amrex::ParticleReal x0p,


/**
* Qdsmc particles x0,y0,z0 positions should match node positions
* Qdsmc particles x0,y0,z0 positions should at nodes positions
* at the beginning of every step, so the field gathering
* does not require any interpolation.
* does not require any interpolation, it only needs to read
* the values from the nodes.
*/
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void gather_vector_field_qdsmc(const amrex::ParticleReal x0p,
Expand Down Expand Up @@ -106,7 +107,9 @@ void push_qdsmc_particle(const amrex::ParticleReal x0p,
*/
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void do_deposit_scalar(amrex::Array4<amrex::Real> const& scalar_field,
const amrex::ParticleReal xp, const amrex::ParticleReal yp, const amrex::ParticleReal zp,
const amrex::ParticleReal xp,
const amrex::ParticleReal yp,
const amrex::ParticleReal zp,
const amrex::XDim3 & xyzmin,
const amrex::XDim3 & dinv,
const amrex::ParticleReal valuep)
Expand Down
14 changes: 11 additions & 3 deletions Source/Fluids/WarpXFluidContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ void WarpXFluidContainer::HybridInitializeKe (ablastr::fields::MultiFabRegister&
{
using warpx::fields::FieldType;
ablastr::fields::ScalarField rho_fp = fields.get(FieldType::rho_fp, lev);

#ifdef AMREX_USE_OMP
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
#endif
Expand All @@ -1492,7 +1492,8 @@ void WarpXFluidContainer::HybridInitializeKe (ablastr::fields::MultiFabRegister&

ParallelFor(tilebox, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
if( rho(i, j, k) > 0.0_rt ){
Ke(i, j, k) = Te(i, j, k)*std::pow((rho(i, j, k)/PhysConst::q_e), 1-gamma);
amrex::Real ne = rho(i, j, k)/PhysConst::q_e;
Ke(i, j, k) = Te(i, j, k)*std::pow(ne, 1-gamma);
}
});
}
Expand All @@ -1504,6 +1505,11 @@ void WarpXFluidContainer::HybridUpdateTe (ablastr::fields::MultiFabRegister& fie
using warpx::fields::FieldType;
ablastr::fields::ScalarField rho_fp = fields.get(FieldType::rho_fp, lev);

WarpX &warpx = WarpX::GetInstance();
const amrex::Geometry &geom = warpx.Geom(lev);
const auto dx = geom.CellSizeArray();
const auto cell_volume = dx[0]*dx[1]*dx[2];

#ifdef AMREX_USE_OMP
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
#endif
Expand All @@ -1518,7 +1524,9 @@ void WarpXFluidContainer::HybridUpdateTe (ablastr::fields::MultiFabRegister& fie
ParallelFor(tilebox, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
Te(i, j, k) = 0;
if( rho(i, j, k) > 0.0_rt ){
Te(i, j, k) = Ke(i, j, k)*std::pow((rho(i, j, k)/PhysConst::q_e), gamma-1)*PhysConst::q_e;
amrex::Real ne = rho(i, j, k)/PhysConst::q_e;
amrex::Real N_cell = ne*cell_volume;
Te(i, j, k) = (Ke(i, j, k)/std::pow(ne, 1-gamma))/N_cell;
}
});
}
Expand Down

0 comments on commit 277dafd

Please sign in to comment.