OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
BCHandler.hpp
Go to the documentation of this file.
1#ifndef OPALX_SRC_PARTBUNCH_BCHANDLER_HPP
2#define OPALX_SRC_PARTBUNCH_BCHANDLER_HPP
3
4#include <array>
5#include <ostream>
6
7#include "Ippl.h"
9
28template <unsigned Dim>
29class BCHandler {
30public:
42
55 static BCType strToBCType(const std::string& str) {
56 if (str == "OPEN") {
57 return OPEN;
58 } else if (str == "PERIODIC") {
59 return PERIODIC;
60 } else if (str == "DIRICHLET") {
61 return DIRICHLET;
62 } else {
63 throw OpalException(
64 "BCHandler::strToBCType", "Unknown boundary condition type: " + str);
65 }
66 }
67
71 BCHandler(const BCHandler& other) = default;
72
84 template <typename... Bcs>
85 BCHandler(Bcs... bcs) : bcs_m{{static_cast<BCType>(bcs)...}} {
86 if (sizeof...(bcs) != Dim) {
87 throw OpalException(
88 "BCHandler::BCHandler", "Number of passed BCs does not match dimensionality!");
89 }
90 }
91
98 bool isAll(BCType bc_type) const {
99 for (unsigned int d = 0; d < Dim; ++d) {
100 if (bcs_m[d] != bc_type) return false;
101 }
102 return true;
103 }
104
114 bool isAllEqual() const {
115 int base_case = bcs_m[0];
116 for (unsigned int d = 1; d < Dim; ++d) {
117 if (bcs_m[d] != base_case) return false;
118 }
119 return true;
120 }
121
128 friend std::ostream& operator<<(std::ostream& os, const BCHandler& h) {
129 os << "* BCHandler<" << Dim << ">: [";
130 for (unsigned int d = 0; d < Dim; ++d) {
131 switch (h.bcs_m[d]) {
132 case OPEN:
133 os << "OPEN";
134 break;
135 case PERIODIC:
136 os << "PERIODIC";
137 break;
138 case DIRICHLET:
139 os << "DIRICHLET";
140 break;
141 default:
142 os << "UNKNOWN";
143 break;
144 }
145 if (d + 1 < Dim) os << ", ";
146 }
147 os << "]";
148 return os;
149 }
150
178 template <typename Field>
179 ippl::BConds<Field, Dim> toIPPLBConds() const {
180 typedef ippl::BConds<Field, Dim> bc_type;
181 bc_type bc_container;
182
183 for (unsigned int face = 0; face < 2 * Dim; ++face) {
184 unsigned int d = face / 2; // Dimension associated with this face
185
186 if (bcs_m[d] == PERIODIC) {
187 bc_container[face] = std::make_shared<ippl::PeriodicFace<Field>>(face);
188 } else if (bcs_m[d] == DIRICHLET) {
189 bc_container[face] = std::make_shared<ippl::ZeroFace<Field>>(face);
190 } else if (bcs_m[d] == OPEN) {
191 bc_container[face] = std::make_shared<ippl::NoBcFace<Field>>(face);
192 } else {
193 throw OpalException("BCHandler::toIPPLBConds", "Unsupported BCType encountered.");
194 }
195 }
196
197 return bc_container;
198 }
199
200private:
202 std::array<BCType, Dim> bcs_m;
203};
204
205#endif // OPALX_SRC_PARTBUNCH_BCHANDLER_HPP
constexpr unsigned Dim
Definition OPALTypes.h:7
Handler for boundary conditions per spatial dimension.
Definition BCHandler.hpp:29
bool isAllEqual() const
Check whether all stored BCs are equal (all the same value).
friend std::ostream & operator<<(std::ostream &os, const BCHandler &h)
Stream output helper for debugging and logging.
static BCType strToBCType(const std::string &str)
Convert a textual boundary-condition name to BCType enum.
Definition BCHandler.hpp:55
BCHandler(const BCHandler &other)=default
Defaulted copy constructor.
BCHandler(Bcs... bcs)
Variadic constructor accepting exactly Dim BC values.
Definition BCHandler.hpp:85
std::array< BCType, Dim > bcs_m
Internal storage of boundary conditions, one per dimension.
bool isAll(BCType bc_type) const
Return true if every stored BC equals bc_type.
Definition BCHandler.hpp:98
ippl::BConds< Field, Dim > toIPPLBConds() const
BCType
Supported boundary condition types.
Definition BCHandler.hpp:41