ABLATE Source Documentation  0.12.33
linearFunction.hpp
1 #ifndef ABLATELIBRARY_LINEARFUNCTION_FUNCTION_HPP
2 #define ABLATELIBRARY_LINEARFUNCTION_FUNCTION_HPP
3 #include <muParser.h>
4 #include "formulaBase.hpp"
5 
6 namespace ablate::mathFunctions {
11 class LinearFunction : public MathFunction {
12  private:
13  std::shared_ptr<MathFunction> startFunction;
14  std::shared_ptr<MathFunction> endFunction;
15  const double start;
16  const double end;
17  const int dir;
18 
19  static PetscErrorCode LinearFunctionPetscFunction(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nf, PetscScalar* u, void* ctx);
20 
30  inline static double Interpolate(double x, double x0, double x1, double y0, double y1) {
31  if (x < x0) {
32  return y0;
33  } else if (x > x1) {
34  return y1;
35  }
36 
37  return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
38  }
39 
49  inline double DetermineDirectionValue(double x, double y, double z) const {
50  switch (dir) {
51  case 0:
52  return x;
53  case 1:
54  return y;
55  case 2:
56  return z;
57  default:
58  return x;
59  }
60  }
61 
62  public:
63  LinearFunction(const LinearFunction&) = delete;
64  void operator=(const LinearFunction&) = delete;
65 
74  explicit LinearFunction(std::shared_ptr<MathFunction> startFunction, std::shared_ptr<MathFunction> endFunction, double start, double end, int dir);
75 
76  double Eval(const double& x, const double& y, const double& z, const double& t) const override;
77 
78  double Eval(const double* xyz, const int& ndims, const double& t) const override;
79 
80  void Eval(const double& x, const double& y, const double& z, const double& t, std::vector<double>& result) const override;
81 
82  void Eval(const double* xyz, const int& ndims, const double& t, std::vector<double>& result) const override;
83 
84  void* GetContext() override { return this; }
85 
86  PetscFunction GetPetscFunction() override { return LinearFunctionPetscFunction; }
87 };
88 } // namespace ablate::mathFunctions
89 
90 #endif // ABLATELIBRARY_SIMPLEFORMULA_HPP
Definition: linearFunction.hpp:11
double Eval(const double &x, const double &y, const double &z, const double &t) const override
Definition: linearFunction.cpp:10
void * GetContext() override
Definition: linearFunction.hpp:84
PetscFunction GetPetscFunction() override
Definition: linearFunction.hpp:86
Definition: mathFunction.hpp:13