enrichedPatchMasterPoints.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) 2011-2016 OpenFOAM Foundation
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 "enrichedPatch.H"
27 #include "primitiveMesh.H"
28 #include "demandDrivenData.H"
29 #include "DynamicList.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 const Foam::label Foam::enrichedPatch::nFaceHits_ = 4;
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 void Foam::enrichedPatch::calcMasterPointFaces() const
38 {
39  if (masterPointFacesPtr_)
40  {
42  << "Master point face addressing already calculated."
43  << abort(FatalError);
44  }
45 
46  // Note:
47  // Master point face addressing lists the master faces for all points
48  // in the enriched patch support (if there are no master faces, which is
49  // normal, the list will be empty). The index represents the index of
50  // the master face rather than the index from the enriched patch
51  // Master face points lists the points of the enriched master face plus
52  // points projected into the master face
53 
54  Map<DynamicList<label>> mpf(meshPoints().size());
55 
56  const faceList& ef = enrichedFaces();
57 
58  // Add the original face points
59  forAll(masterPatch_, facei)
60  {
61  const face& curFace = ef[facei + slavePatch_.size()];
62 // Pout<< "Cur face in pfAddr: " << curFace << endl;
63  forAll(curFace, pointi)
64  {
65  Map<DynamicList<label>>::iterator mpfIter =
66  mpf.find(curFace[pointi]);
67 
68  if (mpfIter == mpf.end())
69  {
70  // Not found, add new dynamic list
71  mpf.insert
72  (
73  curFace[pointi],
74  DynamicList<label>(primitiveMesh::facesPerPoint_)
75  );
76 
77  // Iterator is invalidated - have to find again
78  mpf.find(curFace[pointi])().append(facei);
79  }
80  else
81  {
82  mpfIter().append(facei);
83  }
84  }
85  }
86 
87  // Add the projected points which hit the face
88  const labelList& slaveMeshPoints = slavePatch_.meshPoints();
89 
90  forAll(slavePointFaceHits_, pointi)
91  {
92  if
93  (
94  slavePointPointHits_[pointi] < 0
95  && slavePointEdgeHits_[pointi] < 0
96  && slavePointFaceHits_[pointi].hit()
97  )
98  {
99  // Get the index of projected point corresponding to this slave
100  // point
101  const label mergedSmp =
102  pointMergeMap().find(slaveMeshPoints[pointi])();
103 
104  Map<DynamicList<label>>::iterator mpfIter =
105  mpf.find(mergedSmp);
106 
107  if (mpfIter == mpf.end())
108  {
109  // Not found, add new dynamic list
110  mpf.insert
111  (
112  mergedSmp,
113  DynamicList<label>(primitiveMesh::facesPerPoint_)
114  );
115 
116  // Iterator is invalidated - have to find again
117  mpf.find(mergedSmp)().append
118  (
119  slavePointFaceHits_[pointi].hitObject()
120  );
121  }
122  else
123  {
124  mpfIter().append(slavePointFaceHits_[pointi].hitObject());
125  }
126  }
127  }
128 
129  // Re-pack dynamic lists into normal lists
130  const labelList mpfToc = mpf.toc();
131 
132  masterPointFacesPtr_ = new Map<labelList>(2*mpfToc.size());
133  Map<labelList>& masterPointFaceAddr = *masterPointFacesPtr_;
134 
135  forAll(mpfToc, mpfTocI)
136  {
137  labelList l;
138  l.transfer(mpf.find(mpfToc[mpfTocI])());
139 
140  masterPointFaceAddr.insert(mpfToc[mpfTocI], l);
141  }
142  // Pout<< "masterPointFaceAddr: " << masterPointFaceAddr << endl;
143 }
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
149 {
150  if (!masterPointFacesPtr_)
151  {
152  calcMasterPointFaces();
153  }
154 
155  return *masterPointFacesPtr_;
156 }
157 
158 
159 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
List< face > faceList
Definition: faceListFwd.H:43
const Map< labelList > & masterPointFaces() const
Master point face addressing.
static const unsigned facesPerPoint_
Estimated number of faces per point.
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:142
const faceList & enrichedFaces() const
Return enriched faces.
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Map< label > & pointMergeMap()
Return map of point merges.
Template functions to aid in the implementation of demand driven data.
const labelList & meshPoints() const
Return mesh points.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49