- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 Jacobi 方法求解泊松方程(在二维轴对称圆柱坐标系中)。 L2 范数从第一次迭代的 ~1E3(我的猜测非常糟糕)非常缓慢地减少到 ~0.2。然后,经过多次迭代,L2 范数开始增加。
我的几何图形是平行板,在两个板上的 r = 0 处都有尖点。 (如果这很重要的话)。
我的代码有什么错误吗?我需要使用不同的算法吗? (我有一个尚未运行的 DADI 算法。)
这是我的雅可比法算法。然后这只是包裹在一个 while 循环中。
subroutine Jacobi(PoissonRHS, V, resid)
implicit none
real, dimension(0:,0:) :: PoissonRHS, V
REAL resid
integer :: i,j, lb, ub
real, dimension(0:size(V,1)-1, 0:size(V,2)-1) :: oldV
real :: dr = delta(1)
real :: dz = delta(2)
real :: dr2 = (delta(1))**(-2)
real :: dz2 = (delta(2))**(-2)
integer :: M = cells(1)
integer :: N = cells(2)
oldV = V
!Note: All of the equations are second order accurate
!If at r = 0 and in the computational domain
! This is the smoothness condition, dV(r=0)/dr = 0
V(0,:) = (4.0*oldV(1,:)-oldV(2,:))/3.0
!If at r = rMax and in the computational domain
! This is an approximation and should be fixed to improve accuracy, it should be
! lim r->inf V' = 0, while this is V'(r = R) = 0
V(M, 1:N-1) = 0.5 / (dr2 + dz2) * ( &
(2.0*dr2)*oldV(M-1,1:N-1) + &
dz2 * (oldV(M,2:N) + oldV(M,0:N-2)) &
- PoissonRHS(M,1:N-1))
do i = 1, M-1
lb = max(0, nint(lowerBoundary(i * dr) / dz)) + 1
ub = min(N, nint(upperBoundary(i * dr) / dz)) - 1
V(i,lb:ub) = 0.5 / (dr2 + dz2) * ( &
((1.0 - 0.5/dble(i))*dr2)*oldV(i-1,lb:ub) + &
((1.0 + 0.5/dble(i))*dr2)*oldV(i+1,lb:ub) + &
dz2 * (oldV(i,lb+1:ub+1) + oldV(i,lb-1:ub-1)) &
- PoissonRHS(i,lb:ub))
V(i, 0:lb-1) = V0
V(i, ub+1:N) = VL
enddo
!compare to old V values to check for convergence
resid = sqrt(sum((oldV-V)**2))
return
end subroutine Jacobi
最佳答案
根据其他读数,这似乎是一个精度问题。因为(例如)我有表达式
V(i,lb:ub) = 0.5 / (dr2 + dz2) * ( &
((1.0 - 0.5/dble(i))*dr2)*oldV(i-1,lb:ub) + &
((1.0 + 0.5/dble(i))*dr2)*oldV(i+1,lb:ub) + &
dz2 * (oldV(i,lb+1:ub+1) + oldV(i,lb-1:ub-1)) &
- PoissonRHS(i,lb:ub))
其中 dr2
和 dz2
非常大。因此,通过分发这些,我得到的项是 ~1 并且代码收敛(缓慢,但这是数学的函数)。
所以我的新代码是
subroutine Preconditioned_Jacobi(PoissonRHS, V, resid)
implicit none
real, dimension(0:,0:) :: PoissonRHS, V
REAL resid
integer :: i,j, lb, ub
real, dimension(0:size(V,1)-1, 0:size(V,2)-1) :: oldV
real :: dr = delta(1)
real :: dz = delta(2)
real :: dr2 = (delta(1))**(-2)
real :: dz2 = (delta(2))**(-2)
real :: b,c,d
integer :: M = cells(1)
integer :: N = cells(2)
b = 0.5*(dr**2)/((dr**2) + (dz**2))
c = 0.5*(dz**2)/((dr**2) + (dz**2))
d = -0.5 / (dr2 + dz2)
oldV = V
!Note: All of the equations are second order accurate
!If at r = 0 and in the computational domain
! This is the smoothness condition, dV(r=0)/dr = 0
V(0,:) = (4.0*oldV(1,:)-oldV(2,:))/3.0 !same as: oldV(0,:) - 2.0/3.0 * (1.5 * oldV(0,:) - 2.0 * oldV(1,:) + 0.5 * oldV(2,:) - 0)
!If at r = rMax and in the computational domain
! This is an approximation and should be fixed to improve accuracy, it should be
! lim r->inf V' = 0, while this is V'(r = R) = 0
V(M,1:N-1) = d*PoissonRHS(M,1:N-1) &
+ 2.0*c * oldV(M-1,1:N-1) &
+ b * ( oldV(M,0:N) + oldV(M,2:N) )
do i = 1, M-1
lb = max(0, nint(lowerBoundary(i * dr) / dz)) + 1
ub = min(N, nint(upperBoundary(i * dr) / dz)) - 1
V(i,lb:ub) = d*PoissonRHS(i,lb:ub) &
+ (c * (1.0-0.5/dble(i)) * oldV(i-1,lb:ub)) &
+ (c * (1.0+0.5/dble(i)) * oldV(i+1,lb:ub)) &
+ b * (oldV(i,lb-1:ub-1) + oldV(i,lb+1:ub+1))
V(i, 0:lb-1) = V0
V(i, ub+1:N) = VL
enddo
!compare to old V values to check for convergence
resid = sum(abs(oldV-V))
return
end subroutine Preconditioned_Jacobi
关于algorithm - 雅可比方法先收敛再发散,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32322835/
我有几个关于我的遗传算法和整体 GA 的问题。 我创建了一个 GA,当给定一条曲线时,它会尝试找出产生这条曲线的函数。 例子如下积分 {{-2, 4},{-1, 1},{0, 0},{1, 1},{2
我正在尝试编写一个 GA 来解决以下难题... 二进制编码(我认为)非常有效。每件作品可以是: 原始向上或翻转的方式 - 1 位 旋转 0(即无)、90、180 或 270 度 - 2 位 在位置 (
我正在编写一个小代码(顺序)来计算适度数据集的网页排名(尽管并非完全微不足道)。 算法是这样的: while ( not converged ) { // Do a bunch of thing
我正在尝试检测长时间序列中的微事件。为此,我将训练一个 LSTM 网络。 数据。每个时间样本的输入是 11 个不同的特征,经过一定程度的标准化以适合 0-1。输出将是两个类之一。 批处理。由于巨大类别
我试图通过使用 optim 函数在 R 中找到最佳 GARCH 模型的参数。但是,我的值(value)观会变得很高,这是没有意义的。我在 MATLAB 中使用 fminsearch 实现了类似的算法,
我运行了 20 倍 cv.glmnet 套索模型以获得 lambda 的“最佳”值。但是,当我尝试重现 glmnet() 的结果时,我收到一条错误消息: Warning messages: 1: fr
我在 dymola 中构建了一个模型。虽然在初始化过程中出现了一些错误,但最终还是计算成功了。 模型收敛成功后,我尝试使用“在模型中保存起始值”选项将正确的迭代变量 strat 值存储到模型中,以便模
我有一个分层 Logit,可以随着时间的推移进行观察。正在关注Carter 2010 ,我添加了时间、时间^2 和时间^3 术语。在添加时间变量之前,模型会使用 Metropolis 或 NUTS 进
再次感谢您花时间阅读这篇文章。 我知道这个问题已经被问了很多,而且我已经检查了很多关于这个问题的帖子:然而,我对使用反向传播的成功 XOR 学习的探索仍未完成。 我按照建议尝试调整学习率、动量、有/无
我是一名优秀的程序员,十分优秀!