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-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 "pointPatchMapper.H"
27 #include "pointPatch.H"
28 #include "polyTopoChangeMap.H"
29 #include "faceMapper.H"
30 #include "demandDrivenData.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 void Foam::pointPatchMapper::calcAddressing() const
35 {
36  if
37  (
38  directAddrPtr_
39  || interpolationAddrPtr_
40  || weightsPtr_
41  )
42  {
44  << "Addressing already calculated"
45  << abort(FatalError);
46  }
47 
48  if (direct())
49  {
50  // Direct mapping.
51  directAddrPtr_ = new labelList(map_.patchPointMap()[patch_.index()]);
52  }
53  else
54  {
55  // Interpolative mapping.
56 
57  // NOTE: Incorrect:
58  // FOR NOW only takes first patch point instead of averaging all
59  // patch points. Problem is we don't know what points were in the patch
60  // for points that were merged.
61 
62  interpolationAddrPtr_ = new labelListList(patch_.size());
63  labelListList& addr = *interpolationAddrPtr_;
64 
65  weightsPtr_ = new scalarListList(addr.size());
66  scalarListList& w = *weightsPtr_;
67 
68  const labelList& ppm = map_.patchPointMap()[patch_.index()];
69 
70  forAll(ppm, i)
71  {
72  if (ppm[i] >= 0)
73  {
74  addr[i] = labelList(1, ppm[i]);
75  w[i] = scalarList(1, 1.0);
76  }
77  else
78  {
79  // Inserted point.
81  // addr[i] = labelList(1, label(0));
82  // w[i] = scalarList(1, 1.0);
83  }
84  }
85  }
86 }
87 
88 
89 void Foam::pointPatchMapper::clearOut()
90 {
91  deleteDemandDrivenData(directAddrPtr_);
92  deleteDemandDrivenData(interpolationAddrPtr_);
93  deleteDemandDrivenData(weightsPtr_);
94 }
95 
96 
97 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
98 
100 (
101  const pointPatch& patch,
102  const pointMapper& pointMap,
103  const polyTopoChangeMap& map
104 )
105 :
107  patch_(patch),
108  pointMapper_(pointMap),
109  map_(map),
110  sizeBeforeMapping_
111  (
112  patch_.index() < map_.oldPatchNMeshPoints().size()
113  ? map_.oldPatchNMeshPoints()[patch_.index()]
114  : 0
115  ),
116  directAddrPtr_(nullptr),
117  interpolationAddrPtr_(nullptr),
118  weightsPtr_(nullptr)
119 {}
120 
121 
122 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
123 
125 {
126  clearOut();
127 }
128 
129 
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 
133 {
134  if (!direct())
135  {
137  << "Requested direct addressing for an interpolative mapper."
138  << abort(FatalError);
139  }
140 
141  if (!directAddrPtr_)
142  {
143  calcAddressing();
144  }
145 
146  return *directAddrPtr_;
147 }
148 
149 
151 {
152  if (direct())
153  {
155  << "Requested interpolative addressing for a direct mapper."
156  << abort(FatalError);
157  }
158 
159  if (!interpolationAddrPtr_)
160  {
161  calcAddressing();
162  }
163 
164  return *interpolationAddrPtr_;
165 }
166 
167 
169 {
170  if (direct())
171  {
173  << "Requested interpolative weights for a direct mapper."
174  << abort(FatalError);
175  }
176 
177  if (!weightsPtr_)
178  {
179  calcAddressing();
180  }
181 
182  return *weightsPtr_;
183 }
184 
185 
186 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
187 
188 
189 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
190 
191 
192 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
193 
194 
195 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:57
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