Fix mass extraction + db close order + nan handling

- Journal now extracts p173 mass expression and writes _temp_mass.txt
- history.get_study_summary() called before history.close()
- Optuna nan rejection: fallback to INFEASIBLE_MASS penalty
- pyNastran warning 'nx 2512 not supported' is harmless (reads fine)
This commit is contained in:
2026-02-11 16:29:45 +00:00
parent 0229ce53bb
commit 93a5508c07
2 changed files with 33 additions and 2 deletions

View File

@@ -1170,6 +1170,31 @@ def solve_simple_workflow(
f"[JOURNAL] Solve completed: {numsolved} solved, {numfailed} failed, {numskipped} skipped"
)
# Extract mass from geometry part expression (p173) and write to temp file
try:
mass_value = None
# Find geometry part (Beam.prt)
for part in theSession.Parts:
part_type = type(part).__name__
if "fem" not in part_type.lower() and "sim" not in part_type.lower():
# This is the geometry part — look for mass expression
for expr in part.Expressions:
if expr.Name == "p173":
mass_value = expr.Value
print(f"[JOURNAL] Mass expression p173 = {mass_value}")
break
break
if mass_value is not None:
mass_file = os.path.join(working_dir, "_temp_mass.txt")
with open(mass_file, "w") as f:
f.write(f"p173={mass_value}\n")
print(f"[JOURNAL] Wrote mass to {mass_file}")
else:
print(f"[JOURNAL] WARNING: Could not find mass expression p173")
except Exception as e:
print(f"[JOURNAL] WARNING: Mass extraction failed: {e}")
# Save all
try:
anyPartsModified, partSaveStatus = theSession.Parts.SaveAll()