|
| 1 | +% file s_test_suite_equilibrium.m |
| 2 | +% brief contains script to test for equilibrium conditions |
| 3 | + |
| 4 | +% brief This script runs both the finite difference and spectral codes to |
| 5 | +% test that initial equilibrium conditions are satisfied |
| 6 | +clc; |
| 7 | +clear; |
| 8 | + |
| 9 | +addpath('../toolchain/'); |
| 10 | +addpath('../src/forward_solver/'); |
| 11 | + |
| 12 | +num_tests = 4*2*2*2*5; |
| 13 | +errors_fd = zeros(num_tests,1); |
| 14 | +errors_sp = zeros(num_tests,1); |
| 15 | +failed_tests = zeros(size(errors_sp)); |
| 16 | +% define threshold |
| 17 | +threshold = 1e-2; |
| 18 | + |
| 19 | +fprintf('Checking L2 norm errors...\n'); |
| 20 | + |
| 21 | +% equilibrium test case |
| 22 | +masstrans = 0; |
| 23 | +collapse = 0; |
| 24 | +Req = 10e-6; |
| 25 | +R0 = Req; |
| 26 | +T8 = 298.15; |
| 27 | +tfin = 2e-3; |
| 28 | +tvector = linspace(0,tfin,1000); |
| 29 | +mu = 0.5; |
| 30 | +wave_type = 1; |
| 31 | +dt = 3e-4; |
| 32 | +tw = 1e-4; |
| 33 | +pA = 1e5; |
| 34 | +% equation options |
| 35 | +count = 1; |
| 36 | +for radial = 1:4 |
| 37 | + for bubtherm = 0:1 |
| 38 | + for medtherm = 0:1 |
| 39 | + for vapor = 0:1 |
| 40 | + for stress = 1:5 |
| 41 | + if bubtherm == 0 && medtherm == 1 |
| 42 | + count = count + 2; |
| 43 | + continue; |
| 44 | + end |
| 45 | + varin = {'radial',radial,... |
| 46 | + 'bubtherm',bubtherm,... |
| 47 | + 'masstrans',masstrans,... |
| 48 | + 'tvector',tvector,... |
| 49 | + 'vapor',vapor,... |
| 50 | + 'medtherm',medtherm,... |
| 51 | + 'stress',stress,... |
| 52 | + 'collapse',collapse,... |
| 53 | + 'method',23,... |
| 54 | + 'Req',Req,... |
| 55 | + 'mu',mu,... |
| 56 | + 'R0',R0,... |
| 57 | + 't8',T8,... |
| 58 | + 'wave_type',wave_type,... |
| 59 | + 'dt',dt,... |
| 60 | + 'tw',tw,... |
| 61 | + 'pA',pA}; |
| 62 | + [ttest,Rf_test] = f_imr_fd(varin{:},'Nt',50,'Mt',50); |
| 63 | + plot(ttest,Rf_test) |
| 64 | + errors_fd(count) = abs(1-Rf_test(end)); |
| 65 | + fprintf('Test %d: L2 norm error = %.6e\n', count, errors_fd(count)); |
| 66 | + [~,Rs_test] = f_imr_spectral(varin{:},'Nt',12,'Mt',12); |
| 67 | + errors_sp(count) = abs(Rs_test(1)-Rs_test(end)); |
| 68 | + fprintf('Test %d: L2 norm error = %.6e\n', count+1, errors_sp(count)); |
| 69 | + if ( errors_fd(count) > threshold ) |
| 70 | + failed_tests(count) = count; |
| 71 | + end |
| 72 | + if ( errors_sp(count) > threshold ) |
| 73 | + failed_tests(count+1) = count+1; |
| 74 | + end |
| 75 | + count = count + 2; |
| 76 | + end |
| 77 | + end |
| 78 | + end |
| 79 | + end |
| 80 | +end |
| 81 | + |
| 82 | +% Find the last non-empty cell index |
| 83 | +lastNonEmptyIdx = find(failed_tests ~= 0, 1, 'last'); |
| 84 | +% Truncate the array, keeping empty cells within range |
| 85 | +failed_tests = failed_tests(1:lastNonEmptyIdx); |
| 86 | + |
| 87 | +% Remove zeros from failed_tests |
| 88 | +failed_tests(failed_tests == 0) = []; |
| 89 | + |
| 90 | +if isempty(failed_tests) |
| 91 | + fprintf('✅ All tests PASSED.\n'); |
| 92 | + % Success |
| 93 | + exit(0); |
| 94 | +else |
| 95 | + fprintf('❌ Tests FAILED at indices: %s\n', sprintf('%d ', failed_tests)); |
| 96 | + % Fail the workflow |
| 97 | + exit(1); |
| 98 | +end |
0 commit comments