| | 1 | | using Morpho25.Utility; |
| | 2 | | using System; |
| | 3 | |
|
| | 4 | |
|
| | 5 | | namespace Morpho25.Settings |
| | 6 | | { |
| | 7 | | public enum WindAccuracy |
| | 8 | | { |
| | 9 | | standard, |
| | 10 | | quick |
| | 11 | | } |
| | 12 | |
|
| | 13 | | /// <summary> |
| | 14 | | /// Main settings class. |
| | 15 | | /// </summary> |
| | 16 | | public class MainSettings : Configuration |
| | 17 | | { |
| | 18 | | private int _simulationDuration; |
| | 19 | | private double _specificHumidity; |
| | 20 | | private double _relativeHumidity; |
| | 21 | | private double _initialTemperature; |
| | 22 | | private string _startDate; |
| | 23 | | private string _startTime; |
| | 24 | | private double _windDir; |
| | 25 | | private double _windLimit; |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Name of simulation file (*.simx). |
| | 29 | | /// </summary> |
| 0 | 30 | | public string Name { get; } |
| | 31 | | /// <summary> |
| | 32 | | /// Model. |
| | 33 | | /// </summary> |
| 0 | 34 | | public Model Inx { get; } |
| | 35 | | /// <summary> |
| | 36 | | /// It sets when your simulation starts. Format DD.MM.YYYY. |
| | 37 | | /// </summary> |
| | 38 | | public string StartDate |
| | 39 | | { |
| 0 | 40 | | get { return _startDate; } |
| | 41 | | set |
| 0 | 42 | | { |
| 0 | 43 | | DateValidation(value); |
| 0 | 44 | | _startDate = value; |
| 0 | 45 | | } |
| | 46 | | } |
| | 47 | | /// <summary> |
| | 48 | | /// It sets at what time your simulation starts. Format HH:MM:SS. |
| | 49 | | /// </summary> |
| | 50 | | public string StartTime |
| | 51 | | { |
| 0 | 52 | | get { return _startTime; } |
| | 53 | | set |
| 0 | 54 | | { |
| 0 | 55 | | TimeValidation(value); |
| 0 | 56 | | _startTime = value; |
| 0 | 57 | | } |
| | 58 | | } |
| | 59 | | /// <summary> |
| | 60 | | /// Initial wind speed (m/s). |
| | 61 | | /// </summary> |
| 0 | 62 | | public double WindSpeed { get; set; } |
| | 63 | | /// <summary> |
| | 64 | | /// Initial wind direction (°dec). |
| | 65 | | /// </summary> |
| | 66 | | public double WindDir |
| | 67 | | { |
| | 68 | | get |
| 0 | 69 | | { return _windDir; } |
| | 70 | | set |
| 0 | 71 | | { |
| | 72 | |
|
| 0 | 73 | | if (value < 0 || value > 360) |
| 0 | 74 | | throw new ArgumentException("Angle must be in range (0, 360)."); |
| 0 | 75 | | _windDir = value; |
| 0 | 76 | | } |
| | 77 | | } |
| | 78 | | /// <summary> |
| | 79 | | /// Roughness. |
| | 80 | | /// </summary> |
| 0 | 81 | | public double Roughness { get; set; } |
| | 82 | | /// <summary> |
| | 83 | | /// Initial temperature of the air (°C). |
| | 84 | | /// </summary> |
| | 85 | | public double InitialTemperature |
| | 86 | | { |
| 0 | 87 | | get { return _initialTemperature; } |
| | 88 | | set |
| 0 | 89 | | { |
| 0 | 90 | | _initialTemperature = value + Util.TO_KELVIN; |
| 0 | 91 | | } |
| | 92 | | } |
| | 93 | | /// <summary> |
| | 94 | | /// Duration of simulation in hours. |
| | 95 | | /// </summary> |
| | 96 | | public int SimDuration |
| | 97 | | { |
| 0 | 98 | | get { return _simulationDuration; } |
| | 99 | | set |
| 0 | 100 | | { |
| 0 | 101 | | if (value < 0) |
| 0 | 102 | | throw new ArgumentException("You cannot insert negative numbers"); |
| 0 | 103 | | _simulationDuration = value; |
| 0 | 104 | | } |
| | 105 | | } |
| | 106 | | /// <summary> |
| | 107 | | /// Initial specific humidity of the air in 2500 m. |
| | 108 | | /// </summary> |
| | 109 | | public double SpecificHumidity |
| | 110 | | { |
| | 111 | | get |
| 0 | 112 | | { return _specificHumidity; } |
| | 113 | | set |
| 0 | 114 | | { |
| 0 | 115 | | ItIsPositive(value); |
| 0 | 116 | | _specificHumidity = value; |
| 0 | 117 | | } |
| | 118 | | } |
| | 119 | | /// <summary> |
| | 120 | | /// Initial relative humidity of the air in 2m (%). |
| | 121 | | /// </summary> |
| | 122 | | public double RelativeHumidity |
| | 123 | | { |
| | 124 | | get |
| 0 | 125 | | { return _relativeHumidity; } |
| | 126 | | set |
| 0 | 127 | | { |
| | 128 | |
|
| 0 | 129 | | IsHumidityOk(value); |
| 0 | 130 | | _relativeHumidity = value; |
| 0 | 131 | | } |
| | 132 | | } |
| | 133 | |
|
| | 134 | | /// <summary> |
| | 135 | | /// Wind limit m/s |
| | 136 | | /// </summary> |
| | 137 | | public double WindLimit |
| | 138 | | { |
| | 139 | | get |
| 0 | 140 | | { return _windLimit; } |
| | 141 | | set |
| 0 | 142 | | { |
| 0 | 143 | | _windLimit = value; |
| 0 | 144 | | } |
| | 145 | | } |
| | 146 | |
|
| | 147 | | /// <summary> |
| | 148 | | /// Wind accuracy |
| | 149 | | /// </summary> |
| 0 | 150 | | public WindAccuracy WindAccuracy { get; set; } |
| | 151 | |
|
| | 152 | | private void DateValidation(string value) |
| 0 | 153 | | { |
| 0 | 154 | | var pattern = @"^[0-9]{2}.[0-9]{2}.[0-9]{4}"; |
| 0 | 155 | | var regexp = new System.Text.RegularExpressions.Regex(pattern); |
| 0 | 156 | | if (!regexp.IsMatch(value)) |
| 0 | 157 | | throw new ArgumentException("Format must to be DD.MM.YYYY"); |
| 0 | 158 | | } |
| | 159 | |
|
| | 160 | | private void TimeValidation(string value) |
| 0 | 161 | | { |
| 0 | 162 | | var pattern = @"^[0-9]{2}:[0-9]{2}:[0-9]{2}"; |
| 0 | 163 | | var regexp = new System.Text.RegularExpressions.Regex(pattern); |
| 0 | 164 | | if (!regexp.IsMatch(value)) |
| 0 | 165 | | throw new ArgumentException("Format must to be HH:MM:SS"); |
| 0 | 166 | | } |
| | 167 | |
|
| | 168 | | /// <summary> |
| | 169 | | /// Main configuration of the SIMX file. |
| | 170 | | /// </summary> |
| | 171 | | /// <param name="name">Name of the simulation file</param> |
| | 172 | | /// <param name="inx">Model</param> |
| 0 | 173 | | public MainSettings(string name, Model inx) |
| 0 | 174 | | { |
| 0 | 175 | | Name = name; |
| 0 | 176 | | Inx = inx; |
| 0 | 177 | | StartDate = "23.06.2018"; |
| 0 | 178 | | StartTime = "06:00:00"; |
| 0 | 179 | | WindSpeed = 2.5; |
| 0 | 180 | | WindDir = 0.0; |
| 0 | 181 | | Roughness = 0.01000; |
| 0 | 182 | | InitialTemperature = 19; |
| 0 | 183 | | SimDuration = 24; |
| 0 | 184 | | SpecificHumidity = 7.00; |
| 0 | 185 | | RelativeHumidity = 50; |
| 0 | 186 | | WindLimit = 5.0; |
| 0 | 187 | | WindAccuracy = WindAccuracy.standard; |
| 0 | 188 | | } |
| | 189 | |
|
| | 190 | | /// <summary> |
| | 191 | | /// Title of the XML section |
| | 192 | | /// </summary> |
| 0 | 193 | | public string Title => "mainData"; |
| | 194 | |
|
| | 195 | | /// <summary> |
| | 196 | | /// Values of the XML section |
| | 197 | | /// </summary> |
| 0 | 198 | | public string[] Values => new[] { |
| 0 | 199 | | Name, |
| 0 | 200 | | Inx.Workspace.ModelName + ".inx", |
| 0 | 201 | | Name, |
| 0 | 202 | | " ", |
| 0 | 203 | | StartDate, |
| 0 | 204 | | StartTime, |
| 0 | 205 | | SimDuration.ToString(), |
| 0 | 206 | | WindSpeed.ToString("n5"), |
| 0 | 207 | | WindDir.ToString("n5"), |
| 0 | 208 | | Roughness.ToString("n5"), |
| 0 | 209 | | InitialTemperature.ToString("n5"), |
| 0 | 210 | | SpecificHumidity.ToString("n5"), |
| 0 | 211 | | RelativeHumidity.ToString("n5"), |
| 0 | 212 | | WindLimit.ToString("n5"), |
| 0 | 213 | | WindAccuracy.ToString(), |
| 0 | 214 | | }; |
| | 215 | |
|
| | 216 | | /// <summary> |
| | 217 | | /// Tags of the XML section |
| | 218 | | /// </summary> |
| 0 | 219 | | public string[] Tags => new[] { |
| 0 | 220 | | "simName", |
| 0 | 221 | | "INXFile", |
| 0 | 222 | | "filebaseName", |
| 0 | 223 | | "outDir", |
| 0 | 224 | | "startDate", |
| 0 | 225 | | "startTime", |
| 0 | 226 | | "simDuration", |
| 0 | 227 | | "windSpeed", |
| 0 | 228 | | "windDir", |
| 0 | 229 | | "z0", |
| 0 | 230 | | "T_H", |
| 0 | 231 | | "Q_H", |
| 0 | 232 | | "Q_2m", |
| 0 | 233 | | "windLimit", |
| 0 | 234 | | "windAccuracy" |
| 0 | 235 | | }; |
| | 236 | |
|
| | 237 | | /// <summary> |
| | 238 | | /// String representation of main settings. |
| | 239 | | /// </summary> |
| | 240 | | /// <returns>String representation.</returns> |
| | 241 | | public override string ToString() |
| 0 | 242 | | { |
| 0 | 243 | | return $"Config::MainSettings::{StartDate}::{StartTime}"; |
| 0 | 244 | | } |
| | 245 | |
|
| | 246 | | } |
| | 247 | |
|
| | 248 | | } |