|
Palabos
Version 1.0
|
00001 /* This file is part of the Palabos library. 00002 * 00003 * Copyright (C) 2011 FlowKit Sarl 00004 * Avenue de Chailly 23 00005 * 1012 Lausanne, Switzerland 00006 * E-mail contact: contact@flowkit.com 00007 * 00008 * The most recent release of Palabos can be downloaded at 00009 * <http://www.palabos.org/> 00010 * 00011 * The library Palabos is free software: you can redistribute it and/or 00012 * modify it under the terms of the GNU Affero General Public License as 00013 * published by the Free Software Foundation, either version 3 of the 00014 * License, or (at your option) any later version. 00015 * 00016 * The library is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Affero General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Affero General Public License 00022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00023 */ 00024 00025 #ifndef BENCHMARK_UTIL_H 00026 #define BENCHMARK_UTIL_H 00027 00028 #include "core/globalDefs.h" 00029 #include <deque> 00030 00031 namespace plb { 00032 00033 namespace util { 00034 00036 00043 template<typename T> 00044 class ValueTracer { 00045 public: 00047 00053 ValueTracer(T u, T L, T epsilon); 00055 void resetScale(T u, T L); 00057 void resetValues(); 00059 plint getDeltaT() const; 00061 void takeValue(T val, bool doPrint=false); 00063 bool hasConverged() const; 00065 bool hasConvergedMinMax() const; 00066 T computeAverage() const; 00067 T computeStdDev(T average) const; 00068 void setEpsilon(T epsilon_); 00069 private: 00070 plint deltaT; 00071 T epsilon; 00072 plint t; 00073 bool converged; 00074 std::deque<T> values; 00075 }; 00076 00078 00082 template<typename T> 00083 class BisectStepper { 00084 public: 00086 00090 BisectStepper(T _iniVal, T _step=0.); 00092 T getVal(bool stable, bool doPrint=false); 00094 bool hasConverged(T epsilon) const; 00095 private: 00096 T iniVal, currentVal, lowerVal, upperVal; 00097 T step; 00098 enum {first, up, down, bisect} state; 00099 }; 00100 00101 } // namespace util 00102 00103 } // namespace plb 00104 00105 #endif