Skip to content

Commit dfa5a28

Browse files
authored
Merge pull request #117 from csrc-sdsu/addBCs3_fixed
Add Periodic Boundary Conditions, operators, and examples ( Add BCs3 fixed )
2 parents 5cd0508 + 05f9910 commit dfa5a28

72 files changed

Lines changed: 1709 additions & 461 deletions

File tree

Some content is hidden

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

examples/matlab/elliptic1DHomogeneousDirichlet.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
% - u'' = 1, 0 < x < 1, u(0) = 0, u(1) = 0
44
% exact solution: u(x) = x(1-x)/2
55
% ===================================================
6-
% example that uses addBC1D
6+
% example that uses addScalarBC1D
77
%
88
close all; clc;
99

@@ -22,7 +22,7 @@
2222
v = [0;0];
2323
A = - lap(k,m,dx);
2424
b = ones(size(A,2),1);
25-
[A0,b0] = addBC1D(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/elliptic1DLeftDirichletRightNeumann.m

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

@@ -22,7 +22,7 @@
2222
v = [0;0];
2323
A = - lap(k,m,dx);
2424
b = ones(size(A,2),1);
25-
[A0,b0] = addBC1D(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/elliptic1DLeftDirichletRightRobin.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
% b = 400, c = 10, d = 15
1010
% So, E = (pi - 3985)/401, F = 10
1111
% ===================================================
12-
% example that uses addBC1D
12+
% example that uses addScalarBC1D
1313
%
1414
close all; clc;
1515

@@ -28,7 +28,7 @@
2828
v = [10;15];
2929
A = - lap(k,m,dx);
3030
b = pi^2 * sin(pi*xc);
31-
[A0,b0] = addBC1D(A,b,k,m,dx,dc,nc,v);
31+
[A0,b0] = addScalarBC1D(A,b,k,m,dx,dc,nc,v);
3232
ua = A0\b0; % approximate solution
3333

3434
% plot

examples/matlab/elliptic1DLeftNeumannRightNeumann.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
% Compatibility condition:
66
% integ(f) = integ(-u'') = - u'(1) + u'(0)
77
% ===================================================
8-
% example that uses addBC1D
8+
% example that uses addScalarBC1D
99
%
1010
close all; clc;
1111

@@ -24,7 +24,7 @@
2424
v = [0;0];
2525
A = - lap(k,m,dx);
2626
b = xc - 0.5*ones(size(A,2),1);
27-
[A0,b0] = addBC1D(A,b,k,m,dx,dc,nc,v);
27+
[A0,b0] = addScalarBC1D(A,b,k,m,dx,dc,nc,v);
2828
ua = A0\b0; % approximate solution (there are infinity solutions)
2929
ua = ua - ua(1) + ue(1); % shifting ua to match ue(1) with ua(1)
3030

examples/matlab/elliptic1DLeftNeumannRightRobin.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
% b = 400, c = 10, d = 15
1010
% So, E = - (10 + pi), F = (402 pi + 4025)/400
1111
% ===================================================
12-
% example that uses addBC1D
12+
% example that uses addScalarBC1D
1313
%
1414
close all; clc;
1515

@@ -28,7 +28,7 @@
2828
v = [10;15];
2929
A = - lap(k,m,dx);
3030
b = pi^2 * sin(pi*xc);
31-
[A0,b0] = addBC1D(A,b,k,m,dx,dc,nc,v);
31+
[A0,b0] = addScalarBC1D(A,b,k,m,dx,dc,nc,v);
3232
ua = A0\b0; % approximate solution
3333

3434
% plot

examples/matlab/elliptic1DLeftRobinRightRobin.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
% a = -200, b = 400, c = 10, d = 15
1212
% So, E = (35 - pi)/403, F = (402 pi - 3995)/80600
1313
% ===================================================
14-
% example that uses addBC1D
14+
% example that uses addScalarBC1D
1515
%
1616
close all; clc;
1717

@@ -30,7 +30,7 @@
3030
v = [10;15];
3131
A = - lap(k,m,dx);
3232
b = pi^2 * sin(pi*xc);
33-
[A0,b0] = addBC1D(A,b,k,m,dx,dc,nc,v);
33+
[A0,b0] = addScalarBC1D(A,b,k,m,dx,dc,nc,v);
3434
ua = A0\b0; % approximate solution
3535

3636
% plot

examples/matlab/elliptic1DNonHomogeneousDirichlet.m

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

@@ -22,7 +22,7 @@
2222
v = [1/2;1/2];
2323
A = - lap(k,m,dx);
2424
b = ones(size(A,2),1);
25-
[A0,b0] = addBC1D(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
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
% ====================== Test 1 =====================
2+
% 1D Poisson BVP: Dirichlet, Dirichlet Homogeneous BC
3+
% - u'' = 1, 0 < x < 1, u(0) = 0, u(1) = 0
4+
% exact solution: u(x) = x(1-x)/2
5+
% ===================================================
6+
% example that uses addScalarBC1D with non-periodic boundary conditions
7+
%
8+
close all; clc;
9+
10+
addpath('../../src/matlab');
11+
12+
k = 2;
13+
bvp = 1;
14+
m = 2*k+1;
15+
dx = 1/m;
16+
% centers and vertices
17+
xc = [0 dx/2:dx:1-dx/2 1]';
18+
t = '- u" = 1, 0 < x < 1, u(0) = 0, u(1) = 0, with exact solution u(x) = x(1-x)/2';
19+
ue = 0.5*xc.*(1-xc); % exact solution
20+
dc = [1;1];
21+
nc = [0;0];
22+
v = [0;0];
23+
A = - lap(k,m,dx,dc,nc);
24+
b = ones(size(A,2),1);
25+
[A0,b0] = addScalarBC1D(A,b,k,m,dx,dc,nc,v);
26+
ua = A0\b0; % approximate solution
27+
28+
% plot
29+
figure(bvp)
30+
plot(xc,ue,'b*',xc,ua,'ro');
31+
title(t); %,'interpreter','latex');
32+
xlabel('x');
33+
ylabel('u');
34+
legend({'exact','approx'});

examples/matlab/elliptic1DPeriodicBC.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
% - u'' = 4 pi^2 sin(2 pi x), 0 < x < 1, u(0) = u(1), u'(0) = u'(1)
44
% exact solution: u(x) = sin(2 pi x) + constant
55
% ===================================================
6-
% example that uses addBC1D
6+
% example that uses addScalarBC1D with periodic boundary conditions
77
% testing 1D bc
88
%
99
close all; clc;
@@ -15,15 +15,15 @@
1515
m = 20;
1616
dx = 1/m;
1717
% centers and vertices
18-
xc = [0 dx/2:dx:1-dx/2 1]';
18+
xc = (dx/2:dx:1-dx/2)';
1919
t = '- u" = 4 pi^2 sin(2 pi x), 0 < x < 1, u(0) = u(1), u''(0) = u''(1), with exact solution u(x) = sin(2 pi x) + constant';
2020
ue = sin(2*pi*xc); % exact solution
2121
dc = [0;0];
2222
nc = [0;0];
2323
v = [0;0];
24-
A = - lap(k,m,dx);
24+
A = - lap(k,m,dx,dc,nc);
2525
b = 4*pi^2 * sin(2*pi*xc);
26-
[A0,b0] = addBC1D(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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
% Solves the 1D Poisson's equation with Robin boundary conditions
2+
% same example as elliptic1D that uses addScalarBC1D
3+
%
24

35
clc
46
close all
@@ -20,7 +22,7 @@
2022

2123
L = lap(k, m, dx); % 1D Mimetic laplacian operator
2224
U = exp(grid)'; % RHS
23-
[L0,U0] = addBC1D(L,U,k,m,dx,dc,nc,v); % add BC to system
25+
[L0,U0] = addScalarBC1D(L,U,k,m,dx,dc,nc,v); % add BC to system
2426
U0 = L0\U0; % Solve a linear system of equations
2527

2628
% Plot result

0 commit comments

Comments
 (0)