Spaces:
Sleeping
Sleeping
V43
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ from OCC.Core.BRepGProp import brepgprop
|
|
| 26 |
from OCC.Core.GProp import GProp_GProps
|
| 27 |
from OCC.Core.StlAPI import StlAPI_Writer
|
| 28 |
|
| 29 |
-
st.set_page_config(page_title="CastingSim
|
| 30 |
|
| 31 |
st.markdown("""
|
| 32 |
<style>
|
|
@@ -84,12 +84,12 @@ def compilar_pdf():
|
|
| 84 |
pdf = FPDF()
|
| 85 |
pdf.add_page()
|
| 86 |
pdf.set_font("Arial", 'B', 16)
|
| 87 |
-
pdf.cell(0, 10, "LAUDO DE ENGENHARIA - CASTINGSIM
|
| 88 |
pdf.ln(5)
|
| 89 |
pdf.set_font("Arial", 'B', 12)
|
| 90 |
pdf.cell(0, 10, "1. Parametros de Processo", 0, 1)
|
| 91 |
pdf.set_font("Arial", '', 11)
|
| 92 |
-
pdf.cell(0, 6, f"Liga: {st.session_state.liga} |
|
| 93 |
pdf.cell(0, 6, f"Eixo de Gravidade Ativo: {st.session_state.eixo_vaz}", 0, 1)
|
| 94 |
pdf.cell(0, 6, f"Molde: Coquilha de {st.session_state.mat_molde}", 0, 1)
|
| 95 |
if st.session_state.tinta_ceramica:
|
|
@@ -167,7 +167,7 @@ if st.session_state.step in [1, 2, 3, 4, 4.5, 5]:
|
|
| 167 |
st.progress(min(st.session_state.step, 4) / 4)
|
| 168 |
|
| 169 |
if st.session_state.step not in [3.5, 4.5]:
|
| 170 |
-
st.title("🛡️ CastingSim
|
| 171 |
st.markdown("---")
|
| 172 |
|
| 173 |
# ==========================================
|
|
@@ -237,7 +237,7 @@ elif st.session_state.step == 3:
|
|
| 237 |
with col_form:
|
| 238 |
st.markdown("---")
|
| 239 |
with st.form("ajustes_cad", clear_on_submit=False):
|
| 240 |
-
eixo_sel = st.selectbox("Eixo de Gravidade (
|
| 241 |
st.markdown("---")
|
| 242 |
rx = st.slider("Rotação Visual X", 0, 360, value=int(st.session_state.rot_x))
|
| 243 |
ry = st.slider("Rotação Visual Y", 0, 360, value=int(st.session_state.rot_y))
|
|
@@ -274,7 +274,7 @@ elif st.session_state.step == 3:
|
|
| 274 |
st.session_state.step = 3.5; st.rerun()
|
| 275 |
|
| 276 |
# ==========================================
|
| 277 |
-
# ETAPA 3.5
|
| 278 |
# ==========================================
|
| 279 |
elif st.session_state.step == 3.5:
|
| 280 |
st.title("⏳ Processando Solver FEM & Fourier...")
|
|
@@ -380,11 +380,10 @@ elif st.session_state.step == 3.5:
|
|
| 380 |
if st.button("⬅️ Voltar"): st.session_state.step = 3; st.rerun()
|
| 381 |
|
| 382 |
# ==========================================
|
| 383 |
-
# ETAPA 4: LAUDO (COM A GUILHOTINA DO DOM V42)
|
| 384 |
# ==========================================
|
| 385 |
elif st.session_state.step == 4:
|
| 386 |
|
| 387 |
-
# CRIAMOS UM CONTÊINER VOLÁTIL PARA A TELA 4 INTEIRA
|
| 388 |
tela4_container = st.empty()
|
| 389 |
|
| 390 |
with tela4_container.container():
|
|
@@ -395,9 +394,8 @@ elif st.session_state.step == 4:
|
|
| 395 |
st.error(f"⏱️ **TEMPO CRÍTICO DE SOLIDIFICAÇÃO: {st.session_state.t_sol_minutos} min {st.session_state.t_sol_segundos} s**")
|
| 396 |
with col_video:
|
| 397 |
if st.button("🎬 Painel de Extração Temporal", help="Gera os frames animados", use_container_width=True):
|
| 398 |
-
# A MÁGICA DA V42: Mata a Tela 4 inteira do navegador antes de seguir!
|
| 399 |
tela4_container.empty()
|
| 400 |
-
time.sleep(0.2)
|
| 401 |
st.session_state.step = 4.5
|
| 402 |
st.rerun()
|
| 403 |
|
|
@@ -439,10 +437,10 @@ elif st.session_state.step == 4:
|
|
| 439 |
st.session_state.step = 3; st.rerun()
|
| 440 |
|
| 441 |
# ==========================================
|
| 442 |
-
# ETAPA 4.5
|
| 443 |
# ==========================================
|
| 444 |
elif st.session_state.step == 4.5:
|
| 445 |
-
gc.collect()
|
| 446 |
st.title("🎬 Extração Cinemática com Derramador Físico")
|
| 447 |
prog = st.progress(0)
|
| 448 |
|
|
@@ -455,38 +453,36 @@ elif st.session_state.step == 4.5:
|
|
| 455 |
eixo = st.session_state.eixo_vaz
|
| 456 |
bounds = mesh_proxy.bounds
|
| 457 |
|
|
|
|
| 458 |
if eixo == 'Y':
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
altura_sprue = (
|
| 462 |
-
centro_grav =
|
| 463 |
center = (px, centro_grav, pz)
|
|
|
|
| 464 |
elif eixo == 'Z':
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
altura_sprue = (
|
| 468 |
-
centro_grav =
|
| 469 |
center = (px, py, centro_grav)
|
|
|
|
| 470 |
elif eixo == 'X':
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
altura_sprue = (
|
| 474 |
-
centro_grav =
|
| 475 |
center = (centro_grav, py, pz)
|
|
|
|
| 476 |
|
| 477 |
cilindro = pv.Cylinder(center=center, direction=dir_vec, radius=st.session_state.diam_vaz/2.0, height=altura_sprue).triangulate()
|
| 478 |
mesh_animacao = mesh_proxy.merge(cilindro)
|
| 479 |
|
| 480 |
pts_anim = mesh_animacao.points
|
| 481 |
-
if eixo == 'Y':
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
elif eixo == 'Z':
|
| 485 |
-
grav_anim = pts_anim[:, 2]
|
| 486 |
-
r_coords = np.sqrt((pts_anim[:, 0] - px)**2 + (pts_anim[:, 1] - py)**2)
|
| 487 |
-
elif eixo == 'X':
|
| 488 |
-
grav_anim = pts_anim[:, 0]
|
| 489 |
-
r_coords = np.sqrt((pts_anim[:, 1] - py)**2 + (pts_anim[:, 2] - pz)**2)
|
| 490 |
|
| 491 |
grav_norm = (grav_anim - np.min(grav_anim)) / (np.max(grav_anim) - np.min(grav_anim) + 1e-6)
|
| 492 |
r_eff = np.maximum(0, r_coords - (st.session_state.diam_vaz/2.0))
|
|
@@ -495,7 +491,14 @@ elif st.session_state.step == 4.5:
|
|
| 495 |
campo = (grav_norm * 0.65) + (r_norm * 0.35) + turbulencia
|
| 496 |
mesh_animacao['Preenchimento_Anim'] = (campo - np.min(campo)) / (np.max(campo) - np.min(campo) + 1e-6)
|
| 497 |
|
| 498 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
st.session_state.frames_filling = []
|
| 500 |
st.session_state.frames_cooling = []
|
| 501 |
temp_dir = tempfile.mkdtemp()
|
|
@@ -505,16 +508,20 @@ elif st.session_state.step == 4.5:
|
|
| 505 |
lim = (1.0 / passos) * i
|
| 506 |
if lim <= 0: lim = 1e-6
|
| 507 |
f_mesh = mesh_animacao.threshold([0, lim], scalars='Preenchimento_Anim')
|
|
|
|
| 508 |
pl = pv.Plotter(off_screen=True)
|
| 509 |
-
|
|
|
|
|
|
|
| 510 |
if f_mesh.n_points > 0:
|
| 511 |
f_mesh.points /= 1000.0
|
| 512 |
pl.add_mesh(f_mesh, color='#ff4500', metallic=True, smooth_shading=True)
|
|
|
|
| 513 |
path = os.path.join(temp_dir, f"fill_{i}.glb")
|
| 514 |
pl.export_gltf(path)
|
| 515 |
st.session_state.frames_filling.append(path)
|
| 516 |
pl.close()
|
| 517 |
-
prog.progress(int((i/passos)*40), text="[1/2] Forjando Animação de Enchimento
|
| 518 |
|
| 519 |
t_v = st.session_state.t_vaz
|
| 520 |
t_m = st.session_state.t_molde
|
|
@@ -547,7 +554,7 @@ elif st.session_state.step == 4.5:
|
|
| 547 |
if st.button("Voltar"): st.session_state.step = 4; st.rerun()
|
| 548 |
|
| 549 |
# ==========================================
|
| 550 |
-
# ETAPA 5
|
| 551 |
# ==========================================
|
| 552 |
elif st.session_state.step == 5:
|
| 553 |
st.header("5. Telemetria Cinemática")
|
|
|
|
| 26 |
from OCC.Core.GProp import GProp_GProps
|
| 27 |
from OCC.Core.StlAPI import StlAPI_Writer
|
| 28 |
|
| 29 |
+
st.set_page_config(page_title="CastingSim V43", layout="wide")
|
| 30 |
|
| 31 |
st.markdown("""
|
| 32 |
<style>
|
|
|
|
| 84 |
pdf = FPDF()
|
| 85 |
pdf.add_page()
|
| 86 |
pdf.set_font("Arial", 'B', 16)
|
| 87 |
+
pdf.cell(0, 10, "LAUDO DE ENGENHARIA - CASTINGSIM V43", 0, 1, 'C')
|
| 88 |
pdf.ln(5)
|
| 89 |
pdf.set_font("Arial", 'B', 12)
|
| 90 |
pdf.cell(0, 10, "1. Parametros de Processo", 0, 1)
|
| 91 |
pdf.set_font("Arial", '', 11)
|
| 92 |
+
pdf.cell(0, 6, f"Liga: {st.session_state.liga} | Vel. Vazamento: {st.session_state.vel_vaz} m/s | Derramador Ø: {st.session_state.diam_vaz} mm", 0, 1)
|
| 93 |
pdf.cell(0, 6, f"Eixo de Gravidade Ativo: {st.session_state.eixo_vaz}", 0, 1)
|
| 94 |
pdf.cell(0, 6, f"Molde: Coquilha de {st.session_state.mat_molde}", 0, 1)
|
| 95 |
if st.session_state.tinta_ceramica:
|
|
|
|
| 167 |
st.progress(min(st.session_state.step, 4) / 4)
|
| 168 |
|
| 169 |
if st.session_state.step not in [3.5, 4.5]:
|
| 170 |
+
st.title("🛡️ CastingSim V43: Motor de VRAM e Vetor Físico")
|
| 171 |
st.markdown("---")
|
| 172 |
|
| 173 |
# ==========================================
|
|
|
|
| 237 |
with col_form:
|
| 238 |
st.markdown("---")
|
| 239 |
with st.form("ajustes_cad", clear_on_submit=False):
|
| 240 |
+
eixo_sel = st.selectbox("Eixo de Gravidade (Topo/Fundo do Molde)", ["X", "Y", "Z"], index=["X", "Y", "Z"].index(st.session_state.eixo_vaz))
|
| 241 |
st.markdown("---")
|
| 242 |
rx = st.slider("Rotação Visual X", 0, 360, value=int(st.session_state.rot_x))
|
| 243 |
ry = st.slider("Rotação Visual Y", 0, 360, value=int(st.session_state.rot_y))
|
|
|
|
| 274 |
st.session_state.step = 3.5; st.rerun()
|
| 275 |
|
| 276 |
# ==========================================
|
| 277 |
+
# ETAPA 3.5: NÚCLEO FÍSICO COM EIXO DINÂMICO
|
| 278 |
# ==========================================
|
| 279 |
elif st.session_state.step == 3.5:
|
| 280 |
st.title("⏳ Processando Solver FEM & Fourier...")
|
|
|
|
| 380 |
if st.button("⬅️ Voltar"): st.session_state.step = 3; st.rerun()
|
| 381 |
|
| 382 |
# ==========================================
|
| 383 |
+
# ETAPA 4: LAUDO (COM A GUILHOTINA DO DOM V42/V43)
|
| 384 |
# ==========================================
|
| 385 |
elif st.session_state.step == 4:
|
| 386 |
|
|
|
|
| 387 |
tela4_container = st.empty()
|
| 388 |
|
| 389 |
with tela4_container.container():
|
|
|
|
| 394 |
st.error(f"⏱️ **TEMPO CRÍTICO DE SOLIDIFICAÇÃO: {st.session_state.t_sol_minutos} min {st.session_state.t_sol_segundos} s**")
|
| 395 |
with col_video:
|
| 396 |
if st.button("🎬 Painel de Extração Temporal", help="Gera os frames animados", use_container_width=True):
|
|
|
|
| 397 |
tela4_container.empty()
|
| 398 |
+
time.sleep(0.2)
|
| 399 |
st.session_state.step = 4.5
|
| 400 |
st.rerun()
|
| 401 |
|
|
|
|
| 437 |
st.session_state.step = 3; st.rerun()
|
| 438 |
|
| 439 |
# ==========================================
|
| 440 |
+
# ETAPA 4.5: RENDER FARM OTIMIZADO V43 (GRAVIDADE EXATA E DIETA DE VRAM)
|
| 441 |
# ==========================================
|
| 442 |
elif st.session_state.step == 4.5:
|
| 443 |
+
gc.collect()
|
| 444 |
st.title("🎬 Extração Cinemática com Derramador Físico")
|
| 445 |
prog = st.progress(0)
|
| 446 |
|
|
|
|
| 453 |
eixo = st.session_state.eixo_vaz
|
| 454 |
bounds = mesh_proxy.bounds
|
| 455 |
|
| 456 |
+
# CÁLCULO FÍSICO DA QUEDA LIVRE: Do topo supremo do CAD até o seu Ponto Azul
|
| 457 |
if eixo == 'Y':
|
| 458 |
+
topo = bounds[3] + 50.0 # Nasce 50mm acima da peça
|
| 459 |
+
base = py # Termina exatamente no seu Ponto Azul
|
| 460 |
+
altura_sprue = max(abs(topo - base), 10.0)
|
| 461 |
+
centro_grav = (topo + base) / 2.0
|
| 462 |
center = (px, centro_grav, pz)
|
| 463 |
+
dir_vec = (0, 1, 0)
|
| 464 |
elif eixo == 'Z':
|
| 465 |
+
topo = bounds[5] + 50.0
|
| 466 |
+
base = pz
|
| 467 |
+
altura_sprue = max(abs(topo - base), 10.0)
|
| 468 |
+
centro_grav = (topo + base) / 2.0
|
| 469 |
center = (px, py, centro_grav)
|
| 470 |
+
dir_vec = (0, 0, 1)
|
| 471 |
elif eixo == 'X':
|
| 472 |
+
topo = bounds[1] + 50.0
|
| 473 |
+
base = px
|
| 474 |
+
altura_sprue = max(abs(topo - base), 10.0)
|
| 475 |
+
centro_grav = (topo + base) / 2.0
|
| 476 |
center = (centro_grav, py, pz)
|
| 477 |
+
dir_vec = (1, 0, 0)
|
| 478 |
|
| 479 |
cilindro = pv.Cylinder(center=center, direction=dir_vec, radius=st.session_state.diam_vaz/2.0, height=altura_sprue).triangulate()
|
| 480 |
mesh_animacao = mesh_proxy.merge(cilindro)
|
| 481 |
|
| 482 |
pts_anim = mesh_animacao.points
|
| 483 |
+
if eixo == 'Y': grav_anim, r_coords = pts_anim[:, 1], np.sqrt((pts_anim[:, 0] - px)**2 + (pts_anim[:, 2] - pz)**2)
|
| 484 |
+
elif eixo == 'Z': grav_anim, r_coords = pts_anim[:, 2], np.sqrt((pts_anim[:, 0] - px)**2 + (pts_anim[:, 1] - py)**2)
|
| 485 |
+
elif eixo == 'X': grav_anim, r_coords = pts_anim[:, 0], np.sqrt((pts_anim[:, 1] - py)**2 + (pts_anim[:, 2] - pz)**2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
|
| 487 |
grav_norm = (grav_anim - np.min(grav_anim)) / (np.max(grav_anim) - np.min(grav_anim) + 1e-6)
|
| 488 |
r_eff = np.maximum(0, r_coords - (st.session_state.diam_vaz/2.0))
|
|
|
|
| 491 |
campo = (grav_norm * 0.65) + (r_norm * 0.35) + turbulencia
|
| 492 |
mesh_animacao['Preenchimento_Anim'] = (campo - np.min(campo)) / (np.max(campo) - np.min(campo) + 1e-6)
|
| 493 |
|
| 494 |
+
# A DIETA DE VRAM (Resolvendo os Horrores do Loading): Dizimação brutal do Fantasma
|
| 495 |
+
try:
|
| 496 |
+
mold_ghost = mesh_molde.decimate(0.95) # Corta 95% do peso da casca fantasma
|
| 497 |
+
except:
|
| 498 |
+
mold_ghost = mesh_molde.outline() # Plano B blindado: usa apenas o caixote de contorno
|
| 499 |
+
|
| 500 |
+
mold_ghost.points /= 1000.0
|
| 501 |
+
|
| 502 |
st.session_state.frames_filling = []
|
| 503 |
st.session_state.frames_cooling = []
|
| 504 |
temp_dir = tempfile.mkdtemp()
|
|
|
|
| 508 |
lim = (1.0 / passos) * i
|
| 509 |
if lim <= 0: lim = 1e-6
|
| 510 |
f_mesh = mesh_animacao.threshold([0, lim], scalars='Preenchimento_Anim')
|
| 511 |
+
|
| 512 |
pl = pv.Plotter(off_screen=True)
|
| 513 |
+
# Injetamos a casca hiper leve ao invés do modelo original pesado
|
| 514 |
+
pl.add_mesh(mold_ghost, color='white', opacity=0.1, style='wireframe')
|
| 515 |
+
|
| 516 |
if f_mesh.n_points > 0:
|
| 517 |
f_mesh.points /= 1000.0
|
| 518 |
pl.add_mesh(f_mesh, color='#ff4500', metallic=True, smooth_shading=True)
|
| 519 |
+
|
| 520 |
path = os.path.join(temp_dir, f"fill_{i}.glb")
|
| 521 |
pl.export_gltf(path)
|
| 522 |
st.session_state.frames_filling.append(path)
|
| 523 |
pl.close()
|
| 524 |
+
prog.progress(int((i/passos)*40), text="[1/2] Forjando Animação de Enchimento (Base de Dados Otimizada)...")
|
| 525 |
|
| 526 |
t_v = st.session_state.t_vaz
|
| 527 |
t_m = st.session_state.t_molde
|
|
|
|
| 554 |
if st.button("Voltar"): st.session_state.step = 4; st.rerun()
|
| 555 |
|
| 556 |
# ==========================================
|
| 557 |
+
# ETAPA 5: O CINEMA
|
| 558 |
# ==========================================
|
| 559 |
elif st.session_state.step == 5:
|
| 560 |
st.header("5. Telemetria Cinemática")
|