Skip to content

Kuramoto Sivashinky 1D PDE #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/+otp/+kuramotosivashinsky/+presets/Canonical.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
% The Kuramoto-Sivashinky equation is a chaotic problem.
%
% In this particular discretization, we are applying a spectral
% method, therefore the boundary conditions will be chosen to be as cyclic
% on the domain [0, L]. Note that this is different from another typical
% domain of [-L, L]. The larger the L, the more interesting the problem is
% but the more points are required to do a good discretization. The current
% canonical implementation with the size, L, and is used in
%
% Kassam, Aly-Khan, and Lloyd N. Trefethen.
% "Fourth-order time-stepping for stiff PDEs."
% SIAM Journal on Scientific Computing 26, no. 4 (2005): 1214-1233.
%

classdef Canonical < otp.kuramotosivashinsky.KuramotoSivashinskyProblem

methods
function obj = Canonical(varargin)

p = inputParser;
addParameter(p, 'Size', 128);
addParameter(p, 'L', 32*pi);

parse(p, varargin{:});

s = p.Results;

N = s.Size;
L = s.L;

params.L = L;

h = L/N;

% exclude the left boundary point as it is identical to the
% right boundary point
x = linspace(h, L, N).';

u0 = cos(x/16).*(1+sin(x/16));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace hardcoded 16 so i.c. is periodic for different L. It might be easier to have x in the range 0 to 2 pi.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I have x in 0 to 2 pi, then I would have to calculate h differently. I will change u0, to be a function of L and use cospi and sinpi. I think that is simpler.


u0hat = fft(u0);

tspan = [0, 150];

obj = [email protected](tspan, u0hat, params);

end
end
end
57 changes: 57 additions & 0 deletions src/+otp/+kuramotosivashinsky/KuramotoSivashinskyProblem.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
classdef KuramotoSivashinskyProblem < otp.Problem

methods
function obj = KuramotoSivashinskyProblem(timeSpan, y0, parameters)
[email protected]('Kuramoto-Sivashinsky', [], timeSpan, y0, parameters);
end
end

methods
function soly = convert2grid(~, soly)

soly = real(ifft(soly));

end

end

methods (Access = protected)
function onSettingsChanged(obj)

L = obj.Parameters.L;

N = obj.NumVars;

div = L/(2*pi);

% note that k already has "i" in it
k = (1i*[0:(N/2 - 1), 0, (-N/2 + 1):-1].'/div);
k2 = k.^2;
k4 = k.^4;
k24 = k2 + k4;

obj.Rhs = otp.Rhs(@(t, u) otp.kuramotosivashinsky.f(t, u, k, k24), ...
otp.Rhs.FieldNames.Jacobian, ...
@(t, u) otp.kuramotosivashinsky.jac(t,u, k, k24), ...
otp.Rhs.FieldNames.JacobianVectorProduct, ...
@(t, u, v) otp.kuramotosivashinsky.jvp(t, u, v, k, k24), ...
otp.Rhs.FieldNames.JacobianAdjointVectorProduct, ...
@(t, u, v) otp.kuramotosivashinsky.javp(t, u, v, k, k24));

end

function validateNewState(obj, newTimeSpan, newY0, newParameters)

[email protected](obj, ...
newTimeSpan, newY0, newParameters)

if mod(numel(newY0), 2) ~= 0
error('The problem size has to be an even integer.');
end

otp.utils.StructParser(newParameters) ...
.checkField('L', 'scalar', 'finite', 'positive');

end
end
end
7 changes: 7 additions & 0 deletions src/+otp/+kuramotosivashinsky/f.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function ut = f(~, u, k, k24)

u2 = fft(real(ifft(u)).^2);

ut = -k24.*u - (k/2).*u2;

end
5 changes: 5 additions & 0 deletions src/+otp/+kuramotosivashinsky/jac.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function j = jac(~, u, k, k24)

j = -diag(k24) - k.*ifft(fft(diag(real(ifft(u)))).').';

end
5 changes: 5 additions & 0 deletions src/+otp/+kuramotosivashinsky/javp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function jv = javp(~, u, v, k, k24)

jv = -k24.*v - fft(real(ifft(u)).*ifft(conj(k).*v));

end
5 changes: 5 additions & 0 deletions src/+otp/+kuramotosivashinsky/jvp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function jv = jvp(~, u, v, k, k24)

jv = -k24.*v - k.*fft(real(ifft(u)).*ifft(v));

end