Page MenuHomec4science

functions.cpp
No OneTemporary

File Metadata

Created
Thu, Jun 6, 08:08

functions.cpp

//
// Created by lionel on 11.12.19.
//
#include "functions.h"
double mylinear(double t){
return t;
}
double myzero(double t){
return 0;
}
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.");
}
}
std::function<Eigen::VectorXd(double)> RHSFunctionFactory::constructTimeDependantFunction(Eigen::VectorXd & list) {
int d = list.size(); // gets the dimension of the output
return [d, list](double t) {
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;
};
}
double (* RHSFunctionFactory::getFunction(FunctionType f))(double t){
switch (f){
case Linear:
return mylinear;
case Cosine:
return cos;
case Zero:
return myzero;
default :
throw std::invalid_argument("Function type was not implemented.");
}
}

Event Timeline