Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting different velocities in versions 0.9.0 and 0.10.0 #625

Open
dad616610 opened this issue May 19, 2024 · 5 comments
Open

Getting different velocities in versions 0.9.0 and 0.10.0 #625

dad616610 opened this issue May 19, 2024 · 5 comments

Comments

@dad616610
Copy link

dad616610 commented May 19, 2024

Consider the following example

Example

import pandapipes as pp

def main():
    net = pp.create_empty_network("network", fluid="lgas")

    pp.create_junctions(net, nr_junctions=2, pn_bar=1, tfluid_k=300)
    pp.create_pipe_from_parameters(net, from_junction=0, to_junction=1, length_km=0.1, diameter_m=0.2)
    pp.create_ext_grid(net, junction=0, p_bar=6)
    pp.create_sink(net, junction=1, mdot_kg_per_s=6)

    pp.pipeflow(net, mode="hydraulics", friction_model="colebrook")

    print(net.res_pipe)


if __name__ == "__main__":
    main()

Result in 0.9.0

   v_from_m_per_s  v_to_m_per_s  v_mean_m_per_s  p_from_bar  p_to_bar  \
0       41.008797     43.510454       42.211015         6.0  5.602638   

   t_from_k  t_to_k  mdot_from_kg_per_s  mdot_to_kg_per_s  vdot_norm_m3_per_s  \
0     300.0   300.0                 6.0              -6.0            8.246366   

       reynolds   lambda  normfactor_from  normfactor_to  
0  3.160386e+06  0.01971          0.15623        0.16576 

Result in 0.10.0

   v_from_m_per_s  v_to_m_per_s  v_mean_m_per_s  p_from_bar  p_to_bar  \
0       37.320712     39.376898       38.312616         6.0  5.639141

   t_from_k  t_to_k  mdot_from_kg_per_s  mdot_to_kg_per_s  vdot_norm_m3_per_s  \
0     300.0   300.0                 6.0              -6.0            7.504737

       reynolds    lambda  normfactor_from  normfactor_to
0  3.160386e+06  0.019722          0.15623       0.164837

As you can see the velocity is drastically changed. Is this intentional? Could this PR #597 be a velocity changer?

I used velocity to calculate the Reynolds number by hand using this formula:

$$Re = \frac{net.res\_pipe['v\_from\_m\_per\_s'] * pp.get\_fluid(net).get\_density(T) * net.pipe['diameter\_m']}{pp.get\_fluid(net).get\_viscocity(T) * net.res\_pipe['normfactor\_from']}$$

, where T is the initial temperature

The formula above in Python

T = 300
Re = (
    pp.get_fluid(net).get_density(T)
    * net.res_pipe["v_from_m_per_s"]
    / net.res_pipe["normfactor_from"]
    * net.pipe["diameter_m"]
    / pp.get_fluid(net).get_viscosity(T)
)

With version 0.9.0 the Reynolds numbers calculated by pandapipes and by hand matched. With version 0.10.0, however, the Reynolds numbers didn't match. The Reynolds numbers calculated by pandapipes are identical in versions 0.9.0 and 0.10.0

@dad616610 dad616610 changed the title Getting different velocities in 0.10.0 Getting different velocities in versions 0.9.0 and 0.10.0 May 19, 2024
@dlohmeier
Copy link
Collaborator

Hello @dad616610 ,
thanks for raising the issue. We will have a look at the given example. The new version with the PR you mentioned definitely changed some results, but I was not aware that it could be so drastic. I will let you know about my findings.
Kind regards!

@dlohmeier
Copy link
Collaborator

One aspect that comes to my mind is the tolerance. If you change the value of tol_res and tol_m to smaller values, does that change anything? It is a little harder to find a good compromise for the tolerance of the mass flow change for both gas and liquid media.

@dad616610
Copy link
Author

dad616610 commented May 21, 2024

Hello @dlohmeier

Thank you for your reply and a way to fix this

I've added a tol=1e-9 and changed pp.pipeflow in the code from the first message like this:

  pp.pipeflow(
      net,
      mode="hydraulics",
      friction_model="colebrook",
      tol_p=tol,
      tol_v=tol,
      tol_T=tol,
      tol_res=tol,
      tol_m=tol,
  )

The results didn't change (at all)

@j-zipplies
Copy link

j-zipplies commented Jul 23, 2024

What I noted, when I tried to reproduce: In the example 'fluid="water" ' is defined. To reproduce the given output, this must be changed to 'fluid="lgas" '.

@dlohmeier
Copy link
Collaborator

I found one important aspect of why the Reynolds numbers would not match as the temperature. In pandapipes 0.9.0 we made an error by using the fluid temperature for calculation, but when calculating the reynolds number based on norm velocity, you also need to use the norm density / norm temperature. If I use the norm density, I get the desired result.

tn = 273.15
Re_from = (
    pp.get_fluid(net).get_density(tn)
    * net.res_pipe["v_from_m_per_s"]
    / net.res_pipe["normfactor_from"]
    * net.pipe["diameter_m"]
    / pp.get_fluid(net).get_viscosity(T)
)[0]

Re_to = (
    pp.get_fluid(net).get_density(tn)
    * net.res_pipe["v_to_m_per_s"]
    / net.res_pipe["normfactor_to"]
    * net.pipe["diameter_m"]
    / pp.get_fluid(net).get_viscosity(T)
)[0]

print(Re_from, Re_to, net.res_pipe.at[0, "reynolds"])

For me, this all equals. Unfortunately, the error increases with differing temperatures from normal conditions, and probably also with decreasing norm factors (with a norm factor of 0.15, we are already quite far away from ideal gas behavior). This is why your example leads to such great differences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants