From 923255b156e455cfd3f551b9084ab4da700ebc79 Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Fri, 4 Apr 2025 15:05:05 +0200
Subject: [PATCH] Prepare model_maker to accept random generators

---
 src/scripts/model_maker.py | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/src/scripts/model_maker.py b/src/scripts/model_maker.py
index 10b10d0f..cfb0e28e 100755
--- a/src/scripts/model_maker.py
+++ b/src/scripts/model_maker.py
@@ -247,7 +247,7 @@ def load_model(model_file):
             print("ERROR: %s is not a supported scaling mode!"%(model['radiation_settings']['scale_name']))
             return (None, None)
         sph_types = model['particle_settings']['sph_types']
-        if (len(sph_types) != sconf['nsph']):
+        if (len(sph_types) != sconf['nsph'] and len(sph_types) != 0):
             print("ERROR: vector of sphere types does not match the declared number of spheres!")
             return (None, None)
         else:
@@ -313,20 +313,30 @@ def load_model(model_file):
         gconf['vec_sph_y'] = [0.0 for i in range(gconf['nsph'])]
         gconf['vec_sph_z'] = [0.0 for i in range(gconf['nsph'])]
         if (gconf['application'] != "SPHERE" or gconf['nsph'] != 1):
-            # TODO: put here a test to allow for empty vectors in case of random generation
-            if (len(model['geometry_settings']['x_coords']) != gconf['nsph']):
-                print("ERROR: X coordinates do not match the number of spheres!")
+            if (len(model['geometry_settings']['x_coords']) != len(model['geometry_settings']['y_coords'])):
+                print("ERROR: X and Y coordinate vectors have different lengths!")
+                return (None, None)
+            if (len(model['geometry_settings']['x_coords']) != len(model['geometry_settings']['z_coords'])):
+                print("ERROR: X and Z coordinate vectors have different lengths!")
                 return (None, None)
-            if (len(model['geometry_settings']['y_coords']) != gconf['nsph']):
-                print("ERROR: Y coordinates do not match the number of spheres!")
+            if (len(model['geometry_settings']['y_coords']) != len(model['geometry_settings']['z_coords'])):
+                print("ERROR: Y and Z coordinate vectors have different lengths!")
                 return (None, None)
-            if (len(model['geometry_settings']['z_coords']) != gconf['nsph']):
-                print("ERROR: Z coordinates do not match the number of spheres!")
+            if (len(model['particle_settings']['sph_types']) == 0 and len(model['geometry_settings']['x_coords']) != 0):
+                print("ERROR: random type assignment is not allowed with assigned coordinates!")
                 return (None, None)
-            for si in range(gconf['nsph']):
-                gconf['vec_sph_x'][si] = float(model['geometry_settings']['x_coords'][si])
-                gconf['vec_sph_y'][si] = float(model['geometry_settings']['y_coords'][si])
-                gconf['vec_sph_z'][si] = float(model['geometry_settings']['z_coords'][si])
+            # TODO: put here a test to allow for empty vectors in case of random generation
+            if (len(model['geometry_settings']['x_coords']) == 0):
+                # Generate random cluster
+                print("DEBUG: would generate random cluster.")
+            else:
+                if (len(model['geometry_settings']['x_coords']) != gconf['nsph']):
+                    print("ERROR: coordinate vectors do not match the number of spheres!")
+                    return (None, None)
+                for si in range(gconf['nsph']):
+                    gconf['vec_sph_x'][si] = float(model['geometry_settings']['x_coords'][si])
+                    gconf['vec_sph_y'][si] = float(model['geometry_settings']['y_coords'][si])
+                    gconf['vec_sph_z'][si] = float(model['geometry_settings']['z_coords'][si])
     else: # model is None
         print("ERROR: could not parse " + model_file + "!")
     return (sconf, gconf)
-- 
GitLab