polyTopoChanger.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 Copyright (C) 2017-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "polyTopoChanger.H"
30#include "polyMesh.H"
31#include "polyTopoChange.H"
32#include "Time.H"
33#include "PtrListOps.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
40}
41
42
43// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44
45bool Foam::polyTopoChanger::readContents()
46{
47 if
48 (
52 )
53 {
54 PtrList<polyMeshModifier>& modifiers = *this;
55
56 // Read modifiers
57 Istream& is = readStream(typeName);
58
59 PtrList<entry> patchEntries(is);
60 modifiers.setSize(patchEntries.size());
61
62 forAll(modifiers, modifierI)
63 {
64 modifiers.set
65 (
66 modifierI,
68 (
69 patchEntries[modifierI].keyword(),
70 patchEntries[modifierI].dict(),
71 modifierI,
72 *this
73 )
74 );
75 }
76
77 is.check(FUNCTION_NAME);
78 close();
79 return true;
80 }
81
82 return false;
83}
84
85
86// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
87
89(
90 const IOobject& io,
92)
93:
96 mesh_(mesh)
97{
98 // Warn for MUST_READ_IF_MODIFIED
99 warnNoRereading<polyTopoChanger>();
100
101 readContents();
102}
103
104
106(
107 polyMesh& mesh,
108 const IOobject::readOption rOpt
109
110)
111:
113 (
115 (
116 "meshModifiers",
117 mesh.time().findInstance
118 (
119 mesh.meshDir(),
120 "meshModifiers",
121 (
122 // Safety? promote NO_READ to READ_IF_PRESENT
123 rOpt == IOobject::NO_READ
124 ? IOobject::READ_IF_PRESENT
125 : rOpt
126 )
127 ),
128 polyMesh::meshSubDir,
129 mesh,
130 rOpt,
131 IOobject::NO_WRITE
132 ),
133 mesh
134 )
135{}
136
137
139:
140 polyTopoChanger(mesh, IOobject::readOption::READ_IF_PRESENT)
141{}
142
143
145{
146 return PtrListOps::get<word>(*this, typeOp<polyMeshModifier>());
147}
148
149
151{
152 return PtrListOps::get<word>(*this, typeOp<polyMeshModifier>());
153}
154
155
157{
158 // Go through all mesh modifiers and accumulate the morphing information
159 const PtrList<polyMeshModifier>& topoChanges = *this;
160
161 bool triggerChange = false;
162
163 forAll(topoChanges, morphI)
164 {
165 if (topoChanges[morphI].active())
166 {
167 bool curTriggerChange = topoChanges[morphI].changeTopology();
168
169 if (debug)
170 {
171 Info<< "Modifier " << morphI << " named "
172 << topoChanges[morphI].name();
173
174 if (curTriggerChange)
175 {
176 Info<< " morphing" << endl;
177 }
178 else
179 {
180 Info<< " unchanged" << endl;
181 }
182 }
183
184 triggerChange = triggerChange || curTriggerChange;
185 }
186 else
187 {
188 if (debug)
189 {
190 Info<< "Modifier " << morphI << " named "
191 << topoChanges[morphI].name() << " inactive" << endl;
192 }
193 }
194
195 }
196
197 return triggerChange;
198}
199
200
203{
204 // Collect changes from all modifiers
205 const PtrList<polyMeshModifier>& topoChanges = *this;
206
208 polyTopoChange& ref = ptr.ref();
209
210 forAll(topoChanges, morphI)
211 {
212 if (topoChanges[morphI].active())
213 {
214 topoChanges[morphI].setRefinement(ref);
215 }
216 }
217
218 return ptr;
219}
220
221
223{
224 const PtrList<polyMeshModifier>& topoChanges = *this;
225
226 forAll(topoChanges, morphI)
227 {
228 if (topoChanges[morphI].active())
229 {
230 topoChanges[morphI].modifyMotionPoints(p);
231 }
232 }
233}
234
235
237{
238 // Go through all mesh modifiers and accumulate the morphing information
239 PtrList<polyMeshModifier>& topoChanges = *this;
240
241 forAll(topoChanges, morphI)
242 {
243 topoChanges[morphI].updateMesh(m);
244 }
245
246 // Force the mesh modifiers to auto-write. This allows us to
247 // preserve the current state of modifiers corresponding with
248 // the mesh.
249 writeOpt(IOobject::AUTO_WRITE);
250 instance() = mesh_.time().timeName();
251}
252
253
255(
256 const bool inflate,
257 const bool syncParallel,
258 const bool orderCells,
259 const bool orderPoints
260)
261{
262 if (changeTopology())
263 {
264 autoPtr<polyTopoChange> ref = topoChangeRequest();
265
266 autoPtr<mapPolyMesh> topoChangeMap = ref().changeMesh
267 (
268 mesh_,
269 inflate,
270 syncParallel,
271 orderCells,
272 orderPoints
273 );
274
275 update(topoChangeMap());
276 mesh_.updateMesh(topoChangeMap());
277 return topoChangeMap;
278 }
279
280 mesh_.topoChanging(false);
281 return nullptr;
282}
283
284
286(
288)
289{
290 setSize(tm.size());
291
292 // Copy the patch pointers
293 forAll(tm, tmI)
294 {
295 if (tm[tmI]->topoChanger() != *this)
296 {
298 << "Mesh modifier created with different mesh reference."
299 << abort(FatalError);
300 }
301 set(tmI, tm[tmI]);
302 }
303
304 writeOpt(IOobject::AUTO_WRITE);
305}
306
307
309(
310 const word& modName
311) const
312{
313 const PtrList<polyMeshModifier>& topoChanges = *this;
314
315 forAll(topoChanges, morphI)
316 {
317 if (topoChanges[morphI].name() == modName)
318 {
319 return morphI;
320 }
321 }
322
323 // Modifier not found
324 if (debug)
325 {
327 << "List of available modifier names: " << names() << endl;
328 }
329
330 // Not found, return -1
331 return -1;
332}
333
334
336{
337 os << *this;
338 return os.good();
339}
340
341
342// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
343
345{
346 return &me != this;
347}
348
349
351{
352 return &me == this;
353}
354
355
356// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
357
359{
360 os << mme.size() << nl << token::BEGIN_LIST;
361
362 forAll(mme, mmeI)
363 {
364 mme[mmeI].writeDict(os);
365 }
366
368
369 return os;
370}
371
372
373// ************************************************************************* //
Functions to operate on Pointer Lists.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
readOption
Enumeration defining the read options.
Definition: IOobject.H:177
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:180
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
virtual bool update()
Update the mesh for both mesh motion and topology change.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:162
Virtual base class for mesh modifiers.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Direct mesh changes based on v1.3 polyTopoChange syntax.
List of mesh modifiers defining the mesh dynamics.
bool writeData(Ostream &) const
writeData member function required by regIOobject
label findModifierID(const word &modName) const
Find modifier given a name.
autoPtr< polyTopoChange > topoChangeRequest() const
Return topology change request.
void addTopologyModifiers(const List< polyMeshModifier * > &tm)
Add given set of topology modifiers to the topoChanger.
wordList types() const
Return a list of patch types.
bool changeTopology() const
Is topology change required.
autoPtr< mapPolyMesh > changeMesh(const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
wordList names() const
Return a list of patch names.
void modifyMotionPoints(pointField &) const
Modify point motion.
friend bool operator!=(const refineCell &rc1, const refineCell &rc2)
Definition: refineCell.H:106
friend bool operator==(const refineCell &rc1, const refineCell &rc2)
Definition: refineCell.H:97
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
void close()
Close Istream.
bool headerOk()
Read and check header info. Does not check the headerClassName.
Definition: regIOobject.C:438
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
@ END_LIST
End list [isseparator].
Definition: token.H:156
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
volScalarField & p
rDeltaT ref()
mesh update()
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define WarningInFunction
Report a warning using Foam::Warning.
#define FUNCTION_NAME
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
points setSize(newPointi)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Extract type (as a word) from an object, typically using its type() method.
Definition: word.H:255