COMSOL求解常微分方程

COMSOL Multiphysics多物理场仿真软件也提供了求救常微分方程(ODE)和偏微分方程(PDE)的接口,下面详细介绍一下。

(1)建立模型,选择模型向导–>零维–>数学–>全局常微分和微分代数方程(ge),选择研究,选择瞬态,点击完成
(2)在组件下面可以看到刚刚添加的全局常微分和微分代数方程(ge),在右边栏,全局方程那里输入需要求解的函数。

这里写图片描述

以上图电路实例来说,现有RLC串联电路,假设R、L、C的参数都为1,电容电压: uC(t) ,电容电流: i(t) ,电感电压: uL(t) ,电阻电压: uR(t) ,输入电压 uin=sin(2πft) 则有下面的关系式:

uC(t)i(t)uL(t)uR(t)uin=uC(t)=CduC(t)dt=Ldi(t)dt=LCdu2C(t)dt2=Ri(t)=RCduC(t)dt=uC(t)+uL(t)+uR(t)

化简上式可得:
du2C(t)dt2+duC(t)dt+uC(t)=uin
,换成常见的数学形式为
f′′+f+f=sin(2πft)

要想在COMSOL求解该二阶微分方程,可以先用之前的方法在python里面求解,python代码如下:

from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
def f(y,t):
    dy1 = y[1]
    dy2 = np.sin(100*t)-y[0]-y[1]
    return [dy1,dy2]

t = np.linspace(0,20,3000)
# 初值[0,0]表示y(0)=0,y’(0)=0
# 返回y, 其中y[:,0]是y[0]的值 ,就是最终解 ,y[:,1]是y’(x)的值
y = odeint(f,[0,0],t)

l1, = plt.plot(t,y[:,0],label='y(0)')
#l2, = plt.plot(t,y[:,1],label='y(1)')

plt.legend()
plt.grid('on')
plt.show()

输出结果如下:

RLC_python.png

输入电源参数设置为 2πf=100 ,初值设定为 y(0)=0 , y(0)=0 ,由结果可知是一个衰减震荡的过程。

(3)步骤(2)得到的COMSOL设置结果如下:

RLC_COMSOL_ODE.png

关于全局方程的书写官方原文如下:

In each column enter as follows:\
• Enter the Name of the state variable. This also defines time-derivative variables. If a state variable is called u, its
first and second time derivatives are ut and utt, respectively. These variables become available in all geometries.
Therefore the names must be unique.\
• Use the f(u,ut,utt,t) column to specify the right-hand side of the equation that is to be set equal to zero.
The software then adds this global equation to the system of equations. When solving the model, the value of
the state variable u is adapted in such a way that the associated global equation is satisfied. All state variables and
their time derivatives can be used as well as any parameters, global variables, and coupling operators with a scalar
output and global domain of definition in the f(u,ut,utt,t) column. The variables can be functions of the state
variables in the global equations. Setting an equation for a state is optional. The default value of 0 means that
the software does not add any additional condition to the model.\
• If the time derivative of a state variable appears somewhere in the model during a time-dependent solution, the
state variable needs an initial condition. Models that contain second time derivatives also require an initial value
for the first time derivatives of the state variables. Set these conditions in the third (Initial value (u_ 0)) and fourth (Initial value (u_t 0)) columns.\
• Enter comments about the state or the equation in the last column, Description.\
\emph{特别注意}:\
(1)方程名称是作为变量用于整个几何体的,因此不要在其他地方重复误用,本例的函数名为f,也可以是u,y,g,h以及func之类等\
(2)方程关于时间的一阶导和二阶导表达式写作:ft和ftt,这是以本例函数名称为f来说的,如果函数名为y,就是yt和ytt,如果函数名是func,就是funct和
functt;\

(4)按下图设置仿真步长和时间,range(0,0.01,20)意思是仿真时间0-20s(因为一开始建立模型的研究类型是瞬态),仿真步长0.01s:

step_setup.png

点击计算,发现结果与python求救不符合,结果如下图所示:

comsol_ode_wrong_res

经过与前面python的结果对比,求解值比较小,数量级是 103 ,因此要修改COMSOL仿真配置中的容差,将\pmb{物理场控制}改为\pmb{用户控制},设置容差为\pmb{1e-6},设置和正确求解的最终结果如下图:

这里写图片描述

comsol_rlc_result

在COMSOL里自带的例子中,事先在\pmb{全局定义}设置了\pmb{参数}a,b,c,分别对应参数 σ , ρ β ,方程设置如下:

这里写图片描述

得到的结果和python求解的类似。

  • 8
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
COMSOL Multiphysics是一种用于模拟和求解科学和工程问题的先进工具。在COMSOL中,偏微分方程组接口允许用户以一种直观的方式定义和求解微分方程组。 偏微分方程组接口提供了一个可视化的环境,使用户可以通过选择和拖放来定义和配置偏微分方程。用户可以从各种方程和边界条件库中选择合适的方程和条件,并在模型中应用它们。接口还提供了一些预定义的偏微分方程,如热传导、电场、磁场等,用户可以直接选择使用或根据需要进行修改。 通过偏微分方程组接口,用户可以轻松定义系统的几何形状、边界条件和物理参数。接口还提供了丰富的后处理功能,允许用户可视化和分析模型的结果。用户可以绘制场变量的分布、计算积分和导出数据,以便进行进一步的分析和解释。 对于求解微分方程组,COMSOL提供了多种求解器选项。用户可以选择使用有限元法、有限差分法、边界元法等进行求解。同时,COMSOL还支持并行计算和多处理器求解,以加快求解速度。 总结来说,COMSOL的偏微分方程组接口提供了一种直观、灵活和高效的方式来定义、求解和分析偏微分方程组。它适用于许多科学和工程领域的模拟和仿真应用,如热传导、电磁场、结构力学等。使用COMSOL,用户可以更好地理解和解释系统的行为,并优化设计和决策。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值