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 | Copyright (C) 2011-2016 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 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
42 
44 {
45  if (axis_ != vector::rootMax)
46  {
47  return;
48  }
49 
50  if (returnReduce(size(), sumOp<label>()))
51  {
52  const vectorField& nf(faceNormals());
53  n_ = gAverage(nf);
54 
55  if (debug)
56  {
57  Info<< "Patch " << name() << " calculated average normal "
58  << n_ << endl;
59  }
60 
61 
62  // Check the wedge is planar
63  forAll(nf, facei)
64  {
65  if (magSqr(n_ - nf[facei]) > SMALL)
66  {
67  // only issue warning instead of error so that the case can
68  // still be read for post-processing
70  << "Wedge patch '" << name() << "' is not planar." << nl
71  << "At local face at "
72  << primitivePatch::faceCentres()[facei]
73  << " the normal " << nf[facei]
74  << " differs from the average normal " << n_
75  << " by " << magSqr(n_ - nf[facei]) << nl
76  << "Either correct the patch or split it into planar parts"
77  << endl;
78  }
79  }
80 
81  centreNormal_ =
82  vector
83  (
84  sign(n_.x())*(max(mag(n_.x()), 0.5) - 0.5),
85  sign(n_.y())*(max(mag(n_.y()), 0.5) - 0.5),
86  sign(n_.z())*(max(mag(n_.z()), 0.5) - 0.5)
87  );
88  centreNormal_ /= mag(centreNormal_);
89 
90  cosAngle_ = centreNormal_ & n_;
91 
92  const scalar cnCmptSum =
93  centreNormal_.x() + centreNormal_.y() + centreNormal_.z();
94 
95  if (mag(cnCmptSum) < (1 - SMALL))
96  {
98  << "wedge " << name()
99  << " centre plane does not align with a coordinate plane by "
100  << 1 - mag(cnCmptSum)
101  << exit(FatalError);
102  }
103 
104  axis_ = centreNormal_ ^ n_;
105  scalar magAxis = mag(axis_);
106 
107  if (magAxis < SMALL)
108  {
110  << "wedge " << name()
111  << " plane aligns with a coordinate plane." << nl
112  << " The wedge plane should make a small angle (~2.5deg)"
113  " with the coordinate plane" << nl
114  << " and the the pair of wedge planes should be symmetric"
115  << " about the coordinate plane." << nl
116  << " Normal of wedge plane is " << n_
117  << " , implied coordinate plane direction is " << centreNormal_
118  << exit(FatalError);
119  }
120 
121  axis_ /= magAxis;
122 
123  faceT_ = rotationTensor(centreNormal_, n_);
124  cellT_ = faceT_ & faceT_;
125  }
126 }
127 
128 
129 // * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * * * //
130 
132 (
133  const word& name,
134  const label size,
135  const label start,
136  const label index,
137  const polyBoundaryMesh& bm,
138  const word& patchType
139 )
140 :
141  polyPatch(name, size, start, index, bm, patchType),
142  axis_(vector::rootMax),
143  centreNormal_(vector::rootMax),
144  n_(vector::rootMax),
145  cosAngle_(0.0),
146  faceT_(Zero),
147  cellT_(Zero)
148 {}
149 
150 
152 (
153  const word& name,
154  const dictionary& dict,
155  const label index,
156  const polyBoundaryMesh& bm,
157  const word& patchType
158 )
159 :
160  polyPatch(name, dict, index, bm, patchType),
161  axis_(vector::rootMax),
162  centreNormal_(vector::rootMax),
163  n_(vector::rootMax),
164  cosAngle_(0.0),
165  faceT_(Zero),
166  cellT_(Zero)
167 {}
168 
169 
171 (
172  const wedgePolyPatch& pp,
173  const polyBoundaryMesh& bm
174 )
175 :
176  polyPatch(pp, bm),
177  axis_(pp.axis_),
178  centreNormal_(pp.centreNormal_),
179  n_(pp.n_),
180  cosAngle_(pp.cosAngle_),
181  faceT_(pp.faceT_),
182  cellT_(pp.cellT_)
183 {}
184 
185 
187 (
188  const wedgePolyPatch& pp,
189  const polyBoundaryMesh& bm,
190  const label index,
191  const label newSize,
192  const label newStart
193 )
194 :
195  polyPatch(pp, bm, index, newSize, newStart),
196  axis_(pp.axis_),
197  centreNormal_(pp.centreNormal_),
198  n_(pp.n_),
199  cosAngle_(pp.cosAngle_),
200  faceT_(pp.faceT_),
201  cellT_(pp.cellT_)
202 {}
203 
204 
206 (
207  const wedgePolyPatch& pp,
208  const polyBoundaryMesh& bm,
209  const label index,
210  const labelUList& mapAddressing,
211  const label newStart
212 )
213 :
214  polyPatch(pp, bm, index, mapAddressing, newStart),
215  axis_(pp.axis_),
216  centreNormal_(pp.centreNormal_),
217  n_(pp.n_),
218  cosAngle_(pp.cosAngle_),
219  faceT_(pp.faceT_),
220  cellT_(pp.cellT_)
221 {}
222 
223 
224 // ************************************************************************* //
dimensionedScalar sign(const dimensionedScalar &ds)
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
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:137
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
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 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:91
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:262
defineTypeNameAndDebug(combustionModel, 0)
const Field< PointType > & faceCentres() const
Return face centres for patch.
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.