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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "rawTopoChangerFvMesh.H"
29 #include "mapPolyMesh.H"
31 #include "volFields.H"
32 #include "linear.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(rawTopoChangerFvMesh, 0);
40  (
41  topoChangerFvMesh,
42  rawTopoChangerFvMesh,
43  IOobject
44  );
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
50 // Construct from components
51 Foam::rawTopoChangerFvMesh::rawTopoChangerFvMesh(const IOobject& io)
52 :
54 {}
55 
56 
57 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
58 
60 {}
61 
62 
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 
66 {
67  // Do mesh changes (use inflation - put new points in topoChangeMap)
68  Info<< "rawTopoChangerFvMesh : Checking for topology changes..."
69  << endl;
70 
71  // Mesh not moved/changed yet
72  moving(false);
73  topoChanging(false);
74 
75  // Do any topology changes. Sets topoChanging (through polyTopoChange)
76  autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
77 
78  bool hasChanged = topoChangeMap.valid();
79 
80  if (hasChanged)
81  {
82  Info<< "rawTopoChangerFvMesh : Done topology changes..."
83  << endl;
84 
85  // Temporary: fix fields on patch faces created out of nothing
86  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87 
88  // Two situations:
89  // - internal faces inflated out of nothing
90  // - patch faces created out of previously internal faces
91 
92  // Is face mapped in any way?
93  bitSet mappedFace(nFaces());
94 
95  const label nOldInternal = topoChangeMap().oldPatchStarts()[0];
96 
97  const labelList& faceMap = topoChangeMap().faceMap();
98  for (label facei = 0; facei < nInternalFaces(); facei++)
99  {
100  if (faceMap[facei] >= 0)
101  {
102  mappedFace.set(facei);
103  }
104  }
105  for (label facei = nInternalFaces(); facei < nFaces(); facei++)
106  {
107  if (faceMap[facei] >= 0 && faceMap[facei] >= nOldInternal)
108  {
109  mappedFace.set(facei);
110  }
111  }
112 
113  const List<objectMap>& fromFaces = topoChangeMap().facesFromFacesMap();
114 
115  forAll(fromFaces, i)
116  {
117  mappedFace.set(fromFaces[i].index());
118  }
119 
120  const List<objectMap>& fromEdges = topoChangeMap().facesFromEdgesMap();
121 
122  forAll(fromEdges, i)
123  {
124  mappedFace.set(fromEdges[i].index());
125  }
126 
127  const List<objectMap>& fromPts = topoChangeMap().facesFromPointsMap();
128 
129  forAll(fromPts, i)
130  {
131  mappedFace.set(fromPts[i].index());
132  }
133 
134  // Set unmapped faces to zero
135  Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values."
136  << endl;
137  zeroUnmappedValues<scalar, fvPatchField, volMesh>(mappedFace);
138  zeroUnmappedValues<vector, fvPatchField, volMesh>(mappedFace);
139  zeroUnmappedValues<sphericalTensor, fvPatchField, volMesh>(mappedFace);
140  zeroUnmappedValues<symmTensor, fvPatchField, volMesh>(mappedFace);
141  zeroUnmappedValues<tensor, fvPatchField, volMesh>(mappedFace);
142 
143  // Special handling for phi: set unmapped faces to recreated phi
144  Info<< "rawTopoChangerFvMesh :"
145  << " recreating phi for unmapped boundary values." << endl;
146 
147  const volVectorField& U = lookupObject<volVectorField>("U");
148  surfaceScalarField& phi = lookupObjectRef<surfaceScalarField>("phi");
149 
150  setUnmappedValues
151  (
152  phi,
153  mappedFace,
154  (linearInterpolate(U) & Sf())()
155  );
156 
157 
158  if (topoChangeMap().hasMotionPoints())
159  {
160  pointField newPoints = topoChangeMap().preMotionPoints();
161 
162  // Give the meshModifiers opportunity to modify points
163  Info<< "rawTopoChangerFvMesh :"
164  << " calling modifyMotionPoints." << endl;
165  topoChanger_.modifyMotionPoints(newPoints);
166 
167  // Actually move points
168  Info<< "rawTopoChangerFvMesh :"
169  << " calling movePoints." << endl;
170 
171  movePoints(newPoints);
172  }
173  }
174  else
175  {
176  //Pout<< "rawTopoChangerFvMesh :"
177  // << " no topology changes..." << endl;
178  }
179 
180  return hasChanged;
181 }
182 
183 
184 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:94
Foam::rawTopoChangerFvMesh::update
virtual bool update()
Update the mesh for both mesh motion and topology change.
Definition: rawTopoChangerFvMesh.C:65
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
mapPolyMesh.H
Foam::bitSet::set
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:563
Foam::autoPtr::valid
bool valid() const noexcept
True if the managed pointer is non-null.
Definition: autoPtrI.H:107
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
rawTopoChangerFvMesh.H
Foam::label
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:62
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::rawTopoChangerFvMesh::~rawTopoChangerFvMesh
virtual ~rawTopoChangerFvMesh()
Destructor.
Definition: rawTopoChangerFvMesh.C:59
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
U
U
Definition: pEqn.H:72
Foam::linearInterpolate
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > linearInterpolate(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: linear.H:112
Foam::List< label >
Foam::topoChangerFvMesh
Abstract base class for a topology changing fvMesh.
Definition: topoChangerFvMesh.H:52
Foam::GeometricField< vector, fvPatchField, volMesh >
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)