initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / sampling / sampledSet / cloud / cloudSet.C
blob35366196c9a186d71018506d6e41081d32b346bb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "cloudSet.H"
28 #include "sampledSet.H"
29 #include "meshSearch.H"
30 #include "DynamicList.H"
31 #include "polyMesh.H"
32 #include "addToRunTimeSelectionTable.H"
33 #include "word.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 namespace Foam
39     defineTypeNameAndDebug(cloudSet, 0);
40     addToRunTimeSelectionTable(sampledSet, cloudSet, word);
44 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
46 void Foam::cloudSet::calcSamples
48     DynamicList<point>& samplingPts,
49     DynamicList<label>& samplingCells,
50     DynamicList<label>& samplingFaces,
51     DynamicList<label>& samplingSegments,
52     DynamicList<scalar>& samplingCurveDist
53 ) const
55     forAll(sampleCoords_, sampleI)
56     {
57         label cellI = searchEngine().findCell(sampleCoords_[sampleI]);
59         if (cellI != -1)
60         {
61             samplingPts.append(sampleCoords_[sampleI]);
62             samplingCells.append(cellI);
63             samplingFaces.append(-1);
64             samplingSegments.append(0);
65             samplingCurveDist.append(1.0 * sampleI);
66         }
67     }
71 void Foam::cloudSet::genSamples()
73     // Storage for sample points
74     DynamicList<point> samplingPts;
75     DynamicList<label> samplingCells;
76     DynamicList<label> samplingFaces;
77     DynamicList<label> samplingSegments;
78     DynamicList<scalar> samplingCurveDist;
80     calcSamples
81     (
82         samplingPts,
83         samplingCells,
84         samplingFaces,
85         samplingSegments,
86         samplingCurveDist
87     );
89     samplingPts.shrink();
90     samplingCells.shrink();
91     samplingFaces.shrink();
92     samplingSegments.shrink();
93     samplingCurveDist.shrink();
95     setSamples
96     (
97         samplingPts,
98         samplingCells,
99         samplingFaces,
100         samplingSegments,
101         samplingCurveDist
102     );
106 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
108 Foam::cloudSet::cloudSet
110     const word& name,
111     const polyMesh& mesh,
112     meshSearch& searchEngine,
113     const word& axis,
114     const List<point>& sampleCoords
117     sampledSet(name, mesh, searchEngine, axis),
118     sampleCoords_(sampleCoords)
120     genSamples();
122     if (debug)
123     {
124         write(Info);
125     }
129 Foam::cloudSet::cloudSet
131     const word& name,
132     const polyMesh& mesh,
133     meshSearch& searchEngine,
134     const dictionary& dict
137     sampledSet(name, mesh, searchEngine, dict),
138     sampleCoords_(dict.lookup("points"))
140     genSamples();
142     if (debug)
143     {
144         write(Info);
145     }
149 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
151 Foam::cloudSet::~cloudSet()
155 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
157 Foam::point Foam::cloudSet::getRefPoint(const List<point>& pts) const
159     if (pts.size() > 0)
160     {
161         // Use first samplePt as starting point
162         return pts[0];
163     }
164     else
165     {
166         return vector::zero;
167     }
171 // ************************************************************************* //