From de8c4e1b86705bc85ca2832b8faa68bfa20a7726 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Fri, 1 Aug 2014 14:15:55 +0200 Subject: [PATCH] Added linspace function Signed-off-by: Ian Bell --- include/CoolPropTools.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/CoolPropTools.h b/include/CoolPropTools.h index 2cc281ae..b4969876 100644 --- a/include/CoolPropTools.h +++ b/include/CoolPropTools.h @@ -242,8 +242,7 @@ if (double_vectors.find(s) != double_vectors.end()){ return double_vectors[s]; } else{ throw std::exception(); } }; }; - - /// Utility function for a std::map of pointers + /// Utility function to clear a std::map of pointers //http://stackoverflow.com/questions/569110/why-is-memory-still-accessible-after-stdmapclear-is-called template void freeClear( M & amap ) { for ( typename M::iterator it = amap.begin(); it != amap.end(); ++it ) { @@ -252,6 +251,16 @@ amap.clear(); } + /// Make a linearly spaced vector of points + template std::vector linspace(T xmin, T xmax, int n) { + std::vector x(n, 0.0); + + for ( std::size_t i = 0; i < n; ++i) { + x[i] = (xmax-xmin)/(n-1)*i+xmin; + } + return x; + } + /// Some functions related to testing and comparison of values bool inline check_abs(double A, double B, double D){ double max = fabs(A);