aboutsummaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/Particles/ParticleCreation/ElementaryProcess.H1
-rw-r--r--Source/Particles/ParticleCreation/Make.package2
-rw-r--r--Source/Particles/ParticleCreation/SmartCopy.H21
-rw-r--r--Source/Particles/ParticleCreation/SmartCopy.cpp34
4 files changed, 58 insertions, 0 deletions
diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.H b/Source/Particles/ParticleCreation/ElementaryProcess.H
index f9f4ad8b1..bd9342e46 100644
--- a/Source/Particles/ParticleCreation/ElementaryProcess.H
+++ b/Source/Particles/ParticleCreation/ElementaryProcess.H
@@ -5,6 +5,7 @@
#include "CopyParticle.H"
#include "TransformParticle.H"
#include "DefaultInitialization.H"
+#include "SmartCopy.H"
/**
* \brief Base class for particle creation processes
diff --git a/Source/Particles/ParticleCreation/Make.package b/Source/Particles/ParticleCreation/Make.package
index 9d3e328dd..53c57c231 100644
--- a/Source/Particles/ParticleCreation/Make.package
+++ b/Source/Particles/ParticleCreation/Make.package
@@ -2,6 +2,8 @@ CEXE_headers += ElementaryProcess.H
CEXE_headers += CopyParticle.H
CEXE_headers += TransformParticle.H
CEXE_headers += DefaultInitialization.H
+CEXE_headers += SmartCopy.H
+CEXE_sources += SmartCopy.cpp
INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Particles/ParticleCreation/
VPATH_LOCATIONS += $(WARPX_HOME)/Source/Particles/ParticleCreation/
diff --git a/Source/Particles/ParticleCreation/SmartCopy.H b/Source/Particles/ParticleCreation/SmartCopy.H
new file mode 100644
index 000000000..f60e2aba3
--- /dev/null
+++ b/Source/Particles/ParticleCreation/SmartCopy.H
@@ -0,0 +1,21 @@
+#ifndef SMART_COPY_H_
+#define SMART_COPY_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+using NameMap = std::map<std::string, int>;
+
+struct SmartCopyTag
+{
+ std::vector<std::string> common_names;
+ std::vector<int> src_comps;
+ std::vector<int> dst_comps;
+
+ int size () const noexcept { return common_names.size(); }
+};
+
+SmartCopyTag getSmartCopyTag (const NameMap& src, const NameMap& dst);
+
+#endif
diff --git a/Source/Particles/ParticleCreation/SmartCopy.cpp b/Source/Particles/ParticleCreation/SmartCopy.cpp
new file mode 100644
index 000000000..eaaa817eb
--- /dev/null
+++ b/Source/Particles/ParticleCreation/SmartCopy.cpp
@@ -0,0 +1,34 @@
+#include "SmartCopy.H"
+
+SmartCopyTag getSmartCopyTag (const NameMap& src, const NameMap& dst)
+{
+ 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;
+}