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-2013 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");
146  (
147  lookupObject<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 // ************************************************************************* //
virtual bool update()
Update the mesh for both mesh motion and topology change.
label nFaces() const
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
polyTopoChanger topoChanger_
const surfaceVectorField & Sf() const
Return cell face area vectors.
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set).
Definition: autoPtrI.H:83
const surfaceScalarField & phi() const
Return cell face motion fluxes.
A bit-packed bool list.
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 topoChanging() const
Is mesh topology changing.
Definition: polyMesh.H:507
autoPtr< mapPolyMesh > changeMesh(const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
messageStream Info
Namespace for OpenFOAM.
Abstract base class for a topology changing fvMesh.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
#define forAll(list, i)
Definition: UList.H:421
void modifyMotionPoints(pointField &) const
Modify point motion.
Macros for easy insertion into run-time selection tables.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > linearInterpolate(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: linear.H:107
label nInternalFaces() const
bool moving() const
Is mesh moving.
Definition: polyMesh.H:493
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
virtual ~rawTopoChangerFvMesh()
Destructor.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
bool movePoints()
Do what is neccessary if the mesh has moved.
U
Definition: pEqn.H:82
defineTypeNameAndDebug(combustionModel, 0)