using Hydro.CodeProvider;
|
using Hydro.CommonBase;
|
using Hydro.ConfigModel;
|
using Hydro.HydraulicModel;
|
using Hydro.ParrelControl;
|
|
using SolutionDBHelper_NS;
|
using System;
|
using System.CodeDom;
|
using System.Collections.Generic;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using System.Xml.Linq;
|
//using WaterDistributioinManager;
|
using Hydro.ConfigModel;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
namespace Hydro.HydraulicHelperNS
|
{
|
public partial class HydraulicHelper
|
{
|
#region 系统设置
|
public string SetOption()
|
{
|
string result = null;
|
int err = 0;
|
err=epanet.setoption(HydraulicCore.Const_class.Const_Save_results_Mode.EN_NOSAVE, 0);
|
if (err > 0) return ReportQuestion( err);
|
|
err = epanet.setstatusreport(HydraulicCore.Const_class.Const_statuslevel.EN_NONE);
|
if (err > 0) return ReportQuestion(err);
|
|
|
return result;
|
}
|
#endregion
|
|
|
|
#region 传参到模型中
|
string SetValueToModel_条件(string txt="初始条件")
|
{
|
string result = null;
|
int err = 0;
|
//设置初始条件后计算
|
List<variable> variables;
|
if (txt=="初始条件")
|
variables= param.初始条件;
|
else
|
variables = param.下阶段条件;
|
|
variables.ForEach(v =>
|
{
|
|
if (result != null) return;
|
List<int> list_index = new List<int>();
|
if (v.modelIndex > 0 )
|
{
|
list_index.Add(v.modelIndex);
|
}
|
else if (v.modelIndex == 0)
|
{
|
v.Vars.ForEach(s => list_index.Add(s.modelIndex));
|
}
|
dynamic temp = v.LogicValue;
|
if (temp == null)
|
{
|
result = $"{v.logicType}[{v.Name}]报错,未获取到LogicValue\r\n报错位置:Calc_ValsInitValue=>{txt}设置-->v.LogicValue的值为空";
|
return;
|
}
|
for (int i = 0; i < list_index.Count; i++)
|
{
|
if (!v.isArrInput)
|
err = SetItemValue(list_index[i], temp, (HydraulicInputType)v.Type);
|
else
|
err = SetItemPattern("Pattern_" + v.expressString, list_index[i], v.LogicValues, (HydraulicInputType)v.Type);
|
|
if (err > 9)
|
{
|
result = $"{v.logicType}[{v.Name}]{ReportQuestion(err)}\r\n报错位置:Calc_ValsInitValue-->{txt}设置-->SetValueToModel";
|
break;
|
}
|
}
|
|
|
|
/*
|
*[Cloudflight修改]2024-5-15
|
*LogicValues不再作为EPA中的模式使用,而是作为实际值使用,每次计算时都会按照LogicValues[i]的值进行设置
|
*/
|
//if (v.LogicValues != null && v.LogicValues.Length > 0)
|
//{
|
// for (int i = 0; i < list_index.Count; i++)
|
// {
|
// err = SetItemPattern("Pattern_" + v.expressString, list_index[i], v.LogicValues, (HydraulicInputType)v.Type);
|
// if (err > 9)
|
// result = $"Calc_ValsInitValue:{v.logicType}[{v.Name}]{ReportQuestion(err)}";
|
// }
|
//}
|
//else //设置模式跟设置值,只设一个
|
//{
|
// dynamic temp = v.LogicValue;
|
// //if (temp == null) temp = v.expressString;
|
// if (temp == null)
|
// result = $"{v.logicType}[{v.Name}]未获取到LogicValue\r\n报错位置:Calc_ValsInitValue=>初始条件设置";
|
// else
|
// {
|
// err = SetItemValue(v.modelIndex, temp, (HydraulicInputType)v.Type);
|
// if (err > 9)
|
// result = $"{v.logicType}[{v.Name}]{ReportQuestion(err)}报错位置:Calc_ValsInitValue=>初始条件设置";
|
// }
|
//}
|
|
//else if (v.modelIndex==0)
|
//{
|
// v.Vars.ForEach(s => s.CalcValue_Init = GetCalcValue(s));
|
//}
|
});
|
return result;
|
}
|
|
string set下阶段条件()
|
{
|
return SetValueToModel_条件("下阶段条件");
|
}
|
|
|
/// <summary>
|
/// 初始值计算
|
/// </summary>
|
/// <param name="param"></param>
|
/// <returns></returns>
|
public string Calc_ValsInitValue(out bool isCalc)
|
{
|
|
#region 初始判断
|
var TypeArr = Enum.GetValues(typeof(HydraulicInputType));
|
//this.param = param;
|
|
string result = null;
|
int err = 0;
|
|
#endregion
|
//处理变量
|
bool flag = true;
|
|
isCalc = false;
|
|
variable vv = null;
|
|
if ((vv = param.水量分配变量.Find(v => v.IndicatorType == "总水量")) != null && gParam.CurrentTotalDemand == -1)
|
{
|
int multiTimes = gParam.GlobalConfig.Ext.MultiTimes;
|
|
err = epanet.setoption(HydraulicCore.Const_class.Const_Option_types.EN_DEMANDMULT, 1);
|
|
//获取变量初始值
|
flag = true;
|
|
if (vv != null)
|
{
|
if (gParam.CurrentTotalDemand == -1)
|
{
|
double demand = 0;
|
double demand1 = 0;
|
|
err = epanet.getTotalDemand(multiTimes, out demand);
|
//demand1 = vv.Vars[0].GetValue(GetCalcValue, 0, true);
|
|
gParam.CurrentTotalDemand = demand;
|
//(vv.Vars[0] as variable).Value_Set = null;
|
|
|
Log.Add($"==============系统设置=============\r\n模型时刻[{gParam.GlobalConfig.Ext.MultiTimes}]epa计算时刻[{multiTimes}]\r\nepanet方法统计总水量:{demand}计算方法统计总水量:{demand1}\r\n总水量为{gParam.CurrentTotalDemand}");
|
}
|
}
|
}
|
|
result=SetValueToModel_条件();
|
if (result != null) return result;
|
|
param.水量分配变量.ForEach(v =>
|
{
|
if (result != null) return;
|
if ( v.IndicatorType == "总水量")
|
{
|
dynamic temp = v.LogicValue;
|
//if (temp == null) temp = v.expressString;
|
if (temp == null)
|
result = $"{v.logicType}[{v.Name}]未获取到逻辑值\r\n报错位置:Calc_ValsInitValue";
|
else
|
{
|
err = SetItemValue(v.modelIndex, temp, (HydraulicInputType)v.Type);
|
if (err > 9)
|
result = $"总水量设置错误:{v.logicType}[{v.Name}]{ReportQuestion(err)}\r\n报错位置:Calc_ValsInitValue";
|
}
|
|
}
|
|
//else if (v.IndicatorType == "当量分配")
|
//{
|
// try
|
// {
|
// gParam.GlobalConfig.Ext.Distribution_UnitDemands = v.LogicPattern.Select(s => (float)s).ToArray();
|
// gParam.GlobalConfig.Ext.waterdistributeMode = 0;
|
// }
|
// catch
|
// {
|
// result = $"{v.logicType}(当量分配)[{v.Name}]{v.expressType}分配表达式格式错误";
|
// return;
|
// }
|
//}
|
//else if (v.IndicatorType == "随机分配")
|
//{
|
// try
|
// {
|
// gParam.GlobalConfig.Ext.Distribution_OverAvgFactor = (float)v.LogicValue;
|
// gParam.GlobalConfig.Ext.waterdistributeMode = 1;
|
// }
|
// catch
|
// {
|
// result = $"{v.logicType}(随机分配)[{v.Name}]{v.expressType}水量分配表达式格式错误";
|
// return;
|
// }
|
//}
|
|
});
|
if (result != null) return result;
|
|
|
//if ((vv = param.初始条件.Find(v => v.IndicatorType == "总水量")) != null && gParam.CurrentTotalDemand == -1 || param.变量全集.FindAll(v => variable.listUsedInitValue.IndexOf(v.expressType) >= 0).Count > 0)
|
if (gParam.GlobalConfig.Ext.MultiTimes>=0 && gParam.GlobalConfig.Ext.isWaterModelCalc && param.变量全集.FindAll(v => variable.listUsedInitValue.IndexOf(v.expressType) >= 0).Count > 0 )
|
{
|
//BookMark :2024年5月21日初始计算值的实现,目前只考虑了单时刻计算,若需要多时刻计算,需要重新设计
|
int CurrentEPAPeriod = -1;
|
isCalc = true;
|
//计算
|
int multiTimes = gParam.GlobalConfig.Ext.MultiTimes;
|
EPACalc(param, null, multiTimes,ref CurrentEPAPeriod);
|
|
param.约束变量.FindAll(m => variable.listUsedInitValue.IndexOf(m.expressType) >= 0).ForEach(v =>
|
{
|
v.CalcValue_Init = GetModelValue(v);
|
});
|
|
param.变量.FindAll(m => variable.listUsedInitValue.IndexOf(m.expressType) >= 0).ForEach( v =>
|
{
|
v.CalcValue_Init = GetModelValue(v);
|
});
|
//集合不再实现初始计算值
|
param.集合.FindAll(m => variable.listUsedInitValue.IndexOf(m.expressType) >= 0).ForEach(v =>
|
{
|
v.CalcValue_Init = GetModelValue(v);
|
//s.Vars.ForEach(v =>
|
//{
|
// v.Type = s.Type;
|
// v.isNode = s.isNode;
|
// v.CalcValue_Init = GetCalcValue(v);
|
//});
|
});
|
}
|
return null;
|
|
}
|
|
/// <summary>
|
/// 将配置值和SCADA值设定到模型中
|
/// </summary>
|
/// <param name="param"></param>
|
/// <returns></returns>
|
public string SetVarsToModel(bool isInitVarSetted = false)
|
{
|
|
#region 初始判断
|
|
|
|
var TypeArr = Enum.GetValues(typeof(HydraulicInputType));
|
//this.param = param;
|
|
string result = null;
|
int err = 0;
|
|
#endregion
|
|
//result=SetOption();
|
//if (result != null) return result;
|
|
|
param.水量分配变量.ForEach(v =>
|
{
|
if (result != null) return;
|
if ( v.IndicatorType == "总水量")
|
{
|
dynamic temp = v.LogicValue;
|
if (temp == null) temp = v.expressString;
|
err = SetItemValue(v.modelIndex, temp, (HydraulicInputType)v.Type);
|
if (err > 9)
|
result = $"总水量设置错误:{v.logicType}[{v.Name}]{ReportQuestion(err)}";
|
}
|
//else if (v.IndicatorType == "总分配水量")
|
//{
|
// dynamic temp = v.LogicValue;
|
// if (temp == null) temp = v.expressString;
|
// err = SetItemValue(v.modelIndex, temp, (HydraulicInputType)v.Type);
|
// if (err > 9)
|
// result = $"总分配水量设置错误:{v.logicType}[{v.Name}]{ReportQuestion(err)}";
|
//}
|
});
|
if (result != null) return result;
|
|
|
if (!isInitVarSetted) result = SetValueToModel_条件();
|
if (result != null) return result;
|
#region 抽取成方法
|
//param.初始条件.ForEach(v =>
|
//{
|
// if (result != null) return;
|
// if (v.modelIndex > 0)
|
// {
|
// if (v.LogicValues != null && v.LogicValues.Length > 0)
|
// {
|
// err = SetItemPattern(v.modelObjectID, v.LogicValues, (HydraulicInputType)v.Type);
|
// if (err > 9)
|
// result = $"SetVarsToModel:{v.logicType}[{v.Name}]{ReportQuestion(err)}";
|
// }
|
// else //设置模式跟设置值,只设一个
|
// {
|
// dynamic temp = v.LogicValue;
|
// if (temp == null) temp = v.expressString;
|
// err = SetItemValue(v.modelIndex, temp, (HydraulicInputType)v.Type);
|
// if (err > 9)
|
// result = $"SetVarsToModel:{v.logicType}[{v.Name}]{ReportQuestion(err)}";
|
// }
|
// }
|
//});
|
//if (result != null) return result;
|
|
|
//param.下阶段条件.ForEach(v =>
|
//{
|
// if (v.modelIndex > 0)
|
// {
|
// if (v.LogicValues != null && v.LogicValues.Length > 0)
|
// {
|
// err = SetItemPattern(v.modelObjectID, v.LogicValues, (HydraulicInputType)v.Type);
|
// if (err > 9) result = $"SetVarsToModel:{v.logicType}[{v.Name}]{ReportQuestion(err)}";
|
// }
|
// else //设置模式跟设置值,只设一个
|
// {
|
// dynamic temp = v.LogicValue;
|
// if (temp == null) temp = v.expressString;
|
// err = SetItemValue(v.modelIndex, temp, (HydraulicInputType)v.Type);
|
// if (err > 9) result = $"SetVarsToModel:{v.logicType}[{v.Name}]{ReportQuestion(err)}";
|
// }
|
// }
|
|
//});
|
#endregion
|
|
result = set下阶段条件();
|
if (result != null) return result;
|
return null;
|
}
|
|
|
|
#endregion
|
}
|
}
|