FreeFOAM The Cross-Platform CFD Toolkit
attachInterface.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-2010 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 "attachDetach.H"
27 #include <OpenFOAM/polyMesh.H>
28 #include <OpenFOAM/primitiveMesh.H>
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 const Foam::scalar Foam::attachDetach::positionDifference_ = 1e-8;
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::attachDetach::attachInterface
42 (
43  polyTopoChange& ref
44 ) const
45 {
46  // Algorithm:
47  // 1. Create the reverse patch out of the slave faces.
48  // 2. Go through all the mesh points from the master and slave patch.
49  // If the point labels are different, insert them into the point
50  // renumbering list and remove them from the mesh.
51  // 3. Remove all faces from the slave patch
52  // 4. Modify all the faces from the master patch by making them internal
53  // between the faceCell cells for the two patches. If the master owner
54  // is higher than the slave owner, turn the face around
55  // 5. Get all the faces attached to the slave patch points.
56  // If they have not been removed, renumber them using the
57  // point renumbering list.
58 
59  if (debug)
60  {
61  Pout<< "void attachDetach::attachInterface("
62  << "polyTopoChange& ref) const "
63  << " for object " << name() << " : "
64  << "Attaching interface" << endl;
65  }
66 
67  const polyMesh& mesh = topoChanger().mesh();
68  const faceList& faces = mesh.faces();
69  const labelList& own = mesh.faceOwner();
70  const labelList& nei = mesh.faceNeighbour();
71 
72  const polyPatch& masterPatch = mesh.boundaryMesh()[masterPatchID_.index()];
73  const polyPatch& slavePatch = mesh.boundaryMesh()[slavePatchID_.index()];
74 
75  const label masterPatchStart = masterPatch.start();
76  const label slavePatchStart = slavePatch.start();
77 
78  const labelList& slaveMeshPoints = slavePatch.meshPoints();
79 
80  const Map<label>& removedPointMap = pointMatchMap();
81 
82  const labelList removedPoints = removedPointMap.toc();
83 
84  forAll (removedPoints, pointI)
85  {
86  ref.setAction(polyRemovePoint(removedPoints[pointI]));
87  }
88 
89 // Pout << "Points to be mapped: " << removedPoints << endl;
90  // Remove all faces from the slave patch
91  for (label i = 0; i < slavePatch.size(); i++)
92  {
93  ref.setAction(polyRemoveFace(i + slavePatchStart));
94 // Pout << "Removing face " << i + slavePatchStart << endl;
95  }
96 
97  // Modify the faces from the master patch
98  const labelList& masterFaceCells = masterPatch.faceCells();
99  const labelList& slaveFaceCells = slavePatch.faceCells();
100 
101  const boolList& mfFlip = mesh.faceZones()[faceZoneID_.index()].flipMap();
102 
103  forAll (masterFaceCells, faceI)
104  {
105  // If slave neighbour is greater than master, face does not need
106  // turning. Modify it to become internal
107  if (masterFaceCells[faceI] < slaveFaceCells[faceI])
108  {
109  ref.setAction
110  (
111  polyModifyFace
112  (
113  faces[masterPatchStart + faceI], // modified face
114  masterPatchStart + faceI, // label of face being modified
115  masterFaceCells[faceI], // owner
116  slaveFaceCells[faceI], // neighbour
117  false, // face flip
118  -1, // patch for face
119  false, // remove from zone
120  faceZoneID_.index(), // zone for face
121  mfFlip[faceI] // face flip in zone
122  )
123  );
124  }
125  else
126  {
127  // Flip required
128  ref.setAction
129  (
130  polyModifyFace
131  (
132  faces[masterPatchStart + faceI].reverseFace(), // mod face
133  masterPatchStart + faceI, // label of face being modified
134  slaveFaceCells[faceI], // owner
135  masterFaceCells[faceI], // neighbour
136  true, // face flip
137  -1, // patch for face
138  false, // remove from zone
139  faceZoneID_.index(), // zone for face
140  !mfFlip[faceI] // face flip in zone
141  )
142  );
143  }
144  }
145 
146  // Renumber faces affected by point removal
147 // Pout << "slaveMeshPoints: " << slaveMeshPoints << endl;
148  // Make a map of faces that need to be renumbered
149  labelHashSet facesToModifyMap
150  (
151  slaveMeshPoints.size()*primitiveMesh::facesPerPoint_
152  );
153 
154  const labelListList& pf = mesh.pointFaces();
155 
156  // Grab all the faces off the points in the slave patch. If the face has
157  // not been removed, add it to the map of faces to renumber
158  forAll (slaveMeshPoints, pointI)
159  {
160  const labelList& curFaces = pf[slaveMeshPoints[pointI]];
161 
162  forAll (curFaces, faceI)
163  {
164  if (!ref.faceRemoved(curFaces[faceI]))
165  {
166  facesToModifyMap.insert(curFaces[faceI]);
167  }
168  }
169  }
170 
171  // Grab the faces to be renumbered
172  const labelList ftm = facesToModifyMap.toc();
173 
174  forAll (ftm, faceI)
175  {
176  // For every face to modify, copy the face and re-map the vertices.
177  // It is known all the faces will be changed since they hang off
178  // re-mapped vertices
179  label curFaceID = ftm[faceI];
180 
181  face newFace(faces[curFaceID]);
182 
183  forAll (newFace, pointI)
184  {
186  removedPointMap.find(newFace[pointI]);
187 
188  if (rpmIter != removedPointMap.end())
189  {
190  // Point mapped. Replace it
191  newFace[pointI] = rpmIter();
192  }
193  }
194 
195 // Pout<< "face label: " << curFaceID << " old face: " << faces[curFaceID] << " new face: " << newFace << endl;
196 
197  // Get face zone and its flip
198  label modifiedFaceZone = mesh.faceZones().whichZone(curFaceID);
199  bool modifiedFaceZoneFlip = false;
200 
201  if (modifiedFaceZone >= 0)
202  {
203  modifiedFaceZoneFlip =
204  mesh.faceZones()[modifiedFaceZone].flipMap()
205  [
206  mesh.faceZones()[modifiedFaceZone].whichFace(curFaceID)
207  ];
208  }
209 
210 
211  label patchID = mesh.boundaryMesh().whichPatch(curFaceID);
212  label neiCell;
213  if (patchID == -1)
214  {
215  neiCell = nei[curFaceID];
216  }
217  else
218  {
219  neiCell = -1;
220  }
221 
222 
223  // Modify the face
224  ref.setAction
225  (
226  polyModifyFace
227  (
228  newFace, // modified face
229  curFaceID, // label of face being modified
230  own[curFaceID], // owner
231  neiCell, // neighbour
232  false, // face flip
233  patchID, // patch for face
234  false, // remove from zone
235  modifiedFaceZone, // zone for face
236  modifiedFaceZoneFlip // face flip in zone
237  )
238  );
239  }
240 
241  if (debug)
242  {
243  Pout<< "void attachDetach::attachInterface("
244  << "polyTopoChange& ref) const "
245  << " for object " << name() << " : "
246  << "Finished attaching interface" << endl;
247  }
248 }
249 
250 
252 (
253  pointField& motionPoints
254 ) const
255 {
256  const Map<label>& removedPointMap = pointMatchMap();
257 
258  const labelList removedPoints = removedPointMap.toc();
259 
260  if (debug)
261  {
262  Pout<< "void attachDetach::modifyMotionPoints("
263  << "pointField& motionPoints) const "
264  << " for object " << name() << " : "
265  << "Adjusting motion points." << endl;
266 
267  // Calculate the difference in motion point positions
268  scalar pointDiff = 0;
269 
270  forAll (removedPoints, pointI)
271  {
272  pointDiff +=
273  mag
274  (
275  motionPoints[removedPoints[pointI]]
276  - motionPoints[removedPointMap.find(removedPoints[pointI])()]
277  );
278  }
279 
280  if (pointDiff > removedPoints.size()*positionDifference_)
281  {
282  Pout<< "Point motion difference = " << pointDiff << endl;
283  }
284  }
285 
286  // Put the slave point on top of the master point
287  forAll (removedPoints, pointI)
288  {
289  motionPoints[removedPoints[pointI]] =
290  motionPoints[removedPointMap.find(removedPoints[pointI])()];
291  }
292 
293 }
294 
295 
296 // ************************ vim: set sw=4 sts=4 et: ************************ //