symmetryPlanePolyPatch.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) 2013-2024 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 "symmetryPlanePolyPatch.H"
28 #include "RemoteData.H"
29 #include "Tuple3.H"
30 #include "symmetryPolyPatch.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
37 
40 }
41 
42 
43 // * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
44 
46 {
47  if (n_ != vector::rootMax)
48  {
49  return;
50  }
51 
52  if (!returnReduce(size(), sumOp<label>()))
53  {
54  return;
55  }
56 
58  const vectorField& nf(faceNormals());
59  n_ = gAverage(nf);
60 
61  if (debug)
62  {
63  Info<< "Patch " << name() << " calculated average normal "
64  << n_ << endl;
65  }
66 
67  // Get the largest variation from the average normal
69  if (size())
70  {
71  const scalarField deltaNSqr(magSqr(n_ - nf));
72  const label i = findMax(deltaNSqr);
73  maxDeltaN = {Pstream::myProcNo(), i, {deltaNSqr[i], cf[i], nf[i]}};
74  }
76  (
77  maxDeltaN,
78  RemoteData<Tuple3<scalar, vector, vector>>::greatestFirstEqOp()
79  );
80 
81  // Fail if the symmetry plane is not planar
82  if (maxDeltaN.data.first() > small)
83  {
84  Ostream& fos =
86  << "Symmetry plane '" << name()
87  << "' is not planar" << endl;
88 
89  fos << "At patch face #" << maxDeltaN.elementi;
90 
91  if (Pstream::parRun())
92  {
93  fos << " on processor #" << maxDeltaN.proci;
94  }
95 
96  fos << " with centre " << maxDeltaN.data.second()
97  << " the normal " << maxDeltaN.data.third()
98  << " differs from the average normal " << n_
99  << " by " << maxDeltaN.data.first() << nl
100  << "Either split the patch into planar parts or use the "
101  << symmetryPolyPatch::typeName << " patch type"
102  << exit(FatalError);
103  }
104 }
105 
106 
107 // * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * * * //
108 
110 (
111  const word& name,
112  const label size,
113  const label start,
114  const label index,
115  const polyBoundaryMesh& bm,
116  const word& patchType
117 )
118 :
119  polyPatch(name, size, start, index, bm, patchType),
120  n_(vector::rootMax)
121 {}
122 
123 
125 (
126  const word& name,
127  const dictionary& dict,
128  const label index,
129  const polyBoundaryMesh& bm,
130  const word& patchType
131 )
132 :
133  polyPatch(name, dict, index, bm, patchType),
134  n_(vector::rootMax)
135 {}
136 
137 
139 (
140  const symmetryPlanePolyPatch& pp,
141  const polyBoundaryMesh& bm
142 )
143 :
144  polyPatch(pp, bm),
145  n_(pp.n_)
146 {}
147 
148 
150 (
151  const symmetryPlanePolyPatch& pp,
152  const polyBoundaryMesh& bm,
153  const label index,
154  const label newSize,
155  const label newStart
156 )
157 :
158  polyPatch(pp, bm, index, newSize, newStart),
159  n_(pp.n_)
160 {}
161 
162 
163 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
const Field< PointType > & faceNormals() const
Return face normals for patch.
const Field< PointType > & faceCentres() const
Return face centres for patch.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Struct for keeping processor, element (cell, face, point) and a piece of data. Used for finding minim...
Definition: RemoteData.H:65
Type data
Data.
Definition: RemoteData.H:75
A 3-tuple for storing three objects of different types.
Definition: Tuple3.H:60
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
static const Form rootMax
Definition: VectorSpace.H:122
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & name() const
Return name.
Foam::polyBoundaryMesh.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
label elementi
Element index.
Definition: remote.H:70
label proci
Processor index.
Definition: remote.H:67
virtual void calcGeometry(PstreamBuffers &)
Calculate the patch geometry.
symmetryPlanePolyPatch(const word &name, const label size, const label start, const label index, const polyBoundaryMesh &bm, const word &patchType)
Construct from components.
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
label findMax(const ListType &, const label start=0)
Find index of max element (and larger than given element).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
defineTypeNameAndDebug(combustionModel, 0)
Type gAverage(const FieldField< Field, Type > &f)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
static const char nl
Definition: Ostream.H:267
void combineReduce(const List< UPstream::commsStruct > &comms, T &Value, const CombineOp &cop, const int tag, const label comm)
dictionary dict