Dual.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2022 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 "Dual.H"
27 #include "coupledPointPatchField.H"
28 
29 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const fvMesh& mesh
35 )
36 {
37  autoPtr<labelList> s(new labelList(2));
38  s()[0] = mesh.nCells();
39  s()[1] = mesh.nPoints();
40  return s;
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
46 template<class Type>
48 (
49  const IOobject& io,
50  const dictionary& dict,
51  const fvMesh& mesh
52 )
53 :
54  AveragingMethod<Type>(io, dict, mesh, size(mesh)),
55  volumeCell_(mesh.V()),
56  volumeDual_(mesh.nPoints(), 0.0),
57  dataCell_(FieldField<Field, Type>::operator[](0)),
58  dataDual_(FieldField<Field, Type>::operator[](1))
59 {
60  forAll(this->mesh_.C(), celli)
61  {
62  List<tetIndices> cellTets =
63  polyMeshTetDecomposition::cellTetIndices(this->mesh_, celli);
64  forAll(cellTets, tetI)
65  {
66  const tetIndices& tetIs = cellTets[tetI];
67  const triFace triIs = tetIs.faceTriIs(this->mesh_);
68  const scalar v = tetIs.tet(this->mesh_).mag();
69  volumeDual_[triIs[0]] += v;
70  volumeDual_[triIs[1]] += v;
71  volumeDual_[triIs[2]] += v;
72  }
73  }
74 
75  mesh.globalData().syncPointData
76  (
77  volumeDual_,
80  );
81 }
82 
83 
84 template<class Type>
86 (
87  const Dual<Type>& am
88 )
89 :
91  volumeCell_(am.volumeCell_),
92  volumeDual_(am.volumeDual_),
93  dataCell_(FieldField<Field, Type>::operator[](0)),
94  dataDual_(FieldField<Field, Type>::operator[](1))
95 {}
96 
97 
98 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
99 
100 template<class Type>
102 {}
103 
104 
105 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
106 
107 template<class Type>
109 {
110  this->mesh_.globalData().syncPointData
111  (
112  dataDual_,
113  plusEqOp<Type>(),
115  );
116 }
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
121 template<class Type>
123 (
124  const barycentric& coordinates,
125  const tetIndices& tetIs,
126  const Type& value
127 )
128 {
129  const triFace triIs(tetIs.faceTriIs(this->mesh_));
130 
131  dataCell_[tetIs.cell()] +=
132  coordinates[0]*value
133  / (0.25*volumeCell_[tetIs.cell()]);
134 
135  for(label i = 0; i < 3; i ++)
136  {
137  dataDual_[triIs[i]] +=
138  coordinates[i+1]*value
139  / (0.25*volumeDual_[triIs[i]]);
140  }
141 }
142 
143 
144 template<class Type>
146 (
147  const barycentric& coordinates,
148  const tetIndices& tetIs
149 ) const
150 {
151  const triFace triIs(tetIs.faceTriIs(this->mesh_));
152 
153  return
154  coordinates[0]*dataCell_[tetIs.cell()]
155  + coordinates[1]*dataDual_[triIs[0]]
156  + coordinates[2]*dataDual_[triIs[1]]
157  + coordinates[3]*dataDual_[triIs[2]];
158 }
159 
160 
161 template<class Type>
164 (
165  const barycentric& coordinates,
166  const tetIndices& tetIs
167 ) const
168 {
169  const triFace triIs(tetIs.faceTriIs(this->mesh_));
170 
171  const label celli(tetIs.cell());
172 
173  const tensor T
174  (
175  inv
176  (
177  tensor
178  (
179  this->mesh_.points()[triIs[0]] - this->mesh_.C()[celli],
180  this->mesh_.points()[triIs[1]] - this->mesh_.C()[celli],
181  this->mesh_.points()[triIs[2]] - this->mesh_.C()[celli]
182  )
183  )
184  );
185 
186  const vector t( - T.T().x() - T.T().y() - T.T().z());
187 
188  const TypeGrad S
189  (
190  dataDual_[triIs[0]],
191  dataDual_[triIs[1]],
192  dataDual_[triIs[2]]
193  );
194 
195  const Type s(dataCell_[celli]);
196 
197  return (T & S) + (t*s);
198 }
199 
200 
201 template<class Type>
203 {
204  syncDualData();
205 
207 }
208 
209 
210 template<class Type>
212 (
213  const AveragingMethod<scalar>& weight
214 )
215 {
216  syncDualData();
217 
219 }
220 
221 
222 template<class Type>
225 {
226  return tmp<Field<Type>>(dataCell_);
227 }
228 
229 
230 // ************************************************************************* //
tmp< Field< Type > > primitiveField() const
Return an internal field of the average.
Definition: Dual.C:224
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Type interpolate(const barycentric &coordinates, const tetIndices &tetIs) const
Interpolate.
Definition: Dual.C:146
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
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
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Default transformation behaviour.
outerProduct< vector, Type >::type TypeGrad
Protected typedefs.
Dual(const IOobject &io, const dictionary &dict, const fvMesh &mesh)
Constructors.
Definition: Dual.C:48
triFace faceTriIs(const polyMesh &mesh) const
Return the indices corresponding to the tri on the face for.
Definition: tetIndicesI.H:67
fvMesh & mesh
tetPointRef tet(const polyMesh &mesh) const
Return the geometry corresponding to this tet.
Definition: tetIndicesI.H:108
TypeGrad interpolateGrad(const barycentric &coordinates, const tetIndices &tetIs) const
Interpolate gradient.
Definition: Dual.C:164
Generic field type.
Definition: FieldField.H:51
virtual ~Dual()
Destructor.
Definition: Dual.C:101
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
tmp< fvMatrix< Type > > S(const Pair< tmp< volScalarField::Internal >> &, const GeometricField< Type, fvPatchField, volMesh > &)
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:68
label cell() const
Return the cell.
Definition: tetIndicesI.H:31
scalar mag() const
Return volume.
Definition: tetrahedronI.H:170
Base class for lagrangian averaging methods.
Definition: MPPICParcel.H:55
List< label > labelList
A List of labels.
Definition: labelList.H:56
Storage and named access for the indices of a tet which is part of the decomposition of a cell...
Definition: tetIndices.H:81
Dual-mesh lagrangian averaging procedure.
Definition: Dual.H:64
AveragingMethod< Type >::TypeGrad TypeGrad
Gradient type.
Definition: Dual.H:73
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
const volScalarField & T
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
tmp< GeometricField< Type, fvPatchField, volMesh > > average(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Area-weighted average a surfaceField creating a volField.
Definition: fvcAverage.C:46
void average()
Calculate the average.
Definition: Dual.C:202
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
A class for managing temporary objects.
Definition: PtrList.H:53
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
void add(const barycentric &coordinates, const tetIndices &tetIs, const Type &value)
Member Functions.
Definition: Dual.C:123