Loading...
Searching...
No Matches
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-2024 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::readIOcontents()
46{
47 if (isReadRequired() || (isReadOptional() && headerOk()))
48 {
49 PtrList<polyMeshModifier>& modifiers = *this;
50
51 // Read modifiers
52 Istream& is = readStream(typeName);
53
54 PtrList<entry> entries(is);
55 modifiers.resize_null(entries.size());
56
57 forAll(modifiers, modifieri)
58 {
59 modifiers.set
60 (
61 modifieri,
63 (
64 entries[modifieri].keyword(),
65 entries[modifieri].dict(),
66 modifieri,
67 *this
68 )
69 );
70 }
71
72 is.check(FUNCTION_NAME);
73 close();
74 return true;
75 }
77 return false;
78}
79
80
81// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
82
83Foam::polyTopoChanger::polyTopoChanger
84(
85 const IOobject& io,
87)
88:
91 mesh_(mesh)
92{
93 // Warn for MUST_READ_IF_MODIFIED
95
96 readIOcontents();
97}
98
99
100Foam::polyTopoChanger::polyTopoChanger
101(
102 polyMesh& mesh,
104)
105:
107 (
109 (
110 "meshModifiers",
111 mesh.time().findInstance
112 (
113 mesh.meshDir(),
114 "meshModifiers",
115 (
116 // Safety? promote NO_READ to LAZY_READ
117 rOpt == IOobject::NO_READ
118 ? IOobject::LAZY_READ
119 : rOpt
120 )
121 ),
122 polyMesh::meshSubDir,
123 mesh,
124 rOpt,
126 ),
127 mesh
128 )
129{}
130
132Foam::polyTopoChanger::polyTopoChanger(polyMesh& mesh)
133:
134 polyTopoChanger(mesh, IOobjectOption::READ_IF_PRESENT)
135{}
136
141}
142
145{
147}
148
149
151{
152 // Go through all mesh modifiers and accumulate the morphing information
153 const PtrList<polyMeshModifier>& topoChanges = *this;
154
155 bool triggerChange = false;
156
157 forAll(topoChanges, morphI)
158 {
159 if (topoChanges[morphI].active())
160 {
161 bool curTriggerChange = topoChanges[morphI].changeTopology();
162
163 if (debug)
164 {
165 Info<< "Modifier " << morphI << " named "
166 << topoChanges[morphI].name();
167
168 if (curTriggerChange)
169 {
170 Info<< " morphing" << endl;
171 }
172 else
173 {
174 Info<< " unchanged" << endl;
175 }
176 }
177
178 triggerChange = triggerChange || curTriggerChange;
179 }
180 else
181 {
182 if (debug)
183 {
184 Info<< "Modifier " << morphI << " named "
185 << topoChanges[morphI].name() << " inactive" << endl;
186 }
187 }
188
190
191 return triggerChange;
192}
193
194
197{
198 // Collect changes from all modifiers
199 const PtrList<polyMeshModifier>& topoChanges = *this;
200
202 polyTopoChange& ref = ptr.ref();
203
204 forAll(topoChanges, morphI)
205 {
206 if (topoChanges[morphI].active())
207 {
208 topoChanges[morphI].setRefinement(ref);
210 }
211
212 return ptr;
213}
214
215
217{
218 const PtrList<polyMeshModifier>& topoChanges = *this;
219
220 forAll(topoChanges, morphI)
221 {
222 if (topoChanges[morphI].active())
224 topoChanges[morphI].modifyMotionPoints(p);
225 }
226 }
227}
228
229
231{
232 // Go through all mesh modifiers and accumulate the morphing information
233 PtrList<polyMeshModifier>& topoChanges = *this;
234
235 forAll(topoChanges, morphI)
236 {
237 topoChanges[morphI].updateMesh(m);
238 }
239
240 // Force the mesh modifiers to auto-write. This allows us to
241 // preserve the current state of modifiers corresponding with
242 // the mesh.
244 instance() = mesh_.time().timeName();
245}
246
247
249(
250 const bool inflate,
251 const bool syncParallel,
252 const bool orderCells,
253 const bool orderPoints
254)
255{
256 if (changeTopology())
257 {
258 autoPtr<polyTopoChange> ref = topoChangeRequest();
259
260 autoPtr<mapPolyMesh> topoChangeMap = ref().changeMesh
261 (
262 mesh_,
263 inflate,
264 syncParallel,
265 orderCells,
266 orderPoints
267 );
268
269 update(topoChangeMap());
270 mesh_.updateMesh(topoChangeMap());
271 return topoChangeMap;
273
274 mesh_.topoChanging(false);
275 return nullptr;
276}
277
278
280(
281 const List<polyMeshModifier*>& tm
282)
283{
284 setSize(tm.size());
285
286 // Copy the patch pointers
287 forAll(tm, tmI)
288 {
289 if (tm[tmI]->topoChanger() != *this)
290 {
292 << "Mesh modifier created with different mesh reference."
293 << abort(FatalError);
294 }
295 set(tmI, tm[tmI]);
296 }
297
298 writeOpt(IOobject::AUTO_WRITE);
299}
300
301
303(
304 const word& modName
305) const
306{
307 const PtrList<polyMeshModifier>& topoChanges = *this;
308
309 forAll(topoChanges, morphI)
310 {
311 if (topoChanges[morphI].name() == modName)
312 {
313 return morphI;
314 }
315 }
316
317 // Modifier not found
318 if (debug)
319 {
321 << "List of available modifier names: " << names() << endl;
323
324 // Not found, return -1
325 return -1;
326}
327
328
329bool Foam::polyTopoChanger::writeData(Ostream& os) const
330{
331 os << *this;
332 return os.good();
333}
334
335
336// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
338bool Foam::polyTopoChanger::operator!=(const polyTopoChanger& me) const
339{
340 return &me != this;
341}
342
343
346 return &me == this;
347}
348
349
350// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
351
352Foam::Ostream& Foam::operator<<(Ostream& os, const polyTopoChanger& mme)
353{
354 os << mme.size() << nl << token::BEGIN_LIST;
355
356 forAll(mme, mmeI)
357 {
358 mme[mmeI].writeDict(os);
359 }
360
362
363 return os;
364}
365
366
367// ************************************************************************* //
Functions to operate on Pointer Lists.
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
bool isReadOptional() const noexcept
True if (LAZY_READ) bits are set [same as READ_IF_PRESENT].
bool isReadRequired() const noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
writeOption writeOpt() const noexcept
Get the write option.
readOption
Enumeration defining read preferences.
@ NO_READ
Nothing to be read.
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ LAZY_READ
Reading is optional [identical to READ_IF_PRESENT].
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition IOobject.C:456
void warnNoRereading() const
Helper: warn that type does not support re-reading.
const fileName & instance() const noexcept
Read access to instance path component.
Definition IOobjectI.H:289
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
const polyMeshModifier * set(const label i) const
Definition PtrList.H:171
constexpr PtrList() noexcept
Definition PtrListI.H:29
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
label size() const noexcept
The number of entries in the list.
Definition UPtrListI.H:106
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition autoPtr.H:178
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Virtual base class for mesh modifiers.
static autoPtr< polyMeshModifier > New(const word &name, const dictionary &dict, const label index, const polyTopoChanger &mme)
Select constructed from dictionary.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
Direct mesh changes based on v1.3 polyTopoChange syntax.
List of mesh modifiers defining the mesh dynamics.
bool operator==(const polyTopoChanger &) const
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.
const polyMesh & mesh() const
Return the mesh reference.
void addTopologyModifiers(const List< polyMeshModifier * > &tm)
Add given set of topology modifiers to the topoChanger.
wordList types() const
Return a list of patch types.
polyMesh & mesh_
Reference to mesh.
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)
bool operator!=(const polyTopoChanger &) const
void update(const mapPolyMesh &m)
Force recalculation of locally stored data on topological change.
wordList names() const
Return a list of patch names.
void modifyMotionPoints(pointField &) const
Modify point motion.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
void close()
Close Istream.
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
bool headerOk()
Read and check header info. Does not check the headerClassName.
@ BEGIN_LIST
Begin list [isseparator].
Definition token.H:174
@ END_LIST
End list [isseparator].
Definition token.H:175
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
volScalarField & p
rDeltaT ref()
mesh update()
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
const auto & io
auto & name
auto & names
#define WarningInFunction
Report a warning using Foam::Warning.
#define FUNCTION_NAME
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
Namespace for handling debugging switches.
Definition debug.C:45
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
errorManip< error > abort(error &err)
Definition errorManip.H:139
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
vectorField pointField
pointField is a vectorField.
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
points setSize(newPointi)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
Extract type (as a word) from an object, typically using its type() method.
Definition word.H:362