CoolFace
Apppublic

cdshelat/MorphAI

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
materials.py121 linesDownload Raw Back to root
1import numpy as np2 3MATERIALS = {4    "PLA (Bioplastic)": {5        "E_gpa": 3.5, "rho_gcc": 1.24, "nu": 0.36, "yield_strength_mpa": 50,6        "color": "#4CAF50", "printable": True, "print_temp": "200-220C", "bed_temp": "60C",7        "cost_per_kg": 20.0, "cost_level": 1, "notes": "Best for beginners. Stiff but brittle."8    },9    "PETG (Engineering Plastic)": {10        "E_gpa": 2.1, "rho_gcc": 1.27, "nu": 0.39, "yield_strength_mpa": 53,11        "color": "#2196F3", "printable": True, "print_temp": "230-250C", "bed_temp": "80C",12        "cost_per_kg": 25.0, "cost_level": 2, "notes": "Tougher than PLA. Good chemical resistance."13    },14    "ABS (Acrylonitrile Butadiene Styrene)": {15        "E_gpa": 2.3, "rho_gcc": 1.05, "nu": 0.35, "yield_strength_mpa": 44,16        "color": "#FF9800", "printable": True, "print_temp": "230-250C", "bed_temp": "100C",17        "cost_per_kg": 22.0, "cost_level": 2, "notes": "Needs enclosure. Heat resistant to ~100C."18    },19    "Nylon PA12": {20        "E_gpa": 1.6, "rho_gcc": 1.01, "nu": 0.39, "yield_strength_mpa": 50,21        "color": "#9C27B0", "printable": True, "print_temp": "240-260C", "bed_temp": "70C",22        "cost_per_kg": 40.0, "cost_level": 3, "notes": "Tough and fatigue resistant. Absorbs moisture."23    },24    "TPU (Flexible)": {25        "E_gpa": 0.05, "rho_gcc": 1.21, "nu": 0.47, "yield_strength_mpa": 29,26        "color": "#F44336", "printable": True, "print_temp": "220-240C", "bed_temp": "30-60C",27        "cost_per_kg": 30.0, "cost_level": 2, "notes": "Rubber-like. Shock absorption."28    },29    "Carbon Fiber PETG (Composite)": {30        "E_gpa": 9.5, "rho_gcc": 1.30, "nu": 0.30, "yield_strength_mpa": 110,31        "color": "#78909C", "printable": True, "print_temp": "240-260C", "bed_temp": "80C",32        "cost_per_kg": 80.0, "cost_level": 4, "notes": "High stiffness-to-weight. Hardened nozzle required."33    },34    "Titanium Ti-6Al-4V (Reference)": {35        "E_gpa": 114.0, "rho_gcc": 4.43, "nu": 0.34, "yield_strength_mpa": 880,36        "color": "#90A4AE", "printable": False, "print_temp": "N/A", "bed_temp": "N/A",37        "cost_per_kg": 500.0, "cost_level": 5, "notes": "Aerospace benchmark. Not FDM printable."38    },39    "Aluminum 6061 (Reference)": {40        "E_gpa": 68.9, "rho_gcc": 2.70, "nu": 0.33, "yield_strength_mpa": 276,41        "color": "#CFD8DC", "printable": False, "print_temp": "N/A", "bed_temp": "N/A",42        "cost_per_kg": 200.0, "cost_level": 5, "notes": "Machined metal benchmark. Not FDM printable."43    },44}45 46FACES = [47    "Left (X=0)", "Right (X=W)", "Bottom (Y=0)",48    "Top (Y=H)", "Front (Z=0)", "Back (Z=D)"49]50 51INFILL_PATTERNS = {52    "Gyroid": {53        "desc": "Isotropic TPMS. Best all-round. Excellent fatigue resistance.",54        "color": "#00BCD4",55        "fn": lambda x, y, z, p: (56            np.sin(2*np.pi*x/p)*np.cos(2*np.pi*y/p) +57            np.sin(2*np.pi*y/p)*np.cos(2*np.pi*z/p) +58            np.sin(2*np.pi*z/p)*np.cos(2*np.pi*x/p)59        )60    },61    "Schwartz-P": {62        "desc": "Stiffer in compression. Fewer triangles, faster slicing.",63        "color": "#FF5722",64        "fn": lambda x, y, z, p: (65            np.cos(2*np.pi*x/p) + np.cos(2*np.pi*y/p) + np.cos(2*np.pi*z/p)66        )67    },68    "Honeycomb": {69        "desc": "2D hex extruded in Z. Lightest weight option (up to 30% mass saving).",70        "color": "#FFC107",71        "fn": lambda x, y, z, p: (72            np.cos(2*np.pi*x/p) +73            np.cos(np.pi*x/p + np.sqrt(3)*np.pi*y/p) +74            np.cos(np.pi*x/p - np.sqrt(3)*np.pi*y/p)75        )76    },77    "Diamond": {78        "desc": "Highest surface area. Best for heat dissipation.",79        "color": "#E040FB",80        "fn": lambda x, y, z, p: (81            np.sin(2*np.pi*x/p)*np.sin(2*np.pi*y/p)*np.sin(2*np.pi*z/p) +82            np.sin(2*np.pi*x/p)*np.cos(2*np.pi*y/p)*np.cos(2*np.pi*z/p) +83            np.cos(2*np.pi*x/p)*np.sin(2*np.pi*y/p)*np.cos(2*np.pi*z/p) +84            np.cos(2*np.pi*x/p)*np.cos(2*np.pi*y/p)*np.sin(2*np.pi*z/p)85        )86    },87}88 89 90def compute_mat_scores(mat_names, box_w, box_h, box_d, vf, force_n, sf, norm_comp):91    scores = {}92    load_area_m2 = (box_h * box_d) * 1e-693    stress_mpa = (force_n / load_area_m2) / 1e694    for name in mat_names:95        m = MATERIALS[name]96        mass_g = (box_w/10) * (box_h/10) * (box_d/10) * vf * m["rho_gcc"]97        comp = norm_comp / m["E_gpa"]98        ok = stress_mpa <= m["yield_strength_mpa"] / sf99        ashby = (m["E_gpa"]**(1/3)) / m["rho_gcc"]100        scores[name] = {101            "mass_g": round(mass_g, 1),102            "comp": round(comp, 3),103            "stress_ok": ok,104            "ashby": round(ashby, 4),105            "allowable": round(m["yield_strength_mpa"] / sf, 1),106            "stress_applied": round(stress_mpa, 3),107        }108    return scores109 110 111def rank_materials(scores):112    names = list(scores.keys())113    if not names:114        return {}115    return {116        "stiffest":   min(names, key=lambda n: scores[n]["comp"]),117        "lightest":   min(names, key=lambda n: scores[n]["mass_g"]),118        "best_ashby": max(names, key=lambda n: scores[n]["ashby"]),119        "cheapest":   min(names, key=lambda n: MATERIALS[n]["cost_level"]),120    }121