AguaClara / aguaclara

An open-source Python package for designing and performing research on AguaClara water treatment plants.
https://aguaclara.github.io/aguaclara/
MIT License
24 stars 13 forks source link

Array Multiplication & Division in `pc.re_pipe` #321

Open WPennock opened 2 years ago

WPennock commented 2 years ago

I have been inputting 8-element long arrays for diameter and flow rate into pc.re_pipe. When I do this, I get an (8, 8, 1) matrix. If I then switch from a single value of kinematic viscosity to 8, I get an (8, 8, 8) matrix. I can't figure out what's going wrong, since when I write out the operation that is written in the code for pc.re_pipe, I get a single (8,) array. This phenomenon throws off all dependent functions (e.g., fric_pipe).

I will show the error here:


D = [0.30, 0.20, 0.20, 0.20, 0.20, 0.20, 0.20, 0.25]*u.m 
Q_0 = [0.20, 0.10, 0.10, 0.05, 0.05, 0.10, 0.20, 0.25]*u.m**3/u.s
nu = 1E-6*u.m**2/u.s

print(np.shape((4 * Q_0) / (np.pi * D * nu)))

print(np.shape(ac.fric_pipe(Q_0,D,nu,eps)))

and this returns


(8,)
(8, 8, 1)
HannahSi commented 2 years ago

Hi @WPennock! Apologies for the late response to your issue. What you're seeing is the result of a function with the utility.list_handler() decorator above it (or, in the source code, @ut.list_handler()). This decorator was added to many functions in the aguaclara package to emulate NumPy functions that can either take in scalar inputs and produce scalar outputs or take in vector inputs and produce vector outputs (so giving a function a list of values is similar to calling the function on each value and storing the outputs in a list). When multiple inputs are lists, the result is a multidimensional array. There's a more thorough explanation in the documentation here.

The functionality isn't very well documented, and I don't blame you for being confused. What do you need to pass 8-element arrays into pc.re_pipe for? What kind of output do you need?