Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plotting problem
#1
Hello

(I'm new to Python)
Im trying to plot 4 functions with quite some variables, however in the end it's only dependent on x.
My code:
import numpy as np
import math
import CoolProp.CoolProp as CoolProp
import matplotlib.pyplot as plt
import sympy as sym
from sympy.abc import x   #python laten weten dat x een variabele is

#ingeven variabelen
D = 0.04 ;    #tube diameter in m
A = (D/2)**2*math.pi;  # cross section area in m²
G = 0.1/A;  # mass velocity of liquid + vapor in kg/m²s
g = 9.81;
q= 10000;  #local heat flux in W/m²
S = 0.8;
p = 101300;
M = 102.03;
#eigenschappen R134a
rho_V = CoolProp.PropsSI('D','T',273.15+10,'Q',1,'R134a');
rho_L = CoolProp.PropsSI('D','T',273.15+10,'Q',0,'R134a');
mu_L = CoolProp.PropsSI('V','T',273.15+10,'Q',0,'R134a');
mu_V = CoolProp.PropsSI('V','T',273.15+10,'Q',1,'R134a');
sigma = 10.03;   #surface tension
h_V = CoolProp.PropsSI('H','P', 101300,'Q',1,'R134a');
h_L = CoolProp.PropsSI('H','P', 101300,'Q',0,'R134a');
h_LV= h_V - h_L; #latent heat of vaporisation
c_pV = CoolProp.PropsSI('CPMOLAR','Q',1, 'T', 273.15+10,'R134a');
c_pL = CoolProp.PropsSI('CPMOLAR','Q',0, 'T', 273.15+10,'R134a');
lambda_V = CoolProp.PropsSI('L','Q',1, 'T', 273.15+10,'R134a');
lambda_L = CoolProp.PropsSI('L','Q',0, 'T', 273.15+10,'R134a');
Pr_V = CoolProp.PropsSI('PRANDTL','Q',1, 'T', 273.15+10,'R134a');
#bepalen nodige waarden

epsilon = x/rho_V*((1+0.12*(1+x))*(x/rho_V+(1-x)/rho_L)+1.18*(1-x)*(g*sigma*(rho_L-rho_V))**0.25/(G*rho_L**0.5))**-1
theta_strat = 2*math.pi - 2*(math.pi*(1-epsilon)+(3*math.pi/2)**1/3*(1-2*(1-epsilon)+(1-epsilon)**1/3-epsilon**1/3)-1/200*(1-epsilon)*epsilon*(1-2*(1-epsilon))*(1+4*((1-epsilon)**2+epsilon**2)));
A_LD = A*(1-epsilon)/D**2;
A_VD = A*epsilon/D**2;
h_LD = 0.5*(1-sym.cos((2*math.pi-theta_strat)/2))    #cos in radialen!!!!
q_crit = 0.131*rho_V**(1/2)*h_LV*(g*(rho_L-rho_V)*sigma)**(1/4);
Fr_V = G**2/(rho_V*(rho_L-rho_V)*g*D);
Fr_L = G**2/(rho_L**2*g*D);
We_L = G**2*D/(rho_L*sigma);
We_V = G**2*D/(rho_V*sigma);

#ingeven functies            x=vapor quality
G_strat = (226.3**2*A_LD*A_VD**2*rho_V*(rho_L - rho_V)*mu_L*g/(x**2*(1 - x)*math.pi**3))**(1/3);
G_wavy = (16*A_VD**3*g*D*rho_L*rho_V*(math.pi**2/(25*h_LD**2)*(We_L/Fr_L)**(-1) + 1)/(x**2*math.pi**2*((1 - (2*h_LD - 1)**2)**0.5)))**0.5 + 50;
G_dryout = (1/0.235*(sym.log(0.58/x) + 0.52)*(D/(rho_V*sigma))**-0.17*(1/g*D*rho_V*(rho_L - rho_V))**-0.37*(rho_V/rho_L)**-0.25*(q/q_crit)**-0.70)**0.926;
G_mist = (1/0.0058*(sym.log(0.61/x) + 0.57)*(D/(rho_V*sigma))**-0.38*(1/g*D*rho_V*(rho_L - rho_V))**-0.15*(rho_V/rho_L)**0.09*(q/q_crit)**-0.27)**0.943;

#x waarden overgang
x_IA = ((0.34**(1/0.875)*(rho_V/rho_L)**(-1/1.75)*(mu_L/mu_V)**(-1/7))+1)**(-1);
x_di = 0.58*math.exp(0.52-0.235*We_V**0.17*Fr_V**0.37*(rho_V/rho_L)**0.25*(q/q_crit)**0.7);
x_de = 0.61*math.exp(0.57-5.8*10**-3*We_V**0.38*Fr_V**0.15*(rho_V/rho_L)**-0.09*(q/q_crit)**0.27);

#plot flow pattern map
xas = np.linspace(0,1,11);
lam1 = sym.lambdify(x,G_strat);
lam2 = sym.lambdify(x,G_wavy);
lam3 = sym.lambdify(x,G_dryout);
lam4 = sym.lambdify(x,G_mist);
plt.plot(xas,lam1(xas));
plt.plot(xas,lam2(xas));
plt.plot(xas,lam3(xas));
plt.plot(xas,lam4(xas));
plt.show()
I get the error "TypeError: only length-1 arrays can be converted to Python scalars"
while plotting the 2nd function 'G_wavy'. I think it has something to do with the variable h_LD?

Any solution?

Thanks in advance!
Reply


Messages In This Thread
plotting problem - by TDW5 - Nov-01-2019, 11:54 AM
RE: plotting problem - by Larz60+ - Nov-01-2019, 04:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Floor division problem with plotting x-axis tick labels Mark17 5 2,132 Apr-03-2022, 01:48 PM
Last Post: Mark17
  problem in plotting intraday results using matplotlib mr_byte31 0 2,967 Aug-20-2018, 11:32 AM
Last Post: mr_byte31

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020