二维热方程-添加初始条件并检查Dirichlet边界条件是否正确

如何解决二维热方程-添加初始条件并检查Dirichlet边界条件是否正确

我对使用numpy和sympy库还是很陌生。抱歉,如果我在上面有很多打印件,我只是想检查代码是否正常工作。 我正在尝试解决这个2D热方程问题,并且在理解如何添加初始条件(温度为30度)和添加齐次Dirichlet边界条件(例如,板的两边(即顶部,底部和2面)。作为示例,我尝试将板顶部的温度添加为1000度,但出现错误“ IndexError:索引18超出轴18尺寸18的范围”。 我已经设法将函数添加到代码上,并且似乎也可以正常输出,但在添加条件上就有点丢失了。我试图在线查找类似的问题,但无法真正理解正在发生的事情。

以下是原始2D热方程的链接:https://drive.google.com/file/d/1q3KyfaHD7hZTbdIYc9_e5otusELqYJaD/view?usp=sharing

以下是用于明确的有限差分的最终方程的链接:https://drive.google.com/file/d/1unJHXO3b3xig8RhBen5k0eOg40YUfjyv/view?usp=sharing

i; j是位置(节点号),k =时间(时间步号)

我还试图找到温度达到稳定状态的时间

我已经添加了到目前为止完成的全部代码

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import sympy as sp
from sympy.solvers import solve
from sympy import Function,Symbol

#Length of workpiece
Lx= 0.05 #Length of work piece in the x direction,measured in meters (m)
Nx= 18 #Number of mesh points along the x-direction
Ly= 0.1 #Length of work piece in the y direction,measured in meters (m)
Ny= 9 #Number of mesh points along the y-direction
dy=Lx/Nx #distance between nodes in x
dx=Ly/Ny #distance between nodes in x

#Defining material properties
conduc= 16.26 #Conductivity of the material in (W/m (degrees)C)
rho= 8020 #Density of the material in (kg/m^3)
c=502 #Specific heat of the material (J/kg(degrees)C)

#Calculating the alpha (thermal diffusivity) for the plate,in (m^2/s)
a=((conduc)/(rho*c))
print (a)

t=215;
nt= 215; #number of steps wrt time
dt= t/nt; #timestep

#Define the mesh in space
x= np.linspace(1,Lx,Nx)[np.newaxis] #vector to create mesh
y= np.linspace(1,Ly,Ny)[np.newaxis]
x,y=np.meshgrid(x,y) #mesh grid function return
print (x,y)

T = np.ones(([Nx,Ny]))

#Adding the other conditions
T[Nx,:]= 1000 #Assining the temp for the top

sym= sp.symbols('i,j,k')
function = sp.Function('T(i,k)+(dt*a(((T(i+1,k)-2*T(i,k)+T(i-1,k))/(dx**2))+(a*dt(((T(i,j+1,k,k)+T(i,j-1,k))/dy**2)')
print(function)

更新:我已经将此添加到了代码中,并且这些似乎可行。但是,我注意到我的T = np.ones(([Nx,Ny]))是18 x 9,但是盘子在水平面上更长。这是否意味着我只需要翻转矩阵?

#Temperatures for the plate

Ttop=1000        # temp for the top side of the plate
Tbottom = 500   # temnp for the bottom side of the plate 
Tright = 500    #temp for the right side of the plate
Tleft = 1000   #temp for the left side of the plate

  
#Adding the boundaries on the system

T[:,0] = Ttop       #temp for the top
print (T[:,0])

T[:,-1] = Tbottom  #temp for bottom 
print (T[:,-1])

T[0,:] = Tright   #temp for the right
print (T[0,:])

T[-1,:] = Tleft    #temp for the left   
print (T[-1,:])

解决方法

我认为我已经设法将其整理出来,并根据@chris的建议添加了每一侧的温度后检查了这些值。https://scipython.com/book/chapter-7-matplotlib/examples/the-two-dimensional-diffusion-equation/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res