immersedBoundaryFvPatchTemplates.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 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class Type>
34 (
35  const Field<Type>& psi
36 ) const
37 {
39  (
40  new FieldField<Field, Type>(Pstream::nProcs())
41  );
42  FieldField<Field, Type>& procPsi = tprocPsi();
43 
44  forAll (procPsi, procI)
45  {
46  procPsi.set
47  (
48  procI,
49  new Field<Type>
50  (
51  ibProcCentres()[procI].size(),
53  )
54  );
55  }
56 
57  if (Pstream::parRun())
58  {
59  // Send
60  for (label procI = 0; procI < Pstream::nProcs(); procI++)
61  {
62  if (procI != Pstream::myProcNo())
63  {
64  // Do not send empty lists
65  if (!ibProcCells()[procI].empty())
66  {
67  Field<Type> curPsi(psi, ibProcCells()[procI]);
68 
69  // Parallel data exchange
70  OPstream toProc
71  (
72  Pstream::blocking,
73  procI,
74  curPsi.size()*sizeof(Type)
75  );
76 
77  toProc << curPsi;
78  }
79  }
80  }
81 
82  // Receive
83  for (label procI = 0; procI < Pstream::nProcs(); procI++)
84  {
85  if (procI != Pstream::myProcNo())
86  {
87  // Do not receive empty lists
88  if (!procPsi[procI].empty())
89  {
90  // Parallel data exchange
91  IPstream fromProc
92  (
93  Pstream::blocking,
94  procI,
95  procPsi[procI].size()*sizeof(Type)
96  );
97 
98  fromProc >> procPsi[procI];
99  }
100  }
101  }
102  }
103 
104  return tprocPsi;
105 }
106 
107 
108 template<class Type>
111 (
112  const Field<Type>& triValues
113 ) const
114 {
115  if (triValues.size() != ibMesh().size())
116  {
118  (
119  "template<class Type>\n"
120  "Foam::tmp<Foam::Field<Type> >\n"
121  "immersedBoundaryFvPatch::toIbPoints\n"
122  "(\n"
123  " const Field<Type>& triValues\n"
124  ") const"
125  ) << "Field size does not correspond to size of immersed boundary "
126  << "triangulated surface for patch " << name() << nl
127  << "Field size = " << triValues.size()
128  << " surface size = " << ibMesh().size()
129  << abort(FatalError);
130  }
131 
132  const labelList& ibc = ibCells();
133 
134  tmp<Field<Type> > tIbPsi
135  (
137  );
138  Field<Type>& ibPsi = tIbPsi();
139 
140  const labelList& hf = hitFaces();
141 
142  // Assuming triSurface data is on triangles
143  forAll (ibPsi, cellI)
144  {
145  ibPsi[cellI] = triValues[hf[cellI]];
146  }
147 
148 // const vectorField& p = ibPoints();
149 // const List<labelledTri>& faces = ibMesh();
150 // const vectorField& triPoints = ibMesh().points();
151 
152 // // Assuming triSurface data is on vertices
153 // forAll (ibPsi, cellI)
154 // {
155 // const labelledTri& tri = faces[hf[cellI]];
156 // triPointRef triPt = faces[hf[cellI]].tri(triPoints);
157 
158 // ibPsi[cellI] =
159 // triValues[tri[0]]*triPt.Ni(0, p[cellI])
160 // + triValues[tri[1]]*triPt.Ni(1, p[cellI])
161 // + triValues[tri[2]]*triPt.Ni(2, p[cellI]);
162 // }
163 
164  return tIbPsi;
165 }
166 
167 
168 template<class Type>
171 (
172  const tmp<Field<Type> >& ttriValues
173 ) const
174 {
175  tmp<Field<Type> > tint = toIbPoints(ttriValues());
176  ttriValues.clear();
177  return tint;
178 
179 }
180 
181 
182 template<class Type>
185 (
186  const Field<Type>& ibValues
187 ) const
188 {
189  if (ibValues.size() != ibCells().size())
190  {
192  (
193  "template<class Type>\n"
194  "Foam::tmp<Foam::Field<Type> >\n"
195  "immersedBoundaryFvPatch::toTriFaces\n"
196  "(\n"
197  " const Field<Type>& ibValues\n"
198  ") const"
199  ) << "Field size does not correspond to size of IB points "
200  << "triangulated surface for patch " << name() << nl
201  << "Field size = " << ibValues.size()
202  << " IB points size = " << ibCells().size()
203  << abort(FatalError);
204  }
205 
206  const labelListList& ctfAddr = cellsToTriAddr();
207  const scalarListList& ctfWeights = cellsToTriWeights();
208 
209  tmp<Field<Type> > tIbPsi
210  (
211  new Field<Type>(ctfAddr.size(), pTraits<Type>::zero)
212  );
213  Field<Type>& ibPsi = tIbPsi();
214 
215  // Do interpolation
216  forAll (ctfAddr, triI)
217  {
218  const labelList& curAddr = ctfAddr[triI];
219  const scalarList& curWeights = ctfWeights[triI];
220 
221  forAll (curAddr, cellI)
222  {
223  ibPsi[triI] += curWeights[cellI]*ibValues[curAddr[cellI]];
224  }
225  }
226 
227  return tIbPsi;
228 }
229 
230 
231 template<class Type>
234 (
235  const tmp<Field<Type> >& tibValues
236 ) const
237 {
238  tmp<Field<Type> > tint = toTriFaces(tibValues());
239  tibValues.clear();
240  return tint;
241 
242 }
243 
244 
245 template<class Type>
248 (
249  const Field<Type>& cellValues
250 ) const
251 {
252  if (cellValues.size() != mesh_.nCells())
253  {
255  (
256  "template<class Type>\n"
257  "Foam::tmp<Foam::Field<Type> >\n"
258  "immersedBoundaryFvPatch::toSamplingPoints\n"
259  "(\n"
260  " const Field<Type>& cellValues\n"
261  ") const"
262  ) << "Field size does not correspond to cell centres "
263  << "for patch " << name() << nl
264  << "Field size = " << cellValues.size()
265  << " nCells = " << mesh_.nCells()
266  << abort(FatalError);
267  }
268 
269  // Get addressing
270  const labelList& ibc = ibCells();
271  const labelListList& ibcc = ibCellCells();
272  const List<List<labelPair> >& ibcProcC = ibCellProcCells();
273 
274  // Get weights
275  const scalarListList& cellWeights = ibSamplingWeights();
276  const scalarListList& cellProcWeights = ibSamplingProcWeights();
277 
278  tmp<Field<Type> > tIbPsi
279  (
281  );
282  Field<Type>& ibPsi = tIbPsi();
283 
284  // Do interpolation, local cell data
285  forAll (ibc, cellI)
286  {
287  const labelList& curAddr = ibcc[cellI];
288  const scalarList& curWeights = cellWeights[cellI];
289 
290  forAll (curAddr, ccI)
291  {
292  ibPsi[cellI] += curWeights[ccI]*cellValues[curAddr[ccI]];
293  }
294  }
295 
296  // Parallel communication for psi
297  FieldField<Field, Type> procCellValues = sendAndReceive(cellValues);
298 
299  // Do interpolation, cell data from other processors
300  forAll (ibc, cellI)
301  {
302  const List<labelPair>& curProcCells = ibcProcC[cellI];
303  const scalarList& curProcWeights = cellProcWeights[cellI];
304 
305  forAll (curProcCells, cpcI)
306  {
307  ibPsi[cellI] +=
308  curProcWeights[cpcI]*
309  procCellValues
310  [
311  curProcCells[cpcI].first()
312  ]
313  [
314  curProcCells[cpcI].second()
315  ];
316  }
317  }
318 
319  return tIbPsi;
320 }
321 
322 
323 template<class Type>
326 (
327  const Field<Type>& f
328 ) const
329 {
330  const dynamicLabelList& triFInM = this->triFacesInMesh();
331 
332  tmp<Field<Type> > trf(new Field<Type>(triFInM.size()));
333  Field<Type>& rf = trf();
334 
335  forAll(triFInM, faceI)
336  {
337  rf[faceI] = f[triFInM[faceI]];
338  }
339 
340  return trf;
341 }
342 
343 
344 // ************************************************************************ //
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::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:50
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< Type >
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::FatalError
error FatalError
fvMesh.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
psi
const volScalarField & psi
Definition: setRegionFluidFields.H:13
f
labelList f(nPoints)
Foam::immersedBoundaryFvPatch::toIbPoints
tmp< Field< Type > > toIbPoints(const Field< Type > &triValues) const
Collect ibPoint values: from tri face fields onto intersection.
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::pTraits
Traits class for primitives.
Definition: pTraits.H:50
immersedBoundaryFvPatch.H
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:50
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::immersedBoundaryFvPatch::toSamplingPoints
tmp< Field< Type > > toSamplingPoints(const Field< Type > &cellValues) const
Interpolation functions to sampling points from mesh cell centres.
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::immersedBoundaryFvPatch::renumberField
const tmp< Field< Type > > renumberField(const Field< Type > &f) const
Renumber Field to corespond to triangular faces contained.
Foam::immersedBoundaryFvPatch::sendAndReceive
tmp< FieldField< Field, Type > > sendAndReceive(const Field< Type > &psi) const
Send and receive.
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::immersedBoundaryFvPatch::toTriFaces
tmp< Field< Type > > toTriFaces(const Field< Type > &ibValues) const
triFace values: collect data from IB fields onto intersection