patchIntersection.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2023-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "patchIntersection.H"
27 #include "primitivePatch.H"
28 #include "vtkWritePolyData.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
33 
34 namespace Foam
35 {
37 }
38 
39 
40 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
41 
42 void Foam::patchIntersection::report(const word& writeSuffix)
43 {
44  {
45  const primitivePatch patch
46  (
47  SubList<face>(faces_, faces_.size()),
48  points_
49  );
50 
51  scalar srcArea = 0, tgtArea = 0, intersectionArea = 0;
52  forAll(faces_, facei)
53  {
54  const scalar a = faces_[facei].mag(points_);
55  const bool isSrc = faceSrcFaces_[facei] != -1;
56  const bool isTgt = faceTgtFaces_[facei] != -1;
57  srcArea += isSrc ? a : 0;
58  tgtArea += isTgt ? a : 0;
59  intersectionArea += isSrc && isTgt ? a : 0;
60  }
61  Info<< indent << "Source/target coverage = "
62  << intersectionArea/srcArea << "/"
63  << intersectionArea/tgtArea << endl;
64 
65  DynamicList<label> nEdgesNFaces, nFacesNEdges;
66  forAll(faces_, facei)
67  {
68  const label n = faces_[facei].size();
69  nEdgesNFaces.resize(max(nEdgesNFaces.size(), n + 1), 0);
70  ++ nEdgesNFaces[n];
71  }
72  forAll(patch.edgeFaces(), edgei)
73  {
74  const label n = patch.edgeFaces()[edgei].size();
75  nFacesNEdges.resize(max(nFacesNEdges.size(), n + 1), 0);
76  ++ nFacesNEdges[n];
77  }
78  Info<< indent << "Faces by number of edges = (";
79  forAll(nEdgesNFaces, n)
80  {
81  Info<< (n ? " " : "") << nEdgesNFaces[n];
82  }
83  Info<< ")" << endl << indent << "Edges by number of faces = (";
84  forAll(nFacesNEdges, n)
85  {
86  Info<< (n ? " " : "") << nFacesNEdges[n];
87  }
88  Info<< ")" << endl;
89  }
90 
91  if (debug)
92  {
93  Info<< indent << "Writing intersected patch" << incrIndent << endl;
94 
95  const fileName patchFileName =
96  type() + "_patch" + (writeSuffix.empty() ? "" : "_")
97  + writeSuffix + ".vtk";
98  Info<< indent << "Writing patch to " << patchFileName << endl;
100  (
101  patchFileName,
102  "intersectedPatch",
103  false,
104  points_,
105  labelList(),
106  labelListList(),
107  faces_,
108  "srcFace",
109  false,
111  "tgtFace",
112  false,
114  );
115 
116  const fileName patchEdgesFileName =
117  type() + "_patchEdges" + (writeSuffix.empty() ? "" : "_")
118  + writeSuffix + ".vtk";
119  Info<< indent << "Writing patch edges to " << patchEdgesFileName
120  << endl;
121  const primitivePatch patch
122  (
123  SubList<face>(faces_, faces_.size()),
124  points_
125  );
126  labelField edgeNFaces(patch.nEdges());
127  forAll(patch.edgeFaces(), edgei)
128  {
129  edgeNFaces[edgei] = patch.edgeFaces()[edgei].size();
130  }
132  (
133  patchEdgesFileName,
134  "intersectedPatchEdges",
135  false,
136  patch.localPoints(),
137  labelList(),
138  patch.edges(),
139  faceList(),
140  "nFaces",
141  false,
142  edgeNFaces
143  );
144 
145  Info<< decrIndent;
146  }
147 }
148 
149 
150 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
151 
153 (
154  const label srcNPoints,
155  const label tgtNPoints,
156  const label srcNEdges,
157  const label tgtNEdges,
158  const label srcNFaces,
159  const label tgtNFaces
160 )
161 :
162  points_(),
163 
164  srcPointPoints_(srcNPoints),
165  tgtPointPoints_(tgtNPoints),
166  pointSrcPoints_(),
167  pointTgtPoints_(),
168 
169  srcEdgePoints_(srcNEdges),
170  tgtEdgePoints_(tgtNEdges),
171  pointSrcEdges_(),
172  pointTgtEdges_(),
173 
174  pointSrcFaces_(),
175  pointTgtFaces_(),
176 
177  faces_(),
178 
179  srcFaceFaces_(srcNFaces),
180  tgtFaceFaces_(tgtNFaces),
181  faceSrcFaces_(),
182  faceTgtFaces_()
183 {}
184 
185 
186 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
187 
189 {}
190 
191 
192 // ************************************************************************* //
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
void resize(const label)
Alter the addressed list size.
Definition: DynamicListI.H:216
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
label nEdges() const
Return number of edges in patch.
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
const labelListList & edgeFaces() const
Return edge-face addressing.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
A List obtained as a section of another List.
Definition: SubList.H:56
A class for handling file names.
Definition: fileName.H:82
Base class for patch intersections. Provides type name and debugging. See templated derivatives for a...
virtual word type() const =0
DynamicField< point > points_
The intersection points.
virtual ~patchIntersection()
Destructor.
void report(const word &writeSuffix=word::null)
Report properties of the intersection process.
DynamicList< face > faces_
The intersection faces.
DynamicList< label > faceTgtFaces_
The intersection faces' corresponding target faces, or -1.
patchIntersection(const label srcNPoints, const label tgtNPoints, const label srcNEdges, const label tgtNEdges, const label srcNFaces, const label tgtNFaces)
Construct given sizes.
static const bool orientToSource_
Flag to set whether the faces of the intersection are oriented the.
DynamicList< label > faceSrcFaces_
The intersection faces' corresponding source faces, or -1.
A class for handling words, derived from string.
Definition: word.H:63
void write(const fileName &file, const word &title, const bool binary, const PointField &points, const VertexList &vertices, const LineList &lines, const FaceList &faces, const wordList &fieldNames, const boolList &fieldIsPointValues, const UPtrList< const Field< label >> &fieldLabelValues #define FieldTypeValuesConstArg(Type, nullArg))
Write VTK polygonal data to a file. Takes a PtrList of fields of labels and.
Namespace for OpenFOAM.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:272
List< label > labelList
A List of labels.
Definition: labelList.H:56
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:265
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:49
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:243
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)