OPAL (Object Oriented Parallel Accelerator Library) 2022.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 "AmrObject.h"
25
27 : AmrObject(CHARGE_DENSITY, 0.75, 1.0e-15)
28{ }
29
30
32 double scaling,
33 double chargedensity)
34 : tagging_m(tagging)
35 , scaling_m(scaling)
36 , chargedensity_m(chargedensity)
37 , maxNumPart_m(1)
38 , minNumPart_m(1)
39 , refined_m(false)
40 , amrSolveTimer_m(IpplTimings::getTimer("AMR solve"))
41 , amrRegridTimer_m(IpplTimings::getTimer("AMR regrid"))
42{ }
43
44
46{ }
47
48
50 tagging_m = tagging;
51}
52
53
54void AmrObject::setTagging(const std::string& tagging) {
55 if ( tagging == "POTENTIAL" )
56 tagging_m = TaggingCriteria::POTENTIAL;
57 else if (tagging == "EFIELD" )
58 tagging_m = TaggingCriteria::EFIELD;
59 else if ( tagging == "MOMENTA" )
60 tagging_m = TaggingCriteria::MOMENTA;
61 else if ( tagging == "MAX_NUM_PARTICLES" )
62 tagging_m = TaggingCriteria::MAX_NUM_PARTICLES;
63 else if ( tagging == "MIN_NUM_PARTICLES" )
64 tagging_m = TaggingCriteria::MIN_NUM_PARTICLES;
65 else if ( tagging == "CHARGE_DENSITY" )
66 tagging_m = TaggingCriteria::CHARGE_DENSITY;
67 else
68 throw OpalException("AmrObject::setTagging(std::string)",
69 "Not supported refinement criteria "
70 "[CHARGE_DENSITY | POTENTIAL | EFIELD | "
71 "MOMENTA | MAX_NUM_PARTICLES | MIN_NUM_PARTICLES].");
72}
73
74
75void AmrObject::setScalingFactor(double scaling) {
76 scaling_m = scaling;
77}
78
79
80void AmrObject::setChargeDensity(double chargedensity) {
81 chargedensity_m = chargedensity;
82}
83
84
85void AmrObject::setMaxNumParticles(size_t maxNumPart) {
86 maxNumPart_m = maxNumPart;
87}
88
89
90void AmrObject::setMinNumParticles(size_t minNumPart) {
91 minNumPart_m = minNumPart;
92}
93
94
95const bool& AmrObject::isRefined() const {
96 return refined_m;
97}
98
99
100std::string AmrObject::enum2string(int number) {
101 std::string tagging;
102 switch ( number ) {
103 case TaggingCriteria::CHARGE_DENSITY:
104 tagging = "CHARGE_DENSITY";
105 break;
106 case TaggingCriteria::POTENTIAL:
107 tagging = "POTENTIAL";
108 break;
109 case TaggingCriteria::EFIELD:
110 tagging = "EFIELD";
111 break;
112 case TaggingCriteria::MOMENTA:
113 tagging = "MOMENTA";
114 break;
115 case TaggingCriteria::MIN_NUM_PARTICLES:
116 tagging = "MIN_NUM_PARTICLES";
117 break;
118 case TaggingCriteria::MAX_NUM_PARTICLES:
119 tagging = "MAX_NUM_PARTICLES";
120 break;
121 default:
122 throw OpalException("AmrObject::enum2string(int)",
123 "Only numbers between 0 and 5 allowed.");
124 }
125 return tagging;
126}
void setMinNumParticles(size_t minNumPart)
Definition: AmrObject.cpp:90
virtual ~AmrObject()
Definition: AmrObject.cpp:45
const bool & isRefined() const
Definition: AmrObject.cpp:95
void setScalingFactor(double scaling)
Definition: AmrObject.cpp:75
double scaling_m
Scaling factor for tagging [0, 1].
Definition: AmrObject.h:184
TaggingCriteria
Methods for tagging cells for refinement.
Definition: AmrObject.h:39
void setMaxNumParticles(size_t maxNumPart)
Definition: AmrObject.cpp:85
double chargedensity_m
Tagging value for CHARGE_DENSITY.
Definition: AmrObject.h:186
bool refined_m
Only set to true in AmrObject::initFineLevels()
Definition: AmrObject.h:192
TaggingCriteria tagging_m
Tagging strategy.
Definition: AmrObject.h:182
void setChargeDensity(double chargedensity)
Definition: AmrObject.cpp:80
static std::string enum2string(int number)
Definition: AmrObject.cpp:100
size_t minNumPart_m
Tagging value for MIN_NUM_PARTICLES.
Definition: AmrObject.h:190
void setTagging(TaggingCriteria tagging)
Definition: AmrObject.cpp:49
size_t maxNumPart_m
Tagging value for MAX_NUM_PARTICLES.
Definition: AmrObject.h:188
The base class for all OPAL exceptions.
Definition: OpalException.h:28