-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtsgRuleGaussLegendre.hpp
77 lines (57 loc) · 2.57 KB
/
tsgRuleGaussLegendre.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Code Author: Miroslav Stoyanov, Mar 2013
*
* Copyright (C) 2013 Miroslav Stoyanov
*
* This file is part of
* Toolkit for Adaprive Stochastic Modeling And Non-Intrusive Approximation
* a.k.a. TASMANIAN
*
* TASMANIAN is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TASMANIAN is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TASMANIAN. If not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef __TASMANIAN_SPARSE_GRID_RULE_GL_HPP
#define __TASMANIAN_SPARSE_GRID_RULE_GL_HPP
#include "tsgHardcodedConstants.hpp"
#include "tsgBase1DRule.hpp"
#include "math.h"
#include <iostream>
namespace TasGrid{
class RuleGaussLegendre : public OneDRule{
public:
RuleGaussLegendre( const int max_level );
~RuleGaussLegendre();
int getMaxLevel() const;
int getNumPoints( int level ) const;
int getBasisLevel( int level ) const;
void getPoints( int level, int* &pnts ) const;
const char * getDescription() const;
double getX( int point ) const;
double getWeight( int level, int point ) const;
double eval( int level, int point, double x ) const;
TypeOneDRule getType() const;
void buildOneLevel( int level, double* &w, double* &x ); // this is cheating to let RulePWLocal use the Gauss-Legendre rules of only one fixed level
protected:
void evalPdP( int n, double x, double &p, double &dp ) const; // evaluates the n-th order Legendre polynomial at x, returns the value p and its derivative dp
void findOnePoint( int n, double &x, double &w ) const; // using Neuton's mehtod, converge to a point and compute its weight (n is the other of the Legendre polynomial)
private:
int max_level;
int *levels; // gives the cumulative offset of each level
int *level_points; // gives a list of the points associated with each level
double *weights; // contains the weight associated with each level
double *nodes; // contains the x-coordinate of each sample point
const double tol; // needed to compare points, if points are within tol of each other, assume they are the same point
};
};
#endif