mappedPatchBaseBase.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) 2011-2025 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 "mappedPatchBaseBase.H"
27 #include "Time.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
34 }
35 
36 
39 {"always", "detect", "never"};
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 :
46  patch_(pp),
47  coupleGroup_(),
48  nbrRegionName_(patch_.boundaryMesh().mesh().name()),
49  nbrPatchName_(patch_.name()),
50  transform_(true),
51  moveUpdate_(moveUpdate::always)
52 {}
53 
54 
56 (
57  const polyPatch& pp,
58  const word& nbrRegionName,
59  const word& nbrPatchName,
61 )
62 :
63  patch_(pp),
64  coupleGroup_(),
65  nbrRegionName_(nbrRegionName),
66  nbrPatchName_(nbrPatchName),
67  transform_(transform),
68  moveUpdate_(moveUpdate::always)
69 {}
70 
71 
73 (
74  const polyPatch& pp,
75  const dictionary& dict,
76  const transformType tt
77 )
78 :
79  patch_(pp),
80  coupleGroup_(dict),
81  nbrRegionName_
82  (
83  coupleGroup_.valid() ? word::null
84  : dict.lookupOrDefaultBackwardsCompatible<word>
85  (
86  {"neighbourRegion", "sampleRegion"},
87  pp.boundaryMesh().mesh().name()
88  )
89  ),
90  nbrPatchName_
91  (
92  coupleGroup_.valid() ? word::null
93  : dict.lookupOrDefault<bool>("samePatch", false) ? pp.name()
94  : dict.lookupBackwardsCompatible<word>({"neighbourPatch", "samplePatch"})
95  ),
96  transform_
97  (
98  tt == transformType::none ? cyclicTransform(true)
99  : tt == transformType::defaultNone ? cyclicTransform(dict, true)
100  : tt == transformType::specified ? cyclicTransform(dict, false)
101  : cyclicTransform()
102  ),
103  moveUpdate_
104  (
105  dict.found("moveUpdate")
106  ? moveUpdateNames_.read(dict.lookup("moveUpdate"))
107  : dict.found("reMapAfterMove") // <-- backwards compatibility
108  ? (
109  dict.lookup<bool>("reMapAfterMove")
110  ? moveUpdate::always
111  : moveUpdate::never
112  )
113  : moveUpdate::always
114  )
115 {
116  const bool haveCoupleGroup = coupleGroup_.valid();
117 
118  const bool haveNbrRegion =
119  dict.found("neighbourRegion") || dict.found("sampleRegion");
120  const bool haveNbrPatch =
121  dict.found("neighbourPatch") || dict.found("samplePatch");
122 
123  const bool isSamePatch = dict.lookupOrDefault<bool>("samePatch", false);
124 
125  if ((haveNbrRegion || haveNbrPatch || isSamePatch) && haveCoupleGroup)
126  {
128  << "Either neighbourRegion/Patch information or a coupleGroup "
129  << "should be specified, not both" << exit(FatalIOError);
130  }
131 
132  if (haveNbrPatch && isSamePatch)
133  {
135  << "Either a neighbourPatch should be specified, or samePatch "
136  << "should be set to true, not both" << exit(FatalIOError);
137  }
138 
139  if (tt == transformType::none)
140  {
142  cyclicTransform(dict, true).transformType();
143 
144  if (cttt != cyclicTransform::NONE)
145  {
147  << word(cyclicTransform::transformTypeNames[cttt]).capitalise()
148  << " transform specified for patch '" << patch_.name()
149  << "' in region '" << patch_.boundaryMesh().mesh().name()
150  << "'. This patch does not support transformed mapping."
151  << exit(FatalIOError);
152  }
153  }
154 }
155 
156 
158 (
159  const polyPatch& pp,
160  const mappedPatchBaseBase& mpb
161 )
162 :
163  patch_(pp),
164  coupleGroup_(mpb.coupleGroup_),
165  nbrRegionName_(mpb.nbrRegionName_),
166  nbrPatchName_(mpb.nbrPatchName_),
167  transform_(mpb.transform_),
168  moveUpdate_(mpb.moveUpdate_)
169 {}
170 
171 
172 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
173 
175 {}
176 
177 
178 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
179 
181 {
182  const polyMesh& mesh = patch_.boundaryMesh().mesh();
183 
184  return mesh.time().foundObject<polyMesh>(nbrRegionName());
185 }
186 
187 
189 {
190  const polyMesh& mesh = patch_.boundaryMesh().mesh();
191 
192  return mesh.time().lookupObject<polyMesh>(nbrRegionName());
193 }
194 
195 
197 {
198  const polyMesh& nbrMesh = this->nbrMesh();
199 
200  const label patchi = nbrMesh.boundaryMesh().findIndex(nbrPatchName());
201 
202  if (patchi == -1)
203  {
205  << "Cannot find patch " << nbrPatchName()
206  << " in region " << nbrRegionName() << endl
207  << "Valid patches are " << nbrMesh.boundaryMesh().names()
208  << exit(FatalError);
209  }
210 
211  return nbrMesh.boundaryMesh()[patchi];
212 }
213 
214 
216 (
217  const polyPatch& patch,
218  const polyPatch& nbrPatch
219 )
220 {
221  const polyMesh& mesh = patch.boundaryMesh().mesh();
222  const polyMesh& nbrMesh = nbrPatch.boundaryMesh().mesh();
223 
224  if (!mesh.moving() && !nbrMesh.moving()) return false;
225 
226  auto localPatchMoving = [](const polyPatch& patch)
227  {
228  const polyMesh& mesh = patch.boundaryMesh().mesh();
229 
230  if (!mesh.moving()) return false;
231 
232  const pointField& points = mesh.points();
233  const pointField& oldPoints = mesh.oldPoints();
234 
235  // !!! Note that this is an exact binary comparison of the point
236  // positions. This isn't typical, but in most cases where this is
237  // relevant the mesh motion is being switched off entirely for a period
238  // of time, or the motion is only present in another part of the mesh,
239  // and the points in question therefore do not change their value in
240  // any way. This prevents the need for a more substantial calculation
241  // procedure and the specification of tolerances and similar.
242 
243  return
245  != UIndirectList<point>(oldPoints, patch.meshPoints());
246  };
247 
248  return
250  (
251  localPatchMoving(patch) || localPatchMoving(nbrPatch),
252  orOp<bool>()
253  );
254 }
255 
256 
258 {
259  return
260  dict.found("coupleGroup")
261  || dict.found("neighbourRegion")
262  || dict.found("sampleRegion")
263  || dict.found("neighbourPatch")
264  || dict.found("samplePatch")
265  || dict.found("samePatch");
266 }
267 
268 
270 {
271  writeEntryIfDifferent(os, "neighbourRegion", word::null, nbrRegionName_);
272  writeEntryIfDifferent(os, "neighbourPatch", word::null, nbrPatchName_);
273 
274  coupleGroup_.write(os);
275 
276  transform_.write(os);
277 
278  writeEntryIfDifferent<word>
279  (
280  os,
281  "moveUpdate",
282  moveUpdateNames_[moveUpdate::always],
283  moveUpdateNames_[moveUpdate_]
284  );
285 }
286 
287 
288 // ************************************************************************* //
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:55
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
A List with indirect addressing.
Definition: UIndirectList.H:60
Cyclic plane transformation.
static const NamedEnum< transformTypes, 4 > transformTypeNames
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:740
T lookupOrDefault(const word &, const T &, const bool writeDefault=writeOptionalEntries > 0) const
Find and return a T, if not found return the given default.
ITstream & lookupBackwardsCompatible(const wordList &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream, trying a list of keywords.
Definition: dictionary.C:751
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:539
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:420
Base class for engines and poly patches which provide mapping between two poly patches.
const polyPatch & nbrPolyPatch() const
Get the patch to map from.
virtual void write(Ostream &) const
Write as a dictionary.
const polyMesh & nbrMesh() const
Get the mesh for the region to map from.
virtual ~mappedPatchBaseBase()
Destructor.
bool haveNbr() const
Is the neighbour available?
transformType
The type of the transformation permitted/required by this patch.
static const NamedEnum< moveUpdate, 3 > moveUpdateNames_
Names of the move-update conditions.
static bool specified(const dictionary &dict)
Return whether or not the given dictionary contains a.
static bool moving(const polyPatch &patch, const polyPatch &nbrPatch)
Return whether or not the patches have moved.
moveUpdate
Enumeration for the condition that triggers re-calculation of the.
mappedPatchBaseBase(const polyPatch &)
Construct from patch.
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type and name.
bool foundObject(const word &name) const
Is the named Type in registry.
label findIndex(const word &patchName) const
Find patch index given a name.
wordList names() const
Return the list of patch names.
const polyMesh & mesh() const
Return the mesh reference.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
virtual const pointField & oldPoints() const
Return old points for mesh motion.
Definition: polyMesh.C:1369
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:401
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1331
bool moving() const
Is mesh moving.
Definition: polyMesh.H:473
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:270
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
const pointField & points
bool valid(const PtrList< ModelType > &l)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2)
Helper function to write the keyword and entry only if the.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:501
defineTypeNameAndDebug(combustionModel, 0)
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
dictionary dict