RectangularDomain.h 2.24 KB
Newer Older
frey_m's avatar
frey_m committed
1 2
//
// Class RectangularDomain
3 4
//   This class provides a rectangular beam pipe. The mesh adapts to the bunch
//   in longitudinal direction.
frey_m's avatar
frey_m committed
5
//
6
// Copyright (c) 2008,        Yves Ineichen, ETH Zürich,
frey_m's avatar
frey_m committed
7
//               2013 - 2015, Tülin Kaman, Paul Scherrer Institut, Villigen PSI, Switzerland
8
//               2017 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
frey_m's avatar
frey_m committed
9 10
// All rights reserved
//
11 12 13 14 15
// 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
16 17 18 19 20 21 22 23 24 25 26
//
// 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
27 28 29 30
#ifndef RECTANGULAR_DOMAIN_H
#define RECTANGULAR_DOMAIN_H

#include <vector>
31
#include <string>
32
#include "Solvers/RegularDomain.h"
gsell's avatar
gsell committed
33

34
class RectangularDomain : public RegularDomain {
gsell's avatar
gsell committed
35 36

public:
37 38 39 40 41
    /**
     * \param a is the longer side a of the rectangle
     * \param b is the shorter side b of the rectangle
     *
     */
42
    RectangularDomain(double a, double b, IntVector_t nr, Vector_t hr);
gsell's avatar
gsell committed
43

44
    /// calculates intersection with the beam pipe
45
    void compute(Vector_t hr, NDIndex<3> /*localId*/);
46

gsell's avatar
gsell committed
47
    /// queries if a given (x,y,z) coordinate lies inside the domain
48
    inline bool isInside(int x, int y, int /*z*/) const {
frey_m's avatar
frey_m committed
49 50
        double xx = (x - (nr_m[0] - 1) / 2.0) * hr_m[0];
        double yy = (y - (nr_m[1] - 1) / 2.0) * hr_m[1];
51
        return (xx <= getXRangeMax() && yy < getYRangeMax());
gsell's avatar
gsell committed
52 53 54 55
    }

private:
    /// conversion from (x,y,z) to index on the 3D grid
56
    int indexAccess(int x, int y, int z) const {
57
        return y * nr_m[0] + x + z * getNumXY();
gsell's avatar
gsell committed
58
    }
frey_m's avatar
frey_m committed
59

60
    int coordAccess(int idx) const {
61
        return idx % getNumXY();
gsell's avatar
gsell committed
62 63 64
    }
};

65 66 67 68 69 70 71 72 73 74
#endif

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