EllipticDomain.h 5.51 KB
Newer Older
frey_m's avatar
frey_m committed
1 2 3 4
//
// Class EllipticDomain
//   :FIXME: add brief description
//
5
// Copyright (c) 2008,        Yves Ineichen, ETH Zürich,
frey_m's avatar
frey_m committed
6
//               2013 - 2015, Tülin Kaman, Paul Scherrer Institut, Villigen PSI, Switzerland
7
//               2017 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
frey_m's avatar
frey_m committed
8 9
// All rights reserved
//
10 11 12 13 14
// 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
15 16 17 18 19 20 21 22 23 24 25
//
// 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
26 27 28 29 30 31 32 33
#ifndef ELLIPTICAL_DOMAIN_H
#define ELLIPTICAL_DOMAIN_H

#include <vector>
#include <map>
#include <string>
#include <cmath>
#include "IrregularDomain.h"
34
#include "Structure/BoundaryGeometry.h"
gsell's avatar
gsell committed
35 36 37 38 39 40 41

class EllipticDomain : public IrregularDomain {

public:

    EllipticDomain(Vector_t nr, Vector_t hr);
    EllipticDomain(double semimajor, double semiminor, Vector_t nr, Vector_t hr, std::string interpl);
42 43 44
    EllipticDomain(BoundaryGeometry *bgeom, Vector_t nr, Vector_t hr, std::string interpl);
    EllipticDomain(BoundaryGeometry *bgeom, Vector_t nr, std::string interpl);

gsell's avatar
gsell committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    ~EllipticDomain();

    /// returns discretization at (x,y,z)
    void getBoundaryStencil(int x, int y, int z, double &W, double &E, double &S, double &N, double &F, double &B, double &C, double &scaleFactor);
    /// returns discretization at 3D index
    void getBoundaryStencil(int idx, double &W, double &E, double &S, double &N, double &F, double &B, double &C, double &scaleFactor);
    /// returns index of neighbours at (x,y,z)
    void getNeighbours(int x, int y, int z, int &W, int &E, int &S, int &N, int &F, int &B);
    /// returns index of neighbours at 3D index
    void getNeighbours(int idx, int &W, int &E, int &S, int &N, int &F, int &B);
    /// returns type of boundary condition
    std::string getType() {return "Elliptic";}
    /// queries if a given (x,y,z) coordinate lies inside the domain
    inline bool isInside(int x, int y, int z) {
        double xx = (x - (nr[0] - 1) / 2.0) * hr[0];
        double yy = (y - (nr[1] - 1) / 2.0) * hr[1];
        return ((xx * xx / (SemiMajor * SemiMajor) + yy * yy / (SemiMinor * SemiMinor) < 1) && z != 0 && z != nr[2] - 1);
    }

64
    int getNumXY(int /*z*/) { return nxy_m; }
gsell's avatar
gsell committed
65 66 67 68 69
    /// set semi-minor
    void setSemiMinor(double sm) {SemiMinor = sm;}
    /// set semi-major
    void setSemiMajor(double sm) {SemiMajor = sm;}

70
    /// calculates intersection 
71 72
    void compute(Vector_t hr);
    void compute(Vector_t hr, NDIndex<3> localId);
gsell's avatar
gsell committed
73 74 75 76 77

    double getXRangeMin() { return -SemiMajor; }
    double getXRangeMax() { return SemiMajor;  }
    double getYRangeMin() { return -SemiMinor; }
    double getYRangeMax() { return SemiMinor;  }
78 79 80
    double getZRangeMin() { return zMin_m; }
    double getZRangeMax() { return zMax_m; }

gsell's avatar
gsell committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

    //TODO: ?
    int getStartIdx() {return 0;}

    bool hasGeometryChanged() { return hasGeometryChanged_m; }

private:

    /// Map from a single coordinate (x or y) to a list of intersection values with
    /// boundary.
    typedef std::multimap<int, double> EllipticPointList;

    /// all intersection points with grid lines in X direction
    EllipticPointList IntersectXDir;

    /// all intersection points with grid lines in Y direction
    EllipticPointList IntersectYDir;

    /// mapping (x,y,z) -> idx
    std::map<int, int> IdxMap;

    /// mapping idx -> (x,y,z)
    std::map<int, int> CoordMap;

    /// semi-major of the ellipse
    double SemiMajor;
    /// semi-minor of the ellipse
    double SemiMinor;
    /// number of nodes in the xy plane (for this case: independent of the z coordinate)
    int nxy_m;
    /// interpolation type
    int interpolationMethod;
    /// flag indicating if geometry has changed for the current time-step
    bool hasGeometryChanged_m;

    /// conversion from (x,y) to index in xy plane
    inline int toCoordIdx(int x, int y) { return y * nr[0] + x; }
    /// conversion from (x,y,z) to index on the 3D grid
    inline int getIdx(int x, int y, int z) {
        if(isInside(x, y, z) && x >= 0 && y >= 0 && z >= 0)
            return IdxMap[toCoordIdx(x, y)] + (z - 1) * nxy_m;
        else
            return -1;
    }
    /// conversion from a 3D index to (x,y,z)
    inline void getCoord(int idx, int &x, int &y, int &z) {
        int ixy = idx % nxy_m;
        int xy = CoordMap[ixy];
        int inr = (int)nr[0];
        x = xy % inr;
        y = (xy - x) / nr[0];
        z = (idx - ixy) / nxy_m + 1;
    }

    /// different interpolation methods for boundary points
136 137 138
    void constantInterpolation(int x, int y, int z, double &W, double &E, double &S, double &N, double &F, double &B, double &C, double &scaleFactor);
    void linearInterpolation(int x, int y, int z, double &W, double &E, double &S, double &N, double &F, double &B, double &C, double &scaleFactor);
    void quadraticInterpolation(int x, int y, int z, double &W, double &E, double &S, double &N, double &F, double &B, double &C, double &scaleFactor);
gsell's avatar
gsell committed
139 140 141 142

};

#endif //#ifdef ELLIPTICAL_DOMAIN_H
143 144 145 146 147 148 149 150

// 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: