OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
RegularDomain.cpp
Go to the documentation of this file.
1//
2// Class RegularDomain
3// Base class for simple domains that do not change the x-y shape in
4// longitudinal direction.
5//
6// Copyright (c) 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
7// All rights reserved
8//
9// This file is part of OPAL.
10//
11// OPAL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 3 of the License, or
14// (at your option) any later version.
15//
16// You should have received a copy of the GNU General Public License
17// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18//
20
22 const Vector_t& hr,
23 const std::string& interpl)
24 : IrregularDomain(nr, hr, interpl)
25 , nxy_m(nr[0] * nr[1])
26{ }
27
28
29void RegularDomain::resizeMesh(Vector_t& origin, Vector_t& hr, const Vector_t& rmin,
30 const Vector_t& rmax, double dh)
31{
32 Vector_t mymax = Vector_t(0.0, 0.0, 0.0);
33
34 // apply bounding box increment dh, i.e., "BBOXINCR" input argument
35 double zsize = rmax[2] - rmin[2];
36
37 setMinMaxZ(rmin[2] - zsize * (1.0 + dh),
38 rmax[2] + zsize * (1.0 + dh));
39
40 origin = Vector_t(getXRangeMin(), getYRangeMin(), getMinZ());
42
43 for (int i = 0; i < 3; ++i)
44 hr[i] = (mymax[i] - origin[i]) / nr_m[i];
45}
46
47
49 double &scaleFactor) const
50{
51 scaleFactor = 1.0;
52 value.west = -1.0 / (hr_m[0] * hr_m[0]);
53 value.east = -1.0 / (hr_m[0] * hr_m[0]);
54 value.north = -1.0 / (hr_m[1] * hr_m[1]);
55 value.south = -1.0 / (hr_m[1] * hr_m[1]);
56 value.front = -1.0 / (hr_m[2] * hr_m[2]);
57 value.back = -1.0 / (hr_m[2] * hr_m[2]);
58
59 value.center = 2.0 / (hr_m[0] * hr_m[0])
60 + 2.0 / (hr_m[1] * hr_m[1])
61 + 2.0 / (hr_m[2] * hr_m[2]);
62
63 // we are a right boundary point
64 if (!isInside(x + 1, y, z))
65 value.east = 0.0;
66
67 // we are a left boundary point
68 if (!isInside(x - 1, y, z))
69 value.west = 0.0;
70
71 // we are a upper boundary point
72 if (!isInside(x, y + 1, z))
73 value.north = 0.0;
74
75 // we are a lower boundary point
76 if (!isInside(x, y - 1, z))
77 value.south = 0.0;
78
79 // handle boundary condition in z direction
80 robinBoundaryStencil(z, value.front, value.back, value.center);
81}
82
83
84void RegularDomain::robinBoundaryStencil(int z, double &F, double &B, double &C) const {
85 if (z == 0 || z == nr_m[2] - 1) {
86
87 // case where we are on the Robin BC in Z-direction
88 // where we distinguish two cases
89 // IFF: this values should not matter because they
90 // never make it into the discretization matrix
91 if (z == 0)
92 F = 0.0;
93 else
94 B = 0.0;
95
96 // add contribution of Robin discretization to center point
97 // d the distance between the center of the bunch and the boundary
98 double d = 0.5 * hr_m[2] * (nr_m[2] - 1);
99 C += 2.0 / (d * hr_m[2]);
100 }
101}
const int nr
IntVector_t nr_m
number of mesh points in each direction
double getXRangeMax() const
double getYRangeMax() const
void setMinMaxZ(double minz, double maxz)
Vektor< int, 3 > IntVector_t
double getXRangeMin() const
virtual bool isInside(int x, int y, int z) const =0
double getMaxZ() const
double getYRangeMin() const
IrregularDomain(const IntVector_t &nr, const Vector_t &hr, const std::string &interpl)
Vector_t hr_m
mesh-spacings in each direction
Stencil< double > StencilValue_t
double getMinZ() const
int nxy_m
number of nodes in the xy plane (for this case: independent of the z coordinate)
RegularDomain(const IntVector_t &nr, const Vector_t &hr, const std::string &interpl)
void resizeMesh(Vector_t &origin, Vector_t &hr, const Vector_t &rmin, const Vector_t &rmax, double dh) override
void constantInterpolation(int x, int y, int z, StencilValue_t &value, double &scaleFactor) const override
different interpolation methods for boundary points
void robinBoundaryStencil(int z, double &F, double &B, double &C) const
function to handle the open boundary condition in longitudinal direction
Vektor< double, 3 > Vector_t