1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
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"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(rawTopoChangerFvMesh, 0);
37 addToRunTimeSelectionTable
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 // Construct from components
49 Foam::rawTopoChangerFvMesh::rawTopoChangerFvMesh(const IOobject& 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..."
68 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
70 bool hasChanged = topoChangeMap.valid();
74 Info<< "rawTopoChangerFvMesh : Done topology changes..."
77 // Temporary: fix fields on patch faces created out of nothing
78 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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++)
92 if (faceMap[faceI] >= 0)
94 mappedFace[faceI] = 1;
97 for (label faceI = nInternalFaces(); faceI < nFaces(); faceI++)
99 if (faceMap[faceI] >= 0 && faceMap[faceI] >= nOldInternal)
101 mappedFace[faceI] = 1;
105 const List<objectMap>& fromFaces = topoChangeMap().facesFromFacesMap();
109 mappedFace[fromFaces[i].index()] = 1;
112 const List<objectMap>& fromEdges = topoChangeMap().facesFromEdgesMap();
116 mappedFace[fromEdges[i].index()] = 1;
119 const List<objectMap>& fromPts = topoChangeMap().facesFromPointsMap();
123 mappedFace[fromPts[i].index()] = 1;
126 // Set unmapped faces to zero
127 Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values."
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&>
141 lookupObject<surfaceScalarField>("phi")
147 (linearInterpolate(U) & Sf())()
151 if (topoChangeMap().hasMotionPoints())
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);
169 //Pout<< "rawTopoChangerFvMesh :"
170 // << " no topology changes..." << endl;
173 changing(hasChanged);
179 // ************************************************************************* //