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 | Copyright (C) 2011-2017 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
49 Foam::rawTopoChangerFvMesh::rawTopoChangerFvMesh(const IOobject& io)
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  // Special handling for phi: set unmapped faces to recreated phi
142  Info<< "rawTopoChangerFvMesh :"
143  << " recreating phi for unmapped boundary values." << endl;
144  const volVectorField& U = lookupObject<volVectorField>("U");
145  surfaceScalarField& phi = lookupObjectRef<surfaceScalarField>("phi");
146  setUnmappedValues
147  (
148  phi,
149  mappedFace,
150  (linearInterpolate(U) & Sf())()
151  );
152 
153 
154  if (topoChangeMap().hasMotionPoints())
155  {
156  pointField newPoints = topoChangeMap().preMotionPoints();
157 
158  // Give the meshModifiers opportunity to modify points
159  Info<< "rawTopoChangerFvMesh :"
160  << " calling modifyMotionPoints." << endl;
161  topoChanger_.modifyMotionPoints(newPoints);
162 
163  // Actually move points
164  Info<< "rawTopoChangerFvMesh :"
165  << " calling movePoints." << endl;
166 
167  movePoints(newPoints);
168  }
169  }
170  else
171  {
172  //Pout<< "rawTopoChangerFvMesh :"
173  // << " no topology changes..." << endl;
174  }
175 
176  return hasChanged;
177 }
178 
179 
180 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
const surfaceVectorField & Sf() const
Return cell face area vectors.
U
Definition: pEqn.H:83
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:496
label nInternalFaces() const
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > linearInterpolate(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: linear.H:107
label nFaces() const
const surfaceScalarField & phi() const
Return cell face motion fluxes.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
bool movePoints()
Do what is neccessary 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)
A bit-packed bool list.
bool topoChanging() const
Is mesh topology changing.
Definition: polyMesh.H:510
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.