sampledPatchInternalFieldTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 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 
27 #include "interpolationCellPoint.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
34 Foam::sampledSurfaces::patchInternalField::sampleField
35 (
36  const VolField<Type>& vField
37 ) const
38 {
39  // One value per face
41  Field<Type>& values = tvalues.ref();
42 
43  forAll(patchStart(), i)
44  {
45  // Get patchface wise data by sampling internal field
46  Field<Type> interpVals = vField.primitiveField();
47  mappers_[i].map().distribute(interpVals);
48 
49  // Store at correct position in values
50  label end =
51  (
52  i < patchStart().size()-1
53  ? patchStart()[i+1]
54  : patchFaceLabels().size()
55  );
56 
57  for (label triI = patchStart()[i]; triI < end; triI++)
58  {
59  values[triI] = interpVals[patchFaceLabels()[triI]];
60  }
61  }
62 
63  return tvalues;
64 }
65 
66 
67 template<class Type>
69 Foam::sampledSurfaces::patchInternalField::interpolateField
70 (
71  const interpolation<Type>& interpolator
72 ) const
73 {
74  label sz = 0;
75  forAll(patchIndices(), i)
76  {
77  sz += mesh().boundaryMesh()[patchIndices()[i]].size();
78  }
79 
80  Field<Type> allPatchVals(sz);
81  sz = 0;
82 
83  forAll(patchIndices(), i)
84  {
85  // Cells on which samples are generated
86  const labelList& sampleCells = mappers_[i].cellIndices();
87 
88  // Send the sample points to the cells
89  const distributionMap& distMap = mappers_[i].map();
90  pointField samplePoints(mappers_[i].samplePoints());
91  distMap.reverseDistribute(sampleCells.size(), samplePoints);
92 
93  // Interpolate values
94  Field<Type> sampleValues(sampleCells.size());
95  forAll(sampleCells, i)
96  {
97  if (sampleCells[i] != -1)
98  {
99  sampleValues[i] =
100  interpolator.interpolate(samplePoints[i], sampleCells[i]);
101  }
102  }
103 
104  // Send the values back to the patch
105  Field<Type> patchValues(sampleValues);
106  distMap.distribute(patchValues);
107 
108  // Insert into the full value field
109  SubList<Type>(allPatchVals, patchValues.size(), sz) = patchValues;
110  sz += patchValues.size();
111  }
112 
113  // Interpolate to points. Reconstruct the patch of all faces to aid
114  // interpolation.
115 
116  labelList meshFaceLabels(allPatchVals.size());
117  sz = 0;
118  forAll(patchIndices(), i)
119  {
120  const polyPatch& pp = mesh().boundaryMesh()[patchIndices()[i]];
121  forAll(pp, i)
122  {
123  meshFaceLabels[sz++] = pp.start()+i;
124  }
125  }
126 
127  indirectPrimitivePatch allPatches
128  (
129  IndirectList<face>(mesh().faces(), meshFaceLabels),
130  mesh().points()
131  );
132 
134  (
135  allPatches
136  ).faceToPointInterpolate(allPatchVals);
137 }
138 
139 
140 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic GeometricField class.
const Internal::FieldType & primitiveField() const
Return a const-reference to the primitive field.
A List with indirect addressing.
Definition: IndirectList.H:105
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
label size() const
The surface size is the number of faces.
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
tmp< Field< Type > > faceToPointInterpolate(const Field< Type > &ff) const
Interpolate from faces to points.
Class containing processor-to-processor mapping information.
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
void reverseDistribute(const label constructSize, List< T > &, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
Abstract base class for interpolation.
Definition: interpolation.H:55
virtual Type interpolate(const vector &position, const label celli, const label facei=-1) const =0
Interpolate field to the given point in the given cell.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:280
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:270
const labelList & patchFaceLabels() const
Definition: sampledPatch.H:160
const labelList & patchStart() const
Definition: sampledPatch.H:155
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
const pointField & points
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