| """
|
| AlgoRythm Prandtl Aero — Advanced Physics Encoding
|
| Encodes "Actual Geometry" and "Laws of Physics" into the dataset.
|
| Includes:
|
| 1. Von Mises Stress Criteria
|
| 2. L-PBF Overhang Analysis (Geometric Manufacturing Constraints)
|
| 3. Thermal Distortion Prediction
|
| 4. Local Curvature Analysis
|
| """
|
| import math
|
| import numpy as np
|
|
|
|
|
|
|
| def calc_von_mises_stress(sigma_xx, sigma_yy, sigma_zz, tau_xy, tau_yz, tau_zx):
|
| """
|
| Calculates Von Mises Yield Criterion stress.
|
| σ_v = sqrt(0.5 * [(σ_x - σ_y)² + (σ_y - σ_z)² + (σ_z - σ_x)² + 6(τ_xy² + τ_yz² + τ_zx²)])
|
| """
|
| term1 = (sigma_xx - sigma_yy)**2 + (sigma_yy - sigma_zz)**2 + (sigma_zz - sigma_xx)**2
|
| term2 = 6 * (tau_xy**2 + tau_yz**2 + tau_zx**2)
|
| return math.sqrt(0.5 * (term1 + term2))
|
|
|
| def check_yield_criterion(sigma_vm, yield_strength, safety_factor=1.25):
|
| """True/False check if design yields under load."""
|
| limit = yield_strength / safety_factor
|
| return sigma_vm < limit, limit
|
|
|
|
|
|
|
| def calc_max_overhang_angle(material_key):
|
| """
|
| Returns the maximum self-supporting angle (degrees from horizontal)
|
| before support structures are required.
|
| """
|
|
|
|
|
| if "Ti6Al4V" in material_key: return 35.0
|
| if "Inconel" in material_key: return 45.0
|
| if "Copper" in material_key: return 45.0
|
| return 45.0
|
|
|
| def analyze_geometry_printability(geometry_type, angle_deg):
|
| """
|
| Determines if a geometric feature honors the "Law of Gravity" in printing.
|
| Returns: (Pass/Fail, Explanation)
|
| """
|
| limit = 45.0
|
| if angle_deg < limit:
|
| return False, f"FAIL: Angle {angle_deg}° < {limit}° limit. Will collapse due to gravity/thermal stress."
|
| return True, f"PASS: Angle {angle_deg}° is self-supporting."
|
|
|
|
|
|
|
| def predict_thermal_distortion(L_mm, dT, CTE):
|
| """
|
| Predicts linear thermal expansion/distortion.
|
| δ = L * α * ΔT
|
| """
|
| delta = L_mm * CTE * dT
|
| return delta
|
|
|
| def calc_residual_stress_buildup(E_GPa, CTE, dT):
|
| """
|
| Estimates residual stress from rapid cooling in L-PBF.
|
| σ = E * α * ΔT (Simplified 1D constraint)
|
| """
|
| sigma = (E_GPa * 1e9) * CTE * dT
|
| return sigma / 1e6
|
|
|
|
|
|
|
| def calc_characteristic_velocity(Pc_Pa, At_m2, mdot_kg_s):
|
| """
|
| Calculates Characteristic Velocity (c*).
|
| c* = (Pc * At) / mdot
|
| Measure of combustion efficiency.
|
| """
|
| if mdot_kg_s <= 0: return 0.0
|
| c_star = (Pc_Pa * At_m2) / mdot_kg_s
|
| return c_star
|
|
|
| def calc_thrust_coefficient(k, epsilon, Pa_Pa, Pc_Pa):
|
| """
|
| Calculates Thrust Coefficient (Cf) using ideal rocket theory.
|
| k: Specific heat ratio (gamma)
|
| epsilon: Nozzle area expansion ratio (Ae/At)
|
| """
|
|
|
| term1 = (2 * k**2 / (k - 1))
|
| term2 = (2 / (k + 1)) ** ((k + 1) / (k - 1))
|
| term3 = 1 - (Pa_Pa / Pc_Pa) ** ((k - 1) / k)
|
|
|
|
|
| if Pc_Pa <= 0 or Pa_Pa < 0: return 0.0
|
| if term3 < 0: term3 = 0
|
|
|
| Cf_ideal = math.sqrt(term1 * term2 * term3)
|
|
|
|
|
|
|
| return Cf_ideal
|
|
|
| def calc_isp(F_N, mdot_kg_s, g0=9.80665):
|
| """
|
| Calculates Specific Impulse (Isp).
|
| Isp = F / (mdot * g0)
|
| """
|
| if mdot_kg_s <= 0: return 0.0
|
| return F_N / (mdot_kg_s * g0)
|
|
|
|
|
|
|
| def calc_pressure_drop_darcy(f, L_m, Dh_m, rho_kg_m3, v_m_s):
|
| """
|
| Darcy-Weisbach Equation for pressure loss.
|
| dP = f * (L/D) * (rho * v^2 / 2)
|
| """
|
| if Dh_m <= 0: return float('inf')
|
| dP = f * (L_m / Dh_m) * (0.5 * rho_kg_m3 * v_m_s**2)
|
| return dP
|
|
|
| def calc_bartz_heat_flux(D_t_m, Pc_Pa, c_star, Pr, mu_gas, cp_gas, T_comb_K):
|
| """
|
| Simplified Bartz Reference:
|
| h_g = 0.026 / D_t^0.2 * (mu^0.2 * cp / Pr^0.6) * (Pc / c*)^0.8
|
| Returns approx h_g (W/m2K)
|
| Note: Highly sensitive to units.
|
| """
|
|
|
|
|
| try:
|
| term1 = 0.026 / (D_t_m ** 0.2)
|
| term2 = (mu_gas**0.2 * cp_gas) / (Pr**0.6)
|
| term3 = (Pc_Pa / c_star) ** 0.8
|
| h_g = term1 * term2 * term3
|
| return h_g
|
| except:
|
| return 0.0
|
|
|
|
|
|
|
| def get_material_properties(material_key, temp_K):
|
| """
|
| Returns (YieldStrength_MPa, ThermalCond_W_mK) at specific temperature.
|
| Data approximated from standard aerospace alloys.
|
| """
|
|
|
| if "Inconel" in material_key:
|
|
|
| if temp_K < 800: return 1100.0, 11.4
|
| if temp_K < 1000: return 900.0, 22.0
|
| return 200.0, 25.0
|
|
|
|
|
| if "Copper" in material_key or "GRCop" in material_key:
|
| if temp_K < 600: return 400.0, 320.0
|
| if temp_K < 900: return 200.0, 300.0
|
| return 50.0, 280.0
|
|
|
|
|
| if "Ti64" in material_key or "Titanium" in material_key:
|
| if temp_K < 600: return 800.0, 6.7
|
| return 100.0, 12.0
|
|
|
| return 500.0, 20.0
|
|
|
|
|
|
|
| def check_margin_of_safety_aerospace(allowable, load, factor=1.4):
|
| """
|
| Standard Aerospace MoS calculation.
|
| MoS = (Allowable / (Load * Factor)) - 1
|
| Must be > 0.
|
| """
|
| if load <= 0: return 99.9
|
| mos = (allowable / (load * factor)) - 1
|
| return mos
|
|
|
| def calc_critical_crack_length(K1c, sigma_applied):
|
| """
|
| Griffith Crack Theory approximation.
|
| a_c = (1/pi) * (K1c / sigma)^2
|
| """
|
| if sigma_applied <= 0: return float('inf')
|
|
|
| return (1.0 / math.pi) * (K1c / sigma_applied)**2 * 1000
|
|
|
|
|
|
|
| def suggest_correction(param_name, current_val, deviation_ratio, limit):
|
| """
|
| Returns a physics-based suggestion to fix a failed constraint.
|
| Example: Stress is 1.5x Yield -> Suggest increasing Wall Thickness by 1.6x.
|
| """
|
| if "Stress" in param_name or "MoS" in param_name:
|
|
|
|
|
|
|
| correction_factor = deviation_ratio * 1.2
|
| new_val = current_val * correction_factor
|
| return f"Increase Wall Thickness to {new_val:.2f}mm (Factor {correction_factor:.2f}x)"
|
|
|
| if "Temp" in param_name or "Heat" in param_name:
|
|
|
| return f"Increase Cooling Flow or Channel Depth by {deviation_ratio*1.1:.2f}x"
|
|
|
| if "Deflection" in param_name:
|
|
|
|
|
| correction_factor = (deviation_ratio)**(1.0/3.0) * 1.15
|
| new_val = current_val * correction_factor
|
| return f"Increase Rib/Wall Thickness to {new_val:.2f}mm (Stiffness increase)"
|
|
|
| return "Check Physics Model."
|
|
|