File: ConcentrationRegulator.h

package info (click to toggle)
lammps 20220106.git7586adbb6a%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 348,064 kB
  • sloc: cpp: 831,421; python: 24,896; xml: 14,949; f90: 10,845; ansic: 7,967; sh: 4,226; perl: 4,064; fortran: 2,424; makefile: 1,501; objc: 238; lisp: 163; csh: 16; awk: 14; tcl: 6
file content (216 lines) | stat: -rw-r--r-- 6,933 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#ifndef CONCENTRATION_REGULATOR_H
#define CONCENTRATION_REGULATOR_H

#include <map>
#include <string>

#include "AtomicRegulator.h"
#include "LammpsInterface.h"

namespace ATC {

  /**
   *  @class  ConcentrationRegulator
   *  @brief  Manager class for atom-continuum control of charge and potential
   */

  class ConcentrationRegulatorMethod;
  class ConcentrationRegulator : public AtomicRegulator {

  public:
    enum ConcentrationRegulatorType {NONE=0,TRANSITION};
    /** parser data */
    struct ConcentrationRegulatorParameters {
      ConcentrationRegulatorParameters():
        method(NONE),
        type(0),
        groupbit(0),
        transitionType(0),
        value(0),
        frequency(0),
        transitionInterval(0),
        maxEnergy(0),
        maxExchanges(0),
        maxAttempts(0) { };
      ConcentrationRegulatorType method;
      int type;
      int groupbit;
      int transitionType;
      double value;
      int frequency;
      int transitionInterval;
      double maxEnergy;
      int maxExchanges;
      int maxAttempts;
      std::string transitionTag;
      ESET elemset;
    };

    /** constructor */
    ConcentrationRegulator(ATC_Coupling *atc);
    /** destructor */
    ~ConcentrationRegulator();
    /** parser/modifier */
    virtual bool modify(int narg, char **arg);
    /** construct methods */
    virtual void construct_methods();
    /** pre time integration */
    virtual void initialize();

    //WIP_JAT need a nicer way to consistently handle sets of regulators, not sure how yet
    // application steps
    /** apply the regulator in the pre-predictor phase */
    virtual void apply_pre_predictor(double /* dt */, int /* timeStep */){};
    /** apply the regulator in the mid-predictor phase */
    virtual void apply_mid_predictor(double /* dt */, int /* timeStep */){};
    /** apply the regulator in the post-predictor phase */
    virtual void apply_post_predictor(double /* dt */, int /* timeStep */){};
    /** apply the regulator in the pre-correction phase */
    virtual void apply_pre_corrector(double /* dt */, int /* timeStep */){};
    /** apply the regulator in the post-correction phase */
    virtual void apply_post_corrector(double /* dt */, int /* timeStep */){};
    /** compute the thermal boundary flux, must be consistent with regulator */
    virtual void compute_boundary_flux(FIELDS & /* fields */){};
    /** add contributions (if any) to the finite element right-hand side */
    virtual void add_to_rhs(FIELDS & /* rhs */){};

    /** prior to exchanges */
    virtual void pre_force();
    /** prior to exchanges */
    virtual void pre_exchange();
    /** following a run */
    virtual void finish();
    /** ATC output */
    virtual void output(OUTPUT_LIST & outputData) const;
    /** scalar output */
    virtual double compute_vector(int n) const;
    virtual int size_vector(int s) const;

    bool needs_temperature() { return regulators_.size() > 0; }

  protected:
    /** registry charge regulators */
    std::map<std::string,ConcentrationRegulatorMethod *> regulators_;
    std::map<std::string,ConcentrationRegulatorParameters> parameters_;

  private:
    ConcentrationRegulator(); // DO NOT define this
  };

  /**
   *  @class  ConcentrationRegulatorMethod
   *  @brief  Base class for ConcentrationRegulator algorithms
   */

  class ConcentrationRegulatorMethod : public RegulatorShapeFunction {

  public:
    ConcentrationRegulatorMethod(ConcentrationRegulator *c)
      : RegulatorShapeFunction(c) {};
    ~ConcentrationRegulatorMethod() {};
    void initialize(void) {};
    virtual void pre_force() {};
    virtual void pre_exchange() {};
    virtual void finish() {};
    virtual void set_weights() {};
    virtual double compute_vector(int /* n */) const { return 0;}
    virtual void output(OUTPUT_LIST & /* outputData */){};
  private:
    ConcentrationRegulatorMethod(); // DO NOT define this
  };

  /**
   *  @class  ConcentrationRegulatorMethodTransition
   *  @brief  GCMC + thermodynamic integration
   */
  class ConcentrationRegulatorMethodTransition : public ConcentrationRegulatorMethod {

  public:
    /** constructor */
    ConcentrationRegulatorMethodTransition(
      ConcentrationRegulator *concentrationRegulator,
      ConcentrationRegulator::ConcentrationRegulatorParameters & parameters);
    /** destructor */
    ~ConcentrationRegulatorMethodTransition(){
      if (randomNumberGenerator_) delete randomNumberGenerator_;
    }
    /** initialize */
    void initialize(void);
    /** prior to force evaluation  */
    virtual void pre_force();
    /** prior to exchanges */
    virtual void pre_exchange();
    /** "thermo" output */
    virtual double compute_vector(int n) const;
  protected:
    /** set transition state: epsilon and charge */
    int mask(int /* type */, int /* groupbit */) {return 0;}
    int count(void) const;
    int excess(void) const;
    double energy(int id) const;
    double energy(double * x) const;
    double insertion_location(DENS_VEC & x) const;
    double deletion_id(ID_PAIR & id) const ;
    double deletion_id_consistent(ID_PAIR & id) const ;
    double deletion_id_free(ID_PAIR & id) const ;
    double insertion_factor(int c) const // a ramp
    {
      if (c < transitionInterval_) return ((double) c)/transitionInterval_;
      else                         return 1.0;
    }
    void transition();
    bool accept(double energy, double T = 0) const;
    bool delete_atoms(int n);
    bool insert_atoms(int n);
    int pick_element() const;
    void pick_coordinates(const int elem, DENS_VEC & xi, DENS_VEC& x ) const;
    void pick_velocity(DENS_VEC & v, const double T ) const;
    double uniform() const;
    double normal() const;

    /** pointer to conc regulator object for data */
    ConcentrationRegulator * concentrationRegulator_;

    /** interscale manager */
    class InterscaleManager * interscaleManager_;

    /** interscale manager */
    class LammpsInterface * lammpsInterface_;

    /** member data */
    class AtomInElementSet * list_;
    double targetConcentration_;
    double targetCount_;
    ESET elemset_;
    POTENTIAL p_;
    RNG_POINTER randomNumberGenerator_;
    DENS_VEC volumes_;
    double V_;
    double q0_;
    int controlType_;
    int controlIndex_;
    int transitionType_;
    int transitionInterval_;;
    int transitionCounter_;
    int nInTransition_;
    double transitionFactor_;
    DENS_VEC epsilon0_;
    ID_LIST deletionIds_, insertionIds_;
    int controlMask_;
    int frequency_;
    double maxEnergy_;
    int maxExchanges_;
    int maxAttempts_;
    int nexchanges_;
    bool initialized_;
    double sigma_;

    void sync_random_number_generators() const;
    mutable int _rngUniformCounter_; // for parallel consistency
    mutable int _rngNormalCounter_; // for parallel consistency

  private:
    ConcentrationRegulatorMethodTransition(); // DO NOT define this
  };
};
#endif