182 lines
6.7 KiB
Python
182 lines
6.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Investigación correcta de pipes en TSNet
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
|
|
def investigate_pipes_correctly():
|
|
"""
|
|
Investiga la forma correcta de acceder a los pipes en TSNet
|
|
"""
|
|
print("=== INVESTIGACIÓN CORRECTA DE PIPES EN TSNET ===")
|
|
|
|
try:
|
|
import tsnet
|
|
import wntr
|
|
|
|
print(f"✓ TSNet version: {tsnet.__version__}")
|
|
print(f"✓ WNTR version: {wntr.__version__}")
|
|
except ImportError as e:
|
|
print(f"✗ Error al importar: {e}")
|
|
return False
|
|
|
|
# Usar archivo INP existente
|
|
temp_dir = r"c:\Users\migue\AppData\Local\Temp\TSNet"
|
|
inp_path = os.path.join(temp_dir, "network_20250912_003944.inp")
|
|
|
|
if not os.path.exists(inp_path):
|
|
print(f"✗ Archivo INP no encontrado: {inp_path}")
|
|
return False
|
|
|
|
try:
|
|
tm = tsnet.network.TransientModel(inp_path)
|
|
print("✓ Modelo cargado exitosamente")
|
|
|
|
# Investigar diferentes formas de acceder a pipes
|
|
print("\n=== FORMAS DE ACCEDER A PIPES ===")
|
|
|
|
# 1. Probar tm.pipes() como método
|
|
try:
|
|
pipes_method = tm.pipes()
|
|
print(f"✓ tm.pipes() funciona, tipo: {type(pipes_method)}")
|
|
if hasattr(pipes_method, "__len__"):
|
|
print(f" - Número de pipes: {len(pipes_method)}")
|
|
|
|
# Iterar sobre los pipes
|
|
for i, (pipe_name, pipe_obj) in enumerate(pipes_method.items()):
|
|
print(f"\n--- PIPE {i}: {pipe_name} ---")
|
|
print(f" Tipo: {type(pipe_obj)}")
|
|
|
|
# Listar atributos del pipe
|
|
pipe_attrs = [
|
|
attr for attr in dir(pipe_obj) if not attr.startswith("_")
|
|
]
|
|
print(f" Atributos ({len(pipe_attrs)}):")
|
|
for attr in sorted(pipe_attrs)[:10]: # Solo los primeros 10
|
|
try:
|
|
value = getattr(pipe_obj, attr)
|
|
if not callable(value):
|
|
print(f" - {attr}: {value}")
|
|
except:
|
|
pass
|
|
|
|
# Verificar initial_head
|
|
if hasattr(pipe_obj, "initial_head"):
|
|
print(f" ✓ Tiene initial_head: {pipe_obj.initial_head}")
|
|
else:
|
|
print(f" ✗ NO tiene initial_head")
|
|
|
|
# Intentar asignar
|
|
try:
|
|
pipe_obj.initial_head = 0.0
|
|
print(f" ✓ initial_head asignado exitosamente = 0.0")
|
|
except Exception as e:
|
|
print(f" ✗ Error al asignar initial_head: {e}")
|
|
|
|
# Solo verificar el primer pipe para no inundar output
|
|
if i >= 2:
|
|
print(f" ... (mostrando solo los primeros 3 pipes)")
|
|
break
|
|
|
|
except Exception as e:
|
|
print(f"✗ tm.pipes() falló: {e}")
|
|
|
|
# 2. Probar otras formas de acceso
|
|
alternative_methods = [
|
|
"pipe_name_list",
|
|
"get_link",
|
|
]
|
|
|
|
for method_name in alternative_methods:
|
|
if hasattr(tm, method_name):
|
|
try:
|
|
method = getattr(tm, method_name)
|
|
if callable(method):
|
|
if method_name == "pipe_name_list":
|
|
pipe_names = method
|
|
print(f"\n✓ {method_name}: {pipe_names}")
|
|
|
|
# Usar get_link para obtener objetos pipe
|
|
if hasattr(tm, "get_link"):
|
|
for pipe_name in pipe_names[:3]: # Solo los primeros 3
|
|
try:
|
|
pipe_obj = tm.get_link(pipe_name)
|
|
print(
|
|
f"\n--- PIPE via get_link({pipe_name}) ---"
|
|
)
|
|
print(f" Tipo: {type(pipe_obj)}")
|
|
|
|
if hasattr(pipe_obj, "initial_head"):
|
|
print(
|
|
f" ✓ Tiene initial_head: {pipe_obj.initial_head}"
|
|
)
|
|
else:
|
|
print(f" ✗ NO tiene initial_head")
|
|
try:
|
|
pipe_obj.initial_head = 0.0
|
|
print(
|
|
f" ✓ initial_head asignado = 0.0"
|
|
)
|
|
except Exception as e:
|
|
print(f" ✗ Error asignando: {e}")
|
|
|
|
except Exception as e:
|
|
print(
|
|
f" ✗ Error obteniendo pipe {pipe_name}: {e}"
|
|
)
|
|
else:
|
|
result = method()
|
|
print(f"\n✓ {method_name}(): {result}")
|
|
else:
|
|
print(f"\n✓ {method_name}: {method}")
|
|
except Exception as e:
|
|
print(f"✗ Error con {method_name}: {e}")
|
|
|
|
# 3. Intentar simulación sin corrección para ver el error exacto
|
|
print("\n=== SIMULACIÓN SIN CORRECCIÓN (para ver error exacto) ===")
|
|
try:
|
|
results = tsnet.simulation.MOCSimulator(
|
|
tm, results_obj="results", friction="steady"
|
|
)
|
|
print("✓ Simulación exitosa sin corrección")
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ Error en simulación: {e}")
|
|
|
|
# Analizar el error
|
|
error_str = str(e)
|
|
if "initial_head" in error_str:
|
|
print(" → Confirmado: Error por initial_head")
|
|
elif "division by zero" in error_str:
|
|
print(" → Error de división por cero")
|
|
else:
|
|
print(f" → Otro error: {error_str}")
|
|
|
|
# Imprimir traceback para ver dónde ocurre exactamente
|
|
import traceback
|
|
|
|
print("\n--- TRACEBACK COMPLETO ---")
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"✗ Error general: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
|
|
def main():
|
|
"""Función principal"""
|
|
success = investigate_pipes_correctly()
|
|
return success
|
|
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
sys.exit(0 if success else 1)
|