Dual.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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "Dual.H"
29 #include "coupledPointPatchField.H"
30 
31 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
32 
33 template<class Type>
35 {
36  labelList sizes(2);
37  sizes[0] = mesh.nCells();
38  sizes[1] = mesh.nPoints();
39  return sizes;
40 }
41 
42 
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 
45 template<class Type>
47 (
48  const IOobject& io,
49  const dictionary& dict,
50  const fvMesh& mesh
51 )
52 :
53  AveragingMethod<Type>(io, dict, mesh, sizing(mesh)),
54  volumeCell_(mesh.V()),
55  volumeDual_(mesh.nPoints(), Zero),
56  dataCell_(FieldField<Field, Type>::operator[](0)),
57  dataDual_(FieldField<Field, Type>::operator[](1))
58 {
59  forAll(this->mesh_.C(), celli)
60  {
61  List<tetIndices> cellTets =
62  polyMeshTetDecomposition::cellTetIndices(this->mesh_, celli);
63  forAll(cellTets, tetI)
64  {
65  const tetIndices& tetIs = cellTets[tetI];
66  const triFace triIs = tetIs.faceTriIs(this->mesh_);
67  const scalar v = tetIs.tet(this->mesh_).mag();
68  volumeDual_[triIs[0]] += v;
69  volumeDual_[triIs[1]] += v;
70  volumeDual_[triIs[2]] += v;
71  }
72  }
73 
74  mesh.globalData().syncPointData
75  (
76  volumeDual_,
79  );
80 }
81 
82 
83 template<class Type>
85 (
86  const Dual<Type>& am
87 )
88 :
90  volumeCell_(am.volumeCell_),
91  volumeDual_(am.volumeDual_),
92  dataCell_(FieldField<Field, Type>::operator[](0)),
93  dataDual_(FieldField<Field, Type>::operator[](1))
94 {}
95 
96 
97 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
98 
99 template<class Type>
101 {
102  this->mesh_.globalData().syncPointData
103  (
104  dataDual_,
105  plusEqOp<Type>(),
107  );
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
112 
113 template<class Type>
115 (
116  const barycentric& coordinates,
117  const tetIndices& tetIs,
118  const Type& value
119 )
120 {
121  const triFace triIs(tetIs.faceTriIs(this->mesh_));
122 
123  dataCell_[tetIs.cell()] +=
124  coordinates[0]*value
125  / (0.25*volumeCell_[tetIs.cell()]);
126 
127  for (label i = 0; i < 3; ++i)
128  {
129  dataDual_[triIs[i]] +=
130  coordinates[i+1]*value
131  / (0.25*volumeDual_[triIs[i]]);
132  }
133 }
134 
135 
136 template<class Type>
138 (
139  const barycentric& coordinates,
140  const tetIndices& tetIs
141 ) const
142 {
143  const triFace triIs(tetIs.faceTriIs(this->mesh_));
144 
145  return
146  coordinates[0]*dataCell_[tetIs.cell()]
147  + coordinates[1]*dataDual_[triIs[0]]
148  + coordinates[2]*dataDual_[triIs[1]]
149  + coordinates[3]*dataDual_[triIs[2]];
150 }
151 
152 
153 template<class Type>
156 (
157  const barycentric& coordinates,
158  const tetIndices& tetIs
159 ) const
160 {
161  const triFace triIs(tetIs.faceTriIs(this->mesh_));
162 
163  const label celli(tetIs.cell());
164 
165  const tensor T
166  (
167  inv
168  (
169  tensor
170  (
171  this->mesh_.points()[triIs[0]] - this->mesh_.C()[celli],
172  this->mesh_.points()[triIs[1]] - this->mesh_.C()[celli],
173  this->mesh_.points()[triIs[2]] - this->mesh_.C()[celli]
174  )
175  )
176  );
177 
178  const vector t( - T.T().x() - T.T().y() - T.T().z());
179 
180  const TypeGrad S
181  (
182  dataDual_[triIs[0]],
183  dataDual_[triIs[1]],
184  dataDual_[triIs[2]]
185  );
186 
187  const Type s(dataCell_[celli]);
188 
189  return (T & S) + (t*s);
190 }
191 
192 
193 template<class Type>
195 {
196  syncDualData();
197 
199 }
200 
201 
202 template<class Type>
204 (
205  const AveragingMethod<scalar>& weight
206 )
207 {
208  syncDualData();
209 
211 }
212 
213 
214 template<class Type>
217 {
218  return tmp<Field<Type>>(dataCell_);
219 }
220 
221 
222 // ************************************************************************* //
Foam::AveragingMethod
Base class for lagrangian averaging methods.
Definition: KinematicParcel.H:69
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::Tensor< scalar >
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::tetIndices::tet
tetPointRef tet(const polyMesh &mesh) const
Return the geometry corresponding to this tet.
Definition: tetIndicesI.H:155
coupledPointPatchField.H
Foam::FieldField
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:53
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
Definition: gmvOutputSpray.H:25
Foam::tetIndices::cell
label cell() const
Return the cell.
Definition: tetIndicesI.H:31
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Dual.H
Foam::AveragingMethods::Dual::TypeGrad
AveragingMethod< Type >::TypeGrad TypeGrad
Public typedefs.
Definition: Dual.H:78
Foam::AveragingMethods::Dual::add
void add(const barycentric &coordinates, const tetIndices &tetIs, const Type &value)
Member Functions.
Definition: Dual.C:115
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::fac::average
tmp< GeometricField< Type, faPatchField, areaMesh > > average(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Area-weighted average a edgeField creating a areaField.
Definition: facAverage.C:47
Foam::inv
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:73
Foam::AveragingMethods::Dual::primitiveField
tmp< Field< Type > > primitiveField() const
Return an internal field of the average.
Definition: Dual.C:216
coordinates
PtrList< coordinateSystem > coordinates(solidRegions.size())
Foam::Barycentric< scalar >
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:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::AveragingMethods::Dual::Dual
Dual(const IOobject &io, const dictionary &dict, const fvMesh &mesh)
Constructors.
Definition: Dual.C:47
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:68
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::AveragingMethods::Dual::interpolate
Type interpolate(const barycentric &coordinates, const tetIndices &tetIs) const
Interpolate.
Definition: Dual.C:138
Foam::AveragingMethods::Dual::interpolateGrad
TypeGrad interpolateGrad(const barycentric &coordinates, const tetIndices &tetIs) const
Interpolate gradient.
Definition: Dual.C:156
Foam::mapDistribute::transform
Default transformation behaviour.
Definition: mapDistribute.H:209
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::triFace
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:69
Foam::Vector< scalar >
Foam::List< label >
Foam::AveragingMethods::Dual
Dual-mesh lagrangian averaging procedure.
Definition: Dual.H:69
Foam::AveragingMethods::Dual::average
void average()
Calculate the average.
Definition: Dual.C:194
Foam::plusEqOp
Definition: ops.H:72
Foam::tetrahedron::mag
scalar mag() const
Return volume.
Definition: tetrahedronI.H:172
Foam::AveragingMethod::TypeGrad
outerProduct< vector, Type >::type TypeGrad
Protected typedefs.
Definition: AveragingMethod.H:68