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 // * * * * * * * * * * * * * * * * 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 // ************************************************************************* //
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > linearInterpolate(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: linear.H:120
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:82
virtual ~rawTopoChangerFvMesh()
Destructor.
Macros for easy insertion into run-time selection tables.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
Abstract base class for a topology changing fvMesh.
virtual bool update()
Update the mesh for both mesh motion and topology change.
defineTypeNameAndDebug(combustionModel, 0)
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)
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)