207 lines
9.3 KiB
C#
207 lines
9.3 KiB
C#
using System;
|
|
using CtrEditor.HydraulicSimulator;
|
|
|
|
namespace CtrEditor
|
|
{
|
|
/// <summary>
|
|
/// Ejemplo para probar las nuevas funcionalidades de NPSH
|
|
/// Reproduce el problema original del usuario donde una bomba
|
|
/// seguía funcionando con tanque vacío y alta presión de descarga
|
|
/// </summary>
|
|
public class NPSHTestExample
|
|
{
|
|
public static void TestNPSHConfiguration()
|
|
{
|
|
Console.WriteLine("=== TESTING NPSH VERIFICATION SYSTEM ===");
|
|
Console.WriteLine();
|
|
|
|
// Configuración original problemática del usuario
|
|
Console.WriteLine("1. TESTING ORIGINAL PROBLEM SCENARIO:");
|
|
Console.WriteLine(" - Tanque origen: VACÍO (1.01 bar)");
|
|
Console.WriteLine(" - Tanque destino: 34 bar presión");
|
|
Console.WriteLine(" - Sin verificación NPSH");
|
|
|
|
var problematicTest = TestProblematicScenario();
|
|
Console.WriteLine($" Resultado SIN NPSH: Bomba funciona = {problematicTest.canOperate}");
|
|
Console.WriteLine($" Presión diferencial: {problematicTest.pressureDiff:F2} bar");
|
|
Console.WriteLine();
|
|
|
|
// Test con verificación NPSH habilitada
|
|
Console.WriteLine("2. TESTING WITH NPSH VERIFICATION ENABLED:");
|
|
Console.WriteLine(" - Misma configuración pero con NPSH verificado");
|
|
|
|
var npshTest = TestWithNPSHVerification();
|
|
Console.WriteLine($" Resultado CON NPSH: Bomba puede operar = {npshTest.canOperate}");
|
|
Console.WriteLine($" NPSH Disponible: {npshTest.npshAvailable:F2} m");
|
|
Console.WriteLine($" NPSH Requerido: {npshTest.npshRequired:F2} m");
|
|
Console.WriteLine($" Factor cavitación: {npshTest.cavitationFactor:F2}");
|
|
Console.WriteLine();
|
|
|
|
// Test con condiciones normales de operación
|
|
Console.WriteLine("3. TESTING NORMAL OPERATING CONDITIONS:");
|
|
Console.WriteLine(" - Tanque origen: 5 bar presión");
|
|
Console.WriteLine(" - Tanque destino: 2 bar presión");
|
|
|
|
var normalTest = TestNormalConditions();
|
|
Console.WriteLine($" Resultado NORMAL: Bomba puede operar = {normalTest.canOperate}");
|
|
Console.WriteLine($" NPSH Disponible: {normalTest.npshAvailable:F2} m");
|
|
Console.WriteLine($" Factor cavitación: {normalTest.cavitationFactor:F2}");
|
|
Console.WriteLine();
|
|
|
|
// Test de configuración dinámica
|
|
Console.WriteLine("4. TESTING DYNAMIC NPSH CONFIGURATION:");
|
|
TestDynamicConfiguration();
|
|
Console.WriteLine();
|
|
|
|
Console.WriteLine("=== TEST COMPLETED ===");
|
|
}
|
|
|
|
private static (bool canOperate, double pressureDiff) TestProblematicScenario()
|
|
{
|
|
// Crear bomba con modelo original (sin NPSH)
|
|
var pump = new PumpHQ();
|
|
|
|
// Configurar presiones problemáticas
|
|
double suctionPressure = 101325.0; // 1.01 bar (atmosférica)
|
|
double dischargePressure = 3400000.0; // 34 bar
|
|
double flowRate = 10.0; // L/min
|
|
|
|
// Calcular con modelo original
|
|
double pressureDiff = pump.Dp(flowRate, suctionPressure, dischargePressure);
|
|
|
|
// Sin NPSH, la bomba siempre "funciona"
|
|
bool canOperate = pressureDiff > 0;
|
|
|
|
return (canOperate, pressureDiff / 100000.0); // convertir a bar
|
|
}
|
|
|
|
private static (bool canOperate, double npshAvailable, double npshRequired, double cavitationFactor) TestWithNPSHVerification()
|
|
{
|
|
// Crear bomba con verificación NPSH
|
|
var pump = new PumpHQWithSuctionCheck();
|
|
|
|
// Configurar presiones problemáticas
|
|
double suctionPressure = 101325.0; // 1.01 bar (atmosférica)
|
|
double dischargePressure = 3400000.0; // 34 bar
|
|
double flowRate = 10.0; // L/min
|
|
double tankLevel = 0.5; // 50 cm de altura
|
|
double vaporPressure = 2337.0; // Presión vapor agua a 20°C
|
|
double suctionLosses = 0.5; // Pérdidas de succión estimadas
|
|
|
|
// Actualizar presiones en la bomba
|
|
pump.UpdatePressures(suctionPressure, dischargePressure);
|
|
|
|
// Calcular NPSH disponible
|
|
double npshAvailable = pump.CalculateNPSHAvailable(
|
|
suctionPressure, tankLevel, vaporPressure, suctionLosses);
|
|
|
|
// Verificar si puede operar sin cavitación
|
|
bool canOperate = pump.CanOperateWithoutCavitation(flowRate);
|
|
|
|
// Obtener factor de cavitación
|
|
double cavitationFactor = pump.GetCavitationFactor(flowRate);
|
|
|
|
return (canOperate, npshAvailable, 3.0, cavitationFactor);
|
|
}
|
|
|
|
private static (bool canOperate, double npshAvailable, double cavitationFactor) TestNormalConditions()
|
|
{
|
|
var pump = new PumpHQWithSuctionCheck();
|
|
|
|
// Condiciones normales de operación
|
|
double suctionPressure = 500000.0; // 5 bar
|
|
double dischargePressure = 200000.0; // 2 bar
|
|
double flowRate = 15.0; // L/min
|
|
double tankLevel = 2.0; // 2 metros de altura
|
|
double vaporPressure = 2337.0;
|
|
double suctionLosses = 0.3;
|
|
|
|
pump.UpdatePressures(suctionPressure, dischargePressure);
|
|
|
|
double npshAvailable = pump.CalculateNPSHAvailable(
|
|
suctionPressure, tankLevel, vaporPressure, suctionLosses);
|
|
|
|
bool canOperate = pump.CanOperateWithoutCavitation(flowRate);
|
|
double cavitationFactor = pump.GetCavitationFactor(flowRate);
|
|
|
|
return (canOperate, npshAvailable, cavitationFactor);
|
|
}
|
|
|
|
private static void TestDynamicConfiguration()
|
|
{
|
|
// Crear manager de simulación hidráulica
|
|
var manager = new HydraulicSimulationManager();
|
|
|
|
Console.WriteLine(" Configuración inicial - NPSH deshabilitado:");
|
|
manager.EnableNPSHVerification = false;
|
|
Console.WriteLine($" NPSH habilitado: {manager.EnableNPSHVerification}");
|
|
|
|
Console.WriteLine(" Habilitando NPSH con parámetros personalizados:");
|
|
manager.ConfigureNPSHSettings(
|
|
enableNPSH: true,
|
|
npshRequired: 2.5, // metros
|
|
vaporPressure: 2500.0, // Pa
|
|
suctionLosses: 0.8 // metros
|
|
);
|
|
|
|
Console.WriteLine($" NPSH habilitado: {manager.EnableNPSHVerification}");
|
|
Console.WriteLine(" Configuración aplicada correctamente");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Método para integrar en el UI y probar con bombas reales
|
|
/// </summary>
|
|
public static void TestWithRealPumpComponent()
|
|
{
|
|
Console.WriteLine("=== TESTING REAL PUMP COMPONENT ===");
|
|
Console.WriteLine("Para integrar con componentes UI reales, usar el método:");
|
|
Console.WriteLine("NPSHTestExample.TestWithRealPumpComponent() desde el UI");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Método para verificar el problema original específico del usuario
|
|
/// </summary>
|
|
public static void VerifyOriginalProblemFixed()
|
|
{
|
|
Console.WriteLine("=== VERIFICANDO SOLUCIÓN AL PROBLEMA ORIGINAL ===");
|
|
Console.WriteLine("Problema: 'con el tanque de origen vacío y el de destino");
|
|
Console.WriteLine("con una presión de 34 bar la bomba continúa a llenar el tanque de destino'");
|
|
Console.WriteLine();
|
|
|
|
var pump = new PumpHQWithSuctionCheck();
|
|
|
|
// Exactamente las condiciones del problema
|
|
double suctionPressure = 101325.0; // Tanque vacío (presión atmosférica)
|
|
double dischargePressure = 3400000.0; // 34 bar como reportó el usuario
|
|
double flowRate = 5.0; // Flujo típico
|
|
|
|
pump.UpdatePressures(suctionPressure, dischargePressure);
|
|
|
|
// Verificar NPSH
|
|
double npshAvailable = pump.CalculateNPSHAvailable(
|
|
suctionPressure, 0.1, 2337.0, 0.5); // Tanque casi vacío
|
|
|
|
bool canOperate = pump.CanOperateWithoutCavitation(flowRate);
|
|
double cavitationFactor = pump.GetCavitationFactor(flowRate);
|
|
|
|
Console.WriteLine($"Presión succión: {suctionPressure/100000:F2} bar");
|
|
Console.WriteLine($"Presión descarga: {dischargePressure/100000:F2} bar");
|
|
Console.WriteLine($"NPSH disponible: {npshAvailable:F2} m");
|
|
Console.WriteLine($"Factor cavitación: {cavitationFactor:F2}");
|
|
Console.WriteLine($"Bomba puede operar: {canOperate}");
|
|
Console.WriteLine();
|
|
|
|
if (!canOperate)
|
|
{
|
|
Console.WriteLine("✅ PROBLEMA SOLUCIONADO: La bomba ya no puede operar");
|
|
Console.WriteLine(" en condiciones físicamente imposibles!");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("❌ PROBLEMA PERSISTE: La bomba aún puede operar");
|
|
Console.WriteLine(" en condiciones incorrectas.");
|
|
}
|
|
}
|
|
}
|
|
}
|