lixiaojun
2025-03-17 85fc43aa549bbe24c4d867a055c0d90d21deba8b
Yw.Epanet.Calcu.Core/04-Inp/InpGenerater.cs
ÎļþÃû´Ó Yw.Epanet.Calcu.Core/04-Inp/InpGenerateHelper.cs ÐÞ¸Ä
@@ -1,19 +1,10 @@
namespace Yw.Epanet
{
    /// <summary>
    /// Inp生成辅助类
    /// Inp生成器
    /// </summary>
    public static class InpGenerateHelper
    public static class InpGenerater
    {
        private const char _section_head = '[';// èЂ头
        private const char _section_tail = ']';//节尾
        //获取节点名称
        private static string GetSectionName(string sectionName)
        {
            var name = $"{_section_head}{sectionName?.ToUpper()}{_section_tail}";
            return name;
        }
        /// <summary>
        /// è½¬æ¢è‡³Inp字符串
@@ -28,7 +19,7 @@
            #region Title
            var titleSectionName = GetSectionName(InpSection.Title);
            var titleSectionName = InpSection.Title;
            sb.AppendLine(titleSectionName);
            sb.AppendLine(nw.Title);
            sb.AppendLine(string.Empty);
@@ -37,7 +28,7 @@
            #region Junctions
            var junctionsSectionName = GetSectionName(InpSection.Junctions);
            var junctionsSectionName = InpSection.Junctions;
            sb.AppendLine(junctionsSectionName);
            sb.AppendLine(";ID \tElev \tDemand \tDemandPattern");
            var allJunctionList = nw.GetAllJunctions();
@@ -55,7 +46,7 @@
            #region Reservoirs 
            var reservoirsSectionName = GetSectionName(InpSection.Reservoirs);
            var reservoirsSectionName = InpSection.Reservoirs;
            sb.AppendLine(reservoirsSectionName);
            sb.AppendLine(";ID \tHead \tHeadPattern");
            nw.Reservoirs?.ForEach(x =>
@@ -71,7 +62,7 @@
            #region Tanks
            var tanksSectionName = GetSectionName(InpSection.Tanks);
            var tanksSectionName = InpSection.Tanks;
            sb.AppendLine(tanksSectionName);
            sb.AppendLine(";ID \tPoolElev \tInitLevel \tMinLevel \tMaxLevel \tMinVol \tVolCurve");
            nw.Tanks?.ForEach(x =>
@@ -92,7 +83,7 @@
            #region Pipes
            var pipesSectionName = GetSectionName(InpSection.Pipes);
            var pipesSectionName = InpSection.Pipes;
            sb.AppendLine(pipesSectionName);
            sb.AppendLine(";ID \tStartNodeId \tEndNodeId \tLength \tDiameter \tRoughness \tMinorLoss \tLinkStatus");
            nw.Pipes?.ForEach(x =>
@@ -113,7 +104,7 @@
            #region Pumps
            var pumpsSectionName = GetSectionName(InpSection.Pumps);
            var pumpsSectionName = InpSection.Pumps;
            sb.AppendLine(pumpsSectionName);
            sb.AppendLine(";ID \tStartNodeId \tEndNodeId \tProperty");
            nw.Pumps?.ForEach(x =>
@@ -138,7 +129,7 @@
            #region Valves
            var valvesSectionName = GetSectionName(InpSection.Valves);
            var valvesSectionName = InpSection.Valves;
            sb.AppendLine(valvesSectionName);
            sb.AppendLine(";ID \tStartNodeId \tEndNodeId \tDiameter \tValveType \tValveSetting \tMinorLoss");
            nw.Valves?.ForEach(x =>
@@ -158,7 +149,7 @@
            #region Emitters
            var emittersSectionName = GetSectionName(InpSection.Emitters);
            var emittersSectionName = InpSection.Emitters;
            sb.AppendLine(emittersSectionName);
            sb.AppendLine(";ID \tCoefficient");
            var allEmitterList = nw.Emitters;
@@ -174,7 +165,7 @@
            #region Curves
            var curvesSectionName = GetSectionName(InpSection.Curves);
            var curvesSectionName = InpSection.Curves;
            sb.AppendLine(curvesSectionName);
            sb.AppendLine(";ID \tX-Value \tY-Value");
            nw.Curves?.ForEach(x =>
@@ -196,7 +187,7 @@
            #region Patterns
            var patternsSectionName = GetSectionName(InpSection.Patterns);
            var patternsSectionName = InpSection.Patterns;
            sb.AppendLine(patternsSectionName);
            sb.AppendLine(";ID \tMultipliers");
            nw.Patterns?.ForEach(x =>
@@ -221,7 +212,7 @@
            #region Energy
            var energySectionName = GetSectionName(InpSection.Energy);
            var energySectionName = InpSection.Energy;
            sb.AppendLine(energySectionName);
            sb.AppendLine("Global Efficiency \t75 \t;");
            sb.AppendLine("Global Price \t0 \t;");
@@ -232,7 +223,7 @@
            #region Status
            var statusSectionName = GetSectionName(InpSection.Status);
            var statusSectionName = InpSection.Status;
            sb.AppendLine(statusSectionName);
            sb.AppendLine(";ID \tStatus/Setting");
            nw.Pipes?.ForEach(x =>
@@ -283,7 +274,7 @@
            #region Demands
            var demandsSectionName = GetSectionName(InpSection.Demands);
            var demandsSectionName = InpSection.Demands;
            sb.AppendLine(demandsSectionName);
            sb.AppendLine(";Junction \tDemand \tPattern \tCategory");
            sb.AppendLine(string.Empty);
@@ -292,7 +283,7 @@
            #region Controls
            var controlsSectionName = GetSectionName(InpSection.Controls);
            var controlsSectionName = InpSection.Controls;
            sb.AppendLine(controlsSectionName);
            sb.AppendLine(string.Empty);
@@ -300,7 +291,7 @@
            #region Rules
            var rulesSectionName = GetSectionName(InpSection.Rules);
            var rulesSectionName = InpSection.Rules;
            sb.AppendLine(rulesSectionName);
            sb.AppendLine(string.Empty);
@@ -308,7 +299,7 @@
            #region Quality
            var qualitySectionName = GetSectionName(InpSection.Quality);
            var qualitySectionName = InpSection.Quality;
            sb.AppendLine(qualitySectionName);
            sb.AppendLine(";Node \tInitQual");
            sb.AppendLine(string.Empty);
@@ -317,7 +308,7 @@
            #region Reactions
            var reactionsSectionName = GetSectionName(InpSection.Reactions);
            var reactionsSectionName = InpSection.Reactions;
            sb.AppendLine(reactionsSectionName);
            sb.AppendLine(";Type \tPipe/Tank \tCoefficient");
            sb.AppendLine(string.Empty);
@@ -335,7 +326,7 @@
            #region Sources
            var sourcesSectionName = GetSectionName(InpSection.Sources);
            var sourcesSectionName = InpSection.Sources;
            sb.AppendLine(sourcesSectionName);
            sb.AppendLine(";Node \tType \tQuality \tPattern");
            sb.AppendLine(string.Empty);
@@ -344,7 +335,7 @@
            #region Mixing
            var mixingSectionName = GetSectionName(InpSection.Mixing);
            var mixingSectionName = InpSection.Mixing;
            sb.AppendLine(mixingSectionName);
            sb.AppendLine(";Tank \tModel");
            sb.AppendLine(string.Empty);
@@ -353,7 +344,7 @@
            #region Options
            var optionsSectionName = GetSectionName(InpSection.Options);
            var optionsSectionName = InpSection.Options;
            sb.AppendLine(optionsSectionName);
            sb.AppendLine("Units \tCMH");
            sb.AppendLine("Headloss \tH-W");
@@ -379,7 +370,7 @@
            #region Times
            var timesSectionName = GetSectionName(InpSection.Times);
            var timesSectionName = InpSection.Times;
            sb.AppendLine(timesSectionName);
            sb.AppendLine("Duration \t0:00");
            sb.AppendLine("Hydraulic Timestep \t1:00");
@@ -396,7 +387,7 @@
            #region Report
            var reportSectionName = GetSectionName(InpSection.Report);
            var reportSectionName = InpSection.Report;
            sb.AppendLine(reportSectionName);
            sb.AppendLine("Status \tYes");
            sb.AppendLine("Summary \tNo");
@@ -407,7 +398,7 @@
            #region Tags
            var tagsSectionName = GetSectionName(InpSection.Tags);
            var tagsSectionName = InpSection.Tags;
            sb.AppendLine(tagsSectionName);
            sb.AppendLine(string.Empty);
@@ -415,7 +406,7 @@
            #region Coordinates
            var coordinatesSectionName = GetSectionName(InpSection.Coordinates);
            var coordinatesSectionName = InpSection.Coordinates;
            sb.AppendLine(coordinatesSectionName);
            sb.AppendLine(";ID \tX-Coord \tY-Coord");
            var allNodeList = nw.GetAllNodes();
@@ -432,7 +423,7 @@
            #region Vertices
            var verticesSectionName = GetSectionName(InpSection.Vertices);
            var verticesSectionName = InpSection.Vertices;
            sb.AppendLine(verticesSectionName);
            sb.AppendLine(";Link \tX-Coord \tY-Coord");
            sb.AppendLine(string.Empty);
@@ -441,7 +432,7 @@
            #region Labels
            var labelsSectionName = GetSectionName(InpSection.Labels);
            var labelsSectionName = InpSection.Labels;
            sb.AppendLine(labelsSectionName);
            sb.AppendLine(";X-Coord \tY-Coord \tLabel & Anchor Node");
            sb.AppendLine(string.Empty);
@@ -450,7 +441,7 @@
            #region Backdrop
            var backdropSectionName = GetSectionName(InpSection.Backdrop);
            var backdropSectionName = InpSection.Backdrop;
            sb.AppendLine(backdropSectionName);
            sb.AppendLine("DIMENSIONS \t0.000             \t0.000             \t10000.000         \t10000.000");
            sb.AppendLine("UNITS \tNone");
@@ -462,7 +453,7 @@
            #region End
            var endSectionName = GetSectionName(InpSection.End);
            var endSectionName = InpSection.End;
            sb.AppendLine(endSectionName);
            #endregion