2025-11-26 12:01:50 -05:00
|
|
|
"""
|
2026-01-27 12:02:30 -05:00
|
|
|
Extract mass from Nastran BDF/DAT file.
|
|
|
|
|
|
|
|
|
|
This module provides a simple wrapper around the BDFMassExtractor class.
|
2025-11-26 12:01:50 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from typing import Dict, Any
|
2026-01-27 12:02:30 -05:00
|
|
|
|
|
|
|
|
from optimization_engine.extractors.bdf_mass_extractor import BDFMassExtractor
|
2025-11-26 12:01:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_mass_from_bdf(bdf_file: Path) -> Dict[str, Any]:
|
|
|
|
|
"""
|
2026-01-27 12:02:30 -05:00
|
|
|
Extract mass from Nastran BDF file.
|
2025-11-26 12:01:50 -05:00
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
bdf_file: Path to .dat or .bdf file
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
dict: {
|
2026-01-27 12:02:30 -05:00
|
|
|
'total_mass': mass in kg (primary key),
|
|
|
|
|
'mass_kg': mass in kg,
|
|
|
|
|
'mass_g': mass in grams,
|
|
|
|
|
'cg': center of gravity [x, y, z],
|
|
|
|
|
'num_elements': number of elements,
|
|
|
|
|
'breakdown': mass by element type
|
2025-11-26 12:01:50 -05:00
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
bdf_file = Path(bdf_file)
|
|
|
|
|
|
|
|
|
|
if not bdf_file.exists():
|
|
|
|
|
raise FileNotFoundError(f"BDF file not found: {bdf_file}")
|
|
|
|
|
|
2026-01-27 12:02:30 -05:00
|
|
|
extractor = BDFMassExtractor(str(bdf_file))
|
|
|
|
|
result = extractor.extract_mass()
|
2025-11-26 12:01:50 -05:00
|
|
|
|
2026-01-27 12:02:30 -05:00
|
|
|
# Add 'total_mass' as primary key for compatibility
|
|
|
|
|
result["total_mass"] = result["mass_kg"]
|
2025-11-26 12:01:50 -05:00
|
|
|
|
2026-01-27 12:02:30 -05:00
|
|
|
return result
|
2025-11-26 12:01:50 -05:00
|
|
|
|
|
|
|
|
|
2026-01-27 12:02:30 -05:00
|
|
|
if __name__ == "__main__":
|
2025-11-26 12:01:50 -05:00
|
|
|
import sys
|
2026-01-27 12:02:30 -05:00
|
|
|
|
2025-11-26 12:01:50 -05:00
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
bdf_file = Path(sys.argv[1])
|
|
|
|
|
result = extract_mass_from_bdf(bdf_file)
|
|
|
|
|
print(f"Mass from BDF: {result['mass_kg']:.6f} kg ({result['mass_g']:.3f} g)")
|
2026-01-27 12:02:30 -05:00
|
|
|
print(f"CG: {result['cg']}")
|
|
|
|
|
print(f"Elements: {result['num_elements']}")
|
2025-11-26 12:01:50 -05:00
|
|
|
else:
|
|
|
|
|
print(f"Usage: python {sys.argv[0]} <bdf_file>")
|