1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
93 // << mesh.faceZones()[faceZoneID_.index()]().localPoints()
96 // For all faces, create the mapping
97 label nPointErrors = 0;
98 label nFaceErrors = 0;
102 // Get the local master face
103 face curLocalFace = mlf[faceI];
105 // Flip face based on flip index to recover original orientation
111 // Get the opposing face from the master cell
112 oppositeFace lidFace =
113 cells[mc[faceI]].opposingFace(mf[faceI], faces);
115 if (!lidFace.found())
117 // This is not a valid layer; cannot continue
122 // Pout<< "curMasterFace: " << faces[mf[faceI]] << nl
123 // << "cell shape: " << mesh.cellShapes()[mc[faceI]] << nl
124 // << "curLocalFace: " << curLocalFace << nl
125 // << "lidFace: " << lidFace
126 // << " master index: " << lidFace.masterIndex()
127 // << " oppositeIndex: " << lidFace.oppositeIndex() << endl;
129 // Grab the opposite face for face collapse addressing
130 ftc[faceI] = lidFace.oppositeIndex();
132 // Using the local face insert the points into the lid list
133 forAll(curLocalFace, pointI)
135 const label clp = curLocalFace[pointI];
139 // Point not mapped yet. Insert the label
140 ptc[clp] = lidFace[pointI];
144 // Point mapped from some other face. Check the label
145 if (ptc[clp] != lidFace[pointI])
148 // Pout<< "Topological error in cell layer pairing. "
149 // << "This mesh is either topologically incorrect "
150 // << "or the master afce layer is not defined "
151 // << "consistently. Please check the "
152 // << "face zone flip map." << nl
153 // << "First index: " << ptc[clp]
154 // << " new index: " << lidFace[pointI] << endl;
158 // Pout<< "ptc: " << ptc << endl;
161 reduce(nPointErrors, sumOp<label>());
162 reduce(nFaceErrors, sumOp<label>());
164 if (nPointErrors > 0 || nFaceErrors > 0)
178 const Foam::labelList& Foam::layerAdditionRemoval::pointsPairing() const
180 if (!pointsPairingPtr_)
184 "const labelList& layerAdditionRemoval::pointsPairing() const"
185 ) << "Problem with layer pairing data for object " << name()
186 << abort(FatalError);
189 return *pointsPairingPtr_;
192 const Foam::labelList& Foam::layerAdditionRemoval::facesPairing() const
194 if (!facesPairingPtr_)
198 "const labelList& layerAdditionRemoval::facesPairing() const"
199 ) << "Problem with layer pairing data for object " << name()
200 << abort(FatalError);
203 return *facesPairingPtr_;
207 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
209 void Foam::layerAdditionRemoval::modifyMotionPoints
211 pointField& motionPoints
216 Pout<< "void layerAdditionRemoval::modifyMotionPoints("
217 << "pointField& motionPoints) const for object "
223 Pout<< "No motion point adjustment" << endl;
228 // ************************************************************************* //