AveragingMethod.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) 2013-2017 OpenFOAM Foundation
9  Copyright (C) 2019 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 "AveragingMethod.H"
30 #include "runTimeSelectionTables.H"
31 #include "pointMesh.H"
32 
33 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
34 
35 template<class Type>
37 {}
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
42 template<class Type>
44 (
45  const IOobject& io,
46  const dictionary& dict,
47  const fvMesh& mesh,
48  const labelList& size
49 )
50 :
51  regIOobject(io),
53  dict_(dict),
54  mesh_(mesh)
55 {
56  forAll(size, i)
57  {
59  (
60  new Field<Type>(size[i], Zero)
61  );
62  }
63 }
64 
65 
66 template<class Type>
68 (
69  const AveragingMethod<Type>& am
70 )
71 :
72  regIOobject(am),
74  dict_(am.dict_),
75  mesh_(am.mesh_)
76 {}
77 
78 
79 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
80 
81 template<class Type>
84 (
85  const IOobject& io,
86  const dictionary& dict,
87  const fvMesh& mesh
88 )
89 {
90  const word modelType(dict.get<word>(typeName));
91 
92  //Info<< "Selecting averaging method " << modelType << endl;
93 
94  auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
95 
96  if (!cstrIter.found())
97  {
99  (
100  dict,
101  "averaging limiter",
102  modelType,
103  *dictionaryConstructorTablePtr_
104  ) << abort(FatalIOError);
105  }
106 
107  return autoPtr<AveragingMethod<Type>>(cstrIter()(io, dict, mesh));
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
112 
113 template<class Type>
115 {
116  updateGrad();
117 }
118 
119 
120 template<class Type>
122 (
123  const AveragingMethod<scalar>& weight
124 )
125 {
126  updateGrad();
127 
128  *this /= max(weight, SMALL);
129 }
130 
131 
132 template<class Type>
134 {
135  return os.good();
136 }
137 
138 
139 template<class Type>
140 bool Foam::AveragingMethod<Type>::write(const bool valid) const
141 {
142  const pointMesh pointMesh_(mesh_);
143 
144  // point volumes
145  Field<scalar> pointVolume(mesh_.nPoints(), Zero);
146 
147  // output fields
149  (
150  IOobject
151  (
152  this->name() + ":cellValue",
153  this->time().timeName(),
154  mesh_
155  ),
156  mesh_,
158  );
160  (
161  IOobject
162  (
163  this->name() + ":cellGrad",
164  this->time().timeName(),
165  mesh_
166  ),
167  mesh_,
169  );
171  (
172  IOobject
173  (
174  this->name() + ":pointValue",
175  this->time().timeName(),
176  mesh_
177  ),
178  pointMesh_,
180  );
182  (
183  IOobject
184  (
185  this->name() + ":pointGrad",
186  this->time().timeName(),
187  mesh_
188  ),
189  pointMesh_,
191  );
192 
193  // Barycentric coordinates of the tet vertices
195  tetCrds
196  ({
197  barycentric(1, 0, 0, 0),
198  barycentric(0, 1, 0, 0),
199  barycentric(0, 0, 1, 0),
200  barycentric(0, 0, 0, 1)
201  });
202 
203  // tet-volume weighted sums
204  forAll(mesh_.C(), celli)
205  {
206  const List<tetIndices> cellTets =
207  polyMeshTetDecomposition::cellTetIndices(mesh_, celli);
208 
209  forAll(cellTets, tetI)
210  {
211  const tetIndices& tetIs = cellTets[tetI];
212  const triFace triIs = tetIs.faceTriIs(mesh_);
213  const scalar v = tetIs.tet(mesh_).mag();
214 
215  cellValue[celli] += v*interpolate(tetCrds[0], tetIs);
216  cellGrad[celli] += v*interpolateGrad(tetCrds[0], tetIs);
217 
218  forAll(triIs, vertexI)
219  {
220  const label pointi = triIs[vertexI];
221 
222  pointVolume[pointi] += v;
223  pointValue[pointi] += v*interpolate(tetCrds[vertexI], tetIs);
224  pointGrad[pointi] += v*interpolateGrad(tetCrds[vertexI], tetIs);
225  }
226  }
227  }
228 
229  // average
230  cellValue.primitiveFieldRef() /= mesh_.V();
231  cellGrad.primitiveFieldRef() /= mesh_.V();
232  pointValue.primitiveFieldRef() /= pointVolume;
233  pointGrad.primitiveFieldRef() /= pointVolume;
234 
235  // write
236  if (!cellValue.write(valid)) return false;
237  if (!cellGrad.write(valid)) return false;
238  if (!pointValue.write(valid)) return false;
239  if (!pointGrad.write(valid)) return false;
240 
241  return true;
242 }
243 
244 
245 // ************************************************************************* //
Foam::AveragingMethod
Base class for lagrangian averaging methods.
Definition: MPPICParcel.H:61
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::tetIndices::tet
tetPointRef tet(const polyMesh &mesh) const
Return the geometry corresponding to this tet.
Definition: tetIndicesI.H:154
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::FieldField
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:53
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::AveragingMethod::write
virtual bool write(const bool valid=true) const
Write using setting from DB.
Definition: AveragingMethod.C:140
Foam::FatalIOError
IOerror FatalIOError
AveragingMethod.H
Foam::AveragingMethod::New
static autoPtr< AveragingMethod< Type > > New(const IOobject &io, const dictionary &dict, const fvMesh &mesh)
Selector.
Definition: AveragingMethod.C:84
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::AveragingMethod::dict_
const dictionary & dict_
Protected data.
Definition: AveragingMethod.H:74
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:380
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::AveragingMethod::updateGrad
virtual void updateGrad()
Protected member functions.
Definition: AveragingMethod.C:36
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
timeName
word timeName
Definition: getTimeIndex.H:3
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
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:43
Foam::tetIndices::faceTriIs
triFace faceTriIs(const polyMesh &mesh, const bool warn=true) const
Return the indices corresponding to the tri on the face for.
Definition: tetIndicesI.H:67
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:50
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::GeometricField::primitiveFieldRef
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field.
Definition: GeometricField.C:735
Foam::AveragingMethod::AveragingMethod
AveragingMethod(const IOobject &io, const dictionary &dict, const fvMesh &mesh, const labelList &size)
Constructors.
Definition: AveragingMethod.C:44
Foam::tetIndices
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Definition: tetIndices.H:83
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
Foam::triFace
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:70
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::List< label >
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
Foam::AveragingMethod::mesh_
const fvMesh & mesh_
The mesh on which the averaging is to be done.
Definition: AveragingMethod.H:77
append
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
Foam::AveragingMethod::writeData
virtual bool writeData(Ostream &) const
Dummy write.
Definition: AveragingMethod.C:133
Foam::barycentric
Barycentric< scalar > barycentric
A scalar version of the templated Barycentric.
Definition: barycentric.H:47
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:216
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::tetrahedron::mag
scalar mag() const
Return volume.
Definition: tetrahedronI.H:172
Foam::AveragingMethod::average
virtual void average()
Calculate the average.
Definition: AveragingMethod.C:114
Foam::fac::interpolate
static tmp< GeometricField< Type, faePatchField, edgeMesh > > interpolate(const GeometricField< Type, faPatchField, areaMesh > &tvf, const edgeScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
pointMesh.H