IFEM  90A354
Chebyshev.h
Go to the documentation of this file.
1 // $Id$
2 //==============================================================================
12 //==============================================================================
13 
14 #ifndef _CHEBYSHEV_H
15 #define _CHEBYSHEV_H
16 
17 #include "Function.h"
18 #include "TensorFunction.h"
19 
20 #include <array>
21 #include <functional>
22 #include <memory>
23 
24 
29 namespace Chebyshev
30 {
34  Real evalPol1(int polnum, Real xi);
38  Real evalPol2(int polnum, Real xi);
39 
43  Real evalDer1(int polnum, Real xi);
47  Real evalDer2(int polnum, Real xi);
48 
52  Real eval2Der1(int polnum, Real xi);
53 }
54 
55 
60 class ChebyshevFunc : public RealFunc
61 {
62  std::vector<Real> coefs;
63  std::array<int,3> n;
64  std::array<std::array<double,2>,3> domain;
65 
66 public:
70  ChebyshevFunc(const std::string& input, bool file);
71 
73  bool isZero() const override { return coefs.empty(); }
74 
76  const std::vector<Real>& getCoefs() const { return coefs; }
78  const std::array<int,3>& getSize() const { return n; }
79 
81  Real deriv(const Vec3& X, int c) const override;
82 
84  Real dderiv(const Vec3& X, int c, int c2) const override;
85 
86 protected:
88  Real evaluate(const Vec3& X) const override;
89 
90 private:
92  struct Func
93  {
94  std::function<Real(int, Real)> f;
95  double w;
96  };
97 
99  Real evaluateTP (const Vec3& X, const std::array<Func,3>& funcs) const;
100 
103  void read(std::istream& in);
104 };
105 
106 
111 class ChebyshevVecFunc : public VecFunc
112 {
113  std::array<std::unique_ptr<ChebyshevFunc>,3> f;
114 
115 public:
119  ChebyshevVecFunc(const std::vector<std::string>& input, bool file);
120 
122  bool isZero() const override { return !f[0] || f[0]->isZero(); }
123 
124 protected:
126  Vec3 evaluate(const Vec3& X) const override;
128  std::vector<Real> evalGradient(const Vec3&) const override;
130  std::vector<Real> evalHessian(const Vec3& X) const override;
131 };
132 
133 
139 {
140  std::vector<std::unique_ptr<ChebyshevFunc>> f;
141 
142 public:
146  ChebyshevTensorFunc(const std::vector<std::string>& input, bool file);
147 
149  bool isZero() const override { return f.empty(); }
150 
151 protected:
153  Tensor evaluate(const Vec3& X) const override;
155  std::vector<Real> evalGradient(const Vec3&) const override;
157  std::vector<Real> evalHessian(const Vec3&) const override;
158 };
159 
160 #endif
General functions with arbitrary argument and value type.
#define Real
The floating point type to use.
Definition: ImmersedBoundaries.h:18
Spatial tensor-valued functions.
A scalar-valued spatial function, chebyshev polynomials.
Definition: Chebyshev.h:61
Real evaluateTP(const Vec3 &X, const std::array< Func, 3 > &funcs) const
Performs the actual tensor-product evaluation.
Definition: Chebyshev.C:109
void read(std::istream &in)
Reads input from a stream.
Definition: Chebyshev.C:89
std::vector< Real > coefs
Function coefficients.
Definition: Chebyshev.h:62
const std::vector< Real > & getCoefs() const
Returns a const reference to the coefficients.
Definition: Chebyshev.h:76
std::array< int, 3 > n
Number of coefficients.
Definition: Chebyshev.h:63
std::array< std::array< double, 2 >, 3 > domain
Physical domain.
Definition: Chebyshev.h:64
bool isZero() const override
Returns whether the function is identically zero or not.
Definition: Chebyshev.h:73
Real deriv(const Vec3 &X, int c) const override
Returns a first-derivative of the function.
Definition: Chebyshev.C:139
Real dderiv(const Vec3 &X, int c, int c2) const override
Returns a second-derivative of the function.
Definition: Chebyshev.C:153
Real evaluate(const Vec3 &X) const override
Evaluates the function at point X.
Definition: Chebyshev.C:102
ChebyshevFunc(const std::string &input, bool file)
The constructor initializes the function parameters from a file.
Definition: Chebyshev.C:73
const std::array< int, 3 > & getSize() const
Returns the number of polynomials in each parameter direction.
Definition: Chebyshev.h:78
A tensor-valued spatial function, chebyshev polynomials.
Definition: Chebyshev.h:139
std::vector< std::unique_ptr< ChebyshevFunc > > f
Vector of components.
Definition: Chebyshev.h:140
std::vector< Real > evalGradient(const Vec3 &) const override
Returns the gradient of the function as a 1D array.
Definition: Chebyshev.C:239
ChebyshevTensorFunc(const std::vector< std::string > &input, bool file)
The constructor initializes the function parameters from files.
Definition: Chebyshev.C:216
std::vector< Real > evalHessian(const Vec3 &) const override
Returns the hessian of the function as a 1D array.
Definition: Chebyshev.C:252
Tensor evaluate(const Vec3 &X) const override
Evaluates the function at point X.
Definition: Chebyshev.C:226
bool isZero() const override
Returns whether the function is identically zero or not.
Definition: Chebyshev.h:149
A vector-valued spatial function, chebyshev polynomials.
Definition: Chebyshev.h:112
bool isZero() const override
Returns whether the function is identically zero or not.
Definition: Chebyshev.h:122
std::array< std::unique_ptr< ChebyshevFunc >, 3 > f
Functions.
Definition: Chebyshev.h:113
Vec3 evaluate(const Vec3 &X) const override
Evaluates the function at point X.
Definition: Chebyshev.C:185
std::vector< Real > evalGradient(const Vec3 &) const override
Returns the gradient of the function as a 1D array.
Definition: Chebyshev.C:191
ChebyshevVecFunc(const std::vector< std::string > &input, bool file)
The constructor initializes the function parameters from files.
Definition: Chebyshev.C:175
std::vector< Real > evalHessian(const Vec3 &X) const override
Returns the hessian of the function as a 1D array.
Definition: Chebyshev.C:203
Scalar-valued unary function of a spatial point.
Definition: Function.h:193
Tensor-valued unary function of a spatial point.
Definition: TensorFunction.h:27
Simple class for representing a non-symmetric second-order tensor.
Definition: Tensor.h:28
Simple class for representing a point in 3D space.
Definition: Vec3.h:27
Vector-valued unary function of a spatial point.
Definition: Function.h:242
Evaluation of Chebyshev polynomials.
Definition: Chebyshev.h:30
Real evalDer2(int polnum, Real xi)
Evaluates the first derivative of a 1D Chebyshev polynomial of second kind.
Definition: Chebyshev.C:53
Real evalDer1(int polnum, Real xi)
Evaluates the first derivative of a 1D Chebyshev polynomial of first kind.
Definition: Chebyshev.C:44
Real evalPol2(int polnum, Real xi)
Evaluates a 1D Chebyshev polynomial of second kind.
Definition: Chebyshev.C:33
Real evalPol1(int polnum, Real xi)
Evaluates a 1D Chebyshev polynomial of first kind.
Definition: Chebyshev.C:22
Real eval2Der1(int polnum, Real xi)
Evaluates the second derivative of a 1D Chebyshev polynomial of first kind.
Definition: Chebyshev.C:59
Struct defining function and weight in one direction.
Definition: Chebyshev.h:93
std::function< Real(int, Real)> f
Function to evaluate.
Definition: Chebyshev.h:94
double w
Weight.
Definition: Chebyshev.h:95