Commit 908438c0 authored by frey_m's avatar frey_m
Browse files

yMerge branch '543-saamg-enable-rectangulardomain' of gitlab.psi.ch:OPAL/src...

yMerge branch '543-saamg-enable-rectangulardomain' of gitlab.psi.ch:OPAL/src into 565-follow-up-from-resolve-saamg-enable-rectangulardomain

+ add base class for regular domains
parents 8451cf66 f194d79b
...@@ -19,6 +19,7 @@ if (ENABLE_SAAMG_SOLVER) ...@@ -19,6 +19,7 @@ if (ENABLE_SAAMG_SOLVER)
IrregularDomain.cpp IrregularDomain.cpp
MGPoissonSolver.cpp MGPoissonSolver.cpp
RectangularDomain.cpp RectangularDomain.cpp
RegularDomain.cpp
) )
list (APPEND HDRS list (APPEND HDRS
...@@ -28,6 +29,7 @@ if (ENABLE_SAAMG_SOLVER) ...@@ -28,6 +29,7 @@ if (ENABLE_SAAMG_SOLVER)
IrregularDomain.h IrregularDomain.h
MGPoissonSolver.h MGPoissonSolver.h
RectangularDomain.h RectangularDomain.h
RegularDomain.h
) )
endif () endif ()
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
EllipticDomain::EllipticDomain(BoundaryGeometry *bgeom, IntVector_t nr, Vector_t hr, EllipticDomain::EllipticDomain(BoundaryGeometry *bgeom, IntVector_t nr, Vector_t hr,
std::string interpl) std::string interpl)
: IrregularDomain(nr, hr, interpl) : RegularDomain(nr, hr, interpl)
{ {
Vector_t min(-bgeom->getA(), -bgeom->getB(), bgeom->getS()); Vector_t min(-bgeom->getA(), -bgeom->getB(), bgeom->getS());
Vector_t max( bgeom->getA(), bgeom->getB(), bgeom->getS() + bgeom->getLength()); Vector_t max( bgeom->getA(), bgeom->getB(), bgeom->getS() + bgeom->getLength());
...@@ -50,13 +50,6 @@ EllipticDomain::~EllipticDomain() { ...@@ -50,13 +50,6 @@ EllipticDomain::~EllipticDomain() {
//nothing so far //nothing so far
} }
int EllipticDomain::getNumXY() const {
return nxy_m;
}
// for this geometry we only have to calculate the intersection on // for this geometry we only have to calculate the intersection on
// one x-y-plane // one x-y-plane
// for the moment we center the ellipse around the center of the grid // for the moment we center the ellipse around the center of the grid
...@@ -72,7 +65,6 @@ void EllipticDomain::compute(Vector_t hr, NDIndex<3> localId) { ...@@ -72,7 +65,6 @@ void EllipticDomain::compute(Vector_t hr, NDIndex<3> localId) {
setHr(hr); setHr(hr);
hasGeometryChanged_m = true; hasGeometryChanged_m = true;
//reset number of points inside domain //reset number of points inside domain
nxy_m = 0;
// clear previous coordinate maps // clear previous coordinate maps
idxMap_m.clear(); idxMap_m.clear();
...@@ -85,6 +77,8 @@ void EllipticDomain::compute(Vector_t hr, NDIndex<3> localId) { ...@@ -85,6 +77,8 @@ void EllipticDomain::compute(Vector_t hr, NDIndex<3> localId) {
int idx = 0; int idx = 0;
int x, y; int x, y;
int nxy = 0;
/* we need to scan the full x-y-plane on all cores /* we need to scan the full x-y-plane on all cores
* in order to figure out the number of valid * in order to figure out the number of valid
* grid points per plane --> otherwise we might * grid points per plane --> otherwise we might
...@@ -95,11 +89,13 @@ void EllipticDomain::compute(Vector_t hr, NDIndex<3> localId) { ...@@ -95,11 +89,13 @@ void EllipticDomain::compute(Vector_t hr, NDIndex<3> localId) {
if (isInside(x, y, 1)) { if (isInside(x, y, 1)) {
idxMap_m[toCoordIdx(x, y)] = idx; idxMap_m[toCoordIdx(x, y)] = idx;
coordMap_m[idx++] = toCoordIdx(x, y); coordMap_m[idx++] = toCoordIdx(x, y);
nxy_m++; nxy++;
} }
} }
} }
setNumXY(nxy);
switch (interpolationMethod_m) { switch (interpolationMethod_m) {
case CONSTANT: case CONSTANT:
break; break;
...@@ -142,24 +138,6 @@ void EllipticDomain::compute(Vector_t hr, NDIndex<3> localId) { ...@@ -142,24 +138,6 @@ void EllipticDomain::compute(Vector_t hr, NDIndex<3> localId) {
} }
} }
void EllipticDomain::resizeMesh(Vector_t& origin, Vector_t& hr, const Vector_t& rmin,
const Vector_t& rmax, double dh)
{
Vector_t mymax = Vector_t(0.0, 0.0, 0.0);
// apply bounding box increment dh, i.e., "BBOXINCR" input argument
double zsize = rmax[2] - rmin[2];
setMinMaxZ(rmin[2] - zsize * (1.0 + dh),
rmax[2] + zsize * (1.0 + dh));
origin = Vector_t(getXRangeMin(), getYRangeMin(), getMinZ());
mymax = Vector_t(getXRangeMax(), getYRangeMax(), getMaxZ());
for (int i = 0; i < 3; ++i)
hr[i] = (mymax[i] - origin[i]) / nr_m[i];
}
void EllipticDomain::constantInterpolation(int x, int y, int z, StencilValue_t& value, void EllipticDomain::constantInterpolation(int x, int y, int z, StencilValue_t& value,
double &scaleFactor) const double &scaleFactor) const
{ {
......
...@@ -32,11 +32,11 @@ ...@@ -32,11 +32,11 @@
#include <map> #include <map>
#include <string> #include <string>
#include <cmath> #include <cmath>
#include "IrregularDomain.h" #include "Solvers/RegularDomain.h"
#include "Structure/BoundaryGeometry.h" #include "Structure/BoundaryGeometry.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
class EllipticDomain : public IrregularDomain { class EllipticDomain : public RegularDomain {
public: public:
EllipticDomain(BoundaryGeometry *bgeom, IntVector_t nr, EllipticDomain(BoundaryGeometry *bgeom, IntVector_t nr,
...@@ -44,8 +44,6 @@ public: ...@@ -44,8 +44,6 @@ public:
~EllipticDomain(); ~EllipticDomain();
int getNumXY() const override;
/// queries if a given (x,y,z) coordinate lies inside the domain /// queries if a given (x,y,z) coordinate lies inside the domain
bool isInside(int x, int y, int z) const { bool isInside(int x, int y, int z) const {
double xx = getXRangeMin() + hr_m[0] * (x + 0.5); double xx = getXRangeMin() + hr_m[0] * (x + 0.5);
...@@ -60,9 +58,6 @@ public: ...@@ -60,9 +58,6 @@ public:
/// calculates intersection /// calculates intersection
void compute(Vector_t hr, NDIndex<3> localId); void compute(Vector_t hr, NDIndex<3> localId);
void resizeMesh(Vector_t& origin, Vector_t& hr, const Vector_t& rmin,
const Vector_t& rmax, double dh) override;
private: private:
/// Map from a single coordinate (x or y) to a list of intersection values with /// Map from a single coordinate (x or y) to a list of intersection values with
...@@ -75,19 +70,16 @@ private: ...@@ -75,19 +70,16 @@ private:
/// all intersection points with grid lines in Y direction /// all intersection points with grid lines in Y direction
EllipticPointList_t intersectYDir_m; EllipticPointList_t intersectYDir_m;
/// number of nodes in the xy plane (for this case: independent of the z coordinate)
int nxy_m;
/// conversion from (x,y) to index in xy plane /// conversion from (x,y) to index in xy plane
int toCoordIdx(int x, int y) const { return y * nr_m[0] + x; } int toCoordIdx(int x, int y) const { return y * nr_m[0] + x; }
/// conversion from (x,y,z) to index on the 3D grid /// conversion from (x,y,z) to index on the 3D grid
int indexAccess(int x, int y, int z) const { int indexAccess(int x, int y, int z) const {
return idxMap_m.at(toCoordIdx(x, y)) + z * nxy_m; return idxMap_m.at(toCoordIdx(x, y)) + z * getNumXY();
} }
int coordAccess(int idx) const { int coordAccess(int idx) const {
int ixy = idx % nxy_m; int ixy = idx % getNumXY();
return coordMap_m.at(ixy); return coordMap_m.at(ixy);
} }
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "ArbitraryDomain.h" #include "ArbitraryDomain.h"
#include "EllipticDomain.h" #include "EllipticDomain.h"
#include "BoxCornerDomain.h" #include "BoxCornerDomain.h"
#include "RectangularDomain.h"
#include "Track/Track.h" #include "Track/Track.h"
#include "Physics/Physics.h" #include "Physics/Physics.h"
...@@ -127,6 +128,11 @@ MGPoissonSolver::MGPoissonSolver ( PartBunch *beam, ...@@ -127,6 +128,11 @@ MGPoissonSolver::MGPoissonSolver ( PartBunch *beam,
currentGeometry->getL2(), currentGeometry->getL2(),
orig_nr_m, hr_m, interpl)); orig_nr_m, hr_m, interpl));
bp_m->compute(itsBunch_m->get_hr(), layout_m->getLocalNDIndex()); bp_m->compute(itsBunch_m->get_hr(), layout_m->getLocalNDIndex());
} else if (currentGeometry->getTopology() == "RECTANGULAR") {
bp_m = std::unique_ptr<IrregularDomain>(
new RectangularDomain(currentGeometry->getA(),
currentGeometry->getB(),
orig_nr_m, hr_m));
} else { } else {
throw OpalException("MGPoissonSolver::MGPoissonSolver", throw OpalException("MGPoissonSolver::MGPoissonSolver",
"Geometry not known"); "Geometry not known");
......
This diff is collapsed.
// //
// Class RectangularDomain // Class RectangularDomain
// :FIXME: add brief description // This class provides a rectangular beam pipe. The mesh adapts to the bunch
// in longitudinal direction.
// //
// Copyright (c) 2008, Yves Ineichen, ETH Zürich, // Copyright (c) 2008, Yves Ineichen, ETH Zürich,
// 2013 - 2015, Tülin Kaman, Paul Scherrer Institut, Villigen PSI, Switzerland // 2013 - 2015, Tülin Kaman, Paul Scherrer Institut, Villigen PSI, Switzerland
...@@ -28,9 +29,9 @@ ...@@ -28,9 +29,9 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "IrregularDomain.h" #include "Solvers/RegularDomain.h"
class RectangularDomain : public IrregularDomain { class RectangularDomain : public RegularDomain {
public: public:
/** /**
...@@ -51,16 +52,13 @@ public: ...@@ -51,16 +52,13 @@ public:
} }
private: private:
/// number of nodes in the xy plane (for this case: independent of the z coordinate)
int nxy_m;
/// conversion from (x,y,z) to index on the 3D grid /// conversion from (x,y,z) to index on the 3D grid
int indexAccess(int x, int y, int z) const { int indexAccess(int x, int y, int z) const {
return y * nr_m[0] + x + z * nxy_m; return y * nr_m[0] + x + z * getNumXY();
} }
int coordAccess(int idx) const { int coordAccess(int idx) const {
return idx % nxy_m; return idx % getNumXY();
} }
void constantInterpolation(int x, int y, int z, StencilValue_t& value, void constantInterpolation(int x, int y, int z, StencilValue_t& value,
......
//
// Class RegularDomain
// Base class for simple domains that do not change the x-y shape in
// longitudinal direction.
//
// Copyright (c) 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#include "Solvers/RegularDomain.h"
RegularDomain::RegularDomain(const IntVector_t& nr,
const Vector_t& hr,
const std::string& interpl)
: IrregularDomain(nr, hr, interpl)
, nxy_m(nr[0] * nr[1])
{ }
void RegularDomain::resizeMesh(Vector_t& origin, Vector_t& hr, const Vector_t& rmin,
const Vector_t& rmax, double dh)
{
Vector_t mymax = Vector_t(0.0, 0.0, 0.0);
// apply bounding box increment dh, i.e., "BBOXINCR" input argument
double zsize = rmax[2] - rmin[2];
setMinMaxZ(rmin[2] - zsize * (1.0 + dh),
rmax[2] + zsize * (1.0 + dh));
origin = Vector_t(getXRangeMin(), getYRangeMin(), getMinZ());
mymax = Vector_t(getXRangeMax(), getYRangeMax(), getMaxZ());
for (int i = 0; i < 3; ++i)
hr[i] = (mymax[i] - origin[i]) / nr_m[i];
}
\ No newline at end of file
//
// Class RegularDomain
// Base class for simple domains that do not change the x-y shape in
// longitudinal direction.
//
// Copyright (c) 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#ifndef REGULAR_DOMAIN_H
#define REGULAR_DOMAIN_H
#include "Solvers/IrregularDomain.h"
class RegularDomain : public IrregularDomain {
public:
RegularDomain(const IntVector_t& nr,
const Vector_t& hr,
const std::string& interpl);
int getNumXY() const override {
return nxy_m;
}
void setNumXY(int nxy) { nxy_m = nxy; }
void resizeMesh(Vector_t& origin, Vector_t& hr, const Vector_t& rmin,
const Vector_t& rmax, double dh) override;
private:
/// number of nodes in the xy plane (for this case: independent of the z coordinate)
int nxy_m;
};
#endif
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment