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-2019 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 (
37 ) const
38 {
39  // One value per face
40  tmp<Field<Type>> tvalues(new Field<Type>(patchFaceLabels().size()));
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(patchIDs(), i)
76  {
77  sz += mesh().boundaryMesh()[patchIDs()[i]].size();
78  }
79 
80  Field<Type> allPatchVals(sz);
81  sz = 0;
82 
83  forAll(patchIDs(), i)
84  {
85  // See mappedFixedValueFvPatchField
86  const mapDistribute& distMap = mappers_[i].map();
87 
88  // Send back sample points to processor that holds the cell.
89  // Mark cells with point::max so we know which ones we need
90  // to interpolate (since expensive).
91  vectorField samples(mappers_[i].samplePoints());
92  distMap.reverseDistribute(mesh().nCells(), point::max, samples);
93 
94  Field<Type> patchVals(mesh().nCells());
95 
96  forAll(samples, celli)
97  {
98  if (samples[celli] != point::max)
99  {
100  patchVals[celli] = interpolator.interpolate
101  (
102  samples[celli],
103  celli
104  );
105  }
106  }
107 
108  distMap.distribute(patchVals);
109 
110  // Now patchVals holds the interpolated data in patch face order.
111  // Collect.
112  SubList<Type>(allPatchVals, patchVals.size(), sz) = patchVals;
113  sz += patchVals.size();
114  }
115 
116  // Interpolate to points. Reconstruct the patch of all faces to aid
117  // interpolation.
118 
119  labelList meshFaceLabels(allPatchVals.size());
120  sz = 0;
121  forAll(patchIDs(), i)
122  {
123  const polyPatch& pp = mesh().boundaryMesh()[patchIDs()[i]];
124  forAll(pp, i)
125  {
126  meshFaceLabels[sz++] = pp.start()+i;
127  }
128  }
129 
130  indirectPrimitivePatch allPatches
131  (
132  IndirectList<face>(mesh().faces(), meshFaceLabels),
133  mesh().points()
134  );
135 
137  (
138  allPatches
139  ).faceToPointInterpolate(allPatchVals);
140 }
141 
142 
143 // ************************************************************************* //
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
Generic GeometricField class.
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.
scalarField samples(nIntervals, 0)
A list of faces which address into the list of points.
dynamicFvMesh & mesh
const pointField & points
Pre-declare SubField and related Field type.
Definition: Field.H:56
void reverseDistribute(const label constructSize, List< T > &, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
Class containing processor-to-processor mapping information.
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:309
Abstract base class for interpolation.
A class for managing temporary objects.
Definition: PtrList.H:53
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
A List with indirect addressing.
Definition: IndirectList.H:101