Mimetic Operators Library Enhanced 4.0
Loading...
Searching...
No Matches
Divergence Class Reference

Mimetic Divergence operator. More...

#include <divergence.h>

Inheritance diagram for Divergence:

Public Member Functions

 Divergence (u16 k, u32 m, Real dx)
 1-D Mimetic Divergence Constructor
 
 Divergence (u16 k, u32 m, u32 n, Real dx, Real dy)
 2-D Mimetic Divergence Constructor
 
 Divergence (u16 k, u32 m, u32 n, u32 o, Real dx, Real dy, Real dz)
 3-D Mimetic Divergence Constructor
 
vec getQ ()
 Returns the weights used in the Mimeitc Divergence Operators.
 

Detailed Description

Mimetic Divergence operator.

Definition at line 26 of file divergence.h.

Constructor & Destructor Documentation

◆ Divergence() [1/3]

Divergence::Divergence ( u16 k,
u32 m,
Real dx )

1-D Mimetic Divergence Constructor

Parameters
kOrder of accuracy
mNumber of cells
dxSpacing between cells

Definition at line 19 of file divergence.cpp.

19 : sp_mat(m + 2, m + 1) {
20 assert(!(k % 2));
21 assert(k > 1 && k < 7);
22 assert(m > 2 * k);
23
24 switch (k) {
25 case 2:
26 for (u32 i = 1; i < m + 1; i++) {
27 at(i, i - 1) = -1.0;
28 at(i, i) = 1.0;
29 }
30 // Weights
31 Q = { 1.0, 1.0, 1.0, 1.0, 1.0 };
32 break;
33 case 4:
34 // A
35 at(1, 0) = -11.0 / 12.0;
36 at(1, 1) = 17.0 / 24.0;
37 at(1, 2) = 3.0 / 8.0;
38 at(1, 3) = -5.0 / 24.0;
39 at(1, 4) = 1.0 / 24.0;
40 // A'
41 at(m, m) = 11.0 / 12.0;
42 at(m, m - 1) = -17.0 / 24.0;
43 at(m, m - 2) = -3.0 / 8.0;
44 at(m, m - 3) = 5.0 / 24.0;
45 at(m, m - 4) = -1.0 / 24.0;
46 // Middle
47 for (u32 i = 2; i < m; i++) {
48 at(i, i - 2) = 1.0 / 24.0;
49 at(i, i - 1) = -9.0 / 8.0;
50 at(i, i) = 9.0 / 8.0;
51 at(i, i + 1) = -1.0 / 24.0;
52 }
53 Q = { 2186.0 / 1943.0 , 2125.0 / 2828.0 , 1441.0 / 1240.0 , 648.0 / 673.0
54 , 349.0 / 350.0 , 648.0 / 673.0 , 1441.0 / 1240.0 , 2125.0 / 2828.0
55 , 2186.0 / 1943.0 };
56 break;
57 case 6:
58 // A
59 at(1, 0) = -1627.0 / 1920.0;
60 at(1, 1) = 211.0 / 640.0;
61 at(1, 2) = 59.0 / 48.0;
62 at(1, 3) = -235.0 / 192.0;
63 at(1, 4) = 91.0 / 128.0;
64 at(1, 5) = -443.0 / 1920.0;
65 at(1, 6) = 31.0 / 960.0;
66 at(2, 0) = 31.0 / 960.0;
67 at(2, 1) = -687.0 / 640.0;
68 at(2, 2) = 129.0 / 128.0;
69 at(2, 3) = 19.0 / 192.0;
70 at(2, 4) = -3.0 / 32.0;
71 at(2, 5) = 21.0 / 640.0;
72 at(2, 6) = -3.0 / 640.0;
73 // A'
74 at(m, m) = 1627.0 / 1920.0;
75 at(m, m - 1) = -211.0 / 640.0;
76 at(m, m - 2) = -59.0 / 48.0;
77 at(m, m - 3) = 235.0 / 192.0;
78 at(m, m - 4) = -91.0 / 128.0;
79 at(m, m - 5) = 443.0 / 1920.0;
80 at(m, m - 6) = -31.0 / 960.0;
81 at(m - 1, m) = -31.0 / 960.0;
82 at(m - 1, m - 1) = 687.0 / 640.0;
83 at(m - 1, m - 2) = -129.0 / 128.0;
84 at(m - 1, m - 3) = -19.0 / 192.0;
85 at(m - 1, m - 4) = 3.0 / 32.0;
86 at(m - 1, m - 5) = -21.0 / 640.0;
87 at(m - 1, m - 6) = 3.0 / 640.0;
88 // Middle
89 for (u32 i = 3; i < m - 1; i++) {
90 at(i, i - 3) = -3.0 / 640.0;
91 at(i, i - 2) = 25.0 / 384.0;
92 at(i, i - 1) = -75.0 / 64.0;
93 at(i, i) = 75.0 / 64.0;
94 at(i, i + 1) = -25.0 / 384.0;
95 at(i, i + 2) = 3.0 / 640.0;
96 }
97 // Weights
98 Q = { 2383.0 / 2005.0 , 929.0 / 2002.0 , 887.0 / 531.0 , 3124.0 / 5901.0
99 , 1706.0 / 1457.0 , 457.0 / 467.0 , 1057.0 / 1061.0 , 457.0 / 467.0
100 , 1706.0 / 1457.0 , 3124.0 / 5901.0 , 887.0 / 531.0 , 929.0 / 2002.0
101 , 2383.0 / 2005.0 };
102 break;
103 }
104
105 // Scaling
106 *this /= dx;
107}

◆ Divergence() [2/3]

Divergence::Divergence ( u16 k,
u32 m,
u32 n,
Real dx,
Real dy )

2-D Mimetic Divergence Constructor

Parameters
kOrder of accuracy
mNumber of cells in x-direction
nNumber of cells in y-direction
dxSpacing between cells in x-direction
dySpacing between cells in y-direction

Definition at line 110 of file divergence.cpp.

110 {
111 Divergence Dx(k, m, dx);
112 Divergence Dy(k, n, dy);
113
114 sp_mat Im = speye(m + 2, m + 2);
115 sp_mat In = speye(n + 2, n + 2);
116
117 Im.shed_col(0);
118 Im.shed_col(m);
119 In.shed_col(0);
120 In.shed_col(n);
121
122 sp_mat D1 = Utils::spkron(In, Dx);
123 sp_mat D2 = Utils::spkron(Dy, Im);
124
125 // Dimensions = (m+2)*(n+2), 2*m*n+m+n
126 if (m != n)
127 *this = Utils::spjoin_rows(D1, D2);
128 else {
129 sp_mat A1(1, 2);
130 sp_mat A2(1, 2);
131 A1(0, 0) = A2(0, 1) = 1.0;
132 *this = Utils::spkron(A1, D1) + Utils::spkron(A2, D2);
133 }
134}
Divergence(u16 k, u32 m, Real dx)
1-D Mimetic Divergence Constructor
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
static sp_mat spkron(const sp_mat &A, const sp_mat &B)
A wrappper for implementing a sparse Kroenecker product.
Definition utils.cpp:70

◆ Divergence() [3/3]

Divergence::Divergence ( u16 k,
u32 m,
u32 n,
u32 o,
Real dx,
Real dy,
Real dz )

3-D Mimetic Divergence Constructor

Parameters
kOrder of accuracy
mNumber of cells in x-direction
nNumber of cells in y-direction
oNumber of cells in z-direction
dxSpacing between cells in x-direction
dySpacing between cells in y-direction
dzSpacing between cells in z-direction

Definition at line 137 of file divergence.cpp.

137 {
138 Divergence Dx(k, m, dx);
139 Divergence Dy(k, n, dy);
140 Divergence Dz(k, o, dz);
141
142 sp_mat Im = speye(m + 2, m + 2);
143 sp_mat In = speye(n + 2, n + 2);
144 sp_mat Io = speye(o + 2, o + 2);
145
146 Im.shed_col(0);
147 Im.shed_col(m);
148 In.shed_col(0);
149 In.shed_col(n);
150 Io.shed_col(0);
151 Io.shed_col(o);
152
153 sp_mat D1 = Utils::spkron(Utils::spkron(Io, In), Dx);
154 sp_mat D2 = Utils::spkron(Utils::spkron(Io, Dy), Im);
155 sp_mat D3 = Utils::spkron(Utils::spkron(Dz, In), Im);
156
157 // Dimensions = (m+2)*(n+2)*(o+2), 3*m*n*o+m*n+m*o+n*o
158 if ((m != n) || (n != o))
159 *this = Utils::spjoin_rows(Utils::spjoin_rows(D1, D2), D3);
160 else {
161 sp_mat A1(1, 3);
162 sp_mat A2(1, 3);
163 sp_mat A3(1, 3);
164 A1(0, 0) = A2(0, 1) = A3(0, 2) = 1.0;
165 *this =
166 Utils::spkron(A1, D1) + Utils::spkron(A2, D2) + Utils::spkron(A3, D3);
167 }
168}

Member Function Documentation

◆ getQ()

vec Divergence::getQ ( )

Returns the weights used in the Mimeitc Divergence Operators.

Note
for informational purposes only, can be used in constructing new operators.

Definition at line 171 of file divergence.cpp.

171{ return Q; }

The documentation for this class was generated from the following files: