EllipticDomain.h 3.4 KB
Newer Older
frey_m's avatar
frey_m committed
1 2
//
// Class EllipticDomain
3 4 5
//   This class provides an elliptic beam pipe. The mesh adapts to the bunch size
//   in the longitudinal direction. At the intersection of the mesh with the
//   beam pipe, three stencil interpolation methods are available.
frey_m's avatar
frey_m committed
6
//
7
// Copyright (c) 2008,        Yves Ineichen, ETH Zürich,
frey_m's avatar
frey_m committed
8
//               2013 - 2015, Tülin Kaman, Paul Scherrer Institut, Villigen PSI, Switzerland
9
//               2017 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
frey_m's avatar
frey_m committed
10 11
// All rights reserved
//
12 13 14 15 16
// Implemented as part of the master thesis
// "A Parallel Multigrid Solver for Beam Dynamics"
// and the paper
// "A fast parallel Poisson solver on irregular domains applied to beam dynamics simulations"
// (https://doi.org/10.1016/j.jcp.2010.02.022)
frey_m's avatar
frey_m committed
17 18 19 20 21 22 23 24 25 26 27
//
// 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/>.
//
gsell's avatar
gsell committed
28 29 30 31 32 33 34
#ifndef ELLIPTICAL_DOMAIN_H
#define ELLIPTICAL_DOMAIN_H

#include <vector>
#include <map>
#include <string>
#include <cmath>
35
#include "Solvers/RegularDomain.h"
36
#include "Structure/BoundaryGeometry.h"
37
#include "Utilities/OpalException.h"
gsell's avatar
gsell committed
38

39
class EllipticDomain : public RegularDomain {
gsell's avatar
gsell committed
40 41

public:
42
    EllipticDomain(BoundaryGeometry *bgeom, IntVector_t nr,
43 44
                   Vector_t hr, std::string interpl);

gsell's avatar
gsell committed
45 46 47
    ~EllipticDomain();

    /// queries if a given (x,y,z) coordinate lies inside the domain
48
    bool isInside(int x, int y, int z) const {
frey_m's avatar
frey_m committed
49 50
        double xx = getXRangeMin() + hr_m[0] * (x + 0.5);
        double yy = getYRangeMin() + hr_m[1] * (y + 0.5);
51

52 53
        bool isInsideEllipse = (xx * xx / (getXRangeMax() * getXRangeMax()) +
                                yy * yy / (getYRangeMax() * getYRangeMax()) < 1);
54

55
        return (isInsideEllipse && z >= 0 && z < nr_m[2]);
gsell's avatar
gsell committed
56 57
    }

58
    /// calculates intersection
59
    void compute(Vector_t hr, NDIndex<3> localId);
gsell's avatar
gsell committed
60 61 62 63 64

private:

    /// Map from a single coordinate (x or y) to a list of intersection values with
    /// boundary.
65
    typedef std::multimap<int, double> EllipticPointList_t;
gsell's avatar
gsell committed
66 67

    /// all intersection points with grid lines in X direction
68
    EllipticPointList_t intersectXDir_m;
gsell's avatar
gsell committed
69 70

    /// all intersection points with grid lines in Y direction
71
    EllipticPointList_t intersectYDir_m;
gsell's avatar
gsell committed
72 73

    /// conversion from (x,y) to index in xy plane
74
    int toCoordIdx(int x, int y) const { return y * nr_m[0] + x; }
75

gsell's avatar
gsell committed
76
    /// conversion from (x,y,z) to index on the 3D grid
77
    int indexAccess(int x, int y, int z) const {
78
        return idxMap_m.at(toCoordIdx(x, y)) + z * getNumXY();
gsell's avatar
gsell committed
79
    }
80

81
    int coordAccess(int idx) const {
82
        int ixy = idx % getNumXY();
83
        return coordMap_m.at(ixy);
gsell's avatar
gsell committed
84 85 86
    }

    /// different interpolation methods for boundary points
87
    void linearInterpolation(int x, int y, int z, StencilValue_t& value,
88
                             double &scaleFactor) const override;
89

90
    void quadraticInterpolation(int x, int y, int z, StencilValue_t& value,
91
                                double &scaleFactor) const override;
gsell's avatar
gsell committed
92 93 94
};

#endif //#ifdef ELLIPTICAL_DOMAIN_H
95 96 97 98 99 100 101 102

// vi: set et ts=4 sw=4 sts=4:
// Local Variables:
// mode:c
// c-basic-offset: 4
// indent-tabs-mode: nil
// require-final-newline: nil
// End: