File: TimeIntegrator.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 (382 lines) | stat: -rw-r--r-- 10,923 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#ifndef TIME_INTEGRATOR_H
#define TIME_INTEGRATOR_H

#include "MatrixLibrary.h"
#include "TimeFilter.h"
#include "ATC_TypeDefs.h"

namespace ATC {

  // forward declarations
  class ATC_Method;
  class ATC_Coupling;
  class TimeIntegrationMethod;

  /**
   *  @class  AtomTimeIntegrator
   *  @brief  Base class for various time integrators for atomic quantities (replacing other lammps fixes)
   */

  class AtomTimeIntegrator {

  public:

    // constructor
    AtomTimeIntegrator(){};

    // destructor
    virtual ~AtomTimeIntegrator(){};

    /** create and get necessary transfer operators */
    virtual void construct_transfers(){};

   /** Predictor phase, Verlet first step for velocity */
    virtual void init_integrate_velocity(double /* dt */){};

    /** Predictor phase, Verlet first step for position */
    virtual void init_integrate_position(double /* dt */){};

    /** Corrector phase, Verlet second step for velocity */
    virtual void final_integrate(double /* dt */){};

  };

  /**
   *  @class  AtomTimeIntegratorType
   *  @brief  class for applying velocity-verlet based on atom type
   */

  class AtomTimeIntegratorType : public AtomTimeIntegrator {

  public:

    // constructor
    AtomTimeIntegratorType(ATC_Method * atc, AtomType atomType);

    // destructor
    virtual ~AtomTimeIntegratorType(){};

    /** create and get necessary transfer operators */
    virtual void construct_transfers();

   /** Predictor phase, Verlet first step for velocity */
    virtual void init_integrate_velocity(double dt);

    /** Predictor phase, Verlet first step for position */
    virtual void init_integrate_position(double dt);

    /** Corrector phase, Verlet second step for velocity */
    virtual void final_integrate(double dt);

  protected:

    /** pointer to atc object */
    ATC_Method * atc_;

    /** atom type this is applied to */
    AtomType atomType_;

    /** atomic masses */
    DENS_MAN * mass_;

    /** atomic positions */
    DENS_MAN * position_;

    /** atomic velocities */
    DENS_MAN * velocity_;

    /** atomic forces */
    DENS_MAN * force_;

    // workspace
    DENS_MAT _deltaQuantity_;

  private:

    // DO NOT define this
    AtomTimeIntegratorType();

  };

  /**
   *  @class  TimeIntegrator
   *  @brief  Base class for various time integrators for FE quantities
   */

  class TimeIntegrator {

  public:

    /** types of time integration */
    enum TimeIntegrationType {
      NONE=0,
      STEADY,
      VERLET,
      GEAR,
      FRACTIONAL_STEP,
      EXPLICIT,
      IMPLICIT,
      CRANK_NICOLSON,
      DIRECT
    };

    // constructor
    TimeIntegrator(ATC_Coupling * atc,
                   TimeIntegrationType timeIntegrationType = STEADY);

    // destructor
    virtual ~TimeIntegrator();

    /** parser/modifier */
    virtual bool modify(int /* narg */, char ** /* arg */){return false;};

    /** create objects to implement requested numerical method */
    virtual void construct_methods() = 0;

    /** create and get necessary transfer operators */
    virtual void construct_transfers();

    /** pre time integration initialization of data */
    virtual void initialize();

    /** flag if reset is needed */
    bool need_reset() const {return needReset_;};

    // time step methods, corresponding to ATC_Coupling
    /** first part of pre_initial_integrate */
    virtual void pre_initial_integrate1(double dt);
    /** second part of pre_initial_integrate */
    virtual void pre_initial_integrate2(double dt);

    /** first part of post_initial_integrate */
    virtual void post_initial_integrate1(double dt);
    /** second part of post_initial_integrate */
    virtual void post_initial_integrate2(double dt);

    /** first part of pre_final_integrate */
    virtual void pre_final_integrate1(double dt);
    /** second part of pre_final_integrate */
    virtual void pre_final_integrate2(double dt);

    /** first part of post_final_integrate */
    virtual void post_final_integrate1(double dt);
    /** second part of post_final_integrate */
    virtual void post_final_integrate2(double dt);
    /** third part of post_final_integrate */
    virtual void post_final_integrate3(double dt);

    /** checks to see if first RHS computation is needed */
    virtual bool has_final_predictor();
    /** checks to see if second RHS computation is needed */
    virtual bool has_final_corrector();

    /** adds any contributions from time integrator to RHS */
    virtual void add_to_rhs();
    /** post processing step prior to output */
    virtual void post_process();
    /** add output data */
    virtual void output(OUTPUT_LIST & outputData);
    /** pack persistent fields */
    virtual void pack_fields(RESTART_LIST & data);

    /** finalize any data */
    virtual void finish();

    // Member data access
    /** access to time integration type */
    TimeIntegrationType time_integration_type() const
    { return timeIntegrationType_; };

    /** access to ATC Transfer object */
    ATC_Coupling * atc() {return atc_;};

    /** access to time filter object */
    TimeFilter * time_filter() {return timeFilter_;};

    /** access to time filter manager object */
    TimeFilterManager * time_filter_manager() {return timeFilterManager_;};

    /** force the integrator to be reset */
    void force_reset() {needReset_ = true;};

    /** force the integrator not to be reset */
    void force_no_reset() {needReset_ = false;};

  protected:

    /** pointer to time integrator method */
    TimeIntegrationMethod * timeIntegrationMethod_;

    /** pointer to access ATC methods */
    ATC_Coupling * atc_;

    /** time filter for specific updates */
    TimeFilter * timeFilter_;

    /** time filter manager for getting time filtering info */
    TimeFilterManager * timeFilterManager_;

    /** type of integration scheme being used */
    TimeIntegrationType timeIntegrationType_;

    /** flat to reset data */
    bool needReset_;

  private:

    // DO NOT define this
    TimeIntegrator();

  };

  /**
   *  @class  TimeIntegrationMethod
   *  @brief  Base class for time integration methods which update FE quantities
   */

  class TimeIntegrationMethod {

  public:

    // constructor
    TimeIntegrationMethod(TimeIntegrator * timeIntegrator);

    // destructor
    virtual ~TimeIntegrationMethod(){};

    /** create and get necessary transfer operators */
    virtual void construct_transfers(){};
    /** pre time integration */
    virtual void initialize(){};

    // time step methods, corresponding to ATC_Coupling and TimeIntegrator
    /** first part of pre_initial_integrate */
    virtual void pre_initial_integrate1(double /* dt */){};
    /** second part of pre_initial_integrate */
    virtual void pre_initial_integrate2(double /* dt */){};

    /** first part of post_initial_integrate */
    virtual void post_initial_integrate1(double /* dt */){};
    /** second part of post_initial_integrate */
    virtual void post_initial_integrate2(double /* dt */){};

    /** first part of pre_final_integrate */
    virtual void pre_final_integrate1(double /* dt */){};
    /** second part of pre_final_integrate */
    virtual void pre_final_integrate2(double /* dt */){};

    /** first part of post_final_integrate */
    virtual void post_final_integrate1(double /* dt */){};
    /** second part of post_final_integrate */
    virtual void post_final_integrate2(double /* dt */){};
    /** third part of post_final_integrate */
    virtual void post_final_integrate3(double /* dt */){};

    /** checks to see if first RHS computation is needed */
    virtual bool has_final_predictor() {return false;};
    /** checks to see if second RHS computation is needed */
    virtual bool has_final_corrector() {return false;};

    /** adds any contributions from time integrator to RHS */
    virtual void add_to_rhs() {};
    /** post processing step */
    virtual void post_process(){};
    /** add output data */
    virtual void output(OUTPUT_LIST & /* outputData */){};
    /** pack persistent fields */
    virtual void pack_fields(RESTART_LIST & /* data */){};

    /** finalize any states */
    virtual void finish(){};

  protected:

    /** owning time integrator */
    TimeIntegrator * timeIntegrator_;

    /** associated ATC transfer object */
    ATC_Coupling * atc_;

  private:

    // DO NOT define this
    TimeIntegrationMethod();

  };

  //--------------------------------------------------------
  //--------------------------------------------------------
  //  time integration functions not associated
  //  with any particular class
  //--------------------------------------------------------
  //--------------------------------------------------------

  inline void gear1_4_predict(MATRIX & f,
                              MATRIX & dot_f,
                              MATRIX & ddot_f,
                              const MATRIX & dddot_f,
                              double dt)
  // 4th order Gear integrator for 1rst order ODE predictor step
  {
    f      = f + dot_f*dt + ddot_f*(1./2.*dt*dt) + dddot_f*(1./6.*dt*dt*dt);
    dot_f  = dot_f + ddot_f*dt+dddot_f*(1./2.*dt*dt);
    ddot_f = ddot_f + dddot_f*dt;
  };

  inline void gear1_3_predict(MATRIX & f,
                              MATRIX & dot_f,
                              const MATRIX & ddot_f,
                              double dt)
  // 3rd order Gear integrator for 1rst order ODE predictor step
  {
    f      = f + dot_f*dt + ddot_f*(1./2.*dt*dt);
    dot_f  = dot_f + ddot_f*dt;
  };

  inline void gear1_4_correct(MATRIX & f,
                              MATRIX & dot_f,
                              MATRIX & ddot_f,
                              MATRIX & dddot_f,
                              const MATRIX & R_f,
                              double dt)
  // 4th order Gear integrator for 1rst order ODE corrector step
  {
    f       = f       + (3./8.)*R_f;
    dot_f   = dot_f   + (1./dt)*R_f;
    ddot_f  = ddot_f  + (3./2./dt/dt)*R_f;
    dddot_f = dddot_f + (1./dt/dt/dt)*R_f;
  };

  inline void gear1_3_correct(MATRIX & f,
                              MATRIX & dot_f,
                              MATRIX & ddot_f,
                              const MATRIX & R_f,
                              double dt)
  // 3rd order Gear integrator for 1rst order ODE corrector step
  {
    f      = f      + (5./12.)*R_f;
    dot_f  = dot_f  + (1./dt)*R_f;
    ddot_f = ddot_f + (1./dt/dt)*R_f;
  };

  inline void explicit_1(MATRIX & f,
                         const MATRIX & dot_f,
                         double dt)
  // 1rst order explicit ODE update
  {
    f = f + dt*dot_f;
  };

  inline void explicit_2(MATRIX & f,
                         const MATRIX & dot_f,
                         const MATRIX & ddot_f,
                         double dt)
  // 2nd order explicit ODE update
  {
    f = f + dt*dot_f + .5*dt*dt*ddot_f;
  };

};

#endif