using AStation.Curve;
|
using DevExpress.XtraEditors;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Linq;
|
using System.Windows.Forms;
|
|
|
namespace AStation.WinFrmUI.Chart
|
{
|
public partial class ImportCurveByOnePointCtrl : XtraUserControl
|
{
|
|
//构造函数
|
public ImportCurveByOnePointCtrl()
|
{
|
InitializeComponent();
|
this.comboBoxType.SelectedIndex = 0;
|
this.txtQ.Focus();
|
this.txtQ.SelectAll();
|
|
this.imgCmbCurveSourceFrom.Properties.AddEnum(typeof(AStation.Chart.eSourceWay), false);
|
this.imgCmbCurveSourceFrom.EditValue = AStation.Chart.eSourceWay.现场测试;
|
}
|
|
double _ratedn = -1;
|
AStation.Curve.GroupPoint _ratedParas = null;
|
List<AStation.Curve.CurvePoint> pointInfoQH = null;
|
List<AStation.Curve.CurvePoint> pointInfoQE = null;
|
List<AStation.Curve.CurvePoint> pointInfoQP = null;
|
List<AStation.Curve.CurvePoint> pointInfoNPSH = null;
|
Model.PumpCurveInfo _featCurveExpressGroup = null;
|
|
|
//计算转速比
|
private void CalcNs()
|
{
|
if (string.IsNullOrEmpty(this.txtQ.Text) ||
|
string.IsNullOrEmpty(this.txtH.Text) ||
|
string.IsNullOrEmpty(this.txtN.Text))
|
return;
|
|
var YLJS = Convert.ToInt32(this.spinEditYLJS.Text);
|
var Q = Convert.ToDouble(this.txtQ.Text);
|
var H = Convert.ToDouble(this.txtH.Text);
|
var N = Convert.ToDouble(this.txtN.Text);
|
|
double ns = 0;
|
if (this.checkEditSXB.Checked)
|
{
|
ns = AStation.Curve.PumpCalculateHelper.CalculateNs(Q / 2, H / YLJS, N);
|
}
|
else
|
{
|
ns = AStation.Curve.PumpCalculateHelper.CalculateNs(Q, H / YLJS, N);
|
}
|
|
this.txtNS.EditValue = Math.Round(ns, 2);
|
}
|
|
//产生曲线
|
private bool CreateCurveCore()
|
{
|
_featCurveExpressGroup = null;
|
double? k0 = 0;
|
if (double.TryParse(this.txtK0.Text, out double value))
|
{
|
k0 = Convert.ToDouble(txtK0.Text);
|
if (k0 < 1.001)
|
{
|
XtraMessageBox.Show("关死点系数不能小于1");
|
return false;
|
}
|
}
|
|
if (string.IsNullOrEmpty(this.txtQ.Text) || string.IsNullOrEmpty(this.txtH.Text))
|
{
|
MessageBox.Show("流量扬程不能为空");
|
return false;
|
}
|
if (string.IsNullOrEmpty(this.txtN.Text))
|
{
|
MessageBox.Show("转速不能为空");
|
return false;
|
}
|
|
_ratedn = double.Parse(this.txtN.Text);
|
if (_ratedn < 10)
|
{
|
MessageBox.Show("转速有这么小吗?");
|
return false;
|
}
|
|
_ratedParas = new AStation.Curve.GroupPoint();
|
_ratedParas.Q = double.Parse(this.txtQ.Text);
|
_ratedParas.H = double.Parse(this.txtH.Text);
|
if (_ratedParas.H < 1 || _ratedParas.Q < 1)
|
{
|
MessageBox.Show("流量扬程有这么小吗?");
|
return false;
|
}
|
|
if (string.IsNullOrWhiteSpace(this.txtE.Text))
|
{
|
double ns = AStation.Curve.PumpCalculateHelper.CalculateNs(_ratedParas.Q, _ratedParas.H, _ratedn);
|
double eff = AStation.Curve.PumpCalculateHelper.CalculateEByPumpType(_ratedParas.Q, _ratedParas.H, _ratedn, comboBoxType.SelectedIndex + 1);
|
|
_ratedParas.E = eff;
|
// this.txtE.Text = string.Format("{0:0.0}", eff);
|
this.txtE.EditValue = Math.Round(eff, 1);
|
}
|
else
|
{
|
_ratedParas.E = double.Parse(this.txtE.Text);
|
}
|
if (_ratedParas.E > 99)
|
{
|
MessageBox.Show("效率有这么大吗?");
|
return false;
|
}
|
_ratedParas.P = AStation.Curve.PumpCalculateHelper.CalculateP(_ratedParas.Q, _ratedParas.H, _ratedParas.E);
|
if (string.IsNullOrWhiteSpace(this.txtP.Text))
|
{
|
this.txtP.EditValue = Math.Round(_ratedParas.P, 1);
|
}
|
//汽蚀
|
double NPSHr = 0;
|
if (!double.TryParse(this.txtNPSH.Text, out NPSHr))
|
{
|
NPSHr = AStation.Curve.PumpCalculateHelper.CalculateNPSHrByPumpType(_ratedParas.Q, _ratedParas.H, _ratedn, comboBoxType.SelectedIndex + 1);//双吸离心泵
|
NPSHr = Math.Round(NPSHr, 1);
|
this.txtNPSH.EditValue = NPSHr;
|
}
|
_ratedParas.NPSH = NPSHr;
|
|
//得到点位置
|
bool iOK = DimensionlessCurvesHelper.CalcPoints(_ratedParas, _ratedn, k0,
|
ref pointInfoQH, ref pointInfoQE, ref pointInfoQP, ref pointInfoNPSH, checkEditSXB.Checked, Convert.ToInt32(spinEditYLJS.Value));
|
if (!iOK)
|
{
|
XtraMessageBox.Show("Error:265");
|
return false;
|
}
|
|
//消除驼峰
|
if (k0 == null || k0 < 0.1)
|
{
|
double spaceH = _ratedParas.H / 200;//200为预估值
|
|
for (int i = pointInfoQH.Count - 2; i >= 0; i--)
|
{
|
if (pointInfoQH[i].Y < pointInfoQH[i + 1].Y)
|
{
|
pointInfoQH[i].Y = pointInfoQH[i + 1].Y + spaceH;
|
}
|
}
|
}
|
|
if (!string.IsNullOrEmpty(txtMaxRatio.Text))
|
{
|
double qre = 0;
|
if (double.TryParse(txtMaxRatio.Text, out qre))
|
{
|
if (qre > 1.01 && qre < 1.8)
|
{
|
var ratio = _ratedParas.Q * qre / pointInfoQH.Last().X;
|
if (qre > 1.35)
|
{
|
var pointInfoQH2 = GetFitPointsByExtend(pointInfoQH, ratio);
|
var maxPt_E = GetLineInsert(pointInfoQE[pointInfoQE.Count - 2].X, pointInfoQE[pointInfoQE.Count - 1].X, pointInfoQE[pointInfoQE.Count - 2].Y, pointInfoQE[pointInfoQE.Count - 1].Y, qre * _ratedParas.Q);
|
pointInfoQE.Add(new AStation.Curve.CurvePoint(qre * _ratedParas.Q, maxPt_E));
|
pointInfoQH = pointInfoQH2;
|
pointInfoQE = new AStation.Curve.FitHelper(pointInfoQE).GetFitPoints(20);
|
pointInfoQP = CalculateP(pointInfoQH, pointInfoQE);
|
}
|
else
|
{
|
pointInfoQH = GetFitPointsByExtend(pointInfoQH, ratio);
|
pointInfoQE = GetFitPointsByExtend(pointInfoQE, ratio);
|
pointInfoQP = GetFitPointsByExtend(pointInfoQP, ratio);
|
}
|
}
|
}
|
}
|
|
var qhPoints = pointInfoQH.Select(x => new AStation.Curve.CurvePoint(x.X, x.Y)).ToList();
|
var qePoints = pointInfoQE.Select(x => new AStation.Curve.CurvePoint(x.X, x.Y)).ToList();
|
var qpPoints = pointInfoQP.Select(x => new AStation.Curve.CurvePoint(x.X, x.Y)).ToList();
|
|
var qhCurve = AStation.Curve.FitHelper.BuildCurveExpress(qhPoints, AStation.Curve.eFitType.CubicCurve);
|
var qeCurve = AStation.Curve.FitHelper.BuildCurveExpress(qePoints, AStation.Curve.eFitType.CubicCurve);
|
var qPCurve = AStation.Curve.FitHelper.BuildCurveExpress(qpPoints, AStation.Curve.eFitType.CubicCurve);
|
_featCurveExpressGroup = new Model.PumpCurveInfo(qhCurve, qeCurve, qPCurve);
|
|
this.chartFeatCurveViewCtrl1.SetBindingData(qhCurve, qeCurve, qPCurve);
|
|
return true;
|
}
|
|
|
|
public List<AStation.Curve.CurvePoint> GetFitPointsByExtend(List<AStation.Curve.CurvePoint> points, double ratioExtend, int pointNumber = 20)
|
{
|
if (points == null)
|
return default;
|
var fitPow = AStation.Curve.FitHelper.GetFitPow(AStation.Curve.eFitType.CubicCurve);
|
if (points.Count < fitPow + 1)
|
return default;
|
var express = AStation.Curve.FitHelper.BuildCurveExpress(points, AStation.Curve.eFitType.CubicCurve);
|
return express.GetFitPointsByXRange(express.Min, express.Max * ratioExtend, pointNumber);
|
}
|
|
public double GetLineInsert(double X1, double X2, double Y1, double Y2, double X)
|
{
|
if (Math.Abs(X2 - X1) < 1E-06)
|
{
|
return 0.0;
|
}
|
|
if (Math.Abs(Y2 - Y1) < 1E-06)
|
{
|
return 0.0;
|
}
|
|
return Y1 + (Y2 - Y1) / (X2 - X1) * (X - X1);
|
}
|
|
|
/// <summary>
|
/// 获取数据
|
/// </summary>
|
/// <param name="curveCode"></param>
|
/// <param name="eCurveSourceFrom"></param>
|
/// <param name="featCurvePointGroup"></param>
|
/// <param name="featCurveExpressGroup"></param>
|
/// <returns></returns>
|
public bool GetCurve(out string curveCode, out AStation.Chart.eSourceWay eCurveSourceFrom, out Model.PumpCurveInfo featCurveExpressGroup)
|
{
|
curveCode = this.txtCurveCode.Text.Trim();
|
eCurveSourceFrom = (AStation.Chart.eSourceWay)this.imgCmbCurveSourceFrom.EditValue;
|
featCurveExpressGroup = null;
|
|
if (!CreateCurveCore())
|
return false;
|
|
if (string.IsNullOrEmpty(curveCode))
|
{
|
XtraMessageBox.Show("请输入曲线名称!");
|
return false;
|
}
|
eCurveSourceFrom = (AStation.Chart.eSourceWay)this.imgCmbCurveSourceFrom.EditValue;
|
featCurveExpressGroup = _featCurveExpressGroup;
|
return true;
|
}
|
|
#region 事件
|
|
private void txtQ_EditValueChanged(object sender, EventArgs e)
|
{
|
CalcNs();
|
}
|
|
private void txtH_EditValueChanged(object sender, EventArgs e)
|
{
|
CalcNs();
|
}
|
|
private void txtN_EditValueChanged(object sender, EventArgs e)
|
{
|
CalcNs();
|
}
|
|
private void spinEditYLJS_EditValueChanged(object sender, EventArgs e)
|
{
|
CalcNs();
|
}
|
|
private void labReckon_Click(object sender, EventArgs e)
|
{
|
//水力参数
|
try
|
{
|
if (string.IsNullOrEmpty(txtH.Text) || string.IsNullOrEmpty(txtQ.Text))
|
{
|
MessageBox.Show("流量扬程不能为空");
|
return;
|
}
|
//转速
|
if (string.IsNullOrEmpty(txtN.Text))
|
{
|
MessageBox.Show("转速不能为空");
|
return;
|
}
|
_ratedn = double.Parse(txtN.Text);
|
if (_ratedn < 10)
|
{
|
MessageBox.Show("转速有这么小吗?");
|
return;
|
}
|
_ratedParas = new AStation.Curve.GroupPoint();
|
_ratedParas.Q = double.Parse(txtQ.Text);
|
_ratedParas.H = double.Parse(txtH.Text);
|
if (_ratedParas.H < 1 || _ratedParas.Q < 1)
|
{
|
MessageBox.Show("流量扬程有这么小吗?");
|
return;
|
}
|
|
}
|
catch
|
{
|
MessageBox.Show("请输入数字");
|
return;
|
}
|
|
//double ns = AStation.Curve.PumpCalculateHelper.CalculateNs(_ratedParas.Q, _ratedParas.H, _ratedn);
|
|
double eff = AStation.Curve.PumpCalculateHelper.CalculateEByPumpType(_ratedParas.Q, _ratedParas.H, _ratedn, comboBoxType.SelectedIndex + 1);
|
txtE.Text = string.Format("{0:0.0}", eff);
|
_ratedParas.E = eff;
|
|
double NPSHr = AStation.Curve.PumpCalculateHelper.CalculateNPSHrByPumpType(_ratedParas.Q, _ratedParas.H, _ratedn, comboBoxType.SelectedIndex + 1);//双吸离心泵
|
|
NPSHr = Math.Round(NPSHr, 1);
|
txtNPSH.Text = NPSHr.ToString();
|
}
|
|
private void labCalcuE_Click(object sender, EventArgs e)
|
{
|
#region 得到参数
|
double Q, H, P;
|
try
|
{
|
if (string.IsNullOrEmpty(txtH.Text) || string.IsNullOrEmpty(txtQ.Text) || string.IsNullOrEmpty(txtE.Text))
|
{
|
MessageBox.Show("流量,扬程和功率,不能为空");
|
return;
|
}
|
H = double.Parse(txtH.Text);
|
Q = double.Parse(txtQ.Text);
|
P = double.Parse(txtP.Text);
|
if (H < 1 || Q < 1 || P < 1)
|
{
|
MessageBox.Show("参数有这么小吗");
|
return;
|
}
|
}
|
catch
|
{
|
MessageBox.Show("请输入数字");
|
return;
|
}
|
#endregion
|
|
double E = AStation.Curve.PumpCalculateHelper.CalculateE(Q, H, P);
|
txtE.Text = string.Format("{0:0.0}", E);
|
|
if (E > 99)
|
{
|
MessageBox.Show("功率是否输入有误?");
|
return;
|
}
|
}
|
|
private void labCalcuP_Click(object sender, EventArgs e)
|
{
|
#region 得到参数
|
double Q, H, E;
|
try
|
{
|
if (string.IsNullOrEmpty(txtH.Text) || string.IsNullOrEmpty(txtQ.Text) || string.IsNullOrEmpty(txtE.Text))
|
{
|
MessageBox.Show("流量,扬程和功率,不能为空");
|
return;
|
}
|
H = double.Parse(txtH.Text);
|
Q = double.Parse(txtQ.Text);
|
E = double.Parse(txtE.Text);
|
if (H < 0.1 || Q < 0.1 || E < 1)
|
{
|
MessageBox.Show("参数有这么小吗");
|
return;
|
}
|
}
|
catch
|
{
|
MessageBox.Show("请输入数字");
|
return;
|
}
|
#endregion
|
|
double P = AStation.Curve.PumpCalculateHelper.CalculateP(Q, H, E);
|
if (P < 1)
|
{
|
txtP.Text = string.Format("{0:0.000}", P);
|
}
|
else if (P < 10)
|
{
|
txtP.Text = string.Format("{0:0.00}", P);
|
}
|
else if (P < 100)
|
{
|
txtP.Text = string.Format("{0:0.0}", P);
|
}
|
else
|
{
|
txtP.Text = string.Format("{0:N0}", P);
|
}
|
}
|
|
//生成曲线
|
private void btnCreate_Click(object sender, EventArgs e)
|
{
|
CreateCurveCore();
|
}
|
|
#endregion
|
|
|
public static List<AStation.Curve.CurvePoint> CalculateP(List<AStation.Curve.CurvePoint> pointQH, List<AStation.Curve.CurvePoint> pointQE)
|
{
|
if (pointQH == null || pointQH.Count() <= 2)
|
return null;
|
bool isFromZero = true;
|
if (pointQH.First().X > 500 || pointQH.First().X > pointQH.Last().X * 0.2)
|
isFromZero = false;
|
return CalculateP_RefZero(AStation.Curve.eFitType.CubicCurve, AStation.Curve.eFitType.CubicCurve, AStation.Curve.eFitType.CubicCurve,
|
pointQH, pointQE, AStation.Curve.Constant.WaterDensity, -1, isFromZero);
|
}
|
|
//有时 会把零流量点扬程传入 ref_zero_power
|
public static List<AStation.Curve.CurvePoint> CalculateP_RefZero(
|
AStation.Curve.eFitType CurveFitTypeQH,
|
AStation.Curve.eFitType CurveFitTypeQE,
|
AStation.Curve.eFitType CurveFitTypeQP,
|
List<AStation.Curve.CurvePoint> pointQH,
|
List<AStation.Curve.CurvePoint> pointQE,
|
double midu,
|
double ref_zero_power,
|
bool isFromZero)
|
{
|
if (pointQH == null || pointQH.Count < 3)
|
return null;
|
if (pointQE == null || pointQE.Count < 3)
|
return null;
|
|
var expressQH = AStation.Curve.FitHelper.BuildCurveExpress(pointQH, CurveFitTypeQH);
|
var expressQE = AStation.Curve.FitHelper.BuildCurveExpress(pointQE, CurveFitTypeQE);
|
|
var expressQP = CalculateP_RefZero(CurveFitTypeQE, expressQH, expressQE, midu, ref_zero_power, isFromZero, false);
|
|
return AStation.Curve.FitHelper.GetFitPoints(expressQP, pointQE.Count());
|
}
|
|
public static AStation.Curve.CurveExpress CalculateP_RefZero(
|
AStation.Curve.eFitType CurveFitTypeQP,
|
AStation.Curve.CurveExpress expressQH,
|
AStation.Curve.CurveExpress expressQE,
|
double midu, double ref_zero_power, bool isFromZero, bool isSavePointInExpress)
|
{
|
if (expressQH == null)
|
return null;
|
if (expressQE == null)
|
return null;
|
int point_num = 16;//点不能太多
|
var pointQH = AStation.Curve.FitHelper.GetFitPoints(expressQH, point_num);
|
if (pointQH == null || pointQH.Count < 3)
|
return null;
|
var pointQE = AStation.Curve.FitHelper.GetFitPoints(expressQE, point_num);
|
if (pointQE == null || pointQE.Count < 3)
|
return null;
|
|
List<AStation.Curve.CurvePoint> pointQP = new List<AStation.Curve.CurvePoint>();
|
//间距
|
double minQ = Math.Max(pointQH.First().X, pointQE.First().X);
|
double maxQ = Math.Min(pointQH.Last().X, pointQE.Last().X);
|
|
//
|
double Q, H, E, P;
|
|
double space = (maxQ - minQ) / (point_num - 1);
|
|
AStation.Curve.FitHelper fitCurveQE = new AStation.Curve.FitHelper(expressQE);
|
AStation.Curve.FitHelper fitCurveQH = new AStation.Curve.FitHelper(expressQH);
|
|
if (isFromZero)
|
{
|
#region 保证从0开始: 保证Q=0时,P不是计算出来的;
|
for (int i = 5; i < point_num; i++)//前面几个点不要
|
{
|
Q = pointQE.First().X + space * i;
|
E = fitCurveQE.GetFitPointY(Q);
|
H = fitCurveQH.GetFitPointY(Q);
|
if (H < 0.1 || E < 0.5)
|
continue;
|
|
P = AStation.Curve.PumpCalculateHelper.CalculateP(Q, H, E, midu);
|
if (P < 2)
|
{
|
P = Math.Round(P, 3);
|
}
|
else if (P < 30)
|
{
|
P = Math.Round(P, 2);
|
}
|
else if (P < 100)
|
{
|
P = Math.Round(P, 1);
|
}
|
else
|
{
|
P = Math.Round(P, 0);
|
}
|
pointQP.Add(new AStation.Curve.CurvePoint(Q, P));
|
}
|
|
pointQP = AStation.Curve.FitHelper.GetFitPoints(pointQP, CurveFitTypeQP, point_num);
|
if (pointQP == null)
|
return null;
|
|
|
|
if (ref_zero_power > 0.1)
|
{
|
pointQP.Insert(0, new AStation.Curve.CurvePoint(0, ref_zero_power));
|
}
|
else
|
{
|
if (pointQP[0].Y >= pointQP[1].Y)
|
{
|
pointQP[0].Y = pointQP[1].Y * 0.95;
|
}
|
double startP = AStation.Curve.CurveLineHelper.GetYbyX(pointQP[0].X, pointQP[0].Y, pointQP[1].X, pointQP[1].Y, 0);
|
if (startP < 0.001)
|
startP = pointQP[0].Y;
|
|
if (startP < 2)
|
{
|
startP = Math.Round(startP, 3);
|
}
|
else if (startP < 30)
|
{
|
startP = Math.Round(startP, 2);
|
}
|
else if (startP < 100)
|
{
|
startP = Math.Round(startP, 1);
|
}
|
else
|
{
|
startP = Math.Round(startP, 0);
|
}
|
|
pointQP.Insert(0, new AStation.Curve.CurvePoint(0, startP));
|
}
|
|
|
return AStation.Curve.FitHelper.BuildCurveExpress(pointQP, CurveFitTypeQP);
|
#endregion
|
}
|
else
|
{
|
#region 保证从0开始: 保证Q=0时,P不是计算出来的;
|
for (int i = 0; i < point_num; i++)//前面几个点不要
|
{
|
Q = pointQE.First().X + space * i;
|
E = fitCurveQE.GetFitPointY(Q);
|
H = fitCurveQH.GetFitPointY(Q);
|
if (H < 0.1 || E < 0.5)
|
continue;
|
|
P = AStation.Curve.PumpCalculateHelper.CalculateP(Q, H, E, midu);
|
if (P < 2)
|
{
|
P = Math.Round(P, 3);
|
}
|
else if (P < 30)
|
{
|
P = Math.Round(P, 2);
|
}
|
else if (P < 100)
|
{
|
P = Math.Round(P, 1);
|
}
|
else
|
{
|
P = Math.Round(P, 0);
|
}
|
pointQP.Add(new AStation.Curve.CurvePoint(Q, P));
|
}
|
|
pointQP = AStation.Curve.FitHelper.GetFitPoints(pointQP, CurveFitTypeQP, point_num);
|
if (pointQP == null)
|
return null;
|
|
return AStation.Curve.FitHelper.BuildCurveExpress(pointQP, CurveFitTypeQP);
|
#endregion
|
}
|
|
}
|
|
}
|
}
|