initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / scalarRange / scalarRanges.C
blobc59e2b5a9d615e49c05bfa8432e51eaa9261c10d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 "scalarRanges.H"
28 #include "DynamicList.H"
29 #include "ListOps.H"
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 Foam::scalarRanges::scalarRanges()
35     List<scalarRange>(0)
39 Foam::scalarRanges::scalarRanges(Istream& is)
41     List<scalarRange>(0)
43     DynamicList<scalarRange> lst;
45     while (is.good())
46     {
47         scalarRange sr(is);
48         if (sr.isDefined())
49         {
50             lst.append(sr);
51         }
52     }
54     transfer(lst);
58 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
60 bool Foam::scalarRanges::selected(const scalar& value) const
62     forAll(*this, i)
63     {
64         if (operator[](i).selected(value))
65         {
66             return true;
67         }
68     }
70     return false;
74 Foam::List<bool> Foam::scalarRanges::selected
76     const List<scalar>& values
77 ) const
79     List<bool> lst(values.size(), false);
81     // check ranges
82     forAll(values, i)
83     {
84         if (selected(values[i]))
85         {
86             lst[i] = true;
87         }
88     }
90     // check specific values
91     forAll(*this, rangeI)
92     {
93         if (operator[](rangeI).isExact())
94         {
95             scalar target = operator[](rangeI).value();
97             int nearestIndex = -1;
98             scalar nearestDiff = Foam::GREAT;
100             forAll(values, timeIndex)
101             {
102                 scalar diff = fabs(values[timeIndex] - target);
103                 if (diff < nearestDiff)
104                 {
105                     nearestDiff = diff;
106                     nearestIndex = timeIndex;
107                 }
108             }
110             if (nearestIndex >= 0)
111             {
112                 lst[nearestIndex] = true;
113             }
114         }
115     }
117     return lst;
121 Foam::List<Foam::scalar> Foam::scalarRanges::select
123     const List<scalar>& values
124 ) const
126     return subset(selected(values), values);
130 void Foam::scalarRanges::inplaceSelect
132     List<scalar>& values
133 ) const
135     inplaceSubset(selected(values), values);
139 // ************************************************************************* //