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 "faPatch.H"
30 #include "faBoundaryMesh.H"
31 #include "faMesh.H"
32 #include "mapPolyMesh.H"
33 #include "faceMapper.H"
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 void Foam::faPatchMapper::calcAddressing() const
38 {
39  if (directAddrPtr_)
40  {
42  << "Addressing already calculated"
43  << abort(FatalError);
44  }
45 
46  // Compatibility change HJ, 12/Aug/2017
47  hasUnmapped_ = false;
48 
49  directAddrPtr_ = new labelList(patch_.size(), Zero);
50  labelList& addr = *directAddrPtr_;
51 
52  // Make a map of old edgeFaces, giving edge index in patch given the new
53  // face label next to the patch
54 
55  // Create edge index lookup
56  Map<label> edgeIndexLookup;
57 
58  const labelList& reverseFaceMap = mpm_.reverseFaceMap();
59 
60  forAll(oldEdgeFaces_, oefI)
61  {
62  if (reverseFaceMap[oldEdgeFaces_[oefI]] > -1)
63  {
64  // Face has survived. Insert its label under new face index
65  edgeIndexLookup.insert(reverseFaceMap[oldEdgeFaces_[oefI]], oefI);
66  }
67  }
68 
69  // Go through new edgeFaces and for each edge try to locate old index
70  const labelList& ef = patch_.edgeFaces();
71 
72  forAll(ef, efI)
73  {
74  if (edgeIndexLookup.found(ef[efI]))
75  {
76  addr[efI] = edgeIndexLookup[ef[efI]];
77  }
78  else
79  {
80  // Not found: map from zero
81  addr[efI] = 0;
82 
83  // Compatibility change HJ, 12/Aug/2017
84  hasUnmapped_ = true;
85  }
86  }
87 }
88 
89 
90 void Foam::faPatchMapper::clearOut()
91 {
92  deleteDemandDrivenData(directAddrPtr_);
93  hasUnmapped_ = false;
94 }
95 
96 
97 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
98 
99 Foam::faPatchMapper::faPatchMapper
100 (
101  const faPatch& patch,
102  const mapPolyMesh& mpm
103 )
104 :
105  patch_(patch),
106  mpm_(mpm),
107  sizeBeforeMapping_(patch.size()),
108  oldEdgeFaces_(patch.edgeFaces()),
109  hasUnmapped_(false),
110  directAddrPtr_(nullptr)
111 {}
112 
113 
114 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
115 
117 {
118  clearOut();
119 }
120 
121 
122 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
123 
125 {
126  if (!directAddrPtr_)
127  {
128  calcAddressing();
129  }
130 
131  return *directAddrPtr_;
132 }
133 
134 
136 {
138  << "Requested interpolative addressing for a direct mapper."
139  << abort(FatalError);
140 
141  return labelListList::null();
142 }
143 
144 
146 {
148  << "Requested interpolative weights for a direct mapper."
149  << abort(FatalError);
150 
151  return scalarListList::null();
152 }
153 
154 
155 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::List< labelList >::null
static const List< labelList > & null()
Return a null List.
Definition: ListI.H:108
Foam::faPatchMapper::directAddressing
virtual const labelUList & directAddressing() const
Return direct addressing.
Definition: faPatchMapper.C:124
Foam::faPatchMapper::weights
virtual const scalarListList & weights() const
Return interpolation weights.
Definition: faPatchMapper.C:145
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::faPatchMapper::~faPatchMapper
virtual ~faPatchMapper()
Destructor.
Definition: faPatchMapper.C:116
mapPolyMesh.H
Foam::faPatchMapper::addressing
virtual const labelListList & addressing() const
Return interpolated addressing.
Definition: faPatchMapper.C:135
faMesh.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::faPatch::edgeFaces
const labelUList & edgeFaces() const
Return edge-face addressing.
Definition: faPatch.C:365
faPatchMapper.H
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:42
faceMapper.H
Foam::FatalError
error FatalError
faBoundaryMesh.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::mapPolyMesh::reverseFaceMap
const labelList & reverseFaceMap() const
Reverse face map.
Definition: mapPolyMesh.H:500
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< labelList >
faPatch.H
Foam::UList< label >
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::faPatch
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:65
Foam::faPatch::size
virtual label size() const
Patch size.
Definition: faPatch.H:247