Wolfram 语言

偏微分方程

求解区域中带有事件的偏微分方程

为房间内用恒温器调节的发热系统建模,房间有三面隔热墙和一面受外界气温影响玻璃窗.

In[1]:=
Click for copyable input
\[CapitalOmega] = Rectangle[{0, 0}, {3/2, 1}]; outsideTemp[t_] := 15 + 10*Sin[2 \[Pi] t/24]; kd = 0.78; Ld = 0.05; \[CapitalGamma] = NeumannValue[Ld/kd*(outsideTemp[t] - u[t, x, y]), {x == 0}];

在某事件中,加热器或者加大功率或者减少功率.

In[2]:=
Click for copyable input
heaterLoad = 26; heater[upQ_, t_, tEvent_] := If[upQ == 1, Min[20*Max[(t - tEvent), 0], 1], 1 - Min[20*Max[(t - tEvent - 1/8), 0], 1]]*heaterLoad

偏微分方程模拟空气中的热扩散,其中热量在圆形范围 内产生,但通过玻璃窗散失.

In[3]:=
Click for copyable input
\[Rho] = 1.225; Cp = 1005.4; With[{heating = heater[a[t], t, eventT[t]]}, pde = D[u[t, x, y], t] - \[Rho]*Cp*Laplacian[u[t, x, y], {x, y}] == If[(x - 1/2)^2 + (y - 1/2)^2 <= (2/10)^2, heating, 0] + \[CapitalGamma]];

如果在位置 的恒温器测量的温度在触发值之下/上,且如果离散变量 改变,则加热器打开/关闭.

In[4]:=
Click for copyable input
triggerLow = 18; triggerHigh = 20; events = {a[0] == 1, eventT[0] == 0, WhenEvent[ u[t, 1.25, .25] < triggerLow, {eventT[t], a[t]} -> {If[a[t] == 0, t, eventT[t]], 1}], WhenEvent[ u[t, 1.25, .25] > triggerHigh, {eventT[t], a[t]} -> {If[a[t] == 1, t, eventT[t]], 0}]};

监测以外界温度为初始条件的偏微分方程的时间积分.

In[5]:=
Click for copyable input
eqn = {pde, u[0, x, y] == outsideTemp[0], events}; res = Monitor[ NDSolveValue[ eqn, {u, a}, {t, 0, 2*24}, {x, y} \[Element] \[CapitalOmega], DiscreteVariables -> {eventT[t], a[t]}, EvaluationMonitor :> (monitor = Row[{"t = ", CForm[t]}])], monitor]
Out[5]=

可视化恒温器测量到的温度、外部温度和加热器的触发值. 加热器打开的时候,显示蓝色背景.

In[6]:=
Click for copyable input
hp = Plot[ 25 res[[2]][t], {t, 0, 2*24}, Filling -> Bottom, PlotStyle -> None]; Show[ Plot[{res[[1]][t, 1.25, .25], outsideTemp[t], 18, 20}, {t, 0, 2*24}], hp]
Out[6]=

相关范例

de en es fr ja ko pt-br ru