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 | Copyright (C) 2011-2015 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 
35 {
36  if
37  (
40  || weightsPtr_
41  )
42  {
44  << "Addressing already calculated"
45  << abort(FatalError);
46  }
47 
48  hasUnmapped_ = false;
49 
50  if (direct())
51  {
52  // Direct mapping.
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 
75 
76  weightsPtr_ = new scalarListList(addr.size());
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 
102 {
103  deleteDemandDrivenData(directAddrPtr_);
104  deleteDemandDrivenData(interpolationAddrPtr_);
105  deleteDemandDrivenData(weightsPtr_);
106  hasUnmapped_ = false;
107 }
108 
109 
110 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
111 
112 // Construct from components
114 (
115  const pointPatch& patch,
116  const pointMapper& pointMap,
117  const mapPolyMesh& mpm
118 )
119 :
121  patch_(patch),
122  pointMapper_(pointMap),
123  mpm_(mpm),
124  sizeBeforeMapping_
125  (
126  patch_.index() < mpm_.oldPatchNMeshPoints().size()
127  ? mpm_.oldPatchNMeshPoints()[patch_.index()]
128  : 0
129  ),
130  hasUnmapped_(false),
131  directAddrPtr_(NULL),
132  interpolationAddrPtr_(NULL),
133  weightsPtr_(NULL)
134 {}
135 
136 
137 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
138 
140 {
141  clearOut();
142 }
143 
144 
145 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 
148 {
149  if (!direct())
150  {
152  << "Requested direct addressing for an interpolative mapper."
153  << abort(FatalError);
154  }
155 
156  if (!directAddrPtr_)
157  {
158  calcAddressing();
159  }
160 
161  return *directAddrPtr_;
162 }
163 
164 
166 {
167  if (direct())
168  {
170  << "Requested interpolative addressing for a direct mapper."
171  << abort(FatalError);
172  }
173 
174  if (!interpolationAddrPtr_)
175  {
176  calcAddressing();
177  }
178 
179  return *interpolationAddrPtr_;
180 }
181 
182 
184 {
185  if (direct())
186  {
188  << "Requested interpolative weights for a direct mapper."
189  << abort(FatalError);
190  }
191 
192  if (!weightsPtr_)
193  {
194  calcAddressing();
195  }
196 
197  return *weightsPtr_;
198 }
199 
200 
201 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
202 
203 
204 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
205 
206 
207 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
208 
209 
210 // ************************************************************************* //
Foam::scalarList
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
Foam::pointPatch::index
virtual label index() const =0
Return the index of this patch in the pointBoundaryMesh.
w
volScalarField w(IOobject("w", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE), mesh, dimensionedScalar("w", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0))
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::pointPatchMapper::direct
virtual bool direct() const
Is the mapping direct.
Definition: pointPatchMapper.H:146
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
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:183
mapPolyMesh.H
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
Foam::pointPatchMapper::directAddressing
virtual const labelUList & directAddressing() const
Return direct addressing.
Definition: pointPatchMapper.C:147
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:46
Foam::pointPatchMapper::~pointPatchMapper
virtual ~pointPatchMapper()
Destructor.
Definition: pointPatchMapper.C:139
Foam::pointPatchMapper::pointPatchMapper
pointPatchMapper(const pointPatchMapper &)
Disallow default bitwise copy construct.
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
Foam::pointPatchMapper::directAddrPtr_
labelList * directAddrPtr_
Direct addressing (only one for of addressing is used)
Definition: pointPatchMapper.H:79
Foam::pointMapper
This object provides mapping and fill-in information for point data between the two meshes after the ...
Definition: pointMapper.H:55
Foam::pointPatchMapper::interpolationAddrPtr_
labelListList * interpolationAddrPtr_
Interpolated addressing (only one for of addressing is used)
Definition: pointPatchMapper.H:82
Foam::pointPatchMapper::patch_
const pointPatch & patch_
Reference to patch.
Definition: pointPatchMapper.H:62
Foam::pointPatchMapper::addressing
virtual const labelListList & addressing() const
Return interpolated addressing.
Definition: pointPatchMapper.C:165
faceMapper.H
Foam::pointPatchMapper::mpm_
const mapPolyMesh & mpm_
Reference to mapping data.
Definition: pointPatchMapper.H:68
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::pointPatchMapper::size
virtual label size() const
Return size.
Definition: pointPatchMapper.H:129
pointPatchMapper.H
Foam::mapPolyMesh::patchPointMap
const labelListList & patchPointMap() const
Patch point renumbering.
Definition: mapPolyMesh.H:566
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::pointPatchMapper::hasUnmapped_
bool hasUnmapped_
Definition: pointPatchMapper.H:76
Foam::pointPatchMapper::calcAddressing
void calcAddressing() const
Calculate addressing for mapping with inserted cells.
Definition: pointPatchMapper.C:34
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::UList
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
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::scalarListList
List< scalarList > scalarListList
Definition: scalarList.H:51
Foam::pointPatchMapper::weightsPtr_
scalarListList * weightsPtr_
Interpolation weights.
Definition: pointPatchMapper.H:85
Foam::pointPatchMapper::clearOut
void clearOut()
Clear out local storage.
Definition: pointPatchMapper.C:101
pointPatch.H