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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "wedgePolyPatch.H"
30 #include "SubField.H"
31 #include "transform.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(wedgePolyPatch, 0);
38 
39  addToRunTimeSelectionTable(polyPatch, wedgePolyPatch, word);
40  addToRunTimeSelectionTable(polyPatch, wedgePolyPatch, dictionary);
41 }
42 
43 
44 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
45 
47 {
48  if (axis_ != vector::rootMax)
49  {
50  return;
51  }
52 
53  if (returnReduce(size(), sumOp<label>()))
54  {
55  const vectorField& nf(faceNormals());
56  n_ = gAverage(nf);
57 
58  if (debug)
59  {
60  Info<< "Patch " << name() << " calculated average normal "
61  << n_ << endl;
62  }
63 
64 
65  // Check the wedge is planar
66  forAll(nf, facei)
67  {
68  if (magSqr(n_ - nf[facei]) > SMALL)
69  {
70  // only issue warning instead of error so that the case can
71  // still be read for post-processing
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_.normalise();
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  {
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  {
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 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_(Zero),
150  cellT_(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_(Zero),
169  cellT_(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 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::rootMax
static const Vector< scalar > rootMax
Definition: VectorSpace.H:119
Foam::wedgePolyPatch::calcGeometry
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
Definition: wedgePolyPatch.C:46
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
SubField.H
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::wedgePolyPatch
Wedge front and back plane patch.
Definition: wedgePolyPatch.H:50
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::gAverage
Type gAverage(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:604
wedgePolyPatch.H
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:88
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Vector::normalise
Vector< Cmpt > & normalise()
Normalise the vector by its magnitude.
Definition: VectorI.H:123
Foam::sign
dimensionedScalar sign(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:166
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::UList< label >
Foam::PrimitivePatch::faceNormals
const Field< point_type > & faceNormals() const
Return face unit normals for patch.
Definition: PrimitivePatch.C:445
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::patchIdentifier::name
const word & name() const noexcept
The patch name.
Definition: patchIdentifier.H:135
Foam::wedgePolyPatch::wedgePolyPatch
wedgePolyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType)
Construct from components.
Definition: wedgePolyPatch.C:135
transform.H
3D tensor transformation operations.
Foam::rotationTensor
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
Definition: transform.H:51
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::PrimitivePatch::faceCentres
const Field< point_type > & faceCentres() const
Return face centres for patch.
Definition: PrimitivePatch.C:400