better collision detection
[engrid-github.git] / src / libengrid / physicalboundarycondition.cpp
blobffecd5e779ffb7f56a65d23e53070b507527414d
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::setType(QString type)
35 m_Type = type;
36 m_VarNames.clear();
37 m_VarValues.clear();
38 if (m_Type == "symmetry") {
40 if (m_Type == "wall") {
42 if (m_Type == "slip") {
44 if (m_Type == "inlet") {
45 m_VarNames.push_back("velocity");
46 m_VarValues.push_back(0);
47 m_VarNames.push_back("turbulent-intensity");
48 m_VarValues.push_back(0.04);
49 m_VarNames.push_back("turbulent-length-scale");
50 m_VarValues.push_back(1);
51 m_VarNames.push_back("temperature");
52 m_VarValues.push_back(300);
54 if (m_Type == "outlet") {
55 m_VarNames.push_back("pressure");
56 m_VarValues.push_back(0);
60 QString PhysicalBoundaryCondition::getFoamEpsilon(QString version)
62 QString str;
63 QTextStream s(&str, QIODevice::WriteOnly);
64 if (m_Type == "symmetry") {
65 s << " type symmetryPlane;\n";
67 if (m_Type == "wall") {
68 if (version >= "2.1") {
69 s << " type omegaWallFunction;\n";
70 s << " Cmu 0.09;\n";
71 s << " kappa 0.41;\n";
72 s << " E 9.8;\n";
73 s << " beta1 0.075;\n";
74 s << " value uniform 0;\n";
75 } else {
76 s << " type zeroGradient;\n";
79 if (m_Type == "slip") {
80 s << " type zeroGradient;\n";
82 if (m_Type == "inlet") {
83 double k = 1.5*sqr(getVarValue(0)*getVarValue(1));
84 double epsilon = (pow(0.09, 0.75)*pow(k, 1.5))/getVarValue(2);
85 s << " type fixedValue;\n";
86 s << " value uniform " << epsilon << ";\n";
88 if (m_Type == "outlet") {
89 s << " type zeroGradient;\n";
91 return str;
94 QString PhysicalBoundaryCondition::getFoamK(QString version)
96 QString str;
97 QTextStream s(&str, QIODevice::WriteOnly);
98 if (m_Type == "symmetry") {
99 s << " type symmetryPlane;\n";
101 if (m_Type == "wall") {
102 if (version >= "2.1") {
103 s << " type kqRWallFunction;\n";
104 s << " value uniform 0;\n";
105 } else {
106 s << " type zeroGradient;\n";
109 if (m_Type == "slip") {
110 s << " type zeroGradient;\n";
112 if (m_Type == "inlet") {
113 double k = 1.5*sqr(getVarValue(0)*getVarValue(1));
114 double epsilon = (pow(0.09, 0.75)*pow(k, 1.5))/getVarValue(2);
115 s << " type fixedValue;\n";
116 s << " value uniform " << k << ";\n";
118 if (m_Type == "outlet") {
119 s << " type zeroGradient;\n";
121 return str;
124 QString PhysicalBoundaryCondition::getFoamOmega(QString version)
126 QString str;
127 QTextStream s(&str, QIODevice::WriteOnly);
128 if (m_Type == "symmetry") {
129 s << " type symmetryPlane;\n";
131 if (m_Type == "wall") {
132 if (version >= "2.1") {
133 s << " type omegaWallFunction;\n";
134 s << " Cmu 0.09;\n";
135 s << " kappa 0.41;\n";
136 s << " E 9.8;\n";
137 s << " beta1 0.075;\n";
138 s << " value uniform 0;\n";
139 } else {
140 s << " type zeroGradient;\n";
143 if (m_Type == "slip") {
144 s << " type zeroGradient;\n";
146 if (m_Type == "inlet") {
147 double k = 1.5*sqr(getVarValue(0)*getVarValue(1));
148 double epsilon = (pow(0.09, 0.75)*pow(k, 1.5))/getVarValue(2);
149 double omega = epsilon/(0.09*k);
150 s << " type fixedValue;\n";
151 s << " value uniform " << omega << ";\n";
153 if (m_Type == "outlet") {
154 s << " type zeroGradient;\n";
156 return str;
159 QString PhysicalBoundaryCondition::getFoamNut(QString version)
161 QString str;
162 QTextStream s(&str, QIODevice::WriteOnly);
163 if (m_Type == "symmetry") {
164 s << " type symmetryPlane;\n";
166 if (m_Type == "wall") {
167 if (version >= "2.1") {
168 s << " type nutkWallFunction;\n";
169 s << " Cmu 0.09;\n";
170 s << " kappa 0.41;\n";
171 s << " E 9.8;\n";
172 s << " value uniform 0;\n";
173 } else {
174 EG_BUG;
177 if (m_Type == "slip") {
178 s << " type zeroGradient;\n";
180 if (m_Type == "inlet") {
181 double k = 1.5*sqr(getVarValue(0)*getVarValue(1));
182 double epsilon = (pow(0.09, 0.75)*pow(k, 1.5))/getVarValue(2);
183 double omega = epsilon/(0.09*k);
184 s << " type calculated;\n";
185 s << " value uniform 0;\n";
187 if (m_Type == "outlet") {
188 s << " type zeroGradient;\n";
190 return str;
193 QString PhysicalBoundaryCondition::getFoamP(QString)
195 QString str;
196 QTextStream s(&str, QIODevice::WriteOnly);
197 if (m_Type == "symmetry") {
198 s << " type symmetryPlane;\n";
200 if (m_Type == "wall") {
201 s << " type zeroGradient;\n";
203 if (m_Type == "slip") {
204 s << " type zeroGradient;\n";
206 if (m_Type == "inlet") {
207 s << " type zeroGradient;\n";
209 if (m_Type == "outlet") {
210 s << " type fixedValue;\n";
211 s << " value uniform " << getVarValue(0) << ";\n";
213 return str;
216 QString PhysicalBoundaryCondition::getFoamU(QString, vec3_t n)
218 QString str;
219 QTextStream s(&str, QIODevice::WriteOnly);
220 if (m_Type == "symmetry") {
221 s << " type symmetryPlane;\n";
223 if (m_Type == "wall") {
224 s << " type fixedValue;\n";
225 s << " value uniform (0 0 0);\n";
227 if (m_Type == "slip") {
228 s << " type slip;\n";
230 if (m_Type == "inlet") {
231 s << " type fixedValue;\n";
232 s << " value uniform (" << getVarValue(0)*n[0] << " " << getVarValue(0)*n[1] << " " << getVarValue(0)*n[2] << ");\n";
234 if (m_Type == "outlet") {
235 s << " type zeroGradient;\n";
237 return str;
240 QString PhysicalBoundaryCondition::getFoamT(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 s << " type zeroGradient;\n";
250 if (m_Type == "slip") {
251 s << " type zeroGradient;\n";
253 if (m_Type == "inlet") {
254 s << " type fixedValue;\n";
255 s << " value uniform " << getVarValue(3) << ";\n";
257 if (m_Type == "outlet") {
258 s << " type zeroGradient;\n";
260 return str;
263 QString PhysicalBoundaryCondition::getFoamType()
265 if (m_Type == "symmetry") {
266 return ("symmetryPlane");
268 if (m_Type == "wall") {
269 return ("wall");
271 if (m_Type == "slip") {
272 return ("patch");
274 if (m_Type == "inlet") {
275 return ("patch");
277 if (m_Type == "outlet") {
278 return ("patch");
280 return ("patch");