Question: How to check if a parameter set is in SI base units

For a numericial integration I want to check if all physical parameters are given in SI base units (before stripping of the units for the integration). Right now I am doing this
 

restart

 

Parameters

H = 0.1e-1*Unit('m'), R = 0.6e-2*Unit('m'), r_sub = 0.3e-2*Unit('m'), k = .540*Unit('W'/('m'*'K')), rho = 1060.0*Unit('kg'/'m'^3), Cp = 3745*Unit('J'/('kg'*'K')), Q_flux = 5000*Unit('W'/'m'^2), T_amb = 0*Unit('K'), Nz = 20, Nr = 20, t_final = 30*Unit('s'), t_step = Unit('s'), test_1 = Unit('kW'), test_2 = 2*Unit('N')

H = 0.1e-1*Units:-Unit(m), R = 0.6e-2*Units:-Unit(m), r_sub = 0.3e-2*Units:-Unit(m), k = .540*Units:-Unit(W/(m*K)), rho = 1060.0*Units:-Unit(kg/m^3), Cp = 3745*Units:-Unit(J/(kg*K)), Q_flux = 5000*Units:-Unit(W/m^2), T_amb = 0, Nz = 20, Nr = 20, t_final = 30*Units:-Unit(s), t_step = Units:-Unit(s), test_1 = Units:-Unit(kW), test_2 = 2*Units:-Unit(N)

(1)

H: length of rod
R: outer radius
r_sub: outer radius of heat flux
k: conductance
ρ: density
Cp: heat capacity
Q_flux: heat flux
T_amb: initial Tempearture
Nz: number of axial grid points
Nr: number of radial grid points
t_final: integration time
t_step: sampling interval for temperature fields

test_1: unit given in kilos
test_2: unit given in derived base units

alpha = k/(rho*Cp); simplify(subs(H = 0.1e-1*Units:-Unit(m), R = 0.6e-2*Units:-Unit(m), r_sub = 0.3e-2*Units:-Unit(m), k = .540*Units:-Unit(W/(m*K)), rho = 1060.0*Units:-Unit(kg/m^3), Cp = 3745*Units:-Unit(J/(kg*K)), Q_flux = 5000*Units:-Unit(W/m^2), T_amb = 0, Nz = 20, Nr = 20, t_final = 30*Units:-Unit(s), t_step = Units:-Unit(s), test_1 = Units:-Unit(kW), test_2 = 2*Units:-Unit(N), %))

alpha = 0.1360304305e-6*Units:-Unit(m^2/s)

(2)

α: thermal diffusivity

 

 


One way is to check whether the value of a physical parameter has not changed after simplification

`minus`(map(convert, simplify(`~`[rhs]({Cp = 3745*Units:-Unit(J/(kg*K)), H = 0.1e-1*Units:-Unit(m), Nr = 20, Nz = 20, Q_flux = 5000*Units:-Unit(W/m^2), R = 0.6e-2*Units:-Unit(m), T_amb = 0, k = .540*Units:-Unit(W/(m*K)), r_sub = 0.3e-2*Units:-Unit(m), rho = 1060.0*Units:-Unit(kg/m^3), t_final = 30*Units:-Unit(s), t_step = Units:-Unit(s), test_1 = Units:-Unit(kW), test_2 = 2*Units:-Unit(N)})), unit_free), map(convert, `~`[rhs]({Cp = 3745*Units:-Unit(J/(kg*K)), H = 0.1e-1*Units:-Unit(m), Nr = 20, Nz = 20, Q_flux = 5000*Units:-Unit(W/m^2), R = 0.6e-2*Units:-Unit(m), T_amb = 0, k = .540*Units:-Unit(W/(m*K)), r_sub = 0.3e-2*Units:-Unit(m), rho = 1060.0*Units:-Unit(kg/m^3), t_final = 30*Units:-Unit(s), t_step = Units:-Unit(s), test_1 = Units:-Unit(kW), test_2 = 2*Units:-Unit(N)}), unit_free))

{1000}

(3)

if is(`minus`(map(convert, simplify(`~`[rhs]({Cp = 3745*Units:-Unit(J/(kg*K)), H = 0.1e-1*Units:-Unit(m), Nr = 20, Nz = 20, Q_flux = 5000*Units:-Unit(W/m^2), R = 0.6e-2*Units:-Unit(m), T_amb = 0, k = .540*Units:-Unit(W/(m*K)), r_sub = 0.3e-2*Units:-Unit(m), rho = 1060.0*Units:-Unit(kg/m^3), t_final = 30*Units:-Unit(s), t_step = Units:-Unit(s), test_1 = Units:-Unit(kW), test_2 = 2*Units:-Unit(N)})), unit_free), map(convert, `~`[rhs]({Cp = 3745*Units:-Unit(J/(kg*K)), H = 0.1e-1*Units:-Unit(m), Nr = 20, Nz = 20, Q_flux = 5000*Units:-Unit(W/m^2), R = 0.6e-2*Units:-Unit(m), T_amb = 0, k = .540*Units:-Unit(W/(m*K)), r_sub = 0.3e-2*Units:-Unit(m), rho = 1060.0*Units:-Unit(kg/m^3), t_final = 30*Units:-Unit(s), t_step = Units:-Unit(s), test_1 = Units:-Unit(kW), test_2 = 2*Units:-Unit(N)}), unit_free)) <> {}) then print("Not all units are in SI base units") end if

"Not all units are in SI base units"

(4)

NULL

NULL


Download check_for_SI_base_units.mw

 

I am interested in simpler ways to perform the test. The statement is quite long and not easy to understand.

Given the size of the unit package, there might be a command that I have overlooked to check whether units are in SI base units. 

Have I missed test cases to make the check fool proof?


 
 

Please Wait...