Skip to content

Commit d5a3eed

Browse files
committed
Periodics Operators
These are gradient, divergence, and interpolation periodic operators. They satisfy the following properties: grad = - div^T and interp from nodes to centers is the transpose of the interp from centers to nodes
1 parent f67492e commit d5a3eed

18 files changed

Lines changed: 593 additions & 0 deletions

src/matlab/div2DPer.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
% SPDX-License-Identifier: GPL-3.0-only
2+
%
3+
% Copyright 2008-2024 San Diego State University Research Foundation (SDSURF).
4+
%
5+
% This program is free software: you can redistribute it and/or modify
6+
% it under the terms of the GNU General Public License as published by
7+
% the Free Software Foundation, version 3.
8+
%
9+
% This program is distributed in the hope that it will be useful,
10+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
% LICENSE file or on the web GNU General Public License
13+
% <https://www.gnu.org/licenses/> for more details.
14+
%
15+
% ------------------------------------------------------------------------
16+
17+
function D = div2DPer(k, m, dx, n, dy)
18+
% Returns a two-dimensional mimetic divergence operator
19+
% when the boundary condition is periodic
20+
%
21+
% Parameters:
22+
% k : Order of accuracy
23+
% m : Number of cells along x-axis
24+
% dx : Step size along x-axis
25+
% n : Number of cells along y-axis
26+
% dy : Step size along y-axis
27+
28+
D = - grad2DPer(k, m, dx, n, dy);
29+
end

src/matlab/div3DPer.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
% SPDX-License-Identifier: GPL-3.0-only
2+
%
3+
% Copyright 2008-2024 San Diego State University Research Foundation (SDSURF).
4+
%
5+
% This program is free software: you can redistribute it and/or modify
6+
% it under the terms of the GNU General Public License as published by
7+
% the Free Software Foundation, version 3.
8+
%
9+
% This program is distributed in the hope that it will be useful,
10+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
% LICENSE file or on the web GNU General Public License
13+
% <https://www.gnu.org/licenses/> for more details.
14+
%
15+
% ------------------------------------------------------------------------
16+
17+
function D = div3DPer(k, m, dx, n, dy, o, dz)
18+
% Returns a three-dimensional mimetic divergence operator
19+
% when the boundary condition is periodic
20+
%
21+
% Parameters:
22+
% k : Order of accuracy
23+
% m : Number of cells along x-axis
24+
% dx : Step size along x-axis
25+
% n : Number of cells along y-axis
26+
% dy : Step size along y-axis
27+
% o : Number of cells along z-axis
28+
% dz : Step size along z-axis
29+
30+
D = - grad3DPer(k, m, dx, n, dy, o, dz);
31+
end

src/matlab/divPer.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
% SPDX-License-Identifier: GPL-3.0-only
2+
%
3+
% Copyright 2008-2024 San Diego State University Research Foundation (SDSURF).
4+
%
5+
% This program is free software: you can redistribute it and/or modify
6+
% it under the terms of the GNU General Public License as published by
7+
% the Free Software Foundation, version 3.
8+
%
9+
% This program is distributed in the hope that it will be useful,
10+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
% LICENSE file or on the web GNU General Public License
13+
% <https://www.gnu.org/licenses/> for more details.
14+
%
15+
% ------------------------------------------------------------------------
16+
17+
function D = divPer(k, m, dx)
18+
% Returns a m+2 by m one-dimensional mimetic divergence operator
19+
% when the boundary condition is periodic
20+
%
21+
% Parameters:
22+
% k : Order of accuracy
23+
% m : Number of cells
24+
% dx : Step size
25+
26+
% Assertions:
27+
assert(k >= 2, 'k >= 2');
28+
assert(mod(k, 2) == 0, 'k % 2 = 0');
29+
assert(m >= 2*k+1, ['m >= ' num2str(2*k+1) ' for k = ' num2str(k)]);
30+
31+
D = - gradPer(k,m,dx)';
32+
end

src/matlab/grad2DPer.m

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
% SPDX-License-Identifier: GPL-3.0-only
2+
%
3+
% Copyright 2008-2024 San Diego State University Research Foundation (SDSURF).
4+
%
5+
% This program is free software: you can redistribute it and/or modify
6+
% it under the terms of the GNU General Public License as published by
7+
% the Free Software Foundation, version 3.
8+
%
9+
% This program is distributed in the hope that it will be useful,
10+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
% LICENSE file or on the web GNU General Public License
13+
% <https://www.gnu.org/licenses/> for more details.
14+
%
15+
% ------------------------------------------------------------------------
16+
17+
function G = grad2DPer(k, m, dx, n, dy)
18+
% Returns a two-dimensional mimetic gradient operator
19+
% when the boundary condition is periodic
20+
%
21+
% Parameters:
22+
% k : Order of accuracy
23+
% m : Number of cells along x-axis
24+
% dx : Step size along x-axis
25+
% n : Number of cells along y-axis
26+
% dy : Step size along y-axis
27+
28+
Gx = gradPer(k, m, dx);
29+
Gy = gradPer(k, n, dy);
30+
31+
Im = speye(m, m);
32+
In = speye(n, n);
33+
34+
Sx = kron(In, Gx);
35+
Sy = kron(Gy, Im);
36+
37+
G = [Sx; Sy];
38+
end

src/matlab/grad3DPer.m

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
% SPDX-License-Identifier: GPL-3.0-only
2+
%
3+
% Copyright 2008-2024 San Diego State University Research Foundation (SDSURF).
4+
%
5+
% This program is free software: you can redistribute it and/or modify
6+
% it under the terms of the GNU General Public License as published by
7+
% the Free Software Foundation, version 3.
8+
%
9+
% This program is distributed in the hope that it will be useful,
10+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
% LICENSE file or on the web GNU General Public License
13+
% <https://www.gnu.org/licenses/> for more details.
14+
%
15+
% ------------------------------------------------------------------------
16+
17+
function G = grad3DPer(k, m, dx, n, dy, o, dz)
18+
% Returns a three-dimensional mimetic gradient operator
19+
% when the boundary condition is periodic
20+
%
21+
% Parameters:
22+
% k : Order of accuracy
23+
% m : Number of cells along x-axis
24+
% dx : Step size along x-axis
25+
% n : Number of cells along y-axis
26+
% dy : Step size along y-axis
27+
% o : Number of cells along z-axis
28+
% dz : Step size along z-axis
29+
30+
Im = speye(m, m);
31+
In = speye(n, n);
32+
Io = speye(o, o);
33+
34+
Gx = gradPer(k, m, dx);
35+
Gy = gradPer(k, n, dy);
36+
Gz = gradPer(k, o, dz);
37+
38+
Sx = kron(kron(Io, In), Gx);
39+
Sy = kron(kron(Io, Gy), Im);
40+
Sz = kron(kron(Gz, In), Im);
41+
42+
G = [Sx; Sy; Sz];
43+
end

src/matlab/gradPer.m

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
% SPDX-License-Identifier: GPL-3.0-only
2+
%
3+
% Copyright 2008-2024 San Diego State University Research Foundation (SDSURF).
4+
%
5+
% This program is free software: you can redistribute it and/or modify
6+
% it under the terms of the GNU General Public License as published by
7+
% the Free Software Foundation, version 3.
8+
%
9+
% This program is distributed in the hope that it will be useful,
10+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
% LICENSE file or on the web GNU General Public License
13+
% <https://www.gnu.org/licenses/> for more details.
14+
%
15+
% ------------------------------------------------------------------------
16+
17+
function G = gradPer(k, m, dx)
18+
% Returns a m by m+2 one-dimensional mimetic gradient operator
19+
% when the boundary condition is periodic
20+
%
21+
% Parameters:
22+
% k : Order of accuracy
23+
% m : Number of cells
24+
% dx : Step size
25+
26+
% Assertions:
27+
assert(k >= 2, 'k >= 2');
28+
assert(mod(k, 2) == 0, 'k % 2 = 0');
29+
assert(m >= 2*k, ['m >= ' num2str(2*k) ' for k = ' num2str(k)]);
30+
31+
% constructing circulant matrix
32+
V = sparse(1, m); % vector of values for circulant matrix
33+
idx = repmat(-1,m, m); % matrix of indices for circulant matrix
34+
idx(:,1) = 1:m;
35+
idx = cumsum(idx, 2);
36+
idx = rem(idx+m, m) + 1;
37+
38+
switch k
39+
case 2
40+
V(2:3) = [1, -1];
41+
42+
case 4
43+
V(1:4) = [-1/24, 9/8, -9/8, 1/24];
44+
45+
case 6
46+
V(1:5) = [-25/384, 75/64, -75/64, 25/384, -3/640]; V(end) = 3/640;
47+
48+
case 8
49+
V(1:6) = [-245/3072, 1225/1024, -1225/1024, 245/3072, -49/5120, 5/7168]; V(end-1) = -5/7168; V(end) = 49/5120;
50+
end
51+
52+
% G constructed as a circulant matrix
53+
G = V(idx);
54+
G = (1/dx).*G;
55+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
% SPDX-License-Identifier: GPL-3.0-only
2+
%
3+
% Copyright 2008-2024 San Diego State University Research Foundation (SDSURF).
4+
%
5+
% This program is free software: you can redistribute it and/or modify
6+
% it under the terms of the GNU General Public License as published by
7+
% the Free Software Foundation, version 3.
8+
%
9+
% This program is distributed in the hope that it will be useful,
10+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
% LICENSE file or on the web GNU General Public License
13+
% <https://www.gnu.org/licenses/> for more details.
14+
%
15+
% ------------------------------------------------------------------------
16+
17+
function I = interpolCentersToFacesD1DPer(k, m)
18+
% 1D interpolation from centers to faces.
19+
% when the boundary condition is periodic
20+
% logical centers are [1 1.5 2.5 ... m-1.5 m-0.5]
21+
% m is the number of cells in the logic x-axis
22+
23+
I = interpolFacesToCentersG1DPer(k,m)';
24+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
% SPDX-License-Identifier: GPL-3.0-only
2+
%
3+
% Copyright 2008-2024 San Diego State University Research Foundation (SDSURF).
4+
%
5+
% This program is free software: you can redistribute it and/or modify
6+
% it under the terms of the GNU General Public License as published by
7+
% the Free Software Foundation, version 3.
8+
%
9+
% This program is distributed in the hope that it will be useful,
10+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
% LICENSE file or on the web GNU General Public License
13+
% <https://www.gnu.org/licenses/> for more details.
14+
%
15+
% ------------------------------------------------------------------------
16+
17+
function I = interpolCentersToFacesD2DPer(k, m, n)
18+
% 2D interpolation from centers to faces.
19+
% when the boundary condition is periodic
20+
% logical centers are [1 1.5 2.5 ... m-1.5 m-0.5 m]x[1 1.5 2.5 ... n-1.5 n-0.5 n]
21+
% m and n are the number of cells in the logic x-axis and y-axis
22+
23+
I = interpolFacesToCentersG2DPer(k, m, n)';
24+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
% SPDX-License-Identifier: GPL-3.0-only
2+
%
3+
% Copyright 2008-2024 San Diego State University Research Foundation (SDSURF).
4+
%
5+
% This program is free software: you can redistribute it and/or modify
6+
% it under the terms of the GNU General Public License as published by
7+
% the Free Software Foundation, version 3.
8+
%
9+
% This program is distributed in the hope that it will be useful,
10+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
% LICENSE file or on the web GNU General Public License
13+
% <https://www.gnu.org/licenses/> for more details.
14+
%
15+
% ------------------------------------------------------------------------
16+
17+
function I = interpolCentersToFacesD3DPer(k, m, n, o)
18+
% 3D interpolation from centers to faces
19+
% when the boundary condition is periodic
20+
% logical centers are [1 1.5 ... m-0.5 m]x[1 1.5 ... n-0.5 n]x[1 1.5 ... o-0.5 o]
21+
% m, n, o, are the number of cells in the logical x-, y-, z- axes
22+
23+
I = interpolFacesToCentersG3DPer(k, m, n, o)';
24+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
% SPDX-License-Identifier: GPL-3.0-only
2+
%
3+
% Copyright 2008-2024 San Diego State University Research Foundation (SDSURF).
4+
%
5+
% This program is free software: you can redistribute it and/or modify
6+
% it under the terms of the GNU General Public License as published by
7+
% the Free Software Foundation, version 3.
8+
%
9+
% This program is distributed in the hope that it will be useful,
10+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
% LICENSE file or on the web GNU General Public License
13+
% <https://www.gnu.org/licenses/> for more details.
14+
%
15+
% ------------------------------------------------------------------------
16+
17+
function I = interpolCentersToNodes1DPer(k, m)
18+
% interpolation operator from nodal coordinates to staggered centers
19+
% when the boundary condition is periodic
20+
% m is the number of cells in the logical x-axis
21+
% nodal logical coordinates are [1:1:m]
22+
% centers logical coordinates [1,1.5:m-0.5,m]
23+
24+
I = interpolCentersToFacesD1DPer(k, m);
25+
end

0 commit comments

Comments
 (0)