0

我对 Julia 很陌生,我正在考虑以下问题。我想解决(可能是刚性的)ODE 系统,它根据状态到状态的方法描述冲击波后面的流动松弛,这意味着分子物种的每个振动水平都被认为是伪物种及其连续性方程。在这里,我考虑了 N2/N 的二元混合物(实际上是 N=0 的浓度)。

我已将 julia 代码拆分为几个 .jl 文件。总的来说,我将 ODE 求解器称为如下:

prob = ODEProblem(rpart!,Y0_bar,xspan, 1.)                                                                                          
sol  = DifferentialEquations.solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8, save_everystep=true, progress=true)

其中 Y0_bar 和 xspan 已在前面定义,在 rpart.jl 文件中我定义了系统:

function rpart!(du,u,p,t)

  ni_b = zeros(l);

  ni_b[1:l] = u[1:l]; print("ni_b = ", ni_b, "\n")
  na_b = u[l+1];      print("na_b = ", na_b, "\n")
  v_b  = u[l+2];      print("v_b = ",  v_b,  "\n")
  T_b  = u[l+3];      print("T_b = ",  T_b,  "\n")

  nm_b = sum(ni_b);   #print("nm_b = ", nm_b, "\n")
  Lmax = l-1;         #println("Lmax = ", Lmax, "\n")
  temp = T_b*T0;      #print("T = ", temp, "\n")

  ef_b = 0.5*D/T0;    #println("ef_b = ", ef_b, "\n")

  ei_b = e_i./(k*T0); #println("ei_b = ", ei_b, "\n")
  e0_b = e_0/(k*T0);  #println("e0_b = ", e0_b, "\n")

  sigma   = 2.;                     #println("sigma = ", sigma, "\n")
  Theta_r = Be*h*c/k;               #println("Theta_r = ", Theta_r, "\n")
  Z_rot   = temp./(sigma.*Theta_r); #println("Z_rot = ", Z_rot, "\n")

  M  = sum(m); #println("M = ", M, "\n")
  mb = m/M;    #println("mb = ", mb, "\n")

  A = zeros(l+3,l+3)

  for i = 1:l
    A[i,i]   = v_b
    A[i,l+2] = ni_b[i]
  end

  A[l+1,l+1] = v_b
  A[l+1,l+2] = na_b

  for i = 1:l+1
    A[l+2,i] = T_b
  end
  A[l+2,l+2] = M*v0^2/k/T0*(mb[1]*nm_b+mb[2]*na_b)*v_b
  A[l+2,l+3] = nm_b+na_b

  for i = 1:l
    A[l+3,i] = 2.5*T_b+ei_b[i]+e0_b
  end
  A[l+3,l+1] = 1.5*T_b+ef_b
  A[l+3,l+2] = 1/v_b*(3.5*nm_b*T_b+2.5*na_b*T_b+sum((ei_b.+e0_b).*ni_b)+ef_b*na_b)
  A[l+3,l+3] = 2.5*nm_b+1.5*na_b

  AA = inv(A); println("AA = ", AA, "\n", size(AA), "\n")

  # Equilibrium constant for DR processes
  Kdr = (m[1]*h^2/(m[2]*m[2]*2*pi*k*temp))^(3/2)*Z_rot*exp.(-e_i/(k*temp))*exp(D/temp); println("Kdr = ", Kdr, "\n")

  # Equilibrium constant for VT processes
  Kvt = exp.((e_i[1:end-1]-e_i[2:end])/(k*temp)); println("Kvt = ", Kvt, "\n")

  # Dissociation processes
  kd = zeros(2,l)
  kd = kdis(temp) * Delta*n0/v0;
  println("kd = ", kd, "\n", size(kd), "\n")

  # Recombination processes
  kr = zeros(2,l)
  for iM = 1:2
    kr[iM,:] = kd[iM,:] .* Kdr * n0
  end
  println("kr = ", kr, "\n", size(kr), "\n")

  RD  = zeros(l)

  for i1 = 1:l

    RD[i1] = nm_b*(na_b*na_b*kr[1,i1]-ni_b[i1]*kd[1,i1]) + na_b*(na_b*na_b*kr[2,i1]-ni_b[i1]*kd[2,i1])

  end

  println("RD = ",  RD,  "\n", size(RD))

  B      = zeros(l+3)
  for i  = 1:l
    B[i] = RD[i]
  end
  B[l+1] = - 2*sum(RD)

  du     = AA*B

end

问题是,当我运行模拟并绘制解决方案时,它看起来好像什么也没发生,并且所有配置文件都相等且平坦。事实上,每个时间步的解都等于它自己。所以,我认为我在更新 u 和 du 时犯了一些错误,但我无法修复它。在 Matlab 版本中,我获得了正确的演变。

亲切的问候,洛伦佐

4

1 回答 1

0

您正在使用该版本来改变输出,但您正在创建一个数组而不是改变输出。du .= AA*B

于 2020-11-26T10:42:14.167 回答