rawTopoChangerFvMesh.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
30#include "mapPolyMesh.H"
32#include "volFields.H"
33#include "linear.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
41 (
45 );
47 (
50 doInit
51 );
52}
53
54
55// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56
57// Construct from components
59(
60 const IOobject& io,
61 const bool doInit
62)
63:
64 topoChangerFvMesh(io, doInit)
65{}
66
67
68// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
69
71{}
72
73
74// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75
77{
78 // Do mesh changes (use inflation - put new points in topoChangeMap)
79 Info<< "rawTopoChangerFvMesh : Checking for topology changes..."
80 << endl;
81
82 // Mesh not moved/changed yet
83 moving(false);
84 topoChanging(false);
85
86 // Do any topology changes. Sets topoChanging (through polyTopoChange)
87 autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
88
89 const bool hasChanged = bool(topoChangeMap);
90
91 if (hasChanged)
92 {
93 Info<< "rawTopoChangerFvMesh : Done topology changes..."
94 << endl;
95
96 // Temporary: fix fields on patch faces created out of nothing
97 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98
99 // Two situations:
100 // - internal faces inflated out of nothing
101 // - patch faces created out of previously internal faces
102
103 // Is face mapped in any way?
104 bitSet mappedFace(nFaces());
105
106 const label nOldInternal = topoChangeMap().oldPatchStarts()[0];
107
108 const labelList& faceMap = topoChangeMap().faceMap();
109 for (label facei = 0; facei < nInternalFaces(); facei++)
110 {
111 if (faceMap[facei] >= 0)
112 {
113 mappedFace.set(facei);
114 }
115 }
116 for (label facei = nInternalFaces(); facei < nFaces(); facei++)
117 {
118 if (faceMap[facei] >= 0 && faceMap[facei] >= nOldInternal)
119 {
120 mappedFace.set(facei);
121 }
122 }
123
124 const List<objectMap>& fromFaces = topoChangeMap().facesFromFacesMap();
125
126 forAll(fromFaces, i)
127 {
128 mappedFace.set(fromFaces[i].index());
129 }
130
131 const List<objectMap>& fromEdges = topoChangeMap().facesFromEdgesMap();
132
133 forAll(fromEdges, i)
134 {
135 mappedFace.set(fromEdges[i].index());
136 }
137
138 const List<objectMap>& fromPts = topoChangeMap().facesFromPointsMap();
139
140 forAll(fromPts, i)
141 {
142 mappedFace.set(fromPts[i].index());
143 }
144
145 // Set unmapped faces to zero
146 Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values."
147 << endl;
148 zeroUnmappedValues<scalar, fvPatchField, volMesh>(mappedFace);
149 zeroUnmappedValues<vector, fvPatchField, volMesh>(mappedFace);
150 zeroUnmappedValues<sphericalTensor, fvPatchField, volMesh>(mappedFace);
151 zeroUnmappedValues<symmTensor, fvPatchField, volMesh>(mappedFace);
152 zeroUnmappedValues<tensor, fvPatchField, volMesh>(mappedFace);
153
154 // Special handling for phi: set unmapped faces to recreated phi
155 Info<< "rawTopoChangerFvMesh :"
156 << " recreating phi for unmapped boundary values." << endl;
157
158 const volVectorField& U = lookupObject<volVectorField>("U");
159 surfaceScalarField& phi = lookupObjectRef<surfaceScalarField>("phi");
160
161 setUnmappedValues
162 (
163 phi,
164 mappedFace,
165 (linearInterpolate(U) & Sf())()
166 );
167
168
169 if (topoChangeMap().hasMotionPoints())
170 {
171 pointField newPoints = topoChangeMap().preMotionPoints();
172
173 // Give the meshModifiers opportunity to modify points
174 Info<< "rawTopoChangerFvMesh :"
175 << " calling modifyMotionPoints." << endl;
176 topoChanger_.modifyMotionPoints(newPoints);
177
178 // Actually move points
179 Info<< "rawTopoChangerFvMesh :"
180 << " calling movePoints." << endl;
181
182 movePoints(newPoints);
183 }
184 }
185 else
186 {
187 //Pout<< "rawTopoChangerFvMesh :"
188 // << " no topology changes..." << endl;
189 }
190
191 return hasChanged;
192}
193
194
195// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
surfaceScalarField & phi
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:590
topoChangerFvMesh without any added functionality.
virtual ~rawTopoChangerFvMesh()
Destructor.
virtual bool update()
Update the mesh for both mesh motion and topology change.
Abstract base class for a topology changing fvMesh.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
U
Definition: pEqn.H:72
bool
Definition: EEqn.H:20
const labelList nFaces(UPstream::listGatherValues< label >(aMesh.nFaces()))
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > linearInterpolate(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: linear.H:112
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333