triSurfaceAddressing.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Description
28  Contains fix for PrimitivePatch addressing (which doesn't work if surface
29  is non-manifold). Should be moved into PrimitivePatch.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #include "triSurface.H"
34 #include "PatchTools.H"
35 
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 
38 void Foam::triSurface::calcSortedEdgeFaces() const
39 {
40  if (sortedEdgeFacesPtr_)
41  {
43  << "sortedEdgeFacesPtr_ already set"
44  << abort(FatalError);
45  }
46 
47  const labelListList& eFaces = edgeFaces();
48 
49  sortedEdgeFacesPtr_.reset(new labelListList(eFaces.size()));
50  auto& sortedEdgeFaces = *sortedEdgeFacesPtr_;
51 
53 }
54 
55 
56 void Foam::triSurface::calcEdgeOwner() const
57 {
58  if (edgeOwnerPtr_)
59  {
61  << "edgeOwnerPtr_ already set"
62  << abort(FatalError);
63  }
64 
65  edgeOwnerPtr_.reset(new labelList(nEdges()));
66  auto& edgeOwner = *edgeOwnerPtr_;
67 
68  forAll(edges(), edgeI)
69  {
70  const edge& e = edges()[edgeI];
71 
72  const labelList& myFaces = edgeFaces()[edgeI];
73 
74  if (myFaces.size() == 1)
75  {
76  edgeOwner[edgeI] = myFaces[0];
77  }
78  else
79  {
80  // Find the first face whose vertices are aligned with the edge.
81  // (in case of multiply connected edge the best we can do)
82  edgeOwner[edgeI] = -1;
83 
84  forAll(myFaces, i)
85  {
86  const labelledTri& f = localFaces()[myFaces[i]];
87 
88  if
89  (
90  ((f[0] == e.start()) && (f[1] == e.end()))
91  || ((f[1] == e.start()) && (f[2] == e.end()))
92  || ((f[2] == e.start()) && (f[0] == e.end()))
93  )
94  {
95  edgeOwner[edgeI] = myFaces[i];
96 
97  break;
98  }
99  }
100 
101  if (edgeOwner[edgeI] == -1)
102  {
104  << "Edge " << edgeI << " vertices:" << e
105  << " is used by faces " << myFaces
106  << " vertices:"
107  << UIndirectList<labelledTri>(localFaces(), myFaces)
108  << " none of which use the edge vertices in the same order"
109  << nl << "I give up" << abort(FatalError);
110  }
111  }
112  }
113 }
114 
115 
116 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::PrimitivePatch<::Foam::List< labelledTri >, pointField >::edgeFaces
const labelListList & edgeFaces() const
Return edge-face addressing.
Definition: PrimitivePatch.C:262
PatchTools.H
triSurface.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::PatchTools::sortedEdgeFaces
static labelListList sortedEdgeFaces(const PrimitivePatch< FaceList, PointField > &)
Return edge-face addressing sorted by angle around the edge.
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
f
labelList f(nPoints)
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::triSurface::sortedEdgeFaces
const labelListList & sortedEdgeFaces() const
Return edge-face addressing sorted (for edges with more than.
Definition: triSurface.C:590