The array return by func must be one-dimensional, but got ndim=2. How can we rectify the error

235 Views Asked by At

Please provide the solution for this code - The array return by func must be one-dimensional, but got ndim=2

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math
def scp(y,z):
dh=  0.07 #internal diameter(m)
tk = 0.002 #thickness of the absorber tube(m)
do = dh+ 2*tk #outer diamater of the absorber tube
kat = 45 #thermal conductivity of the absorber tube 
usDPE =0.5 #velocity of the diphenyl-ether (m/s)
I = 800 #global insolation (W/m2K)
Cr = 25 #concentration ratio
nuo = 0.785 #optical efficiency
epsr = 0.095 #emissivity of the solar selcective coating
sigm =5.67*10**-8 #Stefan Boltzann constant
Pat= math.pi*dh #perimeter of the tube 
Tsurr = 293
Tht=y[0]  
B1=0.2336 
B2=120.57
B3=-147.33
B4=7E-07 
CpDPE=(1/(B1+(B2/Tht)+(B3/Tht**2)+(B4*Tht)))*1000 #Specific heat coefficient J/kgK
B5=1.33718
B6=-0.9233E-03
B7=-0.08992E-06 
rhoDPE=(B5+(B6*Tht)+(B7*(Tht)**2))*1000  #Specific heat coefficient kg/m3
B8=0.0451
B9=0.0034
kDPE=B8*math.exp(B9*Tht) #Thermal conductivity of DPE (W/m.K)
D=4.832
mu0=0.063
T0=136.7
muDPE=math.exp(math.log(mu0)+((D*T0)/(Tht-T0)))/1000 #viscosity of DPE (kg/m.s)
ReDPE=(dh*usDPE*rhoDPE)/muDPE #Reynolds number of DPE
PrDPE=(CpDPE*muDPE)/kDPE #Prandtl number of DPE
NuDPE=0.023*ReDPE**0.8*PrDPE**0.4 #Nusselt number of DPE
hj=(NuDPE*kDPE)/dh #heat transfer coefficent of fluid
Uo= (hj*kat)/(kat+(tk*hj)) #Overall heat transfer coefficent of fluid
At= ((math.pi)/4)*dh**2 #Area of the tube
mDPE = rhoDPE*usDPE*At #mass flow rate of DPE
ppar = [(epsr*sigm),0,0,Uo,-(I*Cr*nuo+(Uo*Tht)+(epsr*sigm*Tsurr**4))]
Tw = np.roots(ppar)
Tw1=Tw[3:4]
Tw2=abs(Tw1)
print(Tw2)
dThtdz= (-(4/do)*Uo*(Tht-Tw2))/(rhoDPE*usDPE*CpDPE)
return [dThtdz]
y0 = 563
# length points
z=np.linspace(0,50,1000)
# solve ODE
y = odeint(scp,y0,z,rtol=None,atol=None)
Tht=y[:,0]
plt.figure(1)
plt.plot(z,Tht)
plt.xlabel('length')
plt.ylabel('Heat transfer fluid temperature (K)')
1

There are 1 best solutions below

1
darth baba On

scipy.integrate.odeint accepts a callable that returns the derivative of y at t and this should be a value that is a single dimension array. So don't return a list from this function.

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import math
def scp(y,z):
    dh=  0.07 #internal diameter(m)
    tk = 0.002 #thickness of the absorber tube(m)
    do = dh+ 2*tk #outer diamater of the absorber tube
    kat = 45 #thermal conductivity of the absorber tube 
    usDPE =0.5 #velocity of the diphenyl-ether (m/s)
    I = 800 #global insolation (W/m2K)
    Cr = 25 #concentration ratio
    nuo = 0.785 #optical efficiency
    epsr = 0.095 #emissivity of the solar selcective coating
    sigm =5.67*10**-8 #Stefan Boltzann constant
    Pat= math.pi*dh #perimeter of the tube 
    Tsurr = 293
    Tht=y[0]  
    B1=0.2336 
    B2=120.57
    B3=-147.33
    B4=7E-07 
    CpDPE=(1/(B1+(B2/Tht)+(B3/Tht**2)+(B4*Tht)))*1000 #Specific heat coefficient J/kgK
    B5=1.33718
    B6=-0.9233E-03
    B7=-0.08992E-06 
    rhoDPE=(B5+(B6*Tht)+(B7*(Tht)**2))*1000  #Specific heat coefficient kg/m3
    B8=0.0451
    B9=0.0034
    kDPE=B8*math.exp(B9*Tht) #Thermal conductivity of DPE (W/m.K)
    D=4.832
    mu0=0.063
    T0=136.7
    muDPE=math.exp(math.log(mu0)+((D*T0)/(Tht-T0)))/1000 #viscosity of DPE (kg/m.s)
    ReDPE=(dh*usDPE*rhoDPE)/muDPE #Reynolds number of DPE
    PrDPE=(CpDPE*muDPE)/kDPE #Prandtl number of DPE
    NuDPE=0.023*ReDPE**0.8*PrDPE**0.4 #Nusselt number of DPE
    hj=(NuDPE*kDPE)/dh #heat transfer coefficent of fluid
    Uo= (hj*kat)/(kat+(tk*hj)) #Overall heat transfer coefficent of fluid
    At= ((math.pi)/4)*dh**2 #Area of the tube
    mDPE = rhoDPE*usDPE*At #mass flow rate of DPE
    ppar = [(epsr*sigm),0,0,Uo,-(I*Cr*nuo+(Uo*Tht)+(epsr*sigm*Tsurr**4))]
    Tw = np.roots(ppar)
    Tw1=Tw[3:4]
    Tw2=abs(Tw1)
    print(Tw2)
    dThtdz= (-(4/do)*Uo*(Tht-Tw2))/(rhoDPE*usDPE*CpDPE)
    return dThtdz

y0 = 563
# length points
z=np.linspace(0,50,1000)
# solve ODE
y = odeint(scp,y0,z,rtol=None,atol=None)
Tht=y[:,0]
plt.figure(1)
plt.plot(z,Tht)
plt.xlabel('length')
plt.ylabel('Heat transfer fluid temperature (K)') 

I removed the list when you return dThtdz