All Classes Namespaces Files Functions Variables Typedefs Friends Macros Groups
varScModel5.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 "varScModel5.H"
30 #include "psiQGDThermo.H"
31 #include "addToRunTimeSelectionTable.H"
32 #include "fvcSmooth.H"
33 #include "fvcGrad.H"
34 #include "primitiveMeshTools.H"
35 #include "linear.H"
36 #include "cellSet.H"
37 
38 namespace Foam
39 {
40 namespace qgd
41 {
42  defineTypeNameAndDebug(varScModel5,0);
44  (
45  QGDCoeffs,
46  varScModel5,
47  dictionary
48  );
49 }
50 }
51 
54 (
55  const IOobject& io,
56  const fvMesh& mesh,
57  const dictionary& dict
58 )
59 :
60  QGDCoeffs(io, mesh, dict),
61  smoothCoeff_(0.1),
62  rC_(0.5),
63  minSc_(0.05),
64  maxSc_(1.00),
65  badQualitySc_(0.05),
66  qgdAspectRatioThreshold_(1.5),
67  constSc_(0.05),
68  cqSc_(mesh.V().size(), 0.0),
69  constScCellSetPtr_(nullptr)
70 {
71  scalar ScQGD = 0.0, PrQGD = 1.0;
72 
73  dict.lookup("ScQGD") >> ScQGD;
74  dict.lookup("PrQGD") >> PrQGD;
75 
76  ScQGD_.primitiveFieldRef() = ScQGD;
77  PrQGD_.primitiveFieldRef() = PrQGD;
78 
79  ScQGD_.boundaryFieldRef() = ScQGD;
80  PrQGD_.boundaryFieldRef() = PrQGD;
81 
82  if (dict.found("smoothCoeff"))
83  {
84  dict.lookup("smoothCoeff") >> smoothCoeff_;
85  }
86 
87  if (dict.found("rC"))
88  {
89  dict.lookup("rC") >> rC_;
90  }
91 
92  if (dict.found("minSc"))
93  {
94  dict.lookup("minSc") >> minSc_;
95  }
96 
97  if (dict.found("maxSc"))
98  {
99  dict.lookup("maxSc") >> maxSc_;
100  }
101 
102  if (dict.found("badQualitySc"))
103  {
104  dict.lookup("badQualitySc") >> badQualitySc_;
105  }
106 
107  if (dict.found("maxAspectRatio"))
108  {
109  dict.lookup("maxAspectRatio") >> qgdAspectRatioThreshold_;
110  }
111 
112  scalarField openness(mesh.V().size(), 0);
113  scalarField aspectRatio(mesh.V().size(), 1);
114 
115  primitiveMeshTools::cellClosedness
116  (
117  mesh_,
118  mesh_.geometricD(),
119  mesh_.faceAreas(),
120  mesh_.cellVolumes(),
121  openness,
122  aspectRatio
123  );
124 
125  forAll(aspectRatio, iCell)
126  {
127  if (aspectRatio[iCell] > qgdAspectRatioThreshold_)
128  {
129  cqSc_[iCell] = badQualitySc_ * aspectRatio[iCell] / qgdAspectRatioThreshold_;
130  //cqSc_[iCell] = badQualitySc_;
131  }
132  }
133 
134  if (dict.found("constScCellSet"))
135  {
136  word constScCellSet (dict.lookup("constScCellSet"));
137  constSc_ = ScQGD;
138 
139  constScCellSetPtr_.reset
140  (
141  new cellSet
142  (
143  mesh,
144  constScCellSet,
145  IOobject::MUST_READ,
146  IOobject::NO_WRITE
147  )
148  );
149  }
150 
151  /*
152  {
153  volScalarField hRatio(this->hQGD_);
154  label fid = -1, pid = -1, pfid = -1;
155  scalar hmax = 0.0;
156  forAll(hRatio, celli)
157  {
158  const cell& c = mesh.cells()[celli];
159  hmax = 0.0;
160  forAll(c, facei)
161  {
162  fid = c[facei];
163  if (mesh.isInternalFace(fid))
164  {
165  if (hQGDf_[fid] > hmax)
166  {
167  hmax = hQGDf_[fid];
168  }
169  }
170  else
171  {
172  pid = mesh.boundaryMesh().whichPatch(fid);
173  pfid= mesh.boundary()[pid].patch().whichFace(fid);
174 
175  if (hQGDf_.boundaryField()[pid][pfid] > hmax)
176  {
177  hmax = hQGDf_.boundaryField()[pid][pfid];
178  }
179  }
180  }
181  hRatio.primitiveFieldRef()[celli] = hmax / hQGD_[celli];
182  if (hRatio[celli] > 1.2)
183  {
184  cqSc_[celli] = 1.0;
185  }
186  }
187  }
188  */
189  //fvc::smooth(this->hQGD_, smoothCoeff_);
190 }
194 {
195 }
196 
197 void Foam::qgd::
198 varScModel5::correct(const Foam::QGDThermo& qgdThermo)
199 {
200  const volScalarField& cSound = qgdThermo.c();
201  const volScalarField& p = qgdThermo.p();
202  const volScalarField rho(qgdThermo.rho()*1.0);
203 
204  this->tauQGDf_= linearInterpolate(this->aQGD_)
205  / linearInterpolate(cSound) * hQGDf_;
206 
207  this->tauQGD_ = this->aQGD_ * this->hQGD_ / cSound;
208 
209  this->ScQGD_ =
210  rC_ *
211  (mag(fvc::grad(rho)) * hQGD_ / rho) +
212  (1.0 - rC_) * ScQGD_;
213 
214  this->ScQGD_ =
215  max(this->ScQGD_, minSc_);
216  this->ScQGD_ =
217  min(this->ScQGD_, maxSc_);
218 
219  this->ScQGD_.primitiveFieldRef() =
220  max(this->ScQGD_.primitiveField(), cqSc_);
221 
222  if (constScCellSetPtr_.valid())
223  {
224  const cellSet& constScCells = constScCellSetPtr_();
225 
226  forAllConstIter(cellSet, constScCells, iter)
227  {
228  ScQGD_[iter.key()] = constSc_;
229  }
230  }
231 
232  fvc::smooth(this->ScQGD_, smoothCoeff_);
233 
234  Info<< "max/min ScQGD: "
235  << max(this->ScQGD_).value() << "/"
236  << min(this->ScQGD_).value() << endl;
237 
238  if (runTime_.outputTime())
239  {
240  this->ScQGD_.write();
241  this->hQGD_.write();
242  }
243 
244  forAll(p.primitiveField(), celli)
245  {
246  muQGD_.primitiveFieldRef()[celli] =
247  p.primitiveField()[celli] *
248  ScQGD_.primitiveField()[celli] *
249  tauQGD_.primitiveField()[celli];
250 
251  alphauQGD_.primitiveFieldRef()[celli] = muQGD_.primitiveField()[celli] /
252  PrQGD_.primitiveField()[celli];
253  }
254 
255  forAll(p.boundaryField(), patchi)
256  {
257  forAll(p.boundaryField()[patchi], facei)
258  {
259  muQGD_.boundaryFieldRef()[patchi][facei] =
260  p.boundaryField()[patchi][facei] *
261  ScQGD_.boundaryField()[patchi][facei] *
262  tauQGD_.boundaryField()[patchi][facei];
263 
264  alphauQGD_.boundaryFieldRef()[patchi][facei] =
265  muQGD_.boundaryFieldRef()[patchi][facei] /
266  PrQGD_.boundaryField()[patchi][facei];
267  }
268  }
269 }
270 
271 //
272 //END-OF-FILE
273 //
volScalarField PrQGD_
Definition: QGDCoeffs.H:115
virtual const volScalarField & c() const =0
virtual tmp< volScalarField > rho() const =0
forAll(Y, i)
Definition: QGDYEqn.H:36
varScModel5(const IOobject &io, const fvMesh &mesh, const dictionary &dict)
Definition: varScModel5.C:47
autoPtr< cellSet > constScCellSetPtr_
Definition: varScModel5.H:74
scalar qgdAspectRatioThreshold_
Definition: varScModel5.H:69
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
tmp< surfaceVectorField > grad(const volScalarField &vF)
addToRunTimeSelectionTable(QGDCoeffs, constScPrModel1, dictionary)
defineTypeNameAndDebug(constScPrModel1, 0)
volScalarField & p
Definition: createFields.H:52
volScalarField ScQGD_
Definition: QGDCoeffs.H:120
void correct(const QGDThermo &)
Definition: varScModel5.C:191