diff --git a/optimization_engine/nx/solve_simulation.py b/optimization_engine/nx/solve_simulation.py index 86f2681c..7431780a 100644 --- a/optimization_engine/nx/solve_simulation.py +++ b/optimization_engine/nx/solve_simulation.py @@ -934,10 +934,21 @@ def solve_simple_workflow( # Write expressions to temp file and import exp_file_path = os.path.join(working_dir, "_temp_expressions.exp") + + # Known integer/constant expressions (no unit) + CONSTANT_EXPRESSIONS = { + "hole_count", + } + with open(exp_file_path, "w") as f: for expr_name, expr_value in expression_updates.items(): - # Determine unit based on name - if "angle" in expr_name.lower(): + # Determine unit based on expression type + if expr_name in CONSTANT_EXPRESSIONS: + unit_str = "Constant" + # Write as integer if it's a whole number + if expr_value == int(expr_value): + expr_value = int(expr_value) + elif "angle" in expr_name.lower(): unit_str = "Degrees" else: unit_str = "MilliMeter" @@ -1009,14 +1020,32 @@ def solve_simple_workflow( print(f"[JOURNAL] WARNING: Could not load idealized part: {e}") break - # Find the FEM part + # Find the FEM part (must be .fem, NOT _i.prt idealized part) fem_part = None for part in theSession.Parts: - if "_fem" in part.Name.lower() or part.Name.lower().endswith(".fem"): + part_name = part.Name.lower() + # Match FEM parts but exclude idealized parts (_i) + if ("_fem" in part_name or part_name.endswith(".fem")) and "_i" not in part_name.split("_fem")[-1]: fem_part = part print(f"[JOURNAL] Found FEM part: {part.Name}") break + # If not found by name, try loading .fem file from working directory + if fem_part is None: + for filename in os.listdir(working_dir): + if filename.lower().endswith(".fem"): + fem_path = os.path.join(working_dir, filename) + print(f"[JOURNAL] Loading FEM file: {filename}") + try: + loaded_part, partLoadStatus = theSession.Parts.Open(fem_path) + partLoadStatus.Dispose() + if loaded_part is not None: + fem_part = loaded_part + print(f"[JOURNAL] FEM part loaded: {fem_part.Name}") + break + except Exception as e: + print(f"[JOURNAL] WARNING: Could not load FEM: {e}") + if fem_part: try: # Switch to FEM part - CRITICAL: Use SameAsDisplay to make FEM the work part diff --git a/projects/.stversions/hydrotech-beam/models/Beam_fem1_i~20260211-141332.prt b/projects/.stversions/hydrotech-beam/models/Beam_fem1_i~20260211-141332.prt new file mode 100644 index 00000000..7020fde8 Binary files /dev/null and b/projects/.stversions/hydrotech-beam/models/Beam_fem1_i~20260211-141332.prt differ diff --git a/projects/.stversions/hydrotech-beam/models/Beam_fem1~20260211-141333.fem b/projects/.stversions/hydrotech-beam/models/Beam_fem1~20260211-141333.fem new file mode 100644 index 00000000..bcb5f8de Binary files /dev/null and b/projects/.stversions/hydrotech-beam/models/Beam_fem1~20260211-141333.fem differ diff --git a/projects/.stversions/hydrotech-beam/models/Beam_sim1~20260211-141333.sim b/projects/.stversions/hydrotech-beam/models/Beam_sim1~20260211-141333.sim new file mode 100644 index 00000000..323e3cfa Binary files /dev/null and b/projects/.stversions/hydrotech-beam/models/Beam_sim1~20260211-141333.sim differ diff --git a/projects/.stversions/hydrotech-beam/models/Beam~20260211-141333.prt b/projects/.stversions/hydrotech-beam/models/Beam~20260211-141333.prt new file mode 100644 index 00000000..2ca409c8 Binary files /dev/null and b/projects/.stversions/hydrotech-beam/models/Beam~20260211-141333.prt differ diff --git a/projects/.stversions/hydrotech-beam/studies/01_doe_landscape/results/optuna_study~20260211-141332.db b/projects/.stversions/hydrotech-beam/studies/01_doe_landscape/results/optuna_study~20260211-141332.db new file mode 100644 index 00000000..1ecc44ec Binary files /dev/null and b/projects/.stversions/hydrotech-beam/studies/01_doe_landscape/results/optuna_study~20260211-141332.db differ diff --git a/projects/.stversions/hydrotech-beam/studies/01_doe_landscape/results/optuna_study~20260211-141442.db b/projects/.stversions/hydrotech-beam/studies/01_doe_landscape/results/optuna_study~20260211-141442.db new file mode 100644 index 00000000..bb2a847e Binary files /dev/null and b/projects/.stversions/hydrotech-beam/studies/01_doe_landscape/results/optuna_study~20260211-141442.db differ diff --git a/projects/hydrotech-beam/models/Beam.prt b/projects/hydrotech-beam/models/Beam.prt index 2ca409c8..69682690 100644 Binary files a/projects/hydrotech-beam/models/Beam.prt and b/projects/hydrotech-beam/models/Beam.prt differ diff --git a/projects/hydrotech-beam/models/Beam_fem1.fem b/projects/hydrotech-beam/models/Beam_fem1.fem index bcb5f8de..1b63cdc2 100644 Binary files a/projects/hydrotech-beam/models/Beam_fem1.fem and b/projects/hydrotech-beam/models/Beam_fem1.fem differ diff --git a/projects/hydrotech-beam/models/Beam_fem1_i.prt b/projects/hydrotech-beam/models/Beam_fem1_i.prt index 7020fde8..06ceb87c 100644 Binary files a/projects/hydrotech-beam/models/Beam_fem1_i.prt and b/projects/hydrotech-beam/models/Beam_fem1_i.prt differ diff --git a/projects/hydrotech-beam/models/Beam_sim1.sim b/projects/hydrotech-beam/models/Beam_sim1.sim index 323e3cfa..f698db7c 100644 Binary files a/projects/hydrotech-beam/models/Beam_sim1.sim and b/projects/hydrotech-beam/models/Beam_sim1.sim differ diff --git a/projects/hydrotech-beam/studies/01_doe_landscape/run_doe.py b/projects/hydrotech-beam/studies/01_doe_landscape/run_doe.py index 0c8b135c..58c75032 100644 --- a/projects/hydrotech-beam/studies/01_doe_landscape/run_doe.py +++ b/projects/hydrotech-beam/studies/01_doe_landscape/run_doe.py @@ -644,13 +644,26 @@ def main() -> None: """Entry point.""" args = parse_args() - # Configure logging + # Configure logging — console + file log_level = logging.DEBUG if args.verbose else logging.INFO + log_format = "%(asctime)s [%(levelname)-7s] %(name)s: %(message)s" + log_datefmt = "%Y-%m-%d %H:%M:%S" + + # Ensure results dir exists for log file + results_dir = Path(args.results_dir) + results_dir.mkdir(parents=True, exist_ok=True) + log_file = results_dir / "doe_run.log" + logging.basicConfig( level=log_level, - format="%(asctime)s [%(levelname)-7s] %(name)s: %(message)s", - datefmt="%Y-%m-%d %H:%M:%S", + format=log_format, + datefmt=log_datefmt, + handlers=[ + logging.StreamHandler(), # console + logging.FileHandler(log_file, mode="a", encoding="utf-8"), # file + ], ) + logger.info("Log file: %s", log_file.resolve()) # Run try: