OPALX (Object Oriented Parallel Accelerator Library for Exascale) MINIorX
OPALX
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>
30#include "Physics/Physics.h"
32
33using namespace Expressions;
34
35// TODO: o add a FIELD for DISCRETIZATION, MAXITERS, TOL...
36
38 : Definition(
39 FIELDSOLVER::SIZE, "FIELDSOLVER",
40 "The \"FIELDSOLVER\" statement defines data for a the field solver") {
42 "TYPE", "Name of the attached field solver.", {"NONE", "FFT", "OPEN"}); // removed, since not implemented: "CG ", "P3M"
43
44 itsAttr[FIELDSOLVER::NX] = Attributes::makeReal("NX", "Meshsize in x");
45 itsAttr[FIELDSOLVER::NY] = Attributes::makeReal("NY", "Meshsize in y");
46 itsAttr[FIELDSOLVER::NZ] = Attributes::makeReal("NZ", "Meshsize in z");
47
49 Attributes::makeBool("PARFFTX", "True, dimension 0 i.e x is parallelized", false);
50
52 Attributes::makeBool("PARFFTY", "True, dimension 1 i.e y is parallelized", false);
53
55 Attributes::makeBool("PARFFTZ", "True, dimension 2 i.e z is parallelized", true);
56
58 "BCFFTX", "Boundary conditions in x.", {"OPEN", "DIRICHLET", "PERIODIC"}, "OPEN");
59
61 "BCFFTY", "Boundary conditions in y.", {"OPEN", "DIRICHLET", "PERIODIC"}, "OPEN");
62
64 "BCFFTZ", "Boundary conditions in z.", {"OPEN", "DIRICHLET", "PERIODIC"}, "OPEN");
65
67 "GREENSF", "Which Greensfunction to be used.", {"STANDARD", "INTEGRATED"}, "INTEGRATED");
68
70 Attributes::makeReal("BBOXINCR", "Increase of bounding box in % ", 2.0);
71
72 // \todo does not work registerOwnership(AttributeHandler::STATEMENT);
73}
74
75FieldSolverCmd::FieldSolverCmd(const std::string& name, FieldSolverCmd* parent)
76 : Definition(name, parent) {
77}
78
80}
81
82FieldSolverCmd* FieldSolverCmd::clone(const std::string& name) {
83 return new FieldSolverCmd(name, this);
84}
85
88 update();
89}
90
91FieldSolverCmd* FieldSolverCmd::find(const std::string& name) {
92 FieldSolverCmd* fs = dynamic_cast<FieldSolverCmd*>(OpalData::getInstance()->find(name));
93
94 if (fs == 0) {
95 throw OpalException("FieldSolverCmd::find()", "FieldSolverCmd \"" + name + "\" not found.");
96 }
97 return fs;
98}
99
102}
103
105 using BCH_t = BCHandler<3>;
106
107 BCH_t boundary_conditions(
111 );
112
114
118 if (!boundary_conditions.isAllEqual()) {
119 throw OpalException("PartBunch::PartBunch",
120 "Currently only uniform boundary conditions in all "
121 "dimensions are supported! Please set all "
122 "dimensions to either OPEN or PERIODIC.");
123 }
124
125 return boundary_conditions;
126}
127
128double FieldSolverCmd::getNX() const {
130}
131
132double FieldSolverCmd::getNY() const {
134}
135
136double FieldSolverCmd::getNZ() const {
138}
139
140void FieldSolverCmd::setNX(double value) {
142}
143
144void FieldSolverCmd::setNY(double value) {
146}
147
148void FieldSolverCmd::setNZ(double value) {
150}
151
154}
155
156
159 fsName_m = getType();
160 }
161}
162
164 static const std::map<std::string, FieldSolverCmdType> stringType_s = {
165 {"NONE", FieldSolverCmdType::NONE},
167 {"OPEN", FieldSolverCmdType::OPEN},
168 };
169
170 fsName_m = getType();
171
172 if (fsName_m.empty()) {
173 throw OpalException(
174 "FieldSolverCmd::setFieldSolverCmdType",
175 "The attribute \"TYPE\" isn't set for \"FIELDSOLVER\"!");
176 } else {
177 fsType_m = stringType_s.at(fsName_m);
178 }
179}
180
182 return false;
183}
184
186 os << "* ************* F I E L D S O L V E R ********************************************** "
187 << endl;
188 os << "* FIELDSOLVER " << getOpalName() << '\n'
189 << "* TYPE " << fsName_m << '\n'
190 << "* RANKS " << ippl::Comm->size() << '\n'
191 << "* NX " << Attributes::getReal(itsAttr[FIELDSOLVER::NX]) << '\n'
192 << "* NY " << Attributes::getReal(itsAttr[FIELDSOLVER::NY]) << '\n'
193 << "* NZ " << Attributes::getReal(itsAttr[FIELDSOLVER::NZ]) << '\n'
194 << "* BBOXINCR " << Attributes::getReal(itsAttr[FIELDSOLVER::BBOXINCR]) << '\n'
196
198 os << "* XDIM parallel " << endl;
199 } else {
200 os << "* XDIM serial " << endl;
201 }
202
204 os << "* YDIM parallel " << endl;
205 } else {
206 os << "* YDIM serial " << endl;
207 }
208
210 os << "* ZDIM parallel " << endl;
211 } else {
212 os << "* ZDIM serial " << endl;
213 }
214
215 os << "* ********************************************************************************** "
216 << endl;
217 return os;
218}
@ SIZE
Definition: IndexMap.cpp:173
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
Representation objects and parsers for attribute expressions.
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:90
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Definition: Attributes.cpp:409
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
void setReal(Attribute &attr, double val)
Set real value.
Definition: Attributes.cpp:271
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
std::unique_ptr< mpi::Communicator > Comm
Definition: Ippl.h:22
The base class for all OPAL definitions.
Definition: Definition.h:30
const std::string & getOpalName() const
Return object name.
Definition: Object.cpp:308
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
Object * find(const std::string &name)
Find entry.
Definition: OpalData.cpp:563
static OpalData * getInstance()
Definition: OpalData.cpp:195
Handler for boundary conditions per spatial dimension.
Definition: BCHandler.hpp:26
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.
std::string fsName_m
virtual ~FieldSolverCmd()
double getNY() const
Return meshsize.
double getNZ() const
Return meshsize.
virtual void update()
Update the field solver data.
double getBoxIncr() const
std::string getType()
void setNY(double)
void setFieldSolverCmdType()
void setNX(double)
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Definition: Inform.h:40