aboutsummaryrefslogtreecommitdiff
path: root/Source/Initialization/InjectorDensity.cpp
diff options
context:
space:
mode:
authorGravatar Weiqun Zhang <weiqunzhang@lbl.gov> 2019-07-24 19:43:18 -0700
committerGravatar Weiqun Zhang <weiqunzhang@lbl.gov> 2019-07-24 19:46:35 -0700
commitd59fa46d24417b67554132bc666e45886160bd09 (patch)
treea4148c8779e5840d35b7a88fe9e4bbad3e70d7f9 /Source/Initialization/InjectorDensity.cpp
parentdd40a0f5c5a234c27d2ca0b54d2936d6eec9a89c (diff)
downloadWarpX-d59fa46d24417b67554132bc666e45886160bd09.tar.gz
WarpX-d59fa46d24417b67554132bc666e45886160bd09.tar.zst
WarpX-d59fa46d24417b67554132bc666e45886160bd09.zip
Reimplement AddPlasma. Commits related to AddPlasma in hackathon
branch are squashed into one.
Diffstat (limited to 'Source/Initialization/InjectorDensity.cpp')
-rw-r--r--Source/Initialization/InjectorDensity.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/Source/Initialization/InjectorDensity.cpp b/Source/Initialization/InjectorDensity.cpp
new file mode 100644
index 000000000..f796180fd
--- /dev/null
+++ b/Source/Initialization/InjectorDensity.cpp
@@ -0,0 +1,71 @@
+#include <PlasmaInjector.H>
+
+using namespace amrex;
+
+InjectorDensity::~InjectorDensity ()
+{
+ switch (type)
+ {
+ case Type::parser:
+ {
+ object.parser.m_parser.clear();
+ break;
+ }
+ case Type::custom:
+ {
+ object.custom.clear();
+ break;
+ }
+ case Type::predefined:
+ {
+ object.predefined.clear();
+ break;
+ }
+ }
+}
+
+std::size_t
+InjectorDensity::sharedMemoryNeeded () const noexcept
+{
+ switch (type)
+ {
+ case Type::parser:
+ {
+ return amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double);
+ }
+ default:
+ return 0;
+ }
+}
+
+InjectorDensityPredefined::InjectorDensityPredefined (
+ std::string const& a_species_name) noexcept
+ : profile(Profile::null)
+{
+ ParmParse pp(a_species_name);
+
+ std::vector<amrex::Real> v;
+ pp.getarr("predefined_profile_params", v);
+ p = static_cast<amrex::Real*>
+ (amrex::The_Managed_Arena()->alloc(sizeof(amrex::Real)*v.size()));
+ for (int i = 0; i < static_cast<int>(v.size()); ++i) {
+ p[i] = v[i];
+ }
+
+ std::string which_profile_s;
+ pp.query("predefined_profile_name", which_profile_s);
+ std::transform(which_profile_s.begin(), which_profile_s.end(),
+ which_profile_s.begin(), ::tolower);
+ if (which_profile_s == "parabolic_channel"){
+ profile = Profile::parabolic_channel;
+ AMREX_ALWAYS_ASSERT_WITH_MESSAGE(v.size() > 6,
+ "InjectorDensityPredefined::parabolic_channel: not enough parameters");
+ }
+}
+
+// Note that we are not allowed to have non-trivial destructor.
+// So we rely on clear() to free memory.
+void InjectorDensityPredefined::clear ()
+{
+ amrex::The_Managed_Arena()->free(p);
+}