pointPatchMapper.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "pointPatchMapper.H"
29 #include "pointPatch.H"
30 #include "mapPolyMesh.H"
31 #include "faceMapper.H"
32 #include "demandDrivenData.H"
33 
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 
36 void Foam::pointPatchMapper::calcAddressing() const
37 {
38  if
39  (
40  directAddrPtr_
41  || interpolationAddrPtr_
42  || weightsPtr_
43  )
44  {
46  << "Addressing already calculated"
47  << abort(FatalError);
48  }
49 
50  hasUnmapped_ = false;
51 
52  if (direct())
53  {
54  // Direct mapping.
55  directAddrPtr_ = new labelList(mpm_.patchPointMap()[patch_.index()]);
56  labelList& addr = *directAddrPtr_;
57 
58  forAll(addr, i)
59  {
60  if (addr[i] < 0)
61  {
62  hasUnmapped_ = true;
63  break;
64  }
65  }
66  }
67  else
68  {
69  // Interpolative mapping.
70 
71  // NOTE: Incorrect:
72  // FOR NOW only takes first patch point instead of averaging all
73  // patch points. Problem is we don't know what points were in the patch
74  // for points that were merged.
75 
76  interpolationAddrPtr_ = new labelListList(size());
77  labelListList& addr = *interpolationAddrPtr_;
78 
79  weightsPtr_ = new scalarListList(addr.size());
80  scalarListList& w = *weightsPtr_;
81 
82  const labelList& ppm = mpm_.patchPointMap()[patch_.index()];
83 
84  forAll(ppm, i)
85  {
86  if (ppm[i] >= 0)
87  {
88  addr[i] = labelList(1, ppm[i]);
89  w[i] = scalarList(1, scalar(1));
90  }
91  else
92  {
93  // Inserted point.
95  //addr[i] = labelList(1, Zero);
96  //w[i] = scalarList(1, scalar(1));
97  hasUnmapped_ = true;
98  }
99  }
100  }
101 }
102 
103 
104 void Foam::pointPatchMapper::clearOut()
105 {
106  deleteDemandDrivenData(directAddrPtr_);
107  deleteDemandDrivenData(interpolationAddrPtr_);
108  deleteDemandDrivenData(weightsPtr_);
109  hasUnmapped_ = false;
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
114 
115 Foam::pointPatchMapper::pointPatchMapper
116 (
117  const pointPatch& patch,
118  const pointMapper& pointMap,
119  const mapPolyMesh& mpm
120 )
121 :
123  patch_(patch),
124  pointMapper_(pointMap),
125  mpm_(mpm),
126  sizeBeforeMapping_
127  (
128  patch_.index() < mpm_.oldPatchNMeshPoints().size()
129  ? mpm_.oldPatchNMeshPoints()[patch_.index()]
130  : 0
131  ),
132  hasUnmapped_(false),
133  directAddrPtr_(nullptr),
134  interpolationAddrPtr_(nullptr),
135  weightsPtr_(nullptr)
136 {}
137 
138 
139 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
140 
142 {
143  clearOut();
144 }
145 
146 
147 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
148 
150 {
151  if (!direct())
152  {
154  << "Requested direct addressing for an interpolative mapper."
155  << abort(FatalError);
156  }
157 
158  if (!directAddrPtr_)
159  {
160  calcAddressing();
161  }
162 
163  return *directAddrPtr_;
164 }
165 
166 
168 {
169  if (direct())
170  {
172  << "Requested interpolative addressing for a direct mapper."
173  << abort(FatalError);
174  }
175 
176  if (!interpolationAddrPtr_)
177  {
178  calcAddressing();
179  }
180 
181  return *interpolationAddrPtr_;
182 }
183 
184 
186 {
187  if (direct())
188  {
190  << "Requested interpolative weights for a direct mapper."
191  << abort(FatalError);
192  }
193 
194  if (!weightsPtr_)
195  {
196  calcAddressing();
197  }
198 
199  return *weightsPtr_;
200 }
201 
202 
203 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
204 
205 
206 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
207 
208 
209 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
210 
211 
212 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::scalarListList
List< scalarList > scalarListList
A List of scalarList.
Definition: scalarList.H:66
Foam::scalarList
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:64
Foam::pointPatch::index
virtual label index() const =0
Return the index of this patch in the pointBoundaryMesh.
Foam::pointPatchMapper::direct
virtual bool direct() const
Is the mapping direct.
Definition: pointPatchMapper.H:145
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::pointPatchMapper::weights
virtual const scalarListList & weights() const
Return interpolaion weights.
Definition: pointPatchMapper.C:185
mapPolyMesh.H
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:58
Foam::pointPatchMapper::directAddressing
virtual const labelUList & directAddressing() const
Return direct addressing.
Definition: pointPatchMapper.C:149
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:48
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::pointPatchMapper::~pointPatchMapper
virtual ~pointPatchMapper()
Destructor.
Definition: pointPatchMapper.C:141
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:42
Foam::pointMapper
This object provides mapping and fill-in information for point data between the two meshes after the ...
Definition: pointMapper.H:57
Foam::pointPatchMapper::addressing
virtual const labelListList & addressing() const
Return interpolated addressing.
Definition: pointPatchMapper.C:167
faceMapper.H
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::pointPatchMapper::size
virtual label size() const
Return size.
Definition: pointPatchMapper.H:128
pointPatchMapper.H
Foam::mapPolyMesh::patchPointMap
const labelListList & patchPointMap() const
Patch point renumbering.
Definition: mapPolyMesh.H:570
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< labelList >
Foam::UList< label >
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
pointPatch.H