1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "polyTopoChanger.H"
29 #include "polyTopoChange.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(polyTopoChanger, 0);
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 void Foam::polyTopoChanger::readModifiers()
46 readOpt() == IOobject::MUST_READ
47 || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
50 PtrList<polyMeshModifier>& modifiers = *this;
53 Istream& is = readStream(typeName);
55 PtrList<entry> patchEntries(is);
56 modifiers.setSize(patchEntries.size());
58 forAll(modifiers, modifierI)
65 patchEntries[modifierI].keyword(),
66 patchEntries[modifierI].dict(),
73 // Check state of IOstream
76 "polyTopoChanger::polyTopoChanger"
77 "(const IOobject&, const polyMesh&)"
85 // Read constructor given IOobject and a polyMesh reference
86 Foam::polyTopoChanger::polyTopoChanger
92 PtrList<polyMeshModifier>(),
100 // Read constructor given IOobject and a polyMesh reference
101 Foam::polyTopoChanger::polyTopoChanger(polyMesh& mesh)
103 PtrList<polyMeshModifier>(),
109 mesh.time().findInstance
113 IOobject::READ_IF_PRESENT
117 IOobject::READ_IF_PRESENT,
127 // Return a list of modifier types
128 Foam::wordList Foam::polyTopoChanger::types() const
130 const PtrList<polyMeshModifier>& modifiers = *this;
132 wordList t(modifiers.size());
134 forAll (modifiers, modifierI)
136 t[modifierI] = modifiers[modifierI].type();
143 // Return a list of modifier names
144 Foam::wordList Foam::polyTopoChanger::names() const
146 const PtrList<polyMeshModifier>& modifiers = *this;
148 wordList t(modifiers.size());
150 forAll (modifiers, modifierI)
152 t[modifierI] = modifiers[modifierI].name();
159 // Is topology change required
160 bool Foam::polyTopoChanger::changeTopology() const
162 // Go through all mesh modifiers and accumulate the morphing information
163 const PtrList<polyMeshModifier>& topoChanges = *this;
165 bool triggerChange = false;
167 forAll (topoChanges, morphI)
169 if (topoChanges[morphI].active())
171 bool curTriggerChange = topoChanges[morphI].changeTopology();
175 Info<< "Modifier " << morphI << " named "
176 << topoChanges[morphI].name();
178 if (curTriggerChange)
180 Info << " morphing" << endl;
184 Info << " unchanged" << endl;
188 triggerChange = triggerChange || curTriggerChange;
194 Info<< "Modifier " << morphI << " named "
195 << topoChanges[morphI].name() << " inactive" << endl;
201 return triggerChange;
205 // Return topology change request
206 Foam::autoPtr<Foam::polyTopoChange>
207 Foam::polyTopoChanger::topoChangeRequest() const
209 // Collect changes from all modifiers
210 const PtrList<polyMeshModifier>& topoChanges = *this;
212 polyTopoChange* refPtr(new polyTopoChange(mesh()));
213 polyTopoChange& ref = *refPtr;
215 forAll (topoChanges, morphI)
217 if (topoChanges[morphI].active())
219 topoChanges[morphI].setRefinement(ref);
223 return autoPtr<polyTopoChange>(refPtr);
227 // Correct polyTopoChanger after moving points
228 void Foam::polyTopoChanger::modifyMotionPoints(pointField& p) const
230 const PtrList<polyMeshModifier>& topoChanges = *this;
232 forAll (topoChanges, morphI)
234 if (topoChanges[morphI].active())
236 topoChanges[morphI].modifyMotionPoints(p);
242 // Force recalculation of locally stored data on topological change
243 void Foam::polyTopoChanger::update(const mapPolyMesh& m)
245 // Go through all mesh modifiers and accumulate the morphing information
246 PtrList<polyMeshModifier>& topoChanges = *this;
248 forAll (topoChanges, morphI)
250 topoChanges[morphI].updateMesh(m);
253 // Force the mesh modifiers to auto-write. This allows us to
254 // preserve the current state of modifiers corresponding with
256 writeOpt() = IOobject::AUTO_WRITE;
257 instance() = mesh_.time().timeName();
261 Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChanger::changeMesh
264 const bool syncParallel,
265 const bool orderCells,
266 const bool orderPoints
269 if (changeTopology())
271 autoPtr<polyTopoChange> ref = topoChangeRequest();
273 autoPtr<mapPolyMesh> topoChangeMap = ref().changeMesh
282 update(topoChangeMap());
283 mesh_.updateMesh(topoChangeMap());
284 return topoChangeMap;
288 return autoPtr<mapPolyMesh>(NULL);
293 // Add mesh modifiers to the morph engine
294 void Foam::polyTopoChanger::addTopologyModifiers
296 const List<polyMeshModifier*>& tm
301 // Copy the patch pointers
304 if (tm[tmI]->topoChanger() != *this)
308 "void polyTopoChanger::addTopologyModifiers("
309 "const List<polyMeshModifier*>& tm)"
310 ) << "Mesh modifier created with different mesh reference."
311 << abort(FatalError);
316 writeOpt() = IOobject::AUTO_WRITE;
320 Foam::label Foam::polyTopoChanger::findModifierID
325 const PtrList<polyMeshModifier>& topoChanges = *this;
327 forAll (topoChanges, morphI)
329 if (topoChanges[morphI].name() == modName)
335 // Modifier not found
338 Info<< "label polyTopoChanger::::findModifierID(const word& "
340 << "Modifier named " << modName << " not found. "
341 << "List of available modifier names: " << names() << endl;
344 // Not found, return -1
349 // writeData member function required by regIOobject
350 bool Foam::polyTopoChanger::writeData(Ostream& os) const
357 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
359 bool Foam::polyTopoChanger::operator!=(const polyTopoChanger& me) const
365 bool Foam::polyTopoChanger::operator==(const polyTopoChanger& me) const
371 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
373 Foam::Ostream& Foam::operator<<(Ostream& os, const polyTopoChanger& mme)
375 os << mme.size() << nl << token::BEGIN_LIST;
379 mme[mmeI].writeDict(os);
382 os << token::END_LIST;
388 // ************************************************************************* //