BUG: cloudSet.C: force early construction of tetBasePtIs to avoid demand-driven comms
[OpenFOAM-2.0.x.git] / src / sampling / sampledSet / triSurfaceMeshPointSet / triSurfaceMeshPointSet.C
blob3704f950e0345eb72d4e7b2a4a0a4b89495c2a99
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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 "triSurfaceMeshPointSet.H"
27 #include "meshSearch.H"
28 #include "DynamicList.H"
29 #include "polyMesh.H"
30 #include "addToRunTimeSelectionTable.H"
31 #include "triSurfaceMesh.H"
32 #include "Time.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace Foam
38     defineTypeNameAndDebug(triSurfaceMeshPointSet, 0);
39     addToRunTimeSelectionTable(sampledSet, triSurfaceMeshPointSet, word);
43 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
45 void Foam::triSurfaceMeshPointSet::calcSamples
47     DynamicList<point>& samplingPts,
48     DynamicList<label>& samplingCells,
49     DynamicList<label>& samplingFaces,
50     DynamicList<label>& samplingSegments,
51     DynamicList<scalar>& samplingCurveDist
52 ) const
54     forAll(sampleCoords_, sampleI)
55     {
56         label cellI = searchEngine().findCell(sampleCoords_[sampleI]);
58         if (cellI != -1)
59         {
60             samplingPts.append(sampleCoords_[sampleI]);
61             samplingCells.append(cellI);
62             samplingFaces.append(-1);
63             samplingSegments.append(0);
64             samplingCurveDist.append(1.0 * sampleI);
65         }
66     }
70 void Foam::triSurfaceMeshPointSet::genSamples()
72     // Storage for sample points
73     DynamicList<point> samplingPts;
74     DynamicList<label> samplingCells;
75     DynamicList<label> samplingFaces;
76     DynamicList<label> samplingSegments;
77     DynamicList<scalar> samplingCurveDist;
79     calcSamples
80     (
81         samplingPts,
82         samplingCells,
83         samplingFaces,
84         samplingSegments,
85         samplingCurveDist
86     );
88     samplingPts.shrink();
89     samplingCells.shrink();
90     samplingFaces.shrink();
91     samplingSegments.shrink();
92     samplingCurveDist.shrink();
94     setSamples
95     (
96         samplingPts,
97         samplingCells,
98         samplingFaces,
99         samplingSegments,
100         samplingCurveDist
101     );
105 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
107 Foam::triSurfaceMeshPointSet::triSurfaceMeshPointSet
109     const word& name,
110     const polyMesh& mesh,
111     meshSearch& searchEngine,
112     const dictionary& dict
115     sampledSet(name, mesh, searchEngine, dict),
116     surface_(dict.lookup("surface"))
118     // Load surface.
119     if (mesh.time().foundObject<triSurfaceMesh>(surface_))
120     {
121         // Note: should use localPoints() instead of points() but assume
122         // trisurface is compact.
123         sampleCoords_ = mesh.time().lookupObject<triSurfaceMesh>
124         (
125             surface_
126         ).points();
127     }
128     else
129     {
130         sampleCoords_ = triSurfaceMesh
131         (
132             IOobject
133             (
134                 surface_,
135                 mesh.time().constant(),     // instance
136                 "triSurface",               // local
137                 mesh.time(),
138                 IOobject::MUST_READ,
139                 IOobject::NO_WRITE,
140                 false
141             )
142         ).points();
143     }
145     genSamples();
147     if (debug)
148     {
149         write(Info);
150     }
154 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
156 Foam::triSurfaceMeshPointSet::~triSurfaceMeshPointSet()
160 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
162 Foam::point Foam::triSurfaceMeshPointSet::getRefPoint(const List<point>& pts)
163  const
165     if (pts.size())
166     {
167         // Use first samplePt as starting point
168         return pts[0];
169     }
170     else
171     {
172         return vector::zero;
173     }
177 // ************************************************************************* //