File: TimeFilter.cpp

package info (click to toggle)
lammps 0~20181211.gitad1b1897d%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 318,860 kB
  • sloc: cpp: 729,569; python: 40,508; xml: 14,919; fortran: 12,142; ansic: 7,454; sh: 5,565; perl: 4,105; f90: 2,700; makefile: 2,117; objc: 238; lisp: 163; tcl: 61; csh: 16; awk: 14
file content (382 lines) | stat: -rw-r--r-- 12,946 bytes parent folder | download | duplicates (4)
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
#include "ATC_Transfer.h"
#include "TimeFilter.h"

using std::set;

namespace ATC {

  //--------------------------------------------------------
  //--------------------------------------------------------
  //  Class TimeFilterManager
  //--------------------------------------------------------
  //--------------------------------------------------------
  
  //--------------------------------------------------------
  //  Constructor
  //--------------------------------------------------------
  TimeFilterManager::TimeFilterManager(ATC_Method * atc) :
    atc_(atc),
    filterType_(NO_FILTER),
    filterScale_(0.),
    useFilter_(false),
    equilibrateFilter_(false),
    needReset_(true),
    endEquilibrate_(false)
  {
    // do nothing
  }
  
  //--------------------------------------------------------
  //  Constructor
  //--------------------------------------------------------
  TimeFilterManager::~TimeFilterManager()
  {
    set<TimeFilter * >::iterator it;
    for (it = timeFilterSet_.begin(); it != timeFilterSet_.end(); it++)
      if (*it) delete *it;
  }
  
  //--------------------------------------------------------
  //  modify
  //    parses input commands
  //--------------------------------------------------------
  bool TimeFilterManager::modify(int narg, char ** arg)
  {
    bool foundMatch = false;
  
    // filter scale size
    /*! \page man_filter_scale fix_modify AtC filter scale
      \section syntax
      fix_modify AtC filter scale <scale> \n
      - scale (real) = characteristic time scale of the filter  \n

      \section examples
      <TT> fix_modify AtC filter scale 10.0 </TT> \n

      \section description
      Filters the MD dynamics to construct a more appropriate continuous field.  Equilibrating first filters the time derivatives without changing the dynamics to provide a better initial condition to the filtered dynamics
      \section restrictions
      only for be used with specific transfers:
      thermal, two_temperature

      \section related
      \ref man_time_filter
      \ref man_filter_type

      \section default
      0.
    */
    if (strcmp(arg[0],"scale")==0) {
      filterScale_ = atof(arg[1]);
      if (filterScale_<=0.)
        throw ATC_Error("Bad filtering time scale");
      foundMatch = true;
    }

    // time filtering activation switch
    /*! \page man_time_filter fix_modify AtC filter
      \section syntax
      fix_modify AtC filter <on | off | equilibrate> \n
      - on | off (keyword) = turns filter on or off\n
      - equilibrate = runs dynamics without filtering but initializes filtered quantities
      \section examples
      <TT> fix_modify atc transfer filter on </TT> \n

      \section description
      Filters the MD dynamics to construct a more appropriate continuous field.  Equilibrating first filters the time derivatives without changing the dynamics to provide a better initial condition to the filtered dynamics

      \section restrictions
      only for be used with specific transfers:
      thermal, two_temperature

      \section related
      \ref man_filter_scale \n
      \ref man_equilibrium_start

      \section default
      off
    */
    else if (strcmp(arg[0],"on")==0) { 
      if (filterScale_<=0. && filterType_ != STEP_FILTER)
        throw ATC_Error("Filtering time scale not initialized");
      useFilter_ = true;
      if (!equilibrateFilter_) {
        needReset_ = true;
        endEquilibrate_ = false;
      }
      else {
        endEquilibrate_ = true;
      }
      equilibrateFilter_ = false;
      foundMatch = true;
    }
    else if (strcmp(arg[0],"off")==0) { 
      useFilter_ = false;
      equilibrateFilter_ = false;
      endEquilibrate_ = false;
      needReset_ = true;
      foundMatch = true;
    }
    else if (strcmp(arg[0],"equilibrate")==0) {
      if (filterScale_<=0. && filterType_ != STEP_FILTER)
        throw ATC_Error("Filtering time scale not initialized");
      equilibrateFilter_ = true;
      endEquilibrate_ = false;
      useFilter_ = false;
      needReset_ = true;
      foundMatch = true;
    }

    // filter type 
    /*! \page man_filter_type fix_modify AtC filter type 
      \section syntax
      fix_modify AtC filter type <exponential | step | no_filter> \n

      \section examples
      <TT> fix_modify AtC filter type exponential </TT> \n

      \section description
      Specifies the type of time filter used.
      \section restrictions
      only for be used with specific transfers:
      thermal, two_temperature

      \section related
      \ref man_time_filter
      \ref man_filter_scale

      \section default
      No default. 
    */
    else if (strcmp(arg[0],"type")==0) { 
      if (strcmp(arg[1],"exponential")==0) { 
        filterType_ = EXPONENTIAL_FILTER;
      }
      else if (strcmp(arg[1],"step")==0) { 
        filterType_ = STEP_FILTER;
      }
      else if (strcmp(arg[1],"no_filter")==0) { 
        filterType_ = NO_FILTER;
      }
      else throw ATC_Error("Not a supported time filter type");
      foundMatch = true;
    }


    return foundMatch;
  }

  //--------------------------------------------------------
  //  initialize
  //    filter set up before a run
  //--------------------------------------------------------
  void TimeFilterManager::initialize()
  {
    needReset_ = false;
    endEquilibrate_ = false;
  }

  //--------------------------------------------------------
  //  construct
  //    instantiates the filter
  //--------------------------------------------------------
  
  TimeFilter * TimeFilterManager::construct(const FilterIntegrationType intType)
  {
    TimeFilter * newTimeFilter;
    if (useFilter_ || equilibrateFilter_) {
      if (filterType_ == EXPONENTIAL_FILTER) {
        if (intType == IMPLICIT_EXPLICIT) {
          newTimeFilter = new TimeFilterImplicitExplicit(*this);     
        }
        else if (intType == EXPLICIT_IMPLICIT) {
          newTimeFilter = new TimeFilterExplicitImplicit(*this);     
        }
        else if (intType == EXPLICIT) {
          newTimeFilter = new TimeFilterExplicit(*this);     
        }
        else if (intType == IMPLICIT) {
          newTimeFilter = new TimeFilterImplicit(*this);     
        }
        else if (intType == IMPLICIT_UPDATE) {
          newTimeFilter = new TimeFilterImplicitUpdate(*this);     
        }
        else if (intType == CRANK_NICHOLSON) {
          newTimeFilter = new TimeFilterCrankNicolson(*this);     
        }
        else { // default to return base class
          newTimeFilter = new TimeFilter(*this); 
        }
      }
      else if (filterType_ == STEP_FILTER) {
        newTimeFilter = new TimeFilterStep(*this); 
      }
    }
    else { // default to return base class
      newTimeFilter = new TimeFilter(*this); 
    }
    timeFilterSet_.insert(newTimeFilter);
    return newTimeFilter;
  }
  
  //--------------------------------------------------------
  //--------------------------------------------------------
  //  Class TimeFilter
  //--------------------------------------------------------
  //--------------------------------------------------------
  
  //--------------------------------------------------------
  //  Constructor
  //--------------------------------------------------------
  TimeFilter::TimeFilter(TimeFilterManager & timeFilterManager) :
    atc_(timeFilterManager.atc()),
    filterScale_(timeFilterManager.filter_scale())
  {
    // do nothing
  }

  //--------------------------------------------------------
  //--------------------------------------------------------
  //  Class TimeFilterExponential
  //--------------------------------------------------------
  //--------------------------------------------------------

  //--------------------------------------------------------
  //  Constructor
  //--------------------------------------------------------
  TimeFilterExponential::TimeFilterExponential(TimeFilterManager & timeFilterManager) :
    TimeFilter(timeFilterManager)
  {
    TimeFilter::filterType_ = TimeFilterManager::EXPONENTIAL_FILTER;
  }

  //--------------------------------------------------------
  //--------------------------------------------------------
  //  Class TimeFilterCrankNicoslon
  //--------------------------------------------------------
  //--------------------------------------------------------

  //--------------------------------------------------------
  //  Constructor
  //--------------------------------------------------------
  TimeFilterCrankNicolson::TimeFilterCrankNicolson(TimeFilterManager & timeFilterManager) :
    TimeFilterExponential(timeFilterManager)
  {
    // do nothing
  }

  //--------------------------------------------------------
  //  initialize
  //    resets memory as needed
  //--------------------------------------------------------
  void TimeFilterCrankNicolson::initialize(const MATRIX & target)
  {
    TimeFilterExponential::initialize(target);
    unFilteredQuantityOld_.reset(target.nRows(),target.nCols());
    unFilteredQuantityOld_ = target;
  }
  
  //--------------------------------------------------------
  //--------------------------------------------------------
  //  Class TimeFilterExplicit
  //--------------------------------------------------------
  //--------------------------------------------------------
  
  //--------------------------------------------------------
  //  Constructor
  //--------------------------------------------------------
  TimeFilterExplicit::TimeFilterExplicit(TimeFilterManager & timeFilterManager) :
    TimeFilterExponential(timeFilterManager)
  {
    // do nothing
  }
  
  //--------------------------------------------------------
  //--------------------------------------------------------
  //  Class TimeFilterImplicit
  //--------------------------------------------------------
  //--------------------------------------------------------
  
  //--------------------------------------------------------
  //  Constructor
  //--------------------------------------------------------
  TimeFilterImplicit::TimeFilterImplicit(TimeFilterManager & timeFilterManager) :
    TimeFilterExponential(timeFilterManager)
  {
    // do nothing
  }
  
  //--------------------------------------------------------
  //--------------------------------------------------------
  //  Class TimeFilterImplicitExplicit
  //--------------------------------------------------------
  //--------------------------------------------------------
  
  //--------------------------------------------------------
  //  Constructor
  //--------------------------------------------------------
  TimeFilterImplicitExplicit::TimeFilterImplicitExplicit(TimeFilterManager & timeFilterManager) :
    TimeFilterExponential(timeFilterManager)
  {
    // do nothing
  }

  //--------------------------------------------------------
  //--------------------------------------------------------
  //  Class TimeFilterExplicitImplicit
  //--------------------------------------------------------
  //--------------------------------------------------------
  
  //--------------------------------------------------------
  //  Constructor
  //--------------------------------------------------------
  TimeFilterExplicitImplicit::TimeFilterExplicitImplicit(TimeFilterManager & timeFilterManager) :
    TimeFilterExponential(timeFilterManager)
  {
    // do nothing
  }

  //--------------------------------------------------------
  //--------------------------------------------------------
  //  Class TimeFilterImplicitUpdate
  //--------------------------------------------------------
  //--------------------------------------------------------
  
  //--------------------------------------------------------
  //  Constructor
  //--------------------------------------------------------
  TimeFilterImplicitUpdate::TimeFilterImplicitUpdate(TimeFilterManager & timeFilterManager) :
    TimeFilterExponential(timeFilterManager)
  {
    // do nothing
  }

  //--------------------------------------------------------
  //--------------------------------------------------------
  //  Class TimeFilterStep
  //--------------------------------------------------------
  //--------------------------------------------------------
  
  //--------------------------------------------------------
  //  Constructor
  //--------------------------------------------------------
  TimeFilterStep::TimeFilterStep(TimeFilterManager & timeFilterManager) :
    TimeFilter(timeFilterManager),
    elapsedTime_(0.0)
  {
    // do nothing
  }

  //--------------------------------------------------------
  //  initialize
  //    resets memory as needed
  //--------------------------------------------------------
  void TimeFilterStep::initialize(const MATRIX & target)
  {
    TimeFilter::initialize(target);
    unFilteredQuantityOld_.reset(target.nRows(),target.nCols());
    unFilteredQuantityOld_ = target;
  }


};