public static ThermodynamicParameter CP2(string fluidName, string InpCode, UnitSystems units, double Prop1, double Prop2)
 {
     //Refrigerant r = new Refrigerant(fluidName);
     REFPROP.Name = fluidName;
     REFPROP.FindState(InpCode, units, Prop1, Prop2);
     return REFPROP.CP;
 }
Exemple #2
0
        //This method prints the main string representations and some basic information for all the named units.
        //In any case, note that UnitParser supports a wide range of variations which aren't referred here.
        //Examples: plurals of string representation other than symbols or ignoring certain invalid characters
        //(e.g., blank spaces or conventionally-used characters like "^").
        //Additionally, bear in mind that these are just the members of the Units enum, a small fraction of
        //all the units supported by UnitParser. Any unit belonging to a supported type (UnitTypes enum) which
        //is formed by the combination of one or more named units (Units enum) is also supported. For example,
        //the named unit Units.Foot can be part of many other unnamed units like ft/h (velocity), rood*ft (volume)
        //or tn*ft/s2 (force).
        private static void PrintAllNamedUnits()
        {
            foreach (Units unit in Enum.GetValues(typeof(Units)))
            {
                if (unit == Units.None || unit == Units.Unitless)
                {
                    continue;
                }

                UnitTypes   type   = UnitP.GetUnitType(unit);
                UnitSystems system = UnitP.GetUnitSystem(unit);

                if (type == UnitTypes.None)
                {
                    continue;
                }

                Console.WriteLine("Unit: " + unit.ToString());
                Console.WriteLine("Type: " + type.ToString());
                Console.WriteLine("System: " + system.ToString());

                string representations = "";
                foreach (string representation in UnitP.GetStringsForUnit(unit, true))
                {
                    if (representations != "")
                    {
                        representations += ", ";
                    }
                    representations += representation;
                }

                Console.WriteLine("Representations: " + representations);
                Console.WriteLine();
            }
        }
 public static double CV(string fluidName, string InpCode, UnitSystems units, double Prop1, double Prop2)
 {
     //Refrigerant r = new Refrigerant(fluidName);
     REFPROP.Name = fluidName;
     REFPROP.FindState(InpCode, units, Prop1, Prop2);
     return REFPROP.CV.Value;
 }
        public override void Loaded()
        {
            base.Loaded();

            //settings
            init = true;
            EnableCloudBackup = _settingsStore.CloudEnabled;
            init              = false;
            DailyGoal         = _unitHelper.GetAmount(_settingsStore.DailyGoal).ToString();
            QuietHoursEnabled = _settingsStore.QuietHoursEnabled;
            QuietHoursStart   = _settingsStore.QuietHoursStart;
            QuietHoursEnd     = _settingsStore.QuietHoursEnd;

            // Intervals
            Intervals.Add(new IntervalItem()
            {
                Name = _resourceRepository.GetString("remind15Min"), Value = 1
            });
            Intervals.Add(new IntervalItem()
            {
                Name = _resourceRepository.GetString("remind30Min"), Value = 2
            });
            Intervals.Add(new IntervalItem()
            {
                Name = _resourceRepository.GetString("remind45Min"), Value = 3
            });
            Intervals.Add(new IntervalItem()
            {
                Name = _resourceRepository.GetString("remind60Min"), Value = 4
            });
            Intervals.Add(new IntervalItem()
            {
                Name = _resourceRepository.GetString("remind120Min"), Value = 8
            });
            SelectedInterval = Intervals.FirstOrDefault(i => i.Value == _settingsStore.NotificationInterval);

            // Unit Systems
            UnitSystems.Add(new UnitSystemItem()
            {
                Id = 0, Name = _resourceRepository.GetString("unitMetric")
            });
            UnitSystems.Add(new UnitSystemItem()
            {
                Id = 1, Name = _resourceRepository.GetString("unitUSImperial")
            });
            SelectedUnitSystem   = UnitSystems.FirstOrDefault(i => i.Id == _settingsStore.UnitSystem);
            DailyWaterGoalHeader = String.Format(_resourceRepository.GetString("txtDailyWaterGoal"),
                                                 _unitHelper.AmountText);
        }
Exemple #5
0
        /// <summary>
        /// Calculates the conversion multiplier needed to convert between two Units
        /// </summary>
        /// <param name="currentUnit">The starting unit</param>
        /// <param name="newUnit">The target unit</param>
        /// <returns>Multyplier as a double</returns>
        public static double GetUnitConversion(Units currentUnit, Units newUnit)
        {
            Quantities currentQuantity = currentUnit.GetQuantity();
            Quantities newQuantity     = newUnit.GetQuantity();

            double conversion;

            if (currentQuantity == newQuantity)
            {
                // The units can be converted between

                UnitSystems currentSystem = currentUnit.GetSystem();
                UnitSystems newSystem     = newUnit.GetSystem();

                if (currentSystem == newSystem)
                {
                    // Same system - convert from current unit to base to new unit
                    // new * 1/current
                    conversion = newUnit.GetBaseMultyplier() / currentUnit.GetBaseMultyplier();
                }
                else
                {
                    // Systems are different - convert to system base -> convert to new system -> convert to new unit

                    Units currentSystemBaseUnit = currentQuantity.GetSystemBaseUnit(currentSystem);
                    Units newSystemBaseUnit     = newQuantity.GetSystemBaseUnit(newSystem);

                    conversion = GetUnitConversion(currentUnit, currentQuantity.GetSystemBaseUnit(currentSystem));

                    Dictionary <Units, double> conversions = currentQuantity.GetSystemConversions();

                    conversion *= conversions[newQuantity.GetSystemBaseUnit(newSystem)] / conversions[currentQuantity.GetSystemBaseUnit(currentSystem)];

                    conversion *= GetUnitConversion(newQuantity.GetSystemBaseUnit(newSystem), newUnit);
                }

                return(conversion);
            }
            else
            {
                // The units refer to different quantities so can't be converted
                throw new ArgumentException("Unit conversion failed - the units provided are for different quantities and therfore can't be converted.");
            }
        }
Exemple #6
0
        /// <summary>
        /// This is a method to Calculate, output a heading and run through the program options
        /// <summery>
        public void CalculateIndex()
        {
            ConsoleHelper.OutputHeading("Body Mass Index Calculator");

            //Select units method called to make the unit choice
            UnitSystems unitSystem = SelectUnits();

            //Decision made of choice - imperial or metric
            if (unitSystem == UnitSystems.Imperial)
            {
                InputImperialDetails();
                CalculateImperialBMI();
            }
            else
            {
                InputMetricDetails();
                CalculateMetricBMI();
            }
            //Output the required messages for BMI calculations
            //and if you are BAME therefore are at a higher risk

            OutputHealthMessage();
            OutputBameMessage();
        }
 public InternalEnergy(double value, UnitSystems unitSystem)
     : base(0.0, UnitTypes.H, value, unitSystem)
 {
 }
 public PrantdlNumber(double value, UnitSystems unitSystem)
     : base(0.0, UnitTypes.X, value, unitSystem)
 {
 }
 public Density(double _wm, double value, UnitSystems unitSystem)
     : base(_wm, UnitTypes.D, value, unitSystem)
 {
 }
Exemple #10
0
        /// <summary>
        /// Gets the base unit for a quantity in a system
        /// </summary>
        /// <param name="quantity">The quantity</param>
        /// /// <param name="system">The unisystemt</param>
        /// <returns>The quantity's base unit in the system</returns>
        public static Units GetSystemBaseUnit(this Quantities quantity, UnitSystems system)
        {
            Units result;

            switch (quantity)
            {
            case Quantities.None:
                switch (system)
                {
                case UnitSystems.None:
                    result = Units.NoUnit;
                    break;

                default:
                    throw new ArgumentException("The quantity dosen't exist in the specified system.");
                }
                break;

            case Quantities.Angle:
                switch (system)
                {
                case UnitSystems.Degrees:
                    result = Units.Degrees;
                    break;

                case UnitSystems.Radians:
                    result = Units.Radians;
                    break;

                default:
                    throw new ArgumentException("The quantity dosen't exist in the specified system.");
                }
                break;

            case Quantities.Distance:
                switch (system)
                {
                case UnitSystems.SI:
                    result = Units.m;
                    break;

                default:
                    throw new ArgumentException("The quantity dosen't exist in the specified system.");
                }
                break;

            case Quantities.Mass:
                switch (system)
                {
                case UnitSystems.SI:
                    result = Units.Kg;
                    break;

                case UnitSystems.Imperial:
                    result = Units.lb;
                    break;

                default:
                    throw new ArgumentException("The quantity dosen't exist in the specified system.");
                }
                break;

            case Quantities.Time:
                switch (system)
                {
                case UnitSystems.Time:
                    result = Units.s;
                    break;

                default:
                    throw new ArgumentException("The quantity dosen't exist in the specified system.");
                }
                break;

            default:
                throw new ArgumentException("The quantity dosen't exist.");
            }

            return(result);
        }
 public Density(UnitSystems unitSystem)
     : this(0.0, unitSystem)
 {
 }
        public ThermodynamicParameter(double wm, UnitTypes utp, double value, UnitSystems unitsys, List<ThermodynamicParameter> List)
        {
            this.MolecularWeight = wm;
            this.UnitType = utp;
            this.Value = value;
            try
            {
                //利用映射
                string[] temp = (string[])(typeof(UnitConversion).GetField(UnitType.ToString()).GetValue(null));
                this.Unit = temp[(int)unitsys];
            }
            catch
            {
                RefpropErrorHandler.ErrorHandler(this, "Unknown unit", 1000);
            }

            this.UnitSystem = unitsys;
            List.Add(this);
        }
 public SpecificHeat(UnitSystems unitSystem)
     : this(0.0, unitSystem)
 {
 }
 public ThermalConductivity(UnitSystems unitSystem, List<ThermodynamicParameter> List)
     : base(0.0, UnitTypes.K, 0.0, unitSystem,List)
 {
 }
 public Quality(UnitSystems unitSystem)
     : this(0.0, unitSystem)
 {
 }
 public Quality(double value, UnitSystems unitSystem)
     : base(0.0, UnitTypes.X, value, unitSystem)
 {
 }
 public Pressure(double value, UnitSystems unitSystem)
     : base(0.0, UnitTypes.P, value, unitSystem)
 {
 }
 public Pressure(UnitSystems unitSystem, List<ThermodynamicParameter> List)
     : base(0.0, UnitTypes.P, 0.0, unitSystem,List)
 {
 }
 public Pressure(UnitSystems unitSystem)
     : this(0.0, unitSystem)
 {
 }
 public Temperature(double value, UnitSystems unitSystem)
     : base(0.0, UnitTypes.T, value, unitSystem)
 {
 }
 public SpecificHeat(UnitSystems unitSystem, List<ThermodynamicParameter> List)
     : base(0.0, UnitTypes.S, 0.0, unitSystem,List)
 {
 }
 public ThermalConductivity(UnitSystems unitSystem)
     : this(0.0, unitSystem)
 {
 }
 public SpecificHeat(double value, UnitSystems unitSystem)
     : base(0.0, UnitTypes.S, value, unitSystem)
 {
 }
 public ThermalConductivity(double value, UnitSystems unitSystem)
     : base(0.0, UnitTypes.K, value, unitSystem)
 {
 }
 public SurfaceTension(UnitSystems unitSystem)
     : this(0.0, unitSystem)
 {
 }
 public ThermodynamicParameter(UnitTypes type, double value, UnitSystems unitsys)
     : this(0, type, 0, unitsys)
 {
 }
 public PrantdlNumber(UnitSystems unitSystem)
     : this(0.0, unitSystem)
 {
 }
 public Density(UnitSystems unitSystem, List<ThermodynamicParameter> List)
     : base(0.0, UnitTypes.D, 0.0, unitSystem,List)
 {
 }
 public SurfaceTension(double value, UnitSystems unitSystem)
     : base(0.0, UnitTypes.N, value, unitSystem)
 {
 }
 public CompressibilityFactor(double value, UnitSystems unitSystem)
     : base(0.0, UnitTypes.X, value, unitSystem)
 {
 }
 public Temperature(UnitSystems unitSystem)
     : this(0.0, unitSystem)
 {
 }
 public static ThermodynamicParameter Viscosity2(string fluidName, string InpCode, UnitSystems units, double Prop1, double Prop2)
 {
     REFPROP.Name = fluidName;
     REFPROP.FindState(InpCode, units, Prop1, Prop2);
     return REFPROP.U;
 }
 public Temperature(UnitSystems unitSystem, List<ThermodynamicParameter> List)
     : base(0.0, UnitTypes.T, 0.0, unitSystem,List)
 {
 }
 public SurfaceTension(UnitSystems unitSystem, List<ThermodynamicParameter> List)
     : base(0.0, UnitTypes.N, 0.0, unitSystem,List)
 {
 }
 public PrantdlNumber(UnitSystems unitSystem, List<ThermodynamicParameter> List)
     : base(0.0, UnitTypes.X, 0.0, unitSystem,List)
 {
 }