From 75ea2f36a898dd09d8b68fd53ce9378cd16dc2fc Mon Sep 17 00:00:00 2001 From: Cristian C Lalescu <Cristian.Lalescu@ds.mpg.de> Date: Tue, 23 Jun 2020 07:33:52 +0200 Subject: [PATCH] add class to hold numeric spectrum for subsequent use --- CMakeLists.txt | 1 + cpp/spectrum_function.hpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 cpp/spectrum_function.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e4699ff..11a4862b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -392,6 +392,7 @@ set(hpp_for_lib ${PROJECT_SOURCE_DIR}/cpp/omputils.hpp ${PROJECT_SOURCE_DIR}/cpp/shared_array.hpp ${PROJECT_SOURCE_DIR}/cpp/spline.hpp + ${PROJECT_SOURCE_DIR}/cpp/spectrum_function.hpp ${PROJECT_SOURCE_DIR}/cpp/full_code/ornstein_uhlenbeck_process.hpp ${PROJECT_SOURCE_DIR}/cpp/full_code/ou_vorticity_equation.hpp ) diff --git a/cpp/spectrum_function.hpp b/cpp/spectrum_function.hpp new file mode 100644 index 00000000..ae33f860 --- /dev/null +++ b/cpp/spectrum_function.hpp @@ -0,0 +1,32 @@ +#include<cmath> +#include<vector> + +#include "kspace.hpp" + +template <field_backend be, + kspace_dealias type dt> +class spectrum_function +{ + private: + const kspace<be, dt> *kk; + const std::vector<double> values; + + public: + spectrum_function( + const kspace<be, dt> *KK, + const std::vector &source_values): + kk(KK), + values(source_values) + { + assert(this->values.size() == this->kk->nshells); + } + ~spectrum_function(){} + + double operator()(double kvalue) + { + assert(kvalue >= double(0)); + int index = floor(kvalue / this->kk->dk); + assert(index < this->values.size()); + return this->values[index]; + } +} -- GitLab