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 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 area = 0, srcArea = 0, tgtArea = 0;
52  forAll(faces_, facei)
53  {
54  const scalar a = faces_[facei].mag(points_);
55  area += a;
56  srcArea += faceSrcFaces_[facei] != -1 ? a : 0;
57  tgtArea += faceTgtFaces_[facei] != -1 ? a : 0;
58  }
59  Info<< indent << "Source/target coverage = " << srcArea/area
60  << "/" << tgtArea/area << endl;
61 
62  DynamicList<label> nEdgesNFaces, nFacesNEdges;
63  forAll(faces_, facei)
64  {
65  const label n = faces_[facei].size();
66  nEdgesNFaces.resize(max(nEdgesNFaces.size(), n + 1), 0);
67  ++ nEdgesNFaces[n];
68  }
69  forAll(patch.edgeFaces(), edgei)
70  {
71  const label n = patch.edgeFaces()[edgei].size();
72  nFacesNEdges.resize(max(nFacesNEdges.size(), n + 1), 0);
73  ++ nFacesNEdges[n];
74  }
75  Info<< indent << "Faces by number of edges = (";
76  forAll(nEdgesNFaces, n)
77  {
78  Info<< (n ? " " : "") << nEdgesNFaces[n];
79  }
80  Info<< ")" << endl << indent << "Edges by number of faces = (";
81  forAll(nFacesNEdges, n)
82  {
83  Info<< (n ? " " : "") << nFacesNEdges[n];
84  }
85  Info<< ")" << endl;
86  }
87 
88  if (debug)
89  {
90  Info<< indent << "Writing intersected patch" << incrIndent << endl;
91 
92  const fileName patchFileName =
93  type() + "_patch" + (writeSuffix.empty() ? "" : "_")
94  + writeSuffix + ".vtk";
95  Info<< indent << "Writing patch to " << patchFileName << endl;
97  (
98  patchFileName,
99  "intersectedPatch",
100  false,
101  points_,
102  labelList(),
103  labelListList(),
104  faces_,
105  "srcFace",
106  false,
108  "tgtFace",
109  false,
111  );
112 
113  const fileName patchEdgesFileName =
114  type() + "_patchEdges" + (writeSuffix.empty() ? "" : "_")
115  + writeSuffix + ".vtk";
116  Info<< indent << "Writing patch edges to " << patchEdgesFileName
117  << endl;
118  const primitivePatch patch
119  (
120  SubList<face>(faces_, faces_.size()),
121  points_
122  );
123  labelField edgeNFaces(patch.nEdges());
124  forAll(patch.edgeFaces(), edgei)
125  {
126  edgeNFaces[edgei] = patch.edgeFaces()[edgei].size();
127  }
129  (
130  patchEdgesFileName,
131  "intersectedPatchEdges",
132  false,
133  patch.localPoints(),
134  labelList(),
135  patch.edges(),
136  faceList(),
137  "nFaces",
138  false,
139  edgeNFaces
140  );
141 
142  Info<< decrIndent;
143  }
144 }
145 
146 
147 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
148 
150 (
151  const label srcNPoints,
152  const label tgtNPoints,
153  const label srcNEdges,
154  const label tgtNEdges,
155  const label srcNFaces,
156  const label tgtNFaces
157 )
158 :
159  points_(),
160 
161  srcPointPoints_(srcNPoints),
162  tgtPointPoints_(tgtNPoints),
163  pointSrcPoints_(),
164  pointTgtPoints_(),
165 
166  srcEdgePoints_(srcNEdges),
167  tgtEdgePoints_(tgtNEdges),
168  pointSrcEdges_(),
169  pointTgtEdges_(),
170 
171  pointSrcFaces_(),
172  pointTgtFaces_(),
173 
174  faces_(),
175 
176  srcFaceFaces_(srcNFaces),
177  tgtFaceFaces_(tgtNFaces),
178  faceSrcFaces_(),
179  faceTgtFaces_()
180 {}
181 
182 
183 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
184 
186 {}
187 
188 
189 // ************************************************************************* //
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:62
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:241
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:257
messageStream Info
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:234
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
Field< label > labelField
Specialisation of Field<T> for label.
Definition: labelField.H:49
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:227