Mimetic Operators Library Enhanced
4.0
Loading...
Searching...
No Matches
interpol.cpp
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: GPL-3.0-or-later
3
* © 2008-2024 San Diego State University Research Foundation (SDSURF).
4
* See LICENSE file or https://www.gnu.org/licenses/gpl-3.0.html for details.
5
*/
6
7
/*
8
* @file interpol.cpp
9
*
10
* @brief Mimetic Interpolators
11
*
12
* @date 2024/10/15
13
*
14
*/
15
16
#include "
interpol.h
"
17
18
// 1-D Constructor
19
Interpol::Interpol
(u32 m,
Real
c) : sp_mat(m + 1, m + 2) {
20
assert(m >= 4);
21
assert(c >= 0 && c <= 1);
22
23
at(0, 0) = 1;
24
at(m, m + 1) = 1;
25
26
for
(u32 i = 1; i < m; i++) {
27
at(i, i) = c;
28
at(i, i + 1) = 1 - c;
29
}
30
}
31
32
// 2-D Constructor
33
Interpol::Interpol
(u32 m, u32 n,
Real
c1,
Real
c2) {
34
Interpol
Ix(m, c1);
35
Interpol
Iy(n, c2);
36
37
sp_mat Im = speye(m + 2, m + 2);
38
sp_mat In = speye(n + 2, n + 2);
39
40
Im.shed_row(0);
41
Im.shed_row(m);
42
In.shed_row(0);
43
In.shed_row(n);
44
45
sp_mat I1 =
Utils::spkron
(In, Ix);
46
sp_mat I2 =
Utils::spkron
(Iy, Im);
47
48
// Dimensions = 2*m*n+m+n, (m+2)*(n+2)
49
if
(m != n)
50
*
this
=
Utils::spjoin_cols
(I1, I2);
51
else
{
52
sp_mat A1(2, 1);
53
sp_mat A2(2, 1);
54
A1(0, 0) = A2(1, 0) = 1.0;
55
*
this
=
Utils::spkron
(A1, I1) +
Utils::spkron
(A2, I2);
56
}
57
}
58
59
// 3-D Constructor
60
Interpol::Interpol
(u32 m, u32 n, u32 o,
Real
c1,
Real
c2,
Real
c3) {
61
Interpol
Ix(m, c1);
62
Interpol
Iy(n, c2);
63
Interpol
Iz(o, c3);
64
65
sp_mat Im = speye(m + 2, m + 2);
66
sp_mat In = speye(n + 2, n + 2);
67
sp_mat Io = speye(o + 2, o + 2);
68
69
Im.shed_row(0);
70
Im.shed_row(m);
71
In.shed_row(0);
72
In.shed_row(n);
73
Io.shed_row(0);
74
Io.shed_row(o);
75
76
sp_mat I1 =
Utils::spkron
(
Utils::spkron
(Io, In), Ix);
77
sp_mat I2 =
Utils::spkron
(
Utils::spkron
(Io, Iy), Im);
78
sp_mat I3 =
Utils::spkron
(
Utils::spkron
(Iz, In), Im);
79
80
// Dimensions = 3*m*n*o+m*n+m*o+n*o, (m+2)*(n+2)*(o+2)
81
if
((m != n) || (n != o))
82
*
this
=
Utils::spjoin_cols
(
Utils::spjoin_cols
(I1, I2), I3);
83
else
{
84
sp_mat A1(3, 1);
85
sp_mat A2(3, 1);
86
sp_mat A3(3, 1);
87
A1(0, 0) = A2(1, 0) = A3(2, 0) = 1.0;
88
*
this
=
89
Utils::spkron
(A1, I1) +
Utils::spkron
(A2, I2) +
Utils::spkron
(A3, I3);
90
}
91
}
92
93
// 1-D Constructor for second type
94
Interpol::Interpol
(
bool
type, u32 m,
Real
c) : sp_mat(m + 2, m + 1) {
95
assert(m >= 4 &&
"m >= 4"
);
96
assert(c >= 0 && c <= 1 &&
"0 <= c <= 1"
);
97
98
at(0, 0) = 1;
99
at(m + 2 - 1, m + 1 - 1) = 1;
100
101
vec avg = {c, 1 - c};
102
103
int
j = 0;
104
for
(
int
i = 1; i < m + 1; ++i) {
105
at(i, j) = avg(0);
106
at(i, j + 1) = avg(1);
107
j++;
108
}
109
}
110
111
// 2-D Constructor for second type
112
Interpol::Interpol
(
bool
type, u32 m, u32 n,
Real
c1,
Real
c2) {
113
Interpol
Ix(
true
, m, c1);
114
Interpol
Iy(
true
, n, c2);
115
116
sp_mat Im(m + 2, m);
117
Im.submat(1, 0, m, m - 1) = speye(m, m);
118
119
sp_mat In(n + 2, n);
120
In.submat(1, 0, n, n - 1) = speye(n, n);
121
122
sp_mat Sx =
Utils::spkron
(In, Ix);
123
sp_mat Sy =
Utils::spkron
(Iy, Im);
124
125
*
this
=
Utils::spjoin_rows
(Sx, Sy);
126
}
127
128
// 3-D Constructor for second type
129
Interpol::Interpol
(
bool
type, u32 m, u32 n, u32 o,
Real
c1,
Real
c2,
Real
c3) {
130
Interpol
Ix(
true
, m, c1);
131
Interpol
Iy(
true
, n, c2);
132
Interpol
Iz(
true
, o, c3);
133
134
sp_mat Im(m + 2, m);
135
Im.submat(1, 0, m, m - 1) = speye(m, m);
136
137
sp_mat In(n + 2, n);
138
In.submat(1, 0, n, n - 1) = speye(n, n);
139
140
sp_mat Io(o + 2, o);
141
Io.submat(1, 0, o, o - 1) = speye(o, o);
142
143
sp_mat Sx =
Utils::spkron
(
Utils::spkron
(Io, In), Ix);
144
sp_mat Sy =
Utils::spkron
(
Utils::spkron
(Io, Iy), Im);
145
sp_mat Sz =
Utils::spkron
(
Utils::spkron
(Iz, In), Im);
146
147
*
this
=
Utils::spjoin_rows
(
Utils::spjoin_rows
(Sx, Sy), Sz);
148
}
Interpol::Interpol
Interpol(u32 m, Real c)
1-D Mimetic Interpolator Constructor
Definition
interpol.cpp:19
Utils::spjoin_cols
static sp_mat spjoin_cols(const sp_mat &A, const sp_mat &B)
An in place operation for joining two matrices by columns.
Definition
utils.cpp:138
Utils::spjoin_rows
static sp_mat spjoin_rows(const sp_mat &A, const sp_mat &B)
An in place operation for joining two matrices by rows.
Definition
utils.cpp:103
Utils::spkron
static sp_mat spkron(const sp_mat &A, const sp_mat &B)
A wrappper for implementing a sparse Kroenecker product.
Definition
utils.cpp:70
interpol.h
Real
double Real
Definition
utils.h:21
src
cpp
interpol.cpp
Generated by
1.13.2