All Classes Namespaces Files Functions Variables Typedefs Friends Macros Groups
varScModel6.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10  Copyright (C) 2016-2019 ISP RAS (www.ispras.ru) UniCFD Group (www.unicfd.ru)
11 -------------------------------------------------------------------------------
12 License
13  This file is part of QGDsolver library, based on OpenFOAM+.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 \*---------------------------------------------------------------------------*/
28 
29 #include "varScModel6.H"
30 #include "psiQGDThermo.H"
31 #include "addToRunTimeSelectionTable.H"
32 #include "fvcSmooth.H"
33 #include "fvcGrad.H"
34 #include "fvcSnGrad.H"
35 #include "primitiveMeshTools.H"
36 #include "linear.H"
37 #include "cellSet.H"
38 #include "emptyFvPatch.H"
39 #include "wedgeFvPatch.H"
40 
41 namespace Foam
42 {
43 namespace qgd
44 {
45  defineTypeNameAndDebug(varScModel6,0);
47  (
48  QGDCoeffs,
49  varScModel6,
50  dictionary
51  );
52 }
53 }
54 
57 (
58  const IOobject& io,
59  const fvMesh& mesh,
60  const dictionary& dict
61 )
62 :
63  QGDCoeffs(io, mesh, dict),
64  smoothCoeff_(0.1),
65  rC_(0.5),
66  minSc_(0.05),
67  maxSc_(1.00),
68  badQualitySc_(0.05),
69  qgdAspectRatioThreshold_(1.5),
70  constSc_(0.05),
71  cqSc_(mesh.V().size(), 0.0),
72  constScCellSetPtr_(nullptr)
73 {
74  scalar ScQGD = 0.0, PrQGD = 1.0;
75 
76  dict.lookup("ScQGD") >> ScQGD;
77  dict.lookup("PrQGD") >> PrQGD;
78 
79  ScQGD_.primitiveFieldRef() = ScQGD;
80  PrQGD_.primitiveFieldRef() = PrQGD;
81 
82  ScQGD_.boundaryFieldRef() = ScQGD;
83  PrQGD_.boundaryFieldRef() = PrQGD;
84 
85  if (dict.found("smoothCoeff"))
86  {
87  dict.lookup("smoothCoeff") >> smoothCoeff_;
88  }
89 
90  if (dict.found("rC"))
91  {
92  dict.lookup("rC") >> rC_;
93  }
94 
95  if (dict.found("minSc"))
96  {
97  dict.lookup("minSc") >> minSc_;
98  }
99 
100  if (dict.found("maxSc"))
101  {
102  dict.lookup("maxSc") >> maxSc_;
103  }
104 
105  if (dict.found("badQualitySc"))
106  {
107  dict.lookup("badQualitySc") >> badQualitySc_;
108  }
109 
110  if (dict.found("maxAspectRatio"))
111  {
112  dict.lookup("maxAspectRatio") >> qgdAspectRatioThreshold_;
113  }
114 
115  scalarField openness(mesh.V().size(), 0);
116  scalarField aspectRatio(mesh.V().size(), 1);
117 
118  primitiveMeshTools::cellClosedness
119  (
120  mesh_,
121  mesh_.geometricD(),
122  mesh_.faceAreas(),
123  mesh_.cellVolumes(),
124  openness,
125  aspectRatio
126  );
127 
128  forAll(aspectRatio, iCell)
129  {
130  if (aspectRatio[iCell] > qgdAspectRatioThreshold_)
131  {
132  cqSc_[iCell] = badQualitySc_ * aspectRatio[iCell] / qgdAspectRatioThreshold_;
133  //cqSc_[iCell] = badQualitySc_;
134  }
135  }
136 
137  if (dict.found("constScCellSet"))
138  {
139  word constScCellSet (dict.lookup("constScCellSet"));
140  constSc_ = ScQGD;
141 
142  constScCellSetPtr_.reset
143  (
144  new cellSet
145  (
146  mesh,
147  constScCellSet,
148  IOobject::MUST_READ,
149  IOobject::NO_WRITE
150  )
151  );
152  }
153 
154  /*
155  {
156  volScalarField hRatio(this->hQGD_);
157  label fid = -1, pid = -1, pfid = -1;
158  scalar hmax = 0.0;
159  forAll(hRatio, celli)
160  {
161  const cell& c = mesh.cells()[celli];
162  hmax = 0.0;
163  forAll(c, facei)
164  {
165  fid = c[facei];
166  if (mesh.isInternalFace(fid))
167  {
168  if (hQGDf_[fid] > hmax)
169  {
170  hmax = hQGDf_[fid];
171  }
172  }
173  else
174  {
175  pid = mesh.boundaryMesh().whichPatch(fid);
176  pfid= mesh.boundary()[pid].patch().whichFace(fid);
177 
178  if (hQGDf_.boundaryField()[pid][pfid] > hmax)
179  {
180  hmax = hQGDf_.boundaryField()[pid][pfid];
181  }
182  }
183  }
184  hRatio.primitiveFieldRef()[celli] = hmax / hQGD_[celli];
185  if (hRatio[celli] > 1.2)
186  {
187  cqSc_[celli] = 1.0;
188  }
189  }
190  }
191  */
192  //fvc::smooth(this->hQGD_, smoothCoeff_);
193 }
197 {
198 }
199 
200 void Foam::qgd::
201 varScModel6::correct(const Foam::QGDThermo& qgdThermo)
202 {
203  const volScalarField& cSound = qgdThermo.c();
204  const volScalarField& p = qgdThermo.p();
205  const volScalarField rho(qgdThermo.rho()*1.0);
206 
207  this->tauQGDf_= linearInterpolate(this->aQGD_ / cSound) * hQGDf_;
208  this->tauQGD_ = this->aQGD_ * this->hQGD_ / cSound;
209 
210  const surfaceScalarField pf =
211  linearInterpolate(p);
212  const surfaceScalarField dpf =
213  fvc::snGrad(p)/mesh_.deltaCoeffs();
214 
215  forAll(ScQGD_, icell)
216  {
217  const cell& facesOfCell = mesh_.cells()[icell];
218  ScQGD_[icell] = 0.0;
219  scalar sumDpF = 0.0;
220  scalar sumpf = 0.0;
221  label faceid = -1;
222  label patchid = -1;
223  scalar n = 0.0;
224 
225  forAll(facesOfCell, iface)
226  {
227  faceid = facesOfCell[iface];
228  if (mesh_.isInternalFace(faceid))
229  {
230  sumpf += pf.primitiveField()[faceid];
231  if (mesh_.owner()[faceid] == icell)
232  {
233  sumDpF += dpf.primitiveField()[faceid];
234  }
235  else
236  {
237  sumDpF -= dpf.primitiveField()[faceid];
238  }
239  n = n + 1;
240  }
241  else
242  {
243  patchid = mesh_.boundaryMesh().whichPatch(faceid);
244  if (isA<emptyFvPatch>(mesh_.boundary()[patchid]))
245  {
246  continue;
247  }
248  if (isA<wedgeFvPatch>(mesh_.boundary()[patchid]))
249  {
250  continue;
251  }
252  faceid -= mesh_.boundaryMesh()[patchid].start();
253 
254  if (p.boundaryField()[patchid].coupled())
255  {
256  sumDpF +=
257  (p.boundaryField()[patchid].patchNeighbourField()()[faceid] - p[icell]);
258  }
259  else
260  {
261  sumDpF += dpf.boundaryField()[patchid][faceid];
262  }
263  sumpf += pf.boundaryField()[patchid][faceid];
264  n = n + 1;
265  }
266  }
267  sumpf /= n;
268  ScQGD_[icell] = mag(sumDpF) / sumpf;
269  }
270 
271 
272 // if (mesh_.time().outputTime())
273 // {
274 // sumdp.write();
275 // avrp.write();
276 // }
277 
278 // this->ScQGD_ =
279 // rC_ *
280 // (mag(fvc::grad(rho)) * hQGD_ / rho) +
281 // (1.0 - rC_) * ScQGD_;
282 
283 // this->ScQGD_ =
284 // max(this->ScQGD_, minSc_);
285 // this->ScQGD_ =
286 // min(this->ScQGD_, maxSc_);
287 //
288 // this->ScQGD_.primitiveFieldRef() =
289 // max(this->ScQGD_.primitiveField(), cqSc_);
290 //
291 // if (constScCellSetPtr_.valid())
292 // {
293 // const cellSet& constScCells = constScCellSetPtr_();
294 //
295 // forAllConstIter(cellSet, constScCells, iter)
296 // {
297 // ScQGD_[iter.key()] = constSc_;
298 // }
299 // }
300 //
301 // fvc::smooth(this->ScQGD_, smoothCoeff_);
302 
303  Info<< "max/min ScQGD: "
304  << max(this->ScQGD_).value() << "/"
305  << min(this->ScQGD_).value() << endl;
306 
307  if (runTime_.outputTime())
308  {
309  this->ScQGD_.write();
310  this->hQGD_.write();
311  }
312 
313  forAll(p.primitiveField(), celli)
314  {
315  muQGD_.primitiveFieldRef()[celli] =
316  p.primitiveField()[celli] *
317  ScQGD_.primitiveField()[celli] *
318  tauQGD_.primitiveField()[celli];
319 
320  alphauQGD_.primitiveFieldRef()[celli] = muQGD_.primitiveField()[celli] /
321  PrQGD_.primitiveField()[celli];
322  }
323 
324  forAll(p.boundaryField(), patchi)
325  {
326  forAll(p.boundaryField()[patchi], facei)
327  {
328  muQGD_.boundaryFieldRef()[patchi][facei] =
329  p.boundaryField()[patchi][facei] *
330  ScQGD_.boundaryField()[patchi][facei] *
331  tauQGD_.boundaryField()[patchi][facei];
332 
333  alphauQGD_.boundaryFieldRef()[patchi][facei] =
334  muQGD_.boundaryFieldRef()[patchi][facei] /
335  PrQGD_.boundaryField()[patchi][facei];
336  }
337  }
338 }
339 
340 //
341 //END-OF-FILE
342 //
volScalarField PrQGD_
Definition: QGDCoeffs.H:115
pf
Definition: updateFields.H:21
void correct(const QGDThermo &)
Definition: varScModel6.C:194
autoPtr< cellSet > constScCellSetPtr_
Definition: varScModel6.H:73
varScModel6(const IOobject &io, const fvMesh &mesh, const dictionary &dict)
Definition: varScModel6.C:50
virtual const volScalarField & c() const =0
virtual tmp< volScalarField > rho() const =0
forAll(Y, i)
Definition: QGDYEqn.H:36
Abstract base class for classes implementing thermophysical properties of gases and fluids governed b...
Definition: QGDThermo.H:53
const fvMesh & mesh_
Definition: QGDCoeffs.H:65
volScalarField rho(IOobject("rho", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), thermo.rho())
virtual const volScalarField & p() const =0
addToRunTimeSelectionTable(QGDCoeffs, constScPrModel1, dictionary)
scalar qgdAspectRatioThreshold_
Definition: varScModel6.H:68
defineTypeNameAndDebug(constScPrModel1, 0)
volScalarField & p
Definition: createFields.H:52
volScalarField ScQGD_
Definition: QGDCoeffs.H:120