chombo-discharge
CD_McPhoto.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_McPhoto_H
13 #define CD_McPhoto_H
14 
15 // Std includes
16 #include <random>
17 
18 // Chombo includes
19 #include <Particle.H>
20 #include <ParticleData.H>
21 #include <BinItem.H>
22 
23 // Our includes
24 #include <CD_RtSolver.H>
25 #include <CD_EBParticleMesh.H>
26 #include <CD_ParticleContainer.H>
27 #include <CD_Photon.H>
28 #include <CD_PointParticle.H>
29 #include <CD_NamespaceHeader.H>
30 
38 class McPhoto : public RtSolver
39 {
40 public:
44  enum class WhichContainer
45  {
46  Photons,
47  Bulk,
48  EB,
49  Domain,
50  Source
51  };
52 
56  McPhoto();
57 
61  McPhoto(const McPhoto& a_other);
62 
66  McPhoto(const McPhoto&& a_other);
67 
71  McPhoto&
72  operator=(const McPhoto& a_other);
73 
77  McPhoto&
78  operator=(const McPhoto&& a_other);
79 
83  virtual ~McPhoto();
84 
97  virtual bool
98  advance(const Real a_dt, EBAMRCellData& a_phi, const EBAMRCellData& a_source, const bool a_zeroPhi = false) override;
99 
103  virtual bool
104  isInstantaneous();
105 
115  virtual void
117  ParticleContainer<Photon>& a_ebPhotons,
118  ParticleContainer<Photon>& a_domainPhotons,
119  ParticleContainer<Photon>& a_photons);
120 
131  virtual void
133  ParticleContainer<Photon>& a_ebPhotons,
134  ParticleContainer<Photon>& a_domainPhotons,
135  ParticleContainer<Photon>& a_photons,
136  const Real a_dt);
137 
145  virtual void
146  computeNumPhysicalPhotons(EBAMRCellData& a_numPhysPhotonsTotal,
147  EBAMRCellData& a_numPhysPhotonsPerPacket,
148  const EBAMRCellData& a_source,
149  const Real a_dt) const noexcept;
150 
157  virtual void
159  const EBAMRCellData& a_numPhysicalPhotons,
160  const size_t a_maxPhotonsPerCell) const noexcept;
161 
173  virtual void
175  EBAMRCellData& a_phi,
176  const EBAMRCellData& a_numPhysicalPhotons,
177  const size_t a_maxPhotonsPerCell) const noexcept;
178 
182  virtual void
183  remap();
184 
189  virtual void
190  remap(ParticleContainer<Photon>& a_photons);
191 
196  virtual void
197  depositPhotons();
198 
205  template <class P, const Real& (P::*particleScalarField)() const>
206  void
208  ParticleContainer<P>& a_particles,
209  const DepositionType& a_deposition) const noexcept;
210 
216  virtual void
217  sortPhotonsByCell(const WhichContainer& a_which);
218 
224  virtual void
225  sortPhotonsByPatch(const WhichContainer& a_which);
226 
230  virtual void
231  parseOptions() override;
232 
236  virtual void
237  parseRuntimeOptions() override;
238 
242  virtual void
243  allocate() override;
244 
250  virtual void
251  preRegrid(const int a_base, const int a_oldFinestLevel) override;
252 
256  virtual void
257  deallocate() override;
258 
265  virtual void
266  regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel) override;
267 
271  virtual void
272  registerOperators() override;
273 
280  virtual void
281  computeBoundaryFlux(EBAMRIVData& a_ebFlux, const EBAMRCellData& a_phi) override;
282 
289  virtual void
290  computeDomainFlux(EBAMRIFData& a_domainFlux, const EBAMRCellData& a_phi) override;
291 
298  virtual void
299  computeFlux(EBAMRCellData& a_flux, const EBAMRCellData& a_phi) override;
300 
307  virtual void
308  computeDensity(EBAMRCellData& a_isotropic, const EBAMRCellData& a_phi) override;
309 
314  virtual void
315  clear(const WhichContainer& a_which);
316 
320  virtual void
321  clear();
322 
327  virtual void
328  clear(ParticleContainer<Photon>& a_photons);
329 
334  virtual void
335  clear(AMRParticles<Photon>& a_photons);
336 
341  virtual void
342  writePlotFile() override;
343 
351  virtual void
352  writePlotData(LevelData<EBCellFAB>& a_output,
353  int& a_icomp,
354  const std::string a_outputRealm,
355  const int a_level) const noexcept override;
356 
362 #ifdef CH_USE_HDF5
363  virtual void
364  writeCheckpointLevel(HDF5Handle& a_handle, const int a_level) const override;
365 #endif
366 
372 #ifdef CH_USE_HDF5
373  virtual void
374  readCheckpointLevel(HDF5Handle& a_handle, const int a_level) override;
375 #endif
376 
381  virtual Vector<std::string>
382  getPlotVariableNames() const override;
383 
388  virtual int
389  getNumberOfPlotVariables() const override;
390 
395  virtual int
396  countPhotons(const AMRParticles<Photon>& a_photons) const;
397 
403  getPhotons();
404 
410  getBulkPhotons();
411 
417  getEbPhotons();
418 
425 
432 
436  virtual int
437  getMaxPhotonsPerCell() const noexcept;
438 
442  virtual int
443  getNumSamplingPackets() const noexcept;
444 
454  virtual void
455  computeLoads(Vector<long long>& a_loads, const DisjointBoxLayout& a_dbl, const int a_level) const noexcept override;
456 
457 protected:
461  enum class PhotonGeneration
462  {
463  Deterministic,
464  Stochastic
465  };
466 
470  enum class SourceType
471  {
472  Number,
473  PerVol,
474  PerVolSecond,
475  PerSecond
476  };
477 
483  enum class IntersectionEB
484  {
485  Raycast,
486  Bisection,
487  };
488 
493 
498 
503 
508 
513 
518 
523 
528 
533 
538 
543 
548 
552  int m_numSamplingPackets;
553 
557  int m_seed;
558 
563 
568 
573 
578 
582  IntersectionEB m_intersectionEB;
583 
588 
593 
598 
603 
608 
613 
618 
623 
628 
633 
641  size_t
642  drawPhotons(const Real a_source, const Real a_volume, const Real a_dt) const noexcept;
643 
649  int
650  domainBcMap(const int a_dir, const Side::LoHiSide a_side);
651 
656  Real
657  randomExponential(const Real a_mean) const noexcept;
658 
666  template <class P, const Real& (P::*particleScalarField)() const>
667  void
669  ParticleContainer<P>& a_particles,
670  const DepositionType a_deposition,
671  const CoarseFineDeposition a_coarseFineDeposition) const noexcept;
672 
678  void
679  depositNonConservative(EBAMRIVData& a_depositionNC, const EBAMRCellData& a_depositionKappaC) const noexcept;
680 
687  void
688  depositHybrid(EBAMRCellData& a_depositionH,
689  EBAMRIVData& a_massDifference,
690  const EBAMRIVData& a_depositionNC) const noexcept;
691 
695  void
697 
704  void
706 
710  void
712 
716  void
718 
722  void
724 
728  void
730 
734  void
735  parseSourceType();
736 
740  void
742 
746  void
747  parseDeposition();
748 
752  void
754 
761  virtual void
762  depositPhotonsNGP(LevelData<EBCellFAB>& a_output,
763  const ParticleContainer<Photon>& a_particles,
764  const int a_level) const noexcept;
765 };
766 
767 #include <CD_NamespaceFooter.H>
768 
769 #include <CD_McPhotoImplem.H>
770 
771 #endif
CoarseFineDeposition
Coarse-fine deposition types (see CD_EBAMRParticleMesh for how these are handled).
Definition: CD_CoarseFineDeposition.H:26
DepositionType
Deposition types.
Definition: CD_DepositionType.H:23
Declaration of a class for handling particle-mesh interpolation and deposition.
Implementation of CD_McPhoto.H.
Declaration of a class for holding particles on an AMR hierarchy.
Vector< RefCountedPtr< ParticleData< P > >> AMRParticles
Alias for ParticleData on each AMR level.
Definition: CD_ParticleContainer.H:34
Declaration of a photon class for particle methods.
Declaration of a computational point particle.
Abstract parent class for various radiative transfer solvers.
Radiative tranfer equation solver using Monte-Carlo simulation.
Definition: CD_McPhoto.H:39
void depositNonConservative(EBAMRIVData &a_depositionNC, const EBAMRCellData &a_depositionKappaC) const noexcept
Make the "non-conservative" kappa deposition.
Definition: CD_McPhoto.cpp:1297
bool m_plotDomainPhotons
Check if m_ebPhotons should be plotted.
Definition: CD_McPhoto.H:537
ParticleContainer< Photon > m_domainPhotons
This is a particle container for Photons that crossed boundaries. It is filled during the advance ste...
Definition: CD_McPhoto.H:627
virtual int getNumberOfPlotVariables() const override
Get number of output variables.
Definition: CD_McPhoto.cpp:842
bool m_transparentEB
Turn on/off transparent boundaries.
Definition: CD_McPhoto.H:492
ParticleContainer< Photon > m_sourcePhotons
This is a particle container that can be used to add Photons directly.
Definition: CD_McPhoto.H:632
virtual void computeFlux(EBAMRCellData &a_flux, const EBAMRCellData &a_phi) override
Compute the flux.
Definition: CD_McPhoto.cpp:734
void parseInstantaneous()
Parse whether instantaneous propagation or not.
Definition: CD_McPhoto.cpp:239
void parseIntersectionEB()
Parse EB intersection algorithm.
Definition: CD_McPhoto.cpp:333
virtual void preRegrid(const int a_base, const int a_oldFinestLevel) override
preRegrid operations
Definition: CD_McPhoto.cpp:548
SourceType m_sourceType
Source type.
Definition: CD_McPhoto.H:577
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel) override
Regrid function for this class.
Definition: CD_McPhoto.cpp:580
size_t drawPhotons(const Real a_source, const Real a_volume, const Real a_dt) const noexcept
Draw photons in a cell and volume.
Definition: CD_McPhoto.cpp:977
void depositKappaConservative(EBAMRCellData &a_phi, ParticleContainer< P > &a_particles, const DepositionType a_deposition, const CoarseFineDeposition a_coarseFineDeposition) const noexcept
This computes the "conservative" deposition, multiplied by kappa.
Definition: CD_McPhotoImplem.H:67
bool m_blendConservation
Flag for blending the deposition clouds with the nonconservative divergence.
Definition: CD_McPhoto.H:502
virtual void computeNumPhysicalPhotons(EBAMRCellData &a_numPhysPhotonsTotal, EBAMRCellData &a_numPhysPhotonsPerPacket, const EBAMRCellData &a_source, const Real a_dt) const noexcept
Compute the number of physical photons in each grid cell.
Definition: CD_McPhoto.cpp:892
virtual ParticleContainer< Photon > & getDomainPhotons()
Get domain photons, i.e. photons absorbed on domain edges/faces.
Definition: CD_McPhoto.cpp:1926
WhichContainer
Enum class for identifying various containers. Only used for interface reasons.
Definition: CD_McPhoto.H:45
virtual void computeDensity(EBAMRCellData &a_isotropic, const EBAMRCellData &a_phi) override
Compute isotropic radiative density from mesh solution.
Definition: CD_McPhoto.cpp:748
virtual ParticleContainer< Photon > & getEbPhotons()
Get eb Photons, i.e. photons absorbed on the EB.
Definition: CD_McPhoto.cpp:1915
virtual ~McPhoto()
Destructor.
Definition: CD_McPhoto.cpp:43
virtual void dirtySamplePhotons(ParticleContainer< PointParticle > &a_photons, EBAMRCellData &a_phi, const EBAMRCellData &a_numPhysicalPhotons, const size_t a_maxPhotonsPerCell) const noexcept
Dirty-sampling method for photons.
Definition: CD_McPhoto.cpp:1133
bool m_depositNumber
If true, the NUMBER of of Photons will be deposited in each cell.
Definition: CD_McPhoto.H:507
DepositionType m_deposition
Deposition type.
Definition: CD_McPhoto.H:587
size_t m_maxPhotonsGeneratedPerCell
Number of computational photons generated per cell.
Definition: CD_McPhoto.H:547
bool m_dirtySampling
Dirty sampling or not.
Definition: CD_McPhoto.H:542
void parseTransparentBoundaries()
Turn on/off transparent boundaries.
Definition: CD_McPhoto.cpp:198
void parseDirtySampling()
Parse dirty sampling for photons.
Definition: CD_McPhoto.cpp:211
virtual void computeBoundaryFlux(EBAMRIVData &a_ebFlux, const EBAMRCellData &a_phi) override
Compute the boundary flux.
Definition: CD_McPhoto.cpp:712
bool m_instantaneous
Instantaneous transport or not.
Definition: CD_McPhoto.H:497
void parseSourceType()
Parse source term type.
Definition: CD_McPhoto.cpp:303
ParticleContainer< Photon > m_bulkPhotons
Photons absorbed in the volume.
Definition: CD_McPhoto.H:617
void parsePhotoGeneration()
Parse photogeneration type.
Definition: CD_McPhoto.cpp:279
Real m_bisectStep
Bisection step for when we use the bisection intersection algorithm.
Definition: CD_McPhoto.H:567
virtual void deallocate() override
Deallocate internal storage.
Definition: CD_McPhoto.cpp:565
void parsePseudoPhotons()
Parse pseudophotons, i.e. parse how many photons can be generated per cell.
Definition: CD_McPhoto.cpp:252
IntersectionEB
An enum for switching between various types of EB intersection algorithms when intersecting photons w...
Definition: CD_McPhoto.H:484
virtual void computeDomainFlux(EBAMRIFData &a_domainFlux, const EBAMRCellData &a_phi) override
Compute the domain flux.
Definition: CD_McPhoto.cpp:723
virtual void advancePhotonsTransient(ParticleContainer< Photon > &a_bulkPhotons, ParticleContainer< Photon > &a_ebPhotons, ParticleContainer< Photon > &a_domainPhotons, ParticleContainer< Photon > &a_photons, const Real a_dt)
Move photons and absorb them on various objects.
Definition: CD_McPhoto.cpp:1568
McPhoto(const McPhoto &a_other)
Disallowed copy constructor.
EBAMRIVData m_massDiff
Scratch storage for holding the mass difference when using hybrid deposition.
Definition: CD_McPhoto.H:607
bool m_plotPhotons
Check if m_photons should be plotted.
Definition: CD_McPhoto.H:517
virtual void remap()
Remap computational particles. This remaps m_photons.
Definition: CD_McPhoto.cpp:1735
virtual void allocate() override
Allocate internal storage.
Definition: CD_McPhoto.cpp:525
bool m_plotNumbers
Switch for plotting numbers or densities.
Definition: CD_McPhoto.H:512
McPhoto()
Constructor.
Definition: CD_McPhoto.cpp:32
virtual void computeLoads(Vector< long long > &a_loads, const DisjointBoxLayout &a_dbl, const int a_level) const noexcept override
Get computational loads for a specific grid level. This computes the number of photons in the bulk da...
Definition: CD_McPhoto.cpp:1970
bool m_plotEBPhotons
Check if m_ebPhotons should be plotted.
Definition: CD_McPhoto.H:532
virtual Vector< std::string > getPlotVariableNames() const override
Write checkpoint data into handle.
Definition: CD_McPhoto.cpp:807
virtual ParticleContainer< Photon > & getPhotons()
Get m_photons.
Definition: CD_McPhoto.cpp:1893
int domainBcMap(const int a_dir, const Side::LoHiSide a_side)
Mapping function for domain boundary conditions.
Definition: CD_McPhoto.cpp:877
virtual ParticleContainer< Photon > & getSourcePhotons()
Get source photons.
Definition: CD_McPhoto.cpp:1937
virtual ParticleContainer< Photon > & getBulkPhotons()
Get bulk photons, i.e. photons absorbed on the mesh.
Definition: CD_McPhoto.cpp:1904
void depositHybrid(EBAMRCellData &a_depositionH, EBAMRIVData &a_massDifference, const EBAMRIVData &a_depositionNC) const noexcept
Make the hybrid deposition. Also compute the mass difference.
Definition: CD_McPhoto.cpp:1316
virtual void clear()
Clear data holder.
Definition: CD_McPhoto.cpp:490
virtual void parseOptions() override
Parse class options.
Definition: CD_McPhoto.cpp:153
ParticleContainer< Photon > m_ebPhotons
This is a particle container for Photons that crossed EBs. It is filled during the advance step.
Definition: CD_McPhoto.H:622
virtual void parseRuntimeOptions() override
Parse runtime options.
Definition: CD_McPhoto.cpp:177
CoarseFineDeposition m_coarseFineDeposition
Coarse-fine deposition strategy.
Definition: CD_McPhoto.H:592
void parseDivergenceComputation()
Parse the divergence computation, i.e. if we blend with non-conservative divergence or not.
Definition: CD_McPhoto.cpp:226
PhotonGeneration
Enum for interpreting how photons are generated when using fluid codes.
Definition: CD_McPhoto.H:462
virtual void sortPhotonsByPatch(const WhichContainer &a_which)
Sort container by patch.
Definition: CD_McPhoto.cpp:647
SourceType
Enum for adding flexibility in what the fluid source term contains.
Definition: CD_McPhoto.H:471
ParticleContainer< Photon > m_photons
All particles.
Definition: CD_McPhoto.H:612
virtual void writePlotFile() override
Write plot file.
Definition: CD_McPhoto.cpp:760
virtual void depositPhotons()
Deposit photons on the mesh.
Definition: CD_McPhoto.cpp:1286
void parseDeposition()
Parse deposition method.
Definition: CD_McPhoto.cpp:359
McPhoto & operator=(const McPhoto &&a_other)
Disallowed move assignement operator.
McPhoto(const McPhoto &&a_other)
Disallowed move constructor.
virtual void advancePhotonsInstantaneous(ParticleContainer< Photon > &a_bulkPhotons, ParticleContainer< Photon > &a_ebPhotons, ParticleContainer< Photon > &a_domainPhotons, ParticleContainer< Photon > &a_photons)
Move photons and absorb them on various objects.
Definition: CD_McPhoto.cpp:1409
PhotonGeneration m_photoGenerationMethod
Photon generation type.
Definition: CD_McPhoto.H:572
virtual void writePlotData(LevelData< EBCellFAB > &a_output, int &a_icomp, const std::string a_outputRealm, const int a_level) const noexcept override
Write plot data.
Definition: CD_McPhoto.cpp:1774
McPhoto & operator=(const McPhoto &a_other)
Disallowed assignment operator.
Real randomExponential(const Real a_mean) const noexcept
Random exponential trial.
Definition: CD_McPhoto.cpp:885
void parsePlotVariables()
Parse plot variables.
Definition: CD_McPhoto.cpp:402
int m_seed
RNG seed.
Definition: CD_McPhoto.H:557
virtual int getMaxPhotonsPerCell() const noexcept
Get maximum number of photons generated per cell.
Definition: CD_McPhoto.cpp:1948
virtual void sortPhotonsByCell(const WhichContainer &a_which)
Sort container by cell.
Definition: CD_McPhoto.cpp:605
virtual int getNumSamplingPackets() const noexcept
Get maximum number of photons generated per cell.
Definition: CD_McPhoto.cpp:1959
virtual bool advance(const Real a_dt, EBAMRCellData &a_phi, const EBAMRCellData &a_source, const bool a_zeroPhi=false) override
Advance RTE and deposit photon particles on the mesh.
Definition: CD_McPhoto.cpp:47
virtual int countPhotons(const AMRParticles< Photon > &a_photons) const
Count number of photons in particle list.
Definition: CD_McPhoto.cpp:1757
EBAMRIVData m_depositionNC
Scratch storage for holding the non-conservative deposition.
Definition: CD_McPhoto.H:602
virtual void registerOperators() override
Register operators that this solver needs.
Definition: CD_McPhoto.cpp:689
virtual void generateComputationalPhotons(ParticleContainer< Photon > &a_photons, const EBAMRCellData &a_numPhysicalPhotons, const size_t a_maxPhotonsPerCell) const noexcept
Generate computational photons.
Definition: CD_McPhoto.cpp:1022
EBAMRCellData m_scratch
Coarse data for interpolation of deposition clouds.
Definition: CD_McPhoto.H:597
virtual bool isInstantaneous()
Instantaneous solver or not.
Definition: CD_McPhoto.cpp:147
bool m_plotSourcePhotons
Check if source_bulkPhotons should be plotted.
Definition: CD_McPhoto.H:527
bool m_plotBulkPhotons
Check if m_bulkPhotons should be plotted.
Definition: CD_McPhoto.H:522
virtual void depositPhotonsNGP(LevelData< EBCellFAB > &a_output, const ParticleContainer< Photon > &a_particles, const int a_level) const noexcept
Do an NGP deposit on a specific grid level. Used for IO.
Definition: CD_McPhoto.cpp:1365
int m_haloBuffer
Halo size for particles.
Definition: CD_McPhoto.H:562
Abstract RTE solver class for doing various kinds of radiative transfer equations....
Definition: CD_RtSolver.H:30