- KB Gen 003: NX version (DesigncenterNX 2512), first real results - sol101-static.md: path resolution lessons, in-place solving, result extraction confirmed - CONTEXT.md: solver pipeline operational, first results (disp=17.93mm, stress=111.9MPa) - DECISIONS.md: DEC-HB-008 to DEC-HB-011 (backup/restore, iteration arch, history DB, git workflow) - optimization_engine/README.md: created (DesigncenterNX support, path resolution, NX file refs) - studies/01_doe_landscape/README.md: updated architecture, iteration folders, history DB - _index.md: closed gaps G3,G4,G6,G10-G14, updated generation to 003
116 lines
4.2 KiB
Markdown
116 lines
4.2 KiB
Markdown
# Optimization Engine
|
|
|
|
Core optimization engine for Atomizer structural optimization projects.
|
|
|
|
## Overview
|
|
|
|
The optimization engine provides NX Nastran integration, result extraction, and optimization orchestration. Originally developed for the SAT3 mirror project, now generalized for multiple projects including Hydrotech Beam.
|
|
|
|
## NX Integration (`nx/`)
|
|
|
|
### Supported NX Versions
|
|
|
|
| Version | Status | Notes |
|
|
|---------|--------|-------|
|
|
| NX 2412 | ⚠️ Legacy | Original development version |
|
|
| **DesigncenterNX 2512** | ✅ Current | Siemens rebranded NX to "DesigncenterNX". Install path: `C:\Program Files\Siemens\DesigncenterNX2512` |
|
|
|
|
> **Important:** Siemens rebranded NX to "DesigncenterNX" starting with version 2512. The install directory, executable paths, and search paths all use the new name. Solver configuration must specify `2512` and include `DesigncenterNX` in search paths.
|
|
|
|
### Key Files
|
|
|
|
| File | Purpose |
|
|
|------|---------|
|
|
| `solver.py` | NX solver interface — manages NX session, expression updates, solve execution |
|
|
| `solve_simulation.py` | NX journal script — runs inside NXOpen Python, handles simple + assembly workflows |
|
|
| `solve_simulation_simple.py` | Simplified journal for single-part (simple) workflow |
|
|
| `updater.py` | Expression updater — writes `.exp` files, handles unit types |
|
|
| `export_expressions.py` | Export expressions from NX model |
|
|
| `import_expressions.py` | Import expressions into NX model |
|
|
| `session_manager.py` | NX session lifecycle management |
|
|
| `model_cleanup.py` | Model cleanup utilities |
|
|
| `mesh_converter.py` | Mesh format conversion |
|
|
|
|
### Path Resolution — CRITICAL on Windows
|
|
|
|
**`Path.absolute()` on Windows does NOT resolve `..` components.** Use `Path.resolve()` everywhere.
|
|
|
|
```python
|
|
# WRONG — NX cannot follow ".." in paths
|
|
path = Path("../../models/Beam_sim1.sim").absolute()
|
|
# → C:\...\studies\01_doe_landscape\..\..\models\Beam_sim1.sim ← BROKEN
|
|
|
|
# CORRECT — fully resolved path
|
|
path = Path("../../models/Beam_sim1.sim").resolve()
|
|
# → C:\...\projects\hydrotech-beam\models\Beam_sim1.sim ← WORKS
|
|
```
|
|
|
|
This applies to ALL paths passed to NX journals, including:
|
|
- `.sim` file path
|
|
- `.exp` file path
|
|
- Model directory path
|
|
- Output file paths
|
|
|
|
### NX File References — In-Place Solving Required
|
|
|
|
NX `.sim` files store **absolute internal references** to `.fem` and `.prt` files. Copying model files to different directories breaks these references (`Parts.Open` returns `None`).
|
|
|
|
**Solution:** Always solve on master model files in-place. Use backup/restore for isolation between optimization trials:
|
|
|
|
1. Backup master model files before trial
|
|
2. Write expressions, rebuild, solve in original location
|
|
3. Archive outputs (OP2, F06) to trial-specific folder
|
|
4. Restore master from backup
|
|
|
|
### Expression Units
|
|
|
|
When writing `.exp` files for NX:
|
|
- Length design variables: unit = `MilliMeter`
|
|
- Integer expressions (e.g., `hole_count`): unit = `Constant`
|
|
- **Critical:** Using wrong unit silently corrupts the model
|
|
|
|
### Workflow Types
|
|
|
|
**Simple workflow** (single-part, e.g., Hydrotech Beam):
|
|
```
|
|
Beam.prt → Beam_fem1_i.prt → Beam_fem1.fem → Beam_sim1.sim
|
|
```
|
|
|
|
**Assembly FEM workflow** (multi-part, e.g., SAT3 mirror):
|
|
```
|
|
Multiple .prt → .afm → .sim (node merge, label conflicts)
|
|
```
|
|
|
|
The journal auto-detects workflow type by checking for `.afm` files.
|
|
|
|
## Result Extraction
|
|
|
|
### pyNastran Compatibility
|
|
|
|
pyNastran warns "nx version 2512 not supported" but **reads OP2 files correctly**. Safe to ignore the warning.
|
|
|
|
**Unit note:** pyNastran returns stress in kPa for NX models using kg-mm-s unit system. Divide by 1000 for MPa.
|
|
|
|
### Mass Extraction
|
|
|
|
Mass is extracted via NX expression `p173` (or project-specific expression). The journal writes the value to a temp file (`_temp_mass.txt`) after solve, which Python reads.
|
|
|
|
## Dependencies
|
|
|
|
- Python 3.10+
|
|
- pyNastran (OP2 parsing)
|
|
- NXOpen Python API (on Windows solver node)
|
|
- Optuna (optimization orchestration)
|
|
- scipy, numpy, pandas
|
|
|
|
## Projects Using This Engine
|
|
|
|
| Project | Status | NX Version | Workflow |
|
|
|---------|--------|------------|----------|
|
|
| Hydrotech Beam | Active (DOE Phase 1) | DesigncenterNX 2512 | Simple |
|
|
| SAT3 Mirror | Legacy reference | NX 2412 | Assembly FEM |
|
|
|
|
---
|
|
|
|
*Last updated: 2026-02-11*
|