rawTopoChangerFvMesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "rawTopoChangerFvMesh.H"
27 #include "mapPolyMesh.H"
29 #include "volFields.H"
30 #include "linear.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(rawTopoChangerFvMesh, 0);
38  (
39  topoChangerFvMesh,
40  rawTopoChangerFvMesh,
41  IOobject
42  );
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
48 // Construct from components
50 :
52 {}
53 
54 
55 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
56 
58 {}
59 
60 
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 
64 {
65  // Do mesh changes (use inflation - put new points in topoChangeMap)
66  Info<< "rawTopoChangerFvMesh : Checking for topology changes..."
67  << endl;
68 
69  // Mesh not moved/changed yet
70  moving(false);
71  topoChanging(false);
72 
73  // Do any topology changes. Sets topoChanging (through polyTopoChange)
74  autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
75 
76  bool hasChanged = topoChangeMap.valid();
77 
78  if (hasChanged)
79  {
80  Info<< "rawTopoChangerFvMesh : Done topology changes..."
81  << endl;
82 
83  // Temporary: fix fields on patch faces created out of nothing
84  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85 
86  // Two situations:
87  // - internal faces inflated out of nothing
88  // - patch faces created out of previously internal faces
89 
90  // Is face mapped in any way?
91  PackedBoolList mappedFace(nFaces());
92 
93  const label nOldInternal = topoChangeMap().oldPatchStarts()[0];
94 
95  const labelList& faceMap = topoChangeMap().faceMap();
96  for (label facei = 0; facei < nInternalFaces(); facei++)
97  {
98  if (faceMap[facei] >= 0)
99  {
100  mappedFace[facei] = 1;
101  }
102  }
103  for (label facei = nInternalFaces(); facei < nFaces(); facei++)
104  {
105  if (faceMap[facei] >= 0 && faceMap[facei] >= nOldInternal)
106  {
107  mappedFace[facei] = 1;
108  }
109  }
110 
111  const List<objectMap>& fromFaces = topoChangeMap().facesFromFacesMap();
112 
113  forAll(fromFaces, i)
114  {
115  mappedFace[fromFaces[i].index()] = 1;
116  }
117 
118  const List<objectMap>& fromEdges = topoChangeMap().facesFromEdgesMap();
119 
120  forAll(fromEdges, i)
121  {
122  mappedFace[fromEdges[i].index()] = 1;
123  }
124 
125  const List<objectMap>& fromPts = topoChangeMap().facesFromPointsMap();
126 
127  forAll(fromPts, i)
128  {
129  mappedFace[fromPts[i].index()] = 1;
130  }
131 
132  // Set unmapped faces to zero
133  Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values."
134  << endl;
135  zeroUnmappedValues<scalar, fvPatchField, volMesh>(mappedFace);
136  zeroUnmappedValues<vector, fvPatchField, volMesh>(mappedFace);
137  zeroUnmappedValues<sphericalTensor, fvPatchField, volMesh>(mappedFace);
138  zeroUnmappedValues<symmTensor, fvPatchField, volMesh>(mappedFace);
139  zeroUnmappedValues<tensor, fvPatchField, volMesh>(mappedFace);
140 
141  if (topoChangeMap().hasMotionPoints())
142  {
143  pointField newPoints = topoChangeMap().preMotionPoints();
144 
145  // Give the meshModifiers opportunity to modify points
146  Info<< "rawTopoChangerFvMesh :"
147  << " calling modifyMotionPoints." << endl;
148  topoChanger_.modifyMotionPoints(newPoints);
149 
150  // Actually move points
151  Info<< "rawTopoChangerFvMesh :"
152  << " calling movePoints." << endl;
153 
154  movePoints(newPoints);
155  }
156  }
157  else
158  {
159  // Pout<< "rawTopoChangerFvMesh :"
160  // << " no topology changes..." << endl;
161  }
162 
163  return hasChanged;
164 }
165 
166 
167 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
bool moving() const
Is mesh moving.
Definition: polyMesh.H:512
label nInternalFaces() const
label nFaces() const
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool movePoints()
Do what is necessary if the mesh has moved.
virtual ~rawTopoChangerFvMesh()
Destructor.
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)
Abstract base class for a topology changing fvMesh.
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
Definition: autoPtrI.H:83
void modifyMotionPoints(pointField &) const
Modify point motion.
virtual bool update()
Update the mesh for both mesh motion and topology change.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
rawTopoChangerFvMesh(const IOobject &io)
Construct from database.
A bit-packed bool list.
bool topoChanging() const
Is mesh topology changing.
Definition: polyMesh.H:526
messageStream Info
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
polyTopoChanger topoChanger_
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.