|   |  | 1 |  | using Morpho25.Settings; | 
|   |  | 2 |  | using Morpho25.Utility; | 
|   |  | 3 |  | using System; | 
|   |  | 4 |  | using System.IO; | 
|   |  | 5 |  | using System.Text; | 
|   |  | 6 |  | using System.Xml; | 
|   |  | 7 |  |  | 
|   |  | 8 |  |  | 
|   |  | 9 |  | namespace Morpho25.IO | 
|   |  | 10 |  | { | 
|   |  | 11 |  |     /// <summary> | 
|   |  | 12 |  |     /// Simulation definition class. | 
|   |  | 13 |  |     /// </summary> | 
|   |  | 14 |  |     public class Simx | 
|   |  | 15 |  |     { | 
|   |  | 16 |  |         /// <summary> | 
|   |  | 17 |  |         /// New line. | 
|   |  | 18 |  |         /// </summary> | 
|   |  | 19 |  |         public const string NEWLINE = "\n"; | 
|   |  | 20 |  |         /// <summary> | 
|   |  | 21 |  |         /// Main settings. | 
|   |  | 22 |  |         /// </summary> | 
|   | 0 | 23 |  |         public MainSettings MainSettings { get; } | 
|   |  | 24 |  |         /// <summary> | 
|   |  | 25 |  |         /// Simple forcing settings. | 
|   |  | 26 |  |         /// </summary> | 
|   | 0 | 27 |  |         public SimpleForcing SimpleForcing { get; set; } | 
|   |  | 28 |  |         /// <summary> | 
|   |  | 29 |  |         /// Thread settings. | 
|   |  | 30 |  |         /// </summary> | 
|   | 0 | 31 |  |         public TThread TThread { get; set; } | 
|   |  | 32 |  |         /// <summary> | 
|   |  | 33 |  |         /// Time step definition. | 
|   |  | 34 |  |         /// </summary> | 
|   | 0 | 35 |  |         public TimeSteps TimeSteps { get; set; } | 
|   |  | 36 |  |         /// <summary> | 
|   |  | 37 |  |         /// Timing settings. | 
|   |  | 38 |  |         /// </summary> | 
|   | 0 | 39 |  |         public ModelTiming ModelTiming { get; set; } | 
|   |  | 40 |  |         /// <summary> | 
|   |  | 41 |  |         /// Soil settings. | 
|   |  | 42 |  |         /// </summary> | 
|   | 0 | 43 |  |         public SoilSettings SoilSettings { get; set; } | 
|   |  | 44 |  |         /// <summary> | 
|   |  | 45 |  |         /// Source settings. | 
|   |  | 46 |  |         /// </summary> | 
|   | 0 | 47 |  |         public Sources Sources { get; set; } | 
|   |  | 48 |  |         /// <summary> | 
|   |  | 49 |  |         /// Turbolence settings. | 
|   |  | 50 |  |         /// </summary> | 
|   | 0 | 51 |  |         public Turbulence Turbulence { get; set; } | 
|   |  | 52 |  |         /// <summary> | 
|   |  | 53 |  |         /// Output settings. | 
|   |  | 54 |  |         /// </summary> | 
|   | 0 | 55 |  |         public OutputSettings OutputSettings { get; set; } | 
|   |  | 56 |  |         /// <summary> | 
|   |  | 57 |  |         /// Cloudiness settings. | 
|   |  | 58 |  |         /// </summary> | 
|   | 0 | 59 |  |         public Cloud Cloud { get; set; } | 
|   |  | 60 |  |         /// <summary> | 
|   |  | 61 |  |         /// Background settings. | 
|   |  | 62 |  |         /// </summary> | 
|   | 0 | 63 |  |         public Background Background { get; set; } | 
|   |  | 64 |  |         /// <summary> | 
|   |  | 65 |  |         /// Sun settings. | 
|   |  | 66 |  |         /// </summary> | 
|   | 0 | 67 |  |         public SolarAdjust SolarAdjust { get; set; } | 
|   |  | 68 |  |         /// <summary> | 
|   |  | 69 |  |         /// Building settings. | 
|   |  | 70 |  |         /// </summary> | 
|   | 0 | 71 |  |         public BuildingSettings BuildingSettings { get; set; } | 
|   |  | 72 |  |         /// <summary> | 
|   |  | 73 |  |         /// Radiation settings. | 
|   |  | 74 |  |         /// </summary> | 
|   | 0 | 75 |  |         public RadScheme RadScheme { get; set; } | 
|   |  | 76 |  |         /// <summary> | 
|   |  | 77 |  |         /// Parallel CPU settings. | 
|   |  | 78 |  |         /// </summary> | 
|   | 0 | 79 |  |         public ParallelCPU ParallelCPU { get; set; } | 
|   |  | 80 |  |         /// <summary> | 
|   |  | 81 |  |         /// SOR settings. | 
|   |  | 82 |  |         /// </summary> | 
|   | 0 | 83 |  |         public SOR SOR { get; set; } | 
|   |  | 84 |  |         /// <summary> | 
|   |  | 85 |  |         /// Flow settings. | 
|   |  | 86 |  |         /// </summary> | 
|   | 0 | 87 |  |         public InflowAvg InflowAvg { get; set; } | 
|   |  | 88 |  |         /// <summary> | 
|   |  | 89 |  |         /// Facades. | 
|   |  | 90 |  |         /// </summary> | 
|   | 0 | 91 |  |         public Facades Facades { get; set; } | 
|   |  | 92 |  |         /// <summary> | 
|   |  | 93 |  |         /// Plant settings. | 
|   |  | 94 |  |         /// </summary> | 
|   | 0 | 95 |  |         public PlantSetting PlantSetting { get; set; } | 
|   |  | 96 |  |         /// <summary> | 
|   |  | 97 |  |         /// Lateral boundary condition. | 
|   |  | 98 |  |         /// </summary> | 
|   | 0 | 99 |  |         public LBC LBC { get; set; } | 
|   |  | 100 |  |         /// <summary> | 
|   |  | 101 |  |         /// Full forcing settings. | 
|   |  | 102 |  |         /// </summary> | 
|   | 0 | 103 |  |         public FullForcing FullForcing { get; set; } | 
|   |  | 104 |  |         /// <summary> | 
|   |  | 105 |  |         /// Create a simulation definition. | 
|   |  | 106 |  |         /// </summary> | 
|   |  | 107 |  |         /// <param name="mainSettings">Main settings.</param> | 
|   | 0 | 108 |  |         public Simx(MainSettings mainSettings) | 
|   | 0 | 109 |  |         { | 
|   | 0 | 110 |  |             MainSettings = mainSettings; | 
|   | 0 | 111 |  |             SimpleForcing = null; | 
|   | 0 | 112 |  |             TThread = null; | 
|   | 0 | 113 |  |             TimeSteps = null; | 
|   | 0 | 114 |  |             ModelTiming = null; | 
|   | 0 | 115 |  |             SoilSettings = null; | 
|   | 0 | 116 |  |             Sources = null; | 
|   | 0 | 117 |  |             Turbulence = null; | 
|   | 0 | 118 |  |             OutputSettings = null; | 
|   | 0 | 119 |  |             Cloud = null; | 
|   | 0 | 120 |  |             Background = null; | 
|   | 0 | 121 |  |             SolarAdjust = null; | 
|   | 0 | 122 |  |             BuildingSettings = null; | 
|   | 0 | 123 |  |             RadScheme = null; | 
|   | 0 | 124 |  |             SOR = null; | 
|   | 0 | 125 |  |             InflowAvg = null; | 
|   | 0 | 126 |  |             Facades = null; | 
|   | 0 | 127 |  |             PlantSetting = null; | 
|   | 0 | 128 |  |             LBC = null; | 
|   | 0 | 129 |  |             FullForcing = null; | 
|   | 0 | 130 |  |         } | 
|   |  | 131 |  |         /// <summary> | 
|   |  | 132 |  |         /// Write simulation file. | 
|   |  | 133 |  |         /// </summary> | 
|   |  | 134 |  |         public void WriteSimx() | 
|   | 0 | 135 |  |         { | 
|   | 0 | 136 |  |             var now = DateTime.Now; | 
|   | 0 | 137 |  |             string revisionDate = now.ToString("yyyy-MM-dd HH:mm:ss"); | 
|   | 0 | 138 |  |             string filePath = Path.Combine(MainSettings | 
|   | 0 | 139 |  |                 .Inx.Workspace.ProjectFolder, MainSettings.Name + ".simx"); | 
|   | 0 | 140 |  |             string[] empty = { }; | 
|   |  | 141 |  |  | 
|   | 0 | 142 |  |             XmlTextWriter xWriter = new XmlTextWriter(filePath, Encoding.UTF8); | 
|   | 0 | 143 |  |             xWriter.WriteStartElement("ENVI-MET_Datafile"); | 
|   | 0 | 144 |  |             xWriter.WriteString(NEWLINE); | 
|   |  | 145 |  |  | 
|   |  | 146 |  |             // Header section | 
|   | 0 | 147 |  |             string headerTitle = "Header"; | 
|   | 0 | 148 |  |             string[] headerTag = new string[] { "filetype", "version", | 
|   | 0 | 149 |  |                 "revisiondate", "remark", "encryptionlevel" }; | 
|   | 0 | 150 |  |             string[] headerValue = new string[] { "SIMX", "2", | 
|   | 0 | 151 |  |                 revisionDate, "Created with lb_envimet", "0" }; | 
|   |  | 152 |  |  | 
|   | 0 | 153 |  |             Util.CreateXmlSection(xWriter, headerTitle, | 
|   | 0 | 154 |  |                 headerTag, headerValue, 0, empty); | 
|   |  | 155 |  |  | 
|   |  | 156 |  |             // Main section | 
|   | 0 | 157 |  |             Util.CreateXmlSection(xWriter, MainSettings.Title, | 
|   | 0 | 158 |  |                 MainSettings.Tags, MainSettings.Values, 0, empty); | 
|   |  | 159 |  |  | 
|   |  | 160 |  |             // First Meteorology | 
|   | 0 | 161 |  |             if (SimpleForcing != null && FullForcing == null) | 
|   | 0 | 162 |  |             { | 
|   | 0 | 163 |  |                 Util.CreateXmlSection(xWriter, SimpleForcing.Title, | 
|   | 0 | 164 |  |                     SimpleForcing.Tags, SimpleForcing.Values, 0, empty); | 
|   | 0 | 165 |  |             } | 
|   |  | 166 |  |  | 
|   | 0 | 167 |  |             if (TThread != null) | 
|   | 0 | 168 |  |             { | 
|   | 0 | 169 |  |                 Util.CreateXmlSection(xWriter, TThread.Title, | 
|   | 0 | 170 |  |                     TThread.Tags, TThread.Values, 0, empty); | 
|   | 0 | 171 |  |             } | 
|   |  | 172 |  |  | 
|   | 0 | 173 |  |             if (ModelTiming != null) | 
|   | 0 | 174 |  |             { | 
|   | 0 | 175 |  |                 Util.CreateXmlSection(xWriter, ModelTiming.Title, | 
|   | 0 | 176 |  |                     ModelTiming.Tags, ModelTiming.Values, 0, empty); | 
|   | 0 | 177 |  |             } | 
|   |  | 178 |  |  | 
|   | 0 | 179 |  |             if (SoilSettings != null) | 
|   | 0 | 180 |  |             { | 
|   | 0 | 181 |  |                 Util.CreateXmlSection(xWriter, SoilSettings.Title, | 
|   | 0 | 182 |  |                     SoilSettings.Tags, SoilSettings.Values, 0, empty); | 
|   | 0 | 183 |  |             } | 
|   |  | 184 |  |  | 
|   | 0 | 185 |  |             if (Sources != null) | 
|   | 0 | 186 |  |             { | 
|   | 0 | 187 |  |                 Util.CreateXmlSection(xWriter, Sources.Title, | 
|   | 0 | 188 |  |                     Sources.Tags, Sources.Values, 0, empty); | 
|   | 0 | 189 |  |             } | 
|   |  | 190 |  |  | 
|   | 0 | 191 |  |             if (Turbulence != null) | 
|   | 0 | 192 |  |             { | 
|   | 0 | 193 |  |                 Util.CreateXmlSection(xWriter, Turbulence.Title, | 
|   | 0 | 194 |  |                     Turbulence.Tags, Turbulence.Values, 0, empty); | 
|   | 0 | 195 |  |             } | 
|   |  | 196 |  |  | 
|   | 0 | 197 |  |             if (TimeSteps != null) | 
|   | 0 | 198 |  |             { | 
|   | 0 | 199 |  |                 Util.CreateXmlSection(xWriter, TimeSteps.Title, | 
|   | 0 | 200 |  |                     TimeSteps.Tags, TimeSteps.Values, 0, empty); | 
|   | 0 | 201 |  |             } | 
|   |  | 202 |  |  | 
|   | 0 | 203 |  |             if (OutputSettings != null) | 
|   | 0 | 204 |  |             { | 
|   | 0 | 205 |  |                 Util.CreateXmlSection(xWriter, OutputSettings.Title, | 
|   | 0 | 206 |  |                     OutputSettings.Tags, OutputSettings.Values, 0, empty); | 
|   | 0 | 207 |  |             } | 
|   |  | 208 |  |  | 
|   | 0 | 209 |  |             if (Cloud != null && FullForcing == null) | 
|   | 0 | 210 |  |             { | 
|   | 0 | 211 |  |                 Util.CreateXmlSection(xWriter, Cloud.Title, | 
|   | 0 | 212 |  |                     Cloud.Tags, Cloud.Values, 0, empty); | 
|   | 0 | 213 |  |             } | 
|   |  | 214 |  |  | 
|   | 0 | 215 |  |             if (Background != null) | 
|   | 0 | 216 |  |             { | 
|   | 0 | 217 |  |                 Util.CreateXmlSection(xWriter, Background.Title, | 
|   | 0 | 218 |  |                     Background.Tags, Background.Values, 0, empty); | 
|   | 0 | 219 |  |             } | 
|   |  | 220 |  |  | 
|   | 0 | 221 |  |             if (SolarAdjust != null && FullForcing == null) | 
|   | 0 | 222 |  |             { | 
|   | 0 | 223 |  |                 Util.CreateXmlSection(xWriter, SolarAdjust.Title, | 
|   | 0 | 224 |  |                     SolarAdjust.Tags, SolarAdjust.Values, 0, empty); | 
|   | 0 | 225 |  |             } | 
|   |  | 226 |  |  | 
|   | 0 | 227 |  |             if (BuildingSettings != null) | 
|   | 0 | 228 |  |             { | 
|   | 0 | 229 |  |                 Util.CreateXmlSection(xWriter, BuildingSettings.Title, | 
|   | 0 | 230 |  |                     BuildingSettings.Tags, BuildingSettings.Values, 0, empty); | 
|   | 0 | 231 |  |             } | 
|   |  | 232 |  |  | 
|   | 0 | 233 |  |             if (RadScheme != null) | 
|   | 0 | 234 |  |             { | 
|   | 0 | 235 |  |                 Util.CreateXmlSection(xWriter, RadScheme.Title, | 
|   | 0 | 236 |  |                     RadScheme.Tags, RadScheme.Values, 0, empty); | 
|   | 0 | 237 |  |             } | 
|   |  | 238 |  |  | 
|   | 0 | 239 |  |             if (ParallelCPU != null) | 
|   | 0 | 240 |  |             { | 
|   | 0 | 241 |  |                 Util.CreateXmlSection(xWriter, ParallelCPU.Title, | 
|   | 0 | 242 |  |                     ParallelCPU.Tags, ParallelCPU.Values, 0, empty); | 
|   | 0 | 243 |  |             } | 
|   |  | 244 |  |  | 
|   | 0 | 245 |  |             if (SOR != null) | 
|   | 0 | 246 |  |             { | 
|   | 0 | 247 |  |                 Util.CreateXmlSection(xWriter, SOR.Title, | 
|   | 0 | 248 |  |                     SOR.Tags, SOR.Values, 0, empty); | 
|   | 0 | 249 |  |             } | 
|   |  | 250 |  |  | 
|   | 0 | 251 |  |             if (InflowAvg != null) | 
|   | 0 | 252 |  |             { | 
|   | 0 | 253 |  |                 Util.CreateXmlSection(xWriter, InflowAvg.Title, | 
|   | 0 | 254 |  |                     InflowAvg.Tags, InflowAvg.Values, 0, empty); | 
|   | 0 | 255 |  |             } | 
|   |  | 256 |  |  | 
|   | 0 | 257 |  |             if (PlantSetting != null) | 
|   | 0 | 258 |  |             { | 
|   | 0 | 259 |  |                 Util.CreateXmlSection(xWriter, PlantSetting.Title, | 
|   | 0 | 260 |  |                     PlantSetting.Tags, PlantSetting.Values, 0, empty); | 
|   | 0 | 261 |  |             } | 
|   |  | 262 |  |  | 
|   | 0 | 263 |  |             if (Facades != null) | 
|   | 0 | 264 |  |             { | 
|   | 0 | 265 |  |                 Util.CreateXmlSection(xWriter, Facades.Title, | 
|   | 0 | 266 |  |                     Facades.Tags, Facades.Values, 0, empty); | 
|   | 0 | 267 |  |             } | 
|   |  | 268 |  |  | 
|   |  | 269 |  |             // Third Meteorology | 
|   | 0 | 270 |  |             if (LBC != null && (SimpleForcing == null || FullForcing == null)) | 
|   | 0 | 271 |  |             { | 
|   | 0 | 272 |  |                 Util.CreateXmlSection(xWriter, LBC.Title, | 
|   | 0 | 273 |  |                     LBC.Tags, LBC.Values, 0, empty); | 
|   | 0 | 274 |  |             } | 
|   |  | 275 |  |  | 
|   |  | 276 |  |             // Second Meteorology | 
|   | 0 | 277 |  |             if (FullForcing != null) | 
|   | 0 | 278 |  |             { | 
|   | 0 | 279 |  |                 Util.CreateXmlSection(xWriter, FullForcing.Title, | 
|   | 0 | 280 |  |                     FullForcing.Tags, FullForcing.Values, 0, empty); | 
|   | 0 | 281 |  |             } | 
|   |  | 282 |  |  | 
|   | 0 | 283 |  |             xWriter.WriteEndElement(); | 
|   | 0 | 284 |  |             xWriter.Close(); | 
|   | 0 | 285 |  |         } | 
|   |  | 286 |  |     } | 
|   |  | 287 |  | } |