ABLATE Source Documentation  0.12.33
radiation.hpp
1 #ifndef ABLATELIBRARY_RADIATION_HPP
2 #define ABLATELIBRARY_RADIATION_HPP
3 
4 #include <petsc/private/dmimpl.h>
5 #include <petscdm.h>
6 #include <petscdmswarm.h>
7 #include <petscsf.h>
8 #include <memory>
9 #include <set>
10 #include <utility>
11 #include "eos/radiationProperties/radiationProperties.hpp"
12 #include "finiteVolume/compressibleFlowFields.hpp"
13 #include "finiteVolume/finiteVolumeSolver.hpp"
14 #include "io/interval/interval.hpp"
15 #include "monitors/logs/log.hpp"
16 #include "solver/cellSolver.hpp"
17 #include "solver/timeStepper.hpp"
18 #include "utilities/constants.hpp"
19 #include "utilities/loggable.hpp"
20 #include "utilities/mpiUtilities.hpp"
21 #include "utilities/petscUtilities.hpp"
22 
23 namespace ablate::radiation {
24 
25 class Radiation : protected utilities::Loggable<Radiation> {
27 
28  public:
36  Radiation(const std::string& solverId, const std::shared_ptr<domain::Region>& region, const PetscInt raynumber, std::shared_ptr<eos::radiationProperties::RadiationModel> radiationModelIn,
37  std::shared_ptr<ablate::monitors::logs::Log> = {});
38 
39  virtual ~Radiation();
40 
44  struct Identifier {
46  PetscInt originRank;
48  PetscInt originRayId;
50  PetscInt remoteRank;
52  PetscInt remoteRayId;
54  PetscInt nSegment;
55  };
56 
59  struct Carrier {
60  PetscReal Ij = 0;
61  PetscReal Krad = 1;
62  };
63 
70  static inline PetscReal GetBlackBodyTotalIntensity(PetscReal temperature, const PetscReal refractiveIndex) {
71  return refractiveIndex * refractiveIndex * ablate::utilities::Constants::sbc * temperature * temperature * temperature * temperature / ablate::utilities::Constants::pi;
72  }
73 
82  static inline PetscReal GetBlackBodyWavelengthIntensity(const PetscReal temperature, const PetscReal wavelength, const PetscReal refractiveIndex) {
84  E_lambda /= refractiveIndex * refractiveIndex * wavelength * wavelength * wavelength * wavelength * wavelength;
85  E_lambda /= exp((ablate::utilities::Constants::h * ablate::utilities::Constants::c) / (refractiveIndex * wavelength * ablate::utilities::Constants::k * temperature)) - 1;
87 
88  return E_lambda;
89  }
90 
95  static inline std::string GetClassType() { return "Radiation"; }
96 
98  virtual void Setup(const ablate::domain::Range& cellRange, ablate::domain::SubDomain& subDomain);
99 
103  virtual void Initialize(const ablate::domain::Range& cellRange, ablate::domain::SubDomain& subDomain);
104 
113  inline void GetIntensity(PetscReal* intensity, PetscInt index, const domain::Range& cellRange, PetscReal temperature, PetscReal kappa) {
114  for (int i = 0; i < (int)absorptivityFunction.propertySize; ++i) { // Compute the losses
115  PetscReal netIntensity = -4.0 * ablate::utilities::Constants::pi * GetBlackBodyTotalIntensity(temperature, 1);
116 
117  // add in precomputed gains
118  netIntensity += evaluatedGains[absorptivityFunction.propertySize * (index - cellRange.start) + i];
119 
120  // scale by kappa
121  netIntensity *= kappa;
122 
123  intensity[i] = abs(netIntensity) > ablate::utilities::Constants::large ? ablate::utilities::Constants::large * PetscSignReal(netIntensity) : netIntensity;
124  }
125  }
126 
127  // Add a class called "radiation surface properties" which is used to compute the amount of intensity absorbed by the material. This should be an optional input in the radiation base class.
128  // GetIntensity should compute this, because otherwise the losses will not be accounted for.
129  // Just embed a function within the GetIntensity function that "Computes surface properties" and decides how much of the radiation to do.
130  // Also. the losses are wavelength dependent based on what portion of the black body temperature they are emitting.
131  // Then, the camera properties will be able to be viewed as a radiation surface property.
132  // The radiation solver can take a vector of radiation surface properties.
133  // Each radiation surface property will be evaluated on the EvaluateGains call.
134  // Each property can be output separately.
135 
136  inline std::string GetId() { return solverId; };
137 
138  inline eos::ThermodynamicTemperatureFunction GetAbsorptionFunction() { return absorptivityFunction; };
139 
142  void EvaluateGains(Vec solVec, ablate::domain::Field temperatureField, Vec auxVec);
143 
146  virtual void ParticleStep(ablate::domain::SubDomain& subDomain, DM faceDM, const PetscScalar* faceGeomArray, DM radReturn, PetscInt nlocalpoints,
147  PetscInt nglobalpoints);
148 
150  virtual void IdentifyNewRaysOnRank(domain::SubDomain& subDomain, DM radReturn, PetscInt nlocalpoints);
151 
155  virtual PetscReal SurfaceComponent(const PetscReal normal[], PetscInt iCell, PetscInt nphi, PetscInt ntheta);
156 
158  inline std::shared_ptr<eos::radiationProperties::RadiationModel> GetRadiationModel() { return radiationModel; }
159 
160  protected:
162  DM radSearch = nullptr;
163 
165  Vec faceGeomVec = nullptr;
166  Vec cellGeomVec = nullptr;
167 
169  MPI_Datatype carrierMpiType;
170 
172  struct CellSegment {
174  PetscInt cell;
176  PetscReal pathLength;
177  };
178 
180  struct Virtualcoord {
181  PetscReal x;
182  PetscReal y;
183  PetscReal z;
184  PetscReal xdir;
185  PetscReal ydir;
186  PetscReal zdir;
187  PetscReal hhere;
188  };
189 
191 
197  PetscReal FaceIntersect(PetscInt ip, Virtualcoord* virtualcoord, PetscFVFaceGeom* face) const;
198 
207  void UpdateCoordinates(PetscInt ipart, Virtualcoord* virtualcoord, PetscReal* coord, PetscReal adv) const;
208 
215 
216  virtual void SetBoundary(CellSegment& raySegment, PetscInt index, Identifier identifier) {
217  raySegment.cell = index;
218  raySegment.pathLength = -1;
219  }
220 
222  PetscInt dim = 0;
223  PetscInt nTheta;
224  PetscInt nPhi;
225  PetscReal minCellRadius{};
226 
228  std::vector<std::vector<CellSegment>> raySegments;
229 
231  std::vector<Carrier> raySegmentsCalculations;
232 
235 
238 
240  PetscInt raysPerCell;
241 
243  std::vector<unsigned short int> raySegmentsPerOriginRay;
244 
246  std::vector<Carrier> raySegmentSummary;
247 
249  std::vector<PetscReal> gainsFactor;
250 
252  std::vector<PetscScalar> evaluatedGains;
253 
255  PetscSF remoteAccess = nullptr;
256 
258  std::string solverId;
259 
261  const std::shared_ptr<domain::Region> region;
262 
264  const std::shared_ptr<eos::radiationProperties::RadiationModel> radiationModel;
265 
268  eos::ThermodynamicTemperatureFunction emissivityFunction;
269 
270  // !Store a log used to output the required information
271  const std::shared_ptr<ablate::monitors::logs::Log> log = nullptr;
272  static inline constexpr char IdentifierField[] = "identifier";
273  static inline constexpr char VirtualCoordField[] = "virtual coord";
274 
275  public:
280  inline std::shared_ptr<domain::Region> GetRegion() const { return region; }
281 };
288 std::ostream& operator<<(std::ostream& os, const Radiation::Identifier& id);
289 
290 } // namespace ablate::radiation
291 #endif
Definition: subDomain.hpp:19
Definition: radiation.hpp:25
PetscInt nPhi
The number of angles to solve with, given by user input (x2)
Definition: radiation.hpp:224
Radiation(const std::string &solverId, const std::shared_ptr< domain::Region > &region, const PetscInt raynumber, std::shared_ptr< eos::radiationProperties::RadiationModel > radiationModelIn, std::shared_ptr< ablate::monitors::logs::Log >={})
Definition: radiation.cpp:3
PetscInt dim
Class inputs and Variables.
Definition: radiation.hpp:222
std::vector< Carrier > raySegmentsCalculations
the calculation over each of the remoteRays. indexed over remote ray
Definition: radiation.hpp:231
virtual void ParticleStep(ablate::domain::SubDomain &subDomain, DM faceDM, const PetscScalar *faceGeomArray, DM radReturn, PetscInt nlocalpoints, PetscInt nglobalpoints)
Routine to move the particle one step.
Definition: radiation.cpp:453
MPI_Datatype carrierMpiType
create a data type to simplify moving the carrier
Definition: radiation.hpp:169
std::vector< PetscScalar > evaluatedGains
size up the evaluated gains, this index is based upon order of the requested cells
Definition: radiation.hpp:252
PetscReal FaceIntersect(PetscInt ip, Virtualcoord *virtualcoord, PetscFVFaceGeom *face) const
Class Methods.
Definition: radiation.cpp:373
virtual void IdentifyNewRaysOnRank(domain::SubDomain &subDomain, DM radReturn, PetscInt nlocalpoints)
If this local rank has never seen this search particle before, then it needs to add a new ray segment...
Definition: radiation.cpp:402
std::vector< PetscReal > gainsFactor
the factor for each origin ray
Definition: radiation.hpp:249
PetscInt numberOriginRays
store the number of originating rays
Definition: radiation.hpp:234
void UpdateCoordinates(PetscInt ipart, Virtualcoord *virtualcoord, PetscReal *coord, PetscReal adv) const
Definition: radiation.cpp:356
void EvaluateGains(Vec solVec, ablate::domain::Field temperatureField, Vec auxVec)
Definition: radiation.cpp:536
PetscInt nTheta
The number of angles to solve with, given by user input.
Definition: radiation.hpp:223
static PetscReal GetBlackBodyTotalIntensity(PetscReal temperature, const PetscReal refractiveIndex)
Definition: radiation.hpp:70
static PetscReal GetBlackBodyWavelengthIntensity(const PetscReal temperature, const PetscReal wavelength, const PetscReal refractiveIndex)
Definition: radiation.hpp:82
Vec faceGeomVec
Vector used to describe the entire face geom of the dm. This is constant and does not depend upon reg...
Definition: radiation.hpp:165
std::vector< unsigned short int > raySegmentsPerOriginRay
store the number of ray segments for each originating on this rank. This may be zero
Definition: radiation.hpp:243
PetscInt numberOriginCells
store the number of originating rays cells
Definition: radiation.hpp:237
eos::ThermodynamicTemperatureFunction absorptivityFunction
hold a pointer to the absorptivity function
Definition: radiation.hpp:267
const std::shared_ptr< eos::radiationProperties::RadiationModel > radiationModel
model used to provided the absorptivity function
Definition: radiation.hpp:264
void DeleteOutOfBounds(ablate::domain::SubDomain &subDomain)
Definition: radiation.cpp:656
void GetIntensity(PetscReal *intensity, PetscInt index, const domain::Range &cellRange, PetscReal temperature, PetscReal kappa)
Definition: radiation.hpp:113
virtual void Initialize(const ablate::domain::Range &cellRange, ablate::domain::SubDomain &subDomain)
Definition: radiation.cpp:156
std::vector< std::vector< CellSegment > > raySegments
store the local rays identified on this rank. This includes rays that do and do not originate on this...
Definition: radiation.hpp:228
std::string solverId
the name of this solver
Definition: radiation.hpp:258
std::shared_ptr< eos::radiationProperties::RadiationModel > GetRadiationModel()
provide access to the model used to provided the absorptivity function
Definition: radiation.hpp:158
static std::string GetClassType()
Definition: radiation.hpp:95
DM radSearch
DM which the search particles occupy. This representations the physical particle in space.
Definition: radiation.hpp:162
virtual void Setup(const ablate::domain::Range &cellRange, ablate::domain::SubDomain &subDomain)
Definition: radiation.cpp:15
virtual PetscReal SurfaceComponent(const PetscReal normal[], PetscInt iCell, PetscInt nphi, PetscInt ntheta)
Definition: radiation.cpp:400
const std::shared_ptr< domain::Region > region
the region for which this solver applies
Definition: radiation.hpp:261
PetscInt raysPerCell
the number of rays per cell
Definition: radiation.hpp:240
PetscSF remoteAccess
Store the petscSF that is used for pulling remote ray calculation.
Definition: radiation.hpp:255
std::shared_ptr< domain::Region > GetRegion() const
Definition: radiation.hpp:280
std::vector< Carrier > raySegmentSummary
a vector of raySegment information for every local/remote ray segment ordered as ray,...
Definition: radiation.hpp:246
constexpr static PetscReal pi
Pi.
Definition: constants.hpp:22
constexpr static PetscReal sbc
Stefan-Boltzman Constant (J/K)
Definition: constants.hpp:10
constexpr static PetscReal k
Boltzmann Constant.
Definition: constants.hpp:19
constexpr static PetscReal c
Speed of light.
Definition: constants.hpp:16
constexpr static PetscReal large
A somewhat large number.
Definition: constants.hpp:31
constexpr static PetscReal h
Planck Constant.
Definition: constants.hpp:13
Definition: loggable.hpp:9
Definition: field.hpp:17
Definition: range.hpp:11
PetscInt propertySize
the property size being set
Definition: eos.hpp:48
Definition: radiation.hpp:59
PetscReal Krad
Absorption for the segment. Make sure that this is reset every solve after the value has been transpo...
Definition: radiation.hpp:61
PetscReal Ij
Black body source for the segment. Make sure that this is reset every solve after the value has been ...
Definition: radiation.hpp:60
Definition: radiation.hpp:172
PetscInt cell
< Stores the cell indices of the segment locally.
Definition: radiation.hpp:174
Definition: radiation.hpp:44
PetscInt remoteRank
the remote rank (may be same as originating) for this segment id
Definition: radiation.hpp:50
PetscInt nSegment
The number of segments away from the origin, zero on the origin.
Definition: radiation.hpp:54
PetscInt remoteRayId
The local ray id 'index'.
Definition: radiation.hpp:52
PetscInt originRayId
The local ray id 'index'.
Definition: radiation.hpp:48
PetscInt originRank
the rank for the start of the ray
Definition: radiation.hpp:46
Definition: radiation.hpp:180