Skip to content

Commit

Permalink
Maintenance for R2024b
Browse files Browse the repository at this point in the history
1) Update GitHub workflow with reports published as Pages
2) Update .gitignore to support new workflow
3) Add CollectData to Function Library rather than as local function to
   aid in testing
4) Remove hard-coded colors in cnPDE and explicitPDE
5) Include solutions in InstructorResources
6) Update testing structures in SoftwareTests
7) Minor updates to scripts
8) Reorganize the project to start/stop the ProjectStartupApp
  • Loading branch information
eszmw committed Oct 16, 2024
1 parent 554eb1b commit feb1ee1
Show file tree
Hide file tree
Showing 112 changed files with 1,546 additions and 607 deletions.
60 changes: 40 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ on:
branches: [ release ]
workflow_dispatch:

# Add permission to write GitHub pages
permissions:
contents: write
pages: write
id-token: write

jobs:
test:
strategy:
fail-fast: false
matrix:
MATLABVersion: [R2021a,R2021b,R2022a,R2022b,R2023a,R2023b,R2024a]
MATLABVersion: [R2024a,R2024b]
runs-on: ubuntu-latest
steps:
# Checks-out your repository
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Sets up a display server
- name: Start display server
Expand All @@ -32,14 +38,14 @@ jobs:
uses: matlab-actions/setup-matlab@v2
with:
release: ${{ matrix.MATLABVersion }}
products:
products: >
Symbolic_Math_Toolbox
Image_Processing_Toolbox
Computer_Vision_Toolbox
Statistics_and_Machine_Learning_Toolbox
Curve_Fitting_Toolbox
Statistics_and_Machine_Learning_Toolbox
Curve_Fitting_Toolbox
Automated_Driving_Toolbox
# Run all the tests
- name: Run SmokeTests
uses: matlab-actions/run-command@v2
Expand All @@ -48,10 +54,12 @@ jobs:

# Upload the test results as artifact
- name: Upload TestResults
uses: actions/[email protected]
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: TestResults
path: ./SoftwareTests/TestResults_${{ matrix.MATLABVersion }}.txt
name: TestResults_${{ matrix.MATLABVersion }}
path: ./public/*
overwrite: true

badge:
if: ${{ always() }}
Expand All @@ -62,26 +70,38 @@ jobs:
steps:

# Checks-out your repository
- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Sets up R2023b
- name: Setup MATLAB
uses: matlab-actions/setup-matlab@v1
uses: matlab-actions/setup-matlab@v2
with:
release: R2023b
release: R2024b

# Download the test results from artifact
- name: Download TestResults
uses: actions/download-artifact@v2.1.1
- name: Download All TestResults
uses: actions/download-artifact@v4
with:
name: TestResults
path: ./SoftwareTests/

path: public
pattern: TestResults_*
merge-multiple: true

# Create the test results badge
- name: Run CreateBadge
uses: matlab-actions/run-command@v1
- name: Run PostSmokeTest
uses: matlab-actions/run-command@v2
with:
command: openProject(pwd); PostSmokeTest;

# Deploy reports to GitHub pages
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload pages artifact
uses: actions/upload-pages-artifact@v3
with:
command: openProject(pwd); CreateBadge;
path: public
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

# Commit the JSON for the MATLAB releases badge
- name: Commit changed files
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,5 @@ Data/allStorms.csv
Scripts/myLakeData.mat
myLakeData.mat

# Test results
SoftwareTests/TestResults_*

# GitLab page folder
public/
31 changes: 10 additions & 21 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,30 @@ smoke-test:
# Make sure that the runner you plan to use matches the tags
- matlab
stage: test
parallel:
matrix:
- VERSION: [R2024a,R2024b]
script:
- matlab -batch "openProject(pwd);RunAllTests(true)"
- Set-Alias -Name matlab -Value "C:\Program Files\MATLAB\$VERSION\bin\matlab.exe"
- matlab -batch "openProject(pwd);RunAllTests"
when: always
allow_failure: true
artifacts:
name: "$VERSION"
paths:
- public/*
expire_in: 1 years
when: always


pages:
tags:
- matlab
stage: deploy
script:
- echo 'Deploying pages'
- matlab -batch "openProject(pwd);PostSmokeTest;"
artifacts:
paths:
- public

smoke-test-solution:
tags:
- matlab
stage: release
script:
- matlab -batch "proj = openProject(pwd);
addpath(genpath(proj.RootFolder));
results = runtests(fullfile('InternalFiles','Tests','CI','SolnSmokeTests.m'));
disp(table(results)); assertSuccess(results);"
rules:
# This test should always run when merging to main
# And be available for manual running on any push
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
when: always
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != $CI_DEFAULT_BRANCH
when: manual
allow_failure: true

file-test:
tags:
Expand Down Expand Up @@ -87,6 +75,7 @@ release-testing:
- matlab -batch "proj = openProject(pwd);
cd ..;
addpath(genpath(fullfile('utilities','TestingResources')));
addpath(genpath(fullfile('utilities','Tools')));
runCMTests"
rules:
# This test should always run when merging to main
Expand Down
Empty file removed FunctionLibrary/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion FunctionLibrary/CollectData.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
roi = drawpolygon(ax);
x = roi.Position(:,1);
y = roi.Position(:,2);
end
end
6 changes: 1 addition & 5 deletions FunctionLibrary/cnPDE.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@
% To visualize the outputs
hold on
delete(ax.Children(1:end-1));
try
plot(xVals,[alpha(j*dt);u;beta(j*dt)],LineWidth=1,SeriesIndex="none")
catch % If using R2023a or earlier
plot(xVals,[alpha(j*dt);u;beta(j*dt)],"k",LineWidth=1)
end
plot(xVals,[alpha(j*dt);u;beta(j*dt)],LineWidth=1,SeriesIndex="none")
subtitle("$t = $"+dt*j)
drawnow
pause(0.1)
Expand Down
6 changes: 1 addition & 5 deletions FunctionLibrary/explicitPDE.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@
% To visualize the outputs
hold on
delete(ax.Children(1:end-1));
try
plot(xVals,[alpha((j+1)*dt);u;beta((j+1)*dt)],LineWidth=4,SeriesIndex="none")
catch % If using R2023a or earlier
plot(xVals,[alpha((j+1)*dt);u;beta((j+1)*dt)],"k",LineWidth=4)
end
plot(xVals,[alpha((j+1)*dt);u;beta((j+1)*dt)],"LineWidth",4,SeriesIndex="none")
subtitle("$t = $"+dt*(j+1))
drawnow
pause(0.1)
Expand Down
80 changes: 80 additions & 0 deletions InstructorResources/Solutions/FunctionLibrarySolutions/cnPDESoln.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
function u = cnPDESoln(f,alpha,beta,tEnd,dx,gamma,L)
% Solve the 1D heat equation u_t = gamma*u_{xx} on a rod of length L
% using the Crank-Nicolson method
% u(t,0) = alpha(t)
% u(t,L) = beta(t)
% u(0,x) = f(x)
% The desired spatial resolution is dx
% Output is u = u(tEnd,x_m), a vector of values on the mesh points

% Define dt with reference to both error and stability concerns
% Optimal dt for stability
dtOpt = dx;
% Forcing an integer numbers of dt steps that terminate at tEnd
dt = tEnd/ceil(tEnd/dtOpt);

% % testing %%%%%%%%%%
% dt = 0.005;

% Set up the helper values for defining the required matrices
numRows = L/dx-1;
mu = gamma*dt/(dx^2);
baseDiag = ones(1,numRows);

% Define modA for the explicit updating rule
% modA-I = (A-I)/2, where I is the identity matrix
modA = gallery('tridiag',0.5*mu*baseDiag(1:end-1),(1-mu)*baseDiag,0.5*mu*baseDiag(1:end-1));

% Define modB for the implicit updating rule
% modB-I = (B-I)/2, where I is the identity matrix
modB = gallery('tridiag',-0.5*mu*baseDiag(1:end-1),(1+mu)*baseDiag,-0.5*mu*baseDiag(1:end-1));

% Initialize bAvg = b^(j)+b^(j+1) as a vector of zeros
bAvg = zeros(numRows,1);

% Define a spatial mesh vector
xVals = linspace(0,L,round(L/dx)+1);

% Set up a column vector u0 of the initial values of u when t=0
u0 = f(xVals)';

% Initialize the output to the interior points of u0
u = u0(2:end-1);

% To visualize the outputs
p = plot(xVals,u0,"LineWidth",2,"SeriesIndex",1);
ax = p.Parent;

% Set the y limits to reasonable fixed values
minAlpha = min(alpha(0:dt:tEnd));
maxAlpha = max(alpha(0:dt:tEnd));
minBeta = min(beta(0:dt:tEnd));
maxBeta = max(beta(0:dt:tEnd));
yLower = min([ax.YLim(1),minAlpha,minBeta]);
yUpper = max([ax.YLim(2),maxAlpha,maxBeta]);
scale = (yUpper-yLower)*0.05;
ax.YLim = [yLower-scale yUpper+scale];

title("Solving $\frac{\partial u}{\partial t} = \gamma \frac{\partial^2 u}{\partial x^2}$ with Crank-Nicolson","Interpreter","latex")
subtitle("$t=0$","Interpreter","latex")
xlabel("$x$","Interpreter","latex")
ylabel("$u$","Interpreter","latex")

% Compute new values for halfB*u^(j+1)-b^(j+1) = halfA*u^(j)+b^(j)
% Loop over timesteps to reach tEnd
for j = 1:(tEnd/dt)
bAvg(1) = mu*(alpha((j-1)*dt)+alpha(j*dt))/2;
bAvg(end) = mu*(beta((j-1)*dt)+beta(j*dt))/2;
u = modB\(modA*u+bAvg);
% To visualize the outputs
hold on
delete(ax.Children(1:end-1));
plot(xVals,[alpha(j*dt);u;beta(j*dt)],"LineWidth",2,"SeriesIndex",2)
subtitle("$t = $"+dt*j)
drawnow
pause(0.1)
hold off
% End visualization code
end
legend(["u(0,x)","u(t,x)"],"Location","north")
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
function u = cnPDE(u0,alpha,beta,tEnd,dx,gamma,L,t0)
% Solve the 1D heat equation u_t = gamma*u_{xx} on a rod of length L
% using the Crank-Nicolson method
% u(t,0) = alpha(t)
% u(t,L) = beta(t)
% u(t0,x) = u0
% The desired spatial resolution is dx
% Output is u = u(tEnd,x_m), a vector of values on the mesh points

% Define dt with reference to both error and stability concerns
% Optimal dt for stability
dtOpt = dx;
% Forcing an integer numbers of dt steps that terminate at tEnd
dt = tEnd/ceil((tEnd-t0)/dtOpt);

% % testing %%%%%%%%%%
% dt = 0.005;

% Set up the helper values for defining the required matrices
numRows = L/dx-1;
mu = gamma*dt/(dx^2);
baseDiag = ones(1,numRows);

% Define modA for the explicit updating rule
% modA-I = (A-I)/2, where I is the identity matrix
modA = gallery('tridiag',0.5*mu*baseDiag(1:end-1),(1-mu)*baseDiag,0.5*mu*baseDiag(1:end-1));

% Define modB for the implicit updating rule
% modB-I = (B-I)/2, where I is the identity matrix
modB = gallery('tridiag',-0.5*mu*baseDiag(1:end-1),(1+mu)*baseDiag,-0.5*mu*baseDiag(1:end-1));

% Initialize bAvg = b^(j)+b^(j+1) as a vector of zeros
bAvg = zeros(numRows,1);

% Define a spatial mesh vector
xVals = linspace(0,L,round(L/dx)+1);

% Initialize the output to the interior points of u0
u = u0(2:end-1);

% To visualize the outputs
p = plot(xVals,u0,"LineWidth",4);
ax = p.Parent;

% Set the y limits to reasonable fixed values
minAlpha = min(alpha(0:dt:tEnd));
maxAlpha = max(alpha(0:dt:tEnd));
minBeta = min(beta(0:dt:tEnd));
maxBeta = max(beta(0:dt:tEnd));
yLower = min([ax.YLim(1),minAlpha,minBeta]);
yUpper = max([ax.YLim(2),maxAlpha,maxBeta]);
scale = (yUpper-yLower)*0.05;
ax.YLim = [yLower-scale yUpper+scale];

title("Solving $\frac{\partial u}{\partial t} = \gamma \frac{\partial^2 u}{\partial x^2}$","Interpreter","latex")
subtitle("$t=0$","Interpreter","latex")
xlabel("$x$","Interpreter","latex")
ylabel("$u$","Interpreter","latex")

% Compute new values for halfB*u^(j+1)-b^(j+1) = halfA*u^(j)+b^(j)
% Loop over timesteps to reach tEnd
for j = 0:(tEnd/dt - 1)
bAvg(1) = mu*(alpha(j*dt)+alpha((j+1)*dt))/2;
bAvg(end) = mu*(beta(j*dt)+beta((j+1)*dt))/2;
u = modB\(modA*u+bAvg);
% To visualize the outputs
hold on
delete(ax.Children(1:end-1));
plot(xVals,[alpha((j+1)*dt);u;beta((j+1)*dt)],"LineWidth",4,SeriesIndex="none")
subtitle("$t = $"+dt*(j+1))
drawnow
pause(0.1)
hold off
% End visualization code
end

end
Loading

0 comments on commit feb1ee1

Please sign in to comment.