1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 "mixerFvMesh.H"
28 #include <OpenFOAM/Time.H>
29 #include <meshTools/regionSplit.H>
30 #include <dynamicMesh/slidingInterface.H>
31 #include <OpenFOAM/addToRunTimeSelectionTable.H>
32 #include <OpenFOAM/mapPolyMesh.H>
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(mixerFvMesh, 0);
40 addToRunTimeSelectionTable(topoChangerFvMesh, mixerFvMesh, IOobject);
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 void Foam::mixerFvMesh::addZonesAndModifiers()
48 // Add zones and modifiers for motion action
55 || topoChanger_.size()
58 Info<< "void mixerFvMesh::addZonesAndModifiers() : "
59 << "Zones and modifiers already present. Skipping."
65 Info<< "Time = " << time().timeName() << endl
66 << "Adding zones and modifiers to the mesh" << endl;
69 List<pointZone*> pz(1);
71 // Add an empty zone for cut points
82 // Do face zones for slider
84 List<faceZone*> fz(3);
87 const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
88 const polyPatch& innerSlider =
89 boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
91 labelList isf(innerSlider.size());
95 isf[i] = innerSlider.start() + i;
102 boolList(innerSlider.size(), false),
108 const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
109 const polyPatch& outerSlider =
110 boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
112 labelList osf(outerSlider.size());
116 osf[i] = outerSlider.start() + i;
123 boolList(outerSlider.size(), false),
128 // Add empty zone for cut faces
138 List<cellZone*> cz(1);
140 // Mark every cell with its topological region
141 regionSplit rs(*this);
143 // Get the region of the cell containing the origin.
144 label originRegion = rs[findNearestCell(cs().origin())];
146 labelList movingCells(nCells());
147 label nMovingCells = 0;
151 if (rs[cellI] == originRegion)
153 movingCells[nMovingCells] = cellI;
158 movingCells.setSize(nMovingCells);
159 Info << "Number of cells in the moving region: " << nMovingCells << endl;
169 Info << "Adding point, face and cell zones" << endl;
170 addZones(pz, fz, cz);
172 // Add a topology modifier
173 Info << "Adding topology modifiers" << endl;
174 topoChanger_.setSize(1);
183 outerSliderName + "Zone",
184 innerSliderName + "Zone",
189 slidingInterface::INTEGRAL
192 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
198 void Foam::mixerFvMesh::calcMovingMasks() const
202 Info<< "void mixerFvMesh::calcMovingMasks() const : "
203 << "Calculating point and cell masks"
207 if (movingPointsMaskPtr_)
209 FatalErrorIn("void mixerFvMesh::calcMovingMasks() const")
210 << "point mask already calculated"
211 << abort(FatalError);
214 // Set the point mask
215 movingPointsMaskPtr_ = new scalarField(points().size(), 0);
216 scalarField& movingPointsMask = *movingPointsMaskPtr_;
218 const cellList& c = cells();
219 const faceList& f = faces();
221 const labelList& cellAddr =
222 cellZones()[cellZones().findZoneID("movingCells")];
224 forAll (cellAddr, cellI)
226 const cell& curCell = c[cellAddr[cellI]];
228 forAll (curCell, faceI)
230 // Mark all the points as moving
231 const face& curFace = f[curCell[faceI]];
233 forAll (curFace, pointI)
235 movingPointsMask[curFace[pointI]] = 1;
240 const word innerSliderZoneName
242 word(motionDict_.subDict("slider").lookup("inside"))
246 const labelList& innerSliderAddr =
247 faceZones()[faceZones().findZoneID(innerSliderZoneName)];
249 forAll (innerSliderAddr, faceI)
251 const face& curFace = f[innerSliderAddr[faceI]];
253 forAll (curFace, pointI)
255 movingPointsMask[curFace[pointI]] = 1;
259 const word outerSliderZoneName
261 word(motionDict_.subDict("slider").lookup("outside"))
265 const labelList& outerSliderAddr =
266 faceZones()[faceZones().findZoneID(outerSliderZoneName)];
268 forAll (outerSliderAddr, faceI)
270 const face& curFace = f[outerSliderAddr[faceI]];
272 forAll (curFace, pointI)
274 movingPointsMask[curFace[pointI]] = 0;
280 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
282 // Construct from components
283 Foam::mixerFvMesh::mixerFvMesh
288 topoChangerFvMesh(io),
301 ).subDict(typeName + "Coeffs")
305 coordinateSystem::New
308 motionDict_.subDict("coordinateSystem")
311 rpm_(readScalar(motionDict_.lookup("rpm"))),
312 movingPointsMaskPtr_(NULL)
314 addZonesAndModifiers();
316 Info<< "Mixer mesh:" << nl
317 << " origin: " << cs().origin() << nl
318 << " axis: " << cs().axis() << nl
319 << " rpm: " << rpm_ << endl;
323 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
325 Foam::mixerFvMesh::~mixerFvMesh()
327 deleteDemandDrivenData(movingPointsMaskPtr_);
330 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
332 // Return moving points mask. Moving points marked with 1
333 const Foam::scalarField& Foam::mixerFvMesh::movingPointsMask() const
335 if (!movingPointsMaskPtr_)
340 return *movingPointsMaskPtr_;
344 bool Foam::mixerFvMesh::update()
346 // Rotational speed needs to be converted from rpm
349 csPtr_->globalPosition
351 csPtr_->localPosition(points())
352 + vector(0, rpm_*360.0*time().deltaT().value()/60.0, 0)
357 // Make changes. Use inflation (so put new points in topoChangeMap)
358 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
360 if (topoChangeMap.valid())
364 Info << "Mesh topology is changing" << endl;
367 deleteDemandDrivenData(movingPointsMaskPtr_);
372 csPtr_->globalPosition
374 csPtr_->localPosition(oldPoints())
375 + vector(0, rpm_*360.0*time().deltaT().value()/60.0, 0)
384 // ************************ vim: set sw=4 sts=4 et: ************************ //