Subroutine Input_3DSpool !----------------------------------------------------------------------- use global use component_prameter use constant use time_control use LOCAL_RESM implicit none character*20 :: Para_Inlst01,Para_Inlst02,Para_Inlst03 character*20 :: Para_Inlst04,Para_Inlst05,Para_Inlst06,Para_Inlst07 real*8 :: DX_3DV_Input(100),DY_3DV_Input(100),DZ_3DV_Input(100) real*8 :: VELX_3DV_Input,VELY_3DV_Input,VELZ_3DV_Input real*8 :: ANGX_3DV_Input,ANGY_3DV_Input,ANGZ_3DV_Input integer :: CV_Structure_x,CV_Structure_y,CV_Structure_z real*8 :: Gama_CV,Gama_X,Gama_Y,Gama_z integer :: AQCVIN_x,AQCVIN_y,AQCVIN_z real*8 :: AQQ_Input,AQT_Input, AQH_Input
时间: 2023-09-15 08:20:43 浏览: 131
这是一个 Fortran 的子程序(Subroutine),该子程序名称为 `Input_3DSpool`。下面是该子程序中使用到的一些变量:
- `Para_Inlst01` 到 `Para_Inlst07`:7 个字符型字符串变量,长度为 20。
- `DX_3DV_Input`、`DY_3DV_Input` 和 `DZ_3DV_Input`:三个长度为 100 的实型数组。
- `VELX_3DV_Input`、`VELY_3DV_Input` 和 `VELZ_3DV_Input`:三个实型变量。
- `ANGX_3DV_Input`、`ANGY_3DV_Input` 和 `ANGZ_3DV_Input`:三个实型变量。
- `CV_Structure_x`、`CV_Structure_y` 和 `CV_Structure_z`:三个整型变量。
- `Gama_CV`、`Gama_X`、`Gama_Y` 和 `Gama_z`:四个实型变量。
- `AQCVIN_x`、`AQCVIN_y` 和 `AQCVIN_z`:三个整型变量。
- `AQQ_Input`、`AQT_Input` 和 `AQH_Input`:三个实型变量。
该子程序中的变量命名不够规范,无法确定其具体含义,需要结合具体业务场景进行理解。该子程序的主要功能是读取一些参数和数据,并进行一些计算。其中,变量的类型(字符型、实型、整型)和长度都有明确的定义。
相关问题
subroutine initial_particle implicit double precision (a-h,o-z) include 'variables.f90' ! ---------------------------------------------- dimension no_molecule_cell_r(noy_cell) ! ---------------------------------------------- T_O=t_down_wall+rate_pres**2*(y_length)**4/12.0/16.0/v_kpa_ini/viscosity do j=1,noy_cell cotent_macro_p_cell_f(1,j)=rate_pres*(y_length*yc(j)-yc(j)**2)/2.0/viscosity+u_down_wall+yc(j)/y_length*(u_up_wall-u_down_wall) cotent_macro_p_cell_f(2,j)=0.0 cotent_macro_p_cell_f(3,j)=0.0 cotent_macro_t_cell_f(j)=t_ini enddo
这段代码是Fortran语言的一个子程序,它的功能是初始化粒子的位置、速度和温度等宏观量,以及计算每个细胞内的粒子数和宏观量。具体来说,它会计算初始温度T_O,并根据初始温度和压力计算每个细胞内的初始粒子数和宏观量。然后,它会在每个细胞内随机生成一定数量的粒子,并给这些粒子随机分配速度和位置。最后,它会调用其他子程序计算每个细胞内的粒子数和宏观量。
subroutine FGMRES(A, IA, JA, RHS, N, nzmax, COMPUTED_SOLUTION) implicit none integer N integer SIZE parameter (SIZE=128) integer, intent(in) :: nzmax !--------------------------------------------------------------------------- ! Define arrays for the upper triangle of the coefficient matrix ! Compressed sparse row storage is used for sparse representation !--------------------------------------------------------------------------- integer IA(N+1) integer JA(nzmax) real*8 A(nzmax) !--------------------------------------------------------------------------- ! Allocate storage for the ?par parameters and the solution/rhs/residual vectors !--------------------------------------------------------------------------- integer IPAR(SIZE) real*8 DPAR(SIZE), TMP(N*(2*150+1)+(150*(150+9))/2+1) real*8 RHS(N) !, B(N) real*8 COMPUTED_SOLUTION(N) ! real*8 RESIDUAL(N) !--------------------------------------------------------------------------- ! Some additional variables to use with the RCI (P)FGMRES solver !--------------------------------------------------------------------------- integer ITERCOUNT, EXPECTED_ITERCOUNT parameter (EXPECTED_ITERCOUNT=233) integer RCI_REQUEST, I real*8 DVAR !--------------------------------------------------------------------------- ! An external BLAS function is taken from MKL BLAS to use ! with the RCI (P)FGMRES solver ! Save the right-hand side in vector B for future use !--------------------------------------------------------------------------- ! call DCOPY(N, RHS, 1, B, 1) !--------------------------------------------------------------------------- ! Initialize the initial guess !--------------------------------------------------------------------------- do I=1,N COMPUTED_SOLUTION(I)=0. END DO !--------------------------------------------------------------------------- ! Initialize the solver !--------------------------------------------------------------------------- CALL DFGMRES_INIT(N, COMPUTED_SOLUTION, RHS, RCI_REQUEST, IPAR, DPAR, TMP) IF (RCI_REQUEST.NE.0) GOTO 999 !--------------------------------------------------------------------------- ! Set the desired parameters: ! do the restart after 2 iterations: IPAR(15)=2 ! LOGICAL parameters: ! do not do the stopping test for the maximal number of iterations: IPAR(8)=0 ! do the Preconditioned iterations of FGMRES method: IPAR(11)=1 ! DOUBLE PRECISION parameters ! set the relative tolerance to 1.0D-3 instead of default value 1.0D-6: DPAR(1)=1.0D-3 !--------------------------------------------------------------------------- IPAR(9)=1 IPAR(10)=0 IPAR(12)=1 DPAR(1)=1.0D-6 !--------------------------------------------------------------------------- ! Check the correctness and consistency of the newly set parameters !--------------------------------------------------------------------------- CALL DFGMRES_CHECK(N, COMPUTED_SOLUTION, RHS, RCI_REQUEST, IPAR, DPAR, TMP) IF (RCI_REQUEST.NE.0) GOTO 999 !--------------------------------------------------------------------------- ! Compute the solution by RCI (P)FGMRES solver with preconditioning ! Reverse Communication starts here !--------------------------------------------------------------------------- 1 CALL DFGMRES(N, COMPUTED_SOLUTION, RHS, RCI_REQUEST, IPAR, DPAR, TMP) !--------------------------------------------------------------------------- ! If RCI_REQUEST=0, then the solution was found with the required precision !--------------------------------------------------------------------------- IF (RCI_REQUEST.EQ.0) GOTO 3 !--------------------------------------------------------------------------- ! If RCI_REQUEST=1, then compute the vector A*TMP(IPAR(22)) ! and put the result in vector TMP(IPAR(23)) !--------------------------------------------------------------------------- IF (RCI_REQUEST.EQ.1) THEN CALL MKL_DCSRGEMV('N',N, A, IA, JA, TMP(IPAR(22)), TMP(IPAR(23))) GOTO 1 ! END IF !!--------------------------------------------------------------------------- !! If RCI_request=2, then do the user-defined stopping test !! The residual stopping test for the computed solution is performed here !!--------------------------------------------------------------------------- !! NOTE: from this point vector B(N) is no longer containing the right-hand !! side of the problem! It contains the current FGMRES approximation to the !! solution. If you need to keep the right-hand side, save it in some other !! vector before the call to DFGMRES routine. Here we saved it in vector !! RHS(N). The vector B is used instead of RHS to preserve the original !! right-hand side of the problem and guarantee the proper restart of FGMRES !! method. Vector B will be altered when computing the residual stopping !! criterion! !!--------------------------------------------------------------------------- ! IF (RCI_REQUEST.EQ.2) THEN !! Request to the DFGMRES_GET routine to put the solution into B(N) via IPAR(13) ! IPAR(13)=1 !! Get the current FGMRES solution in the vector B(N) ! CALL DFGMRES_GET(N, COMPUTED_SOLUTION, B, RCI_REQUEST, IPAR, DPAR, TMP, ITERCOUNT) !! Compute the current true residual via MKL (Sparse) BLAS routines ! CALL MKL_DCSRGEMV('N', N, A, IA, JA, B, RESIDUAL) ! CALL DAXPY(N, -1.0D0, RHS, 1, RESIDUAL, 1) ! DVAR=DNRM2(N, RESIDUAL, 1) ! IF (DVAR.LT.1.0E-3) THEN ! GOTO 3 ! ELSE ! GOTO 1 ! END IF !!--------------------------------------------------------------------------- !! If RCI_REQUEST=anything else, then DFGMRES subroutine failed !! to compute the solution vector: COMPUTED_SOLUTION(N) !!--------------------------------------------------------------------------- ELSE ! call data WRITE(*,*) 'This example FAILED as the solver has returned the ERROR code',RCI_REQUEST pause GOTO 999 END IF !--------------------------------------------------------------------------- ! Reverse Communication ends here ! Get the current iteration number and the FGMRES solution (DO NOT FORGET to ! call DFGMRES_GET routine as COMPUTED_SOLUTION is still containing ! the initial guess!) !--------------------------------------------------------------------------- 3 CALL DFGMRES_GET(N, COMPUTED_SOLUTION, RHS, RCI_REQUEST, IPAR, DPAR, TMP, ITERCOUNT) IF (ITERCOUNT<=EXPECTED_ITERCOUNT) THEN ! WRITE(*,*) 'This example has successfully PASSED through all steps of computation!' ! print*,'number of iteration',ITERCOUNT RETURN ELSE WRITE(*,*) 'This example have FAILED as the number of iterations differs from the expected number of iterations' pause STOP 15 END IF 999 WRITE(*,*) 'This example FAILED as the solver has returned the ERROR code',RCI_REQUEST CALL MKL_FREE_BUFFERS STOP 16 END SUBROUTINE FGMRES详细解释下这段代码,中文注释
<think>我们有一个名为FGMRES的子程序,它使用Fortran语言编写,实现了Flexible GeneralizedMinimal Residual(FGMRES)方法,用于求解大型稀疏线性方程组。该子程序使用了IntelMathKernel Library(MKL)中的稀疏矩阵向量乘法和FGMRES求解器。代码详细解释如下:</think>### Fortran FGMRES 求解器代码详解
以下是带中文注释的代码解析:
```fortran
subroutine FGMRES(A, IA, JA, RHS, N, nzmax, COMPUTED_SOLUTION)
implicit none
integer N
integer SIZE
parameter (SIZE=128) ! 参数数组大小
integer, intent(in) :: nzmax ! 稀疏矩阵非零元素最大数量
!---------------------------------------------------------------------------
! 定义系数矩阵上三角的数组(压缩稀疏行存储格式 CSR)
!---------------------------------------------------------------------------
integer IA(N+1) ! 行指针数组(CSR格式)
integer JA(nzmax) ! 列索引数组(CSR格式)
real*8 A(nzmax) ! 非零元素值数组(CSR格式)
!---------------------------------------------------------------------------
! 为参数和解向量分配存储空间
!---------------------------------------------------------------------------
integer IPAR(SIZE) ! 整数参数数组
real*8 DPAR(SIZE) ! 浮点参数数组
real*8 TMP(N*(2*150+1)+(150*(150+9))/2+1) ! 临时工作数组
real*8 RHS(N) ! 右端项向量
real*8 COMPUTED_SOLUTION(N) ! 解向量
!---------------------------------------------------------------------------
! FGMRES求解器相关变量
!---------------------------------------------------------------------------
integer ITERCOUNT, EXPECTED_ITERCOUNT
parameter (EXPECTED_ITERCOUNT=233) ! 预期迭代次数
integer RCI_REQUEST ! 反向通信接口请求码
integer I ! 循环索引
real*8 DVAR ! 临时双精度变量
!---------------------------------------------------------------------------
! 初始化解向量为零
!---------------------------------------------------------------------------
do I=1,N
COMPUTED_SOLUTION(I)=0.
END DO
!---------------------------------------------------------------------------
! 初始化FGMRES求解器
!---------------------------------------------------------------------------
CALL DFGMRES_INIT(N, COMPUTED_SOLUTION, RHS, RCI_REQUEST, IPAR, DPAR, TMP)
IF (RCI_REQUEST.NE.0) GOTO 999 ! 错误处理
!---------------------------------------------------------------------------
! 设置求解器参数:
! IPAR(9)=1 : 使用用户定义的停止条件(实际代码中未实现)
! IPAR(10)=0 : 不使用预处理器(默认)
! IPAR(12)=1 : 使用FGMRES方法(而非GMRES)
! DPAR(1)=1.0D-6 : 设置相对容差为1e-6
!---------------------------------------------------------------------------
IPAR(9)=1
IPAR(10)=0
IPAR(12)=1
DPAR(1)=1.0D-6
!---------------------------------------------------------------------------
! 检查参数一致性
!---------------------------------------------------------------------------
CALL DFGMRES_CHECK(N, COMPUTED_SOLUTION, RHS, RCI_REQUEST, IPAR, DPAR, TMP)
IF (RCI_REQUEST.NE.0) GOTO 999 ! 错误处理
!---------------------------------------------------------------------------
! 使用反向通信接口(RCI)执行FGMRES求解
!---------------------------------------------------------------------------
1 CALL DFGMRES(N, COMPUTED_SOLUTION, RHS, RCI_REQUEST, IPAR, DPAR, TMP)
!---------------------------------------------------------------------------
! 处理RCI请求码:
! 0 = 求解完成
! 1 = 需要计算矩阵向量乘积
! 其他 = 错误
!---------------------------------------------------------------------------
IF (RCI_REQUEST.EQ.0) GOTO 3 ! 成功收敛
IF (RCI_REQUEST.EQ.1) THEN ! 需要计算 A*x
! 使用MKL稀疏矩阵向量乘法:y = A*x
CALL MKL_DCSRGEMV('N', N, A, IA, JA, TMP(IPAR(22)), TMP(IPAR(23)))
GOTO 1 ! 返回继续迭代
ELSE ! 处理错误
WRITE(*,*) '求解器返回错误码', RCI_REQUEST
pause
GOTO 999
END IF
!---------------------------------------------------------------------------
! 收敛后处理:获取最终解和迭代次数
!---------------------------------------------------------------------------
3 CALL DFGMRES_GET(N, COMPUTED_SOLUTION, RHS, RCI_REQUEST, IPAR, DPAR, TMP, ITERCOUNT)
! 验证迭代次数
IF (ITERCOUNT <= EXPECTED_ITERCOUNT) THEN
RETURN ! 成功返回
ELSE
WRITE(*,*) '实际迭代次数', ITERCOUNT, '与预期', EXPECTED_ITERCOUNT, '不符'
pause
STOP 15
END IF
!---------------------------------------------------------------------------
! 错误处理段
!---------------------------------------------------------------------------
999 WRITE(*,*) '求解器返回错误码', RCI_REQUEST
CALL MKL_FREE_BUFFERS ! 释放MKL内存
STOP 16
END SUBROUTINE FGMRES
```
### 关键组件解析:
1. **稀疏矩阵存储**:
- `IA`:行指针数组(CSR格式)
- `JA`:列索引数组
- `A`:非零元素值数组
2. **求解器参数**:
- `IPAR`:控制求解器行为的整数参数(如算法类型、停止条件)
- `DPAR`:浮点参数(如容差)
- `TMP`:大型工作数组(存储Krylov子空间和临时向量)
3. **反向通信接口(RCI)**:
- `RCI_REQUEST` 控制执行流程:
- 0:收敛
- 1:需要计算矩阵向量积
- 其他:错误
- 实现非阻塞式迭代控制
4. **核心操作**:
- 矩阵向量乘:`MKL_DCSRGEMV` (MKL优化稀疏计算)
- 求解器初始化:`DFGMRES_INIT`
- 迭代执行:`DFGMRES`
- 结果获取:`DFGMRES_GET`
5. **特点**:
- 使用Flexible GMRES (FGMRES) 算法,支持变预处理
- 预期迭代次数验证机制
- 严格的错误处理
- 依赖Intel MKL数学库
### 算法流程:
1. 初始化解向量 → 2. 配置求解器参数 → 3. 进入RCI循环 → 4. 根据请求码执行操作 → 5. 收敛后获取解 → 6. 验证结果
此实现特别适合大规模稀疏线性系统求解(如有限元分析、计算流体力学),利用MKL的高性能稀疏计算能力。
阅读全文
相关推荐














