diff --git a/functions.cpp b/functions.cpp index 0ebaf31..0964371 100644 --- a/functions.cpp +++ b/functions.cpp @@ -1,51 +1,50 @@ // // Created by lionel on 11.12.19. // #include "functions.h" double mylinear(double t){ return t; } double myzero(double t){ return 0; } -/// Assign a function type object to an integer as input + FunctionType RHSFunctionFactory::parseType(int functionNumber) { switch (functionNumber){ case 0 : return Zero; case 1 : return Linear; case 2 : return Cosine; default: - throw std::invalid_argument("Could not comprehend the function of input"); + throw std::invalid_argument("Could not comprehend the function of input."); } } -/// Construct the g function of the right hand side, as having a list of numbers that specify which function in each dim + std::function RHSFunctionFactory::constructTimeDependantFunction(Eigen::VectorXd & list) { - int d = list.size(); + int d = list.size(); // gets the dimension of the output return [d, list](double t) { - Eigen::VectorXd result(d); - for (int i = 0; i < d; ++i) { + Eigen::VectorXd result(d); // set the output + for (int i = 0; i < d; ++i) { // each dimension has to get another function result[i] = getFunction(parseType((int)list[i]))(t); } return result; }; } -/// adapter, that converts a FunctionType object to the function double (* RHSFunctionFactory::getFunction(FunctionType f))(double t){ switch (f){ case Linear: return mylinear; case Cosine: return cos; case Zero: return myzero; default : - throw std::exception(); + throw std::invalid_argument("Function type was not implemented."); } } diff --git a/functions.h b/functions.h index 132c04d..b8f360c 100644 --- a/functions.h +++ b/functions.h @@ -1,31 +1,32 @@ // // Created by lionel on 11.12.19. // #ifndef PSCSPROJECT_FUNCTIONS_H #define PSCSPROJECT_FUNCTIONS_H #include #include #include - +/// Symbolic variable for the different function implemented enum FunctionType{Linear, Cosine, Zero}; /** * Class for creating functions from a list of inputs * It creates functions in a format that is usable by ODElibrary */ class RHSFunctionFactory{ private: /// Parser that change the input from number to a FunctionType variable static FunctionType parseType(int functionNumber); /// Get a function object that creates a function element from the specified function type static double (* getFunction(FunctionType f))(double t); public: - std::function constructTimeDependantFunction(Eigen::VectorXd & list); + /// Construct the g function of the RHS, as having a list of numbers specifying the function of each dim + static std::function constructTimeDependantFunction(Eigen::VectorXd & list); }; #endif //PSCSPROJECT_FUNCTIONS_H