Exemple #1
0
 public UnitSystem()
 {
     this.temperature        = TemperatureUnit.Celsius;
     this.pressure           = PressureUnit.Pascal;
     this.massFlowRate       = MassFlowRateUnit.KgPerSec;
     this.volumeFlowRate     = VolumeFlowRateUnit.CubicMeterPerSec;
     this.moistureContent    = MoistureContentUnit.KgPerKg;
     this.relativeHumidity   = RatioUnit.Percent;
     this.enthalpy           = SpecificEnergyUnit.JoulePerKg;
     this.specificHeat       = SpecificHeatUnit.JoulePerKgKelvin;
     this.energy             = EnergyUnit.Joule;
     this.power              = PowerUnit.JoulePerSec;
     this.density            = DensityUnit.KgPerCubicMeter;
     this.dynamicViscosity   = DynamicViscosityUnit.PascalSecond;
     this.kinematicViscosity = KinematicViscosityUnit.SquareMeterPerSec;
     this.conductivity       = ThermalConductivityUnit.WattPerMeterKelvin;
     this.diffusivity        = DiffusivityUnit.SquareMeterPerSec;
     this.mass     = MassUnit.Kilogram;
     this.length   = LengthUnit.Meter;
     this.area     = AreaUnit.SquareMeter;
     this.volume   = VolumeUnit.CubicMeter;
     this.time     = TimeUnit.Second;
     this.Name     = "SI"; //ep
     this.readOnly = true;
 }
Exemple #2
0
        //HeatFluxDensityUnit heatTransferCoefficient;
        //ForceUnit force;
        //SurfaceTensionUnit surfaceTension;

        public UnitSystem(TemperatureUnit temperature, PressureUnit pressure, MassFlowRateUnit massFlowRate,
                          VolumeFlowRateUnit volumeFlowRate, MoistureContentUnit moistureContent,
                          RatioUnit relativeHumidity, SpecificEnergyUnit enthalpy,
                          SpecificHeatUnit specificHeat, EnergyUnit energy, PowerUnit power, DensityUnit density,
                          DynamicViscosityUnit dynamicViscosity, KinematicViscosityUnit kinematicViscosity,
                          ThermalConductivityUnit conductivity, DiffusivityUnit diffusivity, MassUnit mass,
                          LengthUnit length, AreaUnit area, VolumeUnit volume, TimeUnit Time, string name) //ep
        {
            this.temperature        = temperature;
            this.pressure           = pressure;
            this.massFlowRate       = massFlowRate;
            this.volumeFlowRate     = volumeFlowRate;
            this.moistureContent    = moistureContent;
            this.relativeHumidity   = relativeHumidity;
            this.enthalpy           = enthalpy;
            this.specificHeat       = specificHeat;
            this.energy             = energy;
            this.power              = power;
            this.density            = density;
            this.dynamicViscosity   = dynamicViscosity;
            this.kinematicViscosity = kinematicViscosity;
            this.conductivity       = conductivity;
            this.diffusivity        = diffusivity;
            this.mass     = mass;
            this.length   = length;
            this.area     = area;
            this.volume   = volume;
            this.time     = time;
            this.Name     = name;  //ep
            this.readOnly = false; //ep
        }
Exemple #3
0
        /// <summary>
        ///     Creates the quantity with the given numeric value and unit.
        /// </summary>
        /// <param name="value">The numeric value to construct this quantity with.</param>
        /// <param name="unit">The unit representation to construct this quantity with.</param>
        /// <remarks>Value parameter cannot be named 'value' due to constraint when targeting Windows Runtime Component.</remarks>
        /// <exception cref="ArgumentException">If value is NaN or Infinity.</exception>
        private Diffusivity(double value, DiffusivityUnit unit)
        {
            if (unit == DiffusivityUnit.Undefined)
            {
                throw new ArgumentException("The quantity can not be created with an undefined unit.", nameof(unit));
            }

            _value = Guard.EnsureValidNumber(value, nameof(value));
            _unit  = unit;
        }
Exemple #4
0
        /// <summary>
        ///     Convert to the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>Value converted to the specified unit.</returns>
        public double As(DiffusivityUnit unit)
        {
            if (Unit == unit)
            {
                return(Convert.ToDouble(Value));
            }

            var converted = AsBaseNumericType(unit);

            return(Convert.ToDouble(converted));
        }
Exemple #5
0
        private double AsBaseNumericType(DiffusivityUnit unit)
        {
            if (Unit == unit)
            {
                return(_value);
            }

            var baseUnitValue = AsBaseUnit();

            switch (unit)
            {
            case DiffusivityUnit.SquareMeterPerHour: return(baseUnitValue);

            default:
                throw new NotImplementedException($"Can not convert {Unit} to {unit}.");
            }
        }
Exemple #6
0
        public void UpdateUnitSystem(UnitSystem unitSystem)
        {
            this.unitSystem = unitSystem;
            this.TextBox.Clear();
            if (unitSystem != null)
            {
                this.textBoxUnitSystem.ScrollBars = System.Windows.Forms.ScrollBars.None;

                string temperature        = "Temperature: \t\t" + TemperatureUnit.GetUnitAsString(unitSystem.TemperatureUnitType);
                string pressure           = "Pressure: \t\t\t" + PressureUnit.GetUnitAsString(unitSystem.PressureUnitType);
                string massFlowRate       = "Mass Flow Rate: \t\t" + MassFlowRateUnit.GetUnitAsString(unitSystem.MassFlowRateUnitType);
                string volumeFlowRate     = "Volume Flow Rate: \t\t" + VolumeFlowRateUnit.GetUnitAsString(unitSystem.VolumeFlowRateUnitType);
                string moistureContent    = "Moisture Content: \t\t" + MoistureContentUnit.GetUnitAsString(unitSystem.MoistureContentUnitType);
                string relativeHumidity   = "Fraction: \t\t\t" + FractionUnit.GetUnitAsString(unitSystem.FractionUnitType);
                string enthalpy           = "Specific Energy: \t\t" + SpecificEnergyUnit.GetUnitAsString(unitSystem.SpecificEnergyUnitType);
                string specificHeat       = "Specific Heat: \t\t" + SpecificHeatUnit.GetUnitAsString(unitSystem.SpecificHeatUnitType);
                string energy             = "Energy: \t\t\t" + EnergyUnit.GetUnitAsString(unitSystem.EnergyUnitType);
                string power              = "Power: \t\t\t" + PowerUnit.GetUnitAsString(unitSystem.PowerUnitType);
                string density            = "Density: \t\t\t" + DensityUnit.GetUnitAsString(unitSystem.DensityUnitType);
                string dynamicViscosity   = "Dynamic Viscosity: \t\t" + DynamicViscosityUnit.GetUnitAsString(unitSystem.DynamicViscosityUnitType);
                string kinematicViscosity = "Kinematic Viscosity: \t" + KinematicViscosityUnit.GetUnitAsString(unitSystem.KinematicViscosityUnitType);
                string conductivity       = "Thermal Conductivity: \t" + ThermalConductivityUnit.GetUnitAsString(unitSystem.ThermalConductivityUnitType);
                string diffusivity        = "Diffusivity: \t\t" + DiffusivityUnit.GetUnitAsString(unitSystem.DiffusivityUnitType);
                string mass                          = "Mass: \t\t\t" + MassUnit.GetUnitAsString(unitSystem.MassUnitType);
                string length                        = "Length: \t\t\t" + LengthUnit.GetUnitAsString(unitSystem.LengthUnitType);
                string area                          = "Area: \t\t\t" + AreaUnit.GetUnitAsString(unitSystem.AreaUnitType);
                string volume                        = "Volume: \t\t\t" + VolumeUnit.GetUnitAsString(unitSystem.VolumeUnitType);
                string time                          = "Time: \t\t\t" + TimeUnit.GetUnitAsString(unitSystem.TimeUnitType);
                string smallLength                   = "Small Length: \t\t" + SmallLengthUnit.GetUnitAsString(unitSystem.SmallLengthUnitType);
                string microLength                   = "Micro Length: \t\t" + MicroLengthUnit.GetUnitAsString(unitSystem.MicroLengthUnitType);
                string liquidHead                    = "Liquid Head: \t\t" + LiquidHeadUnit.GetUnitAsString(unitSystem.LiquidHeadUnitType);
                string volumeRateFlowLiquids         = "Volume Rate Flow Liquids: \t" + VolumeRateFlowLiquidsUnit.GetUnitAsString(unitSystem.VolumeRateFlowLiquidsUnitType);
                string volumeRateFlowGases           = "Volume Rate Flow Gases: \t" + VolumeRateFlowGasesUnit.GetUnitAsString(unitSystem.VolumeRateFlowGasesUnitType);
                string heatTransferCoeff             = "Heat Transfer Coeff.: \t" + HeatTransferCoefficientUnit.GetUnitAsString(unitSystem.HeatTransferCoefficientUnitType);
                string surfaceTension                = "Surface Tension: \t\t" + SurfaceTensionUnit.GetUnitAsString(unitSystem.SurfaceTensionUnitType);
                string velocity                      = "Velocity: \t\t\t" + VelocityUnit.GetUnitAsString(unitSystem.VelocityUnitType);
                string foulingFactor                 = "Fouling Factor: \t\t" + FoulingFactorUnit.GetUnitAsString(unitSystem.FoulingFactorUnitType);
                string specificVolume                = "Specific Volume: \t\t" + SpecificVolumeUnit.GetUnitAsString(unitSystem.SpecificVolumeUnitType);
                string massVolumeConcentration       = "Mass Volume Concentration: \t" + MassVolumeConcentrationUnit.GetUnitAsString(unitSystem.MassVolumeConcentrationUnitType);
                string planeAngle                    = "Plane Angle: \t\t" + PlaneAngleUnit.GetUnitAsString(unitSystem.PlaneAngleUnitType);
                string volumeHeatTransferCoefficient = "Volume Heat Transfer Coeff.: \t" + VolumeHeatTransferCoefficientUnit.GetUnitAsString(unitSystem.VolumeHeatTransferCoefficientUnitType);

                this.TextBox.AppendText(temperature + "\r\n");
                this.TextBox.AppendText(pressure + "\r\n");
                this.TextBox.AppendText(massFlowRate + "\r\n");
                this.TextBox.AppendText(volumeFlowRate + "\r\n");
                this.TextBox.AppendText(moistureContent + "\r\n");
                this.TextBox.AppendText(relativeHumidity + "\r\n");
                this.TextBox.AppendText(enthalpy + "\r\n");
                this.TextBox.AppendText(specificHeat + "\r\n");
                this.TextBox.AppendText(energy + "\r\n");
                this.TextBox.AppendText(power + "\r\n");
                this.TextBox.AppendText(density + "\r\n");
                this.TextBox.AppendText(dynamicViscosity + "\r\n");
                this.TextBox.AppendText(kinematicViscosity + "\r\n");
                this.TextBox.AppendText(conductivity + "\r\n");
                this.TextBox.AppendText(diffusivity + "\r\n");
                this.TextBox.AppendText(mass + "\r\n");
                this.TextBox.AppendText(length + "\r\n");
                this.TextBox.AppendText(area + "\r\n");
                this.TextBox.AppendText(volume + "\r\n");
                this.TextBox.AppendText(time + "\r\n");
                this.TextBox.AppendText(smallLength + "\r\n");
                this.TextBox.AppendText(microLength + "\r\n");
                this.TextBox.AppendText(liquidHead + "\r\n");
                this.TextBox.AppendText(volumeRateFlowLiquids + "\r\n");
                this.TextBox.AppendText(volumeRateFlowGases + "\r\n");
                this.TextBox.AppendText(heatTransferCoeff + "\r\n");
                this.TextBox.AppendText(surfaceTension + "\r\n");
                this.TextBox.AppendText(velocity + "\r\n");
                this.TextBox.AppendText(foulingFactor + "\r\n");
                this.TextBox.AppendText(specificVolume + "\r\n");
                this.TextBox.AppendText(massVolumeConcentration + "\r\n");
                this.TextBox.AppendText(planeAngle + "\r\n");
                this.TextBox.AppendText(volumeHeatTransferCoefficient + "\r\n");

                this.textBoxUnitSystem.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            }
        }
Exemple #7
0
        /// <summary>
        ///     Converts this Diffusivity to another Diffusivity with the unit representation <paramref name="unit" />.
        /// </summary>
        /// <returns>A Diffusivity with the specified unit.</returns>
        public Diffusivity ToUnit(DiffusivityUnit unit)
        {
            var convertedValue = AsBaseNumericType(unit);

            return(new Diffusivity(convertedValue, unit));
        }
Exemple #8
0
        /// <summary>
        ///     Parse a unit string.
        /// </summary>
        /// <param name="str">String to parse. Typically in the form: {number} {unit}</param>
        /// <param name="unit">The parsed unit if successful.</param>
        /// <returns>True if successful, otherwise false.</returns>
        /// <example>
        ///     Length.TryParseUnit("m", new CultureInfo("en-US"));
        /// </example>
        /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" /> if null.</param>
        public static bool TryParseUnit(string str, [CanBeNull] string cultureName, out DiffusivityUnit unit)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitParser.Default.TryParse <DiffusivityUnit>(str, provider, out unit));
        }
Exemple #9
0
 public static bool TryParseUnit(string str, out DiffusivityUnit unit)
 {
     return(TryParseUnit(str, null, out unit));
 }
Exemple #10
0
 public static Diffusivity From(double value, DiffusivityUnit fromUnit)
 {
     return(new Diffusivity((double)value, fromUnit));
 }
Exemple #11
0
        /// <summary>
        ///     Get unit abbreviation string.
        /// </summary>
        /// <param name="unit">Unit to get abbreviation for.</param>
        /// <returns>Unit abbreviation string.</returns>
        /// <param name="cultureName">Name of culture (ex: "en-US") to use when parsing number and unit. Defaults to <see cref="GlobalConfiguration.DefaultCulture" /> if null.</param>
        public static string GetAbbreviation(DiffusivityUnit unit, [CanBeNull] string cultureName)
        {
            IFormatProvider provider = GetFormatProviderFromCultureName(cultureName);

            return(UnitAbbreviationsCache.Default.GetDefaultAbbreviation(unit, provider));
        }
Exemple #12
0
 /// <summary>
 ///     Get unit abbreviation string.
 /// </summary>
 /// <param name="unit">Unit to get abbreviation for.</param>
 /// <returns>Unit abbreviation string.</returns>
 public static string GetAbbreviation(DiffusivityUnit unit)
 {
     return(GetAbbreviation(unit, null));
 }