limited volume meshing to boundary layer only
[engrid-github.git] / src / libengrid / physicalboundarycondition.cpp
blob2ea2945dabba8e03a6dc84dbf513ab7517aea103
1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 // + +
3 // + This file is part of enGrid. +
4 // + +
5 // + Copyright 2008-2014 enGits GmbH +
6 // + +
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. +
11 // + +
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. +
16 // + +
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/>. +
19 // + +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21 #include "physicalboundarycondition.h"
23 #include <QStringList>
24 #include <QtDebug>
26 PhysicalBoundaryCondition::PhysicalBoundaryCondition()
28 m_Name = "unknown";
29 m_Index = -1;
30 m_Type = "unknown";
33 void PhysicalBoundaryCondition::addBoolVar(QString name, bool v)
35 m_VarTypes.push_back("bool");
36 m_VarNames.push_back(name);
37 if (v) {
38 m_VarValues.push_back("yes");
39 } else {
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);
48 QString txt;
49 txt.setNum(v);
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);
57 QString txt;
58 txt.setNum(v);
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);
73 QString txt, num;
74 txt = "(";
75 num.setNum(v[0]);
76 txt += num;
77 txt += ", ";
78 num.setNum(v[1]);
79 txt += num;
80 txt += ", ";
81 num.setNum(v[2]);
82 txt += num;
83 txt += ")";
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");
98 if (v) {
99 m_VarValues[i] = "yes";
100 } else {
101 m_VarValues[i] = "no";
105 void PhysicalBoundaryCondition::setValue(int i, double v)
107 checkVarType(i, "real");
108 QString num;
109 num.setNum(v);
110 m_VarValues[i] = num;
113 void PhysicalBoundaryCondition::setValue(int i, int v)
115 checkVarType(i, "int");
116 QString num;
117 num.setNum(v);
118 m_VarValues[i] = num;
121 void PhysicalBoundaryCondition::setValue(int i, QString v)
123 checkVarType(i, "string");
124 m_VarValues[i] = v;
127 void PhysicalBoundaryCondition::setValue(int i, vec3_t v)
129 checkVarType(i, "vector");
130 QString num, txt = "(";
131 num.setNum(v[0]);
132 txt += num;
133 txt += ", ";
134 num.setNum(v[1]);
135 txt += num;
136 txt += ", ";
137 num.setNum(v[2]);
138 txt += num;
139 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;
148 m_VarValues[i] = v;
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()
165 QString txt;
166 txt.setNum(m_Index);
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] + ";";
171 return txt;
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)!");
184 return false;
187 vec3_t PhysicalBoundaryCondition::getVarValueAsVec3(int i)
189 QString txt = m_VarValues[i];
190 txt = txt.replace("(", "");
191 txt = txt.replace(")", "");
192 txt = txt.trimmed();
193 QStringList parts = txt.split(",");
194 vec3_t v(0,0,0);
195 if (parts.size() == 3) {
196 for (int j = 0; j < 3; ++j) {
197 v[j] = parts[j].toDouble();
200 return v;
203 void PhysicalBoundaryCondition::setType(QString type)
205 m_Type = type;
206 m_VarNames.clear();
207 m_VarValues.clear();
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)
242 QString str;
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";
250 s << " Cmu 0.09;\n";
251 s << " kappa 0.41;\n";
252 s << " E 9.8;\n";
253 s << " beta1 0.075;\n";
254 s << " value uniform 0;\n";
255 } else {
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";
271 return str;
274 QString PhysicalBoundaryCondition::getFoamK(QString version)
276 QString str;
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";
285 } else {
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";
301 return str;
304 QString PhysicalBoundaryCondition::getFoamOmega(QString version)
306 QString str;
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";
314 s << " Cmu 0.09;\n";
315 s << " kappa 0.41;\n";
316 s << " E 9.8;\n";
317 s << " beta1 0.075;\n";
318 s << " value uniform 0;\n";
319 } else {
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";
336 return str;
339 QString PhysicalBoundaryCondition::getFoamNut(QString version)
341 QString str;
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";
349 s << " Cmu 0.09;\n";
350 s << " kappa 0.41;\n";
351 s << " E 9.8;\n";
352 s << " value uniform 0;\n";
353 } else {
354 EG_BUG;
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";
370 return str;
373 QString PhysicalBoundaryCondition::getFoamP(QString)
375 QString str;
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";
393 return str;
396 QString PhysicalBoundaryCondition::getFoamU(QString, vec3_t n)
398 QString str;
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";
417 return str;
420 QString PhysicalBoundaryCondition::getFoamT(QString version)
422 QString str;
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";
440 return str;
443 QString PhysicalBoundaryCondition::getFoamType()
445 if (m_Type == "symmetry") {
446 return ("symmetryPlane");
448 if (m_Type == "wall") {
449 return ("wall");
451 if (m_Type == "slip") {
452 return ("patch");
454 if (m_Type == "inlet") {
455 return ("patch");
457 if (m_Type == "outlet") {
458 return ("patch");
460 return ("patch");