|
|
|
scalarRanges.CGo to the documentation of this file.00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software; you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM; if not, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 \*---------------------------------------------------------------------------*/ 00026 00027 #include "scalarRanges.H" 00028 #include "DynamicList.H" 00029 #include "ListOps.H" 00030 00031 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // 00032 00033 Foam::scalarRanges::scalarRanges() 00034 : 00035 List<scalarRange>(0) 00036 {} 00037 00038 00039 Foam::scalarRanges::scalarRanges(Istream& is) 00040 : 00041 List<scalarRange>(0) 00042 { 00043 DynamicList<scalarRange> lst; 00044 00045 while (is.good()) 00046 { 00047 scalarRange sr(is); 00048 if (sr.isDefined()) 00049 { 00050 lst.append(sr); 00051 } 00052 } 00053 00054 transfer(lst); 00055 } 00056 00057 00058 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // 00059 00060 bool Foam::scalarRanges::selected(const scalar& value) const 00061 { 00062 forAll(*this, i) 00063 { 00064 if (operator[](i).selected(value)) 00065 { 00066 return true; 00067 } 00068 } 00069 00070 return false; 00071 } 00072 00073 00074 Foam::List<bool> Foam::scalarRanges::selected 00075 ( 00076 const List<scalar>& values 00077 ) const 00078 { 00079 List<bool> lst(values.size(), false); 00080 00081 // check ranges 00082 forAll(values, i) 00083 { 00084 if (selected(values[i])) 00085 { 00086 lst[i] = true; 00087 } 00088 } 00089 00090 // check specific values 00091 forAll(*this, rangeI) 00092 { 00093 if (operator[](rangeI).isExact()) 00094 { 00095 scalar target = operator[](rangeI).value(); 00096 00097 int nearestIndex = -1; 00098 scalar nearestDiff = Foam::GREAT; 00099 00100 forAll(values, timeIndex) 00101 { 00102 scalar diff = fabs(values[timeIndex] - target); 00103 if (diff < nearestDiff) 00104 { 00105 nearestDiff = diff; 00106 nearestIndex = timeIndex; 00107 } 00108 } 00109 00110 if (nearestIndex >= 0) 00111 { 00112 lst[nearestIndex] = true; 00113 } 00114 } 00115 } 00116 00117 return lst; 00118 } 00119 00120 00121 Foam::List<Foam::scalar> Foam::scalarRanges::select 00122 ( 00123 const List<scalar>& values 00124 ) const 00125 { 00126 return subset(selected(values), values); 00127 } 00128 00129 00130 void Foam::scalarRanges::inplaceSelect 00131 ( 00132 List<scalar>& values 00133 ) const 00134 { 00135 inplaceSubset(selected(values), values); 00136 } 00137 00138 00139 // ************************************************************************* // |