1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 Calculate cut edge global addressing, needed for vector-matrix
27 multiply on global boundaries.
29 \*---------------------------------------------------------------------------*/
31 #include "globalTetPolyPatchCellDecomp.H"
32 #include "tetPolyBoundaryMeshCellDecomp.H"
33 #include "tetPolyMeshCellDecomp.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 void globalTetPolyPatchCellDecomp::calcLocalEdgesIndices() const
47 Info<< "labelList globalTetPolyPatchCellDecomp::"
48 << "calcLocalEdgesIndices() const : "
49 << "calculating local edge indices"
53 // Get reference to the mesh
54 const tetPolyMeshCellDecomp& mesh = boundaryMesh().mesh();
56 // Get reference to edges
57 const edgeList& patchEdges = meshEdges();
59 localEdgeIndicesPtr_ = new labelList(patchEdges.size(), -1);
60 labelList& localEdgeInd = *localEdgeIndicesPtr_;
62 const lduAddressing& lduAddr = mesh.lduAddr();
64 forAll (patchEdges, edgeI)
69 patchEdges[edgeI].start(),
70 patchEdges[edgeI].end()
74 # ifdef DEBUGtetFemMatrix
75 if (localEdgeInd.size() > 0 && min(localEdgeInd) < 0)
79 "void globalTetPolyPatchCellDecomp::"
80 "calcLocalEdgesIndices() const"
81 ) << "Problem in local edge addressing"
88 Info<< "void globalTetPolyPatchCellDecomp::"
89 << "calcLocalEdgesIndices() const : "
90 << "finished calculating local edge indices"
96 void globalTetPolyPatchCellDecomp::calcCutEdgeIndices() const
100 Info<< "void globalTetPolyPatchCellDecomp::"
101 << "calcCutEdgeIndices() const : "
102 << "calculating cut edge indices"
106 if (cutEdgeIndicesPtr_)
110 "void globalTetPolyPatchCellDecomp::"
111 "calcCutEdgesIndices() const"
112 ) << "addressing already allocated"
113 << abort(FatalError);
116 // Get reference to the mesh
117 const tetPolyMeshCellDecomp& mesh = boundaryMesh().mesh();
119 // Get reference to edges
120 const edgeList& patchCutEdges = meshCutEdges();
122 cutEdgeIndicesPtr_ = new labelList(patchCutEdges.size(), -1);
123 labelList& cutEdgeInd = *cutEdgeIndicesPtr_;
125 const lduAddressing& lduAddr = mesh.lduAddr();
127 forAll (patchCutEdges, edgeI)
132 patchCutEdges[edgeI].start(),
133 patchCutEdges[edgeI].end()
139 Info<< "void globalTetPolyPatchCellDecomp::"
140 << "calcCutEdgeIndices() const : "
141 << "finished calculating cut edge indices"
147 void globalTetPolyPatchCellDecomp::calcCutEdgeAddressing() const
151 cutEdgeOwnerIndicesPtr_
152 || cutEdgeOwnerStartPtr_
153 || cutEdgeNeighbourIndicesPtr_
154 || cutEdgeNeighbourStartPtr_
155 || doubleCutEdgeIndicesPtr_
156 || doubleCutOwnerPtr_
157 || doubleCutNeighbourPtr_
158 || ownNeiDoubleMaskPtr_
163 "void globalTetPolyPatchCellDecomp::"
164 "calcCutEdgeAddressing() "
166 ) << "addressing already allocated"
167 << abort(FatalError);
171 // Make a list over all edges in the mesh. Mark the ones that are local
172 // to the patch and then collect the rest.
173 // For doubly cut edges, mark up the local points
175 const tetPolyMeshCellDecomp& mesh = boundaryMesh().mesh();
177 // Get reference to mesh points
178 const labelList& mp = meshPoints();
180 // Get reference to local edge indices
181 const labelList& cutEdges = cutEdgeIndices();
183 // Get the cut edge mask. It will be used to create the new mask
184 const scalarField& cutMask = meshCutEdgeMask();
186 // Mark up the cut edges
188 labelList cutIndexLookup(mesh.nEdges(), -1);
190 forAll (cutEdges, edgeI)
192 cutIndexLookup[cutEdges[edgeI]] = edgeI;
195 labelList localPointLabel(mesh.nPoints(), -1);
199 localPointLabel[mp[pointI]] = pointI;
202 // Get reference to addressing
203 const lduAddressing& ldu = mesh.lduAddr();
205 const labelList& globalOwner = ldu.lowerAddr();
206 const labelList& globalNeighbour = ldu.upperAddr();
208 // Allocate doubly cut arrays
209 doubleCutEdgeIndicesPtr_ = new labelList(cutEdges.size(), -1);
210 labelList& doubleCutEdges = *doubleCutEdgeIndicesPtr_;
212 doubleCutOwnerPtr_ = new labelList(cutEdges.size(), -1);
213 labelList& doubleCutOwn = *doubleCutOwnerPtr_;
215 doubleCutNeighbourPtr_ = new labelList(cutEdges.size(), -1);
216 labelList& doubleCutNei = *doubleCutNeighbourPtr_;
218 label nDoubleCut = 0;
223 // Allocate the array
224 cutEdgeOwnerIndicesPtr_ = new labelList(cutEdges.size(), -1);
225 labelList& own = *cutEdgeOwnerIndicesPtr_;
228 cutEdgeOwnerStartPtr_ = new labelList(mp.size() + 1, -1);
229 labelList& ownStart = *cutEdgeOwnerStartPtr_;
231 // Go through all the local points and get all the edges coming
232 // from that point. Check if the edge has been marked as cut;
233 // add it to the list of cut edges and grab the mask value that goes
237 ownStart[pointI] = nOwn;
239 const label curPointID = mp[pointI];
241 // get owner edges indices
242 const label startFaceOwn = ldu.ownerStartAddr()[curPointID];
243 const label endFaceOwn = ldu.ownerStartAddr()[curPointID + 1];
247 label edgeLabel = startFaceOwn;
248 edgeLabel < endFaceOwn;
252 if (cutIndexLookup[edgeLabel] >= 0)
254 if (localPointLabel[globalNeighbour[edgeLabel]] == -1)
257 own[nOwn] = edgeLabel;
263 doubleCutEdges[nDoubleCut] = edgeLabel;
264 doubleCutOwn[nDoubleCut] = pointI;
265 doubleCutNei[nDoubleCut] =
266 localPointLabel[globalNeighbour[edgeLabel]];
274 // reset the size of owner edges
277 // set the last start label by hand
278 ownStart[mp.size()] = nOwn;
283 // Allocate the array
284 cutEdgeNeighbourIndicesPtr_ = new labelList(cutEdges.size(), -1);
285 labelList& nei = *cutEdgeNeighbourIndicesPtr_;
288 cutEdgeNeighbourStartPtr_ = new labelList(mp.size() + 1, -1);
289 labelList& neiStart = *cutEdgeNeighbourStartPtr_;
291 const unallocLabelList& losort = ldu.losortAddr();
293 // Go through all the local points and get all the edges coming
294 // from that point. Check if the edge has been marked as local;
295 // if not, add it to the list of cut edges.
298 neiStart[pointI] = nNei;
300 const label curPointID = mp[pointI];
302 // get neighbour edges indices
303 const label startFaceNei = ldu.losortStartAddr()[curPointID];
304 const label endFaceNei = ldu.losortStartAddr()[curPointID + 1];
308 label edgeLabel = startFaceNei;
309 edgeLabel < endFaceNei;
313 if (cutIndexLookup[losort[edgeLabel]] >= 0)
315 if (localPointLabel[globalOwner[losort[edgeLabel]]] == -1)
318 nei[nNei] = losort[edgeLabel];
324 doubleCutEdges[nDoubleCut] = losort[edgeLabel];
325 doubleCutOwn[nDoubleCut] =
326 localPointLabel[globalOwner[losort[edgeLabel]]];
327 doubleCutNei[nDoubleCut] = pointI;
335 // reset the size of neighbour edges
338 // set the last start label by hand
339 neiStart[mp.size()] = nNei;
341 // Reset the size of double cut edge data
342 doubleCutEdges.setSize(nDoubleCut);
343 doubleCutOwn.setSize(nDoubleCut);
344 doubleCutNei.setSize(nDoubleCut);
346 // Allocate the reordered mask that corresponds to the owner-neighbour
347 // coefficient ordering
348 ownNeiDoubleMaskPtr_ =
351 own.size() + nei.size()
352 + doubleCutOwn.size() + doubleCutNei.size()
354 scalarField& ownNeiDoubleMask = *ownNeiDoubleMaskPtr_;
360 ownNeiDoubleMask[nMask] = cutMask[cutIndexLookup[own[i]]];
366 ownNeiDoubleMask[nMask] = cutMask[cutIndexLookup[nei[i]]];
370 forAll (doubleCutOwn, i)
372 ownNeiDoubleMask[nMask] = cutMask[cutIndexLookup[doubleCutOwn[i]]];
375 ownNeiDoubleMask[nMask] = cutMask[cutIndexLookup[doubleCutNei[i]]];
381 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
383 const labelList& globalTetPolyPatchCellDecomp::localEdgeIndices() const
385 if (!localEdgeIndicesPtr_)
387 calcLocalEdgesIndices();
390 return *localEdgeIndicesPtr_;
395 globalTetPolyPatchCellDecomp::cutEdgeIndices() const
397 if (!cutEdgeIndicesPtr_)
399 calcCutEdgeIndices();
402 return *cutEdgeIndicesPtr_;
407 globalTetPolyPatchCellDecomp::cutEdgeOwnerIndices() const
409 if (!cutEdgeOwnerIndicesPtr_)
411 calcCutEdgeAddressing();
414 return *cutEdgeOwnerIndicesPtr_;
419 globalTetPolyPatchCellDecomp::cutEdgeOwnerStart() const
421 if (!cutEdgeOwnerStartPtr_)
423 calcCutEdgeAddressing();
426 return *cutEdgeOwnerStartPtr_;
431 globalTetPolyPatchCellDecomp::cutEdgeNeighbourIndices() const
433 if (!cutEdgeNeighbourIndicesPtr_)
435 calcCutEdgeAddressing();
438 return *cutEdgeNeighbourIndicesPtr_;
443 globalTetPolyPatchCellDecomp::cutEdgeNeighbourStart() const
445 if (!cutEdgeNeighbourStartPtr_)
447 calcCutEdgeAddressing();
450 return *cutEdgeNeighbourStartPtr_;
455 globalTetPolyPatchCellDecomp::doubleCutEdgeIndices() const
457 if (!doubleCutEdgeIndicesPtr_)
459 calcCutEdgeAddressing();
462 return *doubleCutEdgeIndicesPtr_;
466 const labelList& globalTetPolyPatchCellDecomp::doubleCutOwner() const
468 if (!doubleCutOwnerPtr_)
470 calcCutEdgeAddressing();
473 return *doubleCutOwnerPtr_;
478 globalTetPolyPatchCellDecomp::doubleCutNeighbour() const
480 if (!doubleCutNeighbourPtr_)
482 calcCutEdgeAddressing();
485 return *doubleCutNeighbourPtr_;
490 globalTetPolyPatchCellDecomp::ownNeiDoubleMask() const
492 if (!ownNeiDoubleMaskPtr_)
494 calcCutEdgeAddressing();
497 return *ownNeiDoubleMaskPtr_;
501 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
503 } // End namespace Foam
505 // ************************************************************************* //