From 73f2154ac74c34ca38a418abc82466d773a950bd Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Wed, 30 Apr 2025 18:37:27 +0200
Subject: [PATCH] Use adaptive LM definition in SPHERE wavelength loop

---
 src/sphere/sphere.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/sphere/sphere.cpp b/src/sphere/sphere.cpp
index 288c259f..d9a1fd34 100644
--- a/src/sphere/sphere.cpp
+++ b/src/sphere/sphere.cpp
@@ -576,6 +576,12 @@ int sphere_jxi488_cycle(
     oi->vec_vk[jxindex] = vk;
     oi->vec_xi[jxindex] = xi;
   }
+  // Adaptive definition of L_MAX
+  double wavelength = 2.0 * pi / vk;
+  double size_param = 2.0 * pi * sconf->get_radius(0) / wavelength;
+  int N = int(size_param + 4.05 * pow(size_param, 1.0 / 3.0)) + 2;
+  if (N < l_max) l_max = N;
+  // End of adaptive definition of L_MAX
   vtppoanp->append_line(VirtualBinaryLine(vk));
   double thsca = (gconf->isam > 1) ? sa->ths - sa->th : 0.0;
   for (int i132 = 0; i132 < nsph; i132++) {
-- 
GitLab