AmrPartBunch.h 3.99 KB
Newer Older
frey_m's avatar
frey_m committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
//
// Class AmrPartBunch
//   This class is used to represent a bunch in AMR mode.
//
// Copyright (c) 2017 - 2019, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
// 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/>.
//
21 22 23
#ifndef AMR_PART_BUNCH_H
#define AMR_PART_BUNCH_H

24
#include "Algorithms/PartBunchBase.h"
25
#include "Amr/AmrObject.h"
26

27
class AmrPartBunch : public PartBunchBase<double, 3>
28
{
frey_m's avatar
frey_m committed
29 30 31
public:
    typedef AmrParticle_t pbase_t;
    
32
public:
frey_m's avatar
frey_m committed
33

frey_m's avatar
frey_m committed
34 35
    AmrPartBunch(const PartData *ref);

frey_m's avatar
frey_m committed
36
    AmrPartBunch(const PartData *ref, pbase_t* pbase_p);
frey_m's avatar
frey_m committed
37

frey_m's avatar
frey_m committed
38
    ~AmrPartBunch();
frey_m's avatar
frey_m committed
39

frey_m's avatar
AMR:  
frey_m committed
40
    pbase_t *getAmrParticleBase();
frey_m's avatar
frey_m committed
41

frey_m's avatar
AMR:  
frey_m committed
42
    const pbase_t *getAmrParticleBase() const;
frey_m's avatar
frey_m committed
43

44 45
    void initialize(FieldLayout_t *fLayout);
    
frey_m's avatar
frey_m committed
46 47 48
    // does actually another repartition
    void do_binaryRepart();
    
frey_m's avatar
frey_m committed
49 50
    Vector_t get_hr() const;
    
frey_m's avatar
frey_m committed
51 52
    void set_meshEnlargement(double dh);
    
frey_m's avatar
frey_m committed
53
    VectorPair_t getEExtrema();
54
    
55
    double getRho(int x, int y, int z);
56
    
frey_m's avatar
frey_m committed
57
    FieldLayout_t &getFieldLayout();
58 59
    
    
60 61
    void boundp();
    
62 63
    void computeSelfFields();
    
64
    void computeSelfFields(int bin);
65 66 67
    
    void computeSelfFields_cycl(double gamma);
    
68
    void computeSelfFields_cycl(int bin);
69
    
70 71
    void setSolver(FieldSolver *fs) {
        PartBunchBase<double, 3>::setSolver(fs);
frey_m's avatar
frey_m committed
72
        this->amrobj_mp = fs->getAmrObject();
73 74
    }
    
75 76 77
    virtual void setBinCharge(int bin, double q) { };
    virtual void setBinCharge(int bin) { };
    
frey_m's avatar
frey_m committed
78 79 80 81 82 83 84 85
    /*
     * AmrPartBunch only
     */
    
    const AmrObject* getAmrObject() const {
        return this->amrobj_mp;
    }
    
frey_m's avatar
frey_m committed
86 87 88 89 90 91 92 93
    PoissonSolver *getFieldSolver() {
        return fs_m->solver_m;
    }
    
    const PoissonSolver *getFieldSolver() const {
        return fs_m->solver_m;
    }
    
94 95 96 97
    void setBaseLevelMeshSpacing(const Vector_t& hr) {
        for (int i = 0; i < 3; ++i)
            hr_m[i] = hr[i];
    }
98 99 100 101 102 103 104

    /*!
     * Change the AMR Poisson computation domain.
     * @param ratio per direction.
     */
    void setAmrDomainRatio(const std::vector<double>& ratio);

frey_m's avatar
frey_m committed
105 106
    void gatherLevelStatistics();
    
107 108 109 110
    /*!
     * Only a valid call of root core (core 0)
     * @param l is the level
     */
frey_m's avatar
frey_m committed
111
    const size_t& getLevelStatistics(int l) const;
frey_m's avatar
AMR:  
frey_m committed
112
    
frey_m's avatar
frey_m committed
113
    
114
    /*!
115 116 117 118
     * Update the Lorentz factor before every domainMapping in order
     * to have the correct boosted frame for the particle redistribution,
     * regrid and computation of the self-field forces
     * @param bin is the energy bin
119
     */
120
    void updateLorentzFactor(int bin=0);
frey_m's avatar
frey_m committed
121
    
122 123 124 125 126 127 128 129
    /*!
     * Update the Lorentz factor before every domainMapping in order
     * to have the correct boosted frame for the particle redistribution,
     * regrid and computation of the self-field forces. This function is
     * only used in the single bunch case.
     * @param gamma is the Lorentz factor
     */
    void updateLorentzFactor(double gamma);
130
    
131 132 133 134 135
    //FIXME BCs
    void setBCAllPeriodic() {}
    void setBCAllOpen() {}
    void setBCForDCBeam() {}
    
frey_m's avatar
frey_m committed
136
    
137 138 139
private:
    void updateFieldContainers_m();
    
frey_m's avatar
frey_m committed
140
    void updateDomainLength(Vektor<int, 3>& grid);
141
    
142
    void updateFields(const Vector_t& hr, const Vector_t& origin);
frey_m's avatar
frey_m committed
143
    
144
private:
frey_m's avatar
frey_m committed
145
    
146
    /* pointer to AMR object that is part
147
     * of solver_m (AmrPoissonSolver) in src/Structure/FieldSolver.h
148
     */
149
    AmrObject *amrobj_mp;
frey_m's avatar
AMR:  
frey_m committed
150
    pbase_t *amrpbase_mp;
151
    
152 153 154 155
    /* We need this due to H5PartWrapper etc, but it's always nullptr.
     * Thus, don't use it.
     */
    FieldLayout_t* fieldlayout_m;
frey_m's avatar
frey_m committed
156 157
    
    std::unique_ptr<size_t[]> globalPartPerLevel_m;
158 159 160
};

#endif