-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTest_Chebyshev_1D.cpp
88 lines (70 loc) · 3.26 KB
/
Test_Chebyshev_1D.cpp
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
78
79
80
81
82
83
84
85
86
87
88
//
// Test_Chebyshev_1D.cpp
//
//
// Created by Sivaram Ambikasaran on 1/17/14.
//
//
#include <iostream>
#include <cstdlib>
#include "Chebyshev_Interpolation_1D.hpp"
#include "Eigen/Dense"
using namespace std;
using namespace Eigen;
void get_Points(double center, double radius, unsigned N, double*& x) {
x = new double[N];
double RAND = RAND_MAX;
for (unsigned k=0; k<N; ++k) {
x[k] = center + radius*(2*double(rand())/RAND-1);
}
}
int main() {
srand(time(NULL));
// Obtain the points in both the clusters.
unsigned n1 = 5000;
unsigned n2 = 5000;
double* x1;
double* x2;
double center1 = -1;
double center2 = +1;
double radius1 = 0.5;
double radius2 = 0.5;
get_Points(center1, radius1, n1, x1);
get_Points(center2, radius2, n2, x2);
// Obtain the exact interaction between the two clusters.
double* Kexact;
kernel1D(x1, n1, x2, n2, Kexact);
// Obtain the standard Chebyshev nodes.
double* Cheb_Nodes;
unsigned rank = 20;
get_standard_Chebyshev_nodes(rank, Cheb_Nodes);
// Obtain the scaled Chebyshev nodes for the first cluster.
double* x1_Cheb_Nodes;
scale_Points(0, 1, Cheb_Nodes, rank, center1, radius1, x1_Cheb_Nodes);
// Obtain the scaled Chebyshev nodes for the second cluster.
double* x2_Cheb_Nodes;
scale_Points(0, 1, Cheb_Nodes, rank, center2, radius2, x2_Cheb_Nodes);
// Obtain the standard location for points in the first cluster.
double* x1_Standard_Location;
scale_Points(center1, radius1, x1, n1, 0, 1, x1_Standard_Location);
// Obtain the standard location for points in the second cluster.
double* x2_Standard_Location;
scale_Points(center2, radius2, x2, n2, 0, 1, x2_Standard_Location);
// Obtain L2L for first cluster
double* L2L1;
get_Chebyshev_L2L_Operator(x1_Standard_Location, n1, Cheb_Nodes, rank, L2L1);
// Obtain L2L for second cluster
double* L2L2;
get_Chebyshev_L2L_Operator(x2_Standard_Location, n2, Cheb_Nodes, rank, L2L2);
// Obtain M2L
double* M2L;
kernel1D(x1_Cheb_Nodes, rank, x2_Cheb_Nodes, rank, M2L);
Map<Matrix<double,Dynamic,Dynamic,RowMajor> > Kexact_E(Kexact, n1, n2);
Map<Matrix<double,Dynamic,Dynamic,RowMajor> > L2L1_E(L2L1, n1, rank);
Map<Matrix<double,Dynamic,Dynamic,RowMajor> > L2L2_E(L2L2, n2, rank);
Map<Matrix<double,Dynamic,Dynamic,RowMajor> > M2L_E(M2L, rank, rank);
cout << endl << "Number of points in the first cluster centered at " << center1 << " of length " << 2*radius1 << " is: " << n1 << endl;
cout << endl << "Number of points in the second cluster centered at " << center2 << " of length " << 2*radius2 << " is: " << n2 << endl;
cout << endl << "Rank of interaction considered is: " << rank << endl;
cout << endl << "Maximum error in the low-rank interaction between the two cluster is: " << (Kexact_E-L2L1_E*M2L_E*L2L2_E.transpose()).cwiseAbs().maxCoeff() << endl;
}