immersedBoundaryFvPatchSamplingWeights.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 #include "fvMesh.H"
28 #include "volFields.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
33 {
34  if (debug)
35  {
36  Info<< "immersedBoundaryFvPatch::makeIbSamplingWeights() : "
37  << "making sampling point weights"
38  << endl;
39  }
40 
41  // It is an error to attempt to recalculate
42  // if the pointer is already set
44  {
45  FatalErrorIn("void immersedBoundaryFvPatch::makeIbSamplingWeights()")
46  << "sampling point weights already exist"
47  << abort(FatalError);
48  }
49 
50  // Get addressing
51  const labelList& ibc = ibCells();
52  const labelListList& ibcc = ibCellCells();
53  const List<List<labelPair> >& ibcProcC = ibCellProcCells();
54 
55  // Initialise the weights
57  scalarListList& cellWeights = *ibSamplingWeightsPtr_;
58 
59  forAll (cellWeights, cellI)
60  {
61  cellWeights[cellI].setSize(ibcc[cellI].size(), 0);
62  }
63 
65  scalarListList& cellProcWeights = *ibSamplingProcWeightsPtr_;
66 
67  forAll (cellProcWeights, cellI)
68  {
69  cellProcWeights[cellI].setSize(ibcProcC[cellI].size(), 0);
70  }
71 
72  // Get sampling point locations
73  const vectorField& samplingPoints = ibSamplingPoints();
74  const scalarField& gammaIn = gamma().internalField();
75  const vectorField& CIn = mesh_.C().internalField();
76 
77  const FieldField<Field, scalar>& gammaProc = ibProcGamma();
79 
80  // Go through all cellCells and calculate inverse distance for
81  // all live points
82  forAll (samplingPoints, cellI)
83  {
84  const vector& curP = samplingPoints[cellI];
85 
86  scalar sumW = 0;
87 
88  // Local weights
89  scalarList& curCW = cellWeights[cellI];
90 
91  const labelList& curCells = ibcc[cellI];
92 
93  forAll (curCells, ccI)
94  {
95  // Only pick live cells
96  if (gammaIn[curCells[ccI]] > SMALL)
97  {
98  curCW[ccI] = 1/mag(CIn[curCells[ccI]] - curP);
99  sumW += curCW[ccI];
100  }
101  else
102  {
103  curCW[ccI] = 0;
104  }
105  }
106 
107  // Processor weights
108  const List<labelPair>& interpProcCells = ibcProcC[cellI];
109 
110  scalarList& curProcCW = cellProcWeights[cellI];
111 
112  forAll (interpProcCells, cProcI)
113  {
114  if
115  (
116  gammaProc
117  [
118  interpProcCells[cProcI].first()
119  ]
120  [
121  interpProcCells[cProcI].second()
122  ] > SMALL
123  )
124  {
125  curProcCW[cProcI] =
126  1/mag
127  (
128  CProc
129  [
130  interpProcCells[cProcI].first()
131  ]
132  [
133  interpProcCells[cProcI].second()
134  ] - curP
135  );
136 
137  sumW += curProcCW[cProcI];
138  }
139  else
140  {
141  curProcCW[cProcI] = 0;
142  }
143  }
144 
145  // Divide through by the sum
146  if (sumW < SMALL)
147  {
148  InfoIn
149  (
150  "void immersedBoundaryFvPatch::makeIbSamplingWeights()"
151  ) << "Insufficient live neighbourhood for IB cell "
152  << ibc[cellI] << "." << nl
153  << "Please adjust radiusFactor, angleFactor or "
154  << "immersedBoundaryMaxCellCellRows "
155  << "in immersedBoundaryFvPatch."
156  << endl;
157 
158  // Reset sum and weights and use all points
159  sumW = 0;
160  curCW = 0;
161 
162  forAll (curCells, ccI)
163  {
164  // Use all cells
165  curCW[ccI] = 1/mag(CIn[curCells[ccI]] - curP);
166  sumW += curCW[ccI];
167  }
168  }
169 
170  forAll (curCells, ccI)
171  {
172  curCW[ccI] /= sumW;
173  }
174 
175  forAll (curProcCW, cProcI)
176  {
177  curProcCW[cProcI] /= sumW;
178  }
179  }
180 }
181 
182 
185 {
186  if (!ibSamplingWeightsPtr_)
187  {
188  makeIbSamplingWeights();
189  }
190 
191  return *ibSamplingWeightsPtr_;
192 }
193 
194 
197 {
198  if (!ibSamplingProcWeightsPtr_)
199  {
200  makeIbSamplingWeights();
201  }
202 
203  return *ibSamplingProcWeightsPtr_;
204 }
205 
206 
207 // ************************************************************************* //
volFields.H
InfoIn
#define InfoIn(functionName)
Report a information message using Foam::Info.
Definition: messageStream.H:276
Foam::FieldField
Generic field type.
Definition: FieldField.H:51
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::immersedBoundaryFvPatch::ibCellProcCells
const List< List< labelPair > > & ibCellProcCells() const
Return neighbour cell addressing.
Definition: immersedBoundaryFvPatch.C:2436
Foam::immersedBoundaryFvPatch::ibSamplingProcWeightsPtr_
scalarListList * ibSamplingProcWeightsPtr_
Interpolation weights for sampling processor weights.
Definition: immersedBoundaryFvPatch.H:154
Foam::immersedBoundaryFvPatch::ibProcGamma
const FieldField< Field, scalar > & ibProcGamma() const
Return neighbour proc gamma.
Definition: immersedBoundaryFvPatch.C:2424
Foam::immersedBoundaryFvPatch::mesh_
const fvMesh & mesh_
Finite volume mesh reference.
Definition: immersedBoundaryFvPatch.H:76
Foam::immersedBoundaryFvPatch::makeIbSamplingWeights
void makeIbSamplingWeights() const
Make sampling point weights.
Definition: immersedBoundaryFvPatchSamplingWeights.C:32
Foam::immersedBoundaryFvPatch::ibSamplingPoints
const vectorField & ibSamplingPoints() const
Return IB sampling points.
Definition: immersedBoundaryFvPatch.C:2389
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::immersedBoundaryFvPatch::gamma
const volScalarField & gamma() const
Get fluid cells indicator, marking only live fluid cells.
Definition: immersedBoundaryFvPatch.C:2256
Foam::fvPatch::size
virtual label size() const
Return size.
Definition: fvPatch.H:161
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::immersedBoundaryFvPatch::ibCells
const labelList & ibCells() const
Return list of fluid cells next to immersed boundary (IB cells)
Definition: immersedBoundaryFvPatch.C:2289
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::immersedBoundaryFvPatch::ibSamplingProcWeights
const scalarListList & ibSamplingProcWeights() const
Processor interpolation weights for sampling points.
Definition: immersedBoundaryFvPatchSamplingWeights.C:196
Foam::GeometricField::internalField
InternalField & internalField()
Return internal field.
Definition: GeometricField.C:724
Foam::FatalError
error FatalError
fvMesh.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::immersedBoundaryFvPatch::ibCellCells
const labelListList & ibCellCells() const
Return IB cell extended stencil.
Definition: immersedBoundaryFvPatch.C:2400
Foam::fvMesh::C
const volVectorField & C() const
Return cell centres as volVectorField.
Definition: fvMeshGeometry.C:369
Foam::immersedBoundaryFvPatch::ibSamplingWeightsPtr_
scalarListList * ibSamplingWeightsPtr_
Interpolation weights for sampling weights.
Definition: immersedBoundaryFvPatch.H:151
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::immersedBoundaryFvPatch::ibSamplingWeights
const scalarListList & ibSamplingWeights() const
Interpolation weights for sampling points.
Definition: immersedBoundaryFvPatchSamplingWeights.C:184
immersedBoundaryFvPatch.H
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
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::ibProcCentres
const FieldField< Field, vector > & ibProcCentres() const
Return neighbour proc centres.
Definition: immersedBoundaryFvPatch.C:2412