149 lines
4.3 KiB
Python
149 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Script para probar que TSNet funciona con timestep de 1 segundo
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import tempfile
|
|
|
|
# Agregar el directorio TSNet al path
|
|
sys.path.insert(
|
|
0, r"d:\Proyectos\VisualStudio\CtrEditor\bin\Debug\net8.0-windows8.0\tsnet"
|
|
)
|
|
|
|
try:
|
|
import tsnet
|
|
|
|
print("✓ TSNet importado correctamente")
|
|
|
|
# El contenido INP que genera CtrEditor
|
|
inp_content = """[TITLE]
|
|
TSNet Hydraulic Network
|
|
Generated on 11/09/2025 23:48:56
|
|
CtrEditor TSNet Integration
|
|
|
|
[JUNCTIONS]
|
|
;ID Elev Demand Pattern
|
|
NODE_A_Bomba_Hidraulica 0.00 0.00 ;
|
|
NODE_B_Bomba_Hidraulica 0.00 0.00 ;
|
|
|
|
[RESERVOIRS]
|
|
;ID Head Pattern
|
|
|
|
[TANKS]
|
|
;ID Elevation InitLevel MinLevel MaxLevel Diameter MinVol VolCurve
|
|
Tanque_Destino 0.00 1.0 0.0 2.0 1.0 0
|
|
Tanque_Origen 0.00 1.0 0.0 2.0 1.0 0
|
|
|
|
[PIPES]
|
|
;ID Node1 Node2 Length Diameter Roughness MinorLoss Status
|
|
PIPE1 NODE_B_Bomba_Hidraulica Tanque_Destino 1.00 50.0 0.0010 0 Open
|
|
PIPE2 Tanque_Origen NODE_A_Bomba_Hidraulica 1.00 50.0 0.0010 0 Open
|
|
|
|
[PUMPS]
|
|
;ID Node1 Node2 Parameters
|
|
PUMP1 NODE_A_Bomba_Hidraulica NODE_B_Bomba_Hidraulica HEAD CURVE1
|
|
|
|
[VALVES]
|
|
;ID Node1 Node2 Diameter Type Setting MinorLoss
|
|
|
|
[PATTERNS]
|
|
;ID Multipliers
|
|
1 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
|
|
1 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
|
|
1 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
|
|
|
|
[CURVES]
|
|
;ID X-Value Y-Value
|
|
;PUMP CURVE 1
|
|
CURVE1 0 50.00
|
|
CURVE1 2.50 40.00
|
|
CURVE1 5.00 25.00
|
|
|
|
[QUALITY]
|
|
;Node InitQual
|
|
Tanque_Destino 0.0
|
|
NODE_A_Bomba_Hidraulica 0.0
|
|
NODE_B_Bomba_Hidraulica 0.0
|
|
Tanque_Origen 0.0
|
|
|
|
[OPTIONS]
|
|
Units LPS
|
|
Headloss D-W
|
|
Specific Gravity 1.0
|
|
Viscosity 1.00E-003
|
|
Trials 40
|
|
Accuracy 0.001
|
|
CHECKFREQ 2
|
|
MAXCHECK 10
|
|
DAMPLIMIT 0
|
|
Unbalanced Continue 10
|
|
Pattern 1
|
|
Demand Multiplier 1.0
|
|
Emitter Exponent 0.5
|
|
Quality None mg/L
|
|
Diffusivity 1.0
|
|
Tolerance 0.01
|
|
|
|
[TIMES]
|
|
Duration 0:00:10
|
|
Hydraulic Timestep 0:00:01
|
|
Quality Timestep 0:05:00
|
|
Pattern Timestep 1:00:00
|
|
Pattern Start 0:00:00
|
|
Report Timestep 1:00:00
|
|
Report Start 0:00:00
|
|
Start ClockTime 12:00:00 AM
|
|
Statistic None
|
|
|
|
[COORDINATES]
|
|
;Node X-Coord Y-Coord
|
|
Tanque_Destino 0.00 0.00
|
|
NODE_A_Bomba_Hidraulica 1000.00 0.00
|
|
NODE_B_Bomba_Hidraulica 2000.00 0.00
|
|
Tanque_Origen 3000.00 0.00
|
|
|
|
[END]
|
|
"""
|
|
|
|
# Crear archivo INP temporal
|
|
temp_dir = tempfile.gettempdir()
|
|
tsnet_dir = os.path.join(temp_dir, "TSNet")
|
|
os.makedirs(tsnet_dir, exist_ok=True)
|
|
inp_path = os.path.join(tsnet_dir, "test_ctreditor_network.inp")
|
|
|
|
with open(inp_path, "w") as f:
|
|
f.write(inp_content)
|
|
|
|
print(f"Archivo INP creado: {inp_path}")
|
|
|
|
# Intentar ejecutar TSNet
|
|
print("Iniciando simulación TSNet...")
|
|
|
|
inp_file = tsnet.network.Inp(inp_path)
|
|
ts = tsnet.simulation.Initializer(inp_file, "")
|
|
|
|
# Esta línea causaba "float division by zero" antes del arreglo
|
|
ts.run_simulation()
|
|
|
|
print("✓ ¡Simulación TSNet exitosa! El error de división por cero está resuelto.")
|
|
print("✓ Timestep de 1 segundo funciona correctamente.")
|
|
|
|
# Mostrar algunos resultados
|
|
if hasattr(ts, "results") and ts.results:
|
|
print(f"✓ Resultados generados: {len(ts.results)} nodos")
|
|
for node_id in list(ts.results.keys())[:3]: # Mostrar solo los primeros 3
|
|
node_data = ts.results[node_id]
|
|
print(f" - {node_id}: {len(node_data)} timesteps de datos")
|
|
|
|
except ImportError as e:
|
|
print(f"✗ Error al importar TSNet: {e}")
|
|
except Exception as e:
|
|
print(f"✗ Error en simulación TSNet: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
print("\n=== Test completado ===")
|