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-2023 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 
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 
40 :
41  patch_(pp),
42  coupleGroup_(),
43  nbrRegionName_(patch_.boundaryMesh().mesh().name()),
44  nbrPatchName_(patch_.name()),
45  transform_(true)
46 {}
47 
48 
50 (
51  const polyPatch& pp,
52  const word& nbrRegionName,
53  const word& nbrPatchName,
55 )
56 :
57  patch_(pp),
58  coupleGroup_(),
59  nbrRegionName_(nbrRegionName),
60  nbrPatchName_(nbrPatchName),
61  transform_(transform)
62 {}
63 
64 
66 (
67  const polyPatch& pp,
68  const dictionary& dict,
69  const bool transformIsNone
70 )
71 :
72  patch_(pp),
73  coupleGroup_(dict),
74  nbrRegionName_
75  (
76  coupleGroup_.valid() ? word::null
77  : dict.lookupOrDefaultBackwardsCompatible<word>
78  (
79  {"neighbourRegion", "sampleRegion"},
80  pp.boundaryMesh().mesh().name()
81  )
82  ),
83  nbrPatchName_
84  (
85  coupleGroup_.valid() ? word::null
86  : dict.lookupOrDefault<bool>("samePatch", false) ? pp.name()
87  : dict.lookupBackwardsCompatible<word>({"neighbourPatch", "samplePatch"})
88  ),
89  transform_
90  (
91  transformIsNone
92  ? cyclicTransform(true)
93  : cyclicTransform(dict, false)
94  )
95 {
96  const bool haveCoupleGroup = coupleGroup_.valid();
97 
98  const bool haveNbrRegion =
99  dict.found("neighbourRegion") || dict.found("sampleRegion");
100  const bool haveNbrPatch =
101  dict.found("neighbourPatch") || dict.found("samplePatch");
102 
103  const bool isSamePatch = dict.lookupOrDefault<bool>("samePatch", false);
104 
105  if ((haveNbrRegion || haveNbrPatch || isSamePatch) && haveCoupleGroup)
106  {
108  << "Either neighbourRegion/Patch information or a coupleGroup "
109  << "should be specified, not both" << exit(FatalIOError);
110  }
111 
112  if (haveNbrPatch && isSamePatch)
113  {
115  << "Either a neighbourPatch should be specified, or samePatch "
116  << "should be set to true, not both" << exit(FatalIOError);
117  }
118 }
119 
120 
122 (
123  const polyPatch& pp,
124  const mappedPatchBaseBase& mpb
125 )
126 :
127  patch_(pp),
128  coupleGroup_(mpb.coupleGroup_),
129  nbrRegionName_(mpb.nbrRegionName_),
130  nbrPatchName_(mpb.nbrPatchName_),
131  transform_(mpb.transform_)
132 {}
133 
134 
135 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
136 
138 {}
139 
140 
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 
144 {
145  const polyMesh& mesh = patch_.boundaryMesh().mesh();
146 
147  return mesh.time().foundObject<polyMesh>(nbrRegionName());
148 }
149 
150 
152 {
153  const polyMesh& mesh = patch_.boundaryMesh().mesh();
154 
155  return mesh.time().lookupObject<polyMesh>(nbrRegionName());
156 }
157 
158 
160 {
161  const polyMesh& nbrMesh = this->nbrMesh();
162 
163  const label patchi = nbrMesh.boundaryMesh().findIndex(nbrPatchName());
164 
165  if (patchi == -1)
166  {
168  << "Cannot find patch " << nbrPatchName()
169  << " in region " << nbrRegionName() << endl
170  << "Valid patches are " << nbrMesh.boundaryMesh().names()
171  << exit(FatalError);
172  }
173 
174  return nbrMesh.boundaryMesh()[patchi];
175 }
176 
177 
179 {
180  return
181  dict.found("coupleGroup")
182  || dict.found("neighbourRegion")
183  || dict.found("sampleRegion")
184  || dict.found("neighbourPatch")
185  || dict.found("samplePatch")
186  || dict.found("samePatch");
187 }
188 
189 
191 {
192  writeEntryIfDifferent(os, "neighbourRegion", word::null, nbrRegionName_);
193  writeEntryIfDifferent(os, "neighbourPatch", word::null, nbrPatchName_);
194 
195  coupleGroup_.write(os);
196 
197  transform_.write(os);
198 }
199 
200 
201 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Cyclic plane transformation.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) 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:721
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:509
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?
static bool specified(const dictionary &dict)
Return whether or not the given dictionary contains a.
mappedPatchBaseBase(const polyPatch &)
Construct from patch.
const Time & time() const
Return time.
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
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:404
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
#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
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:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:504
defineTypeNameAndDebug(combustionModel, 0)
IOerror FatalIOError
error FatalError
dictionary dict