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

rawTopoChangerFvMesh.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-2007 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 "rawTopoChangerFvMesh.H"
00027 #include <OpenFOAM/mapPolyMesh.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029 #include <finiteVolume/volFields.H>
00030 #include <finiteVolume/linear.H>
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036     defineTypeNameAndDebug(rawTopoChangerFvMesh, 0);
00037     addToRunTimeSelectionTable
00038     (
00039         topoChangerFvMesh,
00040         rawTopoChangerFvMesh,
00041         IOobject
00042     );
00043 }
00044 
00045 
00046 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00047 
00048 // Construct from components
00049 Foam::rawTopoChangerFvMesh::rawTopoChangerFvMesh(const IOobject& io)
00050 :
00051     topoChangerFvMesh(io)
00052 {}
00053 
00054 
00055 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00056 
00057 Foam::rawTopoChangerFvMesh::~rawTopoChangerFvMesh()
00058 {}
00059 
00060 
00061 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00062 
00063 bool Foam::rawTopoChangerFvMesh::update()
00064 {
00065     // Do mesh changes (use inflation - put new points in topoChangeMap)
00066     Info<< "rawTopoChangerFvMesh : Checking for topology changes..."
00067         << endl;
00068     autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
00069 
00070     bool hasChanged = topoChangeMap.valid();
00071 
00072     if (hasChanged)
00073     {
00074         Info<< "rawTopoChangerFvMesh : Done topology changes..."
00075             << endl;
00076 
00077         // Temporary: fix fields on patch faces created out of nothing
00078         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00079 
00080         // Two situations:
00081         // - internal faces inflated out of nothing
00082         // - patch faces created out of previously internal faces
00083 
00084         // Is face mapped in any way
00085         PackedList<1> mappedFace(nFaces());
00086 
00087         const label nOldInternal = topoChangeMap().oldPatchStarts()[0];
00088 
00089         const labelList& faceMap = topoChangeMap().faceMap();
00090         for (label faceI = 0; faceI < nInternalFaces(); faceI++)
00091         {
00092             if (faceMap[faceI] >= 0)
00093             {
00094                 mappedFace[faceI] = 1;
00095             }
00096         }
00097         for (label faceI = nInternalFaces(); faceI < nFaces(); faceI++)
00098         {
00099             if (faceMap[faceI] >= 0 && faceMap[faceI] >= nOldInternal)
00100             {
00101                 mappedFace[faceI] = 1;
00102             }
00103         }
00104 
00105         const List<objectMap>& fromFaces = topoChangeMap().facesFromFacesMap();
00106 
00107         forAll(fromFaces, i)
00108         {
00109             mappedFace[fromFaces[i].index()] = 1;
00110         }
00111 
00112         const List<objectMap>& fromEdges = topoChangeMap().facesFromEdgesMap();
00113 
00114         forAll(fromEdges, i)
00115         {
00116             mappedFace[fromEdges[i].index()] = 1;
00117         }
00118 
00119         const List<objectMap>& fromPts = topoChangeMap().facesFromPointsMap();
00120 
00121         forAll(fromPts, i)
00122         {
00123             mappedFace[fromPts[i].index()] = 1;
00124         }
00125 
00126         // Set unmapped faces to zero
00127         Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values."
00128             << endl;
00129         zeroUnmappedValues<scalar, fvPatchField, volMesh>(mappedFace);
00130         zeroUnmappedValues<vector, fvPatchField, volMesh>(mappedFace);
00131         zeroUnmappedValues<sphericalTensor, fvPatchField, volMesh>(mappedFace);
00132         zeroUnmappedValues<symmTensor, fvPatchField, volMesh>(mappedFace);
00133         zeroUnmappedValues<tensor, fvPatchField, volMesh>(mappedFace);
00134 
00135         // Special handling for phi: set unmapped faces to recreated phi
00136         Info<< "rawTopoChangerFvMesh :"
00137             << " recreating phi for unmapped boundary values." << endl;
00138         const volVectorField& U = lookupObject<volVectorField>("U");
00139         surfaceScalarField& phi = const_cast<surfaceScalarField&>
00140         (
00141             lookupObject<surfaceScalarField>("phi")
00142         );
00143         setUnmappedValues
00144         (
00145             phi,
00146             mappedFace,
00147             (linearInterpolate(U) & Sf())()
00148         );
00149 
00150 
00151         if (topoChangeMap().hasMotionPoints())
00152         {
00153             pointField newPoints = topoChangeMap().preMotionPoints();
00154 
00155             // Give the meshModifiers opportunity to modify points
00156             Info<< "rawTopoChangerFvMesh :"
00157                 << " calling modifyMotionPoints." << endl;
00158             topoChanger_.modifyMotionPoints(newPoints);
00159 
00160             // Actually move points
00161             Info<< "rawTopoChangerFvMesh :"
00162                 << " calling movePoints." << endl;
00163 
00164             movePoints(newPoints);
00165         }
00166     }
00167     else
00168     {
00169         //Pout<< "rawTopoChangerFvMesh :"
00170         //    << " no topology changes..." << endl;
00171     }
00172 
00173     changing(hasChanged);
00174 
00175     return hasChanged;
00176 }
00177 
00178 
00179 // ************************************************************************* //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines