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-------------------------------------------------------------------------------
10License
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
35namespace Foam
36{
38
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 "
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
const Field< point_type > & faceNormals() const
Return face unit normals for patch.
const Field< point_type > & faceCentres() const
Return face centres for patch.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
void calcGeometry()
Calculate the geometry for the patches.
static const complex rootMax
complex (ROOTVGREAT, ROOTVGREAT)
Definition: complex.H:295
const word & name() const noexcept
The patch name.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
Wedge front and back plane patch.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dimensionedScalar sign(const dimensionedScalar &ds)
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
Definition: transform.H:51
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Type gAverage(const FieldField< Field, Type > &f)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
Vector< scalar > vector
Definition: vector.H:61
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
3D tensor transformation operations.