1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "multiMixerFvMesh.H"
28 #include "regionSplit.H"
29 #include "slidingInterface.H"
30 #include "mapPolyMesh.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(multiMixerFvMesh, 0);
39 addToRunTimeSelectionTable(topoChangerFvMesh, multiMixerFvMesh, IOobject);
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 void Foam::multiMixerFvMesh::addZonesAndModifiers()
47 // Add zones and modifiers for motion action
51 pointZones().size() > 0
52 || faceZones().size() > 0
53 || cellZones().size() > 0
56 Info<< "void multiMixerFvMesh::addZonesAndModifiers() : "
57 << "Zones and modifiers already present. Skipping."
60 if (topoChanger_.size() == 0 && useTopoSliding())
64 "void multiMixerFvMesh::addZonesAndModifiers()"
65 ) << "Mesh modifiers not read properly"
72 Info<< "Time = " << time().timeName() << endl
73 << "Adding zones and modifiers to the mesh. " << rotors_.size()
74 << " sliders found" << endl;
76 DynamicList<pointZone*> pz(rotors_.size());
77 DynamicList<faceZone*> fz(3*rotors_.size());
78 DynamicList<cellZone*> cz(rotors_.size());
80 // Create region split: mark every cell with its topological region
81 regionSplit rs(*this);
83 Info << "Adding point, face and cell zones" << endl;
84 forAll (rotors_, rotorI)
86 rotors_[rotorI].addZones(pz, fz, cz, rs);
90 List<pointZone*> pzList;
91 pzList.transfer(pz.shrink());
93 List<faceZone*> fzList;
94 fzList.transfer(fz.shrink());
96 List<cellZone*> czList;
97 czList.transfer(cz.shrink());
99 addZones(pzList, fzList, czList);
102 if (useTopoSliding())
104 topoChanger_.setSize(rotors_.size());
107 forAll (rotors_, rotorI)
109 rotors_[rotorI].addModifiers(topoChanger_, nextI);
112 Info<< "Adding topology modifiers. nModifiers = " << nextI << endl;
114 // Resize and set topo changer
115 topoChanger_.setSize(nextI);
116 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
117 topoChanger_.write();
120 // Write mesh with new zones
125 bool Foam::multiMixerFvMesh::useTopoSliding() const
129 forAll (rotors_, rotorI)
131 result = (result || rotors_[rotorI].useTopoSliding());
138 void Foam::multiMixerFvMesh::checkRotors() const
140 // Check if all sliding interfaces are in the same state
141 bool rotorState = attached();
143 forAll (topoChanger_, topoI)
145 if (isA<slidingInterface>(topoChanger_[topoI]))
147 const slidingInterface& slider =
148 refCast<const slidingInterface>(topoChanger_[topoI]);
150 if (rotorState != slider.attached())
154 "void multiMixerFvMesh::checkRotors() const"
155 ) << "Some sliders are attached and some are not. "
156 << "Out of sync sliders cannot be handled."
157 << abort(FatalError);
164 bool Foam::multiMixerFvMesh::attached() const
166 // Check if interfaces are attached AND if they are in sync
167 bool attached = false;
169 forAll (topoChanger_, topoI)
171 if (isA<slidingInterface>(topoChanger_[topoI]))
174 || refCast<const slidingInterface>(topoChanger_[0]).attached();
182 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
184 // Construct from components
185 Foam::multiMixerFvMesh::multiMixerFvMesh
190 topoChangerFvMesh(io),
203 ).subDict(typeName + "Coeffs")
206 attachDetach_(dict_.lookupOrDefault<bool>("attachDetach", true))
208 // Read rotors from the dictionary
209 PtrList<entry> rotorEntries(dict_.lookup("rotors"));
210 rotors_.setSize(rotorEntries.size());
212 forAll (rotorEntries, rotorI)
219 rotorEntries[rotorI].keyword(),
221 rotorEntries[rotorI].dict()
226 addZonesAndModifiers();
230 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
232 Foam::multiMixerFvMesh::~multiMixerFvMesh()
236 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
238 bool Foam::multiMixerFvMesh::update()
240 if (useTopoSliding())
242 // Detaching the interface
243 if (attached() && attachDetach_)
245 Info << "Detaching rotors" << endl;
246 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
248 forAll (rotors_, rotorI)
250 rotors_[rotorI].updateTopology();
255 // Accumulate point motion
256 vectorField pointMotion(allPoints().size(), vector::zero);
258 forAll (rotors_, rotorI)
260 pointMotion += rotors_[rotorI].pointMotion();
264 pointField oldPointsNew = allPoints();
267 movePoints(allPoints() + pointMotion);
269 if (useTopoSliding())
271 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh();
272 bool morphing = topoChangeMap.valid();
276 Info << "Attaching rotors" << endl;
278 forAll (rotors_, rotorI)
280 rotors_[rotorI].updateTopology();
283 // Move the sliding interface points to correct position
284 pointField mappedOldPointsNew(allPoints().size());
285 mappedOldPointsNew.map(oldPointsNew, topoChangeMap->pointMap());
287 // Note: using setOldPoints instead of movePoints.
289 setOldPoints(mappedOldPointsNew);
294 // Move the sliding interface points to correct position
295 movePoints(topoChangeMap->preMotionPoints());
303 // ************************************************************************* //