Skip to content

Conversation

@lkncl
Copy link

@lkncl lkncl commented Dec 3, 2025

fixes #69
fixes #41

Summary

This PR fixes a bug where calling make_lstar1 with identical inputs returns inconsistent L* values.
The issue originates from the COMMON /flag_L/ Ilflag variable, which is used inside calcul_Lstar_opt to decide whether to reuse a predicted foot-point (when Ilflag = 1) or compute a new linear estimate (when Ilflag = 0).

Previously:

Ilflag was only initialized to 0 inside make_lstar1.
After the first successful L* computation, Ilflag became 1 and was not reset before subsequent calls.
This caused calcul_Lstar_opt to reuse the last theta value from previous calls, leading to inconsistent L* results for identical inputs.
This bug only affects make_lstar1: all other routines calling calcul_Lstar_opt do not rely on the returned value of Ilflag.

grep -rnw source/ -e "calcul_Lstar_opt"
source/calcul_Lstar_o.f:37:       call calcul_Lstar_opt(t_resol,r_resol,
source/calcul_Lstar_o.f:42:       SUBROUTINE calcul_Lstar_opt(t_resol,r_resol,
source/AE8_AP8.f:163:      CALL calcul_Lstar_opt(t_resol,r_resol,xGEO
source/onera_desp_lib.f:130:           CALL calcul_Lstar_opt(t_resol,r_resol,XGeo
source/onera_desp_lib.f:238:           CALL calcul_Lstar_opt(t_resol,r_resol,xGEO
source/onera_desp_lib.f:246:               CALL calcul_Lstar_opt(t_resol,r_resol,xGEOp(1,ipa)
source/onera_desp_lib.f:1761:           CALL calcul_Lstar_opt(t_resol,r_resol,xGeo
source/onera_desp_lib.f:1774:               CALL calcul_Lstar_opt(t_resol,r_resol,xGEOp(1,ipa)
source/AFRL_CRRES_models.f:143:           CALL calcul_Lstar_opt(t_resol,r_resol,xGEO

I have checked that the logic around these calls does not involves Ilflag. Moreoever, make_lstar_shell_splitting1, make_lstar_shell_splitting2 already have a Ilflag=0 line before each call.

What this PR changes
✔️ 1. Removed the handling of Ilflag from the caller (make_lstar1)

make_lstar1 no longer uses Ilflag
The logic related to Ilflag_old and the fallback call has been removed.

✔️ 2. Ilflag is now always initialized to 0 inside calcul_Lstar_opt

This ensures deterministic behavior: each computation starts cleanly and does not reuse stale state.

✔️ 3. Removed the conditional branch based on Ilflag

Outcome

After this fix, calling make_lstar1 multiple times with identical parameters now returns consistent L*, Lm, B, Beq, I, and MLT values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make_lstar1 returns inconsistent L* values for identical inputs Difference in vectorised and looped Lm/Lstar calculations

1 participant