FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "enrichedPatch.H"
29 #include <OpenFOAM/primitiveMesh.H>
31 #include <OpenFOAM/DynamicList.H>
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 const Foam::label Foam::enrichedPatch::nFaceHits_ = 4;
36 
37 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 
39 void Foam::enrichedPatch::calcMasterPointFaces() const
40 {
41  if (masterPointFacesPtr_)
42  {
43  FatalErrorIn("void enrichedPatch::calcMasterPointFaces() const")
44  << "Master point face addressing already calculated."
45  << abort(FatalError);
46  }
47 
48  // Note:
49  // Master point face addressing lists the master faces for all points
50  // in the enriched patch support (if there are no master faces, which is
51  // normal, the list will be empty). The index represents the index of
52  // the master face rather than the index from the enriched patch
53  // Master face points lists the points of the enriched master face plus
54  // points projected into the master face
55 
56  Map<DynamicList<label> > mpf(meshPoints().size());
57 
58  const faceList& ef = enrichedFaces();
59 
60  // Add the original face points
61  forAll (masterPatch_, faceI)
62  {
63  const face& curFace = ef[faceI + slavePatch_.size()];
64 // Pout << "Cur face in pfAddr: " << curFace << endl;
65  forAll (curFace, pointI)
66  {
67  Map<DynamicList<label> >::iterator mpfIter =
68  mpf.find(curFace[pointI]);
69 
70  if (mpfIter == mpf.end())
71  {
72  // Not found, add new dynamic list
73  // Work-around for compiler bug
74  DynamicList<label> fpp(primitiveMesh::facesPerPoint_);
75  mpf.insert
76  (
77  curFace[pointI],
78  fpp
79  );
80 
81  // Iterator is invalidated - have to find again
82  mpf.find(curFace[pointI])().append(faceI);
83  }
84  else
85  {
86  mpfIter().append(faceI);
87  }
88  }
89  }
90 
91  // Add the projected points which hit the face
92  const labelList& slaveMeshPoints = slavePatch_.meshPoints();
93 
94  forAll (slavePointFaceHits_, pointI)
95  {
96  if
97  (
98  slavePointPointHits_[pointI] < 0
99  && slavePointEdgeHits_[pointI] < 0
100  && slavePointFaceHits_[pointI].hit()
101  )
102  {
103  // Get the index of projected point corresponding to this slave
104  // point
105  const label mergedSmp =
106  pointMergeMap().find(slaveMeshPoints[pointI])();
107 
108  Map<DynamicList<label> >::iterator mpfIter =
109  mpf.find(mergedSmp);
110 
111  if (mpfIter == mpf.end())
112  {
113  // Not found, add new dynamic list
114  // Work-around for compiler bug
115  DynamicList<label> fpp(primitiveMesh::facesPerPoint_);
116  mpf.insert
117  (
118  mergedSmp,
119  fpp
120  );
121 
122  // Iterator is invalidated - have to find again
123  mpf.find(mergedSmp)().append
124  (
125  slavePointFaceHits_[pointI].hitObject()
126  );
127  }
128  else
129  {
130  mpfIter().append(slavePointFaceHits_[pointI].hitObject());
131  }
132  }
133  }
134 
135  // Re-pack dynamic lists into normal lists
136  const labelList mpfToc = mpf.toc();
137 
138  masterPointFacesPtr_ = new Map<labelList>(2*mpfToc.size());
139  Map<labelList>& masterPointFaceAddr = *masterPointFacesPtr_;
140 
141  forAll (mpfToc, mpfTocI)
142  {
143  labelList l;
144  l.transfer(mpf.find(mpfToc[mpfTocI])());
145 
146  masterPointFaceAddr.insert(mpfToc[mpfTocI], l);
147  }
148  // Pout<< "masterPointFaceAddr: " << masterPointFaceAddr << endl;
149 }
150 
151 
152 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
153 
155 {
156  if (!masterPointFacesPtr_)
157  {
158  calcMasterPointFaces();
159  }
160 
161  return *masterPointFacesPtr_;
162 }
163 
164 
165 // ************************ vim: set sw=4 sts=4 et: ************************ //