using DevExpress.XtraEditors;
|
using Yw.Ahart;
|
|
namespace Yw.WinFrmUI.Phart
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public partial class PumpChartPointImportCtrl : XtraUserControl
|
{
|
public PumpChartPointImportCtrl()
|
{
|
InitializeComponent();
|
|
this.repTxtk0.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
|
this.repTxtFlow.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
|
|
}
|
|
|
private List<Yw.Geometry.Point2d> _def_qh_pt_list = null;
|
private List<Yw.Geometry.Point2d> _def_qe_pt_list = null;
|
private List<Yw.Geometry.Point2d> _def_qp_pt_list = null;
|
private List<Yw.Geometry.Point2d> _def_npsh_pt_list = null;
|
private Ahart.eFeatType _feat_type_qh = Ahart.eFeatType.Cubic;
|
private Ahart.eFeatType _feat_type_qe = Ahart.eFeatType.Cubic;
|
private Ahart.eFeatType _feat_type_qp = Ahart.eFeatType.Cubic;
|
|
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(double flow, double head, double n, double? eff, double stage_number, bool is_sxp)
|
{
|
this.barTxtFlow.EditValue = flow;
|
this.barTxtHead.EditValue = head;
|
this.barTxtN.EditValue = n;
|
this.barTxtEff.EditValue = eff;
|
this.barSpinLevel.EditValue = stage_number;
|
this.barCekIsSxp.Checked = is_sxp;
|
|
this.repImgCmbPumpType.AddEnum<eCalcPumpType>();
|
this.barImgCmbPumpType.EditValue = eCalcPumpType.单级单吸离心泵;
|
|
this.repImgCmbPumpType.ButtonClick += (s, e) =>
|
{
|
if (e.Button.Tag is string reckon)
|
{
|
CalcByPumpType();
|
}
|
};
|
|
this.repTxtEff.ButtonClick += (s, e) =>
|
{
|
CalcEff();
|
};
|
|
this.repTxtPower.ButtonClick += (s, e) =>
|
{
|
CalcPower();
|
};
|
|
this.barTxtFlow.EditValueChanged += (s, e) =>
|
{
|
CalcNs();
|
};
|
|
this.barTxtHead.EditValueChanged += (s, e) =>
|
{
|
CalcNs();
|
};
|
|
this.barTxtN.EditValueChanged += (s, e) =>
|
{
|
CalcNs();
|
};
|
|
this.barSpinLevel.EditValueChanged += (s, e) =>
|
{
|
CalcNs();
|
};
|
|
Create();
|
}
|
|
//是否是无效数据
|
private bool IsInvalidData()
|
{
|
if (this.barTxtFlow.EditValue == null)
|
{
|
return true;
|
}
|
if (this.barTxtHead.EditValue == null)
|
{
|
return true;
|
}
|
if (this.barTxtN.EditValue == null)
|
{
|
return true;
|
}
|
if (this.barSpinLevel.EditValue == null)
|
{
|
return true;
|
}
|
|
if (this.barTxtN.EditValue is not double n)
|
{
|
return true;
|
}
|
if (this.barTxtFlow.EditValue is not double flow)
|
{
|
return true;
|
}
|
if (this.barTxtHead.EditValue is not double head)
|
{
|
return true;
|
}
|
if (this.barImgCmbPumpType.EditValue is not eCalcPumpType pump_type)
|
{
|
return true;
|
}
|
|
return false;
|
}
|
|
//根据泵类型计算(估算)
|
private void CalcByPumpType()
|
{
|
if (IsInvalidData())
|
return;
|
var n = Convert.ToDouble(this.barTxtN.EditValue);
|
if (n < 10)
|
return;
|
var flow = Convert.ToDouble(this.barTxtFlow.EditValue);
|
var head = Convert.ToDouble(this.barTxtHead.EditValue);
|
var pump_type = (eCalcPumpType)this.barImgCmbPumpType.EditValue;
|
var eff = Yw.Pump.CalculationHelper.CalcuEByPumpType(flow, head, n, (int)pump_type);
|
var npsh_r = Yw.Pump.CalculationHelper.CalcuNPSHrByPumpType(flow, head, n, (int)pump_type);
|
|
eff = Math.Round(eff, 1);
|
npsh_r = Math.Round(npsh_r, 1);
|
this.barTxtEff.EditValue = eff;
|
this.barTxtNPSH.EditValue = npsh_r;
|
}
|
|
//计算转速比
|
private void CalcNs()
|
{
|
if (IsInvalidData())
|
return;
|
|
var flow = Convert.ToDouble(this.barTxtFlow.EditValue);
|
var head = Convert.ToDouble(this.barTxtHead.EditValue);
|
var n = Convert.ToDouble(this.barTxtN.EditValue);
|
var stage_number = Convert.ToInt32(this.barSpinLevel.EditValue);
|
|
if (this.barCekIsSxp.Checked)
|
flow /= 2;
|
var ns = Yw.Pump.CalculationHelper.CalcuNs(flow, head / stage_number, n);
|
ns = Math.Round(ns, 2);
|
this.barTxtNRatio.EditValue = ns;
|
}
|
|
//计算效率
|
private void CalcEff()
|
{
|
if (IsInvalidData())
|
return;
|
if (this.barTxtPower.EditValue is not double)
|
return;
|
var flow = Convert.ToDouble(this.barTxtFlow.EditValue);
|
var head = Convert.ToDouble(this.barTxtHead.EditValue);
|
var power = Convert.ToDouble(this.barTxtPower.EditValue);
|
|
var eff = Yw.Pump.CalculationHelper.CalcuE(flow, head, power);
|
eff = Math.Round(eff, 1);
|
this.barTxtEff.EditValue = eff;
|
if (eff > 99)
|
{
|
MessageBox.Show("功率是否输入有误?");
|
return;
|
}
|
}
|
|
//计算功率
|
private void CalcPower()
|
{
|
if (IsInvalidData())
|
return;
|
if (this.barTxtEff.EditValue is not double)
|
return;
|
|
var flow = Convert.ToDouble(this.barTxtFlow.EditValue);
|
var head = Convert.ToDouble(this.barTxtHead.EditValue);
|
var eff = Convert.ToDouble(this.barTxtEff.EditValue);
|
|
var power = Yw.Pump.CalculationHelper.CalcuP(flow, head, eff);
|
var digits = 0;
|
if (power < 1)
|
digits = 3;
|
else if (power < 10)
|
digits = 2;
|
else if (power < 100)
|
digits = 1;
|
power = Math.Round(power, digits);
|
this.barTxtPower.EditValue = power;
|
}
|
|
//生成曲线
|
private bool CreateCurve(out List<Yw.Geometry.Point2d> qh_pt_list, out List<Yw.Geometry.Point2d> qe_pt_list, out List<Yw.Geometry.Point2d> qp_pt_list)
|
{
|
qh_pt_list = null;
|
qe_pt_list = null;
|
qp_pt_list = null;
|
if (IsInvalidData())
|
return false;
|
if (this.barTxtEff.EditValue == null)
|
{
|
CalcEff();
|
}
|
if (this.barTxtPower.EditValue == null)
|
{
|
CalcPower();
|
}
|
|
|
double? k0 = 0;
|
if (this.barTxtk0.EditValue != null)
|
{
|
k0 = Convert.ToDouble(barTxtk0.EditValue);
|
if (k0 < 1.001)
|
{
|
XtraMessageBox.Show("关死点系数不能小于1");
|
return false;
|
}
|
}
|
|
double flow, head, eff, power, n;
|
flow = Convert.ToDouble(this.barTxtFlow.EditValue);
|
head = Convert.ToDouble(this.barTxtHead.EditValue);
|
eff = Convert.ToDouble(this.barTxtEff.EditValue);
|
power = Convert.ToDouble(this.barTxtPower.EditValue);
|
n = Convert.ToDouble(this.barTxtN.EditValue);
|
|
|
if (eff > 99)
|
{
|
XtraMessageBox.Show("效率有这么大吗?");
|
return false;
|
}
|
|
if (this.barTxtNPSH.EditValue == null)
|
{
|
var pump_type = (eCalcPumpType)this.barImgCmbPumpType.EditValue;
|
var npsh_r = Yw.Pump.CalculationHelper.CalcuNPSHrByPumpType(flow, head, n, (int)pump_type);//双吸离心泵
|
npsh_r = Math.Round(npsh_r, 1);
|
this.barTxtNPSH.EditValue = npsh_r;
|
}
|
|
var pt = new PumpQueryPointViewModel();
|
pt.Q = flow;
|
pt.H = head;
|
pt.E = eff;
|
pt.P = power;
|
pt.N = n;
|
pt.Hz = 50;
|
|
|
//得到点位置
|
var stage_number = Convert.ToInt32(this.barSpinLevel.EditValue);
|
bool is_ok = Yw.Pump.PerformDimensionlessCurveHelper.CalcPoints(pt.Q, pt.H, pt.E ?? 0, pt.P ?? 0, n, k0,
|
_feat_type_qh, _feat_type_qe, _feat_type_qp,
|
ref qh_pt_list, ref qe_pt_list, ref qp_pt_list, barCekIsSxp.Checked, stage_number);
|
if (!is_ok)
|
{
|
XtraMessageBox.Show("计算失败!");
|
return false;
|
}
|
|
//消除驼峰
|
if (k0 == null || k0 < 0.1)
|
{
|
double space_head = head / 200;//200为预估值
|
for (int i = qh_pt_list.Count - 2; i >= 0; i--)
|
{
|
if (qh_pt_list[i].Y < qh_pt_list[i + 1].Y)
|
{
|
qh_pt_list[i].Y = qh_pt_list[i + 1].Y + space_head;
|
}
|
}
|
}
|
|
if (this.barTxtFlowMaxRatio.EditValue != null)
|
{
|
var qre = Convert.ToDouble(this.barTxtFlowMaxRatio.EditValue);
|
if (qre > 1.01 && qre < 1.8)
|
{
|
var ex_q = flow * qre;
|
var max_q = qh_pt_list.Last().X;
|
var ratio = ex_q / max_q;
|
if (qre > 1.35)
|
{
|
var index1 = qe_pt_list.Count - 2;
|
var index2 = qe_pt_list.Count - 1;
|
var x1 = qe_pt_list[index1].X;
|
var y1 = qe_pt_list[index1].Y;
|
var x2 = qe_pt_list[index2].X;
|
var y2 = qe_pt_list[index2].Y;
|
var x = qre * flow;
|
|
|
var max_powert_E = Yw.Geometry.LineHelper.GetLineInsert(x1, x2, y1, y2, x);
|
qe_pt_list.Add(new Yw.Geometry.Point2d(qre * flow, max_powert_E));
|
|
qh_pt_list = qh_pt_list.GetExpandPointList(_feat_type_qh, 1, ratio);
|
qe_pt_list = qe_pt_list.GetPointList(_feat_type_qe, 20);
|
qp_pt_list = Yw.Pump.CalculationHelper.CalcuP(_feat_type_qp, qh_pt_list, _feat_type_qh, qe_pt_list, _feat_type_qe);
|
}
|
else
|
{
|
qh_pt_list = qh_pt_list.GetExpandPointList(_feat_type_qh, 1, ratio);
|
qe_pt_list = qe_pt_list.GetExpandPointList(_feat_type_qe, 1, ratio);
|
qp_pt_list = qp_pt_list.GetExpandPointList(_feat_type_qp, 1, ratio);
|
}
|
}
|
}
|
|
return true;
|
|
}
|
|
private void Create()
|
{
|
if (IsInvalidData())
|
return;
|
|
var bol = CreateCurve(out List<Yw.Geometry.Point2d> qh_pt_list, out List<Yw.Geometry.Point2d> qe_pt_list, out List<Yw.Geometry.Point2d> qp_pt_list);
|
_def_qh_pt_list = qh_pt_list;
|
_def_qe_pt_list = qe_pt_list;
|
_def_qp_pt_list = qp_pt_list;
|
|
if (!bol)
|
{
|
this.pumpViewChart1.Clear();
|
}
|
else
|
{
|
var list = new List<Yw.WinFrmUI.Phart.PumpViewChartViewModel>();
|
var qh = GetViewModel(_def_qh_pt_list, Yw.Ahart.eCurveType.QH);
|
qh.Color = Yw.WinFrmUI.Phart.PumpChartDisplay.CurveColorQH;
|
list.Add(qh);
|
if (_def_qe_pt_list != null && _def_qe_pt_list.Any())
|
{
|
var qe = GetViewModel(_def_qe_pt_list, Yw.Ahart.eCurveType.QE);
|
qe.Color = Yw.WinFrmUI.Phart.PumpChartDisplay.CurveColorQE;
|
list.Add(qe);
|
}
|
|
if (_def_qp_pt_list != null && _def_qp_pt_list.Any())
|
{
|
var qp = GetViewModel(_def_qp_pt_list, Yw.Ahart.eCurveType.QP);
|
qp.Color = Yw.WinFrmUI.Phart.PumpChartDisplay.CurveColorQP;
|
list.Add(qp);
|
}
|
|
this.pumpViewChart1.SetBindingData(list,null,false);
|
}
|
}
|
|
private Yw.WinFrmUI.Phart.PumpViewChartViewModel GetViewModel(List<Yw.Geometry.Point2d> pt_list,Yw.Ahart.eCurveType curve_type)
|
{
|
var last_pt = pt_list.Last();
|
var vm = new Yw.WinFrmUI.Phart.PumpViewChartViewModel();
|
vm.Id = Guid.NewGuid().ToString();
|
vm.Hz = 50;
|
vm.N = Convert.ToDouble(this.barTxtN.EditValue);
|
vm.CurveType = curve_type;
|
vm.FeatType = eFeatType.Cubic;
|
vm.DefPointList = pt_list;
|
vm.FitPointList = pt_list;
|
vm.GraphParas = "";
|
return vm;
|
}
|
|
|
//生成
|
private void barBtnCreate_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
Create();
|
}
|
|
|
/// <summary>
|
/// 获取数据
|
/// </summary>
|
public bool Get(
|
out List<Yw.Geometry.Point2d> def_qh_pt_list,
|
out List<Yw.Geometry.Point2d> def_qe_pt_list,
|
out List<Yw.Geometry.Point2d> def_qp_pt_list,
|
out Yw.Ahart.eFeatType feat_type_qh,
|
out Yw.Ahart.eFeatType feat_type_qe,
|
out Yw.Ahart.eFeatType feat_type_qp)
|
{
|
def_qh_pt_list = _def_qh_pt_list;
|
def_qe_pt_list = _def_qe_pt_list;
|
def_qp_pt_list = _def_qp_pt_list;
|
feat_type_qh = _feat_type_qh;
|
feat_type_qe = _feat_type_qe;
|
feat_type_qp = _feat_type_qp;
|
if (def_qh_pt_list == null || !def_qh_pt_list.Any())
|
return false;
|
return true;
|
}
|
}
|
}
|