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-2020 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 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(polyTopoChanger, 0);
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void Foam::polyTopoChanger::readModifiers()
45 {
46  if
47  (
51  )
52  {
53  // Warn for MUST_READ_IF_MODIFIED
54  warnNoRereading<polyTopoChanger>();
55 
56  PtrList<polyMeshModifier>& modifiers = *this;
57 
58  // Read modifiers
59  Istream& is = readStream(typeName);
60 
61  PtrList<entry> patchEntries(is);
62  modifiers.setSize(patchEntries.size());
63 
64  forAll(modifiers, modifierI)
65  {
66  modifiers.set
67  (
68  modifierI,
70  (
71  patchEntries[modifierI].keyword(),
72  patchEntries[modifierI].dict(),
73  modifierI,
74  *this
75  )
76  );
77  }
78 
79  is.check(FUNCTION_NAME);
80 
81  close();
82  }
83 }
84 
85 
86 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
87 
88 Foam::polyTopoChanger::polyTopoChanger
89 (
90  const IOobject& io,
91  polyMesh& mesh
92 )
93 :
95  regIOobject(io),
96  mesh_(mesh)
97 {
98  readModifiers();
99 }
100 
101 
102 Foam::polyTopoChanger::polyTopoChanger
103 (
104  polyMesh& mesh,
105  const IOobject::readOption rOpt
106 
107 )
108 :
110  (
111  IOobject
112  (
113  "meshModifiers",
115  (
116  mesh.meshDir(),
117  "meshModifiers",
118  rOpt
119  ),
121  mesh,
122  rOpt,
124  ),
125  mesh
126  )
127 {}
128 
129 
130 Foam::polyTopoChanger::polyTopoChanger(polyMesh& mesh)
131 :
132  polyTopoChanger(mesh, IOobject::readOption::READ_IF_PRESENT)
133 {}
134 
135 
137 {
138  const PtrList<polyMeshModifier>& modifiers = *this;
139 
140  wordList lst(modifiers.size());
141 
142  forAll(modifiers, i)
143  {
144  lst[i] = modifiers[i].type();
145  }
146 
147  return lst;
148 }
149 
150 
152 {
153  const PtrList<polyMeshModifier>& modifiers = *this;
154 
155  wordList lst(modifiers.size());
156 
157  forAll(modifiers, i)
158  {
159  lst[i] = modifiers[i].name();
160  }
161 
162  return lst;
163 }
164 
165 
167 {
168  // Go through all mesh modifiers and accumulate the morphing information
169  const PtrList<polyMeshModifier>& topoChanges = *this;
170 
171  bool triggerChange = false;
172 
173  forAll(topoChanges, morphI)
174  {
175  if (topoChanges[morphI].active())
176  {
177  bool curTriggerChange = topoChanges[morphI].changeTopology();
178 
179  if (debug)
180  {
181  Info<< "Modifier " << morphI << " named "
182  << topoChanges[morphI].name();
183 
184  if (curTriggerChange)
185  {
186  Info<< " morphing" << endl;
187  }
188  else
189  {
190  Info<< " unchanged" << endl;
191  }
192  }
193 
194  triggerChange = triggerChange || curTriggerChange;
195  }
196  else
197  {
198  if (debug)
199  {
200  Info<< "Modifier " << morphI << " named "
201  << topoChanges[morphI].name() << " inactive" << endl;
202  }
203  }
204 
205  }
206 
207  return triggerChange;
208 }
209 
210 
213 {
214  // Collect changes from all modifiers
215  const PtrList<polyMeshModifier>& topoChanges = *this;
216 
217  auto ptr = autoPtr<polyTopoChange>::New(mesh());
218  polyTopoChange& ref = ptr.ref();
219 
220  forAll(topoChanges, morphI)
221  {
222  if (topoChanges[morphI].active())
223  {
224  topoChanges[morphI].setRefinement(ref);
225  }
226  }
227 
228  return ptr;
229 }
230 
231 
233 {
234  const PtrList<polyMeshModifier>& topoChanges = *this;
235 
236  forAll(topoChanges, morphI)
237  {
238  if (topoChanges[morphI].active())
239  {
240  topoChanges[morphI].modifyMotionPoints(p);
241  }
242  }
243 }
244 
245 
247 {
248  // Go through all mesh modifiers and accumulate the morphing information
249  PtrList<polyMeshModifier>& topoChanges = *this;
250 
251  forAll(topoChanges, morphI)
252  {
253  topoChanges[morphI].updateMesh(m);
254  }
255 
256  // Force the mesh modifiers to auto-write. This allows us to
257  // preserve the current state of modifiers corresponding with
258  // the mesh.
259  writeOpt() = IOobject::AUTO_WRITE;
260  instance() = mesh_.time().timeName();
261 }
262 
263 
265 (
266  const bool inflate,
267  const bool syncParallel,
268  const bool orderCells,
269  const bool orderPoints
270 )
271 {
272  if (changeTopology())
273  {
274  autoPtr<polyTopoChange> ref = topoChangeRequest();
275 
276  autoPtr<mapPolyMesh> topoChangeMap = ref().changeMesh
277  (
278  mesh_,
279  inflate,
280  syncParallel,
281  orderCells,
282  orderPoints
283  );
284 
285  update(topoChangeMap());
286  mesh_.updateMesh(topoChangeMap());
287  return topoChangeMap;
288  }
289 
290  mesh_.topoChanging(false);
291  return nullptr;
292 }
293 
294 
296 (
297  const List<polyMeshModifier*>& tm
298 )
299 {
300  setSize(tm.size());
301 
302  // Copy the patch pointers
303  forAll(tm, tmI)
304  {
305  if (tm[tmI]->topoChanger() != *this)
306  {
308  << "Mesh modifier created with different mesh reference."
309  << abort(FatalError);
310  }
311  set(tmI, tm[tmI]);
312  }
313 
314  writeOpt() = IOobject::AUTO_WRITE;
315 }
316 
317 
319 (
320  const word& modName
321 ) const
322 {
323  const PtrList<polyMeshModifier>& topoChanges = *this;
324 
325  forAll(topoChanges, morphI)
326  {
327  if (topoChanges[morphI].name() == modName)
328  {
329  return morphI;
330  }
331  }
332 
333  // Modifier not found
334  if (debug)
335  {
337  << "List of available modifier names: " << names() << endl;
338  }
339 
340  // Not found, return -1
341  return -1;
342 }
343 
344 
346 {
347  os << *this;
348  return os.good();
349 }
350 
351 
352 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
353 
355 {
356  return &me != this;
357 }
358 
359 
361 {
362  return &me == this;
363 }
364 
365 
366 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
367 
369 {
370  os << mme.size() << nl << token::BEGIN_LIST;
371 
372  forAll(mme, mmeI)
373  {
374  mme[mmeI].writeDict(os);
375  }
376 
377  os << token::END_LIST;
378 
379  return os;
380 }
381 
382 
383 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
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:104
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
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:62
update
mesh update()
Foam::polyTopoChanger::findModifierID
label findModifierID(const word &modName) const
Find modifier given a name.
Definition: polyTopoChanger.C:319
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:166
Foam::polyTopoChanger::topoChangeRequest
autoPtr< polyTopoChange > topoChangeRequest() const
Return topology change request.
Definition: polyTopoChanger.C:212
Foam::polyTopoChanger::update
void update(const mapPolyMesh &m)
Force recalculation of locally stored data on topological change.
Definition: polyTopoChanger.C:246
Foam::polyTopoChanger::names
wordList names() const
Return a list of patch names.
Definition: polyTopoChanger.C:151
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::polyTopoChanger::addTopologyModifiers
void addTopologyModifiers(const List< polyMeshModifier * > &tm)
Add given set of topology modifiers to the topoChanger.
Definition: polyTopoChanger.C:296
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:232
Foam::polyTopoChanger::types
wordList types() const
Return a list of patch types.
Definition: polyTopoChanger.C:136
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
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:354
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::polyTopoChanger::writeData
bool writeData(Ostream &) const
writeData member function required by regIOobject
Definition: polyTopoChanger.C:345
Foam::polyTopoChanger::changeMesh
autoPtr< mapPolyMesh > changeMesh(const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Definition: polyTopoChanger.C:265
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:122
Foam::PtrList< polyMeshModifier >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
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
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:71
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::polyTopoChanger::operator==
bool operator==(const polyTopoChanger &) const
Definition: polyTopoChanger.C:360
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::regIOobject::close
void close()
Close Istream.
Definition: regIOobjectRead.C:182
Foam::List< word >
Foam::IOobject::readOpt
readOption readOpt() const
The read option.
Definition: IOobjectI.H:165
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:121
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:123
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:275
Foam::IOobject::readOption
readOption
Enumeration defining the read options.
Definition: IOobject.H:118
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:140
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:224
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:122
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303
Foam::regIOobject::headerOk
bool headerOk()
Read and check header info.
Definition: regIOobject.C:453
Foam::IOobject::MUST_READ
Definition: IOobject.H:120