If you are going to do that much work on a unit registry, I would just go out and create a unit registry myself as shown in the docs here. The way I would try to modify what you did is as follows:
module VesselUnits
# Names exported from this package
export inch, mm, lb, kg, lbf, °F, °C, psi, MPa, kPa, bar, atm, STEEL_DENSITY
# Use registry tools for convenience functions
using FlexUnits.RegistryTools
import ..set_preferred_unit, ..display_simplified_units
# Define your unit registry as a dictionary
const UNITS = PermanentDict{Symbol,Units{Dimensions{FixRat32},AffineTransform{Float64}}}()
# Add units and register new ones directly to UNITS
registry_defaults!(UNITS)
register_unit!(UNITS, "atm" => 101.325 * UNITS[:kPa])
# Define your preferred units directly as a vector (replace with what you want)
const PREFERRED_UNITS = [UNITS[u] for u in [:F, :H, :T, :Ω, :V, :W, :J, :Pa, :N, :C, :L]]
# Use the macro to create your preferred units and string macros
@generate_unit_simplifier(PREFERRED_UNITS)
@generate_registry_exports(UNITS)
# Now that macros are generated, define selected units in namespace
const inch = u"inch" # Imperial Length
const mm = u"mm" # Metric Length
const lb = u"lb" # Imperial Mass
const kg = u"kg" # Metric Mass
const lbf = u"lbf" # Imperial Force
# N is too common # Metric Force
const °F = u"°F" # Imperial Temperature
const °C = u"°C" # Metric Temperature
const psi = u"psi" # Imperial Pressure
const MPa = u"MPa" # Metric Pressure
const kPa = u"kPa" # Alternate Metric Pressure
const bar = u"bar" # Alternate Metric Pressure
const atm = u"atm" # Alternate Metric Pressure
# Define important constants in namespace
const STEEL_DENSITY = 0.28lb/inch^3
# Set preferred units for simplification (can also do this when defining PREFERRED_UNITS)
set_preferred_unit(inch)
set_preferred_unit(lb)
set_preferred_unit(lbf)
set_preferred_unit(psi)
set_preferred_unit(lb/inch^3)
#This sets the global constant to simplify units when displaying results (needs to be imported)
display_simplified_units(true)
end
Now it does what you want
julia> using .VesselUnits
julia> STEEL_DENSITY * 1inch^3
0.28 lb
julia> 3lbf / 1inch^2
2.9999977328476604 psi
Unfortunately, you can’t set affine units as a preferred unit, because compound affine units actually doesn’t make sense at a fundamental level. For example, people write heat capacities as “btu/(lb*°F)” but you never divide or multiply by “°F” directly. You divide or multiply by a difference which implicitly converts your temperatures to “°Ra”. So if you’re being pedantically correct (which computers require you to be), heat capacity is actually “btu/(lb*°Ra)”. You actually cannot even call u"J/(lb*°F)" (btu isn’t registered by default because there’s different definitions) because the operation isn’t allowed on affine units, so you cannot simplify to something like this.