Functions to Convert Units

Description

These functions to convert values between units and set the user's preferred units.

Usage

1
2
3
4
5
6
7
  P.units(units = NULL)
  T.units(units = NULL)
  E.units(units = NULL)
  convert(value, units, T = get("thermo")$opt$Tr,
    P = get("thermo")$opt$Pr, pH = 7, logaH2O = 0)
  envert(value, units)
  outvert(value, units)

Arguments

units

character, name of units to set or convert to/from

value

numeric, value(s) to be converted

T

numeric, temperature (Kelvin), used in G-logK, pe-Eh and logfO2-E0 conversions

P

numeric, pressure (bar), used in logfO2-E0 conversions

pH

numeric, pH, used in logfO2-E0 conversions

logaH2O

numeric, logarithm of activity of water, used in logfO2-E0 conversions

Details

The units settings are used by subcrt, affinity, and diagram to accept input in or convert output to the units desired by the user. The settings, which can be queried or changed with T.units, E.units and P.units, refer to the units of temperature (K or C), energy (cal or J), and pressure (bar, MPa). (The first value in each of those pairs refers to the default units).

The actual units conversions are handled by convert, through which values are transformed into destination units (names not case sensitive). The possible conversions and settings for the units argument are shown in the following table. Note that Eh and E0 both stand for the value of Eh (oxidation-reduction potential in volts); they have different names so that one can choose to convert between Eh and either pe or logfO2.

property units setting of units argument
temperature °C, K C, K
pressure bar, MPa bar, MPa
energy cal, J cal, J
energy cal, cm^3 bar calories, cm3bar
energy cal, [none] G, logK
oxidation potential volt, [none] Eh, pe
oxidation potential volt, [none] E0, logfO2

envert and outvert are wrappers for convert that handle the conditional conversion of values from or to the current units settings. envert converts the value to the units in the argument, and outvert converts the value from the units in the argument, only if they are different than the current setting; otherwise the value is returned unchanged.

Value

Character return for T.units, P.units and E.units; numeric returns by the other functions.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## examples using convert
# temperature (Kelvin) to degrees C
convert(273.15, "C")
# temperature (degrees C) to Kelvin
convert(100, "K")
# Gibbs energy (cal mol-1) to/from logK
convert(1000, "logK")		
convert(1000, "logK", T=373.15)
convert(1, "G") 
# Eh (volt) to pe 
convert(-1, "pe")		
convert(-1, "pe", T=373.15)
# logfO2 to E0 (volt)
convert(-80, "E0")             
convert(-80, "E0", pH=5)
convert(-80, "E0", pH=5, logaH2O=-5)
# calorie to/from joule
convert(10, "J")		
convert(10, "cal")
# cm3bar to calories		
convert(10, "calories")

## examples showing unit settings
T.units("C")  
T1in <- envert(25, "C")         # no convertion
T1out <- outvert(313.15, "K")   # K to C
T.units("K") 
T2in <- envert(298.15, "C")     # K to C
T2out <- outvert(-233.15, "C")  # C to K
# these are the same temperature (25 deg C)
stopifnot(all.equal(T1in, T2in))
# these are numerically equivalent (40 deg C / 40 K)
stopifnot(all.equal(T1out, T2out))
T.units("C")  # return to default

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.