Skip to content

Commit

Permalink
Progres Fixing Tests...
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Jan 10, 2025
1 parent cfc39f4 commit 76deb19
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 81 deletions.
13 changes: 8 additions & 5 deletions Source/Particles/MultiParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,23 +415,29 @@ MultiParticleContainer::AllocData ()
void
MultiParticleContainer::InitData ()
{
InitMultiPhysicsModules();

for (auto& pc : allcontainers) {
pc->InitData();
}
pc_tmp->InitData();

InitMultiPhysicsModules();
// Setup particle collisions
collisionhandler = std::make_unique<CollisionHandler>(this);
}

void
MultiParticleContainer::PostRestart ()
{
InitMultiPhysicsModules();

for (auto& pc : allcontainers) {
pc->PostRestart();
}
pc_tmp->PostRestart();

InitMultiPhysicsModules();
// Setup particle collisions
collisionhandler = std::make_unique<CollisionHandler>(this);
}

void
Expand All @@ -450,9 +456,6 @@ MultiParticleContainer::InitMultiPhysicsModules ()
InitQED();
CheckQEDProductSpecies();
#endif

// Setup particle collisions
collisionhandler = std::make_unique<CollisionHandler>(this);
}

void
Expand Down
4 changes: 2 additions & 2 deletions Source/Particles/ParticleCreation/DefaultInitialization.H
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ amrex::ParticleReal initializeRealValue (const InitializationPolicy policy, amre
return -std::log(amrex::Random(engine));
}
default : {
amrex::Abort("Initialization Policy not recognized");
throw std::runtime_error("Initialization Policy not recognized: " + std::to_string(int(policy)));
return 1.0;
}
}
Expand All @@ -81,7 +81,7 @@ int initializeIntValue (const InitializationPolicy policy) noexcept
case InitializationPolicy::Zero : return 0;
case InitializationPolicy::One : return 1;
default : {
amrex::Abort("Initialization Policy not recognized");
throw std::runtime_error("Initialization Policy not recognized");
return 1;
}
}
Expand Down
1 change: 1 addition & 0 deletions Source/Particles/ParticleCreation/SmartUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ PolicyVec getPolicies (const NameMap& names) noexcept
h_policies.resize(names.size());
for (const auto& kv : names)
{
//amrex::Print() << "getPolicies: " << kv.first << " " << kv.second << std::endl;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
h_policies[kv.second] = initialization_policies[kv.first];
}

Expand Down
159 changes: 85 additions & 74 deletions Source/Particles/PhysicalParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,90 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core,
species_name(name)
{
BackwardCompatibility();

const ParmParse pp_species_name(species_name);

// species type
{
// Setup the charge and mass. There are multiple ways that they can be specified, so checks are needed to
// ensure that a value is specified and warnings given if multiple values are specified.
// The ordering is that species.charge and species.mass take precedence over all other values.
// Next is charge and mass determined from species_type.
// Last is charge and mass from the plasma injector setup
bool charge_from_source = false;
bool mass_from_source = false;
for (auto const& plasma_injector : plasma_injectors) {
// For now, use the last value for charge and mass that is found.
// A check could be added for consistency of multiple values, but it'll probably never be needed
charge_from_source |= plasma_injector->queryCharge(charge);
mass_from_source |= plasma_injector->queryMass(mass);
}

std::string physical_species_s;
const bool species_is_specified = pp_species_name.query("species_type", physical_species_s);
if (species_is_specified) {
const auto physical_species_from_string = species::from_string( physical_species_s );
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(physical_species_from_string,
physical_species_s + " does not exist!");
physical_species = physical_species_from_string.value();
charge = species::get_charge( physical_species );
mass = species::get_mass( physical_species );
}

// parse charge and mass (overriding values of an earlier species type)
const bool charge_is_specified = utils::parser::queryWithParser(pp_species_name, "charge", charge);
const bool mass_is_specified = utils::parser::queryWithParser(pp_species_name, "mass", mass);

if (charge_is_specified && species_is_specified) {
ablastr::warn_manager::WMRecordWarning("Species",
"Both '" + species_name + ".charge' and " +
species_name + ".species_type' are specified.\n" +
species_name + ".charge' will take precedence.\n");
}
if (mass_is_specified && species_is_specified) {
ablastr::warn_manager::WMRecordWarning("Species",
"Both '" + species_name + ".mass' and " +
species_name + ".species_type' are specified.\n" +
species_name + ".mass' will take precedence.\n");
}

WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
charge_from_source ||
charge_is_specified ||
species_is_specified,
"Need to specify at least one of species_type or charge for species '" +
species_name + "'."
);

WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
mass_from_source ||
mass_is_specified ||
species_is_specified,
"Need to specify at least one of species_type or mass for species '" +
species_name + "'."
);
}

// add runtime components
{
pp_species_name.query("do_field_ionization", do_field_ionization);
if (do_field_ionization) {
// Add runtime integer component for ionization level
NewIntComp("ionizationLevel");
}

#ifdef WARPX_QED
pp_species_name.query("do_qed_quantum_sync", m_do_qed_quantum_sync);
if (m_do_qed_quantum_sync) {
NewRealComp("opticalDepthQSR");
}

if (m_do_qed_quantum_sync) {
pp_species_name.get("qed_quantum_sync_phot_product_species",
m_qed_quantum_sync_phot_product_name);
}
#endif
}
}

PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core)
Expand Down Expand Up @@ -266,64 +350,6 @@ void PhysicalParticleContainer::InitData ()
source_name));
}

// Setup the charge and mass. There are multiple ways that they can be specified, so checks are needed to
// ensure that a value is specified and warnings given if multiple values are specified.
// The ordering is that species.charge and species.mass take precedence over all other values.
// Next is charge and mass determined from species_type.
// Last is charge and mass from the plasma injector setup
bool charge_from_source = false;
bool mass_from_source = false;
for (auto const& plasma_injector : plasma_injectors) {
// For now, use the last value for charge and mass that is found.
// A check could be added for consistency of multiple values, but it'll probably never be needed
charge_from_source |= plasma_injector->queryCharge(charge);
mass_from_source |= plasma_injector->queryMass(mass);
}

std::string physical_species_s;
const bool species_is_specified = pp_species_name.query("species_type", physical_species_s);
if (species_is_specified) {
const auto physical_species_from_string = species::from_string( physical_species_s );
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(physical_species_from_string,
physical_species_s + " does not exist!");
physical_species = physical_species_from_string.value();
charge = species::get_charge( physical_species );
mass = species::get_mass( physical_species );
}

// parse charge and mass (overriding values above)
const bool charge_is_specified = utils::parser::queryWithParser(pp_species_name, "charge", charge);
const bool mass_is_specified = utils::parser::queryWithParser(pp_species_name, "mass", mass);

if (charge_is_specified && species_is_specified) {
ablastr::warn_manager::WMRecordWarning("Species",
"Both '" + species_name + ".charge' and " +
species_name + ".species_type' are specified.\n" +
species_name + ".charge' will take precedence.\n");
}
if (mass_is_specified && species_is_specified) {
ablastr::warn_manager::WMRecordWarning("Species",
"Both '" + species_name + ".mass' and " +
species_name + ".species_type' are specified.\n" +
species_name + ".mass' will take precedence.\n");
}

WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
charge_from_source ||
charge_is_specified ||
species_is_specified,
"Need to specify at least one of species_type or charge for species '" +
species_name + "'."
);

WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
mass_from_source ||
mass_is_specified ||
species_is_specified,
"Need to specify at least one of species_type or mass for species '" +
species_name + "'."
);

pp_species_name.query("boost_adjust_transverse_positions", boost_adjust_transverse_positions);
pp_species_name.query("do_backward_propagation", do_backward_propagation);
pp_species_name.query("random_theta", m_rz_random_theta);
Expand All @@ -345,8 +371,6 @@ void PhysicalParticleContainer::InitData ()
pp_species_name, "self_fields_max_iters", self_fields_max_iters);
pp_species_name.query("self_fields_verbosity", self_fields_verbosity);

pp_species_name.query("do_field_ionization", do_field_ionization);

pp_species_name.query("do_resampling", do_resampling);
if (do_resampling) { m_resampler = Resampling(species_name); }

Expand All @@ -368,18 +392,6 @@ void PhysicalParticleContainer::InitData ()
"Radiation reaction can be enabled only if Boris pusher is used");
//_____________________________

#ifdef WARPX_QED
pp_species_name.query("do_qed_quantum_sync", m_do_qed_quantum_sync);
if (m_do_qed_quantum_sync) {
NewRealComp("opticalDepthQSR");
}

if (m_do_qed_quantum_sync){
pp_species_name.get("qed_quantum_sync_phot_product_species",
m_qed_quantum_sync_phot_product_name);
}
#endif

// User-defined integer attributes
pp_species_name.queryarr("addIntegerAttributes", m_user_int_attribs);
const auto n_user_int_attribs = static_cast<int>(m_user_int_attribs.size());
Expand Down Expand Up @@ -3118,8 +3130,7 @@ PhysicalParticleContainer::InitIonizationModule ()
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
physical_element == "H" || !do_adk_correction,
"Correction to ADK by Zhang et al., PRA 90, 043410 (2014) only works with Hydrogen");
// Add runtime integer component for ionization level
NewIntComp("ionizationLevel");

// Get atomic number and ionization energies from file
const int ion_element_id = utils::physics::ion_map_ids.at(physical_element);
ion_atomic_number = utils::physics::ion_atomic_numbers[ion_element_id];
Expand Down

0 comments on commit 76deb19

Please sign in to comment.