OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
AmrObject.cpp
Go to the documentation of this file.
1 //
2 // Class AmrObject
3 // The AMR interface to OPAL. A new AMR library needs
4 // to inherit from this class in order to work properly
5 // with OPAL. Among other things it specifies the refinement
6 // strategies.
7 //
8 // Copyright (c) 2016 - 2020, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
9 // All rights reserved
10 //
11 // Implemented as part of the PhD thesis
12 // "Precise Simulations of Multibunches in High Intensity Cyclotrons"
13 //
14 // This file is part of OPAL.
15 //
16 // OPAL is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
23 //
24 #include "Amr/AmrObject.h"
25 
27 
29  : AmrObject(TaggingCriteria::CHARGE_DENSITY, 0.75, 1.0e-15)
30 { }
31 
32 
34  double scaling,
35  double chargedensity)
36  : tagging_m(tagging)
37  , scaling_m(scaling)
38  , chargedensity_m(chargedensity)
39  , maxNumPart_m(1)
40  , minNumPart_m(1)
41  , refined_m(false)
42  , amrSolveTimer_m(IpplTimings::getTimer("AMR solve"))
43  , amrRegridTimer_m(IpplTimings::getTimer("AMR regrid"))
44 { }
45 
46 
48 { }
49 
50 
52  tagging_m = tagging;
53 }
54 
55 
56 void AmrObject::setTagging(const std::string& tagging) {
57  static const std::map<std::string, TaggingCriteria> stringTaggingCriteria_s = {
58  {"CHARGE_DENSITY", TaggingCriteria::CHARGE_DENSITY},
59  {"POTENTIAL", TaggingCriteria::POTENTIAL},
60  {"EFIELD", TaggingCriteria::EFIELD},
61  {"MOMENTA", TaggingCriteria::MOMENTA},
62  {"MIN_NUM_PARTICLES", TaggingCriteria::MIN_NUM_PARTICLES},
63  {"MAX_NUM_PARTICLES", TaggingCriteria::MAX_NUM_PARTICLES }
64  };
65 
66  if (stringTaggingCriteria_s.count(tagging)) {
67  tagging_m = stringTaggingCriteria_s.at(tagging);
68  } else {
69  throw OpalException("AmrObject::setTagging",
70  "Not supported refinement criteria.\n"
71  "Check the accepted values: "
72  "[CHARGE_DENSITY | POTENTIAL | EFIELD | "
73  "MOMENTA | MIN_NUM_PARTICLES | MAX_NUM_PARTICLES].");
74  }
75 }
76 
77 
78 void AmrObject::setScalingFactor(double scaling) {
79  scaling_m = scaling;
80 }
81 
82 
83 void AmrObject::setChargeDensity(double chargedensity) {
84  chargedensity_m = chargedensity;
85 }
86 
87 
88 void AmrObject::setMaxNumParticles(size_t maxNumPart) {
89  maxNumPart_m = maxNumPart;
90 }
91 
92 
93 void AmrObject::setMinNumParticles(size_t minNumPart) {
94  minNumPart_m = minNumPart;
95 }
96 
97 
98 const bool& AmrObject::isRefined() const {
99  return refined_m;
100 }
101 
102 
103 std::string AmrObject::getTaggingString(int number) {
104  std::string tagging;
105  switch ( number ) {
106  case static_cast<std::underlying_type_t<TaggingCriteria>>(TaggingCriteria::CHARGE_DENSITY):
107  tagging = "CHARGE_DENSITY";
108  break;
109  case static_cast<std::underlying_type_t<TaggingCriteria>>(TaggingCriteria::POTENTIAL):
110  tagging = "POTENTIAL";
111  break;
112  case static_cast<std::underlying_type_t<TaggingCriteria>>(TaggingCriteria::EFIELD):
113  tagging = "EFIELD";
114  break;
115  case static_cast<std::underlying_type_t<TaggingCriteria>>(TaggingCriteria::MOMENTA):
116  tagging = "MOMENTA";
117  break;
118  case static_cast<std::underlying_type_t<TaggingCriteria>>(TaggingCriteria::MIN_NUM_PARTICLES):
119  tagging = "MIN_NUM_PARTICLES";
120  break;
121  case static_cast<std::underlying_type_t<TaggingCriteria>>(TaggingCriteria::MAX_NUM_PARTICLES):
122  tagging = "MAX_NUM_PARTICLES";
123  break;
124  default:
125  throw OpalException("AmrObject::getTaggingString",
126  "Only numbers between 0 and 5 allowed.");
127  }
128  return tagging;
129 }
void setMinNumParticles(size_t minNumPart)
Definition: AmrObject.cpp:93
void setMaxNumParticles(size_t maxNumPart)
Definition: AmrObject.cpp:88
static std::string getTaggingString(int number)
Definition: AmrObject.cpp:103
void setTagging(TaggingCriteria tagging)
Definition: AmrObject.cpp:51
double scaling_m
Scaling factor for tagging [0, 1].
Definition: AmrObject.h:181
TaggingCriteria
Methods for tagging cells for refinement.
Definition: AmrObject.h:39
virtual ~AmrObject()
Definition: AmrObject.cpp:47
size_t minNumPart_m
Tagging value for MIN_NUM_PARTICLES.
Definition: AmrObject.h:187
The base class for all OPAL exceptions.
Definition: OpalException.h:28
TaggingCriteria tagging_m
Tagging strategy.
Definition: AmrObject.h:179
void setChargeDensity(double chargedensity)
Definition: AmrObject.cpp:83
const bool & isRefined() const
Definition: AmrObject.cpp:98
double chargedensity_m
Tagging value for CHARGE_DENSITY.
Definition: AmrObject.h:183
void setScalingFactor(double scaling)
Definition: AmrObject.cpp:78
size_t maxNumPart_m
Tagging value for MAX_NUM_PARTICLES.
Definition: AmrObject.h:185
constexpr double e
The value of .
Definition: Physics.h:39
bool refined_m
Only set to true in AmrObject::initFineLevels()
Definition: AmrObject.h:189