FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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