pointPatchMapper.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) 2011-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 "pointPatchMapper.H"
27 #include "polyTopoChangeMap.H"
28 #include "demandDrivenData.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 void Foam::pointPatchMapper::calcAddressing() const
33 {
34  if
35  (
36  directAddrPtr_
37  || interpolationAddrPtr_
38  || weightsPtr_
39  )
40  {
42  << "Addressing already calculated"
43  << abort(FatalError);
44  }
45 
46  if (direct())
47  {
48  // Direct mapping.
49  directAddrPtr_ = new labelList(map_.patchPointMap()[patch_.index()]);
50  }
51  else
52  {
53  // Interpolative mapping.
54 
55  // NOTE: Incorrect:
56  // FOR NOW only takes first patch point instead of averaging all
57  // patch points. Problem is we don't know what points were in the patch
58  // for points that were merged.
59 
60  interpolationAddrPtr_ = new labelListList(patch_.size());
61  labelListList& addr = *interpolationAddrPtr_;
62 
63  weightsPtr_ = new scalarListList(addr.size());
64  scalarListList& w = *weightsPtr_;
65 
66  const labelList& ppm = map_.patchPointMap()[patch_.index()];
67 
68  forAll(ppm, i)
69  {
70  if (ppm[i] >= 0)
71  {
72  addr[i] = labelList(1, ppm[i]);
73  w[i] = scalarList(1, 1.0);
74  }
75  else
76  {
77  // Inserted point.
79  // addr[i] = labelList(1, label(0));
80  // w[i] = scalarList(1, 1.0);
81  }
82  }
83  }
84 }
85 
86 
87 void Foam::pointPatchMapper::clearOut()
88 {
89  deleteDemandDrivenData(directAddrPtr_);
90  deleteDemandDrivenData(interpolationAddrPtr_);
91  deleteDemandDrivenData(weightsPtr_);
92 }
93 
94 
95 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 
98 (
99  const pointPatch& patch,
100  const pointMapper& pointMap,
101  const polyTopoChangeMap& map
102 )
103 :
105  patch_(patch),
106  pointMapper_(pointMap),
107  map_(map),
108  sizeBeforeMapping_
109  (
110  patch_.index() < map_.oldPatchNMeshPoints().size()
111  ? map_.oldPatchNMeshPoints()[patch_.index()]
112  : 0
113  ),
114  directAddrPtr_(nullptr),
115  interpolationAddrPtr_(nullptr),
116  weightsPtr_(nullptr)
117 {}
118 
119 
120 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
121 
123 {
124  clearOut();
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
131 {
132  if (!direct())
133  {
135  << "Requested direct addressing for an interpolative mapper."
136  << abort(FatalError);
137  }
138 
139  if (!directAddrPtr_)
140  {
141  calcAddressing();
142  }
143 
144  return *directAddrPtr_;
145 }
146 
147 
149 {
150  if (direct())
151  {
153  << "Requested interpolative addressing for a direct mapper."
154  << abort(FatalError);
155  }
156 
157  if (!interpolationAddrPtr_)
158  {
159  calcAddressing();
160  }
161 
162  return *interpolationAddrPtr_;
163 }
164 
165 
167 {
168  if (direct())
169  {
171  << "Requested interpolative weights for a direct mapper."
172  << abort(FatalError);
173  }
174 
175  if (!weightsPtr_)
176  {
177  calcAddressing();
178  }
179 
180  return *weightsPtr_;
181 }
182 
183 
184 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
General field mapper supporting both direct and weighted mapping.
This object provides mapping and fill-in information for point data between the two meshes after the ...
Definition: pointMapper.H:58
virtual const labelListList & addressing() const
Return interpolated addressing.
virtual const scalarListList & weights() const
Return interpolation weights.
virtual const labelUList & directAddressing() const
Return direct addressing.
pointPatchMapper(const pointPatch &patch, const pointMapper &pointMap, const polyTopoChangeMap &map)
Construct from mappers.
virtual ~pointPatchMapper()
Destructor.
virtual bool direct() const
Is the mapping direct?
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
virtual label index() const =0
Return the index of this patch in the pointBoundaryMesh.
virtual label size() const =0
Return size.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelListList & patchPointMap() const
Patch point renumbering.
Template functions to aid in the implementation of demand driven data.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
List< scalarList > scalarListList
Definition: scalarList.H:51
List< label > labelList
A List of labels.
Definition: labelList.H:56
void deleteDemandDrivenData(DataType *&dataPtr)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
error FatalError