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