Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / sampling / sampledSurface / sampledTriSurfaceMesh / sampledTriSurfaceMeshTemplates.C
blob9e8b251f7f5093ef89a159c288f351cc4f682ce8
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2010-2011 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "sampledTriSurfaceMesh.H"
28 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
30 template <class Type>
31 Foam::tmp<Foam::Field<Type> >
32 Foam::sampledTriSurfaceMesh::sampleField
34     const GeometricField<Type, fvPatchField, volMesh>& vField
35 ) const
37     // One value per face
38     tmp<Field<Type> > tvalues(new Field<Type>(sampleElements_.size()));
39     Field<Type>& values = tvalues();
41     if (sampleSource_ == cells)
42     {
43         // Sample cells
45         forAll(sampleElements_, triI)
46         {
47             values[triI] = vField[sampleElements_[triI]];
48         }
49     }
50     else
51     {
52         // Sample boundary faces
54         const polyBoundaryMesh& pbm = mesh().boundaryMesh();
55         label nBnd = mesh().nFaces()-mesh().nInternalFaces();
57         // Create flat boundary field
59         Field<Type> bVals(nBnd, pTraits<Type>::zero);
61         forAll(vField.boundaryField(), patchI)
62         {
63             label bFaceI = pbm[patchI].start() - mesh().nInternalFaces();
65             SubList<Type>
66             (
67                 bVals,
68                 vField.boundaryField()[patchI].size(),
69                 bFaceI
70             ).assign(vField.boundaryField()[patchI]);
71         }
73         // Sample in flat boundary field
75         forAll(sampleElements_, triI)
76         {
77             label faceI = sampleElements_[triI];
78             values[triI] = bVals[faceI-mesh().nInternalFaces()];
79         }
80     }
82     return tvalues;
86 template <class Type>
87 Foam::tmp<Foam::Field<Type> >
88 Foam::sampledTriSurfaceMesh::interpolateField
90     const interpolation<Type>& interpolator
91 ) const
93     // One value per vertex
94     tmp<Field<Type> > tvalues(new Field<Type>(sampleElements_.size()));
95     Field<Type>& values = tvalues();
97     if (sampleSource_ == cells)
98     {
99         // Sample cells.
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.
114         forAll(samplePoints_, pointI)
115         {
116             label faceI = sampleElements_[pointI];
118             values[pointI] = interpolator.interpolate
119             (
120                 samplePoints_[pointI],
121                 mesh().faceOwner()[faceI],
122                 faceI
123             );
124         }
125     }
127     return tvalues;
131 // ************************************************************************* //