-
Notifications
You must be signed in to change notification settings - Fork 3
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
AndreyAPopov
wants to merge
17
commits into
master
Choose a base branch
from
Kuramoto-Sivashinsky
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b849181
Initial Commit of KS
AndreyAPopov c7beadc
Completely changed the problem to be spectral
AndreyAPopov e2f3c6a
Made jacobian more optimal; other
AndreyAPopov dd2f38a
Added Jacobian Adjoint (conjugate as well) vector product.
AndreyAPopov 09e0966
added citation and fixed the tspan
AndreyAPopov 7e63fe2
applied fixes
AndreyAPopov 6445c3c
Merge branch 'master' into Kuramoto-Sivashinsky
AndreyAPopov 91d439c
Steven's changes all implemented.
AndreyAPopov 9a8a63c
more of steven's fixes
AndreyAPopov 3eb99cd
added a comment for future idiot me
AndreyAPopov c1bf87e
Change initial condition to always be periodic.
AndreyAPopov 1b53abc
Added the preset from Sol ODES2
AndreyAPopov 33b0987
Minor fix to N
AndreyAPopov 09f0c92
tspan fix
AndreyAPopov 8c0e7a3
Improvements for Jacobian and JAVP
Steven-Roberts 590b7dd
Merge branch 'master' into Kuramoto-Sivashinsky
AndreyAPopov f9af33c
Updated for new format, and validated all derivatives.
AndreyAPopov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
|
||
u0hat = fft(u0); | ||
|
||
tspan = [0, 150]; | ||
|
||
obj = [email protected](tspan, u0hat, params); | ||
|
||
end | ||
end | ||
end |
57 changes: 57 additions & 0 deletions
57
src/+otp/+kuramotosivashinsky/KuramotoSivashinskyProblem.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
Steven-Roberts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.