wedgePolyPatch.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "wedgePolyPatch.H"
31 #include "SubField.H"
32 #include "transform.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(wedgePolyPatch, 0);
39 
42 }
43 
44 
45 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
46 
48 {
49  if (axis_ != vector::rootMax)
50  {
51  return;
52  }
53 
54  if (returnReduceOr(size()))
55  {
56  const vectorField& nf = faceNormals();
57  n_ = gAverage(nf);
58 
59  if (debug)
60  {
61  Info<< "Patch " << name() << " calculated average normal "
62  << n_ << endl;
63  }
64 
65 
66  // Check the wedge is planar
67  forAll(nf, facei)
68  {
69  if (magSqr(n_ - nf[facei]) > SMALL)
70  {
71  // only issue warning instead of error so that the case can
72  // still be read for post-processing
74  << "Wedge patch '" << name() << "' is not planar." << nl
75  << "At local face at "
76  << primitivePatch::faceCentres()[facei]
77  << " the normal " << nf[facei]
78  << " differs from the average normal " << n_
79  << " by " << magSqr(n_ - nf[facei]) << nl
80  << "Either correct the patch or split it into planar parts"
81  << endl;
82  }
83  }
84 
85  centreNormal_ =
86  vector
87  (
88  sign(n_.x())*(max(mag(n_.x()), 0.5) - 0.5),
89  sign(n_.y())*(max(mag(n_.y()), 0.5) - 0.5),
90  sign(n_.z())*(max(mag(n_.z()), 0.5) - 0.5)
91  );
92  centreNormal_.normalise();
93 
94  cosAngle_ = centreNormal_ & n_;
95 
96  const scalar cnCmptSum =
97  centreNormal_.x() + centreNormal_.y() + centreNormal_.z();
98 
99  if (mag(cnCmptSum) < (1 - SMALL))
100  {
102  << "wedge " << name()
103  << " centre plane does not align with a coordinate plane by "
104  << 1 - mag(cnCmptSum)
105  << exit(FatalError);
106  }
107 
108  axis_ = centreNormal_ ^ n_;
109  scalar magAxis = mag(axis_);
110 
111  if (magAxis < SMALL)
112  {
114  << "wedge " << name()
115  << " plane aligns with a coordinate plane." << nl
116  << " The wedge plane should make a small angle (~2.5deg)"
117  " with the coordinate plane" << nl
118  << " and the pair of wedge planes should be symmetric"
119  << " about the coordinate plane." << nl
120  << " Normal of wedge plane is " << n_
121  << " , implied coordinate plane direction is " << centreNormal_
122  << exit(FatalError);
123  }
124 
125  axis_ /= magAxis;
126 
127  faceT_ = rotationTensor(centreNormal_, n_);
128  cellT_ = faceT_ & faceT_;
129  }
130 }
131 
132 
133 // * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * * * //
134 
136 (
137  const word& name,
138  const label size,
139  const label start,
140  const label index,
141  const polyBoundaryMesh& bm,
142  const word& patchType
143 )
144 :
145  polyPatch(name, size, start, index, bm, patchType),
146  axis_(vector::rootMax),
147  centreNormal_(vector::rootMax),
148  n_(vector::rootMax),
149  cosAngle_(0.0),
150  faceT_(Zero),
151  cellT_(Zero)
152 {}
153 
154 
156 (
157  const word& name,
158  const dictionary& dict,
159  const label index,
160  const polyBoundaryMesh& bm,
161  const word& patchType
162 )
163 :
164  polyPatch(name, dict, index, bm, patchType),
165  axis_(vector::rootMax),
166  centreNormal_(vector::rootMax),
167  n_(vector::rootMax),
168  cosAngle_(0.0),
169  faceT_(Zero),
170  cellT_(Zero)
171 {}
172 
173 
175 (
176  const wedgePolyPatch& pp,
177  const polyBoundaryMesh& bm
178 )
179 :
180  polyPatch(pp, bm),
181  axis_(pp.axis_),
182  centreNormal_(pp.centreNormal_),
183  n_(pp.n_),
184  cosAngle_(pp.cosAngle_),
185  faceT_(pp.faceT_),
186  cellT_(pp.cellT_)
187 {}
188 
189 
191 (
192  const wedgePolyPatch& pp,
193  const polyBoundaryMesh& bm,
194  const label index,
195  const label newSize,
196  const label newStart
197 )
198 :
199  polyPatch(pp, bm, index, newSize, newStart),
200  axis_(pp.axis_),
201  centreNormal_(pp.centreNormal_),
202  n_(pp.n_),
203  cosAngle_(pp.cosAngle_),
204  faceT_(pp.faceT_),
205  cellT_(pp.cellT_)
206 {}
207 
208 
210 (
211  const wedgePolyPatch& pp,
212  const polyBoundaryMesh& bm,
213  const label index,
214  const labelUList& mapAddressing,
215  const label newStart
216 )
217 :
218  polyPatch(pp, bm, index, mapAddressing, newStart),
219  axis_(pp.axis_),
220  centreNormal_(pp.centreNormal_),
221  n_(pp.n_),
222  cosAngle_(pp.cosAngle_),
223  faceT_(pp.faceT_),
224  cellT_(pp.cellT_)
225 {}
226 
227 
228 // ************************************************************************* //
dimensionedScalar sign(const dimensionedScalar &ds)
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
Definition: transform.H:47
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
const Field< point_type > & faceNormals() const
Return face unit normals for patch.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
3D tensor transformation operations.
wedgePolyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType)
Construct from components.
const Field< point_type > & faceCentres() const
Return face centres for patch.
Wedge front and back plane patch.
Vector< scalar > vector
Definition: vector.H:57
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
const word & name() const noexcept
The patch name.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
Buffers for inter-processor communications streams (UOPstream, UIPstream).
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
#define WarningInFunction
Report a warning using Foam::Warning.
Type gAverage(const FieldField< Field, Type > &f)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Field< vector > vectorField
Specialisation of Field<T> for vector.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127