OpenLB 1.7
Loading...
Searching...
No Matches
adeUnitConverter.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2020 Louis Kronberg, Stephan Simonis
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
27#ifndef ADE_UNITCONVERTER_H
28#define ADE_UNITCONVERTER_H
29
30#include <math.h>
31#include <fstream>
32#include <iostream>
33#include <unistd.h>
34
35#include "io/ostreamManager.h"
36#include "io/fileName.h"
37
38#include "core/util.h"
39#include "core/unitConverter.h"
40#include "core/singleton.h"
41
42
43namespace olb {
44
45template <typename T, typename DESCRIPTOR>
46class AdeUnitConverter : public UnitConverter<T, DESCRIPTOR> {
47public:
48
50 T physDeltaX,
51 T physDeltaT,
52 T charPhysLength,
53 T charPhysVelocity,
54 T physDiffusivity,
55 T physDensity
56 )
57
58 :UnitConverter<T, DESCRIPTOR>(
59 physDeltaX, physDeltaT, charPhysLength, charPhysVelocity,
60 physDiffusivity, physDensity),
61 _physDiffusivity(physDiffusivity),
62 _conversionDiffusivity(physDeltaX * physDeltaX / physDeltaT),
63 _latticeAdeRelaxationTime( (physDiffusivity/ _conversionDiffusivity * descriptors::invCs2<T,DESCRIPTOR>()) + 0.5 ),
64 clout(std::cout,"AdeUnitConv")
65 {
66 };
67
69 constexpr T getLatticeAdeRelaxationTime( ) const
70 {
72 };
73
76 {
77 return 1.0 / _latticeAdeRelaxationTime;
78 };
79
80 constexpr T getPhysDiffusivity() const
81 {
82 return _physDiffusivity;
83 }
84
85 constexpr T getLatticeDiffusivity() const
86 {
88 }
89
91 {
93 }
94
95
96 constexpr T getPecletNumber() const
97 {
98 return this->getCharPhysVelocity() * this->getCharPhysLength() / this->getPhysDiffusivity();
99 }
100
101 constexpr T getKnudsenNumber() const
102 {
103 return this->getMachNumber()/getPecletNumber();
104 }
105
106 void print() const override;
107
108 void write(std::string const& fileName = "AdeUnitConverter") const override;
109
110protected:
111 // lattice units, discretization parameters
115
116private:
117 mutable OstreamManager clout;
118};
119
120template <typename T, class DESCRIPTOR>
122
123{
124 clout << "----------------- UnitConverter information -----------------" << std::endl;
125 clout << "-- Parameters:" << std::endl;
126 clout << "Resolution: N= " << this->getResolution() << std::endl;
127 clout << "Lattice velocity: latticeU= " << this->getCharLatticeVelocity() << std::endl;
128 clout << "Lattice relaxation frequency: omega= " << this->getLatticeRelaxationFrequency() << std::endl;
129 clout << "Lattice relaxation time: tau= " << this->getLatticeRelaxationTime() << std::endl;
130 clout << "Characteristical length(m): charL= " << this->getCharPhysLength() << std::endl;
131 clout << "Characteristical speed(m/s): charU= " << this->getCharPhysVelocity() << std::endl;
132 clout << "Phys. density(kg/m^d): charRho= " << this->getPhysDensity() << std::endl;
133 clout << "Peclet Number: Pe= " << getPecletNumber() << std::endl;
134 clout << "Phys. diffusivity (m^2/s): charNu= " << this->getPhysDiffusivity() << std::endl;
135 clout << "Mach number: machNumber= " << this->getMachNumber() << std::endl;
136 clout << "Knudsen number: knudsenNumber= " << getKnudsenNumber() << std::endl;
137 clout << std::endl;
138
139 clout << std::endl;
140 clout << "-- Conversion factors:" << std::endl;
141 clout << "Voxel length(m): physDeltaX= " << this->getConversionFactorLength() << std::endl;
142 clout << "Time step(s): physDeltaT= " << this->getConversionFactorTime() << std::endl;
143 clout << "Velocity factor(m/s): physVelocity= " << this->getConversionFactorVelocity() << std::endl;
144 clout << "Density factor(kg/m^3): physDensity= " << this->getConversionFactorDensity() << std::endl;
145 clout << "Mass factor(kg): physMass= " << this->getConversionFactorMass() << std::endl;
146 clout << "Viscosity factor(m^2/s): physViscosity= " << this->getConversionFactorViscosity() << std::endl;
147 clout << "Force factor(N): physForce= " << this->getConversionFactorForce() << std::endl;
148 clout << "Pressure factor(N/m^2): physPressure= " << this->getConversionFactorPressure() << std::endl;
149 clout << "-------------------------------------------------------------" << std::endl;
150
151}
152
153template <typename T, typename DESCRIPTOR>
154void AdeUnitConverter<T, DESCRIPTOR>::write(std::string const& fileName) const
155{
156 std::string dataFile = singleton::directories().getLogOutDir() + fileName + ".dat";
157
158 if (singleton::mpi().isMainProcessor()) {
159 std::ofstream fout;
160 fout.open(dataFile.c_str(), std::ios::trunc);
161
162 fout << "UnitConverter information\n\n";
163 fout << "----------------- UnitConverter information -----------------\n";
164 fout << "-- Parameters:" << std::endl;
165 fout << "Resolution: N= " << this->getResolution() << "\n";
166 fout << "Lattice velocity: latticeU= " << this->getCharLatticeVelocity() << "\n";
167 fout << "Lattice relaxation frequency: omega= " << this->getLatticeRelaxationFrequency() << "\n";
168 fout << "Lattice relaxation time: tau= " << this->getLatticeRelaxationTime() << "\n";
169 fout << "Characteristical length(m): charL= " << this->getCharPhysLength() << "\n";
170 fout << "Characteristical speed(m/s): charU= " << this->getCharPhysVelocity() << "\n";
171 fout << "Phys. diffusivity (m^2/s): charNu= " << this->getPhysDiffusivity() << "\n";
172 fout << "Phys. density(kg/m^d): charRho= " << this->getPhysDensity() << "\n";
173 fout << "Characteristical pressure(N/m^2): charPressure= " << this->getCharPhysPressure() << "\n";
174 fout << "Mach number: machNumber= " << this->getMachNumber() << "\n";
175 fout << "Knudsen number: knudsenNumber= " << this->getKnudsenNumber() << "\n";
176 fout << "Peclet Number: Pe= " << getPecletNumber() << "\n";
177 fout << "\n";
178 fout << "-- Conversion factors:" << "\n";
179 fout << "Voxel length(m): physDeltaX= " << this->getConversionFactorLength() << "\n";
180 fout << "Time step(s): physDeltaT= " << this->getConversionFactorTime() << "\n";
181 fout << "Velocity factor(m/s): physVelocity= " << this->getConversionFactorVelocity() << "\n";
182 fout << "Density factor(kg/m^3): physDensity= " << this->getConversionFactorDensity() << "\n";
183 fout << "Mass factor(kg): physMass= " << this->getConversionFactorMass() << "\n";
184 fout << "Diffusion factor(m^2/s): physDiffusion= " << this->getConversionFactorDiffusivity() << "\n";
185 fout << "Force factor(N): physForce= " << this->getConversionFactorForce() << "\n";
186
187 fout << "-------------------------------------------------------------" << "\n";
188
189 fout.close();
190 }
191}
192
193template <typename T, typename DESCRIPTOR>
195public:
197 size_t resolution,
198 T latticeRelaxationTime,
199 T charPhysLength,
200 T charPhysVelocity,
201 T physDiffusivity,
202 T physDensity) : AdeUnitConverter<T, DESCRIPTOR>(
203 (charPhysLength/resolution),
204 (latticeRelaxationTime - 0.5) / descriptors::invCs2<T,DESCRIPTOR>() * util::pow((charPhysLength/resolution),2) / physDiffusivity,
205 charPhysLength,
206 charPhysVelocity,
207 physDiffusivity,
208 physDensity)
209 {
210 }
211};
212
213template <typename T, typename DESCRIPTOR>
215public:
216
218 size_t resolution,
219 T charLatticeVelocity,
220 T charPhysLength,
221 T charPhysVelocity,
222 T physViscosity,
223 T physDensity) : AdeUnitConverter<T, DESCRIPTOR>(
224 (charPhysLength/resolution),
225 (charLatticeVelocity / charPhysVelocity * charPhysLength / resolution),
226 charPhysLength,
227 charPhysVelocity,
228 physViscosity,
229 physDensity)
230 {
231 }
232};
233
234}
235#endif
constexpr AdeUnitConverterFromResolutionAndLatticeVelocity(size_t resolution, T charLatticeVelocity, T charPhysLength, T charPhysVelocity, T physViscosity, T physDensity)
constexpr AdeUnitConverterFromResolutionAndRelaxationTime(size_t resolution, T latticeRelaxationTime, T charPhysLength, T charPhysVelocity, T physDiffusivity, T physDensity)
constexpr T getLatticeAdeRelaxationTime() const
return thermal relaxation time in lattice units
constexpr T getKnudsenNumber() const
constexpr T getLatticeAdeRelaxationFrequency() const
return thermal relaxation frequency in lattice units
void write(std::string const &fileName="AdeUnitConverter") const override
constexpr AdeUnitConverter(T physDeltaX, T physDeltaT, T charPhysLength, T charPhysVelocity, T physDiffusivity, T physDensity)
constexpr T getLatticeDiffusivity() const
constexpr T getPecletNumber() const
void print() const override
nice terminal output for conversion factors, characteristical and physical data
constexpr T getPhysDiffusivity() const
constexpr T getConversionFactorDiffusivity() const
class for marking output with some text
Conversion between physical and lattice units, as well as discretization.
constexpr T getCharPhysLength() const
return characteristic length in physical units
constexpr T getMachNumber() const
return Mach number
constexpr T getCharPhysVelocity() const
return characteristic velocity in physical units
std::string getLogOutDir() const
Definition singleton.h:89
These functions help you to create file names.
MpiManager & mpi()
Directories & directories()
Definition singleton.h:150
Top level namespace for all of OpenLB.
Definition of singletons: global, publicly available information.
Unit conversion handling – header file.
Set of functions commonly used in LB computations – header file.