sampledTriSurfaceMeshTemplates.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 
26 #include "sampledTriSurfaceMesh.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class Type>
32 Foam::sampledSurfaces::triSurfaceMesh::sampleField
33 (
35 ) const
36 {
37  // One value per face
38  tmp<Field<Type>> tvalues(new Field<Type>(sampleElements_.size()));
39  Field<Type>& values = tvalues.ref();
40 
41  if (sampleSource_ == cells || sampleSource_ == insideCells)
42  {
43  // Sample cells
44 
45  forAll(sampleElements_, triI)
46  {
47  values[triI] = vField[sampleElements_[triI]];
48  }
49  }
50  else
51  {
52  // Sample boundary faces
53 
54  const polyBoundaryMesh& pbm = mesh().boundaryMesh();
55  label nBnd = mesh().nFaces()-mesh().nInternalFaces();
56 
57  // Create flat boundary field
58 
59  Field<Type> bVals(nBnd, Zero);
60 
61  forAll(vField.boundaryField(), patchi)
62  {
63  label bFacei = pbm[patchi].start() - mesh().nInternalFaces();
64 
66  (
67  bVals,
68  vField.boundaryField()[patchi].size(),
69  bFacei
70  ) = vField.boundaryField()[patchi];
71  }
72 
73  // Sample in flat boundary field
74 
75  forAll(sampleElements_, triI)
76  {
77  label facei = sampleElements_[triI];
78  values[triI] = bVals[facei-mesh().nInternalFaces()];
79  }
80  }
81 
82  return tvalues;
83 }
84 
85 
86 template<class Type>
88 Foam::sampledSurfaces::triSurfaceMesh::interpolateField
89 (
90  const interpolation<Type>& interpolator
91 ) const
92 {
93  // One value per vertex
94  tmp<Field<Type>> tvalues(new Field<Type>(sampleElements_.size()));
95  Field<Type>& values = tvalues.ref();
96 
97  if (sampleSource_ == cells || sampleSource_ == insideCells)
98  {
99  // Sample cells.
100 
101  forAll(sampleElements_, pointi)
102  {
103  values[pointi] = interpolator.interpolate
104  (
105  samplePoints_[pointi],
106  sampleElements_[pointi]
107  );
108  }
109  }
110  else
111  {
112  // Sample boundary faces.
113 
114  forAll(samplePoints_, pointi)
115  {
116  label facei = sampleElements_[pointi];
117 
118  values[pointi] = interpolator.interpolate
119  (
120  samplePoints_[pointi],
121  mesh().faceOwner()[facei],
122  facei
123  );
124  }
125  }
126 
127  return tvalues;
128 }
129 
130 
131 // ************************************************************************* //
#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
const Boundary & boundaryField() const
Return const-reference to the boundary field.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
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.
dynamicFvMesh & mesh
const cellShapeList & cells
Pre-declare SubField and related Field type.
Definition: Field.H:56
static const zero Zero
Definition: zero.H:97
Foam::polyBoundaryMesh.
label patchi
Abstract base class for interpolation.
A class for managing temporary objects.
Definition: PtrList.H:53