nearbyPatchToPatch.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) 2021-2022 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 "nearbyPatchToPatch.H"
27 #include "boundSphere.H"
28 #include "OFstream.H"
29 #include "OBJstream.H"
30 #include "vtkWritePolyData.H"
31 #include "mathematicalConstants.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace patchToPatches
38 {
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
47 (
48  const face& srcFace,
49  const pointField& srcPoints,
50  const vectorField& srcPointNormals
51 ) const
52 {
53  const treeBoundBox bb(srcPoints, srcFace);
54 
55  const point c = bb.midpoint();
56  const scalar l = bb.maxDim();
57 
58  return treeBoundBox(c - l*vector::one, c + l*vector::one);
59 }
60 
61 
63 (
64  const primitiveOldTimePatch& srcPatch,
65  const vectorField& srcPointNormals,
66  const vectorField& srcPointNormals0,
67  const primitiveOldTimePatch& tgtPatch,
68  const label srcFacei,
69  const label tgtFacei
70 )
71 {
72  const point& srcC = srcSpheres_[srcFacei].first();
73  const scalar srcR = srcSpheres_[srcFacei].second();
74  const point& tgtC = tgtSpheres_[tgtFacei].first();
75  const scalar tgtR = tgtSpheres_[tgtFacei].second();
76 
77  if (magSqr(srcC - tgtC) < sqr(srcR + tgtR))
78  {
79  srcLocalTgtFaces_[srcFacei].append(tgtFacei);
80  tgtLocalSrcFaces_[tgtFacei].append(srcFacei);
81 
82  return true;
83  }
84  else
85  {
86  return false;
87  }
88 }
89 
90 
92 (
93  const primitiveOldTimePatch& srcPatch,
94  const vectorField& srcPointNormals,
95  const vectorField& srcPointNormals0,
96  const primitiveOldTimePatch& tgtPatch
97 )
98 {
100  (
101  srcPatch,
102  srcPointNormals,
103  srcPointNormals0,
104  tgtPatch
105  );
106 
107  srcSpheres_.resize(srcPatch.size());
108  forAll(srcPatch, srcFacei)
109  {
110  srcSpheres_[srcFacei] =
112  (
113  UIndirectList<point>(srcPatch.points(), srcPatch[srcFacei])
114  );
115  }
116 
117  tgtSpheres_.resize(tgtPatch.size());
118  forAll(tgtPatch, tgtFacei)
119  {
120  tgtSpheres_[tgtFacei] =
122  (
123  UIndirectList<point>(tgtPatch.points(), tgtPatch[tgtFacei])
124  );
125  }
126 }
127 
128 
129 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
130 
132 :
134  srcSpheres_(),
135  tgtSpheres_()
136 {}
137 
138 
139 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
140 
142 {}
143 
144 
145 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Functions for constructing bounding spheres of lists of points.
const Field< PointType > & points() const
Return reference to global points.
A List with indirect addressing.
Definition: UIndirectList.H:60
static const Form one
Definition: VectorSpace.H:114
point midpoint() const
The midpoint of the bounding box.
Definition: boundBoxI.H:78
scalar maxDim() const
Largest length/height/width dimension.
Definition: boundBoxI.H:108
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
Class to generate coupling geometry between two primitive patches.
Definition: patchToPatch.H:56
virtual void initialise(const primitiveOldTimePatch &srcPatch, const vectorField &srcPointNormals, const vectorField &srcPointNormals0, const primitiveOldTimePatch &tgtPatch)
Initialisation.
Definition: patchToPatch.C:640
Class to generate patchToPatch coupling geometry. Couples a face to the single nearby opposite face o...
nearby(const bool reverse)
Construct from components.
virtual bool intersectFaces(const primitiveOldTimePatch &srcPatch, const vectorField &srcPointNormals, const vectorField &srcPointNormals0, const primitiveOldTimePatch &tgtPatch, const label srcFacei, const label tgtFacei)
Intersect two faces.
virtual treeBoundBox srcBox(const face &srcFace, const pointField &srcPoints, const vectorField &srcPointNormals) const
Get the bound box for a source face.
virtual void initialise(const primitiveOldTimePatch &srcPatch, const vectorField &srcPointNormals, const vectorField &srcPointNormals0, const primitiveOldTimePatch &tgtPatch)
Initialisation.
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:90
const dimensionedScalar c
Speed of light in a vacuum.
defineTypeNameAndDebug(intersection, 0)
Namespace for OpenFOAM.
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
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void reverse(UList< T > &, const label n)
Definition: UListI.H:334
Tuple2< point, scalar > boundSphere(const PointField &ps, Random &rndGen)
Compute a bounding sphere for an arbitrary number of points, and given an.
dimensioned< scalar > magSqr(const dimensioned< Type > &)