Example #1
0
        public static double ToJoule(double srcValue, EnergyRepresentation srcUnit)
        {
            switch (srcUnit)
            {
            case EnergyRepresentation.Joule:
                return(srcValue);

            case EnergyRepresentation.JoulePerMole:
                return(srcValue / SIConstants.AVOGADROS_CONSTANT);

            case EnergyRepresentation.CalorieInternational:
                return(srcValue * SIConstants.CALORIE);

            case EnergyRepresentation.CalorieInternationalPerMole:
                return(srcValue * SIConstants.CALORIE / SIConstants.AVOGADROS_CONSTANT);

            case EnergyRepresentation.ElectronVolt:
                return(srcValue * SIConstants.ELECTRON_VOLT);

            case EnergyRepresentation.KilowattHours:
                return(srcValue * 3600000);

            case EnergyRepresentation.AsTemperatureKelvin:
                return(srcValue * SIConstants.BOLTZMANN);

            default:
                throw new ArgumentOutOfRangeException("EnergyUnit unknown: " + srcUnit.ToString());
            }
        }
Example #2
0
 public static double FromTo(double srcValue, EnergyRepresentation srcUnit, EnergyRepresentation destUnit)
 {
     if (srcUnit == destUnit)
     {
         return(srcValue);
     }
     else
     {
         return(FromJouleTo(ToJoule(srcValue, srcUnit), destUnit));
     }
 }
Example #3
0
		public static double ToJoule(double srcValue, EnergyRepresentation srcUnit)
		{
			switch (srcUnit)
			{
				case EnergyRepresentation.Joule:
					return srcValue;

				case EnergyRepresentation.JoulePerMole:
					return srcValue / SIConstants.AVOGADROS_CONSTANT;

				case EnergyRepresentation.CalorieInternational:
					return srcValue * SIConstants.CALORIE;

				case EnergyRepresentation.CalorieInternationalPerMole:
					return srcValue * SIConstants.CALORIE / SIConstants.AVOGADROS_CONSTANT;

				case EnergyRepresentation.ElectronVolt:
					return srcValue * SIConstants.ELECTRON_VOLT;

				case EnergyRepresentation.KilowattHours:
					return srcValue * 3600000;

				case EnergyRepresentation.AsTemperatureKelvin:
					return srcValue * SIConstants.BOLTZMANN;

				default:
					throw new ArgumentOutOfRangeException("EnergyUnit unknown: " + srcUnit.ToString());
			}
		}
Example #4
0
		public Energy ConvertTo(EnergyRepresentation destUnit)
		{
			return new Energy(FromTo(_value, _unit, destUnit), destUnit);
		}
Example #5
0
		public double InUnitsOf(EnergyRepresentation destUnit)
		{
			return FromTo(_value, _unit, destUnit);
		}
Example #6
0
		public Energy(double value, EnergyRepresentation unit)
		{
			_unit = unit;
			_value = value;
		}
Example #7
0
		/// <summary>
		/// Returns the temperature (in Kelvin) corresponding to the provided energy.
		/// </summary>
		/// <param name="srcValue">Energy value.</param>
		/// <param name="srcUnit">Energy unit.</param>
		/// <returns>Temperature E/kB in Kelvin, where kB is the BOLTZMANN constant and E the energy in Joule.</returns>
		public static double ToTemperatureSI(double srcValue, EnergyRepresentation srcUnit)
		{
			return ToJoule(srcValue, srcUnit) / SIConstants.BOLTZMANN;
		}
Example #8
0
		public static double FromTo(double srcValue, EnergyRepresentation srcUnit, EnergyRepresentation destUnit)
		{
			if (srcUnit == destUnit)
				return srcValue;
			else
				return FromJouleTo(ToJoule(srcValue, srcUnit), destUnit);
		}
Example #9
0
 public Energy ConvertTo(EnergyRepresentation destUnit)
 {
     return(new Energy(FromTo(_value, _unit, destUnit), destUnit));
 }
Example #10
0
 public double InUnitsOf(EnergyRepresentation destUnit)
 {
     return(FromTo(_value, _unit, destUnit));
 }
Example #11
0
 public Energy(double value, EnergyRepresentation unit)
 {
     _unit  = unit;
     _value = value;
 }
Example #12
0
 /// <summary>
 /// Returns the temperature (in Kelvin) corresponding to the provided energy.
 /// </summary>
 /// <param name="srcValue">Energy value.</param>
 /// <param name="srcUnit">Energy unit.</param>
 /// <returns>Temperature E/kB in Kelvin, where kB is the BOLTZMANN constant and E the energy in Joule.</returns>
 public static double ToTemperatureSI(double srcValue, EnergyRepresentation srcUnit)
 {
     return(ToJoule(srcValue, srcUnit) / SIConstants.BOLTZMANN);
 }