chombo-discharge
CD_CdrPlasmaImExSdcStepper.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2021 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_CdrPlasmaImExSdcStepper_H
13 #define CD_CdrPlasmaImExSdcStepper_H
14 
15 // Our includes
16 #include <CD_AmrMesh.H>
17 #include <CD_CdrPlasmaStepper.H>
18 #include <CD_CdrIterator.H>
19 #include <CD_RtIterator.H>
20 #include <CD_NamespaceHeader.H>
21 
22 namespace Physics {
23  namespace CdrPlasma {
24 
29  {
30  public:
31  // Forward declare utility classes for handlnig the extra memory when advancing the solvers.
32  class CdrStorage;
33  class FieldStorage;
34  class RtStorage;
35  class SigmaStorage;
36 
37  public:
42 
47  CdrPlasmaImExSdcStepper(RefCountedPtr<CdrPlasmaPhysics>& a_physics);
48 
52  virtual ~CdrPlasmaImExSdcStepper();
53 
59  Real
60  advance(const Real a_dt) override;
61 
66  void
67  allocateInternals() override;
68 
72  void
73  deallocateInternals() override;
74 
81  void
82  regridInternals(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel) override;
83 
87  void
88  parseOptions() override;
89 
93  void
94  parseRuntimeOptions() override;
95 
96  protected:
100  Vector<RefCountedPtr<CdrStorage>> m_cdrScratch;
101 
105  Vector<RefCountedPtr<RtStorage>> m_rteScratch;
106 
110  RefCountedPtr<FieldStorage> m_fieldScratch;
111 
115  RefCountedPtr<SigmaStorage> m_sigmaScratch;
116 
121 
125  int m_p;
126 
130  int m_k;
131 
136 
141 
147 
152  Real m_minCFL;
153  Real m_maxCFL;
154  Real m_errThresh;
155  Real m_safety;
156  Real m_decreaseSafety;
157  Real m_newDt; // dt for next time step
158  Real m_extrapDt;
159 
160  bool m_extrapAdvect;
161  bool m_adaptiveDt;
162  bool m_printReport;
163  bool m_haveError;
164  bool m_useTGA; // Second order diffusion
165 
166  // Basically only debugging stuff
167  bool m_doAdvectionSource;
168  bool m_doDiffusion;
169  bool m_doPoisson;
170  bool m_doRTE;
171  bool m_computeD;
172  bool m_computeV;
173  bool m_computeS;
174  bool m_consistentE;
175  bool m_consistentRTE;
176  bool m_haveDtErr;
177  bool m_profileSteps;
178 
179  // Error things
180  Vector<Real> m_cdrError;
181  Real m_sigmaError;
182  Real m_maxError;
183  Real m_preError;
184 
185  // Stuff for Lobatto intervals, Vandermonde matrix, integration
186  // weights, Lobatto nodes etc.
187  Vector<Vector<Real>> m_qmj;
188  Vector<Vector<Real>> m_vandermonde;
189  Vector<Real> m_nodes;
190  Vector<Real> m_tm;
191  Vector<Real> m_dtm;
192 
193  std::string m_whichNodes;
194 
195  // Get functions for storage
196  RefCountedPtr<CdrStorage>&
197  getCdrStorage(const CdrIterator<CdrSolver>& a_solverit);
198  RefCountedPtr<RtStorage>&
199  getRtStorage(const RtIterator<RtSolver>& a_solverit);
200 
201  // Allocation functions
202  void
203  allocateCdrStorage();
204  void
205  allocateFieldStorage();
206  void
207  allocateRtStorage();
208  void
209  allocateSigmaStorage();
210 
211  // Get functions for substep data.
212  Vector<EBAMRCellData*>
213  getCdrSolversPhiK(const int a_m);
214  EBAMRIVData&
215  getSigmaSolverK(const int a_m);
216 
217  // Routines for intervals and quadrature
218  void
219  setupQuadratureNodes(const int a_p);
220  void
221  setupUniformNodes(const int a_p);
222  void
223  setupLobattoNodes(const int a_p);
224  void
225  setupChebyshevNodes(const int a_p);
226  void
227  setupQmj(const int a_p);
228  void
229  setupSubintervals(const Real a_time, const Real a_dt);
230  void
231  quad(EBAMRCellData& a_quad, const Vector<EBAMRCellData>& a_integrand, const int a_m);
232  void
233  quad(EBAMRIVData& a_quad, const Vector<EBAMRIVData>& a_integrand, const int a_m);
234 
235  // Routines for copying data at tm[0] and tm[p]
236  void
237  copyCdrToPhiM0();
238  void
239  copySigmaToM0();
240 
241  void
242  copyPhiPToCdr();
243  void
244  copySigmaPToSigma();
245 
246  void
247  integrateRtTransient(const Real a_dt);
248  void
249  integrateRtStationary();
250 
251  // These are the standard IMEX_SDC integration routines
252  void
253  integrate(const Real a_dt, const Real a_time, const bool a_lagged_terms);
254  void
255  integrateAdvectionReaction(const Real a_dt, const int a_m, const bool a_lagged_terms);
256  void
257  integrateAdvection(const Real a_dt, const int a_m, const bool a_lagged_terms);
258  void
259  integrateDiffusion(const Real a_dt, const int a_m, const bool a_lagged_terms);
260 
264  Vector<EBAMRCellData*>
265  getCdrErrors();
266 
267  // Make integrands quadrature-ready
268  void
269  reconcileIntegrands();
270 
271  // IMEX_SDC predictor routines
272  void
273  computeFD0();
274 
275  // IMEX_SDC corrector routines
276  void
277  initializeErrors();
278  void
279  finalizeErrors();
280 
281  // Step size control routines
282  void
283  computeNewDt(bool& a_accept_step, const Real a_dt, const int a_num_corrections);
284  void
285  adaptiveReport(const Real a_first_dt,
286  const Real a_dt,
287  const Real a_new_dt,
288  const int a_corr,
289  const int a_rej,
290  const Real a_max_err);
291 
292  // Poisson, RTE, and diffusion coefficient updates
293  void
294  updateField(); // This uses the solver states
295  void
296  updateField(const Vector<EBAMRCellData*>& a_densities, const EBAMRIVData& a_sigma);
297  void
298  updateDiffusionCoefficients();
299 
300  // Store & restore functions
301  void
302  storeSolvers();
303  void
304  restoreSolvers();
305 
306  // Aux functions
307  void
308  computeReactionNetwork(const int a_m, const Real a_time, const Real a_dt);
309  void
310  computeElectricFieldIntoScratch();
311  void
312  computeCdrEbStates();
313  void
314  computeCdrEbStates(const Vector<EBAMRCellData*>& a_phis);
315  void
316  computeCdrDomainStates();
317  void
318  computeCdrDomainStates(const Vector<EBAMRCellData*>& a_phis);
319  void
320  computeCdrGradients();
321  void
322  computeCdrGradients(const Vector<EBAMRCellData*>& a_phis);
323  void
324  computeCdrFluxes(const Real a_time);
325  void
326  computeCdrFluxes(const Vector<EBAMRCellData*>& a_phis, const Real a_time);
327  void
328  computeCdrDomainFluxes(const Real a_time);
329  void
330  computeCdrDomainFluxes(const Vector<EBAMRCellData*>& a_phis, const Real a_time);
331  void
332  computeCdrVelo(const Real a_time);
333  void
334  computeCdrVelo(const Vector<EBAMRCellData*>& a_phis, const Real a_time);
335  Real
336  computeDt() override;
337  void
338  computeSigmaFlux();
339 
340  //
341  Real
342  getMaxError();
343  Real
344  getMaxNodeDistance();
345 
346  // Profiling
347  void
348  writeStepProfile(const Real a_dt,
349  const Real a_error,
350  const int a_substeps,
351  const int a_corrections,
352  const int a_rejections);
353 
354  // Parse optiosn that are not really used
355  void
356  parseNodes();
357  void
358  parseDiffusionCoupling();
359  void
360  parseAdaptiveOptions();
361  void
362  parseDebugOptions();
363  void
364  parseAdvectionOptions();
365  };
366  } // namespace CdrPlasma
367 } // namespace Physics
368 
369 #include <CD_NamespaceFooter.H>
370 
371 #endif
Declaration of core class for handling AMR-related operations (with embedded boundaries)
Declaration of an iterator class for CdrLayout (for iterating through subsets of solvers).
Declaration of a CdrPlasmaStepper, an abstract class for evolving cdr plasma equations in time.
Iterator class for RtLayout.
Iterator class for CdrLayout. This allows iteration through solvers (or subsets of solvers).
Definition: CD_CdrIterator.H:27
Definition: CD_CdrPlasmaImExSdcStorage.H:24
Definition: CD_CdrPlasmaImExSdcStorage.H:182
Definition: CD_CdrPlasmaImExSdcStorage.H:237
Definition: CD_CdrPlasmaImExSdcStorage.H:280
Class for evolving plasma equations using implicit-explicit spectral deferred corrections.
Definition: CD_CdrPlasmaImExSdcStepper.H:29
Real m_maxDtGrowth
Maximum growth factor for the time step when using adaptive stepping.
Definition: CD_CdrPlasmaImExSdcStepper.H:151
int m_k
Number of correction for the SDC discretization.
Definition: CD_CdrPlasmaImExSdcStepper.H:130
Real computeDt() override
Compute the time step.
Definition: CD_CdrPlasmaImExSdcStepper.cpp:1298
void parseRuntimeOptions() override
Parse run-time options.
Definition: CD_CdrPlasmaImExSdcStepper.cpp:85
int m_maxRetries
Maximum number of retries when using adaptive time steps.
Definition: CD_CdrPlasmaImExSdcStepper.H:120
int m_p
Number of subintervals in the SDC discretization.
Definition: CD_CdrPlasmaImExSdcStepper.H:125
Vector< EBAMRCellData * > getCdrErrors()
Get errors for CDR equations.
Definition: CD_CdrPlasmaImExSdcStepper.cpp:1968
int m_minCorr
Minimum number of SDC corrections.
Definition: CD_CdrPlasmaImExSdcStepper.H:140
Real advance(const Real a_dt) override
Advance method. Implements the ImEx SDC algorithm.
Definition: CD_CdrPlasmaImExSdcStepper.cpp:548
void parseOptions() override
Parse startup options.
Definition: CD_CdrPlasmaImExSdcStepper.cpp:54
void deallocateInternals() override
De-allocation method for deleting run-time storage.
Definition: CD_CdrPlasmaImExSdcStepper.cpp:1450
RefCountedPtr< FieldStorage > m_fieldScratch
Scratch storage for the field solver.
Definition: CD_CdrPlasmaImExSdcStepper.H:110
int m_errorIdx
The species error index – allows us to restrict error evaluation and adaptive times stepping to a spe...
Definition: CD_CdrPlasmaImExSdcStepper.H:146
Vector< RefCountedPtr< CdrStorage > > m_cdrScratch
Scratch storage for the CDR solvers.
Definition: CD_CdrPlasmaImExSdcStepper.H:100
Vector< RefCountedPtr< RtStorage > > m_rteScratch
Scratch storage for the radiative transfer solvers.
Definition: CD_CdrPlasmaImExSdcStepper.H:105
int m_errorNorm
Error norm to use when using adaptive time steps.
Definition: CD_CdrPlasmaImExSdcStepper.H:135
RefCountedPtr< SigmaStorage > m_sigmaScratch
Scratch storage for the surface charge solver.
Definition: CD_CdrPlasmaImExSdcStepper.H:115
void regridInternals(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel) override
For regridding internal storage. Does nothing.
Definition: CD_CdrPlasmaImExSdcStepper.cpp:1377
void allocateInternals() override
Allocation method for setting up internal storage.
Definition: CD_CdrPlasmaImExSdcStepper.cpp:1386
virtual ~CdrPlasmaImExSdcStepper()
Destructor.
Definition: CD_CdrPlasmaImExSdcStepper.cpp:45
CdrPlasmaImExSdcStepper()=delete
Disallowed constructor – use the full constructor.
Abstract class for evolving the minimal plasma model in time.
Definition: CD_CdrPlasmaStepper.H:39
Iterator class for RtLayout.
Definition: CD_RtIterator.H:24
Name containing various physics models for running chombo-discharge code.
Definition: CD_AdvectionDiffusion.H:15