Skip to content

Commit 7a2648c

Browse files
committed
addScalarBC first part almost done
Gral is changed by Scalar, Per by Periodic and added License Identifier. However, there are divGral, gradGral and lapGral operator that still need to be resolved
1 parent 889ddba commit 7a2648c

62 files changed

Lines changed: 564 additions & 771 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/matlab/elliptic1DGralNonPerBC.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
v = [0;0];
2323
A = - lapGral1D(k,m,dx,dc,nc);
2424
b = ones(size(A,2),1);
25-
[A0,b0] = addGralBC1D(A,b,k,m,dx,dc,nc,v);
25+
[A0,b0] = addScalarBC1D(A,b,k,m,dx,dc,nc,v);
2626
ua = A0\b0; % approximate solution
2727

2828
% plot

examples/matlab/elliptic1DGralPerBC.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
v = [0;0];
2424
A = - lapGral1D(k,m,dx,dc,nc);
2525
b = 4*pi^2 * sin(2*pi*xc);
26-
[A0,b0] = addGralBC1D(A,b,k,m,dx,dc,nc,v);
26+
[A0,b0] = addScalarBC1D(A,b,k,m,dx,dc,nc,v);
2727
ua = A0\b0; % approximate solution (there are infinity solutions)
2828
ua = ua - ua(1) + ue(1); % shifting ua to match ue(1) with ua(1)
2929

examples/matlab/elliptic2DXPerYDirichlet.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
% -(u_xx + u_yy) = 2 sin(2 pi x) (1+2 pi^2 y(1-y)), 0 < x,y < 1, u(x,0) = 0 = u(x,1)
44
% exact solution: u(x) = y(1-y)sin(2 pi x)
55
% ===================================================
6-
% example that uses addGralBC2D
6+
% example that uses addScalarBC2D
77
%
88
close all; clc;
99

@@ -31,7 +31,7 @@
3131
A = - lapGral2D(k,m,dx,n,dy,dc,nc);
3232
b = 2*sin(2*pi*X).*(1+2*pi^2*Y.*(1-Y));
3333
b = reshape(b,[],1);
34-
[A0, b0] = addGralBC2D(A, b, k, m, dx, n, dy, dc, nc, v);
34+
[A0, b0] = addScalarBC2D(A, b, k, m, dx, n, dy, dc, nc, v);
3535
ua = A0\b0; % approximate solution (there are infinity solutions)
3636
ua = reshape(ua,m,n+2);
3737

examples/matlab/elliptic3DXDirichletYPerZNeumann.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
A = - lapGral3D(k,m,dx,n,dy,o,dz,dc,nc);
4040
b = 2*sin(2*pi*Y).*Z.*(1+2*pi^2*X.*(1-X));
4141
b = reshape(b,[],1);
42-
[A0,b0] = addGralBC3D(A,b,k,m,dx,n,dy,o,dz,dc,nc,v);
42+
[A0,b0] = addScalarBC3D(A,b,k,m,dx,n,dy,o,dz,dc,nc,v);
4343
ua = A0\b0; % approximate solution
4444
ua = reshape(ua,m+2,n,o+2);
4545

examples/matlab/elliptic3DXDirichletYPerZPer.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
A = - lapGral3D(k,m,dx,n,dy,o,dz,dc,nc);
3939
b = 16*(1-X.^2).*cos(4*X) - 16*X.*sin(4*X) + 2*(cos(4*X)+sin(2*Y)+sin(4*Z)) + (1-X.^2).*(4*sin(2*Y) + 16*sin(4*Z));
4040
b = reshape(b,[],1);
41-
[A0,b0] = addGralBC3D(A,b,k,m,dx,n,dy,o,dz,dc,nc,v);
41+
[A0,b0] = addScalarBC3D(A,b,k,m,dx,n,dy,o,dz,dc,nc,v);
4242
ua = A0\b0; % approximate solution
4343
ua = reshape(ua,m+2,n,o);
4444

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [A, b] = addGralBC1D(A, b, k, m, dx, dc, nc, v)
1+
function [A, b] = addScalarBC1D(A, b, k, m, dx, dc, nc, v)
22
% Separates cases non-periodic and periodic for dealing with boundary data
33
%
44
% Parameters:
@@ -15,6 +15,13 @@
1515
% dc : a0 (2x1 vector for left and right vertices, resp.)
1616
% nc : b0 (2x1 vector for left and right vertices, resp.)
1717
% v : g (2x1 vector for left and right vertices, resp.)
18+
%
19+
% ----------------------------------------------------------------------------
20+
% SPDX-License-Identifier: GPL-3.0-or-later
21+
% © 2008-2024 San Diego State University Research Foundation (SDSURF).
22+
% See LICENSE file or https://www.gnu.org/licenses/gpl-3.0.html for details.
23+
% ----------------------------------------------------------------------------
24+
%
1825

1926
% verify bc sizes and square linear system
2027
assert(all(size(dc) == [2 1]), 'dc is a 2x1 vector');
@@ -39,8 +46,8 @@
3946
% remove first and last coefficients of right-hand-side vector b
4047
b(vec) = 0;
4148

42-
[Abcl,Abcr] = addGralBC1Dlhs(k, m, dx, dc, nc);
49+
[Abcl,Abcr] = addScalarBC1Dlhs(k, m, dx, dc, nc);
4350
A = A + Abcl + Abcr;
44-
b = addGralBC1Drhs(b, v, vec);
51+
b = addScalarBC1Drhs(b, v, vec);
4552
end
4653
end
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [Al, Ar] = addGralBC1Dlhs(k, m, dx, dc, nc)
1+
function [Al, Ar] = addScalarBC1Dlhs(k, m, dx, dc, nc)
22
% This functions uses geometry and boundary type conditions to create
33
% modifications of matrix A associated to each of the boundary faces.
44
%
@@ -13,6 +13,13 @@
1313
% dx : Step size
1414
% dc : Dirichlet coefficient (2x1 vector for left and right vertices, resp.)
1515
% nc : Neumann coefficient (2x1 vector for left and right vertices, resp.)
16+
%
17+
% ----------------------------------------------------------------------------
18+
% SPDX-License-Identifier: GPL-3.0-or-later
19+
% © 2008-2024 San Diego State University Research Foundation (SDSURF).
20+
% See LICENSE file or https://www.gnu.org/licenses/gpl-3.0.html for details.
21+
% ----------------------------------------------------------------------------
22+
%
1623

1724
% Dirichlet coefficient
1825
Al = sparse(m+2, m+2);
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function b = addGralBC1Drhs(b, v, vec)
1+
function b = addScalarBC1Drhs(b, v, vec)
22
% This function uses the non-periodic boundary condition type of each vertex
33
% and the rhs b values associated to left, and right vertices to modify the rhs vector b.
44
%
@@ -10,6 +10,13 @@
1010
% b : Right hand side without boundary conditions added
1111
% v : value (2x1 vector for left and right vertices, resp.)
1212
% vec : vector with indices of rhs associated to bc
13+
%
14+
% ----------------------------------------------------------------------------
15+
% SPDX-License-Identifier: GPL-3.0-or-later
16+
% © 2008-2024 San Diego State University Research Foundation (SDSURF).
17+
% See LICENSE file or https://www.gnu.org/licenses/gpl-3.0.html for details.
18+
% ----------------------------------------------------------------------------
19+
%
1320

1421
% rhs for non-periodic boundary conditions
1522
b(vec) = v;
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [A, b] = addGralBC2D(A, b, k, m, dx, n, dy, dc, nc, v)
1+
function [A, b] = addScalarBC2D(A, b, k, m, dx, n, dy, dc, nc, v)
22
% This function assumes that the unknown u, which represents the discrete
33
% solution the continuous second-order 2D PDE operator
44
% L U = f,
@@ -61,6 +61,13 @@
6161
% dc : a0 (4x1 vector for left, right, bottom, top boundaries, resp.)
6262
% nc : b0 (4x1 vector for left, right, bottom, top boundaries, resp.)
6363
% v : g (4x1 vector of arrays for left, right, bottom, top boundaries, resp.)
64+
%
65+
% ----------------------------------------------------------------------------
66+
% SPDX-License-Identifier: GPL-3.0-or-later
67+
% © 2008-2024 San Diego State University Research Foundation (SDSURF).
68+
% See LICENSE file or https://www.gnu.org/licenses/gpl-3.0.html for details.
69+
% ----------------------------------------------------------------------------
70+
%
6471

6572
% verify bc sizes and square linear system
6673
cellsz = cellfun(@size,v,'uni',false);
@@ -93,7 +100,7 @@
93100
rl = 0; rr = 0; rb = 0; rt = 0; % periodic case
94101

95102
% get modifications of A for left, right, bottom, top edges, resp.
96-
[Abcl,Abcr,Abcb,Abct] = addGralBC2Dlhs(k, m, dx, n, dy, dc, nc);
103+
[Abcl,Abcr,Abcb,Abct] = addScalarBC2Dlhs(k, m, dx, n, dy, dc, nc);
97104

98105
% get rhs entries affected by bcs for left, right, bottom, top edges, resp.
99106
if ~isempty(qrl)
@@ -126,6 +133,6 @@
126133

127134
% update b with boundary information
128135
if ~(isempty(qrl) && isempty(qbt))
129-
b = addGralBC2Drhs(b, dc, nc, v, rl, rr, rb, rt);
136+
b = addScalarBC2Drhs(b, dc, nc, v, rl, rr, rb, rt);
130137
end
131138
end
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [Abcl,Abcr,Abcb,Abct] = addGralBC2Dlhs(k, m, dx, n, dy, dc, nc)
1+
function [Abcl,Abcr,Abcb,Abct] = addScalarBC2Dlhs(k, m, dx, n, dy, dc, nc)
22
% This functions uses geometry and boundary type conditions to create
33
% modifications of matrix A associated to each of the boundary edges.
44
%
@@ -17,6 +17,13 @@
1717
% dy : Horizontal cell size
1818
% dc : a0 (4x1 vector for left, right, bottom, top boundaries, resp.)
1919
% nc : b0 (4x1 vector for left, right, bottom, top boundaries resp.)
20+
%
21+
% ----------------------------------------------------------------------------
22+
% SPDX-License-Identifier: GPL-3.0-or-later
23+
% © 2008-2024 San Diego State University Research Foundation (SDSURF).
24+
% See LICENSE file or https://www.gnu.org/licenses/gpl-3.0.html for details.
25+
% ----------------------------------------------------------------------------
26+
%
2027

2128
Abcl = 0; Abcr = 0; Abcb = 0; Abct = 0; % periodic case
2229

@@ -26,7 +33,7 @@
2633

2734
% 2D boundary operator
2835
if ~isempty(qrl)
29-
[Abcl0,Abcr0] = addGralBC1Dlhs(k, m, dx, dc(1:2,1), nc(1:2,1));
36+
[Abcl0,Abcr0] = addScalarBC1Dlhs(k, m, dx, dc(1:2,1), nc(1:2,1));
3037
if isempty(qbt)
3138
In = speye(n);
3239
else
@@ -40,7 +47,7 @@
4047
end
4148

4249
if ~isempty(qbt)
43-
[Abcb0,Abct0] = addGralBC1Dlhs(k, n, dy, dc(3:4,1), nc(3:4,1));
50+
[Abcb0,Abct0] = addScalarBC1Dlhs(k, n, dy, dc(3:4,1), nc(3:4,1));
4451
if isempty(qrl)
4552
Im = speye(m);
4653
else

0 commit comments

Comments
 (0)