|
|
腼腆的饭卡 · yml配置文件特殊字符处理_yml中的特殊字 ...· 3 年前 · |
|
|
爱健身的显示器 · VBA数组用法-简易实例_51CTO博客_v ...· 3 年前 · |
|
|
坚强的稀饭 · QListWidget的QComboBox下 ...· 3 年前 · |
|
|
才高八斗的哑铃 · java - problem might ...· 3 年前 · |
|
|
独立的奔马 · GitHub 1W star ...· 3 年前 · |
Describe the issue:
I am encountering a TypeError when using np.sqrt in my calculations specifically with the variable densidad2 . The error message indicates that the operation does not support the argument type of Float. This issue arises only when trying to calculate the square root using densidad2 , while similar calculations with densidad 1 work correctly.
The error occurs in line 262 (jupyter notebook exported as .py because github, doesn't allow .ipynb)
Dm2 = np.sqrt(np.abs(gasto/(ratio*np.pi*(densidad2)*w2*np.cos(beta2))))is changed toDm2 = np.sqrt(np.abs(gasto/(ratio*np.pi*float (densidad2)*w2*np.cos(beta2))))works.Reproduce the code example:
import numpy as np import sympy as sp import matplotlib . pyplot as plt from termcolor import colored import sys import numpy as np print ( "Versión de Python:" , sys . version ) print ( "Versión de Numpy:" , np . __version__ ) # %% [markdown] # # Problema de compresor axial (examen 30-11-2016) """Declaración de constantes""" P0 = 1.85 T0 = 465 Mr0 = 0.67 gamma = 1.4 R = 287 coeficiente_parada_estator = 4.1 / 100 coeficiente_parada_rotor = 4.09 / 100 Cp = 1005 """Inicio del ejercicio""" a1 = sp . sqrt ( T0 * gamma * R ) w1 = Mr0 * a1 print ( 'w1' , w1 ) alfa1 = np . deg2rad ( 36.2 ) alfa2 = np . deg2rad ( 49.1 ) c1 = 230.5 c2 = 326.6 u1 = 357.9 u2 = 411.4 c1u = c1 * np . sin ( alfa1 ) print ( 'c1u' , c1u ) c2u = c2 * np . sin ( alfa2 ) print ( 'c2u' , c2u ) W = c1u * u1 - c2u * u2 print ( 'Trabajo W[J]' , W ) perdidas_rotor = coeficiente_parada_rotor * w1 ** 2 / 2 print ( 'pedidas rotor' , perdidas_rotor ) perdidas_estator = coeficiente_parada_estator * c2 ** 2 / 2 print ( 'perdidas estator' , perdidas_estator ) eficiencia = ( np . abs ( W ) - perdidas_estator - perdidas_rotor ) / np . abs ( W ) print ( 'trabajo eficiencia:' , eficiencia ) Ws = np . abs ( W ) - perdidas_estator - perdidas_rotor print ( 'trabajo isentrópico:' , Ws ) #Cálculo de las variables termodinámicas: T1 = T0 print ( f'Temperataura a la entrada (dato): { T1 } K' ) T1t = T1 + c1 ** 2 / ( 2 * Cp ) print ( f'T1t: { T1t } K' ) T1rt = T1 + w1 ** 2 / ( 2 * Cp ) print ( f'T1t: { T1rt } K' ) T2r_prima = T1rt print ( f'T2r_prima: { T2r_prima } K' ) T2rt = T2r_prima + ( u2 ** 2 - u1 ** 2 ) / ( 2 * Cp ) print ( f'T2rt: { T2rt } K' ) T2t = - W / ( 2 * Cp ) + T1t print ( f'T2t: { T2t } K' ) T2 = T2t - c2 ** 2 / ( 2 * Cp ) print ( f'T2: { T2 } K' ) T3t = T2t print ( f'T3t: { T3t } K' ) c3 = c1 #Escalonamiento de repetición T3 = T3t - c3 ** 2 / ( 2 * Cp ) print ( f'T3: { T3 } K' ) # T_3 = T_{3t} - \frac{c_3^2}{2c_p} = T_{3t} - \frac{c_1^2}{2c_p} = 517.6 \, \text{K} # p_{1t} = p_1 \left( \frac{T_1}{T_{1t}} \right)^{\frac{\gamma}{\gamma - 1}} = 2.245 \, \text{bar} # p_{1tR} = p_1 \left( \frac{T_1}{T_{1tR}} \right)^{\frac{\gamma}{\gamma - 1}} = 2.500 \, \text{bar} # p_{1tR}' = p_{1tR} - \rho_1 \omega R \frac{w_1^2}{2} = p_{1tR} - \frac{p_1}{RT_1} \omega R \frac{w_1^2}{2} = 2.476 \, \text{bar} # p_{2tR} = p_{1tR} \left( \frac{T_{1tR}}{T_{2tR}} \right)^{\frac{\gamma}{\gamma - 1}} = 2.844 \, \text{bar} # p_2 = p_{2tR} \left( \frac{T_{2tR}}{T_2} \right)^{\frac{\gamma}{\gamma - 1}} = 2.216 \, \text{bar} # p_{2t} = p_{2t} \left( \frac{T_2}{T_{2t}} \right)^{\frac{\gamma}{\gamma - 1}} = 3.175 \, \text{bar} # p_{3t} = p_{2t} - \rho_2 \omega E \frac{c_2^2}{2} = p_{2t} - \frac{p_2}{RT_2} \omega E \frac{c_2^2}{2} = 3.140 \, \text{bar} # %% [markdown] # # Problema de turbina axial (examen 30-11-2016) # Se tiene un escalonamiento de repetición de turbina como el de la figura. La presión y temperatura estáticas de entrada al rotor son 36.8 bar y 428 K. En las condiciones de diseño el mach absoluto de salida estator vale 0.77. El fluido es un gas perfecto con γ # =1.33 y R= 287 J/kgK. Se pide: """Declaración de constantes""" P1 = 36.8 T1 = 428 M1 = 0.77 gamma = 1.33 R = 287 Cp = 1005 # %% [markdown] # a) Dibujar en el anverso de esta hoja los perfiles de los álabes, indicando cual es estátor y cuál rotor y hacia donde se movería el rotor. Dibujar las cascadas con una solidez de 1. Obtener el valor de u1 y u2. Razonar si el escalonamiento es óptimo. c1 = M1 * np . sqrt ( gamma * R * T1 ) print ( f'c1: { c1 } m/s' ) alfa1 = np . deg2rad ( 55.4 ) w1 = 176.8 beta1 = np . deg2rad ( 2 ) u1 = 250 c2 = 164.6 alfa2 = np . deg2rad ( 12.4 ) w2 = 250.6 beta2 = np . deg2rad ( - 50 ) u2 = 227.5 c1u = c1 * np . sin ( alfa1 ) print ( 'c1u' , c1u ) c2u = c2 * np . sin ( alfa2 ) print ( 'c2u' , c2u ) W = c1u * u1 - c2u * u2 print ( 'Trabajo W[J]' , W ) resultado = ( c1 ** 2 - c2 ** 2 ) / 2 - ( w1 ** 2 - w2 ** 2 ) / 2 + ( u1 ** 2 - u2 ** 2 ) / 2 print ( resultado ) display ( np . abs ( W - resultado ) / W * 100 ) print ( " \n Summary of all velocities and angles used:" ) print ( f"c1 = { c1 :.2f } m/s" ) print ( f"alfa1 = { np . rad2deg ( alfa1 ):.2f } degrees" ) print ( f"w1 = { w1 :.2f } m/s" ) print ( f"beta1 = { np . rad2deg ( beta1 ):.2f } degrees" ) print ( f"u1 = { u1 :.2f } m/s" ) print ( f"c2 = { c2 :.2f } m/s" ) print ( f"alfa2 = { np . rad2deg ( alfa2 ):.2f } degrees" ) print ( f"w2 = { w2 :.2f } m/s" ) print ( f"beta2 = { np . rad2deg ( beta2 ):.2f } degrees" ) print ( f"u2 = { u2 :.2f } m/s" ) # %% [markdown] # b) Estimar el trabajo, las pérdidas, el rendimiento y la relación de presiones total a total. Sabiendo que los coeficientes de pérdida de energía cinética en rotor y estator valen 5.63% y 5.11% respectivamente. coeficiente_perdida_rotor = 5.63 / 100 coeficiente_perdida_estator = 5.11 / 100 perdidas_estator = coeficiente_perdida_estator * c1 ** 2 / 2 perdidas_rotor = coeficiente_perdida_rotor * w2 ** 2 / 2 display ( perdidas_estator ) display ( perdidas_rotor ) print ( colored ( 'Temperaturas:' , "blue" , attrs = [ "bold" ])) T1t = T1 + c1 ** 2 / ( 2 * Cp ) print ( f'T1t: { T1t } k' ) T0t = T1t print ( f'T0t: { T0t } k' ) c0 = c2 #Escalonamiento de repeticion T0 = T0t - c0 ** 2 / ( 2 * Cp ) print ( f'T0: { T0 } k' ) T1tr = T1 + w1 ** 2 / ( 2 * Cp ) print ( f'T1tr: { T1tr } k' ) T2r_prima = T1 print ( f'T2r_prima: { T2r_prima } k' ) T2t = T0t - W / Cp print ( f'T2t: { T2t } k' ) T2 = T2t - c2 ** 2 / ( 2 * Cp ) print ( f'T2: { T2 } k' ) #velocidades isentrópicas, las necesitamos para calcular las temperaturas isentrópicas: print ( colored ( 'velocidades isentrópicas, las necesitamos para calcular las temperaturas isentrópicas:' , 'cyan' )) c1s = c1 * np . sqrt ( coeficiente_perdida_estator + 1 ) print ( f'c1s: { c1s } m/s' ) w2s = w2 * np . sqrt ( coeficiente_perdida_rotor + 1 ) print ( f'w2s: { w2s } m/s' ) T1s = T1t - c1s ** 2 / ( 2 * Cp ) print ( f'T1s: { T1s } k' ) T2tr = T2 + w2 ** 2 / ( 2 * Cp ) print ( f'T2tr: { T2tr } k' ) T2s = T2rt - w2s ** 2 / ( 2 * Cp ) print ( f'T2s: { T2s } k' ) #Presiones print ( colored ( 'Presiones' , "green" , attrs = [ "bold" ])) print ( f"P1: { P1 } bar" ) P1s = P1 print ( f"P1s: { P1s } bar" ) P0t = P1s * ( T1s / T0 ) ** ( gamma / ( 1 - gamma )) print ( f"P0t: { P0t } bar" ) P0 = P0t * ( T0t / T0 ) ** ( gamma / ( 1 - gamma )) print ( f"P0: { P0 } bar" ) P2s = P1 * ( T1 / T2s ) ** ( gamma / ( 1 - gamma )) print ( f"P2s: { P2s } bar" ) P2 = P2s print ( f"P2: { P2 } bar" ) P2t = P2 * ( T2 / T2t ) ** ( gamma / ( 1 - gamma )) print ( f"P2t: { P2t } bar" ) # %% [markdown] # c) Calcular la altura de los álabes gasto = 65 #kg/s ratio = 0.1 densidad1 = ( P1 * 1e5 ) / ( R * T1 ) print ( 'densidad 1:' , densidad1 ) Dm1 = np . sqrt ( gasto / ( ratio * np . pi * densidad1 * w1 * np . cos ( beta1 ))) print ( 'Dm1:' , Dm1 ) H1 = ratio * Dm1 print ( 'H1' , H1 ) densidad2 = ( P2 * 1e5 ) / ( R * T2 ) print ( 'densidad 2:' , densidad2 ) Dm2 = np . sqrt ( np . abs ( gasto / ( ratio * np . pi * ( densidad2 ) * w2 * np . cos ( beta2 )))) print ( 'Dm2:' , Dm2 ) H2 = ratio * Dm2 print ( 'H2' , H2 )Error message:
" name " : " TypeError " , " message " : " loop of ufunc does not support argument 0 of type Float which has no callable sqrt method " , " stack " : " --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) AttributeError: 'Float' object has no attribute 'sqrt' The above exception was the direct cause of the following exception: TypeError Traceback (most recent call last) Cell In[297], line 12 10 densidad2 = (P2*1e5)/(R*T2) 11 print('densidad 2:', densidad2) ---> 12 Dm2 = np.sqrt(np.abs(gasto/(ratio*np.pi*(densidad2)*w2*np.cos(beta2)))) 13 print('Dm2:', Dm2) 14 H2 = ratio * Dm2 TypeError: loop of ufunc does not support argument 0 of type Float which has no callable sqrt method "Python and NumPy Versions:
Python: 3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)]
Numpy: 1.26.4
Runtime Environment:
No response
Context for the issue:
This issue represents an unexpected inconsistency in the behavior of NumPy's mathematical operations. While the calculation with
densidad1proceeds without any errors, the failure to compute the square root ofdensidad2raises questions about the conditions under which these functions operate.Such inconsistencies can be challenging to troubleshoot and may lead to confusion, especially in scientific and engineering applications where accuracy is essential. As NumPy is widely used for numerical computations, addressing this issue would enhance its reliability and ensure that users can trust the results of their calculations, thereby facilitating smoother workflows and better overall user experience. Prioritizing the resolution of this matter would contribute to maintaining the high standards expected from this essential library.