1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "physicalboundarycondition.h"
23 #include <QStringList>
26 PhysicalBoundaryCondition::PhysicalBoundaryCondition()
33 void PhysicalBoundaryCondition::addBoolVar(QString name
, bool v
)
35 m_VarTypes
.push_back("bool");
36 m_VarNames
.push_back(name
);
38 m_VarValues
.push_back("yes");
40 m_VarValues
.push_back("no");
44 void PhysicalBoundaryCondition::addIntVar(QString name
, int v
)
46 m_VarTypes
.push_back("int");
47 m_VarNames
.push_back(name
);
50 m_VarValues
.push_back(txt
);
53 void PhysicalBoundaryCondition::addRealVar(QString name
, double v
)
55 m_VarTypes
.push_back("real");
56 m_VarNames
.push_back(name
);
59 m_VarValues
.push_back(txt
);
62 void PhysicalBoundaryCondition::addStringVar(QString name
, QString v
)
64 m_VarTypes
.push_back("string");
65 m_VarNames
.push_back(name
);
66 m_VarValues
.push_back(v
);
69 void PhysicalBoundaryCondition::addVecVar(QString name
, vec3_t v
)
71 m_VarTypes
.push_back("vector");
72 m_VarNames
.push_back(name
);
84 m_VarValues
.push_back(txt
);
87 void PhysicalBoundaryCondition::checkVarType(int i
, QString type
)
89 if (i
>= m_VarTypes
.size()) EG_BUG
;
90 if (i
>= m_VarNames
.size()) EG_BUG
;
91 if (i
>= m_VarValues
.size()) EG_BUG
;
92 if (m_VarTypes
[i
] != type
) EG_BUG
;
95 void PhysicalBoundaryCondition::setValue(int i
, bool v
)
97 checkVarType(i
, "bool");
99 m_VarValues
[i
] = "yes";
101 m_VarValues
[i
] = "no";
105 void PhysicalBoundaryCondition::setValue(int i
, double v
)
107 checkVarType(i
, "real");
110 m_VarValues
[i
] = num
;
113 void PhysicalBoundaryCondition::setValue(int i
, int v
)
115 checkVarType(i
, "int");
118 m_VarValues
[i
] = num
;
121 void PhysicalBoundaryCondition::setValue(int i
, QString v
)
123 checkVarType(i
, "string");
127 void PhysicalBoundaryCondition::setValue(int i
, vec3_t v
)
129 checkVarType(i
, "vector");
130 QString num
, txt
= "(";
140 m_VarValues
[i
] = txt
;
143 void PhysicalBoundaryCondition::setValueFromString(int i
, QString v
)
145 if (i
>= m_VarTypes
.size()) EG_BUG
;
146 if (i
>= m_VarNames
.size()) EG_BUG
;
147 if (i
>= m_VarValues
.size()) EG_BUG
;
149 if (getVarType(i
) == "real") {
150 setValue(i
, getVarValueAsDouble(i
));
152 if (getVarType(i
) == "int") {
153 setValue(i
, getVarValueAsInt(i
));
155 if (getVarType(i
) == "bool") {
156 setValue(i
, getVarValueAsBool(i
));
158 if (getVarType(i
) == "vector") {
159 setValue(i
, getVarValueAsVec3(i
));
163 QString
PhysicalBoundaryCondition::xmlText()
167 txt
+= " " + m_Name
+ " " + m_Type
+ ";";
168 for (int i
= 0; i
< m_VarTypes
.size(); ++i
) {
169 txt
+= " " + m_VarTypes
[i
] + " " + m_VarNames
[i
] + " = " + m_VarValues
[i
] + ";";
174 bool PhysicalBoundaryCondition::getVarValueAsBool(int i
)
176 QString value
= m_VarValues
[i
].toLower();
177 if (value
== "no") return false;
178 if (value
== "off") return false;
179 if (value
== "false") return false;
180 if (value
== "yes") return true;
181 if (value
== "on") return true;
182 if (value
== "true") return true;
183 EG_ERR_RETURN("boundary condition \"" + m_Name
+ "\": cannot convert \"" + m_VarValues
[i
] + "\" to boolen (true/false)!");
187 vec3_t
PhysicalBoundaryCondition::getVarValueAsVec3(int i
)
189 QString txt
= m_VarValues
[i
];
190 txt
= txt
.replace("(", "");
191 txt
= txt
.replace(")", "");
193 QStringList parts
= txt
.split(",");
195 if (parts
.size() == 3) {
196 for (int j
= 0; j
< 3; ++j
) {
197 v
[j
] = parts
[j
].toDouble();
203 void PhysicalBoundaryCondition::setType(QString type
)
208 if (m_Type
== "turbulent-duct-inlet") {
209 addRealVar("velocity", 1);
210 addRealVar("temperature", 300);
212 if (m_Type
== "laminar-duct-inlet") {
213 addRealVar("velocity", 1);
214 addRealVar("temperature", 300);
216 if (m_Type
== "inflow") {
217 addRealVar("velocity", 1);
218 addRealVar("turbulent-intensity", 0.04);
219 addRealVar("turbulent-length-scale", 1);
220 addRealVar("temperature", 300);
222 if (m_Type
== "outflow") {
223 addBoolVar("supersonic", false);
224 addRealVar("pressure", 0);
226 if (m_Type
== "cyclic") {
227 addStringVar("counterpart", "");
229 if (m_Type
== "symmetry") {
231 if (m_Type
== "DrNUM-turbulent-wall") {
232 addRealVar("yplus-cut-off", 300);
234 if (m_Type
== "wall") {
236 if (m_Type
== "inviscid wall") {
240 QString
PhysicalBoundaryCondition::getFoamEpsilon(QString version
)
243 QTextStream
s(&str
, QIODevice::WriteOnly
);
244 if (m_Type
== "symmetry") {
245 s
<< " type symmetryPlane;\n";
247 if (m_Type
== "wall") {
248 if (version
>= "2.1") {
249 s
<< " type omegaWallFunction;\n";
251 s
<< " kappa 0.41;\n";
253 s
<< " beta1 0.075;\n";
254 s
<< " value uniform 0;\n";
256 s
<< " type zeroGradient;\n";
259 if (m_Type
== "slip") {
260 s
<< " type zeroGradient;\n";
262 if (m_Type
== "inlet") {
263 double k
= 1.5*sqr(getVarValueAsDouble(0)*getVarValueAsDouble(1));
264 double epsilon
= (pow(0.09, 0.75)*pow(k
, 1.5))/getVarValueAsDouble(2);
265 s
<< " type fixedValue;\n";
266 s
<< " value uniform " << epsilon
<< ";\n";
268 if (m_Type
== "outlet") {
269 s
<< " type zeroGradient;\n";
274 QString
PhysicalBoundaryCondition::getFoamK(QString version
)
277 QTextStream
s(&str
, QIODevice::WriteOnly
);
278 if (m_Type
== "symmetry") {
279 s
<< " type symmetryPlane;\n";
281 if (m_Type
== "wall") {
282 if (version
>= "2.1") {
283 s
<< " type kqRWallFunction;\n";
284 s
<< " value uniform 0;\n";
286 s
<< " type zeroGradient;\n";
289 if (m_Type
== "slip") {
290 s
<< " type zeroGradient;\n";
292 if (m_Type
== "inlet") {
293 double k
= 1.5*sqr(getVarValueAsDouble(0)*getVarValueAsDouble(1));
294 double epsilon
= (pow(0.09, 0.75)*pow(k
, 1.5))/getVarValueAsDouble(2);
295 s
<< " type fixedValue;\n";
296 s
<< " value uniform " << k
<< ";\n";
298 if (m_Type
== "outlet") {
299 s
<< " type zeroGradient;\n";
304 QString
PhysicalBoundaryCondition::getFoamOmega(QString version
)
307 QTextStream
s(&str
, QIODevice::WriteOnly
);
308 if (m_Type
== "symmetry") {
309 s
<< " type symmetryPlane;\n";
311 if (m_Type
== "wall") {
312 if (version
>= "2.1") {
313 s
<< " type omegaWallFunction;\n";
315 s
<< " kappa 0.41;\n";
317 s
<< " beta1 0.075;\n";
318 s
<< " value uniform 0;\n";
320 s
<< " type zeroGradient;\n";
323 if (m_Type
== "slip") {
324 s
<< " type zeroGradient;\n";
326 if (m_Type
== "inlet") {
327 double k
= 1.5*sqr(getVarValueAsDouble(0)*getVarValueAsDouble(1));
328 double epsilon
= (pow(0.09, 0.75)*pow(k
, 1.5))/getVarValueAsDouble(2);
329 double omega
= epsilon
/(0.09*k
);
330 s
<< " type fixedValue;\n";
331 s
<< " value uniform " << omega
<< ";\n";
333 if (m_Type
== "outlet") {
334 s
<< " type zeroGradient;\n";
339 QString
PhysicalBoundaryCondition::getFoamNut(QString version
)
342 QTextStream
s(&str
, QIODevice::WriteOnly
);
343 if (m_Type
== "symmetry") {
344 s
<< " type symmetryPlane;\n";
346 if (m_Type
== "wall") {
347 if (version
>= "2.1") {
348 s
<< " type nutkWallFunction;\n";
350 s
<< " kappa 0.41;\n";
352 s
<< " value uniform 0;\n";
357 if (m_Type
== "slip") {
358 s
<< " type zeroGradient;\n";
360 if (m_Type
== "inlet") {
361 double k
= 1.5*sqr(getVarValueAsDouble(0)*getVarValueAsDouble(1));
362 double epsilon
= (pow(0.09, 0.75)*pow(k
, 1.5))/getVarValueAsDouble(2);
363 double omega
= epsilon
/(0.09*k
);
364 s
<< " type calculated;\n";
365 s
<< " value uniform 0;\n";
367 if (m_Type
== "outlet") {
368 s
<< " type zeroGradient;\n";
373 QString
PhysicalBoundaryCondition::getFoamP(QString
)
376 QTextStream
s(&str
, QIODevice::WriteOnly
);
377 if (m_Type
== "symmetry") {
378 s
<< " type symmetryPlane;\n";
380 if (m_Type
== "wall") {
381 s
<< " type zeroGradient;\n";
383 if (m_Type
== "slip") {
384 s
<< " type zeroGradient;\n";
386 if (m_Type
== "inlet") {
387 s
<< " type zeroGradient;\n";
389 if (m_Type
== "outlet") {
390 s
<< " type fixedValue;\n";
391 s
<< " value uniform " << getVarValueAsDouble(0) << ";\n";
396 QString
PhysicalBoundaryCondition::getFoamU(QString
, vec3_t n
)
399 QTextStream
s(&str
, QIODevice::WriteOnly
);
400 if (m_Type
== "symmetry") {
401 s
<< " type symmetryPlane;\n";
403 if (m_Type
== "wall") {
404 s
<< " type fixedValue;\n";
405 s
<< " value uniform (0 0 0);\n";
407 if (m_Type
== "slip") {
408 s
<< " type slip;\n";
410 if (m_Type
== "inlet") {
411 s
<< " type fixedValue;\n";
412 s
<< " value uniform (" << getVarValueAsDouble(0)*n
[0] << " " << getVarValueAsDouble(0)*n
[1] << " " << getVarValueAsDouble(0)*n
[2] << ");\n";
414 if (m_Type
== "outlet") {
415 s
<< " type zeroGradient;\n";
420 QString
PhysicalBoundaryCondition::getFoamT(QString version
)
423 QTextStream
s(&str
, QIODevice::WriteOnly
);
424 if (m_Type
== "symmetry") {
425 s
<< " type symmetryPlane;\n";
427 if (m_Type
== "wall") {
428 s
<< " type zeroGradient;\n";
430 if (m_Type
== "slip") {
431 s
<< " type zeroGradient;\n";
433 if (m_Type
== "inlet") {
434 s
<< " type fixedValue;\n";
435 s
<< " value uniform " << getVarValueAsDouble(3) << ";\n";
437 if (m_Type
== "outlet") {
438 s
<< " type zeroGradient;\n";
443 QString
PhysicalBoundaryCondition::getFoamType()
445 if (m_Type
== "symmetry") {
446 return ("symmetryPlane");
448 if (m_Type
== "wall") {
451 if (m_Type
== "slip") {
454 if (m_Type
== "inlet") {
457 if (m_Type
== "outlet") {