All Classes Namespaces Files Functions Variables Typedefs Friends Macros Groups
QGDCoeffs.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 "QGDCoeffs.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
32 #include "fvMesh.H"
33 #include "Time.H"
34 #include "addToRunTimeSelectionTable.H"
35 #include "coupledFvsPatchFields.H"
36 #include "QGDThermo.H"
37 #include "linear.H"
38 #include "emptyFvPatch.H"
39 #include "wedgeFvPatch.H"
40 #include "zeroGradientFvPatchFields.H"
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 namespace qgd
47 {
48  defineTypeNameAndDebug(QGDCoeffs, 0);
49  defineRunTimeSelectionTable(QGDCoeffs, dictionary);
50 }
51 }
52 
53 namespace Foam
54 {
55 namespace qgd
56 {
57 
58 autoPtr<QGDCoeffs> QGDCoeffs::New
59 (
60  const word& qgdCoeffsType,
61  const fvMesh& mesh,
62  const dictionary& dict
63 )
64 {
65  Info<< "Selecting QGD coeffs evaluation approach type " << qgdCoeffsType << endl;
66 
67  dictionaryConstructorTable::iterator cstrIter =
68  dictionaryConstructorTablePtr_->find(qgdCoeffsType);
69 
70  if (cstrIter == dictionaryConstructorTablePtr_->end())
71  {
72  FatalErrorIn
73  (
74  "QGDCoeffs::New(const word&, const fvMesh&)"
75  ) << "Unknown QGD coeffs evaluation approach type " << qgdCoeffsType << nl << nl
76  << "Valid model types are:" << nl
77  << dictionaryConstructorTablePtr_->sortedToc()
78  << exit(FatalError);
79  }
80 
81  if (dict.found(qgdCoeffsType + "Dict"))
82  {
83  return autoPtr<QGDCoeffs>
84  (
85  cstrIter()
86  (
87  IOobject
88  (
89  qgdCoeffsType,
90  mesh.time().timeName(),
91  mesh,
92  IOobject::NO_READ,
93  IOobject::NO_WRITE
94  ),
95  mesh,
96  dict.subDict(qgdCoeffsType + "Dict")
97  )
98  );
99  }
100 
101  return autoPtr<QGDCoeffs>
102  (
103  cstrIter()
104  (
105  IOobject
106  (
107  qgdCoeffsType,
108  mesh.time().timeName(),
109  mesh,
110  IOobject::NO_READ,
111  IOobject::NO_WRITE
112  ),
113  mesh,
114  dict
115  )
116  );
117 }
118 
119 tmp<volScalarField> QGDCoeffs::readOrCreateAlphaQGD(const fvMesh& mesh)
120 {
121  IOobject aQGDHeader
122  (
123  "alphaQGD",
124  mesh.time().timeName(),
125  mesh,
126  IOobject::READ_IF_PRESENT,
127  IOobject::NO_WRITE
128  );
129 
130  if (aQGDHeader.typeHeaderOk<volScalarField>())
131  {
132  aQGDHeader.writeOpt() = IOobject::AUTO_WRITE;
133 
134  return
135  tmp<volScalarField>
136  (
137  new volScalarField
138  (
139  aQGDHeader,
140  mesh
141  )
142  );
143  }
144 
145  tmp<volScalarField> newAlphaQGD
146  (
147  new volScalarField
148  (
149  aQGDHeader,
150  mesh,
151  dimensionSet(0, 0, 0, 0, 0),
152  zeroGradientFvPatchScalarField::typeName
153  )
154  );
155 
156  newAlphaQGD.ref().primitiveFieldRef() = 0.5;
157  newAlphaQGD.ref().correctBoundaryConditions();
158 
159  return newAlphaQGD;
160 }
161 
162 //
163 QGDCoeffs::QGDCoeffs(const IOobject& io, const fvMesh& mesh, const dictionary& dict)
164 :
165  regIOobject(io, false),
166  refCount(),
167  mesh_(mesh),
168  runTime_(mesh_.time()),
169  muQGD_
170  (
171  IOobject
172  (
173  "muQGD",
174  mesh.time().timeName(),
175  mesh,
176  IOobject::NO_READ,
177  IOobject::NO_WRITE
178  ),
179  mesh,
180  dimensionSet(1, -1, -1, 0, 0)
181  ),
182  alphauQGD_
183  (
184  IOobject
185  (
186  "alphauQGD",
187  mesh.time().timeName(),
188  mesh,
189  IOobject::NO_READ,
190  IOobject::NO_WRITE
191  ),
192  mesh,
193  dimensionSet(1, -1, -1, 0, 0)
194  ),
195  hQGDf_
196  (
197  "hQGDf",
198  1.0 / mag(mesh.surfaceInterpolation::deltaCoeffs())
199  ),
200  hQGD_
201  (
202  IOobject
203  (
204  "hQGD",
205  mesh.time().timeName(),
206  mesh,
207  IOobject::NO_READ,
208  IOobject::NO_WRITE
209  ),
210  mesh,
211  hQGDf_.dimensions()
212  ),
213  taQGD_
214  (
215  readOrCreateAlphaQGD(mesh)
216  ),
217  aQGD_(taQGD_.ref()),
218  tauQGD_
219  (
220  IOobject
221  (
222  "tauQGD",
223  mesh.time().timeName(),
224  mesh,
225  IOobject::NO_READ,
226  IOobject::NO_WRITE
227  ),
228  mesh,
229  dimensionSet(0, 0, 1, 0, 0)
230  ),
231  tauQGDf_
232  (
233  "tauQGDf",
234  linearInterpolate(tauQGD_)
235  ),
236  PrQGD_
237  (
238  IOobject
239  (
240  "PrQGD",
241  mesh.time().timeName(),
242  mesh,
243  IOobject::NO_READ,
244  IOobject::NO_WRITE
245  ),
246  mesh,
247  dimensionSet(0, 0, 0, 0, 0)
248  ),
249  ScQGD_
250  (
251  IOobject
252  (
253  "ScQGD",
254  mesh.time().timeName(),
255  mesh,
256  IOobject::READ_IF_PRESENT,
257  IOobject::NO_WRITE
258  ),
259  mesh,
260  dimensionSet(0, 0, 0, 0, 0)
261  )
262 {
263  this->updateQGDLength(mesh);
264 }
265 
267 {
268 }
269 
270 void Foam::qgd::QGDCoeffs::correct(const QGDThermo& qgdThermo)
271 {
272  forAll(tauQGD_, celli)
273  {
274  tauQGD_.primitiveFieldRef()[celli] = 0.0;
275  muQGD_.primitiveFieldRef()[celli] = 0.0;
276  alphauQGD_.primitiveFieldRef()[celli] = 0.0;
277  ScQGD_.primitiveFieldRef()[celli] = 1.0;
278  PrQGD_.primitiveFieldRef()[celli] = 1.0;
279  }
280  forAll(tauQGD_.boundaryField(), patchi)
281  {
282  forAll(tauQGD_.boundaryField()[patchi], facei)
283  {
284  tauQGD_.boundaryFieldRef()[patchi][facei] =
285  0.0;
286  muQGD_.boundaryFieldRef()[patchi][facei] =
287  0.0;
288  alphauQGD_.boundaryFieldRef()[patchi][facei] =
289  0.0;
290  PrQGD_.boundaryFieldRef()[patchi][facei] =
291  1.0;
292  ScQGD_.boundaryFieldRef()[patchi][facei] =
293  1.0;
294  }
295  }
296 }
297 
298 void Foam::qgd::QGDCoeffs::updateQGDLength(const fvMesh& mesh)
299 {
300  {
301  scalar hown = 0.0;
302  scalar hnei = 0.0;
303  forAll(hQGDf_.primitiveField(), iFace)
304  {
305  hown = mag(mesh.C()[mesh.owner()[iFace]] - mesh.Cf()[iFace]);
306  hnei = mag(mesh.C()[mesh.neighbour()[iFace]] - mesh.Cf()[iFace]);
307  hQGDf_.primitiveFieldRef()[iFace] = 2.0*min(hown, hnei);
308  }
309 
310  forAll(mesh.boundary(), patchi)
311  {
312  const fvPatch& fvp = mesh.boundary()[patchi];
313  if (!fvp.coupled())
314  {
315  hQGDf_.boundaryFieldRef()[patchi] *= 2.0;
316  }
317  }
318  }
319 
320  scalar hint = 0.0;
321  scalar surf = 0.0;
322  label fid = 0;
323  forAll(hQGD_, celli)
324  {
325  const cell& c = mesh.cells()[celli];
326  hint = 0.0;
327  surf = 0.0;
328  label pid = -1;
329  label pfid = -1;
330  forAll(c, facei)
331  {
332  fid = c[facei];
333 
334  if (mesh.isInternalFace(fid))
335  {
336  hint += hQGDf_[fid] * mesh.magSf()[fid];
337  surf += mesh.magSf()[fid];
338  }
339  else
340  {
341  pid = mesh.boundaryMesh().whichPatch(fid);
342  if (pid >= 0)
343  {
344  if
345  (
346  !isA<emptyFvPatch>(mesh.boundary()[pid])
347  &&
348  !isA<wedgeFvPatch>(mesh.boundary()[pid])
349  )
350  {
351  pfid = mesh.boundaryMesh()[pid].whichFace(fid);
352 
353  hint += hQGDf_.boundaryField()[pid][pfid] *
354  mesh.magSf().boundaryField()[pid][pfid];
355  surf += mesh.magSf().boundaryField()[pid][pfid];
356  }
357  }
358  }
359  }
360 
361  hQGD_.primitiveFieldRef()[celli] = hint / surf;
362  }
363 
364  forAll(mesh.boundary(), patchi)
365  {
366  if
367  (
368  !isA<emptyFvPatch>(mesh.boundary()[patchi])
369  //&&
371  )
372  {
373  hQGD_.boundaryFieldRef()[patchi] = hQGDf_.boundaryField()[patchi] * 1.0;
374  }
375  }
376 }
377 
378 const Foam::surfaceScalarField& Foam::qgd::QGDCoeffs::hQGDf() const
379 {
380  return hQGDf_;
381 }
382 
383 const Foam::volScalarField& Foam::qgd::QGDCoeffs::hQGD() const
384 {
385  return hQGD_;
386 }
387 
388 const Foam::volScalarField& Foam::qgd::QGDCoeffs::alphauQGD() const
389 {
390  return alphauQGD_;
391 }
392 
393 const Foam::volScalarField& Foam::qgd::QGDCoeffs::muQGD() const
394 {
395  return muQGD_;
396 }
397 
398 const Foam::volScalarField& Foam::qgd::QGDCoeffs::tauQGD() const
399 {
400  return tauQGD_;
401 }
402 
403 const Foam::surfaceScalarField& Foam::qgd::QGDCoeffs::tauQGDf() const
404 {
405  return tauQGDf_;
406 }
407 
408 }; //namespace qgd
409 
410 }; //namespace Foam
411 
412 
413 //END-OF-FILE
virtual void updateQGDLength(const fvMesh &)
Definition: QGDCoeffs.C:291
defineRunTimeSelectionTable(QGDCoeffs, dictionary)
QGDCoeffs(const IOobject &io, const fvMesh &mesh, const dictionary &dict)
Construct from components.
Definition: QGDCoeffs.C:156
const volScalarField & muQGD() const
Definition: QGDCoeffs.C:386
U ref()
const surfaceScalarField & hQGDf() const
Definition: QGDCoeffs.C:371
static autoPtr< QGDCoeffs > New(const word &qgdCoeffsType, const fvMesh &mesh, const dictionary &dict)
Return a reference to the selected fvscStencil model.
Definition: QGDCoeffs.C:52
const volScalarField & tauQGD() const
Definition: QGDCoeffs.C:391
const surfaceScalarField & tauQGDf() const
Definition: QGDCoeffs.C:396
forAll(Y, i)
Definition: QGDYEqn.H:36
const volScalarField & alphauQGD() const
Definition: QGDCoeffs.C:381
tmp< volScalarField > readOrCreateAlphaQGD(const fvMesh &)
Definition: QGDCoeffs.C:112
Abstract base class for classes implementing thermophysical properties of gases and fluids governed b...
Definition: QGDThermo.H:53
virtual void correct(const QGDThermo &)
Definition: QGDCoeffs.C:263
virtual ~QGDCoeffs()
Definition: QGDCoeffs.C:259
const volScalarField & hQGD() const
Definition: QGDCoeffs.C:376
defineTypeNameAndDebug(constScPrModel1, 0)