-
Notifications
You must be signed in to change notification settings - Fork 65
Adding KP-I example to the example folder for MOLE #119
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
tcalderon-space
wants to merge
1
commit into
csrc-sdsu:master
Choose a base branch
from
tcalderon-space:tcalderon-space/kp_example
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 all commits
Commits
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 hidden or 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,99 @@ | ||
| clear; | ||
| clc; | ||
|
|
||
| % path to mimetic operators | ||
| addpath('C:\Users\littl\sdsu\comp670\calderonTE-master\calderonTE\src\matlab'); | ||
|
|
||
| % Parameters | ||
| k = 2; % Order of accuracy | ||
| m = 99; % Number of cells along x-axis | ||
| n = m; % Number of cells along y-axis | ||
|
|
||
| a = 1; % Used for solution | ||
| b = 0.5; % Used for solution | ||
|
|
||
| % Spatial Discretization | ||
| x_1 = -10; | ||
| x_2 = 10; | ||
| y_1 = -10; | ||
| y_2 = 10; | ||
| dx = (x_2 - x_1) / m; | ||
| dy = (y_2 - y_1) / n; | ||
| dt = dx; | ||
|
|
||
| % Staggered grid | ||
| xgrid = [x_1, x_1+dx/2:dx:x_2-dx/2, x_2]; | ||
| ygrid = [y_1, y_1+dy/2:dy:y_2-dy/2, y_2]; | ||
|
|
||
| num_steps = 1; | ||
| tgrid = 0:dt:(num_steps * dt); | ||
|
|
||
| % Mesh-grid implementation | ||
| [Y, X, T] = meshgrid(ygrid, xgrid, tgrid); | ||
|
|
||
| % Interpolation operators | ||
| I = interpolCentersToFacesD2D(k,m,n); | ||
| Ix = I(1:(n+2)*(m+2), 1:n*(m+1)); | ||
| Iy = I((n+2)*(m+2)+1:end, n*(m+1)+1:end); | ||
|
|
||
|
|
||
| % Mimetic operators | ||
| G = grad2D(k, m, dx, n, dy); | ||
| Gx = G(1:end/2, :); % Gradient in x-direction (size: (m+1) x (m+2)) | ||
| Gy = G(end/2+1:end,:); % Gradient in y-direction | ||
|
|
||
| D = div2D(k, m, dx, n, dy); | ||
| Dx = D(:, 1:end/2); % Divergence in x-direction | ||
| Dy = D(:,end/2+1:end); % Divergence in y-direction | ||
|
|
||
|
|
||
| Lyy = Dy*Gy; | ||
| Lxx = Dx*Gx; | ||
| Lxxxx = Lxx*Lxx; | ||
| Lx = Ix*Gx; | ||
|
|
||
| % Initial condition | ||
| num = - (X + a*Y + 3*T*(a^2 - b^2)).^2 + b^2*(Y + 6*a*T).^2 + (1/b^2); | ||
| den = ( (X + a*Y + 3*T*(a^2 - b^2)).^2 + b^2*(Y + 6*a*T).^2 + (1/b^2) ).^2; | ||
| u0 = 4 * num ./ den; %exact solution | ||
|
|
||
| u = u0(:,:,1); | ||
| u = reshape(u,[],1); % Vectorize [49x1] | ||
|
|
||
| % Boundary conditions (Dirichlet: u=0 at all boundaries) | ||
| dc = [1; 1; 1; 1]; % Dirichlet flags | ||
| nc = [0; 0; 0; 0]; % Neumann flags | ||
|
|
||
| v = cell(4,1); | ||
| v{1} = zeros(n,1); % Left BC | ||
| v{2} = zeros(n,1); % Right BC | ||
| v{3} = zeros(m+2,1); % Bottom BC | ||
| v{4} = zeros(m+2,1); % Top BC | ||
|
|
||
| % Time-stepping | ||
| for t = 1:num_steps | ||
|
|
||
| u_at_faces = Ix.' * u; | ||
| M1 = Ix * diag(u_at_faces) * Gx; | ||
|
|
||
| % Build system matrix | ||
| A = Lx - dt*(6*M1 + Lxxxx - 3*Lyy); | ||
| b = u + dt*(6*M1 + Lxxxx - 3*Lyy)*u; | ||
|
|
||
| % Apply boundary conditions | ||
| [A0, b0] = addBC2D(A, b, k, m, dx, n, dy, dc, nc, v); | ||
|
|
||
| % Solve | ||
| u = A0 \ b0; | ||
|
|
||
| u_2d = reshape(u, m+2, n+2); | ||
|
|
||
|
|
||
| if t <= size(X,3) | ||
| surf(X(:,:,t), Y(:,:,t), u_2d); | ||
| title(['KP-I Solution at t = ', num2str(t)]); | ||
| xlabel('x'); ylabel('y'); zlabel('u'); | ||
| colorbar; | ||
| drawnow; | ||
| end | ||
| 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.
Hi @tcalderon-space , thank you so much for considering contributing to MOLE!
Perhaps here you meant to use this line for testing/debugging purposes, using only 1 time step? Thank you!