diff options
author | 2020-03-19 20:39:17 +0100 | |
---|---|---|
committer | 2020-03-19 12:39:17 -0700 | |
commit | 57011251fc0e5eac168e9a693c39ae6588db274c (patch) | |
tree | 23c5d07df89c50e6bc66d9c037a57e949b234d3e /Source/Particles/ParticleCreation/SmartUtils.cpp | |
parent | bb4871d077fcaa16e799a0f083ec447c34931552 (diff) | |
download | WarpX-57011251fc0e5eac168e9a693c39ae6588db274c.tar.gz WarpX-57011251fc0e5eac168e9a693c39ae6588db274c.tar.zst WarpX-57011251fc0e5eac168e9a693c39ae6588db274c.zip |
Add SmartCreate functor alongside SmartCopy (#825)
* created source files
* initial work to create SmartCreate
* Reorganized ParticleCreation and added SmartCreate.H
* add missing files
* added possibility to modify weight in SmartCreate
* bugfixing
* bugfixing
* bugfixing
* added comments and SmartCreateMode
* fixed comments
* removed template option
* removed unused includes
Diffstat (limited to 'Source/Particles/ParticleCreation/SmartUtils.cpp')
-rw-r--r-- | Source/Particles/ParticleCreation/SmartUtils.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Source/Particles/ParticleCreation/SmartUtils.cpp b/Source/Particles/ParticleCreation/SmartUtils.cpp new file mode 100644 index 000000000..eeff136a7 --- /dev/null +++ b/Source/Particles/ParticleCreation/SmartUtils.cpp @@ -0,0 +1,52 @@ +/* Copyright 2019-2020 Andrew Myers, Axel Huebl, + * Maxence Thevenet + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ +#include "SmartUtils.H" + +PolicyVec getPolicies (const NameMap& names) noexcept +{ + PolicyVec policies; + policies.resize(names.size()); + for (const auto& kv : names) + { + policies[kv.second] = initialization_policies[kv.first]; + } + return policies; +} + +SmartCopyTag getSmartCopyTag (const NameMap& src, const NameMap& dst) noexcept +{ + SmartCopyTag tag; + + // we use the fact that maps are sorted + auto i_src = src.begin(); + auto i_dst = dst.begin(); + while ( (i_src != src.end()) and (i_dst != dst.end()) ) + { + if (i_src->first < i_dst->first) + { + // names are not the same and src is lower + ++i_src; + } + else if (i_src->first > i_dst->first) + { + // names are not the same and dst is lower + ++i_dst; + } + else + { + // name is in both... + tag.common_names.push_back(i_src->first); + tag.src_comps.push_back(i_src->second); + tag.dst_comps.push_back(i_dst->second); + ++i_src; + ++i_dst; + } + } + + return tag; +} |