chombo-discharge
CD_Driver.H
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_Driver_H
13 #define CD_Driver_H
14 
15 // Chombo includes
16 #include <RefCountedPtr.H>
17 
18 #if defined(_OPENMP) && defined(CH_USE_MEMORY_TRACKING)
19 #error "OpenMP and memory tracking are not compatible"
20 #endif
21 
22 // Our includes
24 #include <CD_TimeStepper.H>
25 #include <CD_AmrMesh.H>
26 #include <CD_CellTagger.H>
28 #include <CD_GeoCoarsener.H>
29 #include <CD_NamespaceHeader.H>
30 
35 class Driver
36 {
37 public:
41  Driver() = delete;
42 
51  Driver(const RefCountedPtr<ComputationalGeometry>& a_computationalGeometry,
52  const RefCountedPtr<TimeStepper>& a_timeStepper,
53  const RefCountedPtr<AmrMesh>& a_amr,
54  const RefCountedPtr<CellTagger>& a_cellTagger = RefCountedPtr<CellTagger>(nullptr),
55  const RefCountedPtr<GeoCoarsener>& a_geoCoarsen = RefCountedPtr<GeoCoarsener>(nullptr));
56 
60  virtual ~Driver();
61 
66  void
67  setupAndRun(const std::string a_inputFile);
68 
75  void
76  run(const Real a_startTime, const Real a_endTime, const int a_maxSteps);
77 
85  void
86  setup(const std::string a_inputFile,
87  const int a_initialRegrids,
88  const bool a_restart,
89  const std::string a_restartFile);
90 
91 protected:
95  RefCountedPtr<MultiFluidIndexSpace> m_multifluidIndexSpace;
96 
100  RefCountedPtr<AmrMesh> m_amr;
101 
105  RefCountedPtr<ComputationalGeometry> m_computationalGeometry;
106 
110  RefCountedPtr<TimeStepper> m_timeStepper;
111 
115  RefCountedPtr<CellTagger> m_cellTagger;
116 
120  RefCountedPtr<GeoCoarsener> m_geoCoarsen;
121 
125  std::string m_inputFile;
126 
130  std::string m_realm;
131 
135  std::string m_geometryGeneration;
136 
140  std::string m_outputDirectory;
141 
145  std::string m_outputFileNames;
146 
151 
156 
162 
167 
172 
177 
182 
187 
192 
197 
202 
207 
212 
217 
222 
227 
232 
236  Vector<IntVectSet> m_geomTags;
237 
242 
247 
252 
257 
262 
266  Real m_dt;
267 
271  Real m_time;
272 
276  Real m_capacitance;
277 
282 
287 
292 
297 
301  bool m_profile;
302 
307 
313 
318 
323 
328 
333 
338 
343 
347  bool m_restart;
348 
353 
358 
363 
368 
373 
378 
383  void
384  setAmr(const RefCountedPtr<AmrMesh>& a_amrMesh);
385 
389  void
390  sanityCheck();
391 
396  void
397  parseOptions();
398 
403  void
405 
410  void
412 
416  void
418 
423  void
425 
430  void
432 
436  void
438 
442  void
444 
448  void
449  cacheTags(const EBAMRTags& a_tags);
450 
454  void
456 
462  void
463  getGeometryTags();
464 
480  void
481  getCellsAndBoxes(long long& a_numLocalCells,
482  long long& a_numLocalCellsGhosts,
483  long long& a_numLocalBoxes,
484  long long& a_numTotalCells,
485  long long& a_numTotalCellsGhosts,
486  long long& a_numTotalBoxes,
487  Vector<long long>& a_numLocalLevelBoxes,
488  Vector<long long>& a_numTotalLevelBoxes,
489  Vector<long long>& a_numLocalLevelCells,
490  Vector<long long>& a_numTotalLevelCells,
491  const int& a_finestLevel,
492  const Vector<DisjointBoxLayout>& a_grids);
493 
497  void
498  gridReport();
499 
500 #ifdef CH_USE_HDF5
506  void
507  readCheckpointFile(const std::string& a_restartFile);
508 #endif
509 
516  void
517  regrid(const int a_lmin, const int a_lmax, const bool a_useInitialData);
518 
524  void
525  regridInternals(const int a_oldFinestLevel, const int a_newFinestLevel);
526 
531  void
532  setComputationalGeometry(const RefCountedPtr<ComputationalGeometry>& a_computationalGeometry);
533 
538  void
539  setTimeStepper(const RefCountedPtr<TimeStepper>& a_timeStepper);
540 
545  void
546  setCellTagger(const RefCountedPtr<CellTagger>& a_cellTagger);
547 
552  void
553  setGeoCoarsen(const RefCountedPtr<GeoCoarsener>& a_geoCoarsen);
554 
558  void
559  setupFresh(const int a_initialRegrids);
560 
564 #ifdef CH_USE_HDF5
565  void
566  setupForRestart(const int a_initialRegrids, const std::string a_restartFile);
567 #endif
568 
572  void
574 
578  void
579  checkRestartFile(const std::string a_restartFile) const;
580 
584  void
585  stepReport(const Real a_startTime, const Real a_endTime, const int a_maxSteps);
586 
592  void
593  writePlotFile(const std::string a_filename);
594 
598  void
599  writePlotFile();
600 
605  void
607 
612  void
614 
619  void
621 
626  void
627  writeCrashFile();
628 
632  void
634 
638  void
640 
644  void
646 
647 #ifdef CH_USE_HDF5
654  void
655  writeCheckpointLevel(HDF5Handle& a_handle, const int a_level);
656 #endif
657 
658 #ifdef CH_USE_HDF5
664  void
665  writeCheckpointTags(HDF5Handle& a_handle, const int a_level);
666 #endif
667 
668 #ifdef CH_USE_HDF5
674  void
675  writeCheckpointRealmLoads(HDF5Handle& a_handle, const int a_level);
676 #endif
677 
681 #ifdef CH_USE_HDF5
682  void
683  readCheckpointLevel(HDF5Handle& a_handle, const int a_level);
684 #endif
685 
689 #ifdef CH_USE_HDF5
690  void
691  readCheckpointRealmLoads(Vector<long int>& a_loads,
692  HDF5Handle& a_handle,
693  const std::string a_realm,
694  const int a_level);
695 #endif
696 
700  void
701  writeGeometry();
702 
706  bool
707  tagCells(Vector<IntVectSet>& a_allTags, EBAMRTags& a_cellTags);
708 
713  int
714  getNumberOfPlotVariables() const;
715 
719  Vector<std::string>
720  getPlotVariableNames() const;
721 
729  virtual void
730  writePlotData(LevelData<EBCellFAB>& a_output, int& a_comp, const int a_level) const noexcept;
731 
739  virtual void
740  writeTags(LevelData<EBCellFAB>& a_output, int& a_comp, const int a_level) const noexcept;
741 
749  virtual void
750  writeRanks(LevelData<EBCellFAB>& a_output, int& a_comp, const int a_level) const noexcept;
751 
759  virtual void
760  writeLevelset(LevelData<EBCellFAB>& a_output, int& a_comp, const int a_level) const noexcept;
761 
769  virtual void
770  writeLoads(LevelData<EBCellFAB>& a_output, int& a_comp, const int a_level) const noexcept;
771 
775  int
776  getFinestTagLevel(const EBAMRTags& a_cellTags) const;
777 
781  void
782  rebuildParmParse() const;
783 };
784 
785 #include <CD_NamespaceFooter.H>
786 
787 #endif
Declaration of core class for handling AMR-related operations (with embedded boundaries)
Declaration of a base class for tagging cells across an AMR hierarchy.
Declaration of base class for defining geometries.
Vector< RefCountedPtr< LayoutData< DenseIntVectSet > >> EBAMRTags
Declaration of cell tags.
Definition: CD_EBAMRTags.H:22
Declaration of a utility class for removing geometrically tagged cells.
Multi-fluid index space.
Declaration of main (abstract) time stepper class.
Main class for time/space advancement of streamer equations.
Definition: CD_Driver.H:36
int m_restartStep
Restart step.
Definition: CD_Driver.H:226
std::string m_geometryGeneration
Geometry generation method – can choose between native Chombo or chombo-discharge.
Definition: CD_Driver.H:135
bool m_allowCoarsening
Allow grid coarsening.
Definition: CD_Driver.H:327
int getFinestTagLevel(const EBAMRTags &a_cellTags) const
Return the finest tag level.
Definition: CD_Driver.cpp:1875
void getCellsAndBoxes(long long &a_numLocalCells, long long &a_numLocalCellsGhosts, long long &a_numLocalBoxes, long long &a_numTotalCells, long long &a_numTotalCellsGhosts, long long &a_numTotalBoxes, Vector< long long > &a_numLocalLevelBoxes, Vector< long long > &a_numTotalLevelBoxes, Vector< long long > &a_numLocalLevelCells, Vector< long long > &a_numTotalLevelCells, const int &a_finestLevel, const Vector< DisjointBoxLayout > &a_grids)
Get statics about a DisjointBoxLaout. This will compute the number of grid cells and patches both loc...
Definition: CD_Driver.cpp:376
void cacheTags(const EBAMRTags &a_tags)
Cache tags. This is used.
Definition: CD_Driver.cpp:192
void parseGeometryGeneration()
Parse option for geometry generation.
Definition: CD_Driver.cpp:1215
int m_irregTagGrowth
Irregular tag growth.
Definition: CD_Driver.H:155
void setupGeometryOnly()
Set for restart.
Definition: CD_Driver.cpp:1412
int m_regridInterval
Regrid interval.
Definition: CD_Driver.H:171
bool m_plotLevelset
Plot level sets.
Definition: CD_Driver.H:377
int m_numPlotGhost
Number of ghost cells to plot.
Definition: CD_Driver.H:221
std::string m_outputDirectory
Output directory for output files.
Definition: CD_Driver.H:140
void writePreRegridFile()
Write a regrid file.
Definition: CD_Driver.cpp:2172
virtual void writeLoads(LevelData< EBCellFAB > &a_output, int &a_comp, const int a_level) const noexcept
Write computational loads to output.
Definition: CD_Driver.cpp:2500
std::string m_inputFile
Input file.
Definition: CD_Driver.H:125
int m_plotInterval
Plot interval.
Definition: CD_Driver.H:181
bool tagCells(Vector< IntVectSet > &a_allTags, EBAMRTags &a_cellTags)
Tag cells for refinement. This computes cell tags and global tags (union of cell tags with geometric ...
Definition: CD_Driver.cpp:1904
EBAMRBool m_cachedTags
Cached tags. This is done so that when we regrid and change box ownership we can copy the tags around...
Definition: CD_Driver.H:246
void setupFresh(const int a_initialRegrids)
Setup function.
Definition: CD_Driver.cpp:1499
void allocateInternals()
Allocate internal storage for Driver.
Definition: CD_Driver.cpp:159
void stepReport(const Real a_startTime, const Real a_endTime, const int a_maxSteps)
Write a time step report.
Definition: CD_Driver.cpp:1765
std::string m_outputFileNames
Prefix for all output files.
Definition: CD_Driver.H:145
void parseIrregTagGrowth()
Parse irregular tag growth.
Definition: CD_Driver.cpp:1200
RefCountedPtr< MultiFluidIndexSpace > m_multifluidIndexSpace
Index space.
Definition: CD_Driver.H:95
Real m_wallClockTwo
MPI timer.
Definition: CD_Driver.H:291
void rebuildParmParse() const
Rebuild Parmparse.
Definition: CD_Driver.cpp:1019
void writeCrashFile()
Write a crash file.
Definition: CD_Driver.cpp:2223
int m_verbosity
Verbosity.
Definition: CD_Driver.H:150
void gridReport()
Print regrid report.
Definition: CD_Driver.cpp:452
Driver()=delete
Weak constructor. Not allowed.
Real m_startTime
Simulation start time.
Definition: CD_Driver.H:256
std::string m_realm
Name of realm where Driver allocates his data. This is always Realm::Primal.
Definition: CD_Driver.H:130
void writeComputationalLoads()
Write computational loads.
Definition: CD_Driver.cpp:2011
RefCountedPtr< AmrMesh > m_amr
AMR.
Definition: CD_Driver.H:100
void writePlotFile()
Write a plot file. This writes to plt/.
Definition: CD_Driver.cpp:2152
int getNumberOfPlotVariables() const
Get number of plot variables.
Definition: CD_Driver.cpp:90
EBAMRTags m_tags
Tags.
Definition: CD_Driver.H:241
void parseGeometryRefinement()
Parse geometrical refinement.
Definition: CD_Driver.cpp:1233
void writeCheckpointFile()
Write a checkpoint file.
Definition: CD_Driver.cpp:2540
void createOutputDirectories()
Create output directories.
Definition: CD_Driver.cpp:1274
bool m_plotRanks
Plot MPI ranks.
Definition: CD_Driver.H:367
int m_maxPlotLevel
Maximum plot depth.
Definition: CD_Driver.H:206
RefCountedPtr< GeoCoarsener > m_geoCoarsen
Geometric coarsener.
Definition: CD_Driver.H:120
Real m_refineAngle
Angle refinement threshold.
Definition: CD_Driver.H:296
Real m_stopTime
Simulation stop time.
Definition: CD_Driver.H:261
RefCountedPtr< TimeStepper > m_timeStepper
Time stepper.
Definition: CD_Driver.H:110
RefCountedPtr< ComputationalGeometry > m_computationalGeometry
Geometry.
Definition: CD_Driver.H:105
void setGeoCoarsen(const RefCountedPtr< GeoCoarsener > &a_geoCoarsen)
Set the geo coarsener.
Definition: CD_Driver.cpp:1074
virtual void writeLevelset(LevelData< EBCellFAB > &a_output, int &a_comp, const int a_level) const noexcept
Write level sets.
Definition: CD_Driver.cpp:2453
void getGeometryTags()
Get geometric tags.
Definition: CD_Driver.cpp:234
bool m_writeRestartFiles
Write restart files or not.
Definition: CD_Driver.H:322
void setup(const std::string a_inputFile, const int a_initialRegrids, const bool a_restart, const std::string a_restartFile)
Setup function.
Definition: CD_Driver.cpp:1366
Real m_time
Time.
Definition: CD_Driver.H:271
Real m_wallClockOne
MPI timer.
Definition: CD_Driver.H:286
void writeGeometry()
Write checkpoint data.
Definition: CD_Driver.cpp:2098
int m_geoScanLevel
Geometry scan level.
Definition: CD_Driver.H:161
void regridInternals(const int a_oldFinestLevel, const int a_newFinestLevel)
Regrid internal storage for this class.
Definition: CD_Driver.cpp:722
bool m_geometryOnly
Geometry only.
Definition: CD_Driver.H:352
void sanityCheck()
Sanity check.
Definition: CD_Driver.cpp:1754
void setupAndRun(const std::string a_inputFile)
Setup and run simulations.
Definition: CD_Driver.cpp:997
virtual void writePlotData(LevelData< EBCellFAB > &a_output, int &a_comp, const int a_level) const noexcept
Write internal plot data.
Definition: CD_Driver.cpp:2352
Real m_wallClockStart
MPI timer.
Definition: CD_Driver.H:281
void writePostRegridFile()
Write a regrid file.
Definition: CD_Driver.cpp:2189
int m_geometricTagsDepth
Geometric tag depth.
Definition: CD_Driver.H:186
void setCellTagger(const RefCountedPtr< CellTagger > &a_cellTagger)
Set the cell tagger.
Definition: CD_Driver.cpp:1059
bool m_writeMemory
Write memory report.
Definition: CD_Driver.H:337
void run(const Real a_startTime, const Real a_endTime, const int a_maxSteps)
Run a simulation for a specific time, or until a maximum number of steps have been performed.
Definition: CD_Driver.cpp:777
void parseRuntimeOptions()
Parse runtime options.
Definition: CD_Driver.cpp:1133
bool m_profile
Profile or not.
Definition: CD_Driver.H:301
int m_dielectricTagsDepth
Geometric tag depth for dielectrics.
Definition: CD_Driver.H:196
bool m_needsNewGeometricTags
Special option for when geometric tags are changed during a simulation.
Definition: CD_Driver.H:312
bool m_writeRegridFiles
Write regrid files or not.
Definition: CD_Driver.H:317
int m_timeStep
Time step.
Definition: CD_Driver.H:166
void setComputationalGeometry(const RefCountedPtr< ComputationalGeometry > &a_computationalGeometry)
Set the computational geometry.
Definition: CD_Driver.cpp:1032
void regrid(const int a_lmin, const int a_lmax, const bool a_useInitialData)
Do a regrid step.
Definition: CD_Driver.cpp:611
int m_conductorTagsDepth
Geometric tag depth for conductors.
Definition: CD_Driver.H:191
int m_maxSteps
Maximum number of steps.
Definition: CD_Driver.H:201
bool m_plotLoads
Plot patch loads.
Definition: CD_Driver.H:372
bool m_restart
Restart or not.
Definition: CD_Driver.H:347
int m_growTags
Grow tagged cells.
Definition: CD_Driver.H:231
void writeRestartFile()
Write a restart file.
Definition: CD_Driver.cpp:2206
RefCountedPtr< CellTagger > m_cellTagger
Cell tagger.
Definition: CD_Driver.H:115
void writeMemoryUsage()
Write the memory usage to file.
Definition: CD_Driver.cpp:1971
virtual void writeTags(LevelData< EBCellFAB > &a_output, int &a_comp, const int a_level) const noexcept
Write cell tags to file.
Definition: CD_Driver.cpp:2377
void parsePlotVariables()
Parse plot variables.
Definition: CD_Driver.cpp:1163
Real m_outputDt
Time between outputs.
Definition: CD_Driver.H:251
virtual ~Driver()
Destructor (does nothing)
Definition: CD_Driver.cpp:84
Real m_dt
Time increment.
Definition: CD_Driver.H:266
int m_initialRegrids
Number of initial regrids.
Definition: CD_Driver.H:216
int m_checkpointInterval
Checkpoint interval.
Definition: CD_Driver.H:176
bool m_ebisMemoryLoadBalance
Use memory as load balance for EBIS.
Definition: CD_Driver.H:357
bool m_writeLoads
Write loads to file or not.
Definition: CD_Driver.H:342
void parseOptions()
Parse options.
Definition: CD_Driver.cpp:1085
bool m_doInitLoadBalancing
Do init load balancing.
Definition: CD_Driver.H:332
virtual void writeRanks(LevelData< EBCellFAB > &a_output, int &a_comp, const int a_level) const noexcept
Write MPI ranks to output.
Definition: CD_Driver.cpp:2425
bool m_doCoarsening
Turn on/off geometry coarsening below the base level.
Definition: CD_Driver.H:306
void checkRestartFile(const std::string a_restartFile) const
Check if restart file exists.
Definition: CD_Driver.cpp:1739
int m_maxCheckpointDepth
Maximum plot depth.
Definition: CD_Driver.H:211
Vector< std::string > getPlotVariableNames() const
Get the string identifiers for the internal plot variables from Driver.
Definition: CD_Driver.cpp:116
Vector< IntVectSet > m_geomTags
Tags.
Definition: CD_Driver.H:236
void setTimeStepper(const RefCountedPtr< TimeStepper > &a_timeStepper)
Set the time stepper.
Definition: CD_Driver.cpp:1046
void setAmr(const RefCountedPtr< AmrMesh > &a_amrMesh)
Set amr.
Definition: CD_Driver.cpp:1352
bool m_plotTags
Plot tagged cells.
Definition: CD_Driver.H:362
void writeEBIS()
Write the geometry to file.