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 "mixerGgiFvMesh.H"
28 #include "regionSplit.H"
29 #include "ggiPolyPatch.H"
30 #include "polyPatchID.H"
31 #include "addToRunTimeSelectionTable.H"
32 #include "mapPolyMesh.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(mixerGgiFvMesh, 0);
39 addToRunTimeSelectionTable(dynamicFvMesh, mixerGgiFvMesh, IOobject);
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 void Foam::mixerGgiFvMesh::addZonesAndModifiers()
47 // Add zones and modifiers for motion action
49 if (cellZones().size() > 0)
51 Info<< "void mixerGgiFvMesh::addZonesAndModifiers() : "
52 << "Zones and modifiers already present. Skipping."
58 Info<< "Time = " << time().timeName() << endl
59 << "Adding zones and modifiers to the mesh" << endl;
62 List<pointZone*> pz(0);
63 List<faceZone*> fz(0);
64 List<cellZone*> cz(1);
66 // Copy the face zones associated with the GGI interfaces
67 if (faceZones().size() > 0)
70 Info << "Copying existing face zones" << endl;
72 fz.setSize(faceZones().size());
74 forAll (faceZones(), i)
76 fz[i] = faceZones()[i].clone(faceZones()).ptr();
80 regionSplit rs(*this);
82 // Get the region of the cell containing the origin.
83 label originRegion = rs[findNearestCell(cs().origin())];
85 labelList movingCells(nCells());
86 label nMovingCells = 0;
90 if (rs[cellI] == originRegion)
92 movingCells[nMovingCells] = cellI;
97 movingCells.setSize(nMovingCells);
98 Info << "Number of cells in the moving region: " << nMovingCells << endl;
108 Info << "Adding point, face and cell zones" << endl;
110 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 label movingCellsID = cellZones().findZoneID("movingCells");
143 if (movingCellsID < 0)
145 FatalErrorIn("void mixerGgiFvMesh::calcMovingMasks() const")
146 << "Cannot find moving cell zone ID"
147 << abort(FatalError);
150 const labelList& cellAddr = cellZones()[movingCellsID];
152 forAll (cellAddr, cellI)
154 const cell& curCell = c[cellAddr[cellI]];
156 forAll (curCell, faceI)
158 // Mark all the points as moving
159 const face& curFace = f[curCell[faceI]];
161 forAll (curFace, pointI)
163 movingPointsMask[curFace[pointI]] = 1;
168 // Grab the ggi patches on the moving side
169 wordList movingPatches(dict_.subDict("slider").lookup("moving"));
171 forAll (movingPatches, patchI)
173 const label movingSliderID =
174 boundaryMesh().findPatchID(movingPatches[patchI]);
176 if (movingSliderID < 0)
178 FatalErrorIn("void mixerGgiFvMesh::calcMovingMasks() const")
179 << "Moving slider named " << movingPatches[patchI]
180 << " not found. Valid patch names: "
181 << boundaryMesh().names() << abort(FatalError);
184 const ggiPolyPatch& movingGgiPatch =
185 refCast<const ggiPolyPatch>(boundaryMesh()[movingSliderID]);
187 const labelList& movingSliderAddr = movingGgiPatch.zone();
189 forAll (movingSliderAddr, faceI)
191 const face& curFace = f[movingSliderAddr[faceI]];
193 forAll (curFace, pointI)
195 movingPointsMask[curFace[pointI]] = 1;
200 // Grab the ggi patches on the static side
201 wordList staticPatches(dict_.subDict("slider").lookup("static"));
203 forAll (staticPatches, patchI)
205 const label staticSliderID =
206 boundaryMesh().findPatchID(staticPatches[patchI]);
208 if (staticSliderID < 0)
210 FatalErrorIn("void mixerGgiFvMesh::calcMovingMasks() const")
211 << "Static slider named " << staticPatches[patchI]
212 << " not found. Valid patch names: "
213 << boundaryMesh().names() << abort(FatalError);
216 const ggiPolyPatch& staticGgiPatch =
217 refCast<const ggiPolyPatch>(boundaryMesh()[staticSliderID]);
219 const labelList& staticSliderAddr = staticGgiPatch.zone();
221 forAll (staticSliderAddr, faceI)
223 const face& curFace = f[staticSliderAddr[faceI]];
225 forAll (curFace, pointI)
227 movingPointsMask[curFace[pointI]] = 0;
234 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
236 // Construct from components
237 Foam::mixerGgiFvMesh::mixerGgiFvMesh
255 ).subDict(typeName + "Coeffs")
260 dict_.subDict("coordinateSystem")
262 rpm_(readScalar(dict_.lookup("rpm"))),
263 movingPointsMaskPtr_(NULL)
265 // Make sure the coordinate system does not operate in degrees
266 // Bug fix, HJ, 3/Oct/2011
267 if (!cs_.inDegrees())
269 WarningIn("mixerGgiFvMesh::mixerGgiFvMesh(const IOobject& io)")
270 << "Mixer coordinate system is set to operate in radians. "
271 << "Changing to rad for correct calculation of angular velocity."
273 << "To remove this message please add entry" << nl << nl
274 << "inDegrees true;" << nl << nl
275 << "to the specification of the coordinate system"
278 cs_.inDegrees() = true;
281 addZonesAndModifiers();
283 Info<< "Mixer mesh:" << nl
284 << " origin: " << cs().origin() << nl
285 << " axis : " << cs().axis() << nl
286 << " rpm : " << rpm_ << endl;
290 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
292 Foam::mixerGgiFvMesh::~mixerGgiFvMesh()
294 deleteDemandDrivenData(movingPointsMaskPtr_);
298 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
300 // Return moving points mask. Moving points marked with 1
301 const Foam::scalarField& Foam::mixerGgiFvMesh::movingPointsMask() const
303 if (!movingPointsMaskPtr_)
308 return *movingPointsMaskPtr_;
312 bool Foam::mixerGgiFvMesh::update()
314 // Rotational speed needs to be converted from rpm
319 cs_.localPosition(allPoints())
320 + vector(0, rpm_*360.0*time().deltaT().value()/60.0, 0)
325 // The mesh is not morphing, but flux re-calculation is required
331 // ************************************************************************* //