예제 #1
0
        public static double ConvertToSIValue(TemperatureUnitType unitType, double toBeConvertedValue)
        {
            double kelvinValue = 0;

            if (unitType == TemperatureUnitType.Celsius)
            {
                kelvinValue = toBeConvertedValue + 273.15;
            }
            else if (unitType == TemperatureUnitType.Fahrenheit)
            {
                kelvinValue = (toBeConvertedValue + 459.67) / 1.8;
            }
            else if (unitType == TemperatureUnitType.Kelvin)
            {
                kelvinValue = toBeConvertedValue;
            }
            else if (unitType == TemperatureUnitType.Rankine)
            {
                kelvinValue = toBeConvertedValue / 1.8;
            }
            else if (unitType == TemperatureUnitType.Reaumur)
            {
                kelvinValue = 0.8 * toBeConvertedValue + 273.15;
            }

            return(kelvinValue);
        }
예제 #2
0
        public static double ConvertFromSIValue(TemperatureUnitType unitType, double kelvinValue)
        {
            double convertedValue = 0;

            if (unitType == TemperatureUnitType.Celsius)
            {
                convertedValue = kelvinValue - 273.15;
            }
            else if (unitType == TemperatureUnitType.Fahrenheit)
            {
                convertedValue = 1.8 * kelvinValue - 459.67;
            }
            else if (unitType == TemperatureUnitType.Kelvin)
            {
                convertedValue = kelvinValue;
            }
            else if (unitType == TemperatureUnitType.Rankine)
            {
                convertedValue = 1.8 * kelvinValue;
            }
            else if (unitType == TemperatureUnitType.Reaumur)
            {
                convertedValue = (kelvinValue - 273.15) / 0.8;
            }
            return(convertedValue);
        }
예제 #3
0
        private void CreateDefaultUnit(string name, TemperatureUnitType temperature, PressureUnitType pressure,
                                       LiquidHeadUnitType liquidHead, MassFlowRateUnitType massFlowRate, VolumeFlowRateUnitType volumeFlowRate,
                                       VolumeRateFlowLiquidsUnitType volumeRateFlowLiquids, VolumeRateFlowGasesUnitType volumeRateFlowGases,
                                       MoistureContentUnitType moistureContent, FractionUnitType fraction, SpecificEnergyUnitType specificEnergy,
                                       SpecificEntropyUnitType specificEntropy, SpecificHeatUnitType specificHeat,
                                       EnergyUnitType energy, PowerUnitType power, DensityUnitType density,
                                       SpecificVolumeUnitType specificVolume, DynamicViscosityUnitType dynamicViscosity,
                                       KinematicViscosityUnitType kinematicViscosity, ThermalConductivityUnitType thermalConductivity,
                                       HeatTransferCoefficientUnitType heatTransferCoefficient, VolumeHeatTransferCoefficientUnitType volumeHeatTransferCoefficient,
                                       FoulingFactorUnitType foulingFactor,
                                       HeatFluxUnitType heatFluxDensity, DiffusivityUnitType diffusivity,
                                       SurfaceTensionUnitType surfaceTension, VelocityUnitType velocity, MassUnitType mass,
                                       LengthUnitType length, SmallLengthUnitType smallLength, MicroLengthUnitType microLength,
                                       AreaUnitType area, VolumeUnitType volume, MassVolumeConcentrationUnitType massVolumeConcentration,
                                       TimeUnitType time, PlaneAngleUnitType planeAngle)
        {
            UnitSystem us = new UnitSystem(name, true, temperature, pressure, liquidHead, massFlowRate,
                                           volumeFlowRate, volumeRateFlowLiquids, volumeRateFlowGases, moistureContent,
                                           fraction, specificEnergy, specificEntropy, specificHeat, energy, power,
                                           density, specificVolume, dynamicViscosity, kinematicViscosity, thermalConductivity,
                                           heatTransferCoefficient, volumeHeatTransferCoefficient, foulingFactor, heatFluxDensity,
                                           diffusivity, surfaceTension, velocity, mass, length, smallLength, microLength, area, volume,
                                           massVolumeConcentration, time, planeAngle);

            unitSystemList.Add(us);
            if (!us.IsReadOnly)
            {
                us.UnitSystemChanged += new UnitSystemChangedEventHandler(unitSystem_UnitSystemChanged);
            }
        }
예제 #4
0
 public UnitSystem(string name, bool readOnly, TemperatureUnitType temperature,
                   PressureUnitType pressure, LiquidHeadUnitType liquidHead, MassFlowRateUnitType massFlowRate,
                   VolumeFlowRateUnitType volumeFlowRate, VolumeRateFlowLiquidsUnitType volumeRateFlowLiquids,
                   VolumeRateFlowGasesUnitType volumeRateFlowGases, MoistureContentUnitType moistureContent,
                   FractionUnitType fraction, SpecificEnergyUnitType enthalpy, SpecificEntropyUnitType entropy,
                   SpecificHeatUnitType specificHeat, EnergyUnitType energy, PowerUnitType power, DensityUnitType density,
                   SpecificVolumeUnitType specificVolume,
                   DynamicViscosityUnitType dynamicViscosity, KinematicViscosityUnitType kinematicViscosity,
                   ThermalConductivityUnitType conductivity, HeatTransferCoefficientUnitType heatTransferCoefficient,
                   VolumeHeatTransferCoefficientUnitType volumeHeatTransferCoefficient, FoulingFactorUnitType foulingFactor, HeatFluxUnitType heatFlux,
                   DiffusivityUnitType diffusivity, SurfaceTensionUnitType surfaceTension, VelocityUnitType velocity,
                   MassUnitType mass, LengthUnitType length, SmallLengthUnitType smallLength, MicroLengthUnitType microLength,
                   AreaUnitType area, VolumeUnitType volume, MassVolumeConcentrationUnitType massVolumeConcentration, TimeUnitType time,
                   PlaneAngleUnitType planeAngle, MoleFlowRateUnitType moleFlowRate)
 {
     this.name                          = name;
     this.temperature                   = temperature;
     this.pressure                      = pressure;
     this.liquidHead                    = liquidHead;
     this.massFlowRate                  = massFlowRate;
     this.volumeFlowRate                = volumeFlowRate;
     this.volumeRateFlowLiquids         = volumeRateFlowLiquids;
     this.volumeRateFlowGases           = volumeRateFlowGases;
     this.moistureContent               = moistureContent;
     this.fraction                      = fraction;
     this.enthalpy                      = enthalpy;
     this.entropy                       = entropy;
     this.specificHeat                  = specificHeat;
     this.energy                        = energy;
     this.power                         = power;
     this.density                       = density;
     this.specificVolume                = specificVolume;
     this.dynamicViscosity              = dynamicViscosity;
     this.kinematicViscosity            = kinematicViscosity;
     this.conductivity                  = conductivity;
     this.diffusivity                   = diffusivity;
     this.heatTransferCoefficient       = heatTransferCoefficient;
     this.volumeHeatTransferCoefficient = volumeHeatTransferCoefficient;
     this.foulingFactor                 = foulingFactor;
     this.heatFlux                      = heatFlux;
     this.surfaceTension                = surfaceTension;
     this.velocity                      = velocity;
     this.mass                          = mass;
     this.length                        = length;
     this.smallLength                   = smallLength;
     this.microLength                   = microLength;
     this.area                          = area;
     this.volume                        = volume;
     this.massVolumeConcentration       = massVolumeConcentration;
     this.time                          = time;
     this.planeAngle                    = planeAngle;
     this.moleFlowRate                  = moleFlowRate;
     this.readOnly                      = readOnly;
 }
예제 #5
0
        public virtual void SetObjectData(SerializationInfo info, StreamingContext context)
        {
            int persistedClassVersion = (int)info.GetValue("ClassPersistenceVersionUnitSystem", typeof(int));

            if (persistedClassVersion >= 1)
            {
                this.name                          = (string)info.GetValue("Name", typeof(string));
                this.readOnly                      = (bool)info.GetValue("IsReadOnly", typeof(bool));
                this.area                          = (AreaUnitType)info.GetValue("AreaUnit", typeof(AreaUnitType));
                this.density                       = (DensityUnitType)info.GetValue("DensityUnit", typeof(DensityUnitType));
                this.diffusivity                   = (DiffusivityUnitType)info.GetValue("DiffusivityUnit", typeof(DiffusivityUnitType));
                this.dynamicViscosity              = (DynamicViscosityUnitType)info.GetValue("DynamicViscosityUnit", typeof(DynamicViscosityUnitType));
                this.energy                        = (EnergyUnitType)info.GetValue("EnergyUnit", typeof(EnergyUnitType));
                this.foulingFactor                 = (FoulingFactorUnitType)info.GetValue("FoulingFactorUnit", typeof(FoulingFactorUnitType));
                this.fraction                      = (FractionUnitType)info.GetValue("FractionUnit", typeof(FractionUnitType));
                this.heatFlux                      = (HeatFluxUnitType)info.GetValue("HeatFluxUnit", typeof(HeatFluxUnitType));
                this.heatTransferCoefficient       = (HeatTransferCoefficientUnitType)info.GetValue("HeatTransferCoefficientUnit", typeof(HeatTransferCoefficientUnitType));
                this.volumeHeatTransferCoefficient = (VolumeHeatTransferCoefficientUnitType)info.GetValue("VolumeHeatTransferCoefficientUnit", typeof(VolumeHeatTransferCoefficientUnitType));
                this.kinematicViscosity            = (KinematicViscosityUnitType)info.GetValue("KinematicViscosityUnit", typeof(KinematicViscosityUnitType));
                this.length                        = (LengthUnitType)info.GetValue("LengthUnit", typeof(LengthUnitType));
                this.liquidHead                    = (LiquidHeadUnitType)info.GetValue("LiquidHeadUnit", typeof(LiquidHeadUnitType));
                this.massFlowRate                  = (MassFlowRateUnitType)info.GetValue("MassFlowRateUnit", typeof(MassFlowRateUnitType));
                this.mass                          = (MassUnitType)info.GetValue("MassUnit", typeof(MassUnitType));
                this.massVolumeConcentration       = (MassVolumeConcentrationUnitType)info.GetValue("MassVolumeConcentrationUnit", typeof(MassVolumeConcentrationUnitType));
                this.microLength                   = (MicroLengthUnitType)info.GetValue("MicroLengthUnit", typeof(MicroLengthUnitType));
                this.moistureContent               = (MoistureContentUnitType)info.GetValue("MoistureContentUnit", typeof(MoistureContentUnitType));
                this.planeAngle                    = (PlaneAngleUnitType)info.GetValue("PlaneAngleUnit", typeof(PlaneAngleUnitType));
                this.power                         = (PowerUnitType)info.GetValue("PowerUnit", typeof(PowerUnitType));
                this.pressure                      = (PressureUnitType)info.GetValue("PressureUnit", typeof(PressureUnitType));
                this.smallLength                   = (SmallLengthUnitType)info.GetValue("SmallLengthUnit", typeof(SmallLengthUnitType));
                this.enthalpy                      = (SpecificEnergyUnitType)info.GetValue("SpecificEnergyUnit", typeof(SpecificEnergyUnitType));
                this.entropy                       = (SpecificEntropyUnitType)info.GetValue("SpecificEntropyUnit", typeof(SpecificEntropyUnitType));
                this.specificHeat                  = (SpecificHeatUnitType)info.GetValue("SpecificHeatUnit", typeof(SpecificHeatUnitType));
                this.specificVolume                = (SpecificVolumeUnitType)info.GetValue("SpecificVolumeUnit", typeof(SpecificVolumeUnitType));
                this.surfaceTension                = (SurfaceTensionUnitType)info.GetValue("SurfaceTensionUnit", typeof(SurfaceTensionUnitType));
                this.temperature                   = (TemperatureUnitType)info.GetValue("TemperatureUnit", typeof(TemperatureUnitType));
                this.conductivity                  = (ThermalConductivityUnitType)info.GetValue("ThermalConductivityUnit", typeof(ThermalConductivityUnitType));
                this.time                          = (TimeUnitType)info.GetValue("TimeUnit", typeof(TimeUnitType));
                this.velocity                      = (VelocityUnitType)info.GetValue("VelocityUnit", typeof(VelocityUnitType));
                this.volumeFlowRate                = (VolumeFlowRateUnitType)info.GetValue("VolumeFlowRateUnit", typeof(VolumeFlowRateUnitType));
                this.volumeRateFlowGases           = (VolumeRateFlowGasesUnitType)info.GetValue("VolumeRateFlowGasesUnit", typeof(VolumeRateFlowGasesUnitType));
                this.volumeRateFlowLiquids         = (VolumeRateFlowLiquidsUnitType)info.GetValue("VolumeRateFlowLiquidsUnit", typeof(VolumeRateFlowLiquidsUnitType));
                this.volume                        = (VolumeUnitType)info.GetValue("VolumeUnit", typeof(VolumeUnitType));
            }
            if (persistedClassVersion >= 2)
            {
                this.moleFlowRate = (MoleFlowRateUnitType)info.GetValue("MoleFlowRateUnit", typeof(MoleFlowRateUnitType));
            }
        }
예제 #6
0
        public static TemperatureUnitType GetUnitAsEnum(string unitString)
        {
            IDictionaryEnumerator myEnumerator = unitStringTable.GetEnumerator();
            String name;
            TemperatureUnitType type = TemperatureUnitType.Kelvin;

            while (myEnumerator.MoveNext())
            {
                name = myEnumerator.Value as String;
                if (name.Equals(unitString))
                {
                    type = (TemperatureUnitType)myEnumerator.Key;
                    break;
                }
            }
            return(type);
        }
예제 #7
0
        public void Commit(UnitSystem us)
        {
            this.name                          = us.Name; //ep
            this.temperature                   = us.temperature;
            this.pressure                      = us.pressure;
            this.liquidHead                    = us.liquidHead;
            this.massFlowRate                  = us.massFlowRate;
            this.volumeFlowRate                = us.volumeFlowRate;
            this.volumeRateFlowLiquids         = us.volumeRateFlowLiquids;
            this.volumeRateFlowGases           = us.volumeRateFlowGases;
            this.moistureContent               = us.moistureContent;
            this.fraction                      = us.fraction;
            this.enthalpy                      = us.enthalpy;
            this.entropy                       = us.entropy;
            this.specificHeat                  = us.specificHeat;
            this.energy                        = us.energy;
            this.power                         = us.power;
            this.density                       = us.density;
            this.specificVolume                = us.specificVolume;
            this.dynamicViscosity              = us.dynamicViscosity;
            this.kinematicViscosity            = us.kinematicViscosity;
            this.conductivity                  = us.conductivity;
            this.diffusivity                   = us.diffusivity;
            this.heatTransferCoefficient       = us.heatTransferCoefficient;
            this.volumeHeatTransferCoefficient = us.volumeHeatTransferCoefficient;
            this.foulingFactor                 = us.foulingFactor;
            this.heatFlux                      = us.heatFlux;
            this.surfaceTension                = us.surfaceTension;
            this.velocity                      = us.velocity;
            this.mass                          = us.mass;
            this.length                        = us.length;
            this.smallLength                   = us.smallLength;
            this.microLength                   = us.microLength;
            this.area                          = us.area;
            this.volume                        = us.volume;
            this.massVolumeConcentration       = us.massVolumeConcentration;

            this.time         = us.time;
            this.planeAngle   = us.planeAngle;
            this.moleFlowRate = us.moleFlowRate;

            this.OnUnitSystemChanged(this);
        }
예제 #8
0
 public UnitSystem()
 {
     this.name                          = "SI"; //ep
     this.temperature                   = TemperatureUnitType.Kelvin;
     this.pressure                      = PressureUnitType.Kilopascal;
     this.liquidHead                    = LiquidHeadUnitType.Meter;
     this.massFlowRate                  = MassFlowRateUnitType.KgPerHour;
     this.volumeFlowRate                = VolumeFlowRateUnitType.CubicMeterPerHour;
     this.volumeRateFlowLiquids         = VolumeRateFlowLiquidsUnitType.CubicMeterPerHour;
     this.volumeRateFlowGases           = VolumeRateFlowGasesUnitType.CubicMeterPerHour;
     this.moistureContent               = MoistureContentUnitType.KgPerKg;
     this.fraction                      = FractionUnitType.Percent;
     this.enthalpy                      = SpecificEnergyUnitType.KilojoulePerKg;
     this.entropy                       = SpecificEntropyUnitType.KilojoulePerKgKelvin;
     this.specificHeat                  = SpecificHeatUnitType.KilojoulePerKgKelvin;
     this.energy                        = EnergyUnitType.Kilojoule;
     this.power                         = PowerUnitType.Kilowatt;
     this.density                       = DensityUnitType.KgPerCubicMeter;
     this.specificVolume                = SpecificVolumeUnitType.CubicMeterPerKg;
     this.dynamicViscosity              = DynamicViscosityUnitType.PascalSecond;
     this.kinematicViscosity            = KinematicViscosityUnitType.SquareMeterPerSec;
     this.conductivity                  = ThermalConductivityUnitType.WattPerMeterKelvin;
     this.diffusivity                   = DiffusivityUnitType.SquareMeterPerSec;
     this.velocity                      = VelocityUnitType.MeterPerSec;
     this.mass                          = MassUnitType.Kilogram;
     this.length                        = LengthUnitType.Meter;
     this.smallLength                   = SmallLengthUnitType.Centimeter;
     this.microLength                   = MicroLengthUnitType.Micrometer;
     this.heatTransferCoefficient       = HeatTransferCoefficientUnitType.WattPerSquareMeterKelvin;
     this.volumeHeatTransferCoefficient = VolumeHeatTransferCoefficientUnitType.WattPerCubicMeterKelvin;
     this.foulingFactor                 = FoulingFactorUnitType.SquareMeterKelvinPerWatt;
     this.surfaceTension                = SurfaceTensionUnitType.NewtonPerMeter;
     this.area                          = AreaUnitType.SquareMeter;
     this.volume                        = VolumeUnitType.CubicMeter;
     this.massVolumeConcentration       = MassVolumeConcentrationUnitType.KgPerCubicMeter;
     this.time                          = TimeUnitType.Second;
     this.heatFlux                      = HeatFluxUnitType.WattPerSquareMeter;
     this.planeAngle                    = PlaneAngleUnitType.Radian;
     this.moleFlowRate                  = MoleFlowRateUnitType.KmolePerSec;
     this.readOnly                      = true;
 }
예제 #9
0
 public static string GetUnitAsString(TemperatureUnitType unitType)
 {
     return(unitStringTable[unitType] as String);
 }
예제 #10
0
 private bool temperatureNotificationValueIsValid(String temperature, TemperatureUnitType unit)
 {
     int value = 0;
     bool isInteger = int.TryParse(temperature, out value);
     // Device working temperature is between -20 °C and +60 °C.
     // For High Temperature notification we allow only the positive part of the interval.
     return (isInteger &&
             ((unit == TemperatureUnitType.Celsius && value >= 0 && value <= 60) ||
             (unit == TemperatureUnitType.Fahrenheit && value >= 32 && value <= 140))
            );
 }
예제 #11
0
        public static TemperatureType GetXmlTemperatureType(XElement xmlElement, string name, bool required,
            TemperatureUnitType defaultUnits)
        {
            if (xmlElement.Element(name) == null)
            {
                if (required)
                    Messages.Add(new Message
                                  	{Type = MessageType.Error, Text = String.Format("Required Double element '{0}' is missing.", name)});
                return null;
            }

            string str = xmlElement.Element(name).Value.ToUpper();
            decimal decVal;

            string strUnit = str.ParseOffUnits();
            TemperatureUnitType units = defaultUnits;
            try
            {
                // C, F
                if (!strUnit.IsNullOrEmpty())
                    units = (TemperatureUnitType) Enum.Parse(typeof (TemperatureUnitType), strUnit);
            }
            catch
            {
                Messages.Add(new Message
                              	{
                              		Type = MessageType.Error,
                              		Text = String.Format("Invalid TemperatureType '{0}' value or units is missing.", name)
                              	});
                return null;
            }
            if (!strUnit.IsNullOrEmpty())
                str = str.Replace(strUnit, null).Trim();

            if (str.IsNullOrEmpty() || !Decimal.TryParse(str, out decVal))
            {
                Messages.Add(new Message
                              	{
                              		Type = MessageType.Error,
                              		Text = String.Format("Invalid TemperatureType '{0}' value or units is missing.", name)
                              	});
                return null;
            }

            return new TemperatureType {degrees = units, Value = decVal};
        }