sampledPatchTemplates.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-2026 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 
26 #include "sampledPatch.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class Type>
33 Foam::sampledSurfaces::patch::sampleField
34 (
35  const VolField<Type>& vField
36 ) const
37 {
38  // One value per face
39  tmp<Field<Type>> tvalues(new Field<Type>(patchFaceLabels_.size()));
40  Field<Type>& values = tvalues.ref();
41  forAll(patchFaceLabels_, i)
42  {
43  label patchi = patchIndices_[patchIndex_[i]];
44  const Field<Type>& bField = vField.boundaryField()[patchi];
45  values[i] = bField[patchFaceLabels_[i]];
46  }
47 
48  return tvalues;
49 }
50 
51 
52 template<class Type>
54 Foam::sampledSurfaces::patch::sampleField
55 (
56  const SurfaceField<Type>& sField
57 ) const
58 {
59  // One value per face
60  tmp<Field<Type>> tvalues(new Field<Type>(patchFaceLabels_.size()));
61  Field<Type>& values = tvalues.ref();
62 
63  forAll(patchFaceLabels_, i)
64  {
65  label patchi = patchIndices_[patchIndex_[i]];
66  values[i] = sField.boundaryField()[patchi][patchFaceLabels_[i]];
67  }
68 
69  return tvalues;
70 }
71 
72 
73 template<class Type>
75 Foam::sampledSurfaces::patch::interpolateField
76 (
77  const interpolation<Type>& interpolator
78 ) const
79 {
80  // One value per vertex
81  tmp<Field<Type>> tvalues(new Field<Type>(points().size()));
82  Field<Type>& values = tvalues.ref();
83 
84  const labelList& own = mesh().faceOwner();
85 
86  boolList pointDone(points().size(), false);
87 
88  forAll(faces(), cutFacei)
89  {
90  label patchi = patchIndices_[patchIndex_[cutFacei]];
91  const polyPatch& pp = mesh().boundary()[patchi];
92  label patchFacei = patchFaceLabels()[cutFacei];
93  const face& f = faces()[cutFacei];
94 
95  forAll(f, faceVertI)
96  {
97  label pointi = f[faceVertI];
98 
99  if (!pointDone[pointi])
100  {
101  label facei = patchFacei + pp.start();
102  label celli = own[facei];
103 
104  values[pointi] = interpolator.interpolate
105  (
106  points()[pointi],
107  celli,
108  facei
109  );
110  pointDone[pointi] = true;
111  }
112  }
113  }
114 
115  return tvalues;
116 }
117 
118 
119 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic GeometricField class.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:932
Abstract base class for interpolation.
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1321
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:71
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:277
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:197
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
label patchi
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
labelList f(nPoints)