Repository navigation
Fix Simpson's rule for an odd number of intervals - #36
Merged
Merged
Conversation
SIMPSONS_RULE assumed an even number of intervals. With an odd number, the last interval counted at about two thirds of its value, so the integral was too low. CALC_PLANCK_TBL passes an odd number for about half of all bands and temperatures, which made the Planck table written by prep_spec too low, by up to 0.5 % at 2604 K for a file with 4096 bands of equal width. With an odd number of intervals, the last three intervals now use Simpson's 3/8 rule, and a single interval uses the trapezoidal rule. Results for an even number of intervals do not change.
5 of 8 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
SIMPSONS_RULEassumed an even number of intervals. With an odd number, the last interval counted at about two thirds of its value.CALC_PLANCK_TBLpasses an odd number for about half of all bands and temperatures. As a result, the Planck table thatprep_specwrites in block 6 was too low. For a file with 4096 bands of equal width, the error was 0.5 % at 2604 K and 0.9 % at 4494 K.With an odd number of intervals, the routine now uses Simpson's 3/8 rule over the last three intervals. A single interval uses the trapezoidal rule. Results for an even number of intervals do not change. One side effect: N = 0 now returns 0 instead of
INPUT_ARRAY(0)*DELTA/3.The filter function and polynomial fit options of block 6 call the same routine, so they also get the fix.
Ccorr_kdoes not use this routine. The version is now 2607.3.Closes #35
Validation of changes
Test configuration: Fedora 44, x86-64, GNU Fortran 16.2.1. Built with
./configure && ./build_code(-Ofast -march=native). The build has no warnings forsimpsons_rule.f.Integrator alone: I compiled a small driver against the old and new
simpsons_rule.fand integrated over [0, 1] with N = 1 to 12 intervals.Planck table: I ran the old and new
prep_specon copies of three spectral files, with the same inputs that AGNI uses:I then compared each band of the table with 64-point Gauss-Legendre quadrature of the Planck function. 128-point quadrature agrees to 1e-14.
Sum of the table over all bands, divided by sigma T^4, for a file with 4096 bands from 10 to 50000 cm-1:
Largest relative difference from quadrature, over bands that carry more than 1e-6 of sigma T^4, at the same five temperatures:
The remaining difference of about 1e-4 also appears in the old build where the interval count was already even, so the integration does not cause it. I did not trace it.
Regression tests: I started
examples/quick_testswith this build but it did not finish. The first test (runes) reportedFiles output.txt and gfortran_8_1_0.txt differ, and the same for the ifort reference. I have not checked whether the build without this change gives the same differences. A later test then looped on+++ Unexpected response:, and I stopped the run. I did not runexamples/slow_tests, the Fortitude lint, or a full AGNI run with this build.Checklist