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-2014 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
69  WarningIn
70  (
71  "wedgePolyPatch::calcGeometry(PstreamBuffers&)"
72  )
73  << "Wedge patch '" << name() << "' is not planar." << nl
74  << "At local face at "
75  << primitivePatch::faceCentres()[faceI]
76  << " the normal " << nf[faceI]
77  << " differs from the average normal " << n_
78  << " by " << magSqr(n_ - nf[faceI]) << nl
79  << "Either correct the patch or split it into planar parts"
80  << endl;
81  }
82  }
83 
84  centreNormal_ =
85  vector
86  (
87  sign(n_.x())*(max(mag(n_.x()), 0.5) - 0.5),
88  sign(n_.y())*(max(mag(n_.y()), 0.5) - 0.5),
89  sign(n_.z())*(max(mag(n_.z()), 0.5) - 0.5)
90  );
91  centreNormal_ /= mag(centreNormal_);
92 
93  cosAngle_ = centreNormal_ & n_;
94 
95  const scalar cnCmptSum =
96  centreNormal_.x() + centreNormal_.y() + centreNormal_.z();
97 
98  if (mag(cnCmptSum) < (1 - SMALL))
99  {
100  FatalErrorIn("wedgePolyPatch::calcGeometry(PstreamBuffers&)")
101  << "wedge " << name()
102  << " centre plane does not align with a coordinate plane by "
103  << 1 - mag(cnCmptSum)
104  << exit(FatalError);
105  }
106 
107  axis_ = centreNormal_ ^ n_;
108  scalar magAxis = mag(axis_);
109 
110  if (magAxis < SMALL)
111  {
112  FatalErrorIn("wedgePolyPatch::calcGeometry(PstreamBuffers&)")
113  << "wedge " << name()
114  << " plane aligns with a coordinate plane." << nl
115  << " The wedge plane should make a small angle (~2.5deg)"
116  " with the coordinate plane" << nl
117  << " and the the pair of wedge planes should be symmetric"
118  << " about the coordinate plane." << nl
119  << " Normal of wedge plane is " << n_
120  << " , implied coordinate plane direction is " << centreNormal_
121  << exit(FatalError);
122  }
123 
124  axis_ /= magAxis;
125 
126  faceT_ = rotationTensor(centreNormal_, n_);
127  cellT_ = faceT_ & faceT_;
128  }
129 }
130 
131 
132 // * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * * * //
133 
135 (
136  const word& name,
137  const label size,
138  const label start,
139  const label index,
140  const polyBoundaryMesh& bm,
141  const word& patchType
142 )
143 :
144  polyPatch(name, size, start, index, bm, patchType),
145  axis_(vector::rootMax),
146  centreNormal_(vector::rootMax),
147  n_(vector::rootMax),
148  cosAngle_(0.0),
149  faceT_(tensor::zero),
150  cellT_(tensor::zero)
151 {}
152 
153 
155 (
156  const word& name,
157  const dictionary& dict,
158  const label index,
159  const polyBoundaryMesh& bm,
160  const word& patchType
161 )
162 :
163  polyPatch(name, dict, index, bm, patchType),
164  axis_(vector::rootMax),
165  centreNormal_(vector::rootMax),
166  n_(vector::rootMax),
167  cosAngle_(0.0),
168  faceT_(tensor::zero),
169  cellT_(tensor::zero)
170 {}
171 
172 
174 (
175  const wedgePolyPatch& pp,
176  const polyBoundaryMesh& bm
177 )
178 :
179  polyPatch(pp, bm),
180  axis_(pp.axis_),
181  centreNormal_(pp.centreNormal_),
182  n_(pp.n_),
183  cosAngle_(pp.cosAngle_),
184  faceT_(pp.faceT_),
185  cellT_(pp.cellT_)
186 {}
187 
188 
190 (
191  const wedgePolyPatch& pp,
192  const polyBoundaryMesh& bm,
193  const label index,
194  const label newSize,
195  const label newStart
196 )
197 :
198  polyPatch(pp, bm, index, newSize, newStart),
199  axis_(pp.axis_),
200  centreNormal_(pp.centreNormal_),
201  n_(pp.n_),
202  cosAngle_(pp.cosAngle_),
203  faceT_(pp.faceT_),
204  cellT_(pp.cellT_)
205 {}
206 
207 
209 (
210  const wedgePolyPatch& pp,
211  const polyBoundaryMesh& bm,
212  const label index,
213  const labelUList& mapAddressing,
214  const label newStart
215 )
216 :
217  polyPatch(pp, bm, index, mapAddressing, newStart),
218  axis_(pp.axis_),
219  centreNormal_(pp.centreNormal_),
220  n_(pp.n_),
221  cosAngle_(pp.cosAngle_),
222  faceT_(pp.faceT_),
223  cellT_(pp.cellT_)
224 {}
225 
226 
227 // ************************************************************************* //
Buffers for inter-processor communications streams (UOPstream, UIPstream).
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
dimensioned< scalar > mag(const dimensioned< Type > &)
Wedge front and back plane patch.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dimensioned< scalar > magSqr(const dimensioned< Type > &)
static const Tensor zero
Definition: Tensor.H:80
A class for handling words, derived from string.
Definition: word.H:59
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
dimensionedScalar sign(const dimensionedScalar &ds)
static const Vector rootMax
Definition: Vector.H:84
messageStream Info
wedgePolyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType)
Construct from components.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
static const char nl
Definition: Ostream.H:260
const Field< PointType > & faceCentres() const
Return face centres for patch.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Foam::polyBoundaryMesh.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define forAll(list, i)
Definition: UList.H:421
Macros for easy insertion into run-time selection tables.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError
Type gAverage(const FieldField< Field, Type > &f)
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
3D tensor transformation operations.
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
tensor rotationTensor(const vector &n1, const vector &n2)
Definition: transform.H:46
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)