1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2006-7 H. Jasak All rights reserved
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 "mixerGgiFvMesh.H"
29 #include "regionSplit.H"
30 #include "ggiPolyPatch.H"
31 #include "polyPatchID.H"
32 #include "addToRunTimeSelectionTable.H"
33 #include "mapPolyMesh.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(mixerGgiFvMesh, 0);
40 addToRunTimeSelectionTable(dynamicFvMesh, mixerGgiFvMesh, IOobject);
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 void Foam::mixerGgiFvMesh::addZonesAndModifiers()
48 // Add zones and modifiers for motion action
50 if (cellZones().size() > 0)
52 Info<< "void mixerGgiFvMesh::addZonesAndModifiers() : "
53 << "Zones and modifiers already present. Skipping."
59 Info<< "Time = " << time().timeName() << endl
60 << "Adding zones and modifiers to the mesh" << endl;
63 List<pointZone*> pz(0);
64 List<faceZone*> fz(0);
65 List<cellZone*> cz(1);
67 // Copy the face zones associated with the GGI interfaces
68 if (faceZones().size() > 0)
71 Info << "Copying existing face zones" << endl;
73 fz.setSize(faceZones().size());
75 forAll (faceZones(), i)
77 fz[i] = faceZones()[i].clone(faceZones()).ptr();
81 regionSplit rs(*this);
83 // Get the region of the cell containing the origin.
84 label originRegion = rs[findNearestCell(cs().origin())];
86 labelList movingCells(nCells());
87 label nMovingCells = 0;
91 if (rs[cellI] == originRegion)
93 movingCells[nMovingCells] = cellI;
98 movingCells.setSize(nMovingCells);
99 Info << "Number of cells in the moving region: " << nMovingCells << endl;
109 Info << "Adding point, face and cell zones" << endl;
111 addZones(pz, fz, cz);
118 void Foam::mixerGgiFvMesh::calcMovingMasks() const
122 Info<< "void mixerGgiFvMesh::calcMovingMasks() const : "
123 << "Calculating point and cell masks"
127 if (movingPointsMaskPtr_)
129 FatalErrorIn("void mixerGgiFvMesh::calcMovingMasks() const")
130 << "point mask already calculated"
131 << abort(FatalError);
134 // Set the point mask
135 movingPointsMaskPtr_ = new scalarField(allPoints().size(), 0);
136 scalarField& movingPointsMask = *movingPointsMaskPtr_;
138 const cellList& c = cells();
139 const faceList& f = allFaces();
141 const labelList& cellAddr =
142 cellZones()[cellZones().findZoneID("movingCells")];
144 forAll (cellAddr, cellI)
146 const cell& curCell = c[cellAddr[cellI]];
148 forAll (curCell, faceI)
150 // Mark all the points as moving
151 const face& curFace = f[curCell[faceI]];
153 forAll (curFace, pointI)
155 movingPointsMask[curFace[pointI]] = 1;
160 // Grab the ggi patches on the moving side
161 wordList movingPatches(dict_.subDict("slider").lookup("moving"));
163 forAll (movingPatches, patchI)
165 polyPatchID movingSliderID
167 movingPatches[patchI],
171 if (!movingSliderID.active())
173 FatalErrorIn("void mixerGgiFvMesh::calcMovingMasks() const")
174 << "Moving slider named " << movingPatches[patchI]
175 << " not found. Valid patch names: "
176 << boundaryMesh().names() << abort(FatalError);
179 const ggiPolyPatch& movingGgiPatch =
180 refCast<const ggiPolyPatch>(boundaryMesh()[movingSliderID.index()]);
182 const labelList& movingSliderAddr = movingGgiPatch.zone();
184 forAll (movingSliderAddr, faceI)
186 const face& curFace = f[movingSliderAddr[faceI]];
188 forAll (curFace, pointI)
190 movingPointsMask[curFace[pointI]] = 1;
195 // Grab the ggi patches on the static side
196 wordList staticPatches(dict_.subDict("slider").lookup("static"));
198 forAll (staticPatches, patchI)
200 polyPatchID staticSliderID
202 staticPatches[patchI],
206 if (!staticSliderID.active())
208 FatalErrorIn("void mixerGgiFvMesh::calcMovingMasks() const")
209 << "Static slider named " << staticPatches[patchI]
210 << " not found. Valid patch names: "
211 << boundaryMesh().names() << abort(FatalError);
214 const ggiPolyPatch& staticGgiPatch =
215 refCast<const ggiPolyPatch>(boundaryMesh()[staticSliderID.index()]);
217 const labelList& staticSliderAddr = staticGgiPatch.zone();
219 forAll (staticSliderAddr, faceI)
221 const face& curFace = f[staticSliderAddr[faceI]];
223 forAll (curFace, pointI)
225 movingPointsMask[curFace[pointI]] = 0;
232 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
234 // Construct from components
235 Foam::mixerGgiFvMesh::mixerGgiFvMesh
253 ).subDict(typeName + "Coeffs")
257 coordinateSystem::New
260 dict_.subDict("coordinateSystem")
263 rpm_(readScalar(dict_.lookup("rpm"))),
264 movingPointsMaskPtr_(NULL)
266 addZonesAndModifiers();
268 Info<< "Mixer mesh:" << nl
269 << " origin: " << cs().origin() << nl
270 << " axis : " << cs().axis() << nl
271 << " rpm : " << rpm_ << endl;
275 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
277 Foam::mixerGgiFvMesh::~mixerGgiFvMesh()
279 deleteDemandDrivenData(movingPointsMaskPtr_);
283 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
285 // Return moving points mask. Moving points marked with 1
286 const Foam::scalarField& Foam::mixerGgiFvMesh::movingPointsMask() const
288 if (!movingPointsMaskPtr_)
293 return *movingPointsMaskPtr_;
297 bool Foam::mixerGgiFvMesh::update()
299 // Rotational speed needs to be converted from rpm
302 csPtr_->globalPosition
304 csPtr_->localPosition(allPoints())
305 + vector(0, rpm_*360.0*time().deltaT().value()/60.0, 0)
310 // The mesh is not morphing
315 // ************************************************************************* //