dsmcFields.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) 2016 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "dsmcFields.H"
30 #include "volFields.H"
31 #include "dictionary.H"
32 #include "dsmcCloud.H"
33 #include "constants.H"
35 
36 using namespace Foam::constant;
37 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 namespace functionObjects
43 {
44  defineTypeNameAndDebug(dsmcFields, 0);
45 
47  (
48  functionObject,
49  dsmcFields,
50  dictionary
51  );
52 }
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 
58 Foam::functionObjects::dsmcFields::dsmcFields
59 (
60  const word& name,
61  const Time& runTime,
62  const dictionary& dict
63 )
64 :
66 {
67  read(dict);
68 }
69 
70 
71 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
72 
74 {}
75 
76 
77 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
78 
80 {
82  return true;
83 }
84 
85 
87 {
88  return true;
89 }
90 
91 
93 {
94  word rhoNMeanName = "rhoNMean";
95  word rhoMMeanName = "rhoMMean";
96  word momentumMeanName = "momentumMean";
97  word linearKEMeanName = "linearKEMean";
98  word internalEMeanName = "internalEMean";
99  word iDofMeanName = "iDofMean";
100  word fDMeanName = "fDMean";
101 
102  const volScalarField& rhoNMean =
103  obr_.lookupObject<volScalarField>(rhoNMeanName);
104 
105  const volScalarField& rhoMMean =
106  obr_.lookupObject<volScalarField>(rhoMMeanName);
107 
108  const volVectorField& momentumMean =
109  obr_.lookupObject<volVectorField>(momentumMeanName);
110 
111  const volScalarField& linearKEMean =
112  obr_.lookupObject<volScalarField>(linearKEMeanName);
113 
114  const volScalarField& internalEMean =
115  obr_.lookupObject<volScalarField>(internalEMeanName);
116 
117  const volScalarField& iDofMean =
118  obr_.lookupObject<volScalarField>(iDofMeanName);
119 
120  const volVectorField& fDMean =
121  obr_.lookupObject<volVectorField>(fDMeanName);
122 
123  if (min(mag(rhoNMean)).value() > VSMALL)
124  {
125  Log << "Calculating dsmcFields." << endl;
126 
127  Log << " Calculating UMean field." << endl;
129  (
130  IOobject
131  (
132  "UMean",
133  obr_.time().timeName(),
134  obr_,
136  ),
137  momentumMean/rhoMMean
138  );
139 
140  Log << " Calculating translationalT field." << endl;
141  volScalarField translationalT
142  (
143  IOobject
144  (
145  "translationalT",
146  obr_.time().timeName(),
147  obr_,
149  ),
150 
151  2.0/(3.0*physicoChemical::k.value()*rhoNMean)
152  *(linearKEMean - 0.5*rhoMMean*(UMean & UMean))
153  );
154 
155  Log << " Calculating internalT field." << endl;
156  volScalarField internalT
157  (
158  IOobject
159  (
160  "internalT",
161  obr_.time().timeName(),
162  obr_,
164  ),
165  (2.0/physicoChemical::k.value())*(internalEMean/iDofMean)
166  );
167 
168  Log << " Calculating overallT field." << endl;
169  volScalarField overallT
170  (
171  IOobject
172  (
173  "overallT",
174  obr_.time().timeName(),
175  obr_,
177  ),
178  2.0/(physicoChemical::k.value()*(3.0*rhoNMean + iDofMean))
179  *(linearKEMean - 0.5*rhoMMean*(UMean & UMean) + internalEMean)
180  );
181 
182  Log << " Calculating pressure field." << endl;
184  (
185  IOobject
186  (
187  "p",
188  obr_.time().timeName(),
189  obr_,
191  ),
192  physicoChemical::k.value()*rhoNMean*translationalT
193  );
194 
195  volScalarField::Boundary& pBf = p.boundaryFieldRef();
196 
197  forAll(mesh_.boundaryMesh(), i)
198  {
199  const polyPatch& patch = mesh_.boundaryMesh()[i];
200 
201  if (isA<wallPolyPatch>(patch))
202  {
203  pBf[i] =
204  fDMean.boundaryField()[i]
205  & (patch.faceAreas()/mag(patch.faceAreas()));
206  }
207  }
208 
209 
210  Log << " mag(UMean) max/min : "
211  << max(mag(UMean)).value() << " "
212  << min(mag(UMean)).value() << nl
213 
214  << " translationalT max/min : "
215  << max(translationalT).value() << " "
216  << min(translationalT).value() << nl
217 
218  << " internalT max/min : "
219  << max(internalT).value() << " "
220  << min(internalT).value() << nl
221 
222  << " overallT max/min : "
223  << max(overallT).value() << " "
224  << min(overallT).value() << nl
225 
226  << " p max/min : "
227  << max(p).value() << " "
228  << min(p).value() << endl;
229 
230  UMean.write();
231 
232  translationalT.write();
233 
234  internalT.write();
235 
236  overallT.write();
237 
238  p.write();
239 
240  Log << "dsmcFields written." << nl << endl;
241 
242  return true;
243  }
244  else
245  {
246  Log << "Small value (" << min(mag(rhoNMean))
247  << ") found in rhoNMean field. "
248  << "Not calculating dsmcFields to avoid division by zero."
249  << endl;
250 
251  return false;
252  }
253 }
254 
255 
256 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
volFields.H
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
p
volScalarField & p
Definition: createFieldRefs.H:8
Log
#define Log
Definition: PDRblock.C:35
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionObjects::dsmcFields::execute
virtual bool execute()
Do nothing.
Definition: dsmcFields.C:86
Foam::constant::physicoChemical::k
const dimensionedScalar k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::constant
Different types of constants.
Definition: atomicConstants.C:38
dsmcCloud.H
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::functionObjects::dsmcFields::write
virtual bool write()
Calculate and write the DSMC fields.
Definition: dsmcFields.C:92
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
dsmcFields.H
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::functionObjects::dsmcFields::read
virtual bool read(const dictionary &)
Read the dsmcFields data.
Definition: dsmcFields.C:79
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
constants.H
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
dictionary.H
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:123
UMean
volVectorField UMean(UMeanHeader, mesh)
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::functionObjects::dsmcFields::~dsmcFields
virtual ~dsmcFields()
Destructor.
Definition: dsmcFields.C:73