Skip to content

Commit f8f11b2

Browse files
Merge branch 'main' into feature/license-header-manager
2 parents 2e1e2b5 + c4e0912 commit f8f11b2

34 files changed

Lines changed: 3662 additions & 320 deletions

examples/matlab_octave/tutorials/two_way_wave_equation/comparison_two_way_wave_md_vs_fd.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@
100100
c = 0.1; % Velocity, 1 makes FD sceme exact
101101
west = -2.0; % Domain's leftmost limits
102102
east = 2.0; % Domain's rightmost limit
103+
dt = 0.001; % Time step, must work for all cell sizes
103104

104105
% Number of cells to try, points is cells+1
105-
num_cells = [ 10, 20, 40, 80, 160 ];
106+
num_cells = [ 20, 40, 80, 160 ];
106107

107108
%% Run each of the methods over the different grids
108-
[ U2_fd, error_fd, walltime_fd, flops_fd ] = finite_diff_two_way_wave_eq();
109-
[ U2_md, error_md, walltime_md, flops_md ] = mimetic_diff_two_way_wave_eq();
109+
[ U2_fd, error_fd, walltime_fd, flops_fd ] = finite_diff_two_way_wave_eq(c, dt, num_cells);
110+
[ U2_md, error_md, walltime_md, flops_md ] = mimetic_diff_two_way_wave_eq(k, c, dt, num_cells);
110111

111112
%% Error analysis
112113

@@ -129,7 +130,8 @@
129130
xlim([1 / num_cells(end) 1 / num_cells(1)]);
130131
xlabel('dx'); ylabel('error');
131132
grid on;
132-
title(['Error: FD slope~', num2str(p_fd(1)), ', MD slope~', num2str(p_md(1))]);
133+
title(['Error Convergence, FD slope=', num2str(p_fd(1),'%.2f'), ...
134+
', MD slope=', num2str(p_md(1),'%.2f')]);
133135
legend('FD Error','MD error')
134136
set(gca, "linewidth", 2, "fontsize", 16)
135137

@@ -142,7 +144,7 @@
142144
ylim([min( min(walltime_fd), min(walltime_md) ) max( max(walltime_fd), max(walltime_md) )]);
143145
xlabel('num points'); ylabel('walltime [s]');
144146
grid on;
145-
title(['Walltime, MD is order ', num2str(k)]);
147+
title(['Walltime: FD (order 2) vs MD (order ', num2str(k), ')']);
146148
legend('FD time', 'MD time');
147149
set(gca, "linewidth", 2, "fontsize", 16)
148150

@@ -154,7 +156,7 @@
154156
xlim([ num_cells(1) num_cells(end) ]); ylim([ 1e5 1e8 ]);
155157
xlabel('num cells'); ylabel('FLOPs');
156158
grid on;
157-
title(['FLOPs for each method, mimetic order:', num2str(k)]);
159+
title(['FLOPs: FD (order 2) vs MD (order ', num2str(k), ')']);
158160
legend('FD FLOPs', 'MD FLOPs');
159161
set(gca, "linewidth", 2, "fontsize", 16)
160162

examples/matlab_octave/tutorials/two_way_wave_equation/finite_diff_two_way_wave_eq.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [ U2_fd, error_fd, walltime_fd, flops_fd ] = finite_diff_two_way_wave_eq()
1+
function [ U2_fd, error_fd, walltime_fd, flops_fd ] = finite_diff_two_way_wave_eq(c, dt, num_cells)
22
%% FINITE_DIFF_TWO_WAY_WAVE_EQ
33
% Solve the 1D two-way wave equation using standard finite differences.
44
%
@@ -12,6 +12,11 @@
1212
%
1313
% D_fd = (1/dx^2) * tridiag([1, -2, 1])
1414
%
15+
% INPUTS:
16+
% c - wave speed
17+
% dt - time step
18+
% num_cells - array of number of cells to test.
19+
%
1520
% OUTPUTS:
1621
% U2_fd - Final solution vector at last time step
1722
% error_fd - Norm of error vs. analytic or reference solution
@@ -39,20 +44,16 @@
3944
%
4045

4146
%% Problem definition
42-
c = 0.1; % Velocity, 1 makes FD scheme exact
4347
west = -2.0; % Domain's leftmost limits
4448
east = 2.0; % Domain's rightmost limit
4549

46-
%% Number of cells to try, grid points is cells+1
47-
num_cells = [ 10, 20, 40, 80, 160 ];
48-
4950
% generic holders for metrics within the loops
5051
error_fd = zeros(size(num_cells));
5152
walltime_fd = zeros(size(num_cells));
5253
flops_fd = zeros(size(num_cells));
5354

5455
% Initial Condition Function
55-
f = @(x) ( (x > -0.5) & (x < 0.5) ) .* (cos(pi * x).^2);
56+
f = @(x) exp( -x.^2 / 0.1 );
5657

5758
% Wave solution using d'Alembert
5859
u = @(x,t) 0.5 * ( f(x - c * t) + f(x + c * t) );
@@ -64,7 +65,6 @@
6465
nx = m+1; % number of grid points
6566

6667
dx = (east - west) / m; % spacial discretization
67-
dt = 0.001; % Time step constant for error analysis
6868

6969
r2_fd = c^2 * (dt^2 / dx^2); % c in the equation
7070

@@ -126,7 +126,8 @@
126126

127127
% Number of flops
128128
flops_fd(cell_index) = (2 * nnz_fd + length(U0_fd)) * t;
129-
error_fd(cell_index) = max(U2_fd-analytic_fd);
129+
diff = U2_fd - analytic_fd;
130+
error_fd(cell_index) = norm(diff) / norm(analytic_fd);
130131

131132
end
132133

examples/matlab_octave/tutorials/two_way_wave_equation/mimetic_diff_two_way_wave_eq.m

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [ U2_md, error_md, walltime_md, flops_md ] = mimetic_diff_two_way_wave_eq()
1+
function [ U2_md, error_md, walltime_md, flops_md ] = mimetic_diff_two_way_wave_eq(k, c, dt, num_cells)
22
%% MIMETIC_DIFF_TWO_WAY_WAVE_EQ
33
% Solve the 1D two-way wave equation using mimetic finite differences.
44
%
@@ -11,6 +11,12 @@
1111
% where L is the mimetic discrete Laplacian operator. Note there is no spacial
1212
% discretization, the L takes care of that.
1313
%
14+
% INPUTS:
15+
% k - mimetic order of accuracy (2,4,6,8)
16+
% c - wave speed
17+
% dt - time step
18+
% num_cells - array of number of cells to test.
19+
%
1420
% OUTPUTS:
1521
% U2_md - Final solution vector at last time step
1622
% error_md - Norm of error vs. analytic or reference solution
@@ -43,21 +49,16 @@
4349
%
4450

4551
%% Problem definition
46-
k = 2; % Mimetic Order of Accuracy, can change to 4,6,8
47-
c = 0.1; % Velocity, 1 makes FD sceme exact
4852
west = -2.0; % Domain's leftmost limits
4953
east = 2.0; % Domain's rightmost limit
5054

51-
%% Number of cells to try, points is cells+1
52-
num_cells = [ 10, 20, 40, 80, 160 ];
53-
5455
% generic holders for loop info
5556
error_md = zeros(size(num_cells));
5657
walltime_md = zeros(size(num_cells));
5758
flops_md = zeros(size(num_cells));
5859

5960
% Initial Condition Function
60-
f = @(x) ( (x > -0.5) & (x < 0.5) ) .* (cos(pi * x).^2);
61+
f = @(x) exp( -x.^2 / 0.1 );
6162

6263
% Wave solution using d'Almbert
6364
u = @(x,t) 0.5 * ( f(x - c * t) + f(x + c * t) );
@@ -69,7 +70,6 @@
6970
nx = m+1; % number of grid points
7071

7172
dx = (east - west) / m; % spacial discretization
72-
dt = 0.001; % Time step constant for error analysis
7373

7474
r2_md = c^2 * (dt^2); % c in the equation, dx is built into the
7575
% mimetic operator Laplacian (L)
@@ -108,6 +108,7 @@
108108

109109
% Number of flops
110110
flops_md(cell_index) = (2 * nnz_md + (3 * length(U0_md)) ) * t;
111-
error_md(cell_index) = max(U2_md-analytic_md);
111+
diff = U2_md - analytic_md;
112+
error_md(cell_index) = norm(diff) / norm(analytic_md);
112113

113114
end

julia/MOLE.jl/docs/src/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ Once you have built the documentation (either from the REPL or the command line)
8686
### Operators
8787

8888
```@docs
89-
MOLE.div(k::Int,m::Int,dx)
90-
MOLE.grad(k::Int,m::Int,dx)
91-
MOLE.lap(k::Int,m::Int,dx)
89+
MOLE.Operators.div(k::Int,m::Int,dx)
90+
MOLE.Operators.grad(k::Int,m::Int,dx)
91+
MOLE.Operators.lap(k::Int,m::Int,dx)
9292
```
9393

9494
### Utilities
9595

9696
```@docs
97-
MOLE.robinBC(k::Int, m::Int, dx, a, b)
97+
MOLE.BCs.robinBC(k::Int, m::Int, dx, a, b)
9898
```
9999

100100
## Examples

src/cpp/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ add_library(mole_C++
99
mixedbc.cpp
1010
robinbc.cpp
1111
utils.cpp
12+
interpolCtoF.cpp
13+
interpolCtoN.cpp
14+
interpolFtoC.cpp
15+
interpolNtoC.cpp
1216
)
1317
target_include_directories(mole_C++ PUBLIC ${ARMADILLO_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIRS} ${OpenBLAS_INCLUDE_DIRS} ${SUPERLU_INCLUDE_DIR})
1418
target_link_libraries(mole_C++ PUBLIC ${LINK_LIBS})

0 commit comments

Comments
 (0)