Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default initialization of runtime attributes. #4508

Merged
merged 20 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Examples/Tests/ionization/analysis_ionization.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,13 @@

assert( error_rel < tolerance_rel )

# Check that the user runtime component (if it exists) worked as expected
try:
orig_z = ad['electrons', 'particle_orig_z'].v
assert np.all( (orig_z > 0) & (orig_z < 1.5e-5) )
print('particle_orig_z has reasonable values')
except yt.utilities.exceptions.YTFieldNotFound:
pass # Some of the tested script to not have the quantity orig_z

test_name = os.path.split(os.getcwd())[1]
checksumAPI.evaluate_checksum(test_name, filename)
2 changes: 2 additions & 0 deletions Examples/Tests/ionization/inputs_2d_rt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ ions.physical_element = N
electrons.mass = m_e
electrons.charge = -q_e
electrons.injection_style = none
electrons.addRealAttributes = orig_z
electrons.attribute.orig_z(x,y,z,ux,uy,uz,t) = z

lasers.names = laser1
laser1.profile = Gaussian
Expand Down
1 change: 1 addition & 0 deletions Regression/Checksum/benchmarks_json/ionization_lab.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"particle_momentum_x": 4.407898469197755e-18,
"particle_momentum_y": 0.0,
"particle_momentum_z": 2.642991174223682e-18,
"particle_orig_z": 0.43016526372226926,
"particle_position_x": 0.1095015206652257,
"particle_position_y": 0.6413864600981052,
"particle_weight": 3.443203125e-10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ void BackgroundMCCCollision::doBackgroundIonization
m_mass1, sqrt_kb_m, m_background_temperature_func, t
);

const auto num_added = filterCopyTransformParticles<1>(
const auto num_added = filterCopyTransformParticles<1>(species1, species2,
elec_tile, ion_tile, elec_tile, np_elec, np_ion,
Filter, CopyElec, CopyIon, Transform
);
Expand Down
10 changes: 7 additions & 3 deletions Source/Particles/Collision/BinaryCollision/BinaryCollision.H
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public:

amrex::LayoutData<amrex::Real>* cost = WarpX::getCosts(lev);

// Loop over all grids/tiles at this level
// Loop over all grids/tiles at this level
#ifdef AMREX_USE_OMP
info.SetDynamic(true);
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
Expand Down Expand Up @@ -367,7 +367,9 @@ public:
// Create the new product particles and define their initial values
// num_added: how many particles of each product species have been created
const amrex::Vector<int> num_added = m_copy_transform_functor(n_total_pairs,
soa_1, soa_1, tile_products_data,
soa_1, soa_1,
product_species_vector,
tile_products_data,
particle_ptr_1, particle_ptr_1, m1, m1,
products_mass, p_mask, products_np,
copy_species1, copy_species2,
Expand Down Expand Up @@ -528,7 +530,9 @@ public:
// Create the new product particles and define their initial values
// num_added: how many particles of each product species have been created
const amrex::Vector<int> num_added = m_copy_transform_functor(n_total_pairs,
soa_1, soa_2, tile_products_data,
soa_1, soa_2,
product_species_vector,
tile_products_data,
particle_ptr_1, particle_ptr_2, m1, m2,
products_mass, p_mask, products_np,
copy_species1, copy_species2,
Expand Down
23 changes: 23 additions & 0 deletions Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public:
amrex::Vector<int> operator() (
const index_type& n_total_pairs,
const SoaData_type& soa_1, const SoaData_type& soa_2,
const amrex::Vector<WarpXParticleContainer*>& pc_products,
ParticleTileType** AMREX_RESTRICT tile_products,
ParticleType* particle_ptr_1, ParticleType* particle_ptr_2,
const amrex::ParticleReal& m1, const amrex::ParticleReal& m2,
Expand Down Expand Up @@ -251,6 +252,27 @@ public:
}
});

// Initialize the user runtime components
for (int i = 0; i < m_num_product_species; i++)
{
int start_index = int(products_np[i]);
int stop_index = int(products_np[i] + num_added_vec[i]);
ParticleCreation::DefaultInitializeRuntimeAttributes(*tile_products[i],
0, 0,
pc_products[i]->getUserRealAttribs(), pc_products[i]->getUserIntAttribs(),
pc_products[i]->getParticleComps(), pc_products[i]->getParticleiComps(),
pc_products[i]->getUserRealAttribParser(),
pc_products[i]->getUserIntAttribParser(),
#ifdef WARPX_QED
false, // do not initialize QED quantities, since they were initialized
// when calling the SmartCopy functors
pc_products[i]->get_breit_wheeler_engine_ptr(),
pc_products[i]->get_quantum_sync_engine_ptr(),
#endif
pc_products[i]->getIonizationInitialLevel(),
start_index, stop_index);
}

amrex::Gpu::synchronize();

return num_added_vec;
Expand Down Expand Up @@ -289,6 +311,7 @@ public:
amrex::Vector<int> operator() (
const index_type& /*n_total_pairs*/,
const SoaData_type& /*soa_1*/, const SoaData_type& /*soa_2*/,
amrex::Vector<WarpXParticleContainer*>& /*pc_products*/,
ParticleTileType** /*tile_products*/,
ParticleType* /*particle_ptr_1*/, ParticleType* /*particle_ptr_2*/,
const amrex::ParticleReal& /*m1*/, const amrex::ParticleReal& /*m2*/,
Expand Down
3 changes: 1 addition & 2 deletions Source/Particles/LaserParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public:
amrex::ParticleTile<amrex::Particle<NStructReal, NStructInt>,
NArrayReal, NArrayInt, amrex::PinnedArenaAllocator>& /*pinned_tile*/,
const int /*n_external_attr_real*/,
const int /*n_external_attr_int*/,
const amrex::RandomEngine& /*engine*/) final {}
const int /*n_external_attr_int*/) final {}

void ReadHeader (std::istream& is) final;

Expand Down
8 changes: 4 additions & 4 deletions Source/Particles/MultiParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ MultiParticleContainer::doFieldIonization (int lev,
Bx[pti], By[pti], Bz[pti]);

const auto np_dst = dst_tile.numParticles();
const auto num_added = filterCopyTransformParticles<1>(dst_tile, src_tile, np_dst,
const auto num_added = filterCopyTransformParticles<1>(*pc_product, dst_tile, src_tile, np_dst,
Filter, Copy, Transform);

setNewParticleIDs(dst_tile, np_dst, num_added);
Expand Down Expand Up @@ -1383,7 +1383,7 @@ MultiParticleContainer::doQEDSchwinger ()

const auto Transform = SchwingerTransformFunc{m_qed_schwinger_y_size, PIdx::w};

const auto num_added = filterCreateTransformFromFAB<1>( dst_ele_tile,
const auto num_added = filterCreateTransformFromFAB<1>( *pc_product_ele, *pc_product_pos, dst_ele_tile,
dst_pos_tile, box, fieldsEB, np_ele_dst,
np_pos_dst,Filter, CreateEle, CreatePos,
Transform);
Expand Down Expand Up @@ -1536,7 +1536,7 @@ void MultiParticleContainer::doQedBreitWheeler (int lev,

const auto np_dst_ele = dst_ele_tile.numParticles();
const auto np_dst_pos = dst_pos_tile.numParticles();
const auto num_added = filterCopyTransformParticles<1>(
const auto num_added = filterCopyTransformParticles<1>(*pc_product_ele, *pc_product_pos,
dst_ele_tile, dst_pos_tile,
src_tile, np_dst_ele, np_dst_pos,
Filter, CopyEle, CopyPos, Transform);
Expand Down Expand Up @@ -1616,7 +1616,7 @@ void MultiParticleContainer::doQedQuantumSync (int lev,
const auto np_dst = dst_tile.numParticles();

const auto num_added =
filterCopyTransformParticles<1>(dst_tile, src_tile, np_dst,
filterCopyTransformParticles<1>(*pc_product_phot, dst_tile, src_tile, np_dst,
Filter, CopyPhot, Transform);

setNewParticleIDs(dst_tile, np_dst, num_added);
Expand Down
Loading
Loading