1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Remove a layer of cells and prepare addressing data
28 \*---------------------------------------------------------------------------*/
30 #include "layerAdditionRemoval.H"
32 #include "primitiveMesh.H"
33 #include "polyTopoChange.H"
34 #include "oppositeFace.H"
35 #include "polyTopoChanger.H"
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 bool Foam::layerAdditionRemoval::setLayerPairing() const
42 // This is also the most complex part of the topological change.
43 // Therefore it will be calculated here and stored as temporary
44 // data until the actual topological change, after which it will
47 // Algorithm for point collapse
48 // 1) Go through the master cell layer and for every face of
49 // the face zone find the opposite face in the master cell.
50 // Check the direction of the opposite face and adjust as
51 // necessary. Check other faces to find an edge defining
52 // relative orientation of the two faces and adjust the face
53 // as necessary. Once the face is adjusted, record the
54 // addressing between the master and slave vertex layer.
56 const polyMesh& mesh = topoChanger().mesh();
59 mesh.faceZones()[faceZoneID_.index()].masterCells();
61 const labelList& mf = mesh.faceZones()[faceZoneID_.index()];
63 const boolList& mfFlip =
64 mesh.faceZones()[faceZoneID_.index()].flipMap();
66 const faceList& faces = mesh.faces();
67 const cellList& cells = mesh.cells();
69 // Grab the local faces from the master zone
71 mesh.faceZones()[faceZoneID_.index()]().localFaces();
73 const labelList& meshPoints =
74 mesh.faceZones()[faceZoneID_.index()]().meshPoints();
76 // Create a list of points to collapse for every point of
78 if (pointsPairingPtr_ || facesPairingPtr_)
82 "void Foam::layerAdditionRemoval::setLayerPairing() const"
83 ) << "Problem with layer pairing data"
87 pointsPairingPtr_ = new labelList(meshPoints.size(), -1);
88 labelList& ptc = *pointsPairingPtr_;
90 facesPairingPtr_ = new labelList(mf.size(), -1);
91 labelList& ftc = *facesPairingPtr_;
92 // Pout << "meshPoints: " << meshPoints << nl
93 // << "localPoints: " << mesh.faceZones()[faceZoneID_.index()]().localPoints() << endl;
95 // For all faces, create the mapping
96 label nPointErrors = 0;
97 label nFaceErrors = 0;
101 // Get the local master face
102 face curLocalFace = mlf[faceI];
104 // Flip face based on flip index to recover original orientation
107 curLocalFace = curLocalFace.reverseFace();
110 // Get the opposing face from the master cell
111 oppositeFace lidFace =
112 cells[mc[faceI]].opposingFace(mf[faceI], faces);
114 if (!lidFace.found())
116 // This is not a valid layer; cannot continue
121 // Pout<< "curMasterFace: " << faces[mf[faceI]] << nl
122 // << "cell shape: " << mesh.cellShapes()[mc[faceI]] << nl
123 // << "curLocalFace: " << curLocalFace << nl
124 // << "lidFace: " << lidFace
125 // << " master index: " << lidFace.masterIndex()
126 // << " oppositeIndex: " << lidFace.oppositeIndex() << endl;
128 // Grab the opposite face for face collapse addressing
129 ftc[faceI] = lidFace.oppositeIndex();
131 // Using the local face insert the points into the lid list
132 forAll (curLocalFace, pointI)
134 const label clp = curLocalFace[pointI];
138 // Point not mapped yet. Insert the label
139 ptc[clp] = lidFace[pointI];
143 // Point mapped from some other face. Check the label
144 if (ptc[clp] != lidFace[pointI])
147 // Pout<< "Topological error in cell layer pairing. "
148 // << "This mesh is either topologically incorrect "
149 // << "or the master afce layer is not defined "
150 // << "consistently. Please check the "
151 // << "face zone flip map." << nl
152 // << "First index: " << ptc[clp]
153 // << " new index: " << lidFace[pointI] << endl;
157 // Pout << "ptc: " << ptc << endl;
160 reduce(nPointErrors, sumOp<label>());
161 reduce(nFaceErrors, sumOp<label>());
163 if (nPointErrors > 0 || nFaceErrors > 0)
177 const Foam::labelList& Foam::layerAdditionRemoval::pointsPairing() const
179 if (!pointsPairingPtr_)
183 "const labelList& layerAdditionRemoval::pointsPairing() const"
184 ) << "Problem with layer pairing data for object " << name()
185 << abort(FatalError);
188 return *pointsPairingPtr_;
191 const Foam::labelList& Foam::layerAdditionRemoval::facesPairing() const
193 if (!facesPairingPtr_)
197 "const labelList& layerAdditionRemoval::facesPairing() const"
198 ) << "Problem with layer pairing data for object " << name()
199 << abort(FatalError);
202 return *facesPairingPtr_;
206 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
208 void Foam::layerAdditionRemoval::modifyMotionPoints
210 pointField& motionPoints
215 Pout<< "void layerAdditionRemoval::modifyMotionPoints("
216 << "pointField& motionPoints) const for object "
222 Pout << "No motion point adjustment" << endl;
227 // ************************************************************************* //