sampledFaceZoneTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2020-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "sampledFaceZone.H"
29 #include "volFieldsFwd.H"
30 #include "pointFields.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 template<class Type>
37 Foam::sampledFaceZone::sampleOnFaces
38 (
39  const interpolation<Type>& sampler
40 ) const
41 {
42  const auto& vField = sampler.psi();
43  const labelList& own = mesh().faceOwner();
44  const labelList& nei = mesh().faceNeighbour();
45 
46  // One value per face
47  auto tvalues = tmp<Field<Type>>::New(faceId_.size());
48  auto& values = tvalues.ref();
49 
50  forAll(faceId_, i)
51  {
52  const label facei = faceId_[i];
53  const label patchi = facePatchId_[i];
54 
55  if (patchi != -1)
56  {
57  // Boundary face - face id is the patch-local face id
58  values[i] = vField.boundaryField()[patchi][facei];
59  }
60  else
61  {
62  // Internal face
63  values[i] = 0.5*(vField[own[facei]] + vField[nei[facei]]);
64  }
65  }
66 
67  return tvalues;
68 }
69 
70 
71 template<class Type>
73 Foam::sampledFaceZone::sampleOnFaces
74 (
75  const SurfaceField<Type>& sField
76 ) const
77 {
78  // One value per face
79  auto tvalues = tmp<Field<Type>>::New(faceId_.size());
80  auto& values = tvalues.ref();
81 
82  forAll(faceId_, i)
83  {
84  const label facei = faceId_[i];
85  const label patchi = facePatchId_[i];
86 
87  if (patchi != -1)
88  {
89  // Boundary face - face id is the patch-local face id
90  values[i] = sField.boundaryField()[patchi][facei];
91  }
92  else
93  {
94  // Internal face
95  values[i] = sField[facei];
96  }
97  }
98 
99  return tvalues;
100 }
101 
102 
103 template<class Type>
105 Foam::sampledFaceZone::sampleOnPoints
106 (
107  const interpolation<Type>& interpolator
108 ) const
109 {
110  // One value per vertex
111  auto tvalues = tmp<Field<Type>>::New(points().size(), Zero);
112  auto& values = tvalues.ref();
113 
114  const labelList& own = mesh().faceOwner();
115 
116  bitSet pointDone(points().size());
117 
118  forAll(faces(), i)
119  {
120  const face& f = faces()[i];
121  label facei = faceId_[i];
122  const label patchi = facePatchId_[i];
123 
124  if (patchi != -1)
125  {
126  // Boundary face. patch-local face id -> mesh face id
127  const polyPatch& pp = mesh().boundaryMesh()[patchi];
128 
129  facei += pp.start();
130  }
131 
132 
133  const label celli = own[facei];
134 
135  for (const label pointi : f)
136  {
137  if (pointDone.set(pointi))
138  {
139  values[pointi] = interpolator.interpolate
140  (
141  points()[pointi],
142  celli,
143  facei
144  );
145  }
146  }
147  }
148 
149  return tvalues;
150 }
151 
152 
153 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:504
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
Forwards and collection of common volume field types.
const polyMesh & mesh() const noexcept
Access to the underlying mesh.
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1122
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
static autoPtr< sampledSurface > New(const word &name, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected surface.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
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.
dynamicFvMesh & mesh
const pointField & points
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:608
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1116
labelList f(nPoints)
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
Abstract base class for volume field interpolation.
A class for managing temporary objects.
Definition: HashPtrTable.H:50
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
const GeometricField< Type, fvPatchField, volMesh > & psi() const noexcept
Return the field to be interpolated.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127