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 | Copyright (C) 2013-2014 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "AveragingMethod.H"
27 #include "runTimeSelectionTables.H"
28 #include "pointMesh.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const IOobject& io,
36  const dictionary& dict,
37  const fvMesh& mesh,
38  const labelList& size
39 )
40 :
41  regIOobject(io),
43  dict_(dict),
44  mesh_(mesh)
45 {
46  forAll(size, i)
47  {
49  (
50  new Field<Type>(size[i], pTraits<Type>::zero)
51  );
52  }
53 }
54 
55 
56 template<class Type>
58 (
59  const AveragingMethod<Type>& am
60 )
61 :
62  regIOobject(am),
64  dict_(am.dict_),
65  mesh_(am.mesh_)
66 {}
67 
68 
69 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
70 
71 template<class Type>
74 (
75  const IOobject& io,
76  const dictionary& dict,
77  const fvMesh& mesh
78 )
79 {
80  word averageType(dict.lookup(typeName));
81 
82  //Info<< "Selecting averaging method "
83  // << averageType << endl;
84 
85  typename dictionaryConstructorTable::iterator cstrIter =
86  dictionaryConstructorTablePtr_->find(averageType);
87 
88  if (cstrIter == dictionaryConstructorTablePtr_->end())
89  {
91  (
92  "Foam::AveragingMethod<Type>::New"
93  "("
94  "const IOobject&, "
95  "const dictionary&, "
96  "const fvMesh&"
97  ")"
98  ) << "Unknown averaging method " << averageType
99  << ", constructor not in hash table" << nl << nl
100  << " Valid averaging methods are:" << nl
101  << dictionaryConstructorTablePtr_->sortedToc()
102  << abort(FatalError);
103  }
104 
105  return autoPtr<AveragingMethod<Type> >(cstrIter()(io, dict, mesh));
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
110 
111 template<class Type>
113 {}
114 
115 
116 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
117 
118 template<class Type>
120 {
121  // do nothing
122 }
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
127 template<class Type>
129 {
130  updateGrad();
131 }
132 
133 
134 template<class Type>
136 (
137  const AveragingMethod<scalar>& weight
138 )
139 {
140  updateGrad();
141 
142  *this /= max(weight, SMALL);
143 }
144 
145 
146 template<class Type>
148 {
149  return os.good();
150 }
151 
152 
153 template<class Type>
155 {
156  const pointMesh pointMesh_(mesh_);
157 
158  // point volumes
159  Field<scalar> pointVolume(mesh_.nPoints(), 0);
160 
161  // output fields
163  (
164  IOobject
165  (
166  this->name() + ":cellValue",
167  this->time().timeName(),
168  mesh_
169  ),
170  mesh_,
172  );
174  (
175  IOobject
176  (
177  this->name() + ":cellGrad",
178  this->time().timeName(),
179  mesh_
180  ),
181  mesh_,
183  );
185  (
186  IOobject
187  (
188  this->name() + ":pointValue",
189  this->time().timeName(),
190  mesh_
191  ),
192  pointMesh_,
194  );
196  (
197  IOobject
198  (
199  this->name() + ":pointGrad",
200  this->time().timeName(),
201  mesh_
202  ),
203  pointMesh_,
205  );
206 
207  // tet-volume weighted sums
208  forAll(mesh_.C(), cellI)
209  {
210  const List<tetIndices> cellTets =
211  polyMeshTetDecomposition::cellTetIndices(mesh_, cellI);
212 
213  forAll(cellTets, tetI)
214  {
215  const tetIndices& tetIs = cellTets[tetI];
216  const scalar v = tetIs.tet(mesh_).mag();
217 
218  cellValue[cellI] += v*interpolate(mesh_.C()[cellI], tetIs);
219  cellGrad[cellI] += v*interpolateGrad(mesh_.C()[cellI], tetIs);
220 
221  const face& f = mesh_.faces()[tetIs.face()];
222  labelList vertices(3);
223  vertices[0] = f[tetIs.faceBasePt()];
224  vertices[1] = f[tetIs.facePtA()];
225  vertices[2] = f[tetIs.facePtB()];
226 
227  forAll(vertices, vertexI)
228  {
229  const label pointI = vertices[vertexI];
230 
231  pointVolume[pointI] += v;
232  pointValue[pointI] +=
233  v*interpolate(mesh_.points()[pointI], tetIs);
234  pointGrad[pointI] +=
235  v*interpolateGrad(mesh_.points()[pointI], tetIs);
236  }
237  }
238  }
239 
240  // average
241  cellValue.internalField() /= mesh_.V();
242  cellGrad.internalField() /= mesh_.V();
243  pointValue.internalField() /= pointVolume;
244  pointGrad.internalField() /= pointVolume;
245 
246  // write
247  if (!cellValue.write()) return false;
248  if (!cellGrad.write()) return false;
249  if (!pointValue.write()) return false;
250  if (!pointGrad.write()) return false;
251 
252  return true;
253 }
254 
255 
256 // ************************************************************************* //
static autoPtr< AveragingMethod< Type > > New(const IOobject &io, const dictionary &dict, const fvMesh &mesh)
Selector.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Generic field type.
Definition: FieldField.H:51
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
labelList f(nPoints)
label faceBasePt() const
Return the face base point.
Definition: tetIndicesI.H:42
virtual ~AveragingMethod()
Destructor.
Macros to ease declaration of run-time selection tables.
A class for handling words, derived from string.
Definition: word.H:59
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:59
InternalField & internalField()
Return internal field.
tmp< surfaceScalarField > interpolate(const RhoType &rho)
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:48
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
scalar mag() const
Return volume.
Definition: tetrahedronI.H:171
tetPointRef tet(const polyMesh &mesh) const
Return the geometry corresponding to this tet from the.
Definition: tetIndicesI.H:66
virtual bool write() const
Write using setting from DB.
AveragingMethod(const IOobject &io, const dictionary &dict, const fvMesh &mesh, const labelList &size)
Constructors.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
dictionary dict
Generic dimensioned Type class.
static const char nl
Definition: Ostream.H:260
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
virtual void updateGrad()
Protected member functions.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define forAll(list, i)
Definition: UList.H:421
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
virtual void average()
Calculate the average.
Pre-declare SubField and related Field type.
Definition: Field.H:57
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Generic GeometricField class.
Traits class for primitives.
Definition: pTraits.H:50
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
virtual bool writeData(Ostream &) const
Dummy write.
const fvMesh & mesh_
The mesh on which the averaging is to be done.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Base class for lagrangian averaging methods.
Definition: MPPICParcel.H:55
label facePtA() const
Return face point A.
Definition: tetIndicesI.H:48
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
const dictionary & dict_
Protected data.
Storage and named access for the indices of a tet which is part of the decomposition of a cell...
Definition: tetIndices.H:73
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
virtual bool write() const
Write using setting from DB.
label facePtB() const
Return face point B.
Definition: tetIndicesI.H:54
word timeName
Definition: getTimeIndex.H:3
label face() const
Return the face.
Definition: tetIndicesI.H:36