using System;

namespace HydraulicSimulator.Models
{
    /// <summary>
    /// Pérdida menor con coeficiente K
    /// </summary>
    public class MinorLoss : Element
    {
        public double K { get; set; } // adimensional
        public double DRef { get; set; } // m (para el área de referencia)

        public MinorLoss(double k, double dRef)
        {
            K = k;
            DRef = dRef;
        }

        private double Area => Math.PI * (DRef * DRef) / 4.0;

        public override double Dp(double q, Fluid fluid)
        {
            var area = Area;
            var c = K * 0.5 * fluid.Rho / (area * area);
            return c * q * Math.Abs(q);
        }

        public override double DdpDq(double q, Fluid fluid)
        {
            var area = Area;
            var c = K * 0.5 * fluid.Rho / (area * area);
            return 2.0 * c * Math.Abs(q) + 1e-12;
        }
    }
}
