OpenLB 1.7
Loading...
Searching...
No Matches
powerLawUnitConverter.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2017-2018 Max Gaedtke, Albert Mink, Davide Dapelo
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
24
25#ifndef PL_UNITCONVERTER_HH
26#define PL_UNITCONVERTER_HH
27
28#include <fstream>
29#include <iostream>
30#include <unistd.h>
31#include "core/singleton.h"
32#include "io/fileName.h"
33
34// All OpenLB code is contained in this namespace.
35namespace olb {
36
37template <typename T, typename DESCRIPTOR>
38void PowerLawUnitConverter<T, DESCRIPTOR>::print(std::ostream& clout) const
39{
40 clout << "----------------- UnitConverter information ------------------" << std::endl;
41 clout << "-- Parameters:" << std::endl;
42 clout << "Resolution: N= " << this->getResolution() << std::endl;
43 clout << "Lattice velocity: latticeU= " << this->getCharLatticeVelocity() << std::endl;
44 clout << "Lattice relaxation frequency: omega= " << this->getLatticeRelaxationFrequency( ) << std::endl;
45 clout << "Lattice relaxation time: tau= " << this->getLatticeRelaxationTime() << std::endl;
46 clout << "Characteristical length(m): charL= " << this->getCharPhysLength() << std::endl;
47 clout << "Characteristical speed(m/s): charU= " << this->getCharPhysVelocity() << std::endl;
48 clout << "Phys. char kinematic visco(m^2/s): charNu= " << this->getPhysViscosity() << std::endl;
49 clout << "Phys. consistency coeff(m^2 s^(n-2)): charM= " << this->getPhysConsistencyCoeff() << std::endl;
50 clout << "Power-law index: n= " << this->getPowerLawIndex() << std::endl;
51 clout << "Phys. density(kg/m^d): charRho= " << this->getPhysDensity() << std::endl;
52 clout << "Characteristical pressure(N/m^2): charPressure= " << this->getCharPhysPressure() << std::endl;
53 clout << "Reynolds number: reynoldsNumber= " << this->getReynoldsNumber() << std::endl;
54
55 clout << std::endl;
56 clout << "-- Conversion factors:" << std::endl;
57 clout << "Voxel length(m): physDeltaX= " << this->getConversionFactorLength() << std::endl;
58 clout << "Time step(s): physDeltaT= " << this->getConversionFactorTime() << std::endl;
59 clout << "Velocity factor(m/s): physVelocity= " << this->getConversionFactorVelocity() << std::endl;
60 clout << "Density factor(kg/m^3): physDensity= " << this->getConversionFactorDensity() << std::endl;
61 clout << "Mass factor(kg): physMass= " << this->getConversionFactorMass() << std::endl;
62 clout << "Viscosity factor(m^2/s): physViscosity= " << this->getConversionFactorViscosity() << std::endl;
63 clout << "Force factor(N): physForce= " << this->getConversionFactorForce() << std::endl;
64 clout << "Pressure factor(N/m^2): physPressure= " << this->getConversionFactorPressure() << std::endl;
65
66 clout << "--------------------------------------------------------------" << std::endl;
67
68}
69
70template <typename T, class DESCRIPTOR>
71void PowerLawUnitConverter<T, DESCRIPTOR>::print() const
72{
73 print(clout);
74}
75
76template <typename T, typename DESCRIPTOR>
77void PowerLawUnitConverter<T, DESCRIPTOR>::write(std::string const& fileName) const
78{
79 std::string dataFile = singleton::directories().getLogOutDir() + fileName + ".dat";
80
81 if (singleton::mpi().isMainProcessor()) {
82 std::ofstream fout(dataFile.c_str(), std::ios::trunc);
83 if (!fout) {
84 clout << "error write() function: can not open std::ofstream" << std::endl;
85 }
86 else {
87 print( fout );
88 fout.close();
89 }
90 }
91}
92
93template<typename T, typename DESCRIPTOR>
94PowerLawUnitConverter<T, DESCRIPTOR>* createPowerLawUnitConverter(XMLreader const& params)
95{
96 OstreamManager clout(std::cout,"createUnitConverter");
97 params.setWarningsOn(false);
98
99 T physDeltaX;
100 T physDeltaT;
101
102 T charPhysLength;
103 T charPhysVelocity;
104 T physViscosity;
105 T physConsistencyCoeff;
106 T powerLawIndex;
107 T physDensity;
108 T charPhysPressure = 0;
109
110 int resolution;
111 T latticeRelaxationTime;
112 T charLatticeVelocity;
113
114 int counter = 0; // counting the number of Discretization parameters and returning a warning if more than 2 are provided
115
116
117 // params[parameter].read(value) sets the value or returns false if the parameter can not be found
118 params["Application"]["PhysParameters"]["CharPhysLength"].read(charPhysLength);
119 params["Application"]["PhysParameters"]["CharPhysVelocity"].read(charPhysVelocity);
120 params["Application"]["PhysParameters"]["PhysConsistencyCoeff"].read(physConsistencyCoeff);
121 params["Application"]["PhysParameters"]["powerLawIndex"].read(powerLawIndex);
122 params["Application"]["PhysParameters"]["PhysDensity"].read(physDensity);
123 params["Application"]["PhysParameters"]["CharPhysPressure"].read(charPhysPressure);
124
125 physViscosity = physConsistencyCoeff * util::pow(charPhysVelocity / (2*charPhysLength), powerLawIndex-1);
126
127 std::vector<std::string> discretizationParam = {"PhysDeltaX", "Resolution",
128 "CharLatticeVelocity", "PhysDeltaT", "LatticeRelaxationTime"};
129
130 for(int i = 0; i<discretizationParam.size(); i++){
131 std::string test;
132 if(params["Application"]["Discretization"][discretizationParam[i]].read(test,false)){
133 counter++;
134 }
135 }
136 if(counter>2){
137 clout << "WARNING: More than 2 discretization parameters provided" << std::endl;
138 }
139
140 if (!params["Application"]["Discretization"]["PhysDeltaX"].read(physDeltaX,false)) {
141 if (!params["Application"]["Discretization"]["Resolution"].read<int>(resolution,false)) {
142 if (!params["Application"]["Discretization"]["CharLatticeVelocity"].read(charLatticeVelocity,false)) {
143 // NOT found physDeltaX, resolution or charLatticeVelocity
144 clout << "Error: Have not found PhysDeltaX, Resolution or CharLatticeVelocity in XML file."
145 << std::endl;
146 exit (1);
147 }
148 else {
149 // found charLatticeVelocity
150 if (params["Application"]["Discretization"]["PhysDeltaT"].read(physDeltaT,false)) {
151 physDeltaX = charPhysVelocity / charLatticeVelocity * physDeltaT;
152 }
153 else if (params["Application"]["Discretization"]["LatticeRelaxationTime"].read(latticeRelaxationTime,false)) {
154 physDeltaX = physViscosity * charLatticeVelocity / charPhysVelocity * descriptors::invCs2<T,DESCRIPTOR>() / (latticeRelaxationTime - 0.5);
155 }
156 }
157 }
158 else {
159 // found resolution
160 physDeltaX = charPhysLength / resolution;
161 }
162 }
163 // found physDeltaX
164 if (!params["Application"]["Discretization"]["PhysDeltaT"].read(physDeltaT,false)) {
165 if (!params["Application"]["Discretization"]["LatticeRelaxationTime"].read(latticeRelaxationTime,false)) {
166 if (!params["Application"]["Discretization"]["CharLatticeVelocity"].read(charLatticeVelocity,false)) {
167 // NOT found physDeltaT, latticeRelaxationTime and charLatticeVelocity
168 clout << "Error: Have not found PhysDeltaT, LatticeRelaxationTime or CharLatticeVelocity in XML file."
169 << std::endl;
170 exit (1);
171 }
172 else {
173 // found charLatticeVelocity
174 physDeltaT = charLatticeVelocity / charPhysVelocity * physDeltaX;
175 }
176 }
177 else {
178 // found latticeRelaxationTime
179 physDeltaT = (latticeRelaxationTime - 0.5) / descriptors::invCs2<T,DESCRIPTOR>() * physDeltaX * physDeltaX / physViscosity;
180 }
181 }
182
183 return new PowerLawUnitConverter<T, DESCRIPTOR>(physDeltaX, physDeltaT, charPhysLength, charPhysVelocity, physConsistencyCoeff, powerLawIndex, physDensity, charPhysPressure);
184}
185
187/*
188template <typename T, typename DESCRIPTOR>
189constexpr PowerLawUnitConverterFrom_Resolution_RelaxationTime_Reynolds_PLindex<T, DESCRIPTOR>::
190PowerLawUnitConverterFrom_Resolution_RelaxationTime_Reynolds_PLindex(
191 int resolution,
192 T latticeRelaxationTime,
193 T charPhysLength,
194 T charPhysVelocity,
195 T Re,
196 T powerLawIndex,
197 T physDensity,
198 T charPhysPressure)
199{
200 T physDeltaX = (charPhysLength/resolution);
201 T physConsistencyCoeff = charPhysLength * charPhysVelocity * util::pow( charPhysVelocity / ( 2 * charPhysLength ), 1 - powerLawIndex ) / Re;
202 T physViscosity = physConsistencyCoeff * util::pow( charPhysVelocity / (2 * charPhysLength ), powerLawIndex - 1 );
203 T physDeltaT = (latticeRelaxationTime - 0.5) / descriptors::invCs2<T,DESCRIPTOR>() * util::pow((charPhysLength/resolution),2) / physViscosity;
204
205PowerLawUnitConverter<T, DESCRIPTOR>( physDeltaX, physDeltaT, charPhysLength, charPhysVelocity,
206 physConsistencyCoeff, powerLawIndex, physDensity, charPhysPressure );
207}
208*/
209
210
211
212
213} // namespace olb
214
215#endif
class for marking output with some text
void setWarningsOn(bool warnings) const
switch warnings on/off
Definition xmlReader.h:412
bool read(T &value, bool verboseOn=true, bool exitIfMissing=false) const
Prints out the XML structure read in, mostly for debugging purposes.
std::string getLogOutDir() const
Definition singleton.h:89
These functions help you to create file names.
MpiManager & mpi()
Directories & directories()
Definition singleton.h:150
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
Definition pack.h:112
void print(U data, const std::string &name="", OstreamManager clout=OstreamManager(std::cout,"print"), const char delimiter=',')
Top level namespace for all of OpenLB.
PowerLawUnitConverter< T, DESCRIPTOR > * createPowerLawUnitConverter(XMLreader const &params)
Definition of singletons: global, publicly available information.