OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

mixerFvMesh.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "mixerFvMesh.H"
00028 #include "Time.H"
00029 #include "regionSplit.H"
00030 #include "slidingInterface.H"
00031 #include "addToRunTimeSelectionTable.H"
00032 #include "mapPolyMesh.H"
00033 
00034 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00035 
00036 namespace Foam
00037 {
00038     defineTypeNameAndDebug(mixerFvMesh, 0);
00039 
00040     addToRunTimeSelectionTable(topoChangerFvMesh, mixerFvMesh, IOobject);
00041 }
00042 
00043 
00044 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00045 
00046 void Foam::mixerFvMesh::addZonesAndModifiers()
00047 {
00048     // Add zones and modifiers for motion action
00049 
00050     if
00051     (
00052         pointZones().size()
00053      || faceZones().size()
00054      || cellZones().size()
00055      || topoChanger_.size()
00056     )
00057     {
00058         Info<< "void mixerFvMesh::addZonesAndModifiers() : "
00059             << "Zones and modifiers already present.  Skipping."
00060             << endl;
00061 
00062         return;
00063     }
00064 
00065     Info<< "Time = " << time().timeName() << endl
00066         << "Adding zones and modifiers to the mesh" << endl;
00067 
00068     // Add zones
00069     List<pointZone*> pz(1);
00070 
00071     // Add an empty zone for cut points
00072 
00073     pz[0] = new pointZone
00074     (
00075         "cutPointZone",
00076         labelList(0),
00077         0,
00078         pointZones()
00079     );
00080 
00081 
00082     // Do face zones for slider
00083 
00084     List<faceZone*> fz(3);
00085 
00086     // Inner slider
00087     const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
00088     const polyPatch& innerSlider =
00089         boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
00090 
00091     labelList isf(innerSlider.size());
00092 
00093     forAll (isf, i)
00094     {
00095         isf[i] = innerSlider.start() + i;
00096     }
00097 
00098     fz[0] = new faceZone
00099     (
00100         "insideSliderZone",
00101         isf,
00102         boolList(innerSlider.size(), false),
00103         0,
00104         faceZones()
00105     );
00106 
00107     // Outer slider
00108     const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
00109     const polyPatch& outerSlider =
00110         boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
00111 
00112     labelList osf(outerSlider.size());
00113 
00114     forAll (osf, i)
00115     {
00116         osf[i] = outerSlider.start() + i;
00117     }
00118 
00119     fz[1] = new faceZone
00120     (
00121         "outsideSliderZone",
00122         osf,
00123         boolList(outerSlider.size(), false),
00124         1,
00125         faceZones()
00126     );
00127 
00128     // Add empty zone for cut faces
00129     fz[2] = new faceZone
00130     (
00131         "cutFaceZone",
00132         labelList(0),
00133         boolList(0, false),
00134         2,
00135         faceZones()
00136     );
00137 
00138     List<cellZone*> cz(1);
00139 
00140     // Mark every cell with its topological region
00141     regionSplit rs(*this);
00142 
00143     // Get the region of the cell containing the origin.
00144     label originRegion = rs[findNearestCell(cs().origin())];
00145 
00146     labelList movingCells(nCells());
00147     label nMovingCells = 0;
00148 
00149     forAll(rs, cellI)
00150     {
00151         if (rs[cellI] == originRegion)
00152         {
00153             movingCells[nMovingCells] = cellI;
00154             nMovingCells++;
00155         }
00156     }
00157 
00158     movingCells.setSize(nMovingCells);
00159     Info << "Number of cells in the moving region: " << nMovingCells << endl;
00160 
00161     cz[0] = new cellZone
00162     (
00163         "movingCells",
00164         movingCells,
00165         0,
00166         cellZones()
00167     );
00168 
00169     Info << "Adding point, face and cell zones" << endl;
00170     addZones(pz, fz, cz);
00171 
00172     // Add a topology modifier
00173     Info << "Adding topology modifiers" << endl;
00174     topoChanger_.setSize(1);
00175     topoChanger_.set
00176     (
00177         0,
00178         new slidingInterface
00179         (
00180             "mixerSlider",
00181             0,
00182             topoChanger_,
00183             outerSliderName + "Zone",
00184             innerSliderName + "Zone",
00185             "cutPointZone",
00186             "cutFaceZone",
00187             outerSliderName,
00188             innerSliderName,
00189             slidingInterface::INTEGRAL
00190         )
00191     );
00192     topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
00193 
00194     write();
00195 }
00196 
00197 
00198 void Foam::mixerFvMesh::calcMovingMasks() const
00199 {
00200     if (debug)
00201     {
00202         Info<< "void mixerFvMesh::calcMovingMasks() const : "
00203             << "Calculating point and cell masks"
00204             << endl;
00205     }
00206 
00207     if (movingPointsMaskPtr_)
00208     {
00209         FatalErrorIn("void mixerFvMesh::calcMovingMasks() const")
00210             << "point mask already calculated"
00211             << abort(FatalError);
00212     }
00213 
00214     // Set the point mask
00215     movingPointsMaskPtr_ = new scalarField(points().size(), 0);
00216     scalarField& movingPointsMask = *movingPointsMaskPtr_;
00217 
00218     const cellList& c = cells();
00219     const faceList& f = faces();
00220 
00221     const labelList& cellAddr =
00222         cellZones()[cellZones().findZoneID("movingCells")];
00223 
00224     forAll (cellAddr, cellI)
00225     {
00226         const cell& curCell = c[cellAddr[cellI]];
00227 
00228         forAll (curCell, faceI)
00229         {
00230             // Mark all the points as moving
00231             const face& curFace = f[curCell[faceI]];
00232 
00233             forAll (curFace, pointI)
00234             {
00235                 movingPointsMask[curFace[pointI]] = 1;
00236             }
00237         }
00238     }
00239 
00240     const word innerSliderZoneName
00241     (
00242         word(motionDict_.subDict("slider").lookup("inside"))
00243       + "Zone"
00244     );
00245 
00246     const labelList& innerSliderAddr =
00247         faceZones()[faceZones().findZoneID(innerSliderZoneName)];
00248 
00249     forAll (innerSliderAddr, faceI)
00250     {
00251         const face& curFace = f[innerSliderAddr[faceI]];
00252 
00253         forAll (curFace, pointI)
00254         {
00255             movingPointsMask[curFace[pointI]] = 1;
00256         }
00257     }
00258 
00259     const word outerSliderZoneName
00260     (
00261         word(motionDict_.subDict("slider").lookup("outside"))
00262       + "Zone"
00263     );
00264 
00265     const labelList& outerSliderAddr =
00266         faceZones()[faceZones().findZoneID(outerSliderZoneName)];
00267 
00268     forAll (outerSliderAddr, faceI)
00269     {
00270         const face& curFace = f[outerSliderAddr[faceI]];
00271 
00272         forAll (curFace, pointI)
00273         {
00274             movingPointsMask[curFace[pointI]] = 0;
00275         }
00276     }
00277 }
00278 
00279 
00280 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00281 
00282 // Construct from components
00283 Foam::mixerFvMesh::mixerFvMesh
00284 (
00285     const IOobject& io
00286 )
00287 :
00288     topoChangerFvMesh(io),
00289     motionDict_
00290     (
00291         IOdictionary
00292         (
00293             IOobject
00294             (
00295                 "dynamicMeshDict",
00296                 time().constant(),
00297                 *this,
00298                 IOobject::MUST_READ,
00299                 IOobject::NO_WRITE
00300             )
00301         ).subDict(typeName + "Coeffs")
00302     ),
00303     csPtr_
00304     (
00305         coordinateSystem::New
00306         (
00307             "coordinateSystem",
00308             motionDict_.subDict("coordinateSystem")
00309         )
00310     ),
00311     rpm_(readScalar(motionDict_.lookup("rpm"))),
00312     movingPointsMaskPtr_(NULL)
00313 {
00314     addZonesAndModifiers();
00315 
00316     Info<< "Mixer mesh:" << nl
00317         << "    origin: " << cs().origin() << nl
00318         << "    axis: " << cs().axis() << nl
00319         << "    rpm: " << rpm_ << endl;
00320 }
00321 
00322 
00323 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00324 
00325 Foam::mixerFvMesh::~mixerFvMesh()
00326 {
00327     deleteDemandDrivenData(movingPointsMaskPtr_);
00328 }
00329 
00330 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00331 
00332 // Return moving points mask.  Moving points marked with 1
00333 const Foam::scalarField& Foam::mixerFvMesh::movingPointsMask() const
00334 {
00335     if (!movingPointsMaskPtr_)
00336     {
00337         calcMovingMasks();
00338     }
00339 
00340     return *movingPointsMaskPtr_;
00341 }
00342 
00343 
00344 bool Foam::mixerFvMesh::update()
00345 {
00346      // Rotational speed needs to be converted from rpm
00347     movePoints
00348     (
00349         csPtr_->globalPosition
00350         (
00351             csPtr_->localPosition(points())
00352           + vector(0, rpm_*360.0*time().deltaT().value()/60.0, 0)
00353             *movingPointsMask()
00354         )
00355     );
00356 
00357     // Make changes. Use inflation (so put new points in topoChangeMap)
00358     autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
00359 
00360     if (topoChangeMap.valid())
00361     {
00362         if (debug)
00363         {
00364             Info << "Mesh topology is changing" << endl;
00365         }
00366 
00367         deleteDemandDrivenData(movingPointsMaskPtr_);
00368     }
00369 
00370     movePoints
00371     (
00372         csPtr_->globalPosition
00373         (
00374             csPtr_->localPosition(oldPoints())
00375           + vector(0, rpm_*360.0*time().deltaT().value()/60.0, 0)
00376             *movingPointsMask()
00377         )
00378     );
00379 
00380     return true;
00381 }
00382 
00383 
00384 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd