sampledTriSurfaceTemplates.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 "sampledTriSurface.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class Type>
33 Foam::sampledSurfaces::triSurface::sampleField
34 (
35  const VolField<Type>& vField
36 ) const
37 {
38  // One value per face
39  tmp<Field<Type>> tvalues(new Field<Type>(sampleElements_.size()));
40  Field<Type>& values = tvalues.ref();
41 
42  if (sampleSource_ == cells || sampleSource_ == insideCells)
43  {
44  // Sample cells
45 
46  forAll(sampleElements_, triI)
47  {
48  values[triI] = vField[sampleElements_[triI]];
49  }
50  }
51  else
52  {
53  // Sample boundary faces
54 
55  const polyBoundaryMesh& pbm = mesh().boundary();
56  label nBnd = mesh().nFaces()-mesh().nInternalFaces();
57 
58  // Create flat boundary field
59 
60  Field<Type> bVals(nBnd, Zero);
61 
62  forAll(vField.boundaryField(), patchi)
63  {
64  label bFacei = pbm[patchi].start() - mesh().nInternalFaces();
65 
67  (
68  bVals,
69  vField.boundaryField()[patchi].size(),
70  bFacei
71  ) = vField.boundaryField()[patchi];
72  }
73 
74  // Sample in flat boundary field
75 
76  forAll(sampleElements_, triI)
77  {
78  label facei = sampleElements_[triI];
79  values[triI] = bVals[facei-mesh().nInternalFaces()];
80  }
81  }
82 
83  return tvalues;
84 }
85 
86 
87 template<class Type>
89 Foam::sampledSurfaces::triSurface::interpolateField
90 (
91  const interpolation<Type>& interpolator
92 ) const
93 {
94  // One value per vertex
95  tmp<Field<Type>> tvalues(new Field<Type>(sampleElements_.size()));
96  Field<Type>& values = tvalues.ref();
97 
98  if (sampleSource_ == cells || sampleSource_ == insideCells)
99  {
100  // Sample cells.
101 
102  forAll(sampleElements_, pointi)
103  {
104  values[pointi] = interpolator.interpolate
105  (
106  samplePoints_[pointi],
107  sampleElements_[pointi]
108  );
109  }
110  }
111  else
112  {
113  // Sample boundary faces.
114 
115  forAll(samplePoints_, pointi)
116  {
117  label facei = sampleElements_[pointi];
118 
119  values[pointi] = interpolator.interpolate
120  (
121  samplePoints_[pointi],
122  mesh().faceOwner()[facei],
123  facei
124  );
125  }
126  }
127 
128  return tvalues;
129 }
130 
131 
132 // ************************************************************************* //
#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
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
Abstract base class for interpolation.
Foam::polyBoundaryMesh.
const polyBoundaryMesh & boundary() const
Return boundary mesh.
Definition: polyMesh.H:393
label nInternalFaces() const
label nFaces() const
const polyMesh & mesh() const
Access to the underlying mesh.
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 cellShapeList & cells
static const zero Zero
Definition: zero.H:97
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