“内核死了,重新启动”在spyder,jupyter和代码中没有在atom中工作

时间:2018-05-09 17:14:54

标签: python kernel spyder

我的代码工作正常,然后我再次运行它,代码完成在atom中运行但图像不会弹出。所以我尝试了spyder和jupyter,但在两者中都收到了“内核死了,重启”的错误信息。我尝试了其他问题中提到的一些事情,但没有任何效果。我更新了anaconda导航仪。我对计算机一般没有太多经验,我不确定下一步是什么。我正在运行Python 3.6。非常感谢任何帮助,谢谢。

编辑:添加代码

edit2:解决了,我的代码错了(当然),而不是python:D

   #CIE4365-16
#Assignment 1 - Heat flow
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as spin
from collections import namedtuple
#grid/discretization

def topTbound(t, bPar):
    '''Temperature for top boundary, where t is time'''
    boundT = bPar.avgT - bPar.rangeT * np.cos(2 * np.pi * (t - bPar.tmin) / 365.25)
    return boundT

def heatflux(t, T, sPar, mDim, bPar):
    boundT = topTbound(t, bPar) #temperature for top boundary funtion
    locT = T.copy() #copies T, doesn't change T in the original, can now change it here
    locT[mDim.nin-2, 0] = boundT  #setting the boundary Temperature
    q = np.zeros((mDim.nin, 1)) # ,1 to make it a column
    for i in range(1, mDim.nin-1):
        q[i, 0] = - sPar.lambdaIN[i, 0] * (locT[i, 0] - locT[i - 1, 0]) / mDim.dzn[i - 1, 0]
    # Robin boundary at the top
    q[mDim.nin - 1, 0] = - bPar.kRobinTop * (boundT - T[mDim.nin - 2, 0])
    #q[nin - 1, 0] = q[nin-2, 0] #setting the top
    q[0, 0] = 0 #to show that the bottom layer has no flow, so q must be zero
    return q

#divergence of heatflux through nodes
def divheatflux(t, T, sPar, mDim, bPar):
    locT = T.copy().reshape(nn, 1)
    qH = heatflux(locT, t, sPar, mDim, bPar) #heatflux equation defined earlier
    divqH = np.zeros((mDim.nn, 1))
    for i in range(0, mDim.nn):
        divqH[i, 0] = -(qH[i + 1, 0] - qH[i, 0]) / (mDim.dzin[i, 0] * sPar.zetaBN[i, 0])
    divqHRet = divqH.reshape(mDim.nn)
    return divqHRet

#reshape to columns so it is a vertical profile
depth = -15
dz = 0.1 #distance between internode layers
nin = 151 #number of internodes
nn = nin - 1 #number of nodes is always one less that number of internodes

#zin is the internodes boundaries depth location
zin = np.arange(depth, 0 + dz, dz).reshape(nin, 1)
#nr, nc = np.shape(zin)  #nr (number of rows) is the number of internodes

#number of nodes, will be filled by the for loop
zn = np.zeros([nin-1, 1])
for i in range(0, len(zn)):
    zn[i] = (zin[i, 0] + zin[i+1, 0]) / 2
zn[0, 0] = zin[0, 0]  #this is to change the first value in the array from 0 to -10
zn[len(zn)-1] = zin[len(zin)-1] #this is to change the last value in the array from -0.25 to 0

#dzn will be the distance between the node
dzn = np.zeros([len(zn)-1, 1])
for i in range(0, len(zn)-1):
    dzn[i, 0]=zn[i, 0]-zn[i+1, 0]
#dzn = np.reshape(dzn, ((nin - 2), 1))

#dzin will be the distance between the internodes
dzin = np.zeros(len(zin)-1)
for i in range(0, len(dzin)):
    dzin[i]=zin[i]-zin[i+1]
dzin = np.reshape(dzin, ((nin-1), 1))

#use namedtuple to put dimensions in same place
modDim = namedtuple('ModDim',['zn', 'zin', 'dzn', 'dzin', 'nn' , 'nin'])
mDim = modDim(zn=zn,zin=zin,dzn=dzn,dzin=dzin,nn=nn,nin=nin)

#Properties of the soil
zetasolid = 2.235e6  # [J m^-3 K^-1] volumetric heat capacity of solid
zetawater = 4.154e6  # [J m^-3 K^-1] volumetric heat capacity of water
qu = 0.75  # quartz content
sw = 0 #sw is the water saturation

rhowater = 1000  # [kg/m^3] density of water
rhosolid = 2650  # [kg/m^3] density of solid
rhobulk = 1700  # [kg/m^3] dry bulk density of soil
p = (1 - rhobulk) / rhosolid  # [-] porosity of soil = saturated water content.
lambdaQuartz = 6  # [W/(mK)] thermal conductivity of quartz

#combine soil parameters in one place
soilPar = namedtuple('soilPar',['zetaBN','lambdaIN'])
sPar = soilPar(zetaBN = np.ones(np.shape(zn)) * ((1 - p) * zetasolid + p * zetawater * sw),
               lambdaIN = np.ones(np.shape(zin)) * lambdaQuartz * (24 * 3600))

# boundary parameters
boundPar = namedtuple('boundPar',['avgT', 'rangeT', 'tmin', 'kRobinTop', 'kRobinBot'])
bPar = boundPar(avgT = 283, rangeT = 15, tmin = 46, kRobinTop = 1, kRobinBot = 0)

# Initial Conditions
Tini = np.ones(np.shape(zn)) * (283)  # degrees K

tOut = np.linspace(0, 365.25 * 10, 365)  # time, *10 = 10 years, steps per day
nOut = np.shape(tOut)[0]

T0 = Tini.copy().squeeze()
t_span = [tOut[0], tOut[-1]]
#TODE = spin.solve_ivp(divheatflux, t_span, T0, sPar, mDim, bPar,
#                      method='RK45', t_eval=tOut, vectorized=True, rtol=1e-5)
TODE = spin.odeint(divheatflux, tOut, T0, args = (sPar,mDim,bPar))
for i in range(0, nOut-1):
    TODE[i, nn - 1] = topTbound(tOut[i], bPar)

#plotting
plt.close('all') #closing the previous plots
fig1, ax1 = plt.subplots(figsize=(9,4))
ax1.plot(tOut,TODE[:, 0:nn-1:20], '.-')
ax1.set_title('Temperature')

fig2, ax2 = plt.subplots(figsize=(5,8))

for i in np.arange(0, nOut-1, 10):
   ax2.plot(TODE[i, :], zn.squeeze(),'-')

ax2.set_title('Temperature vs. depth')
plt.show()

0 个答案:

没有答案