CalebBell / fluids

Fluid dynamics component of Chemical Engineering Design Library (ChEDL)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Units issue in some Crane methods

apwebb opened this issue · comments

Hi Caleb,

I ran into an issue using pint units with certain Crane fittings methods, which required me to convert to meters and strip the magnitude out.

K_gate_valve_Crane, K_globe_valve_Crane , bend_rounded_Crane gave me the issues, but there may be others. All three raised a ValueError that traces back to friction.ft_Crane(D) line 1847, which compares the input diameter to 1e-2 as a float.

I'm willing to give a shot at fixing this myself as it's a tiny issue, but I have 0 idea how GitHub works. Do I make a pull request? Then test out some ways to fix the issue in an environment on my machine, then...what?

BTW I am using fluids for some heating coil and hydraulic circuit design using a heat transfer fluid. It is working quite nicely with some custom fits to the fluid manufacturer's tabulated property data.

Hi apwebb,

At first I thought this was a cannot-reproduce bug; but you revealed just enough for me to realize what the issue was.

When I make unit-wrapped functions in the fluids.units module, I traverse through all the functions and objects in the various modules in fluids. The modules like fluids.friction are exposed in fluids.units, so you could do fluids.units.friction.ft_Crane - but you end up pointing to the non-unit aware function, which raises the error.

To fix your issue, just don't use functions from their modules; use fluids.units.K_globe_valve_Crane instead.

I could make it so the modules are not exposed; if you'd like to try a pull request, you could make that change to fluids/units.py (around line 400):

for name in dir(fluids):
	if 'RectangularOffsetStripFinExchanger' in name:
		continue
	if 'ParticleSizeDistribution' in name:
		continue
	obj = getattr(fluids, name)
	if isinstance(obj, types.FunctionType):
		obj = wraps_numpydoc(u)(obj)
	elif type(obj) == type:
		obj = wrap_numpydoc_obj(obj)
	elif type(obj) is types.ModuleType:
		# Functions accessed with the namespace like friction.friction_factor
		# would call the original function - that's no good
		continue
	elif isinstance(obj, str):
		continue
	if name == '__all__':
		continue
	__all__.append(name)
	__funcs.update({name: obj})

Here's a guide to the process:
https://www.thinkful.com/learn/github-pull-request-tutorial/#Time-to-Submit-Your-First-PR

Cheers,
Caleb

Thanks Caleb, I hadn't paid enough attention to the docs and didn't realize there was a module of unit-wrapped functions! I did wonder why in some examples you had imported fluids.units and others just fluids, and why sometimes I had to strip units and other times add them manually. When half my code broke this morning switching from
import fluids as fl
to
import fluids.units as fl
fixing those issues made it clearer what was going on under the hood

I'll give a shot at this PR over the weekend, would be good to understand the inner workings of how python modules go.

Fixed in release 0.1.74!
If you find any other rough edges, please do feel free to submit a PR.