File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727- Fixed a bug that prevented ` .ci-pipelines/ci-cleanup-script.sh ` from removing KPP-generated files for MCM mechanisms
2828- Fixed typo in error message in ` int/rosenbrock_autoreduce.f90 `
2929- Fixed several issues in ` int/runge_kutta.c ` that were causing numerical instability or non-deterministic results
30+ - Fixed computation of sun angle in ` util/UpdateSun.c ` to ensure deterministic behavior
3031
3132### Removed
3233- Removed C-I tests on Microsoft Azure Dev Pipelines
Original file line number Diff line number Diff line change @@ -2,12 +2,30 @@ void Update_SUN()
22{
33KPP_REAL SunRise , SunSet ;
44KPP_REAL Thour , Tlocal , Ttmp ;
5+ KPP_REAL days ;
56const KPP_REAL PI = 3.14159265358979 ;
67
78 SunRise = 4.5 ;
89 SunSet = 19.5 ;
910 Thour = TIME /3600.0 ;
10- Tlocal = Thour - ((int )Thour /24 )* 24 ;
11+ // Calculate integer number of days, handling both positive and negative correctly
12+ // Use explicit floor operation: for positive values, truncation works;
13+ // for negative, we need floor behavior
14+ // Fix generated by AI and implemented by @yantosca, 31 Oct 2025
15+ if (Thour >= 0.0 ) {
16+ days = (KPP_REAL )((long )(Thour / 24.0 ));
17+ } else {
18+ /* For negative, subtract 1 to get floor behavior */
19+ days = (KPP_REAL )((long )(Thour / 24.0 ));
20+ if ((Thour - days * 24.0 ) < 0.0 ) {
21+ days -= 1.0 ;
22+ }
23+ }
24+ Tlocal = Thour - days * 24.0 ;
25+ // Ensure Tlocal is in [0, 24) range for determinism
26+ // Fix generated by AI and implemented by @yantosca, 31 Oct 2025
27+ if (Tlocal >= 24.0 ) Tlocal -= 24.0 ;
28+ if (Tlocal < 0.0 ) Tlocal += 24.0 ;
1129
1230 if ( (Tlocal >= SunRise ) && (Tlocal <= SunSet ) ) {
1331 Ttmp = (2.0 * Tlocal - SunRise - SunSet )/(SunSet - SunRise );
You can’t perform that action at this time.
0 commit comments