< Summary

Information
Class: Morpho25.Settings.MainSettings
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Settings\MainSettings.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 111
Coverable lines: 111
Total lines: 248
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

D:\a\Morpho\Morpho\project\Morpho\Morpho25\Settings\MainSettings.cs

#LineLine coverage
 1using Morpho25.Utility;
 2using System;
 3
 4
 5namespace 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>
 030        public string Name { get; }
 31        /// <summary>
 32        /// Model.
 33        /// </summary>
 034        public Model Inx { get; }
 35        /// <summary>
 36        /// It sets when your simulation starts. Format DD.MM.YYYY.
 37        /// </summary>
 38        public string StartDate
 39        {
 040            get { return _startDate; }
 41            set
 042            {
 043                DateValidation(value);
 044                _startDate = value;
 045            }
 46        }
 47        /// <summary>
 48        /// It sets at what time your simulation starts. Format HH:MM:SS.
 49        /// </summary>
 50        public string StartTime
 51        {
 052            get { return _startTime; }
 53            set
 054            {
 055                TimeValidation(value);
 056                _startTime = value;
 057            }
 58        }
 59        /// <summary>
 60        /// Initial wind speed (m/s).
 61        /// </summary>
 062        public double WindSpeed { get; set; }
 63        /// <summary>
 64        /// Initial wind direction (°dec).
 65        /// </summary>
 66        public double WindDir
 67        {
 68            get
 069            { return _windDir; }
 70            set
 071            {
 72
 073                if (value < 0 || value > 360)
 074                    throw new ArgumentException("Angle must be in range (0, 360).");
 075                _windDir = value;
 076            }
 77        }
 78        /// <summary>
 79        /// Roughness.
 80        /// </summary>
 081        public double Roughness { get; set; }
 82        /// <summary>
 83        /// Initial temperature of the air (°C).
 84        /// </summary>
 85        public double InitialTemperature
 86        {
 087            get { return _initialTemperature; }
 88            set
 089            {
 090                _initialTemperature = value + Util.TO_KELVIN;
 091            }
 92        }
 93        /// <summary>
 94        /// Duration of simulation in hours.
 95        /// </summary>
 96        public int SimDuration
 97        {
 098            get { return _simulationDuration; }
 99            set
 0100            {
 0101                if (value < 0)
 0102                    throw new ArgumentException("You cannot insert negative numbers");
 0103                _simulationDuration = value;
 0104            }
 105        }
 106        /// <summary>
 107        /// Initial specific humidity of the air in 2500 m.
 108        /// </summary>
 109        public double SpecificHumidity
 110        {
 111            get
 0112            { return _specificHumidity; }
 113            set
 0114            {
 0115                ItIsPositive(value);
 0116                _specificHumidity = value;
 0117            }
 118        }
 119        /// <summary>
 120        /// Initial relative humidity of the air in 2m (%).
 121        /// </summary>
 122        public double RelativeHumidity
 123        {
 124            get
 0125            { return _relativeHumidity; }
 126            set
 0127            {
 128
 0129                IsHumidityOk(value);
 0130                _relativeHumidity = value;
 0131            }
 132        }
 133
 134        /// <summary>
 135        /// Wind limit m/s
 136        /// </summary>
 137        public double WindLimit
 138        {
 139            get
 0140            { return _windLimit; }
 141            set
 0142            {
 0143                _windLimit = value;
 0144            }
 145        }
 146
 147        /// <summary>
 148        /// Wind accuracy
 149        /// </summary>
 0150        public WindAccuracy WindAccuracy { get; set; }
 151
 152        private void DateValidation(string value)
 0153        {
 0154            var pattern = @"^[0-9]{2}.[0-9]{2}.[0-9]{4}";
 0155            var regexp = new System.Text.RegularExpressions.Regex(pattern);
 0156            if (!regexp.IsMatch(value))
 0157                throw new ArgumentException("Format must to be DD.MM.YYYY");
 0158        }
 159
 160        private void TimeValidation(string value)
 0161        {
 0162            var pattern = @"^[0-9]{2}:[0-9]{2}:[0-9]{2}";
 0163            var regexp = new System.Text.RegularExpressions.Regex(pattern);
 0164            if (!regexp.IsMatch(value))
 0165                throw new ArgumentException("Format must to be HH:MM:SS");
 0166        }
 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>
 0173        public MainSettings(string name, Model inx)
 0174        {
 0175            Name = name;
 0176            Inx = inx;
 0177            StartDate = "23.06.2018";
 0178            StartTime = "06:00:00";
 0179            WindSpeed = 2.5;
 0180            WindDir = 0.0;
 0181            Roughness = 0.01000;
 0182            InitialTemperature = 19;
 0183            SimDuration = 24;
 0184            SpecificHumidity = 7.00;
 0185            RelativeHumidity = 50;
 0186            WindLimit = 5.0;
 0187            WindAccuracy = WindAccuracy.standard;
 0188        }
 189
 190        /// <summary>
 191        /// Title of the XML section
 192        /// </summary>
 0193        public string Title => "mainData";
 194
 195        /// <summary>
 196        /// Values of the XML section
 197        /// </summary>
 0198        public string[] Values => new[] {
 0199            Name,
 0200            Inx.Workspace.ModelName + ".inx",
 0201            Name,
 0202            " ",
 0203            StartDate,
 0204            StartTime,
 0205            SimDuration.ToString(),
 0206            WindSpeed.ToString("n5"),
 0207            WindDir.ToString("n5"),
 0208            Roughness.ToString("n5"),
 0209            InitialTemperature.ToString("n5"),
 0210            SpecificHumidity.ToString("n5"),
 0211            RelativeHumidity.ToString("n5"),
 0212            WindLimit.ToString("n5"),
 0213            WindAccuracy.ToString(),
 0214        };
 215
 216        /// <summary>
 217        /// Tags of the XML section
 218        /// </summary>
 0219        public string[] Tags => new[] {
 0220            "simName",
 0221            "INXFile",
 0222            "filebaseName",
 0223            "outDir",
 0224            "startDate",
 0225            "startTime",
 0226            "simDuration",
 0227            "windSpeed",
 0228            "windDir",
 0229            "z0",
 0230            "T_H",
 0231            "Q_H",
 0232            "Q_2m",
 0233            "windLimit",
 0234            "windAccuracy"
 0235        };
 236
 237        /// <summary>
 238        /// String representation of main settings.
 239        /// </summary>
 240        /// <returns>String representation.</returns>
 241        public override string ToString()
 0242        {
 0243            return $"Config::MainSettings::{StartDate}::{StartTime}";
 0244        }
 245
 246    }
 247
 248}