From cac5e6ff5d72a35c245e30817b37d5eed42cac1c Mon Sep 17 00:00:00 2001 From: Christian Sendlinger Date: Fri, 10 May 2024 14:21:07 +0200 Subject: [PATCH] added exponential into predefined functions --- include/functions/functions.h | 2 ++ src/functions/functions.cpp | 4 ++++ src/generators/function_generator.cpp | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/include/functions/functions.h b/include/functions/functions.h index 5022eb4..977542a 100755 --- a/include/functions/functions.h +++ b/include/functions/functions.h @@ -12,6 +12,8 @@ std::function Constant(double constant); std::function Product( std::vector> functions); + +std::function Exponential(double prefactor, double scale); }; // namespace D1ToD1 namespace D3ToD1 { diff --git a/src/functions/functions.cpp b/src/functions/functions.cpp index 4a16d06..08d2791 100755 --- a/src/functions/functions.cpp +++ b/src/functions/functions.cpp @@ -55,6 +55,10 @@ std::function Product( return product; }; } + +std::function Exponential(double prefactor, double scale) { + return [=](double x) { return prefactor * std::exp(scale * x); }; +} }; // namespace D1ToD1 namespace D3ToD1 { diff --git a/src/generators/function_generator.cpp b/src/generators/function_generator.cpp index 3c893f2..b9c494f 100755 --- a/src/generators/function_generator.cpp +++ b/src/generators/function_generator.cpp @@ -71,6 +71,13 @@ std::function function1D(json_t* object) { } return D1ToD1::Product(functions); + } else if (json_object_by_path(object, {"Exponential"})) { + DEBUG_LEVEL_2("Creating function1d: Exponential."); + double prefactor = json_double(json_object_by_path( + object, {"Exponential", {"prefactor"}})); + double scale = json_double(json_object_by_path( + object, {"Exponential", {"scale"}})); + return D1ToD1::Exponential(prefactor, scale); } else { ERROR("This 1d to 1d function is not implemented."); return nullptr;