patchTransformedInterpolation.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) 2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 
28 #include "pointFields.H"
29 #include "symmTensor2D.H"
30 #include "tensor2D.H"
31 #include "syncTools.H"
32 #include "volPointInterpolation.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(patchTransformedInterpolation, 0);
39 
41  (
42  motionInterpolation,
43  patchTransformedInterpolation,
44  Istream
45  );
46 }
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
51 (
52  Istream& entry
53 ) const
54 {
56 
57  labelList patches(patchNames.size(), -1);
58 
59  forAll(patchNames, patchI)
60  {
61  patches[patchI] =
62  mesh().boundaryMesh().findPatchID
63  (
64  patchNames[patchI]
65  );
66 
67  if (patches[patchI] == -1)
68  {
70  << "patch \"" << patchNames[patchI]
71  << "\" not found" << exit(FatalError);
72  }
73  }
74 
75  return patches;
76 }
77 
78 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
79 
81 (
82  const fvMesh& mesh,
83  Istream& entry
84 )
85 :
87  patches_(getPatches(entry))
88 {}
89 
90 
91 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
92 
94 {}
95 
96 
97 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
98 
100 (
101  const volScalarField&,
103 ) const
104 {
106 }
107 
108 
110 (
111  const volVectorField& cellDisplacement,
112  pointVectorField& pointDisplacement
113 ) const
114 {
115  const pointField& points(mesh().points());
116  const label nPoints(points.size());
117 
119  (
120  cellDisplacement,
121  pointDisplacement
122  );
123 
124  pointDisplacement.correctBoundaryConditions();
125 
126  vectorField pointRotation(nPoints, vector::zero);
127  scalarField pointExpansion(nPoints, scalar(0));
128 
129  labelList pointDisplacementNSum(nPoints, 0);
130  vectorField pointDisplacementSum(nPoints, vector::zero);
131 
132  forAll(patches_, patchI)
133  {
134  const polyPatch& patch(mesh().boundaryMesh()[patches_[patchI]]);
135 
136  forAll(patch, pFaceI)
137  {
138  const face& f(patch[pFaceI]);
139 
140  const label cellI(patch.faceCells()[pFaceI]);
141  const cell& c(mesh().cells()[cellI]);
142  const labelList cPoints(c.labels(mesh().faces()));
143 
144  // Consider movement around the face centre
145  const point& xOrigin(patch.faceCentres()[pFaceI]);
146 
147  // Mean translation
148  const vector uMean(f.average(points, pointDisplacement));
149 
150  // Calculate rotation and expansion for each point
151  forAll(f, fPointI)
152  {
153  const label pointI(f[fPointI]);
154  const vector& x(points[pointI]);
155  const vector r(x - xOrigin);
156  const vector u(pointDisplacement[pointI] - uMean);
157 
158  pointRotation[pointI] = 2*(r ^ u)/magSqr(r);
159  pointExpansion[pointI] = (r & u)/magSqr(r);
160  }
161 
162  // Mean rotation and expansion
163  const vector omegaMean(f.average(points, pointRotation));
164  const scalar divMean(f.average(points, pointExpansion));
165 
166  // Apply mean solid body motion to all cell points
167  forAll(cPoints, cPointI)
168  {
169  const label pointI(cPoints[cPointI]);
170  const vector& x(points[pointI]);
171  const vector r(x - xOrigin);
172 
173  pointDisplacementNSum[pointI] += 1;
174  pointDisplacementSum[pointI] +=
175  uMean + (omegaMean ^ r) + (divMean*r);
176  }
177  }
178  }
179 
181  (
182  mesh(),
183  pointDisplacementNSum,
184  plusEqOp<label>(),
185  label(0)
186  );
187 
189  (
190  mesh(),
191  pointDisplacementSum,
194  );
195 
196  forAll(points, pointI)
197  {
198  if (pointDisplacementNSum[pointI])
199  {
200  pointDisplacement[pointI] =
201  pointDisplacementSum[pointI]/pointDisplacementNSum[pointI];
202  }
203  }
204 
205  // Correct the faces
206  pointDisplacement.correctBoundaryConditions();
207 }
208 
209 
210 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:65
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
symmTensor2D.H
Foam::patchTransformedInterpolation::patchTransformedInterpolation
patchTransformedInterpolation(const fvMesh &mesh, Istream &entry)
Construct from an fvMesh and an Istream.
Definition: patchTransformedInterpolation.C:81
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
tensor2D.H
syncTools.H
Foam::MeshObject< fvMesh, UpdateableMeshObject, volPointInterpolation >::New
static const volPointInterpolation & New(const fvMesh &mesh)
Definition: MeshObject.C:44
Foam::patchTransformedInterpolation::~patchTransformedInterpolation
virtual ~patchTransformedInterpolation()
Destructor.
Definition: patchTransformedInterpolation.C:93
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:365
patchTransformedInterpolation.H
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::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
patchNames
wordList patchNames(nPatches)
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::plusEqOp
Definition: ops.H:71
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::polyPatch::faceCells
const labelUList & faceCells() const
Return face-cell addressing.
Definition: polyPatch.C:340
Foam::patchTransformedInterpolation::interpolate
virtual void interpolate(const volScalarField &, pointScalarField &) const
Interpolate the given scalar cell displacement.
Definition: patchTransformedInterpolation.C:100
Foam::volPointInterpolation::interpolate
tmp< GeometricField< Type, pointPatchField, pointMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &) const
Interpolate volField using inverse distance weighting.
Definition: volPointInterpolate.C:502
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::patchTransformedInterpolation::getPatches
labelList getPatches(Istream &entry) const
Get patches from the input stream.
Definition: patchTransformedInterpolation.C:51
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:885
volPointInterpolation.H
Foam::motionInterpolation
Base class for interpolation of cell displacement fields, generated by fvMotionSolvers,...
Definition: motionInterpolation.H:50
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::polyPatch::faceCentres
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:308
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
points
const pointField & points
Definition: gmvOutputHeader.H:1
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:59
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
pointFields.H
Foam::syncTools::syncPointList
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
Definition: syncToolsTemplates.C:984