Files
Anto01 6658de02f4 feat(isogrid): FEA stress field → 2D heatmap → adaptive density feedback
Closes the optimization loop: OP2 results → density field refinement.

**extract_stress_field_2d.py (new)**
- Reads OP2 (3D solid or 2D shell elements) + BDF via pyNastran
- Projects element centroids to 2D sandbox coords using geometry transform
- Averages stress through thickness (for solid 3D meshes)
- Normalises by sigma_yield to [0..1]
- save/load helpers (NPZ) for trial persistence

**stress_feedback.py (new)**
- StressFeedbackField: converts 2D stress scatter → smooth density modifier
- Gaussian blur (configurable radius, default 40mm) prevents oscillations
- RBF interpolator (thin-plate spline) for fast pointwise evaluation
- evaluate(x, y) returns S_stress ∈ [0..1]
- from_field() and from_npz() constructors

**density_field.py (modified)**
- evaluate_density() now accepts optional stress_field= argument
- Adaptive formula: η = η₀ + α·I + β·E + γ·S_stress
- gamma_stress param controls feedback gain (0.0 = pure parametric)
- Fully backward compatible (no stress_field = original behaviour)

Usage:
    field = extract_stress_field_2d(op2, bdf, geometry["transform"], sigma_yield=276.0)
    feedback = StressFeedbackField.from_field(field, blur_radius_mm=40.0)
    eta = evaluate_density(x, y, geometry, params, stress_field=feedback)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-18 11:13:28 -05:00
..

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.

# 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