1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
25 Remove a layer of cells and prepare addressing data
27 \*---------------------------------------------------------------------------*/
29 #include "layerAdditionRemoval.H"
31 #include "primitiveMesh.H"
32 #include "polyTopoChange.H"
33 #include "oppositeFace.H"
34 #include "polyTopoChanger.H"
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 bool Foam::layerAdditionRemoval::setLayerPairing() const
41 // This is also the most complex part of the topological change.
42 // Therefore it will be calculated here and stored as temporary
43 // data until the actual topological change, after which it will
46 // Algorithm for point collapse
47 // 1) Go through the master cell layer and for every face of
48 // the face zone find the opposite face in the master cell.
49 // Check the direction of the opposite face and adjust as
50 // necessary. Check other faces to find an edge defining
51 // relative orientation of the two faces and adjust the face
52 // as necessary. Once the face is adjusted, record the
53 // addressing between the master and slave vertex layer.
55 const polyMesh& mesh = topoChanger().mesh();
58 mesh.faceZones()[faceZoneID_.index()].masterCells();
60 const labelList& mf = mesh.faceZones()[faceZoneID_.index()];
62 const boolList& mfFlip =
63 mesh.faceZones()[faceZoneID_.index()].flipMap();
65 const faceList& faces = mesh.faces();
66 const cellList& cells = mesh.cells();
68 // Grab the local faces from the master zone
70 mesh.faceZones()[faceZoneID_.index()]().localFaces();
72 const labelList& meshPoints =
73 mesh.faceZones()[faceZoneID_.index()]().meshPoints();
75 // Create a list of points to collapse for every point of
77 if (pointsPairingPtr_ || facesPairingPtr_)
81 "void Foam::layerAdditionRemoval::setLayerPairing() const"
82 ) << "Problem with layer pairing data"
86 pointsPairingPtr_ = new labelList(meshPoints.size(), -1);
87 labelList& ptc = *pointsPairingPtr_;
89 facesPairingPtr_ = new labelList(mf.size(), -1);
90 labelList& ftc = *facesPairingPtr_;
91 // Pout << "meshPoints: " << meshPoints << nl
92 // << "localPoints: " << mesh.faceZones()[faceZoneID_.index()]().localPoints() << endl;
94 // For all faces, create the mapping
95 label nPointErrors = 0;
96 label nFaceErrors = 0;
100 // Get the local master face
101 face curLocalFace = mlf[faceI];
103 // Flip face based on flip index to recover original orientation
106 curLocalFace = curLocalFace.reverseFace();
109 // Get the opposing face from the master cell
110 oppositeFace lidFace =
111 cells[mc[faceI]].opposingFace(mf[faceI], faces);
113 if (!lidFace.found())
115 // This is not a valid layer; cannot continue
120 // Pout<< "curMasterFace: " << faces[mf[faceI]] << nl
121 // << "cell shape: " << mesh.cellShapes()[mc[faceI]] << nl
122 // << "curLocalFace: " << curLocalFace << nl
123 // << "lidFace: " << lidFace
124 // << " master index: " << lidFace.masterIndex()
125 // << " oppositeIndex: " << lidFace.oppositeIndex() << endl;
127 // Grab the opposite face for face collapse addressing
128 ftc[faceI] = lidFace.oppositeIndex();
130 // Using the local face insert the points into the lid list
131 forAll (curLocalFace, pointI)
133 const label clp = curLocalFace[pointI];
137 // Point not mapped yet. Insert the label
138 ptc[clp] = lidFace[pointI];
142 // Point mapped from some other face. Check the label
143 if (ptc[clp] != lidFace[pointI])
146 // Pout<< "Topological error in cell layer pairing. "
147 // << "This mesh is either topologically incorrect "
148 // << "or the master afce layer is not defined "
149 // << "consistently. Please check the "
150 // << "face zone flip map." << nl
151 // << "First index: " << ptc[clp]
152 // << " new index: " << lidFace[pointI] << endl;
156 // Pout << "ptc: " << ptc << endl;
159 reduce(nPointErrors, sumOp<label>());
160 reduce(nFaceErrors, sumOp<label>());
162 if (nPointErrors > 0 || nFaceErrors > 0)
176 const Foam::labelList& Foam::layerAdditionRemoval::pointsPairing() const
178 if (!pointsPairingPtr_)
182 "const labelList& layerAdditionRemoval::pointsPairing() const"
183 ) << "Problem with layer pairing data for object " << name()
184 << abort(FatalError);
187 return *pointsPairingPtr_;
190 const Foam::labelList& Foam::layerAdditionRemoval::facesPairing() const
192 if (!facesPairingPtr_)
196 "const labelList& layerAdditionRemoval::facesPairing() const"
197 ) << "Problem with layer pairing data for object " << name()
198 << abort(FatalError);
201 return *facesPairingPtr_;
205 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
207 void Foam::layerAdditionRemoval::modifyMotionPoints
209 pointField& motionPoints
214 Pout<< "void layerAdditionRemoval::modifyMotionPoints("
215 << "pointField& motionPoints) const for object "
221 Pout << "No motion point adjustment" << endl;
226 // ************************************************************************* //