From abbc7b1b503907afd565fa9256d3a1bf67b9c0af Mon Sep 17 00:00:00 2001 From: Anto01 Date: Tue, 20 Jan 2026 15:29:29 -0500 Subject: [PATCH] feat: Add detailed Nastran memory error detection in run-baseline - Parse Nastran log file to detect memory allocation failures - Extract requested vs available memory from log - Provide actionable error message with specific values - Include log files in result_files response --- .../backend/api/routes/optimization.py | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/atomizer-dashboard/backend/api/routes/optimization.py b/atomizer-dashboard/backend/api/routes/optimization.py index ec924f4b..1b51fc75 100644 --- a/atomizer-dashboard/backend/api/routes/optimization.py +++ b/atomizer-dashboard/backend/api/routes/optimization.py @@ -4706,6 +4706,33 @@ async def run_baseline_simulation(study_id: str): op2_files = list(baseline_dir.glob("*.op2")) f06_files = list(baseline_dir.glob("*.f06")) bdf_files = list(baseline_dir.glob("*.bdf")) + list(baseline_dir.glob("*.dat")) + log_files = list(baseline_dir.glob("*.log")) + + # Parse Nastran log for specific error messages + error_details = result.get("errors", []) + memory_error = False + if not result.get("success") and log_files: + try: + with open(log_files[0], "r") as f: + log_content = f.read() + if "Unable to allocate requested memory" in log_content: + memory_error = True + # Extract memory request info + import re + + mem_match = re.search(r"Requested size = (\d+) Gbytes", log_content) + avail_match = re.search( + r"Physical memory available:\s+(\d+) MB", log_content + ) + if mem_match and avail_match: + requested = int(mem_match.group(1)) + available = int(avail_match.group(1)) / 1024 # Convert to GB + error_details.append( + f"Nastran memory allocation failed: Requested {requested}GB but only {available:.1f}GB available. " + "Try closing other applications or reduce memory in nastran.rcf" + ) + except Exception: + pass return { "success": result.get("success", False), @@ -4717,11 +4744,16 @@ async def run_baseline_simulation(study_id: str): "op2": [f.name for f in op2_files], "f06": [f.name for f in f06_files], "bdf": [f.name for f in bdf_files], + "log": [f.name for f in log_files], }, - "errors": result.get("errors", []), + "errors": error_details, "message": "Baseline simulation complete" if result.get("success") - else "Simulation failed", + else ( + "Nastran out of memory - close other applications and retry" + if memory_error + else "Simulation failed" + ), } except ImportError as e: