ABLATE Source Documentation  0.12.34
linear.hpp
1 #ifndef ABLATELIBRARY_LINEAR_FUNCTION_HPP
2 #define ABLATELIBRARY_LINEAR_FUNCTION_HPP
3 #include <muParser.h>
4 #include "formulaBase.hpp"
5 
6 namespace ablate::mathFunctions {
11 class Linear : public MathFunction {
12  private:
13  const std::vector<double> startValue;
14  const std::vector<double> endValue;
15  const double start;
16  const double end;
17  const int dir;
18 
19  static PetscErrorCode LinearPetscFunction(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  Linear(const Linear&) = delete;
64  void operator=(const Linear&) = delete;
65 
74  explicit Linear(std::vector<double> startValue, std::vector<double> endValue, 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 LinearPetscFunction; }
87 };
88 } // namespace ablate::mathFunctions
89 
90 #endif // ABLATELIBRARY_SIMPLEFORMULA_HPP
Definition: linear.hpp:11
void * GetContext() override
Definition: linear.hpp:84
PetscFunction GetPetscFunction() override
Definition: linear.hpp:86
double Eval(const double &x, const double &y, const double &z, const double &t) const override
Definition: linear.cpp:18
Definition: mathFunction.hpp:13