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-2019 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 "mapPolyMesh.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  hasUnmapped_ = false;
49 
50  if (direct())
51  {
52  // Direct mapping.
53  directAddrPtr_ = new labelList(mpm_.patchPointMap()[patch_.index()]);
54  labelList& addr = *directAddrPtr_;
55 
56  forAll(addr, i)
57  {
58  if (addr[i] < 0)
59  {
60  hasUnmapped_ = true;
61  }
62  }
63  }
64  else
65  {
66  // Interpolative mapping.
67 
68  // NOTE: Incorrect:
69  // FOR NOW only takes first patch point instead of averaging all
70  // patch points. Problem is we don't know what points were in the patch
71  // for points that were merged.
72 
73  interpolationAddrPtr_ = new labelListList(patch_.size());
74  labelListList& addr = *interpolationAddrPtr_;
75 
76  weightsPtr_ = new scalarListList(addr.size());
77  scalarListList& w = *weightsPtr_;
78 
79  const labelList& ppm = mpm_.patchPointMap()[patch_.index()];
80 
81  forAll(ppm, i)
82  {
83  if (ppm[i] >= 0)
84  {
85  addr[i] = labelList(1, ppm[i]);
86  w[i] = scalarList(1, 1.0);
87  }
88  else
89  {
90  // Inserted point.
92  // addr[i] = labelList(1, label(0));
93  // w[i] = scalarList(1, 1.0);
94  hasUnmapped_ = true;
95  }
96  }
97  }
98 }
99 
100 
101 void Foam::pointPatchMapper::clearOut()
102 {
103  deleteDemandDrivenData(directAddrPtr_);
104  deleteDemandDrivenData(interpolationAddrPtr_);
105  deleteDemandDrivenData(weightsPtr_);
106  hasUnmapped_ = false;
107 }
108 
109 
110 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
111 
113 (
114  const pointPatch& patch,
115  const pointMapper& pointMap,
116  const mapPolyMesh& mpm
117 )
118 :
120  patch_(patch),
121  pointMapper_(pointMap),
122  mpm_(mpm),
123  sizeBeforeMapping_
124  (
125  patch_.index() < mpm_.oldPatchNMeshPoints().size()
126  ? mpm_.oldPatchNMeshPoints()[patch_.index()]
127  : 0
128  ),
129  hasUnmapped_(false),
130  directAddrPtr_(nullptr),
131  interpolationAddrPtr_(nullptr),
132  weightsPtr_(nullptr)
133 {}
134 
135 
136 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
137 
139 {
140  clearOut();
141 }
142 
143 
144 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
145 
147 {
148  if (!direct())
149  {
151  << "Requested direct addressing for an interpolative mapper."
152  << abort(FatalError);
153  }
154 
155  if (!directAddrPtr_)
156  {
157  calcAddressing();
158  }
159 
160  return *directAddrPtr_;
161 }
162 
163 
165 {
166  if (direct())
167  {
169  << "Requested interpolative addressing for a direct mapper."
170  << abort(FatalError);
171  }
172 
173  if (!interpolationAddrPtr_)
174  {
175  calcAddressing();
176  }
177 
178  return *interpolationAddrPtr_;
179 }
180 
181 
183 {
184  if (direct())
185  {
187  << "Requested interpolative weights for a direct mapper."
188  << abort(FatalError);
189  }
190 
191  if (!weightsPtr_)
192  {
193  calcAddressing();
194  }
195 
196  return *weightsPtr_;
197 }
198 
199 
200 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
201 
202 
203 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
204 
205 
206 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
207 
208 
209 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual const labelUList & directAddressing() const
Return direct addressing.
pointPatchMapper(const pointPatch &patch, const pointMapper &pointMap, const mapPolyMesh &mpm)
Construct from mappers.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual bool direct() const
Is the mapping direct.
virtual const scalarListList & weights() const
Return interpolation weights.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
generalPointPatchFieldMapper()
Null constructor.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
const labelList & oldPatchNMeshPoints() const
Return numbers of mesh points per old patch.
Definition: mapPolyMesh.H:627
List< scalarList > scalarListList
Definition: scalarList.H:51
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
const labelListList & patchPointMap() const
Patch point renumbering.
Definition: mapPolyMesh.H:559
Template functions to aid in the implementation of demand driven data.
virtual ~pointPatchMapper()
Destructor.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
virtual label index() const =0
Return the index of this patch in the pointBoundaryMesh.
This object provides mapping and fill-in information for point data between the two meshes after the ...
Definition: pointMapper.H:55
void deleteDemandDrivenData(DataPtr &dataPtr)
virtual const labelListList & addressing() const
Return interpolated addressing.
virtual label size() const =0
Return size.