polyTopoChanger.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-2018 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 "polyTopoChanger.H"
27 #include "polyMesh.H"
28 #include "polyTopoChange.H"
29 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(polyTopoChanger, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
41 void Foam::polyTopoChanger::readModifiers()
42 {
43  if
44  (
45  readOpt() == IOobject::MUST_READ
46  || readOpt() == IOobject::MUST_READ_IF_MODIFIED
47  || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
48  )
49  {
50  if (readOpt() == IOobject::MUST_READ_IF_MODIFIED)
51  {
53  << "Specified IOobject::MUST_READ_IF_MODIFIED but class"
54  << " does not support automatic re-reading."
55  << endl;
56  }
57 
58 
59  PtrList<polyMeshModifier>& modifiers = *this;
60 
61  // Read modifiers
62  Istream& is = readStream(typeName);
63 
64  PtrList<entry> patchEntries(is);
65  modifiers.setSize(patchEntries.size());
66 
67  forAll(modifiers, modifierI)
68  {
69  modifiers.set
70  (
71  modifierI,
73  (
74  patchEntries[modifierI].keyword(),
75  patchEntries[modifierI].dict(),
76  modifierI,
77  *this
78  )
79  );
80  }
81 
82  // Check state of IOstream
83  is.check("polyTopoChanger::readModifiers()");
84 
85  close();
86  }
87 }
88 
89 
91 (
92  const IOobject& io,
93  polyMesh& mesh
94 )
95 :
97  regIOobject(io),
98  mesh_(mesh)
99 {
100  readModifiers();
101 }
102 
103 
105 :
108  (
109  IOobject
110  (
111  "meshModifiers",
112  mesh.time().findInstance
113  (
114  mesh.meshDir(),
115  "meshModifiers",
116  IOobject::READ_IF_PRESENT
117  ),
118  mesh.meshSubDir,
119  mesh,
120  IOobject::READ_IF_PRESENT,
121  IOobject::NO_WRITE
122  )
123  ),
124  mesh_(mesh)
125 {
126  readModifiers();
127 }
128 
129 
131 {
132  const PtrList<polyMeshModifier>& modifiers = *this;
133 
134  wordList t(modifiers.size());
135 
136  forAll(modifiers, modifierI)
137  {
138  t[modifierI] = modifiers[modifierI].type();
139  }
140 
141  return t;
142 }
143 
144 
146 {
147  const PtrList<polyMeshModifier>& modifiers = *this;
148 
149  wordList t(modifiers.size());
150 
151  forAll(modifiers, modifierI)
152  {
153  t[modifierI] = modifiers[modifierI].name();
154  }
155 
156  return t;
157 }
158 
159 
161 {
162  // Go through all mesh modifiers and accumulate the morphing information
163  const PtrList<polyMeshModifier>& topoChanges = *this;
164 
165  bool triggerChange = false;
166 
167  forAll(topoChanges, morphI)
168  {
169  if (topoChanges[morphI].active())
170  {
171  bool curTriggerChange = topoChanges[morphI].changeTopology();
172 
173  if (debug)
174  {
175  Info<< "Modifier " << morphI << " named "
176  << topoChanges[morphI].name();
177 
178  if (curTriggerChange)
179  {
180  Info<< " morphing" << endl;
181  }
182  else
183  {
184  Info<< " unchanged" << endl;
185  }
186  }
187 
188  triggerChange = triggerChange || curTriggerChange;
189  }
190  else
191  {
192  if (debug)
193  {
194  Info<< "Modifier " << morphI << " named "
195  << topoChanges[morphI].name() << " inactive" << endl;
196  }
197  }
198 
199  }
200 
201  return triggerChange;
202 }
203 
204 
207 {
208  // Collect changes from all modifiers
209  const PtrList<polyMeshModifier>& topoChanges = *this;
210 
211  polyTopoChange* refPtr(new polyTopoChange(mesh()));
212  polyTopoChange& ref = *refPtr;
213 
214  forAll(topoChanges, morphI)
215  {
216  if (topoChanges[morphI].active())
217  {
218  topoChanges[morphI].setRefinement(ref);
219  }
220  }
221 
222  return autoPtr<polyTopoChange>(refPtr);
223 }
224 
225 
227 {
228  const PtrList<polyMeshModifier>& topoChanges = *this;
229 
230  forAll(topoChanges, morphI)
231  {
232  if (topoChanges[morphI].active())
233  {
234  topoChanges[morphI].modifyMotionPoints(p);
235  }
236  }
237 }
238 
239 
241 {
242  // Go through all mesh modifiers and accumulate the morphing information
243  PtrList<polyMeshModifier>& topoChanges = *this;
244 
245  forAll(topoChanges, morphI)
246  {
247  topoChanges[morphI].updateMesh(m);
248  }
249 
250  // Force the mesh modifiers to auto-write. This allows us to
251  // preserve the current state of modifiers corresponding with
252  // the mesh.
254  instance() = mesh_.time().timeName();
255 }
256 
257 
259 (
260  const bool inflate,
261  const bool syncParallel,
262  const bool orderCells,
263  const bool orderPoints
264 )
265 {
266  if (changeTopology())
267  {
269 
270  autoPtr<mapPolyMesh> topoChangeMap = ref().changeMesh
271  (
272  mesh_,
273  inflate,
274  syncParallel,
275  orderCells,
276  orderPoints
277  );
278 
279  update(topoChangeMap());
280  mesh_.updateMesh(topoChangeMap());
281  return topoChangeMap;
282  }
283  else
284  {
285  return autoPtr<mapPolyMesh>(nullptr);
286  }
287 }
288 
289 
291 (
292  const List<polyMeshModifier*>& tm
293 )
294 {
295  setSize(tm.size());
296 
297  // Copy the patch pointers
298  forAll(tm, tmI)
299  {
300  if (tm[tmI]->topoChanger() != *this)
301  {
303  << "Mesh modifier created with different mesh reference."
304  << abort(FatalError);
305  }
306  set(tmI, tm[tmI]);
307  }
308 
310 }
311 
312 
314 (
315  const word& modName
316 ) const
317 {
318  const PtrList<polyMeshModifier>& topoChanges = *this;
319 
320  forAll(topoChanges, morphI)
321  {
322  if (topoChanges[morphI].name() == modName)
323  {
324  return morphI;
325  }
326  }
327 
328  // Modifier not found
329  if (debug)
330  {
332  << "List of available modifier names: " << names() << endl;
333  }
334 
335  // Not found, return -1
336  return -1;
337 }
338 
339 
341 {
342  os << *this;
343  return os.good();
344 }
345 
346 
347 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
348 
350 {
351  return &me != this;
352 }
353 
354 
356 {
357  return &me == this;
358 }
359 
360 
361 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
362 
364 {
365  os << mme.size() << nl << token::BEGIN_LIST;
366 
367  forAll(mme, mmeI)
368  {
369  mme[mmeI].writeDict(os);
370  }
371 
372  os << token::END_LIST;
373 
374  return os;
375 }
376 
377 
378 // ************************************************************************* //
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
autoPtr< polyTopoChange > topoChangeRequest() const
Return topology change request.
void update(const mapPolyMesh &m)
Force recalculation of locally stored data on topological change.
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
const word & name() const
Return name.
Definition: IOobject.H:303
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool operator!=(const polyTopoChanger &) const
static autoPtr< polyMeshModifier > New(const word &name, const dictionary &dict, const label index, const polyTopoChanger &mme)
Select constructed from dictionary.
polyMesh & mesh_
Reference to mesh.
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:636
label findModifierID(const word &modName) const
Find modifier given a name.
autoPtr< mapPolyMesh > changeMesh(const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
bool changeTopology() const
Is topology change required.
virtual void updateMesh(const mapPolyMesh &mpm)
Update the mesh corresponding to given map.
List of mesh modifiers defining the mesh dynamics.
A class for handling words, derived from string.
Definition: word.H:59
Virtual base class for mesh modifiers.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void modifyMotionPoints(pointField &) const
Modify point motion.
wordList types() const
Return a list of patch types.
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
bool writeData(Ostream &) const
writeData member function required by regIOobject
const Time & time() const
Return time.
defineTypeNameAndDebug(combustionModel, 0)
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
writeOption writeOpt() const
Definition: IOobject.H:363
const fileName & instance() const
Definition: IOobject.H:390
#define WarningInFunction
Report a warning using Foam::Warning.
const dimensionedScalar me
Electron mass.
Direct mesh changes based on v1.3 polyTopoChange syntax.
Ostream & operator<<(Ostream &, const ensightPart &)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
messageStream Info
polyTopoChanger(const IOobject &, polyMesh &)
Read constructor given IOobject and a polyMesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
bool operator==(const polyTopoChanger &) const
volScalarField & p
rDeltaT ref()
const polyMesh & mesh() const
Return the mesh reference.
void addTopologyModifiers(const List< polyMeshModifier *> &tm)
Add given set of topology modifiers to the topoChanger.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.
wordList names() const
Return a list of patch names.