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  Copyright (C) 2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "pointPatchMapper.H"
30 #include "pointPatch.H"
31 #include "mapPolyMesh.H"
32 #include "faceMapper.H"
33 
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 
36 void Foam::pointPatchMapper::calcAddressing() const
37 {
38  if
39  (
40  directAddrPtr_
41  || interpAddrPtr_
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_ = std::make_unique<labelList>
56  (
57  mpm_.patchPointMap()[patch_.index()]
58  );
59  auto& addr = *directAddrPtr_;
60 
61  forAll(addr, i)
62  {
63  if (addr[i] < 0)
64  {
65  hasUnmapped_ = true;
66  break;
67  }
68  }
69  }
70  else
71  {
72  // Interpolative mapping.
73 
74  // NOTE: Incorrect:
75  // FOR NOW only takes first patch point instead of averaging all
76  // patch points. Problem is we don't know what points were in the patch
77  // for points that were merged.
78 
79  interpAddrPtr_ = std::make_unique<labelListList>(size());
80  auto& addr = *interpAddrPtr_;
81 
82  weightsPtr_ = std::make_unique<scalarListList>(addr.size());
83  auto& wght = *weightsPtr_;
84 
85  const labelList& ppm = mpm_.patchPointMap()[patch_.index()];
86 
87  forAll(ppm, i)
88  {
89  if (ppm[i] >= 0)
90  {
91  addr[i].resize(1, ppm[i]);
92  wght[i].resize(1, 1.0);
93  }
94  else
95  {
96  // Inserted point.
98  //addr[i].resize(1, 0);
99  //wght[i].resize(1, 1.0);
100  hasUnmapped_ = true;
101  }
102  }
103  }
104 }
105 
106 
107 // void Foam::pointPatchMapper::clearOut()
108 // {
109 // directAddrPtr_.reset(nullptr);
110 // interpAddrPtr_.reset(nullptr);
111 // weightsPtr_.reset(nullptr);
112 // hasUnmapped_ = false;
113 // }
114 
115 
116 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
117 
118 Foam::pointPatchMapper::pointPatchMapper
119 (
120  const pointPatch& patch,
121  const pointMapper& pointMap,
122  const mapPolyMesh& mpm
123 )
124 :
126  patch_(patch),
127  pointMapper_(pointMap),
128  mpm_(mpm),
129  sizeBeforeMapping_
130  (
131  patch_.index() < mpm_.oldPatchNMeshPoints().size()
132  ? mpm_.oldPatchNMeshPoints()[patch_.index()]
133  : 0
134  ),
135  hasUnmapped_(false)
136 {}
137 
138 
139 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
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 (!interpAddrPtr_)
175  {
176  calcAddressing();
177  }
178 
179  return *interpAddrPtr_;
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 // ************************************************************************* //
virtual const labelUList & directAddressing() const
Return direct addressing.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
virtual bool direct() const
Is the mapping direct.
virtual const scalarListList & weights() const
Return interpolaion weights.
Foam::pointPatchFieldMapper.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
errorManip< error > abort(error &err)
Definition: errorManip.H:139
virtual label size() const
Return size.
const labelListList & patchPointMap() const noexcept
Patch point renumbering.
Definition: mapPolyMesh.H:701
virtual ~pointPatchMapper()
Destructor.
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:61
virtual label index() const =0
Return the index of this patch in the pointBoundaryMesh.
const std::string patch
OpenFOAM patch number as a std::string.
This object provides mapping and fill-in information for point data between the two meshes after the ...
Definition: pointMapper.H:53
List< label > labelList
A List of labels.
Definition: List.H:62
virtual const labelListList & addressing() const
Return interpolated addressing.