All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wedgePolyPatch.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) 2011-2018 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 "wedgePolyPatch.H"
28 #include "SubField.H"
29 #include "transform.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(wedgePolyPatch, 0);
36 
37  addToRunTimeSelectionTable(polyPatch, wedgePolyPatch, word);
38  addToRunTimeSelectionTable(polyPatch, wedgePolyPatch, dictionary);
39 }
40 
41 
42 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
43 
45 {
46  if (axis_ != vector::rootMax)
47  {
48  return;
49  }
50 
51  if (returnReduce(size(), sumOp<label>()))
52  {
53  const vectorField& nf(faceNormals());
54  n_ = gAverage(nf);
55 
56  if (debug)
57  {
58  Info<< "Patch " << name() << " calculated average normal "
59  << n_ << endl;
60  }
61 
62 
63  // Check the wedge is planar
64  forAll(nf, facei)
65  {
66  if (magSqr(n_ - nf[facei]) > small)
67  {
68  // only issue warning instead of error so that the case can
69  // still be read for post-processing
71  << "Wedge patch '" << name() << "' is not planar." << nl
72  << "At local face at "
73  << primitivePatch::faceCentres()[facei]
74  << " the normal " << nf[facei]
75  << " differs from the average normal " << n_
76  << " by " << magSqr(n_ - nf[facei]) << nl
77  << "Either correct the patch or split it into planar parts"
78  << endl;
79  }
80  }
81 
82  centreNormal_ =
83  vector
84  (
85  sign(n_.x())*(max(mag(n_.x()), 0.5) - 0.5),
86  sign(n_.y())*(max(mag(n_.y()), 0.5) - 0.5),
87  sign(n_.z())*(max(mag(n_.z()), 0.5) - 0.5)
88  );
89  centreNormal_ /= mag(centreNormal_);
90 
91  cosAngle_ = centreNormal_ & n_;
92 
93  const scalar cnCmptSum =
94  centreNormal_.x() + centreNormal_.y() + centreNormal_.z();
95 
96  if (mag(cnCmptSum) < (1 - small))
97  {
99  << "wedge " << name()
100  << " centre plane does not align with a coordinate plane by "
101  << 1 - mag(cnCmptSum)
102  << exit(FatalError);
103  }
104 
105  axis_ = centreNormal_ ^ n_;
106  scalar magAxis = mag(axis_);
107 
108  if (magAxis < small)
109  {
111  << "wedge " << name()
112  << " plane aligns with a coordinate plane." << nl
113  << " The wedge plane should make a small angle (~2.5deg)"
114  " with the coordinate plane" << nl
115  << " and the pair of wedge planes should be symmetric"
116  << " about the coordinate plane." << nl
117  << " Normal of wedge plane is " << n_
118  << " , implied coordinate plane direction is " << centreNormal_
119  << exit(FatalError);
120  }
121 
122  axis_ /= magAxis;
123 
124  faceT_ = rotationTensor(centreNormal_, n_);
125  cellT_ = faceT_ & faceT_;
126  }
127 }
128 
129 
130 // * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * * * //
131 
133 (
134  const word& name,
135  const label size,
136  const label start,
137  const label index,
138  const polyBoundaryMesh& bm,
139  const word& patchType
140 )
141 :
142  polyPatch(name, size, start, index, bm, patchType),
143  axis_(vector::rootMax),
144  centreNormal_(vector::rootMax),
145  n_(vector::rootMax),
146  cosAngle_(0.0),
147  faceT_(Zero),
148  cellT_(Zero)
149 {}
150 
151 
153 (
154  const word& name,
155  const dictionary& dict,
156  const label index,
157  const polyBoundaryMesh& bm,
158  const word& patchType
159 )
160 :
161  polyPatch(name, dict, index, bm, patchType),
162  axis_(vector::rootMax),
163  centreNormal_(vector::rootMax),
164  n_(vector::rootMax),
165  cosAngle_(0.0),
166  faceT_(Zero),
167  cellT_(Zero)
168 {}
169 
170 
172 (
173  const wedgePolyPatch& pp,
174  const polyBoundaryMesh& bm
175 )
176 :
177  polyPatch(pp, bm),
178  axis_(pp.axis_),
179  centreNormal_(pp.centreNormal_),
180  n_(pp.n_),
181  cosAngle_(pp.cosAngle_),
182  faceT_(pp.faceT_),
183  cellT_(pp.cellT_)
184 {}
185 
186 
188 (
189  const wedgePolyPatch& pp,
190  const polyBoundaryMesh& bm,
191  const label index,
192  const label newSize,
193  const label newStart
194 )
195 :
196  polyPatch(pp, bm, index, newSize, newStart),
197  axis_(pp.axis_),
198  centreNormal_(pp.centreNormal_),
199  n_(pp.n_),
200  cosAngle_(pp.cosAngle_),
201  faceT_(pp.faceT_),
202  cellT_(pp.cellT_)
203 {}
204 
205 
207 (
208  const wedgePolyPatch& pp,
209  const polyBoundaryMesh& bm,
210  const label index,
211  const labelUList& mapAddressing,
212  const label newStart
213 )
214 :
215  polyPatch(pp, bm, index, mapAddressing, newStart),
216  axis_(pp.axis_),
217  centreNormal_(pp.centreNormal_),
218  n_(pp.n_),
219  cosAngle_(pp.cosAngle_),
220  faceT_(pp.faceT_),
221  cellT_(pp.cellT_)
222 {}
223 
224 
225 // ************************************************************************* //
dimensionedScalar sign(const dimensionedScalar &ds)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
const Field< PointType > & faceCentres() const
Return face centres for patch.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from unit vector n1 to n2.
Definition: transform.H:47
Macros for easy insertion into run-time selection tables.
A class for handling words, derived from string.
Definition: word.H:59
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.
Wedge front and back plane patch.
static const zero Zero
Definition: zero.H:97
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Foam::polyBoundaryMesh.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(combustionModel, 0)
Buffers for inter-processor communications streams (UOPstream, UIPstream).
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
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
dimensioned< scalar > mag(const dimensioned< Type > &)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Namespace for OpenFOAM.