AmrPeriodicBoundary.h 1.94 KB
Newer Older
frey_m's avatar
frey_m committed
1 2 3 4
//
// Class AmrPeriodicBoundary
//   Periodic boundary condition.
//
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_PERIODIC_BOUNDARY_H
#define AMR_PERIODIC_BOUNDARY_H

#include "AmrBoundary.h"

frey_m's avatar
frey_m committed
27 28
template <class Level>
class AmrPeriodicBoundary : public AmrBoundary<Level> {
29 30

public:
frey_m's avatar
frey_m committed
31 32
    typedef typename Level::umap_t      umap_t;
    typedef typename Level::lo_t        lo_t;
frey_m's avatar
frey_m committed
33
    typedef typename Level::go_t        go_t;
frey_m's avatar
frey_m committed
34 35
    typedef typename Level::scalar_t    scalar_t;
    typedef amr::AmrIntVect_t           AmrIntVect_t;
36

37 38
public:
    
frey_m's avatar
frey_m committed
39
    AmrPeriodicBoundary() : AmrBoundary<Level>(1) { }
40 41
    
    void apply(const AmrIntVect_t& iv,
42 43 44
               const lo_t& dir,
               umap_t& map,
               const scalar_t& value,
frey_m's avatar
frey_m committed
45
               Level* mglevel,
frey_m's avatar
frey_m committed
46
               const go_t* nr);
47 48 49
};


frey_m's avatar
frey_m committed
50 51 52 53 54 55
template <class Level>
void AmrPeriodicBoundary<Level>::apply(const AmrIntVect_t& iv,
                                       const lo_t& dir,
                                       umap_t& map,
                                       const scalar_t& value,
                                       Level* mglevel,
frey_m's avatar
frey_m committed
56
                                       const go_t* nr)
57 58
{
    // find interior neighbour cell on opposite site
59 60
    AmrIntVect_t niv = iv;
    niv[dir] = ( iv[dir] == -1 ) ? nr[dir] - 1 : 0;
61
    
62
    map[mglevel->serialize(niv)] += value;
63 64
}

65

66
#endif