Skip to content

Commit

Permalink
Support time-dependent densition function
Browse files Browse the repository at this point in the history
Fix compilation errors

Fix compilation
  • Loading branch information
RemiLehe committed May 4, 2023
1 parent 18fcea2 commit 1d8cd57
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Source/Initialization/CustomDensityProb.H
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct InjectorDensityCustom
// stored in p.
AMREX_GPU_HOST_DEVICE
amrex::Real
getDensity (amrex::Real, amrex::Real, amrex::Real) const noexcept
getDensity (amrex::Real, amrex::Real, amrex::Real, amrex::Real) const noexcept
{
return p[0];
}
Expand Down
26 changes: 13 additions & 13 deletions Source/Initialization/InjectorDensity.H
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct InjectorDensityConstant

AMREX_GPU_HOST_DEVICE
amrex::Real
getDensity (amrex::Real, amrex::Real, amrex::Real) const noexcept
getDensity (amrex::Real, amrex::Real, amrex::Real, amrex::Real) const noexcept
{
return m_rho;
}
Expand All @@ -41,17 +41,17 @@ private:
// struct whose getDensity returns local density computed from parser.
struct InjectorDensityParser
{
InjectorDensityParser (amrex::ParserExecutor<3> const& a_parser) noexcept
InjectorDensityParser (amrex::ParserExecutor<4> const& a_parser) noexcept
: m_parser(a_parser) {}

AMREX_GPU_HOST_DEVICE
amrex::Real
getDensity (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept
getDensity (amrex::Real x, amrex::Real y, amrex::Real z, amrex::Real t) const noexcept
{
return m_parser(x,y,z);
return m_parser(x,y,z,t);
}

amrex::ParserExecutor<3> m_parser;
amrex::ParserExecutor<4> m_parser;
};

// struct whose getDensity returns local density computed from predefined profile.
Expand All @@ -63,7 +63,7 @@ struct InjectorDensityPredefined

AMREX_GPU_HOST_DEVICE
amrex::Real
getDensity (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept
getDensity (amrex::Real x, amrex::Real y, amrex::Real z, amrex::Real t) const noexcept
{
// Choices for profile are:
// - parabolic_channel
Expand Down Expand Up @@ -134,7 +134,7 @@ struct InjectorDensity
{ }

// This constructor stores a InjectorDensityParser in union object.
InjectorDensity (InjectorDensityParser* t, amrex::ParserExecutor<3> const& a_parser)
InjectorDensity (InjectorDensityParser* t, amrex::ParserExecutor<4> const& a_parser)
: type(Type::parser),
object(t,a_parser)
{ }
Expand Down Expand Up @@ -164,25 +164,25 @@ struct InjectorDensity
// (the union is called Object, and the instance is called object).
AMREX_GPU_HOST_DEVICE
amrex::Real
getDensity (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept
getDensity (amrex::Real x, amrex::Real y, amrex::Real z, amrex::Real t) const noexcept
{
switch (type)
{
case Type::parser:
{
return object.parser.getDensity(x,y,z);
return object.parser.getDensity(x,y,z,t);
}
case Type::constant:
{
return object.constant.getDensity(x,y,z);
return object.constant.getDensity(x,y,z,t);
}
case Type::custom:
{
return object.custom.getDensity(x,y,z);
return object.custom.getDensity(x,y,z,t);
}
case Type::predefined:
{
return object.predefined.getDensity(x,y,z);
return object.predefined.getDensity(x,y,z,t);
}
default:
{
Expand All @@ -201,7 +201,7 @@ private:
union Object {
Object (InjectorDensityConstant*, amrex::Real a_rho) noexcept
: constant(a_rho) {}
Object (InjectorDensityParser*, amrex::ParserExecutor<3> const& a_parser) noexcept
Object (InjectorDensityParser*, amrex::ParserExecutor<4> const& a_parser) noexcept
: parser(a_parser) {}
Object (InjectorDensityCustom*, std::string const& a_species_name) noexcept
: custom(a_species_name) {}
Expand Down
4 changes: 2 additions & 2 deletions Source/Initialization/PlasmaInjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ void PlasmaInjector::parseDensity (amrex::ParmParse& pp)
pp, "density_function(x,y,z)", str_density_function);
// Construct InjectorDensity with InjectorDensityParser.
density_parser = std::make_unique<amrex::Parser>(
utils::parser::makeParser(str_density_function,{"x","y","z"}));
utils::parser::makeParser(str_density_function,{"x","y","z","t"}));
h_inj_rho.reset(new InjectorDensity((InjectorDensityParser*)nullptr,
density_parser->compile<3>()));
density_parser->compile<4>()));
} else {
//No need for profile definition if external file is used
std::string injection_style = "none";
Expand Down
8 changes: 4 additions & 4 deletions Source/Particles/PhysicalParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox)
for (const auto& x : xlim)
for (const auto& y : ylim)
for (const auto& z : zlim)
if (inj_pos->insideBounds(x,y,z) and (inj_rho->getDensity(x,y,z) > 0) ) {
if (inj_pos->insideBounds(x,y,z) and (inj_rho->getDensity(x,y,z,0) > 0) ) {
return 1;
}
return 0;
Expand Down Expand Up @@ -1281,7 +1281,7 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox)
}

u = inj_mom->getMomentum(pos.x, pos.y, z0, engine);
dens = inj_rho->getDensity(pos.x, pos.y, z0);
dens = inj_rho->getDensity(pos.x, pos.y, z0, 0);

// Remove particle if density below threshold
if ( dens < density_min ){
Expand Down Expand Up @@ -1312,7 +1312,7 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox)
continue;
}
// call `getDensity` with lab-frame parameters
dens = inj_rho->getDensity(pos.x, pos.y, z0_lab);
dens = inj_rho->getDensity(pos.x, pos.y, z0_lab, 0);
// Remove particle if density below threshold
if ( dens < density_min ){
ZeroInitializeAndSetNegativeID(p, pa, ip, loc_do_field_ionization, pi
Expand Down Expand Up @@ -1812,7 +1812,7 @@ PhysicalParticleContainer::AddPlasmaFlux (amrex::Real dt)
pu.y = sin_theta*ur + cos_theta*ut;
}
#endif
Real dens = inj_rho->getDensity(ppos.x, ppos.y, ppos.z);
Real dens = inj_rho->getDensity(ppos.x, ppos.y, ppos.z, t);
// Remove particle if density below threshold
if ( dens < density_min ){
p.id() = -1;
Expand Down

0 comments on commit 1d8cd57

Please sign in to comment.