Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / dynamicFvMesh / mixerGgiFvMesh / mixerGgiFvMesh.C
bloba320de58500ff71c05b88a1fe8cf4051f8f14334
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2006-7 H. Jasak All rights reserved
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
28 #include "Time.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 * * * * * * * * * * * * * //
37 namespace Foam
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)
51     {
52         Info<< "void mixerGgiFvMesh::addZonesAndModifiers() : "
53             << "Zones and modifiers already present.  Skipping."
54             << endl;
56         return;
57     }
59     Info<< "Time = " << time().timeName() << endl
60         << "Adding zones and modifiers to the mesh" << endl;
62     // Add zones
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)
69     {
70         // Copy face zones
71         Info << "Copying existing face zones" << endl;
73         fz.setSize(faceZones().size());
75         forAll (faceZones(), i)
76         {
77             fz[i] = faceZones()[i].clone(faceZones()).ptr();
78         }
79     }
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;
89     forAll(rs, cellI)
90     {
91         if (rs[cellI] == originRegion)
92         {
93             movingCells[nMovingCells] = cellI;
94             nMovingCells++;
95         }
96     }
98     movingCells.setSize(nMovingCells);
99     Info << "Number of cells in the moving region: " << nMovingCells << endl;
101     cz[0] = new cellZone
102     (
103         "movingCells",
104         movingCells,
105         0,
106         cellZones()
107     );
109     Info << "Adding point, face and cell zones" << endl;
110     removeZones();
111     addZones(pz, fz, cz);
113     // Write mesh
114     write();
118 void Foam::mixerGgiFvMesh::calcMovingMasks() const
120     if (debug)
121     {
122         Info<< "void mixerGgiFvMesh::calcMovingMasks() const : "
123             << "Calculating point and cell masks"
124             << endl;
125     }
127     if (movingPointsMaskPtr_)
128     {
129         FatalErrorIn("void mixerGgiFvMesh::calcMovingMasks() const")
130             << "point mask already calculated"
131             << abort(FatalError);
132     }
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)
145     {
146         const cell& curCell = c[cellAddr[cellI]];
148         forAll (curCell, faceI)
149         {
150             // Mark all the points as moving
151             const face& curFace = f[curCell[faceI]];
153             forAll (curFace, pointI)
154             {
155                 movingPointsMask[curFace[pointI]] = 1;
156             }
157         }
158     }
160     // Grab the ggi patches on the moving side
161     wordList movingPatches(dict_.subDict("slider").lookup("moving"));
163     forAll (movingPatches, patchI)
164     {
165         polyPatchID movingSliderID
166         (
167             movingPatches[patchI],
168             boundaryMesh()
169         );
171         if (!movingSliderID.active())
172         {
173             FatalErrorIn("void mixerGgiFvMesh::calcMovingMasks() const")
174                 << "Moving slider named " << movingPatches[patchI]
175                 << " not found.  Valid patch names: "
176                 << boundaryMesh().names() << abort(FatalError);
177         }
179         const ggiPolyPatch& movingGgiPatch =
180             refCast<const ggiPolyPatch>(boundaryMesh()[movingSliderID.index()]);
182         const labelList& movingSliderAddr = movingGgiPatch.zone();
184         forAll (movingSliderAddr, faceI)
185         {
186             const face& curFace = f[movingSliderAddr[faceI]];
188             forAll (curFace, pointI)
189             {
190                 movingPointsMask[curFace[pointI]] = 1;
191             }
192         }
193     }
195     // Grab the ggi patches on the static side
196     wordList staticPatches(dict_.subDict("slider").lookup("static"));
198     forAll (staticPatches, patchI)
199     {
200         polyPatchID staticSliderID
201         (
202             staticPatches[patchI],
203             boundaryMesh()
204         );
206         if (!staticSliderID.active())
207         {
208             FatalErrorIn("void mixerGgiFvMesh::calcMovingMasks() const")
209                 << "Static slider named " << staticPatches[patchI]
210                 << " not found.  Valid patch names: "
211                 << boundaryMesh().names() << abort(FatalError);
212         }
214         const ggiPolyPatch& staticGgiPatch =
215             refCast<const ggiPolyPatch>(boundaryMesh()[staticSliderID.index()]);
217         const labelList& staticSliderAddr = staticGgiPatch.zone();
219         forAll (staticSliderAddr, faceI)
220         {
221             const face& curFace = f[staticSliderAddr[faceI]];
223             forAll (curFace, pointI)
224             {
225                 movingPointsMask[curFace[pointI]] = 0;
226             }
227         }
228     }
232 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
234 // Construct from components
235 Foam::mixerGgiFvMesh::mixerGgiFvMesh
237     const IOobject& io
240     dynamicFvMesh(io),
241     dict_
242     (
243         IOdictionary
244         (
245             IOobject
246             (
247                 "dynamicMeshDict",
248                 time().constant(),
249                 *this,
250                 IOobject::MUST_READ,
251                 IOobject::NO_WRITE
252             )
253         ).subDict(typeName + "Coeffs")
254     ),
255     csPtr_
256     (
257         coordinateSystem::New
258         (
259             "coordinateSystem",
260             dict_.subDict("coordinateSystem")
261         )
262     ),
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_)
289     {
290         calcMovingMasks();
291     }
293     return *movingPointsMaskPtr_;
297 bool Foam::mixerGgiFvMesh::update()
299      // Rotational speed needs to be converted from rpm
300     movePoints
301     (
302         csPtr_->globalPosition
303         (
304             csPtr_->localPosition(allPoints())
305           + vector(0, rpm_*360.0*time().deltaT().value()/60.0, 0)
306             *movingPointsMask()
307         )
308     );
310     // The mesh is not morphing
311     return false;
315 // ************************************************************************* //