OpenLB 1.7
Loading...
Searching...
No Matches
radiativeUnitConverter.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2017 Max Gaedtke, Albert Mink
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
28#ifndef RADIATIVEUNITCONVERTER_H
29#define RADIATIVEUNITCONVERTER_H
30
31
32#include <fstream>
33#include "io/ostreamManager.h"
34#include "core/unitConverter.h"
35#include "core/singleton.h"
36#include "utilities/omath.h"
37
38
39// All OpenLB code is contained in this namespace.
40namespace olb {
41
42double getThetaRefracted(double const& thetaIncident, double const& refractiveRelative);
43double getFresnelFunction(double const& theta, double const& refractiveRelative);
44double R_phi_diff (double const& theta, double const& refractiveRelative);
45double R_j_diff (double const& theta, double const& refractiveRelative);
46double getRefractionFunction(const double& refractiveRelative);
47double getRefractionFunction(const double& refractiveRelative);
48double getPartialBBCoefficient(double const& latticeDiffusionCoefficient, double const& relativeRefractiveIndex );
49
50// forward declaration
51template<typename T, typename DESCRIPTOR> class RadiativeUnitConverter;
52
53// wrapper for above function
54template <typename T, typename DESCRIPTOR>
59
60// wrapper for above function
61template <typename T, typename DESCRIPTOR>
66
74template <typename T, typename DESCRIPTOR>
76public:
83 constexpr RadiativeUnitConverter( int resolution, T latticeRelaxationTime, T physAbsorption, T physScattering, T anisotropyFactor=0, T charPhysLength=1, T refractiveMedia=1, T refractiveAmbient=1 )
84 : UnitConverterFromResolutionAndRelaxationTime<T, DESCRIPTOR>( resolution, latticeRelaxationTime, charPhysLength, /*visc*/ 1./(3*(physAbsorption+physScattering)), T(1), T(1) ),
85 clout(std::cout, "RadiativeUnitConverter"),
86 _physAbsorption(physAbsorption),
87 _physScattering(physScattering),
88 _anisotropyFactor(anisotropyFactor),
89 _extinction( physAbsorption+physScattering ),
90 _scatteringAlbedo( physScattering/(physAbsorption+physScattering) ),
91 _physDiffusion( 1.0 / (3.0*(physAbsorption+physScattering)) ),
92 _effectiveAttenuation( util::sqrt(3*physAbsorption*(physAbsorption+physScattering)) ),
93 _refractiveRelative(refractiveMedia/refractiveAmbient),
94 _latticeAbsorption( physAbsorption*this->getConversionFactorLength() ),
95 _latticeScattering( physScattering*this->getConversionFactorLength() ),
96 _latticeDiffusion(_physDiffusion/this->getConversionFactorLength())
97 { };
98
99 constexpr T getPhysAbsorption() const
100 {
101 return _physAbsorption;
102 };
103
104 constexpr T getPhysScattering() const
105 {
106 return _physScattering;
107 };
108
109 constexpr T getAnisotropyFactor() const
110 {
111 return _anisotropyFactor;
112 };
113
114 constexpr T getExtinction() const
115 {
116 return _extinction;
117 };
118
119 constexpr T getScatteringAlbedo() const
120 {
121 return _scatteringAlbedo;
122 };
123
124 constexpr T getPhysDiffusion() const
125 {
126 return _physDiffusion;
127 };
128
129 constexpr T getEffectiveAttenuation() const
130 {
131 return _effectiveAttenuation;
132 };
133
134 constexpr T getLatticeAbsorption() const
135 {
136 return _latticeAbsorption;
137 };
138
139 constexpr T getLatticeScattering() const
140 {
141 return _latticeScattering;
142 };
143
144 constexpr T getLatticeDiffusion() const
145 {
146 return _latticeDiffusion;
147 };
148
149 constexpr T getRefractiveRelative() const
150 {
151 return _refractiveRelative;
152 };
153
154 void print() const override;
155 void print(std::ostream& fout) const;
156 void write() const;
157
158private:
159 mutable OstreamManager clout;
160
161 double _physAbsorption;
162 double _physScattering;
163 double _anisotropyFactor;
164 double _extinction;
165 double _scatteringAlbedo;
166 double _physDiffusion;
167 double _effectiveAttenuation;
168
169 double _refractiveRelative;
170
171 double _latticeAbsorption;
172 double _latticeScattering;
173 double _latticeDiffusion;
174};
175
176template <typename T, class DESCRIPTOR>
177void RadiativeUnitConverter<T, DESCRIPTOR>::print(std::ostream& clout) const
178{
179 clout << "----------------- UnitConverter information -----------------" << std::endl;
180 clout << "-- Parameters:" << std::endl;
181 clout << "Resolution: N= " << this->getResolution() << std::endl;
182 clout << "Lattice relaxation frequency: omega= " << this->getLatticeRelaxationFrequency() << std::endl;
183 clout << "Lattice relaxation time: tau= " << this->getLatticeRelaxationTime() << std::endl;
184 clout << "Characteristical length(m): charL= " << this->getCharPhysLength() << std::endl;
185 clout << "Phys. density(kg/m^d): charRho= " << this->getPhysDensity() << std::endl;
186 clout << "Phys. absorption(1/m): mu_a= " << getPhysAbsorption() << std::endl;
187 clout << "Phys. scattering(1/m): mu_s= " << getPhysScattering() << std::endl;
188 clout << "Extinction(1/m): mu_t= " << getExtinction() << std::endl;
189 clout << "Effective attenuation(1/m): mu_eff= " << getEffectiveAttenuation() << std::endl;
190 clout << "Phys. diffusion(m): D= " << getPhysDiffusion() << std::endl;
191 clout << "Single scattering albedo: albedo= " << getScatteringAlbedo() << std::endl;
192 clout << "Anisotropy factor: g= " << getAnisotropyFactor() << std::endl;
193
194 clout << std::endl;
195 clout << "Lattice diffusion: D^*= " << getLatticeDiffusion() << std::endl;
196 clout << "Lattice absorption: absorption= " << getLatticeAbsorption() << std::endl;
197 clout << "Lattice scattering: scattering= " << getLatticeScattering() << std::endl;
198 clout << "Lattice sink: sink= " << 3./8.*getLatticeAbsorption()*(getLatticeScattering()+getLatticeAbsorption()) << std::endl;
199 clout << "C_R: " << getRefractionFunction(getRefractiveRelative()) << std::endl;
200 clout << "r_F: " << getPartialBBCoefficient(getLatticeDiffusion(),getRefractiveRelative()) << std::endl;
201
202 clout << std::endl;
203 clout << "-- Conversion factors:" << std::endl;
204 clout << "Voxel length(m): physDeltaX= " << this->getConversionFactorLength() << std::endl;
205 clout << "Time step(s): physDeltaT= " << this->getConversionFactorTime() << std::endl;
206 clout << "Density factor(kg/m^3): physDensity= " << this->getConversionFactorDensity() << std::endl;
207 clout << "-------------------------------------------------------------" << std::endl;
208}
209
210template <typename T, class DESCRIPTOR>
212{
213 print(clout);
214}
215
216template <typename T, class DESCRIPTOR>
218{
219 std::string dataFile = singleton::directories().getLogOutDir() + "radiativeUnitConverter.dat";
220 if (singleton::mpi().isMainProcessor()) {
221 std::ofstream fout(dataFile.c_str(), std::ios::trunc);
222 if (!fout) {
223 clout << "error write() function: can not open std::ofstream" << std::endl;
224 }
225 else {
226 print( fout );
227 fout.close();
228 }
229 }
230
231}
232
234
235double getThetaRefracted(double const& thetaIncident, double const& refractiveRelative)
236{
237 double thetaRefracted = M_PI/2.;
238 if ( refractiveRelative * util::sin(thetaIncident) < 1 ) {
239 thetaRefracted = util::asin( refractiveRelative * util::sin(thetaIncident)); // eq.(5.118)
240 }
241 return thetaRefracted;
242};
243
244double getFresnelFunction(double const& theta, double const& refractiveRelative)
245{
246 double thetaRefracted = getThetaRefracted(theta, refractiveRelative);
247 double rf_1 = 0.5 * util::pow((refractiveRelative * util::cos(thetaRefracted) - util::cos(theta)) /
248 (refractiveRelative * util::cos(thetaRefracted) + util::cos(theta)), 2.);
249 double rf_2 = 0.5 * util::pow((refractiveRelative * util::cos(theta) - util::cos(thetaRefracted)) /
250 (refractiveRelative * util::cos(theta) + util::cos(thetaRefracted)), 2.);
251 return rf_1 + rf_2; // eq.(5.115)
252};
253
254double R_phi_diff (double const& theta, double const& refractiveRelative)
255{
256 return 2. * util::sin(theta) * util::cos(theta) * getFresnelFunction(theta,refractiveRelative);
257};
258
259double R_j_diff (double const& theta, double const& refractiveRelative)
260{
261 return 3. * util::sin(theta) * util::pow(util::cos(theta),2.) * getFresnelFunction(theta,refractiveRelative);
262};
263
264double getRefractionFunction(const double& refractiveRelative)
265{
266 int N = 10000.0;
267 double h = (M_PI / 2.) /double(N);
268 double R_phi = 0.0;
269 double R_j = 0.0;
270 for (int i = 0; i < N; i++) {
271 R_phi += h*(R_phi_diff(0.5*h + h*i,refractiveRelative));
272 R_j += h*(R_j_diff (0.5*h + h*i,refractiveRelative));
273 }
274 double R_eff = (R_phi + R_j) / (2 - R_phi + R_j); // eq.(5.112)
275 return (1 + R_eff) / (1 - R_eff); // eq.(5.111) C_R = (1 + R_eff) / (1 - R_eff);
276};
277
278double getPartialBBCoefficient(double const& latticeDiffusionCoefficient, double const& relativeRefractiveIndex )
279{
280 double C_R = getRefractionFunction( relativeRefractiveIndex );
281 return 2 - 2/(4*latticeDiffusionCoefficient*C_R +1);
282};
283
284
285} // namespace olb
286
287#endif
#define M_PI
class for marking output with some text
Conversion between physical and lattice units, as well as discretization.
constexpr RadiativeUnitConverter(int resolution, T latticeRelaxationTime, T physAbsorption, T physScattering, T anisotropyFactor=0, T charPhysLength=1, T refractiveMedia=1, T refractiveAmbient=1)
Documentation of constructor:
void print() const override
nice terminal output for conversion factors, characteristical and physical data
constexpr T getEffectiveAttenuation() const
constexpr T getRefractiveRelative() const
constexpr T getConversionFactorLength() const
access (read-only) to private member variable
std::string getLogOutDir() const
Definition singleton.h:89
MpiManager & mpi()
Directories & directories()
Definition singleton.h:150
ADf< T, DIM > sin(const ADf< T, DIM > &a)
Definition aDiff.h:569
ADf< T, DIM > asin(const ADf< T, DIM > &a)
Definition aDiff.h:596
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
Definition pack.h:112
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Definition aDiff.h:578
Top level namespace for all of OpenLB.
double getThetaRefracted(double const &thetaIncident, double const &refractiveRelative)
Documentation of implemented functions found in 5.2.2 Biomedical Optics, Principles and Imaging; Wang...
double getPartialBBCoefficient(double const &latticeDiffusionCoefficient, double const &relativeRefractiveIndex)
double R_j_diff(double const &theta, double const &refractiveRelative)
double getFresnelFunction(double const &theta, double const &refractiveRelative)
double getRefractionFunction(const double &refractiveRelative)
double R_phi_diff(double const &theta, double const &refractiveRelative)
Definition of singletons: global, publicly available information.
Unit conversion handling – header file.