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

linearValveLayersFvMesh.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 "linearValveLayersFvMesh.H"
00028 #include "Time.H"
00029 #include "slidingInterface.H"
00030 #include "layerAdditionRemoval.H"
00031 #include "pointField.H"
00032 #include "mapPolyMesh.H"
00033 #include "polyTopoChange.H"
00034 #include "addToRunTimeSelectionTable.H"
00035 
00036 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040     defineTypeNameAndDebug(linearValveLayersFvMesh, 0);
00041 
00042     addToRunTimeSelectionTable(topoChangerFvMesh, linearValveLayersFvMesh, IOobject);
00043 }
00044 
00045 
00046 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00047 
00048 void Foam::linearValveLayersFvMesh::addZonesAndModifiers()
00049 {
00050     // Add zones and modifiers for motion action
00051 
00052     if
00053     (
00054         pointZones().size()
00055      || faceZones().size()
00056      || cellZones().size()
00057      || topoChanger_.size()
00058     )
00059     {
00060         Info<< "void linearValveLayersFvMesh::addZonesAndModifiers() : "
00061             << "Zones and modifiers already present.  Skipping."
00062             << endl;
00063 
00064         return;
00065     }
00066 
00067     Info<< "Time = " << time().timeName() << endl
00068         << "Adding zones and modifiers to the mesh" << endl;
00069 
00070     // Add zones
00071     List<pointZone*> pz(1);
00072     List<faceZone*> fz(4);
00073     List<cellZone*> cz(0);
00074 
00075 
00076     // Add an empty zone for cut points
00077 
00078     pz[0] = new pointZone
00079     (
00080         "cutPointZone",
00081         labelList(0),
00082         0,
00083         pointZones()
00084     );
00085 
00086 
00087     // Do face zones for slider
00088 
00089     // Inner slider
00090     const word innerSliderName(motionDict_.subDict("slider").lookup("inside"));
00091     const polyPatch& innerSlider =
00092         boundaryMesh()[boundaryMesh().findPatchID(innerSliderName)];
00093 
00094     labelList isf(innerSlider.size());
00095 
00096     forAll (isf, i)
00097     {
00098         isf[i] = innerSlider.start() + i;
00099     }
00100 
00101     fz[0] = new faceZone
00102     (
00103         "insideSliderZone",
00104         isf,
00105         boolList(innerSlider.size(), false),
00106         0,
00107         faceZones()
00108     );
00109 
00110     // Outer slider
00111     const word outerSliderName(motionDict_.subDict("slider").lookup("outside"));
00112     const polyPatch& outerSlider =
00113         boundaryMesh()[boundaryMesh().findPatchID(outerSliderName)];
00114 
00115     labelList osf(outerSlider.size());
00116 
00117     forAll (osf, i)
00118     {
00119         osf[i] = outerSlider.start() + i;
00120     }
00121 
00122     fz[1] = new faceZone
00123     (
00124         "outsideSliderZone",
00125         osf,
00126         boolList(outerSlider.size(), false),
00127         1,
00128         faceZones()
00129     );
00130 
00131     // Add empty zone for cut faces
00132     fz[2] = new faceZone
00133     (
00134         "cutFaceZone",
00135         labelList(0),
00136         boolList(0, false),
00137         2,
00138         faceZones()
00139     );
00140 
00141     // Add face zone for layer addition
00142     const word layerPatchName
00143     (
00144         motionDict_.subDict("layer").lookup("patch")
00145     );
00146 
00147     const polyPatch& layerPatch =
00148         boundaryMesh()[boundaryMesh().findPatchID(layerPatchName)];
00149 
00150     labelList lpf(layerPatch.size());
00151 
00152     forAll (lpf, i)
00153     {
00154         lpf[i] = layerPatch.start() + i;
00155     }
00156 
00157     fz[3] = new faceZone
00158     (
00159         "valveLayerZone",
00160         lpf,
00161         boolList(layerPatch.size(), true),
00162         0,
00163         faceZones()
00164     );
00165 
00166 
00167     Info << "Adding point and face zones" << endl;
00168     addZones(pz, fz, cz);
00169 
00170     // Add a topology modifier
00171 
00172     List<polyMeshModifier*> tm(2);
00173 
00174     tm[0] = new slidingInterface
00175     (
00176         "valveSlider",
00177         0,
00178         topoChanger_,
00179         outerSliderName + "Zone",
00180         innerSliderName + "Zone",
00181         "cutPointZone",
00182         "cutFaceZone",
00183         outerSliderName,
00184         innerSliderName,
00185         slidingInterface::INTEGRAL,
00186         true                          // Attach-detach action
00187     );
00188 
00189     tm[1] =
00190         new layerAdditionRemoval
00191         (
00192             "valveLayer",
00193             1,
00194             topoChanger_,
00195             "valveLayerZone",
00196             readScalar
00197             (
00198                 motionDict_.subDict("layer").lookup("minThickness")
00199             ),
00200             readScalar
00201             (
00202                 motionDict_.subDict("layer").lookup("maxThickness")
00203             )
00204         );
00205 
00206 
00207     Info << "Adding topology modifiers" << endl;
00208     addTopologyModifiers(tm);
00209 
00210     // Write mesh
00211     write();
00212 }
00213 
00214 
00215 void Foam::linearValveLayersFvMesh::makeLayersLive()
00216 {
00217     const polyTopoChanger& topoChanges = topoChanger_;
00218 
00219     // Enable layering
00220     forAll (topoChanges, modI)
00221     {
00222         if (typeid(topoChanges[modI]) == typeid(layerAdditionRemoval))
00223         {
00224             topoChanges[modI].enable();
00225         }
00226         else if (typeid(topoChanges[modI]) == typeid(slidingInterface))
00227         {
00228             topoChanges[modI].disable();
00229         }
00230         else
00231         {
00232             FatalErrorIn("void linearValveLayersFvMesh::makeLayersLive()")
00233                 << "Don't know what to do with mesh modifier "
00234                 << modI << " of type " << topoChanges[modI].type()
00235                 << abort(FatalError);
00236         }
00237     }
00238 }
00239 
00240 
00241 void Foam::linearValveLayersFvMesh::makeSlidersLive()
00242 {
00243     const polyTopoChanger& topoChanges = topoChanger_;
00244 
00245     // Enable sliding interface
00246     forAll (topoChanges, modI)
00247     {
00248         if (typeid(topoChanges[modI]) == typeid(layerAdditionRemoval))
00249         {
00250             topoChanges[modI].disable();
00251         }
00252         else if (typeid(topoChanges[modI]) == typeid(slidingInterface))
00253         {
00254             topoChanges[modI].enable();
00255         }
00256         else
00257         {
00258             FatalErrorIn("void linearValveLayersFvMesh::makeLayersLive()")
00259                 << "Don't know what to do with mesh modifier "
00260                 << modI << " of type " << topoChanges[modI].type()
00261                 << abort(FatalError);
00262         }
00263     }
00264 }
00265 
00266 
00267 bool Foam::linearValveLayersFvMesh::attached() const
00268 {
00269     const polyTopoChanger& topoChanges = topoChanger_;
00270 
00271     bool result = false;
00272 
00273     forAll (topoChanges, modI)
00274     {
00275         if (typeid(topoChanges[modI]) == typeid(slidingInterface))
00276         {
00277             result =
00278                 result
00279              || refCast<const slidingInterface>(topoChanges[modI]).attached();
00280         }
00281     }
00282 
00283     // Check thal all sliders are in sync (debug only)
00284     forAll (topoChanges, modI)
00285     {
00286         if (typeid(topoChanges[modI]) == typeid(slidingInterface))
00287         {
00288             if
00289             (
00290                 result
00291              != refCast<const slidingInterface>(topoChanges[modI]).attached()
00292             )
00293             {
00294                 FatalErrorIn("bool linearValveLayersFvMesh::attached() const")
00295                     << "Slider " << modI << " named "
00296                     << topoChanges[modI].name()
00297                     << " out of sync: Should be" << result
00298                     << abort(FatalError);
00299             }
00300         }
00301     }
00302 
00303     return result;
00304 }
00305 
00306 
00307 Foam::tmp<Foam::pointField> Foam::linearValveLayersFvMesh::newPoints() const
00308 {
00309     tmp<pointField> tnewPoints
00310     (
00311         new pointField(points())
00312     );
00313 
00314     pointField& np = tnewPoints();
00315 
00316     const word layerPatchName
00317     (
00318         motionDict_.subDict("layer").lookup("patch")
00319     );
00320 
00321     const polyPatch& layerPatch =
00322         boundaryMesh()[boundaryMesh().findPatchID(layerPatchName)];
00323 
00324     const labelList& patchPoints = layerPatch.meshPoints();
00325 
00326     const vector vel
00327     (
00328         motionDict_.lookup("pistonVelocity")
00329     );
00330 
00331     forAll (patchPoints, ppI)
00332     {
00333         np[patchPoints[ppI]] += vel*time().deltaT().value();
00334     }
00335 
00336     return tnewPoints;
00337 }
00338 
00339 
00340 
00341 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00342 
00343 // Construct from components
00344 Foam::linearValveLayersFvMesh::linearValveLayersFvMesh(const IOobject& io)
00345 :
00346     topoChangerFvMesh(io),
00347     motionDict_
00348     (
00349         IOdictionary
00350         (
00351             IOobject
00352             (
00353                 "dynamicMeshDict",
00354                 time().constant(),
00355                 *this,
00356                 IOobject::MUST_READ,
00357                 IOobject::NO_WRITE
00358             )
00359         ).subDict(typeName + "Coeffs")
00360     )
00361 {
00362     addZonesAndModifiers();
00363 }
00364 
00365 
00366 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00367 
00368 Foam::linearValveLayersFvMesh::~linearValveLayersFvMesh()
00369 {}
00370 
00371 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00372 
00373 void Foam::linearValveLayersFvMesh::update()
00374 {
00375     // Detaching the interface
00376     if (attached())
00377     {
00378         Info << "Decoupling sliding interfaces" << endl;
00379         makeSlidersLive();
00380 
00381         // Changing topology
00382         resetMorph();
00383         setMorphTimeIndex(3*time().timeIndex());
00384         updateMesh();
00385     }
00386     else
00387     {
00388         Info << "Sliding interfaces decoupled" << endl;
00389     }
00390 
00391     // Perform layer action and mesh motion
00392     makeLayersLive();
00393 
00394     // Changing topology
00395     resetMorph();
00396     setMorphTimeIndex(3*time().timeIndex() + 1);
00397     updateMesh();
00398 
00399     if (topoChangeMap.valid())
00400     {
00401         if (topoChangeMap().hasMotionPoints())
00402         {
00403             Info << "Topology change; executing pre-motion" << endl;
00404             movePoints(topoChangeMap().preMotionPoints());
00405         }
00406     }
00407 
00408     // Move points
00409     movePoints(newPoints());
00410 
00411     // Attach the interface
00412     Info << "Coupling sliding interfaces" << endl;
00413     makeSlidersLive();
00414 
00415     // Changing topology
00416     resetMorph();
00417     setMorphTimeIndex(3*time().timeIndex() + 2);
00418     updateMesh();
00419 
00420     Info << "Moving points post slider attach" << endl;
00421 //     const pointField p = allPoints();
00422 //     movePoints(p);
00423 
00424     Info << "Sliding interfaces coupled: " << attached() << endl;
00425 }
00426 
00427 
00428 // ************************************************************************* //
00429 
Copyright © 2000-2009 OpenCFD Ltd