diff options
author | 2022-02-11 19:18:03 -0800 | |
---|---|---|
committer | 2022-02-11 19:18:03 -0800 | |
commit | 4a7d3b2944127d4f96147d886fbe12ae87928ab3 (patch) | |
tree | 14741109f8cb0abdab549b25ddd52cbdd6197820 /Source/Particles/PhysicalParticleContainer.cpp | |
parent | 5c3787d9c091adfcb463903e0e370c120b614ce5 (diff) | |
download | WarpX-4a7d3b2944127d4f96147d886fbe12ae87928ab3.tar.gz WarpX-4a7d3b2944127d4f96147d886fbe12ae87928ab3.tar.zst WarpX-4a7d3b2944127d4f96147d886fbe12ae87928ab3.zip |
User-defined integer and real particle attributes (#2735)
* define user attributes, parse them, initialize with respective parsers
* fix warning by using static_cast for int attribute as parser returns real
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* clean-up from self-review
* adding dimensionless velocity, gamma*v/c and time to parser argument
* add documentation
* typo in comment
* unused var
* device vector for kernels
* particle attribute in developer doc
* data ptr for device vector
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* ignore_unused
* Docs: Describe all particle attributes
including pre-defined ones :)
* Docs: Fix formatting (user params)
* Add: 1D and RZ Support
* Docs: Fix Typo in Function Declaration
* Laser-Ion Example: User-Defined Attrib.
Add two user-defined attributes to the laser-ion acceleration
example. This is a 2D test.
Documents the name in the table of commonly used, user-defined
attribute names. The attribute added is the original position
of particles, which I like to plot in "potential" plots that
correlate original position in the target with final energy.
* changing user-interface API with .attribute. and no need for separate 1D 2D 3D RZ code for parser. pos.x/y/z returns the right values
* Adding 1D, 3D, and rz tests
* attribute in inputs
* at(i)
* refinining names for inputs for laser ion and acceleration tests
* typo in input
* reset benchmarks for test-cases that included attributes
Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
Diffstat (limited to 'Source/Particles/PhysicalParticleContainer.cpp')
-rw-r--r-- | Source/Particles/PhysicalParticleContainer.cpp | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index d433c6120..4f2dfd54a 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -82,7 +82,7 @@ #include <AMReX_TinyProfiler.H> #include <AMReX_Utility.H> #include <AMReX_Vector.H> - +#include <AMReX_Parser.H> #ifdef AMREX_USE_OMP # include <omp.h> @@ -287,6 +287,32 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp } #endif + // User-defined integer attributes + pp_species_name.queryarr("addIntegerAttributes", m_user_int_attribs); + int n_user_int_attribs = m_user_int_attribs.size(); + std::vector< std::string > str_int_attrib_function; + str_int_attrib_function.resize(n_user_int_attribs); + m_user_int_attrib_parser.resize(n_user_int_attribs); + for (int i = 0; i < n_user_int_attribs; ++i) { + Store_parserString(pp_species_name, "attribute."+m_user_int_attribs.at(i)+"(x,y,z,ux,uy,uz,t)", str_int_attrib_function.at(i)); + m_user_int_attrib_parser.at(i) = std::make_unique<amrex::Parser>( + makeParser(str_int_attrib_function.at(i),{"x","y","z","ux","uy","uz","t"})); + AddIntComp(m_user_int_attribs.at(i)); + } + + // User-defined real attributes + pp_species_name.queryarr("addRealAttributes", m_user_real_attribs); + int n_user_real_attribs = m_user_real_attribs.size(); + std::vector< std::string > str_real_attrib_function; + str_real_attrib_function.resize(n_user_real_attribs); + m_user_real_attrib_parser.resize(n_user_real_attribs); + for (int i = 0; i < n_user_real_attribs; ++i) { + Store_parserString(pp_species_name, "attribute."+m_user_real_attribs.at(i)+"(x,y,z,ux,uy,uz,t)", str_real_attrib_function.at(i)); + m_user_real_attrib_parser.at(i) = std::make_unique<amrex::Parser>( + makeParser(str_real_attrib_function.at(i),{"x","y","z","ux","uy","uz","t"})); + AddRealComp(m_user_real_attribs.at(i)); + } + // If old particle positions should be saved add the needed components pp_species_name.query("save_previous_position", m_save_previous_position); if (m_save_previous_position) { @@ -903,6 +929,26 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) for (int ia = 0; ia < PIdx::nattribs; ++ia) { pa[ia] = soa.GetRealData(ia).data() + old_size; } + // user-defined integer and real attributes + const int n_user_int_attribs = m_user_int_attribs.size(); + const int n_user_real_attribs = m_user_real_attribs.size(); + amrex::Gpu::DeviceVector<int*> pa_user_int(n_user_int_attribs); + amrex::Gpu::DeviceVector<ParticleReal*> pa_user_real(n_user_real_attribs); + amrex::Gpu::DeviceVector< amrex::ParserExecutor<7> > user_int_attrib_parserexec(n_user_int_attribs); + amrex::Gpu::DeviceVector< amrex::ParserExecutor<7> > user_real_attrib_parserexec(n_user_real_attribs); + for (int ia = 0; ia < n_user_int_attribs; ++ia) { + pa_user_int[ia] = soa.GetIntData(particle_icomps[m_user_int_attribs[ia]]).data() + old_size; + user_int_attrib_parserexec[ia] = m_user_int_attrib_parser[ia]->compile<7>(); + } + for (int ia = 0; ia < n_user_real_attribs; ++ia) { + pa_user_real[ia] = soa.GetRealData(particle_comps[m_user_real_attribs[ia]]).data() + old_size; + user_real_attrib_parserexec[ia] = m_user_real_attrib_parser[ia]->compile<7>(); + } + int** pa_user_int_data = pa_user_int.dataPtr(); + ParticleReal** pa_user_real_data = pa_user_real.dataPtr(); + amrex::ParserExecutor<7> const* user_int_parserexec_data = user_int_attrib_parserexec.dataPtr(); + amrex::ParserExecutor<7> const* user_real_parserexec_data = user_real_attrib_parserexec.dataPtr(); + int* pi = nullptr; if (do_field_ionization) { @@ -1114,6 +1160,14 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) p_optical_depth_BW[ip] = breit_wheeler_get_opt(engine); } #endif + // Initialize user-defined integers with user-defined parser + for (int ia = 0; ia < n_user_int_attribs; ++ia) { + pa_user_int_data[ia][ip] = static_cast<int>(user_int_parserexec_data[ia](pos.x, pos.y, pos.z, u.x, u.y, u.z, t)); + } + // Initialize user-defined real attributes with user-defined parser + for (int ia = 0; ia < n_user_real_attribs; ++ia) { + pa_user_real_data[ia][ip] = user_real_parserexec_data[ia](pos.x, pos.y, pos.z, u.x, u.y, u.z, t); + } u.x *= PhysConst::c; u.y *= PhysConst::c; |