204 lines
7.3 KiB
Python
204 lines
7.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Investigación de initial_velocity en TSNet
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import numpy as np
|
|
|
|
|
|
def investigate_initial_velocity():
|
|
"""
|
|
Investiga qué formato necesita initial_velocity en TSNet
|
|
"""
|
|
print("=== INVESTIGACIÓN INITIAL_VELOCITY 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:
|
|
print("\n=== ANALIZANDO ESTRUCTURA DE PIPES ===")
|
|
|
|
# Cargar modelo
|
|
tm = tsnet.network.TransientModel(inp_path)
|
|
print("✓ Modelo cargado")
|
|
|
|
# Aplicar correcciones básicas primero
|
|
if hasattr(tm, "simulation_period") and tm.simulation_period <= 0:
|
|
tm.simulation_period = 1.0
|
|
if hasattr(tm, "time_step") and tm.time_step <= 0:
|
|
tm.time_step = 0.1
|
|
if tm.time_step >= tm.simulation_period:
|
|
tm.time_step = tm.simulation_period / 10.0
|
|
|
|
print(f"simulation_period = {tm.simulation_period}")
|
|
print(f"time_step = {tm.time_step}")
|
|
|
|
# Investigar pipes
|
|
if hasattr(tm, "pipe_name_list") and hasattr(tm, "get_link"):
|
|
for pipe_name in tm.pipe_name_list:
|
|
pipe_obj = tm.get_link(pipe_name)
|
|
print(f"\n--- PIPE {pipe_name} ---")
|
|
print(f"Tipo: {type(pipe_obj)}")
|
|
|
|
# Buscar atributos relacionados con dimensiones
|
|
relevant_attrs = []
|
|
for attr in dir(pipe_obj):
|
|
if not attr.startswith("_"):
|
|
try:
|
|
value = getattr(pipe_obj, attr)
|
|
# Buscar atributos que podrían indicar dimensiones
|
|
if any(
|
|
keyword in attr.lower()
|
|
for keyword in [
|
|
"length",
|
|
"diameter",
|
|
"segment",
|
|
"node",
|
|
"point",
|
|
]
|
|
):
|
|
relevant_attrs.append((attr, value))
|
|
except:
|
|
pass
|
|
|
|
print("Atributos relevantes:")
|
|
for attr, value in relevant_attrs:
|
|
print(f" {attr}: {value}")
|
|
|
|
# Investigar si tiene algún método relacionado con segmentación
|
|
methods = [
|
|
attr
|
|
for attr in dir(pipe_obj)
|
|
if callable(getattr(pipe_obj, attr)) and not attr.startswith("_")
|
|
]
|
|
segment_methods = [
|
|
m
|
|
for m in methods
|
|
if "segment" in m.lower()
|
|
or "discret" in m.lower()
|
|
or "grid" in m.lower()
|
|
]
|
|
if segment_methods:
|
|
print(f"Métodos de segmentación: {segment_methods}")
|
|
|
|
# Investigar el modelo transient para encontrar parámetros de discretización
|
|
print(f"\n=== INVESTIGANDO DISCRETIZACIÓN EN TRANSIENT MODEL ===")
|
|
|
|
discretization_attrs = []
|
|
for attr in dir(tm):
|
|
if not attr.startswith("_"):
|
|
try:
|
|
value = getattr(tm, attr)
|
|
# Buscar atributos relacionados con discretización espacial
|
|
if any(
|
|
keyword in attr.lower()
|
|
for keyword in [
|
|
"dx",
|
|
"delta",
|
|
"segment",
|
|
"grid",
|
|
"discret",
|
|
"step",
|
|
]
|
|
):
|
|
discretization_attrs.append((attr, value))
|
|
except:
|
|
pass
|
|
|
|
print("Atributos de discretización:")
|
|
for attr, value in discretization_attrs:
|
|
print(f" {attr}: {value}")
|
|
|
|
# Intentar ver si TSNet tiene algún método para calcular el número de segmentos
|
|
print(f"\n=== INTENTANDO CALCULAR NÚMERO DE SEGMENTOS ===")
|
|
|
|
# Método común en métodos de diferencias finitas:
|
|
# Número de segmentos = longitud del pipe / delta_x
|
|
for pipe_name in tm.pipe_name_list:
|
|
pipe_obj = tm.get_link(pipe_name)
|
|
if hasattr(pipe_obj, "length"):
|
|
pipe_length = pipe_obj.length
|
|
print(f"Pipe {pipe_name} longitud: {pipe_length}")
|
|
|
|
# Buscar delta_x o parámetros similares
|
|
possible_dx_attrs = ["dx", "delta_x", "spatial_step"]
|
|
dx = None
|
|
for dx_attr in possible_dx_attrs:
|
|
if hasattr(tm, dx_attr):
|
|
dx = getattr(tm, dx_attr)
|
|
print(f" Encontrado {dx_attr} = {dx}")
|
|
break
|
|
|
|
if dx is None:
|
|
# Estimación: usar un dx razonable basado en la longitud
|
|
dx = pipe_length / 10.0 # 10 segmentos por defecto
|
|
print(f" Estimando dx = {dx} (longitud/10)")
|
|
|
|
num_segments = int(pipe_length / dx) + 1
|
|
print(f" Número de segmentos estimado: {num_segments}")
|
|
|
|
# Crear array de velocidades iniciales
|
|
initial_velocity_array = np.zeros(num_segments)
|
|
print(f" Array initial_velocity shape: {initial_velocity_array.shape}")
|
|
print(f" Array initial_velocity: {initial_velocity_array}")
|
|
|
|
# Intentar asignar el array como initial_velocity
|
|
try:
|
|
pipe_obj.initial_velocity = initial_velocity_array
|
|
print(f" ✓ initial_velocity array asignado exitosamente")
|
|
except Exception as e:
|
|
print(f" ✗ Error asignando array: {e}")
|
|
|
|
# Probar la simulación
|
|
print(f"\n=== PROBANDO SIMULACIÓN CON ARRAYS ===")
|
|
try:
|
|
results = tsnet.simulation.MOCSimulator(
|
|
tm, results_obj="results", friction="steady"
|
|
)
|
|
print("🎉 ¡SIMULACIÓN EXITOSA CON ARRAYS!")
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ Todavía hay error: {e}")
|
|
|
|
# Imprimir traceback para ver exactamente dónde falla
|
|
import traceback
|
|
|
|
print("\n--- TRACEBACK ---")
|
|
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_initial_velocity()
|
|
return success
|
|
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
sys.exit(0 if success else 1)
|