faPatchMapper.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) 2016-2017 Wikki Ltd
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 "faPatchMapper.H"
29 #include "mapPolyMesh.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 void Foam::faPatchMapper::calcAddressing() const
34 {
35  if (directAddrPtr_)
36  {
38  << "Addressing already calculated"
39  << abort(FatalError);
40  }
41 
42  // Compatibility change HJ, 12/Aug/2017
43  hasUnmapped_ = false;
44 
45  directAddrPtr_ = std::make_unique<labelList>(patch_.size(), Foam::zero{});
46  auto& addr = *directAddrPtr_;
47 
48  // Make a map of old edgeFaces, giving edge index in patch given the new
49  // face label next to the patch
50 
51  // Create edge index lookup
52  Map<label> edgeIndexLookup;
53 
54  const labelList& reverseFaceMap = mpm_.reverseFaceMap();
55 
56  forAll(oldEdgeFaces_, oefI)
57  {
58  if (reverseFaceMap[oldEdgeFaces_[oefI]] > -1)
59  {
60  // Face has survived. Insert its label under new face index
61  edgeIndexLookup.insert(reverseFaceMap[oldEdgeFaces_[oefI]], oefI);
62  }
63  }
64 
65  // Go through new edgeFaces and for each edge try to locate old index
66  const labelList& ef = patch_.edgeFaces();
67 
68  forAll(ef, efI)
69  {
70  const auto iter = edgeIndexLookup.cfind(ef[efI]);
71 
72  if (iter.good())
73  {
74  addr[efI] = iter.val();
75  }
76  else
77  {
78  // Not found: map from zero
79  addr[efI] = 0;
80 
81  // Compatibility change HJ, 12/Aug/2017
82  hasUnmapped_ = true;
83  }
84  }
85 }
86 
87 
88 // void Foam::faPatchMapper::clearOut()
89 // {
90 // directAddrPtr_.reset(nullptr);
91 // hasUnmapped_ = false;
92 // }
93 
94 
95 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 
98 (
99  const faPatch& patch,
100  const mapPolyMesh& mpm
101 )
102 :
103  patch_(patch),
104  mpm_(mpm),
105  sizeBeforeMapping_(patch.size()),
106  oldEdgeFaces_(patch.edgeFaces()),
107  hasUnmapped_(false)
108 {}
109 
110 
111 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
114 {}
115 
116 
117 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118 
120 {
121  if (!directAddrPtr_)
122  {
123  calcAddressing();
124  }
125 
126  return *directAddrPtr_;
127 }
128 
129 
131 {
133  << "Requested interpolative addressing for a direct mapper."
134  << abort(FatalError);
135 
136  return labelListList::null();
137 }
138 
139 
141 {
143  << "Requested interpolative weights for a direct mapper."
144  << abort(FatalError);
145 
146  return scalarListList::null();
147 }
148 
149 
150 // ************************************************************************* //
faPatchMapper(const faPatchMapper &)=delete
No copy construct.
virtual ~faPatchMapper()
Destructor.
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 label size() const
Patch size is the number of edge labels, but can be overloaded.
Definition: faPatch.H:392
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
const labelList & reverseFaceMap() const noexcept
Reverse face map.
Definition: mapPolyMesh.H:620
virtual const labelUList & directAddressing() const
Return direct addressing.
const labelUList & edgeFaces() const
Return edge-face addressing.
Definition: faPatch.C:424
errorManip< error > abort(error &err)
Definition: errorManip.H:139
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
const std::string patch
OpenFOAM patch number as a std::string.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
List< label > labelList
A List of labels.
Definition: List.H:62
virtual const scalarListList & weights() const
Return interpolation weights.
static const List< labelList > & null() noexcept
Return a null List (reference to a nullObject). Behaves like an empty List.
Definition: List.H:153
virtual const labelListList & addressing() const
Return interpolated addressing.