3 Commits

Author SHA1 Message Date
14354a2606 feat: Add NX file dependency tree to introspection panel
Backend:
- Add scan_nx_file_dependencies() function to parse NX file chain
- Uses naming conventions to build dependency tree (.sim -> .afm -> .fem -> _i.prt -> .prt)
- Include file_dependencies in introspection response
- Works without NX (pure file-based analysis)

Frontend:
- Add FileDependencies interface for typed API response
- Add collapsible 'File Dependencies' section with tree visualization
- Color-coded file types (purple=sim, blue=afm, green=fem, yellow=idealized, orange=prt)
- Shows orphan geometry files that aren't in the dependency chain
2026-01-20 15:33:04 -05:00
abbc7b1b50 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
2026-01-20 15:29:29 -05:00
1cdcc17ffd fix: NX installation path detection for run-baseline endpoint
- Read nx_install_path from atomizer_spec.json if available
- Auto-detect from common Siemens installation paths
- Fixes issue where NX2512 wasn't found (actual path is DesigncenterNX2512)
2026-01-20 15:23:10 -05:00
2 changed files with 343 additions and 3 deletions

View File

@@ -4485,6 +4485,120 @@ async def export_study_data(study_id: str, format: str):
# ============================================================================
def scan_nx_file_dependencies(model_dir: Path) -> dict:
"""
Scan a model directory for NX files and build a dependency tree.
This uses file naming conventions to determine relationships:
- .sim files reference .afm (assembly FEM) or .fem files
- .afm files reference multiple .fem files
- .fem files reference _i.prt (idealized) files
- _i.prt files are derived from .prt (geometry) files
Returns:
Dictionary with file lists and dependency tree
"""
result = {
"files": {
"sim": [], # Simulation files
"afm": [], # Assembly FEM files
"fem": [], # FEM files
"prt": [], # Part/geometry files
"idealized": [], # Idealized parts (*_i.prt)
},
"dependencies": [], # List of {source, target, type} edges
"root_sim": None,
}
# Collect all files by type
for f in model_dir.iterdir():
if not f.is_file():
continue
name = f.name.lower()
if name.endswith(".sim"):
result["files"]["sim"].append(f.name)
elif name.endswith(".afm"):
result["files"]["afm"].append(f.name)
elif name.endswith(".fem"):
result["files"]["fem"].append(f.name)
elif name.endswith("_i.prt"):
result["files"]["idealized"].append(f.name)
elif name.endswith(".prt"):
result["files"]["prt"].append(f.name)
# Build dependency edges based on NX naming conventions
# SIM -> AFM: SIM file basename matches AFM (e.g., ASSY_M1_assyfem1_sim1.sim -> ASSY_M1_assyfem1.afm)
for sim in result["files"]["sim"]:
sim_base = sim.lower().replace(".sim", "")
# Remove _sim1, _sim2 suffix to get AFM name
afm_base = sim_base.rsplit("_sim", 1)[0] if "_sim" in sim_base else sim_base
# Check for matching AFM
for afm in result["files"]["afm"]:
if afm.lower().replace(".afm", "") == afm_base:
result["dependencies"].append({"source": sim, "target": afm, "type": "sim_to_afm"})
break
else:
# No AFM, check for direct FEM reference
for fem in result["files"]["fem"]:
fem_base = fem.lower().replace(".fem", "")
if afm_base.endswith(fem_base) or fem_base in afm_base:
result["dependencies"].append(
{"source": sim, "target": fem, "type": "sim_to_fem"}
)
break
# Set root sim (first one found)
if result["root_sim"] is None:
result["root_sim"] = sim
# AFM -> FEM: Assembly FEM references component FEMs
# Convention: AFM basename often contains assembly name, FEMs have component names
for afm in result["files"]["afm"]:
afm_base = afm.lower().replace(".afm", "")
# Get the assembly prefix (e.g., ASSY_M1_assyfem1 -> ASSY_M1)
parts = afm_base.split("_")
for fem in result["files"]["fem"]:
fem_base = fem.lower().replace(".fem", "")
# FEM is likely a component if it's not the assembly FEM itself
if fem_base != afm_base:
result["dependencies"].append({"source": afm, "target": fem, "type": "afm_to_fem"})
# FEM -> Idealized PRT: FEM references idealized geometry
# Convention: Model_fem1.fem -> Model_fem1_i.prt
for fem in result["files"]["fem"]:
fem_base = fem.lower().replace(".fem", "")
for idealized in result["files"]["idealized"]:
idealized_base = idealized.lower().replace("_i.prt", "")
if idealized_base == fem_base:
result["dependencies"].append(
{"source": fem, "target": idealized, "type": "fem_to_idealized"}
)
break
# Idealized PRT -> PRT: Idealized part derives from geometry
# Convention: Model_fem1_i.prt -> Model.prt
for idealized in result["files"]["idealized"]:
idealized_base = idealized.lower().replace("_i.prt", "")
# Remove fem suffix to get geometry name (Model_fem1_i -> Model)
geom_base = (
idealized_base.rsplit("_fem", 1)[0] if "_fem" in idealized_base else idealized_base
)
for prt in result["files"]["prt"]:
prt_base = prt.lower().replace(".prt", "")
if prt_base == geom_base:
result["dependencies"].append(
{"source": idealized, "target": prt, "type": "idealized_to_prt"}
)
break
return result
@router.get("/studies/{study_id}/nx/introspect")
async def introspect_nx_model(study_id: str, force: bool = False):
"""
@@ -4554,12 +4668,18 @@ async def introspect_nx_model(study_id: str, force: bool = False):
except:
pass # Invalid cache, re-run
# Scan file dependencies (fast, doesn't need NX)
file_deps = scan_nx_file_dependencies(model_dir)
# Run introspection
try:
from optimization_engine.extractors.introspect_part import introspect_part
result = introspect_part(str(prt_file), str(model_dir), verbose=False)
# Add file dependencies to result
result["file_dependencies"] = file_deps
# Cache results
with open(cache_file, "w") as f:
json.dump(result, f, indent=2)
@@ -4567,7 +4687,16 @@ async def introspect_nx_model(study_id: str, force: bool = False):
return {"study_id": study_id, "cached": False, "introspection": result}
except ImportError:
raise HTTPException(status_code=500, detail="introspect_part module not available")
# If introspect_part not available, return just file dependencies
return {
"study_id": study_id,
"cached": False,
"introspection": {
"success": False,
"error": "introspect_part module not available",
"file_dependencies": file_deps,
},
}
except Exception as e:
raise HTTPException(status_code=500, detail=f"Introspection failed: {str(e)}")
@@ -4662,8 +4791,31 @@ async def run_baseline_simulation(study_id: str):
# Try to run the solver
try:
from optimization_engine.nx.solver import NXSolver
from pathlib import Path as P
# Try to get NX settings from spec
spec_file = study_dir / "atomizer_spec.json"
nx_install_path = None
if spec_file.exists():
with open(spec_file) as f:
spec_data = json.load(f)
nx_install_path = (
spec_data.get("model", {}).get("nx_settings", {}).get("nx_install_path")
)
# Default to common installation path if not in spec
if not nx_install_path:
for candidate in [
"C:/Program Files/Siemens/DesigncenterNX2512",
"C:/Program Files/Siemens/NX2506",
"C:/Program Files/Siemens/NX2412",
]:
if P(candidate).exists():
nx_install_path = candidate
break
solver = NXSolver(
nx_install_dir=P(nx_install_path) if nx_install_path else None,
nastran_version="2512",
timeout=600,
use_journal=True,
@@ -4683,6 +4835,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),
@@ -4694,11 +4873,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:

View File

@@ -19,6 +19,8 @@ import {
Link,
Box,
Settings2,
GitBranch,
File,
} from 'lucide-react';
import { useCanvasStore } from '../../../hooks/useCanvasStore';
@@ -53,6 +55,23 @@ interface DependentFile {
name: string;
}
// File dependency structure from backend
interface FileDependencies {
files: {
sim: string[];
afm: string[];
fem: string[];
prt: string[];
idealized: string[];
};
dependencies: Array<{
source: string;
target: string;
type: string;
}>;
root_sim: string | null;
}
// The API returns expressions in a nested structure
interface ExpressionsResult {
user: Expression[];
@@ -81,6 +100,7 @@ interface IntrospectionResult {
attributes?: Array<{ title: string; value: string }>;
units?: Record<string, unknown>;
linked_parts?: Record<string, unknown>;
file_dependencies?: FileDependencies;
}
// Baseline run result interface
@@ -627,6 +647,142 @@ export function IntrospectionPanel({ filePath, studyId, onClose }: Introspection
</div>
)}
{/* File Dependencies Section (NX file chain) */}
{result.file_dependencies && (
<div className="border border-dark-700 rounded-lg overflow-hidden">
<button
onClick={() => toggleSection('file_deps')}
className="w-full flex items-center justify-between px-3 py-2 bg-dark-800 hover:bg-dark-750 transition-colors"
>
<div className="flex items-center gap-2">
<GitBranch size={14} className="text-cyan-400" />
<span className="text-sm font-medium text-white">
File Dependencies ({result.file_dependencies.dependencies?.length || 0} links)
</span>
</div>
{expandedSections.has('file_deps') ? (
<ChevronDown size={14} className="text-dark-400" />
) : (
<ChevronRight size={14} className="text-dark-400" />
)}
</button>
{expandedSections.has('file_deps') && (
<div className="p-2 space-y-2 max-h-64 overflow-y-auto">
{/* Show file tree structure */}
{result.file_dependencies.root_sim && (
<div className="text-xs">
{/* Simulation files */}
{result.file_dependencies.files.sim.map((sim) => (
<div key={sim} className="ml-0">
<div className="flex items-center gap-1 p-1 bg-purple-500/10 rounded text-purple-400">
<File size={12} />
<span className="font-mono">{sim}</span>
<span className="text-purple-500/60 text-[10px]">(.sim)</span>
</div>
{/* AFM files connected to this SIM */}
{result.file_dependencies!.dependencies
.filter(d => d.source === sim && d.type === 'sim_to_afm')
.map(d => (
<div key={d.target} className="ml-4 mt-1">
<div className="flex items-center gap-1 p-1 bg-blue-500/10 rounded text-blue-400">
<File size={12} />
<span className="font-mono">{d.target}</span>
<span className="text-blue-500/60 text-[10px]">(.afm)</span>
</div>
{/* FEM files connected to this AFM */}
{result.file_dependencies!.dependencies
.filter(d2 => d2.source === d.target && d2.type === 'afm_to_fem')
.map(d2 => (
<div key={d2.target} className="ml-4 mt-1">
<div className="flex items-center gap-1 p-1 bg-green-500/10 rounded text-green-400">
<File size={12} />
<span className="font-mono">{d2.target}</span>
<span className="text-green-500/60 text-[10px]">(.fem)</span>
</div>
{/* Idealized parts connected to this FEM */}
{result.file_dependencies!.dependencies
.filter(d3 => d3.source === d2.target && d3.type === 'fem_to_idealized')
.map(d3 => (
<div key={d3.target} className="ml-4 mt-1">
<div className="flex items-center gap-1 p-1 bg-yellow-500/10 rounded text-yellow-400">
<File size={12} />
<span className="font-mono">{d3.target}</span>
<span className="text-yellow-500/60 text-[10px]">(_i.prt)</span>
</div>
{/* Geometry parts */}
{result.file_dependencies!.dependencies
.filter(d4 => d4.source === d3.target && d4.type === 'idealized_to_prt')
.map(d4 => (
<div key={d4.target} className="ml-4 mt-1">
<div className="flex items-center gap-1 p-1 bg-orange-500/10 rounded text-orange-400">
<File size={12} />
<span className="font-mono">{d4.target}</span>
<span className="text-orange-500/60 text-[10px]">(.prt)</span>
</div>
</div>
))
}
</div>
))
}
</div>
))
}
</div>
))
}
{/* Direct FEM connections (no AFM) */}
{result.file_dependencies!.dependencies
.filter(d => d.source === sim && d.type === 'sim_to_fem')
.map(d => (
<div key={d.target} className="ml-4 mt-1">
<div className="flex items-center gap-1 p-1 bg-green-500/10 rounded text-green-400">
<File size={12} />
<span className="font-mono">{d.target}</span>
<span className="text-green-500/60 text-[10px]">(.fem)</span>
</div>
</div>
))
}
</div>
))}
{/* Show any orphan PRT files not in the tree */}
{result.file_dependencies.files.prt.filter(prt =>
!result.file_dependencies!.dependencies.some(d => d.target === prt)
).length > 0 && (
<div className="mt-2 pt-2 border-t border-dark-700">
<span className="text-dark-500 text-[10px]">Additional geometry files:</span>
{result.file_dependencies.files.prt
.filter(prt => !result.file_dependencies!.dependencies.some(d => d.target === prt))
.map(prt => (
<div key={prt} className="ml-2 mt-1">
<div className="flex items-center gap-1 p-1 bg-dark-800 rounded text-dark-400">
<File size={12} />
<span className="font-mono">{prt}</span>
</div>
</div>
))
}
</div>
)}
</div>
)}
{!result.file_dependencies.root_sim && (
<p className="text-xs text-dark-500 text-center py-2">No simulation file found</p>
)}
</div>
)}
</div>
)}
{/* Extractors Section - only show if available */}
{(result.extractors_available?.length ?? 0) > 0 && (
<div className="border border-dark-700 rounded-lg overflow-hidden">