matchingPatchToPatch.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 "matchingPatchToPatch.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace patchToPatches
34 {
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 Foam::label Foam::patchToPatches::matching::finalise
44 (
45  const primitiveOldTimePatch& srcPatch,
46  const vectorField& srcPointNormals,
47  const vectorField& srcPointNormals0,
48  const primitiveOldTimePatch& tgtPatch,
49  const transformer& tgtToSrc
50 )
51 {
52  const label nCouples =
54  (
55  srcPatch,
56  srcPointNormals,
57  srcPointNormals0,
58  tgtPatch,
59  tgtToSrc
60  );
61 
62  // Make sure every face references exactly one face
63  auto forwardCheck = []
64  (
65  const primitiveOldTimePatch& patch,
66  const List<DynamicList<label>>& localOtherFaces,
67  const bool isSrc
68  )
69  {
70  forAll(localOtherFaces, facei)
71  {
72  if (localOtherFaces[facei].size() != 1)
73  {
75  << (isSrc ? "Source" : "Target")
76  << " face #" << facei << " at "
77  << patch.faceCentres()[facei]
78  << " did not match a face on the "
79  << (isSrc ? "target" : "source")
80  << " side" << exit(FatalError);
81  }
82  }
83  };
84  forwardCheck(srcPatch, srcLocalTgtFaces_, true);
85  forwardCheck(tgtPatch, tgtLocalSrcFaces_, false);
86 
87  // Make sure every face is referenced by exactly one face
88  auto reverseCheck = []
89  (
90  const primitiveOldTimePatch& patch,
91  const List<DynamicList<label>>& otherLocalFaces,
92  const autoPtr<distributionMap>& mapPtr,
93  const bool isSrc
94  )
95  {
97  (
98  mapPtr.valid() ? mapPtr->constructSize() : patch.size(),
99  0
100  );
101 
102  forAll(otherLocalFaces, otherFacei)
103  {
104  forAll(otherLocalFaces[otherFacei], i)
105  {
106  count[otherLocalFaces[otherFacei][i]] ++;
107  }
108  }
109 
110  if (mapPtr.valid())
111  {
113  (
115  List<labelPair>(),
116  patch.size(),
117  mapPtr->constructMap(),
118  false,
119  mapPtr->subMap(),
120  false,
121  count,
122  plusEqOp<label>(),
123  flipOp(),
124  label(0)
125  );
126  }
127 
128  forAll(count, facei)
129  {
130  if (count[facei] != 1)
131  {
133  << (isSrc ? "Source" : "Target")
134  << " face #" << facei << " at "
135  << patch.faceCentres()[facei]
136  << " did not match a face on the "
137  << (isSrc ? "target" : "source")
138  << " side" << exit(FatalError);
139  }
140  }
141  };
142  reverseCheck(srcPatch, tgtLocalSrcFaces_, srcMapPtr_, true);
143  reverseCheck(tgtPatch, srcLocalTgtFaces_, tgtMapPtr_, false);
144 
145  return nCouples;
146 }
147 
148 
149 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
150 
152 :
154 {}
155 
156 
157 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
158 
160 {}
161 
162 
163 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
static void distribute(const Pstream::commsTypes commsType, const List< labelPair > &schedule, const label constructSize, const labelListList &subMap, const bool subHasFlip, const labelListList &constructMap, const bool constructHasFlip, List< T > &, const negateOp &negOp, const int tag=UPstream::msgType())
Distribute data. Note:schedule only used for.
Class to generate coupling geometry between two primitive patches.
Definition: patchToPatch.H:56
tmp< Field< Type > > tgtToSrc(const Field< Type > &tgtFld) const
Interpolate a target patch field to the source with no left.
List< DynamicList< label > > tgtLocalSrcFaces_
For each target face, the coupled local source faces.
Definition: patchToPatch.H:73
autoPtr< distributionMap > srcMapPtr_
Map from source patch faces to target-local source patch faces.
Definition: patchToPatch.H:76
List< DynamicList< label > > srcLocalTgtFaces_
For each source face, the coupled local target faces.
Definition: patchToPatch.H:70
autoPtr< distributionMap > tgtMapPtr_
Map from target patch faces to source-local target patch faces.
Definition: patchToPatch.H:79
Class to generate patchToPatch coupling geometry. Couples a face to the single matching opposite face...
matching(const bool reverse)
Construct from components.
Class to generate patchToPatch coupling geometry. Couples a face to the single nearest opposite face ...
virtual label finalise(const primitiveOldTimePatch &srcPatch, const vectorField &srcPointNormals, const vectorField &srcPointNormals0, const primitiveOldTimePatch &tgtPatch, const transformer &tgtToSrc)
Finalise the intersection.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
volVectorField vectorField(fieldObject, mesh)
addToRunTimeSelectionTable(patchToPatch, intersection, bool)
defineTypeNameAndDebug(intersection, 0)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
void reverse(UList< T > &, const label n)
Definition: UListI.H:334
PrimitiveOldTimePatch< SubList< face >, const pointField & > primitiveOldTimePatch
Addressing for a faceList slice.
error FatalError
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.