FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/pointPatch.H>
28 #include <OpenFOAM/mapPolyMesh.H>
29 #include <OpenFOAM/faceMapper.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  (
45  "void pointPatchMapper::calcAddressing() const"
46  ) << "Addressing already calculated"
47  << abort(FatalError);
48  }
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  addr[i] = 0;
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(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. Map from point0 (arbitrary choice)
91  addr[i] = labelList(1, 0);
92  w[i] = scalarList(1, 1.0);
93  }
94  }
95  }
96 }
97 
98 
99 void Foam::pointPatchMapper::clearOut()
100 {
101  deleteDemandDrivenData(directAddrPtr_);
102  deleteDemandDrivenData(interpolationAddrPtr_);
103  deleteDemandDrivenData(weightsPtr_);
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
108 
109 // Construct from components
110 Foam::pointPatchMapper::pointPatchMapper
111 (
112  const pointPatch& patch,
113  const pointMapper& pointMap,
114  const mapPolyMesh& mpm
115 )
116 :
118  patch_(patch),
119  pointMapper_(pointMap),
120  mpm_(mpm),
121  sizeBeforeMapping_
122  (
123  patch_.index() < mpm_.oldPatchNMeshPoints().size()
124  ? mpm_.oldPatchNMeshPoints()[patch_.index()]
125  : 0
126  ),
127  directAddrPtr_(NULL),
128  interpolationAddrPtr_(NULL),
129  weightsPtr_(NULL)
130 {}
131 
132 
133 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
134 
136 {
137  clearOut();
138 }
139 
140 
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 
144 {
145  if (!direct())
146  {
148  (
149  "const unallocLabelList& pointPatchMapper::directAddressing() const"
150  ) << "Requested direct addressing for an interpolative mapper."
151  << abort(FatalError);
152  }
153 
154  if (!directAddrPtr_)
155  {
156  calcAddressing();
157  }
158 
159  return *directAddrPtr_;
160 }
161 
162 
164 {
165  if (direct())
166  {
168  (
169  "const labelListList& pointPatchMapper::addressing() const"
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  (
189  "const scalarListList& pointPatchMapper::weights() const"
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 // ************************ vim: set sw=4 sts=4 et: ************************ //