Moment.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 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 "Moment.H"
27 
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const IOobject& io,
35  const dictionary& dict,
36  const fvMesh& mesh
37 )
38 :
39  AveragingMethod<Type>(io, dict, mesh, labelList(4, mesh.nCells())),
44  transform_(mesh.nCells(), symmTensor::zero),
45  scale_(0.5*pow(mesh.V(), 1.0/3.0))
46 {
47  scalar a = 1.0/24.0;
48  scalar b = 0.5854101966249685;
49  scalar c = 0.1381966011250105;
50 
51  scalarField wQ(4);
52  wQ[0] = a;
53  wQ[1] = a;
54  wQ[2] = a;
55  wQ[3] = a;
56 
57  vectorField xQ(4);
58  xQ[0] = vector(b, c, c);
59  xQ[1] = vector(c, b, c);
60  xQ[2] = vector(c, c, b);
61  xQ[3] = vector(c, c, c);
62 
63  forAll(mesh.C(), cellI)
64  {
65  const List<tetIndices> cellTets =
66  polyMeshTetDecomposition::cellTetIndices(mesh, cellI);
67 
68  symmTensor A(symmTensor::zero);
69 
70  forAll(cellTets, tetI)
71  {
72  const tetIndices& tetIs = cellTets[tetI];
73  const label faceI = tetIs.face();
74  const face& f = mesh.faces()[faceI];
75 
76  const tensor T
77  (
78  tensor
79  (
80  mesh.points()[f[tetIs.faceBasePt()]] - mesh.C()[cellI],
81  mesh.points()[f[tetIs.facePtA()]] - mesh.C()[cellI],
82  mesh.points()[f[tetIs.facePtB()]] - mesh.C()[cellI]
83  ).T()
84  );
85 
86  const vectorField d((T & xQ)/scale_[cellI]);
87 
88  const scalar v(6.0*tetIs.tet(mesh).mag()/mesh.V()[cellI]);
89 
90  A += v*sum(wQ*sqr(d));
91  }
92 
93  transform_[cellI] = inv(A);
94  }
95 }
96 
97 
98 template<class Type>
100 (
101  const Moment<Type>& am
102 )
103 :
109  transform_(am.transform_)
110 {}
111 
112 
113 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
114 
115 template<class Type>
117 {}
118 
119 
120 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
121 
122 template<class Type>
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128 
129 template<class Type>
131 (
132  const point position,
133  const tetIndices& tetIs,
134  const Type& value
135 )
136 {
137  const label cellI = tetIs.cell();
138 
139  const Type v = value/this->mesh_.V()[cellI];
140  const TypeGrad dv =
141  transform_[cellI]
142  & (
143  v
144  * (position - this->mesh_.C()[cellI])
145  / scale_[cellI]
146  );
147 
148  data_[cellI] += v;
149  dataX_[cellI] += v + dv.x();
150  dataY_[cellI] += v + dv.y();
151  dataZ_[cellI] += v + dv.z();
152 }
153 
154 
155 template<class Type>
157 (
158  const point position,
159  const tetIndices& tetIs
160 ) const
161 {
162  const label cellI = tetIs.cell();
163 
164  return
165  data_[cellI]
166  + (
167  TypeGrad
168  (
169  dataX_[cellI] - data_[cellI],
170  dataY_[cellI] - data_[cellI],
171  dataZ_[cellI] - data_[cellI]
172  )
173  & (position - this->mesh_.C()[cellI])
174  / scale_[cellI]
175  );
176 }
177 
178 
179 template<class Type>
182 (
183  const point position,
184  const tetIndices& tetIs
185 ) const
186 {
187  const label cellI(tetIs.cell());
188 
189  return
190  TypeGrad
191  (
192  dataX_[cellI] - data_[cellI],
193  dataY_[cellI] - data_[cellI],
194  dataZ_[cellI] - data_[cellI]
195  )/scale_[cellI];
196 }
197 
198 
199 template<class Type>
202 {
203  return tmp<Field<Type> >(data_);
204 }
205 
206 
207 // ************************************************************************* //
Foam::AveragingMethod< Type >
Foam::Tensor
Templated 3D tensor derived from VectorSpace adding construction from 9 components,...
Definition: complexI.H:224
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::SymmTensor< scalar >
Foam::tetIndices::tet
tetPointRef tet(const polyMesh &mesh) const
Return the geometry corresponding to this tet from the.
Definition: tetIndicesI.H:66
Foam::FieldField
Generic field type.
Definition: FieldField.H:51
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::AveragingMethods::Moment::~Moment
virtual ~Moment()
Destructor.
Definition: Moment.C:116
Foam::AveragingMethods::Moment::internalField
tmp< Field< Type > > internalField() const
Return an internal field of the average.
Definition: Moment.C:201
Foam::AveragingMethods::Moment::transform_
Field< symmTensor > transform_
Transform tensor from moment to gradient.
Definition: Moment.H:90
A
simpleMatrix< scalar > A(Nc)
Foam::tetIndices::facePtB
label facePtB() const
Return face point B.
Definition: tetIndicesI.H:54
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:59
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:71
Foam::tetIndices::face
label face() const
Return the face.
Definition: tetIndicesI.H:36
Foam::AveragingMethods::Moment::add
void add(const point position, const tetIndices &tetIs, const Type &value)
Member Functions.
Definition: Moment.C:131
Foam::AveragingMethods::Moment::Moment
Moment(const IOobject &io, const dictionary &dict, const fvMesh &mesh)
Constructors.
Definition: Moment.C:33
Foam::AveragingMethods::Moment::interpolate
Type interpolate(const point position, const tetIndices &tetIs) const
Interpolate.
Definition: Moment.C:157
Foam::pow
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Definition: dimensionedScalar.C:73
Foam::tetIndices::faceBasePt
label faceBasePt() const
Return the face base point.
Definition: tetIndicesI.H:42
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Foam::tetIndices::cell
label cell() const
Return the cell.
Definition: tetIndicesI.H:30
Foam::tetIndices
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Definition: tetIndices.H:73
Foam::AveragingMethods::Moment
Moment lagrangian averaging procedure.
Definition: Moment.H:61
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
T
const volScalarField & T
Definition: createFields.H:25
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:333
Foam::tetIndices::facePtA
label facePtA() const
Return face point A.
Definition: tetIndicesI.H:48
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::tetrahedron::mag
scalar mag() const
Return volume.
Definition: tetrahedronI.H:171
Foam::AveragingMethods::Moment::TypeGrad
AveragingMethod< Type >::TypeGrad TypeGrad
Public typedefs.
Definition: Moment.H:70
Foam::AveragingMethods::Moment::interpolateGrad
TypeGrad interpolateGrad(const point position, const tetIndices &tetIs) const
Interpolate gradient.
Definition: Moment.C:182
Foam::AveragingMethods::Moment::updateGrad
virtual void updateGrad()
Private member functions.
Definition: Moment.C:123
Moment.H
Foam::Tensor::T
Tensor< Cmpt > T() const
Transpose.
Definition: TensorI.H:286