Mimetic Operators Library Enhanced
4.0
Loading...
Searching...
No Matches
interpol.cpp
Go to the documentation of this file.
1
#include "
interpol.h
"
2
3
// 1-D Constructor
4
Interpol::Interpol
(u32 m,
Real
c) : sp_mat(m+1, m+2)
5
{
6
assert(m >= 4);
7
assert(c >= 0 && c <= 1);
8
9
at(0, 0) = 1;
10
at(m, m+1) = 1;
11
12
for
(u32 i = 1; i < m; i++) {
13
at(i, i) = c;
14
at(i, i+1) = 1-c;
15
}
16
}
17
18
// 2-D Constructor
19
Interpol::Interpol
(u32 m, u32 n,
Real
c1,
Real
c2)
20
{
21
Interpol
Ix(m, c1);
22
Interpol
Iy(n, c2);
23
24
sp_mat Im = speye(m+2, m+2);
25
sp_mat In = speye(n+2, n+2);
26
27
Im.shed_row(0);
28
Im.shed_row(m);
29
In.shed_row(0);
30
In.shed_row(n);
31
32
sp_mat I1 =
Utils::spkron
(In, Ix);
33
sp_mat I2 =
Utils::spkron
(Iy, Im);
34
35
// Dimensions = 2*m*n+m+n, (m+2)*(n+2)
36
if
(m != n)
37
*
this
=
Utils::spjoin_cols
(I1, I2);
38
else
{
39
sp_mat A1(2, 1);
40
sp_mat A2(2, 1);
41
A1(0, 0) = A2(1, 0) = 1.0;
42
*
this
=
Utils::spkron
(A1, I1) +
Utils::spkron
(A2, I2);
43
}
44
}
45
46
// 3-D Constructor
47
Interpol::Interpol
(u32 m, u32 n, u32 o,
Real
c1,
Real
c2,
Real
c3)
48
{
49
Interpol
Ix(m, c1);
50
Interpol
Iy(n, c2);
51
Interpol
Iz(o, c3);
52
53
sp_mat Im = speye(m+2, m+2);
54
sp_mat In = speye(n+2, n+2);
55
sp_mat Io = speye(o+2, o+2);
56
57
Im.shed_row(0);
58
Im.shed_row(m);
59
In.shed_row(0);
60
In.shed_row(n);
61
Io.shed_row(0);
62
Io.shed_row(o);
63
64
sp_mat I1 =
Utils::spkron
(
Utils::spkron
(Io, In), Ix);
65
sp_mat I2 =
Utils::spkron
(
Utils::spkron
(Io, Iy), Im);
66
sp_mat I3 =
Utils::spkron
(
Utils::spkron
(Iz, In), Im);
67
68
// Dimensions = 3*m*n*o+m*n+m*o+n*o, (m+2)*(n+2)*(o+2)
69
if
((m != n) || (n != o))
70
*
this
=
Utils::spjoin_cols
(
Utils::spjoin_cols
(I1, I2), I3);
71
else
{
72
sp_mat A1(3, 1);
73
sp_mat A2(3, 1);
74
sp_mat A3(3, 1);
75
A1(0, 0) = A2(1, 0) = A3(2, 0) = 1.0;
76
*
this
=
Utils::spkron
(A1, I1) +
Utils::spkron
(A2, I2) +
Utils::spkron
(A3, I3);
77
}
78
}
79
80
// 1-D Constructor for second type
81
Interpol::Interpol
(
bool
type, u32 m,
Real
c) : sp_mat(m+2, m+1)
82
{
83
assert(m >= 4 &&
"m >= 4"
);
84
assert(c >= 0 && c <= 1 &&
"0 <= c <= 1"
);
85
86
at(0, 0) = 1;
87
at(m+2 - 1, m+1 - 1) = 1;
88
89
vec avg = {c, 1 - c};
90
91
int
j = 0;
92
for
(
int
i = 1; i < m+1; ++i) {
93
at(i, j) = avg(0);
94
at(i, j + 1) = avg(1);
95
j++;
96
}
97
}
98
99
// 2-D Constructor for second type
100
Interpol::Interpol
(
bool
type, u32 m, u32 n,
Real
c1,
Real
c2)
101
{
102
Interpol
Ix(
true
, m, c1);
103
Interpol
Iy(
true
, n, c2);
104
105
sp_mat Im(m + 2, m);
106
Im.submat(1, 0, m, m-1) = speye(m, m);
107
108
sp_mat In(n + 2, n);
109
In.submat(1, 0, n, n-1) = speye(n, n);
110
111
sp_mat Sx =
Utils::spkron
(In, Ix);
112
sp_mat Sy =
Utils::spkron
(Iy, Im);
113
114
*
this
=
Utils::spjoin_rows
(Sx, Sy);
115
}
116
117
// 3-D Constructor for second type
118
Interpol::Interpol
(
bool
type, u32 m, u32 n, u32 o,
Real
c1,
Real
c2,
Real
c3)
119
{
120
Interpol
Ix(
true
, m, c1);
121
Interpol
Iy(
true
, n, c2);
122
Interpol
Iz(
true
, o, c3);
123
124
sp_mat Im(m + 2, m);
125
Im.submat(1, 0, m, m-1) = speye(m, m);
126
127
sp_mat In(n + 2, n);
128
In.submat(1, 0, n, n-1) = speye(n, n);
129
130
sp_mat Io(o + 2, o);
131
Io.submat(1, 0, o, o-1) = speye(o, o);
132
133
sp_mat Sx =
Utils::spkron
(
Utils::spkron
(Io, In), Ix);
134
sp_mat Sy =
Utils::spkron
(
Utils::spkron
(Io, Iy), Im);
135
sp_mat Sz =
Utils::spkron
(
Utils::spkron
(Iz, In), Im);
136
137
*
this
=
Utils::spjoin_rows
(
Utils::spjoin_rows
(Sx, Sy), Sz);
138
}
Interpol
Definition
interpol.h:8
Interpol::Interpol
Interpol(u32 m, Real c)
Definition
interpol.cpp:4
Utils::spjoin_cols
static sp_mat spjoin_cols(const sp_mat &A, const sp_mat &B)
Definition
utils.cpp:120
Utils::spjoin_rows
static sp_mat spjoin_rows(const sp_mat &A, const sp_mat &B)
Definition
utils.cpp:85
Utils::spkron
static sp_mat spkron(const sp_mat &A, const sp_mat &B)
Definition
utils.cpp:53
interpol.h
Real
double Real
Definition
utils.h:8
mole_C++
interpol.cpp
Generated by
1.10.0