OpenLB 1.7
Loading...
Searching...
No Matches
unitConverter.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 UNITCONVERTER_H
29#define UNITCONVERTER_H
30
31
32#include "utilities/omath.h"
33#include "io/ostreamManager.h"
34#include "core/util.h"
35#include "io/xmlReader.h"
36
37// known design issues
38// 1. How can we prevent abuse of constructur by mixing up parameters?
39// 2. physical problems may have different names for viscosity, e.g. diffusity, temperature conductivity
40// 4. Feedback about stability or comment the chosen discretization
41// 5. Explain why Desctiptor as template
42// 6. Is it worth to introduce invConversionDensity to avoid division
43
44
45// All OpenLB code is contained in this namespace.
46namespace olb {
47
49 virtual ~UnitConverterBase() = default;
50
51 virtual void print() const = 0;
52 virtual void print(std::ostream& fout) const = 0;
53 virtual void write(std::string const& fileName = "unitConverter") const = 0;
54};
55
56
84template <typename T, typename DESCRIPTOR>
86public:
96 constexpr UnitConverter( T physDeltaX, T physDeltaT, T charPhysLength, T charPhysVelocity,
97 T physViscosity, T physDensity, T charPhysPressure = 0 )
98 : _conversionLength(physDeltaX),
99 _conversionTime(physDeltaT),
101 _conversionDensity(physDensity),
107 _charPhysLength(charPhysLength),
108 _charPhysVelocity(charPhysVelocity),
109 _physViscosity(physViscosity),
110 _physDensity(physDensity),
111 _charPhysPressure(charPhysPressure),
113 _latticeRelaxationTime( (_physViscosity / _conversionViscosity * descriptors::invCs2<T,DESCRIPTOR>()) + 0.5 ),
115 clout(std::cout,"UnitConverter")
116 {
117 }
118
119 virtual ~UnitConverter() = default;
120
122 constexpr int getResolution( ) const
123 {
124 return _resolution;
125 }
127 constexpr T getLatticeRelaxationTime( ) const
128 {
130 }
132 constexpr T getLatticeRelaxationFrequency( ) const
133 {
134 return 1./_latticeRelaxationTime;
135 }
137 template <typename DESCRIPTOR_>
138 constexpr T getLatticeRelaxationFrequencyFromDiffusivity( const T physDiffusivity ) const
139 {
140 return 1.0 / ( physDiffusivity / _conversionViscosity * descriptors::invCs2<T,DESCRIPTOR_>() + 0.5 );
141 }
143 constexpr T getCharPhysLength( ) const
144 {
145 return _charPhysLength;
146 }
148 constexpr T getCharPhysVelocity( ) const
149 {
150 return _charPhysVelocity;
151 }
153 constexpr T getCharLatticeVelocity( ) const
154 {
156 }
158 constexpr T getPhysViscosity( ) const
159 {
160 return _physViscosity;
161 }
163 constexpr T getPhysDensity( ) const
164 {
165 return _physDensity;
166 }
168 constexpr T getCharPhysPressure( ) const
169 {
170 return _charPhysPressure;
171 }
173 constexpr T getReynoldsNumber( ) const
174 {
176 }
178 constexpr T getMachNumber( ) const
179 {
180 return getCharLatticeVelocity() * util::sqrt(descriptors::invCs2<T,DESCRIPTOR>());
181 }
183 constexpr T getKnudsenNumber( ) const
184 {
185 // This calculates the lattice Knudsen number.
186 // See e.g. (7.22) in "The Lattice Boltzmann Method: Principles and Practice" [kruger2017lattice].
187 return getMachNumber() / getReynoldsNumber();
188 }
190 constexpr T getPhysLength( int latticeLength ) const
191 {
192 return _conversionLength * latticeLength;
193 }
195 constexpr int getLatticeLength( T physLength ) const
196 {
197 return int( physLength / _conversionLength + 0.5 );
198 }
200 constexpr T getConversionFactorLength() const
201 {
202 return _conversionLength;
203 }
205 constexpr T getPhysDeltaX() const
206 {
207 return _conversionLength;
208 }
209
211 constexpr T getPhysTime( size_t latticeTime ) const
212 {
213 return _conversionTime * latticeTime;
214 }
216 constexpr size_t getLatticeTime( T physTime ) const
217 {
218 return size_t(physTime / _conversionTime + 0.5);
219 }
221 constexpr T getConversionFactorTime() const
222 {
223 return _conversionTime;
224 }
226 constexpr T getPhysDeltaT() const
227 {
228 return _conversionTime;
229 }
230
232 constexpr T getPhysVelocity( T latticeVelocity ) const
233 {
234 return _conversionVelocity * latticeVelocity;
235 }
237 constexpr T getLatticeVelocity( T physVelocity ) const
238 {
239 return physVelocity / _conversionVelocity;
240 }
242 constexpr T getConversionFactorVelocity() const
243 {
244 return _conversionVelocity;
245 }
246
248 constexpr T getPhysDensity( T latticeDensity ) const
249 {
250 return _conversionDensity * latticeDensity;
251 }
253 constexpr T getLatticeDensity( T physDensity ) const
254 {
255 return physDensity / _conversionDensity;
256 }
257 constexpr T getLatticeDensityFromPhysPressure( T physPressure ) const
258 {
259 return util::densityFromPressure<T,DESCRIPTOR>( getLatticePressure( physPressure ) );
260 }
262 constexpr T getConversionFactorDensity() const
263 {
264 return _conversionDensity;
265 }
266
268 constexpr T getPhysMass( T latticeMass ) const
269 {
270 return _conversionMass * latticeMass;
271 }
273 constexpr T getLatticeMass( T physMass ) const
274 {
275 return physMass / _conversionMass;
276 }
278 constexpr T getConversionFactorMass() const
279 {
280 return _conversionMass;
281 }
282
284 constexpr T getPhysViscosity( T latticeViscosity ) const
285 {
286 return _conversionViscosity * latticeViscosity;
287 }
289 constexpr T getLatticeViscosity( ) const
290 {
292 }
295 {
297 }
298
300 constexpr T getPhysForce( T latticeForce ) const
301 {
302 return _conversionForce * latticeForce;
303 }
305 constexpr T getLatticeForce( T physForce ) const
306 {
307 return physForce / _conversionForce;
308 }
310 constexpr T getConversionFactorForce() const
311 {
312 return _conversionForce;
313 }
314
316 constexpr T getPhysTorque ( T latticeTorque ) const
317 {
318 return _conversionTorque * latticeTorque;
319 }
321 constexpr T getLatticeTorque( T physTorque ) const
322 {
323 return physTorque / _conversionTorque;
324 }
326 constexpr T getConversionFactorTorque() const
327 {
328 return _conversionTorque;
329 }
330
332 constexpr T getPhysPressure( T latticePressure ) const
333 {
334 return _conversionPressure * latticePressure + _charPhysPressure;
335 }
337 constexpr T getLatticePressure( T physPressure ) const
338 {
339 return ( physPressure - _charPhysPressure ) / _conversionPressure;
340 }
342 constexpr T getConversionFactorPressure() const
343 {
344 return _conversionPressure;
345 }
347 virtual void print() const;
348 void print(std::ostream& fout) const;
349
350 void write(std::string const& fileName = "unitConverter") const;
351
352protected:
353 // conversion factors
354 const T _conversionLength; // m
355 const T _conversionTime; // s
356 const T _conversionVelocity; // m / s
357 const T _conversionDensity; // kg / m^3
358 const T _conversionMass; // kg
359 const T _conversionViscosity; // m^2 / s
360 const T _conversionForce; // kg m / s^2
361 const T _conversionTorque; // kg m^2 / s^2
362 const T _conversionPressure; // kg / m s^2
363
364 // physical units, e.g characteristic or reference values
365 const T _charPhysLength; // m
366 const T _charPhysVelocity; // m / s
367 const T _physViscosity; // m^2 / s
368 const T _physDensity; // kg / m^3
369 const T _charPhysPressure; // kg / m s^2
370
371 // lattice units, discretization parameters
372 const size_t _resolution;
375
376private:
377 mutable OstreamManager clout;
378};
379
381template <typename T, typename DESCRIPTOR>
383
384/*
385TODO: check scaling
386template <typename T, typename DESCRIPTOR>
387UnitConverter<T, DESCRIPTOR>* createRefinedUnitConverter(
388 const UnitConverter<T, DESCRIPTOR>* converter, T refinementFactor = 0.5)
389{
390 return new UnitConverter<T, DESCRIPTOR>(
391 converter->getPhysDeltaX() * refinementFactor,
392 converter->getPhysDeltaT() * refinementFactor * refinementFactor,
393 converter->getCharPhysLength(),
394 converter->getCharPhysVelocity(),
395 converter->getPhysViscosity(),
396 converter->getPhysDensity(),
397 converter->getCharPhysPressure()
398 );
399}
400*/
401
402template <typename T, typename DESCRIPTOR>
404public:
406 size_t resolution,
407 T latticeRelaxationTime,
408 T charPhysLength,
409 T charPhysVelocity,
410 T physViscosity,
411 T physDensity,
412 T charPhysPressure = 0) : UnitConverter<T, DESCRIPTOR>(
413 (charPhysLength/resolution),
414 (latticeRelaxationTime - 0.5) / descriptors::invCs2<T,DESCRIPTOR>() * util::pow((charPhysLength/resolution),2) / physViscosity,
415 charPhysLength,
416 charPhysVelocity,
417 physViscosity,
418 physDensity,
419 charPhysPressure)
420 {
421 }
422};
423
424template <typename T, typename DESCRIPTOR>
426public:
428 size_t resolution,
429 T charLatticeVelocity,
430 T charPhysLength,
431 T charPhysVelocity,
432 T physViscosity,
433 T physDensity,
434 T charPhysPressure = 0) : UnitConverter<T, DESCRIPTOR>(
435 (charPhysLength/resolution),
436 (charLatticeVelocity / charPhysVelocity * charPhysLength / resolution),
437 charPhysLength,
438 charPhysVelocity,
439 physViscosity,
440 physDensity,
441 charPhysPressure)
442 {
443 }
444};
445template <typename T, typename DESCRIPTOR>
447public:
449 T latticeRelaxationTime,
450 T charLatticeVelocity,
451 T charPhysLength,
452 T charPhysVelocity,
453 T physViscosity,
454 T physDensity,
455 T charPhysPressure = 0) : UnitConverter<T, DESCRIPTOR>(
456 (physViscosity * charLatticeVelocity / charPhysVelocity * descriptors::invCs2<T,DESCRIPTOR>() / (latticeRelaxationTime - 0.5)),
457 (physViscosity * charLatticeVelocity * charLatticeVelocity / charPhysVelocity / charPhysVelocity * descriptors::invCs2<T,DESCRIPTOR>() / (latticeRelaxationTime - 0.5)),
458 charPhysLength,
459 charPhysVelocity,
460 physViscosity,
461 physDensity,
462 charPhysPressure)
463 {
464 }
465};
466
467} // namespace olb
468
469#include "thermalUnitConverter.h"
471#endif
class for marking output with some text
constexpr UnitConverterFromRelaxationTimeAndLatticeVelocity(T latticeRelaxationTime, T charLatticeVelocity, T charPhysLength, T charPhysVelocity, T physViscosity, T physDensity, T charPhysPressure=0)
constexpr UnitConverterFromResolutionAndLatticeVelocity(size_t resolution, T charLatticeVelocity, T charPhysLength, T charPhysVelocity, T physViscosity, T physDensity, T charPhysPressure=0)
constexpr UnitConverterFromResolutionAndRelaxationTime(size_t resolution, T latticeRelaxationTime, T charPhysLength, T charPhysVelocity, T physViscosity, T physDensity, T charPhysPressure=0)
Conversion between physical and lattice units, as well as discretization.
constexpr T getConversionFactorViscosity() const
access (read-only) to private member variable
void write(std::string const &fileName="unitConverter") const
constexpr T getLatticeViscosity() const
conversion from physical to lattice viscosity
constexpr T getLatticeForce(T physForce) const
conversion from physical to lattice force
constexpr T getCharPhysLength() const
return characteristic length in physical units
constexpr T getLatticeTorque(T physTorque) const
conversion from physical to lattice torque
constexpr T getMachNumber() const
return Mach number
constexpr T getPhysViscosity(T latticeViscosity) const
conversion from lattice to physical viscosity
const size_t _resolution
constexpr int getResolution() const
return resolution
constexpr T getConversionFactorDensity() const
access (read-only) to private member variable
constexpr T getPhysDensity() const
return density in physical units
constexpr T getLatticeRelaxationFrequency() const
return relaxation frequency in lattice units
constexpr T getConversionFactorLength() const
access (read-only) to private member variable
constexpr T getCharLatticeVelocity() const
return characteristic velocity in lattice units
constexpr T getLatticeDensity(T physDensity) const
conversion from physical to lattice density
constexpr size_t getLatticeTime(T physTime) const
conversion from physical to lattice time
constexpr T getLatticeDensityFromPhysPressure(T physPressure) const
constexpr T getPhysDensity(T latticeDensity) const
conversion from lattice to physical density
constexpr T getConversionFactorVelocity() const
access (read-only) to private member variable
constexpr T getPhysTorque(T latticeTorque) const
conversion from lattice to physical torque
constexpr T getPhysMass(T latticeMass) const
conversion from lattice to physical mass
constexpr T getPhysVelocity(T latticeVelocity) const
conversion from lattice to physical velocity
constexpr T getLatticePressure(T physPressure) const
conversion from physical to lattice pressure
constexpr T getConversionFactorMass() const
access (read-only) to private member variable
constexpr T getPhysViscosity() const
return viscosity in physical units
constexpr T getConversionFactorForce() const
access (read-only) to private member variable
constexpr T getConversionFactorPressure() const
access (read-only) to private member variable
constexpr T getLatticeVelocity(T physVelocity) const
conversion from physical to lattice velocity
constexpr UnitConverter(T physDeltaX, T physDeltaT, T charPhysLength, T charPhysVelocity, T physViscosity, T physDensity, T charPhysPressure=0)
Documentation of constructor:
constexpr T getKnudsenNumber() const
return Knudsen number
constexpr T getCharPhysVelocity() const
return characteristic velocity in physical units
constexpr T getPhysDeltaT() const
returns time spacing (timestep length) in s
constexpr T getConversionFactorTime() const
access (read-only) to private member variable
constexpr T getPhysForce(T latticeForce) const
conversion from lattice to physical force
constexpr int getLatticeLength(T physLength) const
conversion from physical to lattice length, returns number of voxels for given physical length
constexpr T getCharPhysPressure() const
return characteristic pressure in physical units
virtual void print() const
nice terminal output for conversion factors, characteristical and physical data
constexpr T getPhysPressure(T latticePressure) const
conversion from lattice to physical pressure
virtual ~UnitConverter()=default
constexpr T getPhysLength(int latticeLength) const
conversion from lattice to physical length
constexpr T getLatticeRelaxationFrequencyFromDiffusivity(const T physDiffusivity) const
return relaxation frequency in lattice units computed from given physical diffusivity in m^2 / s
constexpr T getPhysTime(size_t latticeTime) const
conversion from lattice to physical time
constexpr T getLatticeMass(T physMass) const
conversion from physical to lattice mass
const T _latticeRelaxationTime
constexpr T getLatticeRelaxationTime() const
return relaxation time in lattice units
constexpr T getReynoldsNumber() const
return Reynolds number
constexpr T getPhysDeltaX() const
returns grid spacing (voxel length) in m
constexpr T getConversionFactorTorque() const
access (read-only) to private member variable
Unit conversion handling – header file.
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
Definition pack.h:100
Top level namespace for all of OpenLB.
UnitConverter< T, DESCRIPTOR > * createUnitConverter(XMLreader const &params)
creator function with data given by a XML file
virtual void write(std::string const &fileName="unitConverter") const =0
virtual void print() const =0
virtual void print(std::ostream &fout) const =0
virtual ~UnitConverterBase()=default
Unit conversion handling – header file.
Set of functions commonly used in LB computations – header file.
Input/Output in XML format – header file.