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 -------------------------------------------------------------------------------
11 License
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 
29 #include "rawTopoChangerFvMesh.H"
30 #include "mapPolyMesh.H"
32 #include "volFields.H"
33 #include "linear.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(rawTopoChangerFvMesh, 0);
41  (
42  topoChangerFvMesh,
43  rawTopoChangerFvMesh,
44  IOobject
45  );
47  (
48  topoChangerFvMesh,
49  rawTopoChangerFvMesh,
50  doInit
51  );
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
57 // Construct from components
58 Foam::rawTopoChangerFvMesh::rawTopoChangerFvMesh
59 (
60  const IOobject& io,
61  const bool doInit
62 )
63 :
64  topoChangerFvMesh(io, doInit)
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
71 {
72  // Do mesh changes (use inflation - put new points in topoChangeMap)
73  Info<< "rawTopoChangerFvMesh : Checking for topology changes..."
74  << endl;
75 
76  // Mesh not moved/changed yet
77  moving(false);
78  topoChanging(false);
79 
80  // Do any topology changes. Sets topoChanging (through polyTopoChange)
81  autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
82 
83  const bool hasChanged = bool(topoChangeMap);
84 
85  if (hasChanged)
86  {
87  Info<< "rawTopoChangerFvMesh : Done topology changes..."
88  << endl;
89 
90  // Temporary: fix fields on patch faces created out of nothing
91  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92 
93  // Two situations:
94  // - internal faces inflated out of nothing
95  // - patch faces created out of previously internal faces
96 
97  // Is face mapped in any way?
98  bitSet mappedFace(nFaces());
99 
100  const label nOldInternal = topoChangeMap().oldPatchStarts()[0];
101 
102  const labelList& faceMap = topoChangeMap().faceMap();
103  for (label facei = 0; facei < nInternalFaces(); facei++)
104  {
105  if (faceMap[facei] >= 0)
106  {
107  mappedFace.set(facei);
108  }
109  }
110  for (label facei = nInternalFaces(); facei < nFaces(); facei++)
111  {
112  if (faceMap[facei] >= 0 && faceMap[facei] >= nOldInternal)
113  {
114  mappedFace.set(facei);
115  }
116  }
117 
118  for (const auto& map : topoChangeMap().facesFromFacesMap())
119  {
120  mappedFace.set(map.index());
121  }
122 
123  for (const auto& map : topoChangeMap().facesFromEdgesMap())
124  {
125  mappedFace.set(map.index());
126  }
127 
128  for (const auto& map : topoChangeMap().facesFromPointsMap())
129  {
130  mappedFace.set(map.index());
131  }
132 
133  // Set unmapped faces to zero
134  Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values." << nl;
135 
136  zeroUnmappedValues<scalar, fvPatchField, volMesh>(mappedFace);
137  zeroUnmappedValues<vector, fvPatchField, volMesh>(mappedFace);
138  zeroUnmappedValues<sphericalTensor, fvPatchField, volMesh>(mappedFace);
139  zeroUnmappedValues<symmTensor, fvPatchField, volMesh>(mappedFace);
140  zeroUnmappedValues<tensor, fvPatchField, volMesh>(mappedFace);
141 
142  // Special handling for phi: set unmapped faces to recreated phi
143  Info<< "rawTopoChangerFvMesh :"
144  << " recreating phi for unmapped boundary values." << endl;
145 
146  const auto& U = lookupObject<volVectorField>("U");
147  auto& phi = lookupObjectRef<surfaceScalarField>("phi");
148 
149  setUnmappedValues
150  (
151  phi,
152  mappedFace,
153  (linearInterpolate(U) & Sf())()
154  );
155 
156 
157  if (topoChangeMap().hasMotionPoints())
158  {
159  pointField newPoints = topoChangeMap().preMotionPoints();
160 
161  // Give the meshModifiers opportunity to modify points
162  Info<< "rawTopoChangerFvMesh :"
163  << " calling modifyMotionPoints." << endl;
164  topoChanger_.modifyMotionPoints(newPoints);
165 
166  // Actually move points
167  Info<< "rawTopoChangerFvMesh :"
168  << " calling movePoints." << endl;
169 
170  movePoints(newPoints);
171  }
172  }
173  else
174  {
175  //Pout<< "rawTopoChangerFvMesh :"
176  // << " no topology changes..." << endl;
177  }
178 
179  return hasChanged;
180 }
181 
182 
183 // ************************************************************************* //
const surfaceVectorField & Sf() const
Return cell face area vectors.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > linearInterpolate(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: linear.H:120
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
const surfaceScalarField & phi() const
Return cell face motion fluxes.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual bool movePoints()
Do what is necessary if the mesh has moved.
label nFaces() const noexcept
Number of mesh faces.
autoPtr< mapPolyMesh > changeMesh(const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Macros for easy insertion into run-time selection tables.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
Abstract base class for a topology changing fvMesh.
label nInternalFaces() const noexcept
Number of internal faces.
void modifyMotionPoints(pointField &) const
Modify point motion.
bool topoChanging() const noexcept
Is mesh topology changing.
Definition: polyMesh.H:750
virtual bool update()
Update the mesh for both mesh motion and topology change.
defineTypeNameAndDebug(combustionModel, 0)
bool moving() const noexcept
Is mesh moving.
Definition: polyMesh.H:732
U
Definition: pEqn.H:72
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
void set(T *p) noexcept
Deprecated(2018-02) Identical to reset().
Definition: autoPtr.H:437
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
polyTopoChanger topoChanger_
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)