immersedBoundaryFvPatchTriAddressing.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | foam-extend: Open Source CFD
4  \\ / O peration | Version: 3.2
5  \\ / A nd | Web: http://www.foam-extend.org
6  \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9  This file is part of foam-extend.
10 
11  foam-extend is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation, either version 3 of the License, or (at your
14  option) any later version.
15 
16  foam-extend is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
31 {
32  if (debug)
33  {
34  InfoIn("void immersedBoundaryFvPatch::makeTriAddressing() const")
35  << "creating tri addressing for immersed boundary " << name()
36  << endl;
37  }
38 
39  // It is an error to attempt to recalculate
40  // if the pointer is already set
42  {
43  FatalErrorIn("immersedBoundaryFvPatch::makeTriAddressing() const")
44  << "tri addressing already exist"
45  << "for immersed boundary" << name()
46  << abort(FatalError);
47  }
48 
49  // Get reference to tri patch and hit faces
50  const triSurface& triPatch = ibPolyPatch_.ibMesh();
51  const vectorField& triCentres = triPatch.faceCentres();
52 
53  const labelList& hf = hitFaces();
54  const vectorField& ibp = ibPoints();
55 
56  // Create a markup field and mark all tris containing an ib point with its
57  // index
58  labelList hitTris(triPatch.size(), -1);
59 
60  forAll (hf, hfI)
61  {
62  hitTris[hf[hfI]] = hfI;
63  }
64 
65  // Allocate storage
66  cellsToTriAddrPtr_ = new labelListList(triPatch.size());
68 
69  cellsToTriWeightsPtr_ = new scalarListList(triPatch.size());
71 
72  // Algorithm:
73  // For each tri face, check if it contains an IB point
74  // - if so, set the addressing to the index of IB point and weight to 1
75  // - if not, search the neighbouring faces of the visited faces until
76  // at least 3 IB points are found, or the neighbourhood is exhausted.
77  // When a sufficient number of points is found, calculate the weights
78  // using inverse distance weighting
79 
80  // Get addressing from the triangular patch
81  const labelListList& pf = triPatch.pointFaces();
82 
83  const dynamicLabelList& triFacesInMesh = this->triFacesInMesh();
84  label faceIndex = 0;
85  label counter = 0;
86 
87  forAll (triPatch, triI)
88  {
89  if (hitTris[triI] > -1)
90  {
91  // Triangle contains IB point
92  addr[triI].setSize(1);
93  w[triI].setSize(1);
94 
95  addr[triI] = hitTris[triI];
96  w[triI] = 1;
97  }
98  else
99  {
100  // No direct hit. Start a neighbourhood search
101 
102  // Record already visited faces
103  labelHashSet visited;
104 
105  // Collect new faces to visit
106  SLList<label> nextToVisit;
107 
108  // Collect IB points for interpolation
109  labelHashSet ibPointsToUse;
110 
111  // Initialise with the original tri
112  nextToVisit.insert(triI);
113 
114  do
115  {
116  const label curTri = nextToVisit.removeHead();
117 
118  // Discard tri if already visited
119  if (visited[curTri]) continue;
120 
121  visited.insert(curTri);
122 
123  const triFace& curTriPoints = triPatch[curTri];
124 
125  // For all current points of face, pick up neighbouring faces
126  forAll (curTriPoints, tpI)
127  {
128  const labelList curNbrs = pf[curTriPoints[tpI]];
129 
130  forAll (curNbrs, nbrI)
131  {
132  if (!visited.found(curNbrs[nbrI]))
133  {
134  // Found a face which is not visited. Add it to
135  // the list of faces to visit
136  nextToVisit.append(curNbrs[nbrI]);
137 
138  if (hitTris[curNbrs[nbrI]] > -1)
139  {
140  // Found a neighbour with a hit: use this
141  // IB point
142  ibPointsToUse.insert(hitTris[curNbrs[nbrI]]);
143  }
144  }
145  }
146  }
147  } while
148  (
149  ibPointsToUse.size() < 3
150  && !nextToVisit.empty()
151  );
152 
153  // Found neighbourhood: collect addressing and weights
154  addr[triI] = ibPointsToUse.toc();
155  w[triI].setSize(addr[triI].size());
156 
157  // Raise counter if the face is inside the mesh and
158  // has no ib points in the neighbouring tri faces
159  if
160  (
161  (!triFacesInMesh.empty())
162  && (triI == triFacesInMesh[faceIndex])
163  )
164  {
165  faceIndex++;
166 
167  if (addr[triI].size() == 0)
168  {
169  counter++;
170  }
171  }
172 
173  labelList& curAddr = addr[triI];
174  scalarList& curW = w[triI];
175 
176  vector curTriCentre = triCentres[triI];
177 
178  scalar sumW = 0;
179 
180  forAll (curAddr, ibI)
181  {
182  curW[ibI] = 1/mag(curTriCentre - ibp[curAddr[ibI]]);
183  sumW += curW[ibI];
184  }
185 
186  // Divide weights by sum distance
187  forAll (curW, ibI)
188  {
189  curW[ibI] /= sumW;
190  }
191  }
192  }
193 
194  // Issue a warning if there are triangular faces inside the mesh without
195  // neighbouring faces containing ibPoints
196  if (counter > 0)
197  {
198  WarningIn
199  (
200  "immersedBoundaryFvPatch::makeTriAddressing() const"
201  ) << "Not all triangular faces have neighbours with ibPoints" << nl
202  << "Number of faces:" << counter << nl
203  << "This might cause false force calculation," << nl
204  << "consider coarsening the triangular mesh"
205  << endl;
206  }
207 }
208 
209 
210 const Foam::labelListList&
212 {
213  if (!cellsToTriAddrPtr_)
214  {
215  makeTriAddressing();
216  }
217 
218  return *cellsToTriAddrPtr_;
219 }
220 
221 
224 {
225  if (!cellsToTriWeightsPtr_)
226  {
227  makeTriAddressing();
228  }
229 
230  return *cellsToTriWeightsPtr_;
231 }
232 
233 
234 // ************************************************************************* //
Foam::PrimitivePatch::pointFaces
const labelListList & pointFaces() const
Return point-face addressing.
Definition: PrimitivePatchTemplate.C:352
InfoIn
#define InfoIn(functionName)
Report a information message using Foam::Info.
Definition: messageStream.H:276
w
volScalarField w(IOobject("w", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE), mesh, dimensionedScalar("w", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0))
Foam::LList::append
void append(const T &a)
Add at tail of list.
Definition: LList.H:166
Foam::HashTable::toc
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:201
Foam::SLList< label >
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::immersedBoundaryFvPatch::hitFaces
const labelList & hitFaces() const
Return list of triangles in IB mesh nearest.
Definition: immersedBoundaryFvPatch.C:2377
Foam::LList::insert
void insert(const T &a)
Add at head of list.
Definition: LList.H:160
Foam::immersedBoundaryFvPatch::cellsToTriWeights
const scalarListList & cellsToTriWeights() const
Interpolation weights from IB points to tri faces.
Definition: immersedBoundaryFvPatchTriAddressing.C:223
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::HashSet< label, Hash< label > >
Foam::immersedBoundaryFvPatch::triFacesInMesh
const dynamicLabelList & triFacesInMesh() const
Return labels of triangular faces which are inside the mesh.
Definition: immersedBoundaryFvPatch.C:2576
Foam::fvPatch::name
const word & name() const
Return name.
Definition: fvPatch.H:149
Foam::fvPatch::size
virtual label size() const
Return size.
Definition: fvPatch.H:161
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::FatalError
error FatalError
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
Foam::HashTable::found
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
Foam::immersedBoundaryFvPatch::cellsToTriAddrPtr_
labelListList * cellsToTriAddrPtr_
Interpolation addressing from IB points to tri faces.
Definition: immersedBoundaryFvPatch.H:157
Foam::immersedBoundaryPolyPatch::ibMesh
const triSurfaceMesh & ibMesh() const
Return immersed boundary surface mesh.
Definition: immersedBoundaryPolyPatch.H:192
Foam::immersedBoundaryFvPatch::ibPolyPatch_
const immersedBoundaryPolyPatch & ibPolyPatch_
Reference to processor patch.
Definition: immersedBoundaryFvPatch.H:73
Foam::triFace
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:68
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::PrimitivePatch::faceCentres
const Field< PointType > & faceCentres() const
Return face centres for patch.
Definition: PrimitivePatchTemplate.C:500
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::immersedBoundaryFvPatch::ibPoints
const vectorField & ibPoints() const
Return IB points.
Definition: immersedBoundaryFvPatch.C:2355
immersedBoundaryFvPatch.H
Foam::immersedBoundaryFvPatch::cellsToTriAddr
const labelListList & cellsToTriAddr() const
Interpolation addressing from IB points to tri faces.
Definition: immersedBoundaryFvPatchTriAddressing.C:211
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
WarningIn
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Definition: messageStream.H:254
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::scalarListList
List< scalarList > scalarListList
Definition: scalarList.H:51
Foam::immersedBoundaryFvPatch::makeTriAddressing
void makeTriAddressing() const
Make tri addressing.
Definition: immersedBoundaryFvPatchTriAddressing.C:30
Foam::immersedBoundaryFvPatch::cellsToTriWeightsPtr_
scalarListList * cellsToTriWeightsPtr_
Interpolation weights from IB points to tri faces.
Definition: immersedBoundaryFvPatch.H:160
Foam::LList::removeHead
T removeHead()
Remove and return head.
Definition: LList.H:172