sampledTriSurfaceMeshTemplates.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "sampledTriSurfaceMesh.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 template<class Type>
35 Foam::sampledTriSurfaceMesh::sampleOnFaces
36 (
37  const interpolation<Type>& sampler
38 ) const
39 {
40  const labelList& elements = sampleElements_;
41 
42  if (!onBoundary())
43  {
44  // Sample cells
45 
46  return sampledSurface::sampleOnFaces
47  (
48  sampler,
49  elements,
50  faces(),
51  points()
52  );
53  }
54 
55 
56  //
57  // Sample boundary faces
58  //
59 
60  auto tvalues = tmp<Field<Type>>::New(elements.size());
61  auto& values = tvalues.ref();
62 
63  const polyBoundaryMesh& pbm = mesh().boundaryMesh();
64  const label nBnd = mesh().nBoundaryFaces();
65 
66  // Create flat boundary field
67 
68  Field<Type> bVals(nBnd, Zero);
69 
70  const auto& bField = sampler.psi().boundaryField();
71 
72  forAll(bField, patchi)
73  {
74  const label bFacei = (pbm[patchi].start() - mesh().nInternalFaces());
75 
77  (
78  bVals,
79  bField[patchi].size(),
80  bFacei
81  ) = bField[patchi];
82  }
83 
84  // Sample in flat boundary field
85 
86  forAll(elements, i)
87  {
88  const label bFacei = (elements[i] - mesh().nInternalFaces());
89  values[i] = bVals[bFacei];
90  }
91 
92  return tvalues;
93 }
94 
95 
96 template<class Type>
98 Foam::sampledTriSurfaceMesh::sampleOnPoints
99 (
100  const interpolation<Type>& interpolator
101 ) const
102 {
103  // One value per vertex
104  auto tvalues = tmp<Field<Type>>::New(sampleElements_.size());
105  auto& values = tvalues.ref();
106 
107  if (!onBoundary())
108  {
109  // Sample cells
110 
111  forAll(sampleElements_, pointi)
112  {
113  values[pointi] = interpolator.interpolate
114  (
115  samplePoints_[pointi],
116  sampleElements_[pointi]
117  );
118  }
119  }
120  else
121  {
122  // Sample boundary faces
123 
124  forAll(samplePoints_, pointi)
125  {
126  const label facei = sampleElements_[pointi];
127 
128  values[pointi] = interpolator.interpolate
129  (
130  samplePoints_[pointi],
131  mesh().faceOwner()[facei],
132  facei
133  );
134  }
135  }
136 
137  return tvalues;
138 }
139 
140 
141 // ************************************************************************* //
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
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::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::polyBoundaryMesh::start
label start() const
The start label of the boundary faces in the polyMesh face list.
Definition: polyBoundaryMesh.C:638
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::interpolation::psi
const GeometricField< Type, fvPatchField, volMesh > & psi() const
Return the field to be interpolated.
Definition: interpolation.H:127
sampledTriSurfaceMesh.H
Foam::label
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:62
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::interpolation
Abstract base class for interpolation.
Definition: mappedPatchFieldBase.H:95
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
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
Foam::List< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
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.
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62