NCAR / ccpp-framework

Common Community Physics Package (CCPP)
http://www.dtcenter.org/community-code/common-community-physics-package-ccpp/
Other
26 stars 62 forks source link

Need mechanism to support equivalent units #570

Open nusbaume opened 3 weeks ago

nusbaume commented 3 weeks ago

Description

There are situations where two sets of units are mathematically equivalent even though the actual units text might be different (for example m2 s-2 and J kg-1). Currently this results in an error being thrown stating that units don't match, but it would be nice for the framework to instead recognize that the units are actually equivalent and let the cap generation continue.

Solution

Ideally it might be good to have a dictionary somewhere that indicates which units are equivalent to each other. Then the dictionary can be queried to see if the "different" units are okay, or if they are in fact a mismatch.

Alternatives (optional)

A simpler alternative could be to just add a new no-op unit conversion for each one of these equivalent pairs (e.g. just multiply the units by one). This would avoid having to add any new infrastructure to the framework itself beyond just the new unit conversion function.

gold2718 commented 3 weeks ago

Another alternative would be to add the conversion to unit_conversion.py but have the conversion return an empty string for both the forward and reverse transforms. Then, modify has_unit_transforms to detect this and return False for this case. This might be as easy as just changing the return statement to:

return self.__unit_transforms is not None and self.__unit_transforms[0]
dustinswales commented 3 weeks ago

@gold2718 I like that idea. Nice and neat. See https://github.com/NCAR/ccpp-framework/pull/571