ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / topoChangerFvMesh / rawTopoChangerFvMesh / rawTopoChangerFvMesh.C
blob2234cf1808953bf540ead9c6e12a860a8b6f05b2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "rawTopoChangerFvMesh.H"
27 #include "mapPolyMesh.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "volFields.H"
30 #include "linear.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 namespace Foam
36     defineTypeNameAndDebug(rawTopoChangerFvMesh, 0);
37     addToRunTimeSelectionTable
38     (
39         topoChangerFvMesh,
40         rawTopoChangerFvMesh,
41         IOobject
42     );
46 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
48 // Construct from components
49 Foam::rawTopoChangerFvMesh::rawTopoChangerFvMesh(const IOobject& io)
51     topoChangerFvMesh(io)
55 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
57 Foam::rawTopoChangerFvMesh::~rawTopoChangerFvMesh()
61 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
63 bool Foam::rawTopoChangerFvMesh::update()
65     // Do mesh changes (use inflation - put new points in topoChangeMap)
66     Info<< "rawTopoChangerFvMesh : Checking for topology changes..."
67         << endl;
68     autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
70     bool hasChanged = topoChangeMap.valid();
72     if (hasChanged)
73     {
74         Info<< "rawTopoChangerFvMesh : Done topology changes..."
75             << endl;
77         // Temporary: fix fields on patch faces created out of nothing
78         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80         // Two situations:
81         // - internal faces inflated out of nothing
82         // - patch faces created out of previously internal faces
84         // Is face mapped in any way?
85         PackedBoolList mappedFace(nFaces());
87         const label nOldInternal = topoChangeMap().oldPatchStarts()[0];
89         const labelList& faceMap = topoChangeMap().faceMap();
90         for (label faceI = 0; faceI < nInternalFaces(); faceI++)
91         {
92             if (faceMap[faceI] >= 0)
93             {
94                 mappedFace[faceI] = 1;
95             }
96         }
97         for (label faceI = nInternalFaces(); faceI < nFaces(); faceI++)
98         {
99             if (faceMap[faceI] >= 0 && faceMap[faceI] >= nOldInternal)
100             {
101                 mappedFace[faceI] = 1;
102             }
103         }
105         const List<objectMap>& fromFaces = topoChangeMap().facesFromFacesMap();
107         forAll(fromFaces, i)
108         {
109             mappedFace[fromFaces[i].index()] = 1;
110         }
112         const List<objectMap>& fromEdges = topoChangeMap().facesFromEdgesMap();
114         forAll(fromEdges, i)
115         {
116             mappedFace[fromEdges[i].index()] = 1;
117         }
119         const List<objectMap>& fromPts = topoChangeMap().facesFromPointsMap();
121         forAll(fromPts, i)
122         {
123             mappedFace[fromPts[i].index()] = 1;
124         }
126         // Set unmapped faces to zero
127         Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values."
128             << endl;
129         zeroUnmappedValues<scalar, fvPatchField, volMesh>(mappedFace);
130         zeroUnmappedValues<vector, fvPatchField, volMesh>(mappedFace);
131         zeroUnmappedValues<sphericalTensor, fvPatchField, volMesh>(mappedFace);
132         zeroUnmappedValues<symmTensor, fvPatchField, volMesh>(mappedFace);
133         zeroUnmappedValues<tensor, fvPatchField, volMesh>(mappedFace);
135         // Special handling for phi: set unmapped faces to recreated phi
136         Info<< "rawTopoChangerFvMesh :"
137             << " recreating phi for unmapped boundary values." << endl;
138         const volVectorField& U = lookupObject<volVectorField>("U");
139         surfaceScalarField& phi = const_cast<surfaceScalarField&>
140         (
141             lookupObject<surfaceScalarField>("phi")
142         );
143         setUnmappedValues
144         (
145             phi,
146             mappedFace,
147             (linearInterpolate(U) & Sf())()
148         );
151         if (topoChangeMap().hasMotionPoints())
152         {
153             pointField newPoints = topoChangeMap().preMotionPoints();
155             // Give the meshModifiers opportunity to modify points
156             Info<< "rawTopoChangerFvMesh :"
157                 << " calling modifyMotionPoints." << endl;
158             topoChanger_.modifyMotionPoints(newPoints);
160             // Actually move points
161             Info<< "rawTopoChangerFvMesh :"
162                 << " calling movePoints." << endl;
164             movePoints(newPoints);
165         }
166     }
167     else
168     {
169         //Pout<< "rawTopoChangerFvMesh :"
170         //    << " no topology changes..." << endl;
171     }
173     changing(hasChanged);
175     return hasChanged;
179 // ************************************************************************* //