AmrBoundary.h 2.92 KB
Newer Older
frey_m's avatar
frey_m committed
1 2 3 4
//
// Class AmrBoundary
//   Interface for mesh boundary conditions.
//
frey_m's avatar
frey_m committed
5
// Copyright (c) 2017 - 2020, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
frey_m's avatar
frey_m committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// All rights reserved
//
// Implemented as part of the PhD thesis
// "Precise Simulations of Multibunches in High Intensity Cyclotrons"
//
// 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/>.
//

22 23 24 25 26
#ifndef AMR_BOUNDARY_H
#define AMR_BOUNDARY_H

#include <vector>

27
#include "Amr/AmrDefs.h"
28

frey_m's avatar
frey_m committed
29
template <class Level>
30
class AmrBoundary {
31 32

public:
frey_m's avatar
frey_m committed
33 34
    typedef typename Level::umap_t      umap_t;
    typedef typename Level::lo_t        lo_t;
frey_m's avatar
frey_m committed
35
    typedef typename Level::go_t        go_t;
frey_m's avatar
frey_m committed
36 37 38
    typedef typename Level::scalar_t    scalar_t;
    typedef typename Level::basefab_t   basefab_t;
    typedef amr::AmrIntVect_t           AmrIntVect_t;
39 40 41
    
public:
    
42 43 44
    /*!
     * @param nPoints used in stencil for applying the boundary
     */
frey_m's avatar
frey_m committed
45
    AmrBoundary(go_t nPoints) : nPoints_m(nPoints) { };
46 47 48
    
    
    /*!
49
     * Check if we are on the physical boundary (all directions)
50 51 52
     * @param iv cell to check
     * @param nr is the number of grid points
     */
frey_m's avatar
frey_m committed
53
    bool isBoundary(const AmrIntVect_t& iv, const go_t* nr) const {
54 55 56 57 58 59 60 61 62 63 64 65
        return AMREX_D_TERM(   isBoundary(iv, 0, nr),
                            || isBoundary(iv, 1, nr),
                            || isBoundary(iv, 2, nr));
    }

    /*!
     * Check if we are on the physical boundary (certain direction)
     * @param iv cell to check
     * @param nr is the number of grid points
     */
    bool isBoundary(const AmrIntVect_t& iv,
                    const lo_t& dir,
frey_m's avatar
frey_m committed
66
                    const go_t* nr) const {
67
        return ( iv[dir] < 0 || iv[dir] >= nr[0] );
68 69 70
    }
    
    /*!
71
     * Apply boundary in a certain direction.
72
     * @param iv is the cell where we want to have the boundary value
73 74 75
     * @param dir direction of physical / mesh boundary
     * @param map with indices global matrix indices and matrix values
     * @param value matrix entry (coefficients)
76 77 78 79
     * @param value of matrix entry that is supposed for index
     * @param nr is the number of grid points
     */
    virtual void apply(const AmrIntVect_t& iv,
80 81 82
                       const lo_t& dir,
                       umap_t& map,
                       const scalar_t& value,
frey_m's avatar
frey_m committed
83
                       Level* mglevel,
frey_m's avatar
frey_m committed
84
                       const go_t* nr) = 0;
85
    
86 87 88
    /*!
     * @returns the number of stencil points required
     */
frey_m's avatar
frey_m committed
89
    const go_t& getNumberOfPoints() const {
90 91 92 93
        return nPoints_m;
    }
    
private:
frey_m's avatar
frey_m committed
94
    const go_t nPoints_m;    ///< Number of points used for boundary
95 96 97
};

#endif