OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
FieldSolverCmd.cpp
Go to the documentation of this file.
1//
2// Class FieldSolverCmd
3// The class for the OPAL FIELDSOLVER command.
4// A FieldSolverCmd definition is used by most physics commands to define the
5// particle charge and the reference momentum, together with some other data.
6//
7// Copyright (c) 200x - 2022, Paul Scherrer Institut, Villigen PSI, Switzerland
8//
9// All rights reserved
10//
11// This file is part of OPAL.
12//
13// OPAL is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// You should have received a copy of the GNU General Public License
19// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20//
22
23#include <map>
24
31#include "Physics/Physics.h"
34
35using namespace Expressions;
36
37// TODO: o add a FIELD for DISCRETIZATION, MAXITERS, TOL...
38
40 : Definition(
41 FIELDSOLVER::SIZE, "FIELDSOLVER",
42 "The \"FIELDSOLVER\" statement defines data for a the field solver") {
44 "TYPE", "Name of the attached field solver.",
45 {"NONE", "FFT", "OPEN", "CG"}); // removed, since not implemented: "P3M"
46
48 "BINS", "Name of BINNING definition to be used, or NONE for no binning.", "NONE");
49
50 itsAttr[FIELDSOLVER::NX] = Attributes::makeReal("NX", "Meshsize in x");
51 itsAttr[FIELDSOLVER::NY] = Attributes::makeReal("NY", "Meshsize in y");
52 itsAttr[FIELDSOLVER::NZ] = Attributes::makeReal("NZ", "Meshsize in z");
53
55 Attributes::makeBool("PARFFTX", "True, dimension 0 i.e x is parallelized", false);
56
58 Attributes::makeBool("PARFFTY", "True, dimension 1 i.e y is parallelized", false);
59
61 Attributes::makeBool("PARFFTZ", "True, dimension 2 i.e z is parallelized", true);
62
64 "BCFFTX", "Boundary conditions in x.", {"OPEN", "DIRICHLET", "PERIODIC"}, "OPEN");
65
67 "BCFFTY", "Boundary conditions in y.", {"OPEN", "DIRICHLET", "PERIODIC"}, "OPEN");
68
70 "BCFFTZ", "Boundary conditions in z.", {"OPEN", "DIRICHLET", "PERIODIC"}, "OPEN");
71
73 "GREENSF", "Which Greensfunction to be used.", {"STANDARD", "INTEGRATED"},
74 "INTEGRATED");
75
77 Attributes::makeReal("BBOXINCR", "Increase of bounding box in % ", 2.0);
78
79 // \todo does not work registerOwnership(AttributeHandler::STATEMENT);
80}
81
82FieldSolverCmd::FieldSolverCmd(const std::string& name, FieldSolverCmd* parent)
83 : Definition(name, parent) {}
84
86
87FieldSolverCmd* FieldSolverCmd::clone(const std::string& name) {
88 return new FieldSolverCmd(name, this);
89}
90
95
96FieldSolverCmd* FieldSolverCmd::find(const std::string& name) {
97 FieldSolverCmd* fs = dynamic_cast<FieldSolverCmd*>(OpalData::getInstance()->find(name));
98
99 if (fs == 0) {
100 throw OpalException("FieldSolverCmd::find()", "FieldSolverCmd \"" + name + "\" not found.");
101 }
102 return fs;
103}
104
106
110
112 using BCH_t = BCHandler<3>;
113
114 BCH_t boundary_conditions(
118
120
124 if (!boundary_conditions.isAllEqual()) {
125 throw OpalException(
126 "PartBunch::PartBunch",
127 "Currently only uniform boundary conditions in all "
128 "dimensions are supported! Please set all "
129 "dimensions to either OPEN or PERIODIC.");
130 }
131
132 return boundary_conditions;
133}
134
136
138
140
142
144
146
150
153 fsName_m = getType();
154 }
155}
156
158 static const std::map<std::string, FieldSolverCmdType> stringType_s = {
159 {"NONE", FieldSolverCmdType::NONE},
161 {"OPEN", FieldSolverCmdType::OPEN},
162 {"CG", FieldSolverCmdType::CG}};
163
164 fsName_m = getType();
165
166 if (fsName_m.empty()) {
167 throw OpalException(
168 "FieldSolverCmd::setFieldSolverCmdType",
169 "The attribute \"TYPE\" isn't set for \"FIELDSOLVER\"!");
170 } else {
171 fsType_m = stringType_s.at(fsName_m);
172 }
173}
174
175bool FieldSolverCmd::hasValidSolver() { return false; }
176
178 const std::string binsName = getBinsName();
179 if (binsName == "NONE" || binsName.empty()) {
180 return nullptr;
181 }
182 return BinningCmd::find(binsName);
183}
184
185Inform& FieldSolverCmd::printInfo(Inform& os) const {
186 os << "* ************* F I E L D S O L V E R ********************************************** "
187 << endl;
188 os << "* FIELDSOLVER " << getOpalName() << '\n'
189 << "* BINS " << getBinsName() << '\n'
190 << "* TYPE " << fsName_m << '\n'
191 << "* RANKS " << ippl::Comm->size() << '\n'
192 << "* NX " << Attributes::getReal(itsAttr[FIELDSOLVER::NX]) << '\n'
193 << "* NY " << Attributes::getReal(itsAttr[FIELDSOLVER::NY]) << '\n'
194 << "* NZ " << Attributes::getReal(itsAttr[FIELDSOLVER::NZ]) << '\n'
195 << "* BBOXINCR " << Attributes::getReal(itsAttr[FIELDSOLVER::BBOXINCR]) << '\n'
196 << "* GREENSF " << Attributes::getString(itsAttr[FIELDSOLVER::GREENSF]) << endl;
197
199 os << "* XDIM parallel " << endl;
200 } else {
201 os << "* XDIM serial " << endl;
202 }
203
205 os << "* YDIM parallel " << endl;
206 } else {
207 os << "* YDIM serial " << endl;
208 }
209
211 os << "* ZDIM parallel " << endl;
212 } else {
213 os << "* ZDIM serial " << endl;
214 }
215
216 os << "* ********************************************************************************** "
217 << endl;
218 return os;
219}
@ SIZE
Definition IndexMap.cpp:179
Handler for boundary conditions per spatial dimension.
Definition BCHandler.hpp:29
static BinningCmd * find(const std::string &name)
Find named BINNING command.
The base class for all OPAL definitions.
Definition Definition.h:29
virtual void execute()
Execute (init) the field solver data.
BCHandler< 3 > constructBCHandler() const
Returns solver boundary conditions handler object.
virtual FieldSolverCmd * clone(const std::string &name)
Make clone.
FieldSolverCmdType fsType_m
static FieldSolverCmd * find(const std::string &name)
Find named FieldSolverCmd.
Inform & printInfo(Inform &os) const
void setNZ(double)
FieldSolverCmd()
Exemplar constructor.
double getNX() const
Return meshsize.
BinningCmd * getBinningCmd() const
std::string fsName_m
virtual ~FieldSolverCmd()
double getNY() const
Return meshsize.
double getNZ() const
Return meshsize.
std::string getBinsName() const
virtual void update()
Update the field solver data.
double getBoxIncr() const
std::string getType()
void setNY(double)
void setNX(double)
const std::string & getOpalName() const
Return object name.
Definition Object.cpp:267
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
Object * find(const std::string &name)
Find entry.
Definition OpalData.cpp:477
static OpalData * getInstance()
Definition OpalData.cpp:193
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
double getReal(const Attribute &attr)
Return real value.
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
bool getBool(const Attribute &attr)
Return logical value.
void setReal(Attribute &attr, double val)
Set real value.
std::string getString(const Attribute &attr)
Get string value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Representation objects and parsers for attribute expressions.