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-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(polyTopoChanger, 0);
40 }
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
45 void Foam::polyTopoChanger::readModifiers()
46 {
47  if
48  (
52  )
53  {
54  // Warn for MUST_READ_IF_MODIFIED
55  warnNoRereading<polyTopoChanger>();
56 
57  PtrList<polyMeshModifier>& modifiers = *this;
58 
59  // Read modifiers
60  Istream& is = readStream(typeName);
61 
62  PtrList<entry> patchEntries(is);
63  modifiers.setSize(patchEntries.size());
64 
65  forAll(modifiers, modifierI)
66  {
67  modifiers.set
68  (
69  modifierI,
71  (
72  patchEntries[modifierI].keyword(),
73  patchEntries[modifierI].dict(),
74  modifierI,
75  *this
76  )
77  );
78  }
79 
80  is.check(FUNCTION_NAME);
81 
82  close();
83  }
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
89 Foam::polyTopoChanger::polyTopoChanger
90 (
91  const IOobject& io,
92  polyMesh& mesh
93 )
94 :
96  regIOobject(io),
97  mesh_(mesh)
98 {
99  readModifiers();
100 }
101 
102 
103 Foam::polyTopoChanger::polyTopoChanger
104 (
105  polyMesh& mesh,
106  const IOobject::readOption rOpt
107 
108 )
109 :
111  (
112  IOobject
113  (
114  "meshModifiers",
116  (
117  mesh.meshDir(),
118  "meshModifiers",
119  rOpt
120  ),
122  mesh,
123  rOpt,
125  ),
126  mesh
127  )
128 {}
129 
130 
131 Foam::polyTopoChanger::polyTopoChanger(polyMesh& mesh)
132 :
133  polyTopoChanger(mesh, IOobject::readOption::READ_IF_PRESENT)
134 {}
135 
136 
138 {
139  return PtrListOps::get<word>(*this, typeOp<polyMeshModifier>());
140 }
141 
142 
144 {
145  return PtrListOps::get<word>(*this, typeOp<polyMeshModifier>());
146 }
147 
148 
150 {
151  // Go through all mesh modifiers and accumulate the morphing information
152  const PtrList<polyMeshModifier>& topoChanges = *this;
153 
154  bool triggerChange = false;
155 
156  forAll(topoChanges, morphI)
157  {
158  if (topoChanges[morphI].active())
159  {
160  bool curTriggerChange = topoChanges[morphI].changeTopology();
161 
162  if (debug)
163  {
164  Info<< "Modifier " << morphI << " named "
165  << topoChanges[morphI].name();
166 
167  if (curTriggerChange)
168  {
169  Info<< " morphing" << endl;
170  }
171  else
172  {
173  Info<< " unchanged" << endl;
174  }
175  }
176 
177  triggerChange = triggerChange || curTriggerChange;
178  }
179  else
180  {
181  if (debug)
182  {
183  Info<< "Modifier " << morphI << " named "
184  << topoChanges[morphI].name() << " inactive" << endl;
185  }
186  }
187 
188  }
189 
190  return triggerChange;
191 }
192 
193 
196 {
197  // Collect changes from all modifiers
198  const PtrList<polyMeshModifier>& topoChanges = *this;
199 
200  auto ptr = autoPtr<polyTopoChange>::New(mesh());
201  polyTopoChange& ref = ptr.ref();
202 
203  forAll(topoChanges, morphI)
204  {
205  if (topoChanges[morphI].active())
206  {
207  topoChanges[morphI].setRefinement(ref);
208  }
209  }
210 
211  return ptr;
212 }
213 
214 
216 {
217  const PtrList<polyMeshModifier>& topoChanges = *this;
218 
219  forAll(topoChanges, morphI)
220  {
221  if (topoChanges[morphI].active())
222  {
223  topoChanges[morphI].modifyMotionPoints(p);
224  }
225  }
226 }
227 
228 
230 {
231  // Go through all mesh modifiers and accumulate the morphing information
232  PtrList<polyMeshModifier>& topoChanges = *this;
233 
234  forAll(topoChanges, morphI)
235  {
236  topoChanges[morphI].updateMesh(m);
237  }
238 
239  // Force the mesh modifiers to auto-write. This allows us to
240  // preserve the current state of modifiers corresponding with
241  // the mesh.
242  writeOpt(IOobject::AUTO_WRITE);
243  instance() = mesh_.time().timeName();
244 }
245 
246 
248 (
249  const bool inflate,
250  const bool syncParallel,
251  const bool orderCells,
252  const bool orderPoints
253 )
254 {
255  if (changeTopology())
256  {
257  autoPtr<polyTopoChange> ref = topoChangeRequest();
258 
259  autoPtr<mapPolyMesh> topoChangeMap = ref().changeMesh
260  (
261  mesh_,
262  inflate,
263  syncParallel,
264  orderCells,
265  orderPoints
266  );
267 
268  update(topoChangeMap());
269  mesh_.updateMesh(topoChangeMap());
270  return topoChangeMap;
271  }
272 
273  mesh_.topoChanging(false);
274  return nullptr;
275 }
276 
277 
279 (
280  const List<polyMeshModifier*>& tm
281 )
282 {
283  setSize(tm.size());
284 
285  // Copy the patch pointers
286  forAll(tm, tmI)
287  {
288  if (tm[tmI]->topoChanger() != *this)
289  {
291  << "Mesh modifier created with different mesh reference."
292  << abort(FatalError);
293  }
294  set(tmI, tm[tmI]);
295  }
296 
297  writeOpt(IOobject::AUTO_WRITE);
298 }
299 
300 
302 (
303  const word& modName
304 ) const
305 {
306  const PtrList<polyMeshModifier>& topoChanges = *this;
307 
308  forAll(topoChanges, morphI)
309  {
310  if (topoChanges[morphI].name() == modName)
311  {
312  return morphI;
313  }
314  }
315 
316  // Modifier not found
317  if (debug)
318  {
320  << "List of available modifier names: " << names() << endl;
321  }
322 
323  // Not found, return -1
324  return -1;
325 }
326 
327 
329 {
330  os << *this;
331  return os.good();
332 }
333 
334 
335 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
336 
338 {
339  return &me != this;
340 }
341 
342 
344 {
345  return &me == this;
346 }
347 
348 
349 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
350 
352 {
353  os << mme.size() << nl << token::BEGIN_LIST;
354 
355  forAll(mme, mmeI)
356  {
357  mme[mmeI].writeDict(os);
358  }
359 
360  os << token::END_LIST;
361 
362  return os;
363 }
364 
365 
366 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
setSize
points setSize(newPointi)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
update
mesh update()
Foam::polyTopoChanger::findModifierID
label findModifierID(const word &modName) const
Find modifier given a name.
Definition: polyTopoChanger.C:302
Foam::polyTopoChanger
List of mesh modifiers defining the mesh dynamics.
Definition: polyTopoChanger.H:62
polyTopoChanger.H
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:321
polyTopoChange.H
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:99
Foam::polyTopoChanger::changeTopology
bool changeTopology() const
Is topology change required.
Definition: polyTopoChanger.C:149
Foam::polyTopoChanger::topoChangeRequest
autoPtr< polyTopoChange > topoChangeRequest() const
Return topology change request.
Definition: polyTopoChanger.C:195
Foam::polyTopoChanger::update
void update(const mapPolyMesh &m)
Force recalculation of locally stored data on topological change.
Definition: polyTopoChanger.C:229
Foam::polyTopoChanger::names
wordList names() const
Return a list of patch names.
Definition: polyTopoChanger.C:143
PtrListOps.H
Functions to operate on Pointer Lists.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::polyTopoChanger::addTopologyModifiers
void addTopologyModifiers(const List< polyMeshModifier * > &tm)
Add given set of topology modifiers to the topoChanger.
Definition: polyTopoChanger.C:279
ref
rDeltaT ref()
polyMesh.H
Foam::constant::atomic::me
const dimensionedScalar me
Electron mass.
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::polyTopoChanger::modifyMotionPoints
void modifyMotionPoints(pointField &) const
Modify point motion.
Definition: polyTopoChanger.C:215
Foam::polyTopoChanger::types
wordList types() const
Return a list of patch types.
Definition: polyTopoChanger.C:137
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::IOstream::good
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::polyTopoChanger::operator!=
bool operator!=(const polyTopoChanger &) const
Definition: polyTopoChanger.C:337
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyTopoChanger::writeData
bool writeData(Ostream &) const
writeData member function required by regIOobject
Definition: polyTopoChanger.C:328
Foam::polyTopoChanger::changeMesh
autoPtr< mapPolyMesh > changeMesh(const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Definition: polyTopoChanger.C:248
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:187
Foam::PtrList< polyMeshModifier >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::Time::findInstance
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
Definition: Time.C:797
Foam::polyMesh::meshDir
fileName meshDir() const
Return the local mesh directory (dbDir()/meshSubDir)
Definition: polyMesh.C:840
Foam::polyMeshModifier::New
static autoPtr< polyMeshModifier > New(const word &name, const dictionary &dict, const label index, const polyTopoChanger &mme)
Select constructed from dictionary.
Definition: polyMeshModifierNew.C:35
Foam::IOobject::readOpt
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::polyTopoChanger::operator==
bool operator==(const polyTopoChanger &) const
Definition: polyTopoChanger.C:343
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::regIOobject::close
void close()
Close Istream.
Definition: regIOobjectRead.C:171
Foam::List< word >
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:156
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
Foam::IOobject::readOption
readOption
Enumeration defining the read options.
Definition: IOobject.H:183
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::regIOobject::readStream
Istream & readStream(const word &, const bool valid=true)
Return Istream and check object type against that given.
Definition: regIOobjectRead.C:129
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
Foam::PtrListOps::names
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::typeOp
Extract type (as a word) from an object, typically using its type() method.
Definition: word.H:248
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::regIOobject::headerOk
bool headerOk()
Read and check header info.
Definition: regIOobject.C:436
Foam::IOobject::MUST_READ
Definition: IOobject.H:185