@@ -192,6 +192,41 @@ def extract_size_from_partition(partition_name):
192192 )
193193
194194
195+ def generate_sections_file (size , partitions , destination ):
196+ """
197+ Generates the C file and copies it to the specified build directory.
198+ """
199+ filename = "sections.c"
200+ partition_size = size // partitions
201+
202+ c_code = f"""int
203+ getSection(int i)
204+ {{
205+ int partition_size = { partition_size } ;
206+ int ret = ((i - 1) / partition_size) + 1;
207+ return (ret);
208+ }}
209+ """
210+ try :
211+ # 1. Write the file
212+ with open (filename , "w" ) as f :
213+ f .write (c_code )
214+ print (f"Successfully generated '{ filename } ' with partition_size { partition_size } ." )
215+
216+ # 2. Copy the file to the destination
217+ if not os .path .exists (destination ):
218+ print (f"Error: Destination directory '{ destination } ' does not exist." )
219+ return
220+
221+ shutil .copy (filename , destination )
222+ print (f"Successfully copied '{ filename } ' to '{ destination } '." )
223+
224+ except IOError as e :
225+ print (f"An error occurred during file operations: { e } " )
226+ except PermissionError :
227+ print (f"Permission denied: Unable to write to '{ destination } '." )
228+
229+
195230def execute_simulation (model_path , partition_name ):
196231 """
197232 Compiles and executes the model dynamically, assigning N size constraints first.
@@ -200,6 +235,7 @@ def execute_simulation(model_path, partition_name):
200235
201236 model_p = Path (model_path ).resolve ()
202237 model_file = str (model_p )
238+ model = file_handlers .get_file_name (model_file )
203239
204240 partition_p = Path (partition_name ).resolve ()
205241
@@ -209,11 +245,15 @@ def execute_simulation(model_path, partition_name):
209245
210246 # Derive target destination (<model_name>.part in the model's directory)
211247 target_partition_path = model_p .with_suffix ('.part' )
212-
248+ build_target_path = new_path = Path (os .environ ['MMOC_BUILD' ]) / model
249+ print ("BUILD TARGET" )
250+ print (build_target_path )
251+
213252 # Step 1: Copy custom partition to the required solver location
214253 try :
215254 print (f"Copying partition: { partition_p .name } -> { target_partition_path } " )
216255 shutil .copy2 (Path (partition_name ).resolve (), target_partition_path )
256+ shutil .copy2 (target_partition_path , build_target_path )
217257 except Exception as e :
218258 print (f"Failed to copy partition file: { e } " )
219259 return False
@@ -225,8 +265,9 @@ def execute_simulation(model_path, partition_name):
225265 print (f"Current structural Constants: { current_constants } " )
226266
227267 # Updating constant N size property
228- set_constants (model_file , {"N" : size })
268+ set_constants (model_file , {"N" : size , "SECTIONS" : parts })
229269 print (f"Successfully set Constant 'N' to: { size } " )
270+ print (f"Successfully set Constant 'SECTIONS' to: { parts } " )
230271
231272 except Exception as e :
232273 print (f"Failed handling structural setup attributes: { e } " )
@@ -247,7 +288,10 @@ def execute_simulation(model_path, partition_name):
247288 print (f" { key } : { value } " )
248289 else :
249290 print (" No annotations found" )
250-
291+
292+ if model == "airconds_cont" :
293+ generate_sections_file (size , parts , build_target_path )
294+
251295 # Step 3: Compile the model
252296 print (f"\n Compiling model: { model_file } " )
253297 if compile_model (model_file ):
@@ -265,7 +309,6 @@ def execute_simulation(model_path, partition_name):
265309 return False
266310
267311 # Step 5: Get simulation results
268- model = file_handlers .get_file_name (model_file )
269312 model_log_path = file_handlers .get_full_path (model , 'MMOC_LOG' )
270313 sim_results (model_log_path )
271314 process_model_logs (file_handlers .get_base_path (model_log_path , 'MMOC_LOG' ), model , sim_results )
@@ -306,4 +349,4 @@ def main():
306349
307350
308351if __name__ == "__main__" :
309- main ()
352+ main ()
0 commit comments