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 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"
31 #include "volPointInterpolation.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 (
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 // ************************************************************************* //
volFieldsFwd.H
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::HashTableOps::values
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:149
Foam::bitSet::set
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:574
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::interpolation::psi
const GeometricField< Type, fvPatchField, volMesh > & psi() const
Return the field to be interpolated.
Definition: interpolation.H:127
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:96
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:361
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
volPointInterpolation.H
sampledFaceZone.H
f
labelList f(nPoints)
Foam::List< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::interpolation::interpolate
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.
pointFields.H
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62