FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2007 OpenCFD Ltd.
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 <OpenFOAM/mapPolyMesh.H>
29 #include <finiteVolume/volFields.H>
30 #include <finiteVolume/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  autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(true);
69 
70  bool hasChanged = topoChangeMap.valid();
71 
72  if (hasChanged)
73  {
74  Info<< "rawTopoChangerFvMesh : Done topology changes..."
75  << endl;
76 
77  // Temporary: fix fields on patch faces created out of nothing
78  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79 
80  // Two situations:
81  // - internal faces inflated out of nothing
82  // - patch faces created out of previously internal faces
83 
84  // Is face mapped in any way
85  PackedList<1> mappedFace(nFaces());
86 
87  const label nOldInternal = topoChangeMap().oldPatchStarts()[0];
88 
89  const labelList& faceMap = topoChangeMap().faceMap();
90  for (label faceI = 0; faceI < nInternalFaces(); faceI++)
91  {
92  if (faceMap[faceI] >= 0)
93  {
94  mappedFace[faceI] = 1;
95  }
96  }
97  for (label faceI = nInternalFaces(); faceI < nFaces(); faceI++)
98  {
99  if (faceMap[faceI] >= 0 && faceMap[faceI] >= nOldInternal)
100  {
101  mappedFace[faceI] = 1;
102  }
103  }
104 
105  const List<objectMap>& fromFaces = topoChangeMap().facesFromFacesMap();
106 
107  forAll(fromFaces, i)
108  {
109  mappedFace[fromFaces[i].index()] = 1;
110  }
111 
112  const List<objectMap>& fromEdges = topoChangeMap().facesFromEdgesMap();
113 
114  forAll(fromEdges, i)
115  {
116  mappedFace[fromEdges[i].index()] = 1;
117  }
118 
119  const List<objectMap>& fromPts = topoChangeMap().facesFromPointsMap();
120 
121  forAll(fromPts, i)
122  {
123  mappedFace[fromPts[i].index()] = 1;
124  }
125 
126  // Set unmapped faces to zero
127  Info<< "rawTopoChangerFvMesh : zeroing unmapped boundary values."
128  << endl;
129  zeroUnmappedValues<scalar, fvPatchField, volMesh>(mappedFace);
130  zeroUnmappedValues<vector, fvPatchField, volMesh>(mappedFace);
131  zeroUnmappedValues<sphericalTensor, fvPatchField, volMesh>(mappedFace);
132  zeroUnmappedValues<symmTensor, fvPatchField, volMesh>(mappedFace);
133  zeroUnmappedValues<tensor, fvPatchField, volMesh>(mappedFace);
134 
135  // Special handling for phi: set unmapped faces to recreated phi
136  Info<< "rawTopoChangerFvMesh :"
137  << " recreating phi for unmapped boundary values." << endl;
138  const volVectorField& U = lookupObject<volVectorField>("U");
140  (
141  lookupObject<surfaceScalarField>("phi")
142  );
143  setUnmappedValues
144  (
145  phi,
146  mappedFace,
147  (linearInterpolate(U) & Sf())()
148  );
149 
150 
151  if (topoChangeMap().hasMotionPoints())
152  {
153  pointField newPoints = topoChangeMap().preMotionPoints();
154 
155  // Give the meshModifiers opportunity to modify points
156  Info<< "rawTopoChangerFvMesh :"
157  << " calling modifyMotionPoints." << endl;
158  topoChanger_.modifyMotionPoints(newPoints);
159 
160  // Actually move points
161  Info<< "rawTopoChangerFvMesh :"
162  << " calling movePoints." << endl;
163 
164  movePoints(newPoints);
165  }
166  }
167  else
168  {
169  //Pout<< "rawTopoChangerFvMesh :"
170  // << " no topology changes..." << endl;
171  }
172 
173  changing(hasChanged);
174 
175  return hasChanged;
176 }
177 
178 
179 // ************************************************************************* //