本文记录Linux平台通用的pyHyp安装方法,同样适用于WSL2
参照TUNA使用帮助,安装Anaconda并设置镜像。
新建env,pyhyp
可以换成任意名字:
conda create -n pyhyp
激活env:
conda activate pyhyp
包安装依赖包:
conda install -c conda-forge openmpi"<=4.2" petsc">=3.14,<3.16" cgns==4.2.0 python"<3.10" numpy"<1.22" scipy"<1.8" mpi4py
版本要求见MACH-Aero文档。
安装工具链:
conda install -c conda-forge compilers
设置编译依赖环境变量,编译后不再需要,注意替换pyhyp
为ENV名称。
export CGNS_HOME=$(conda env list | grep pyhyp | awk '{print $3};')
export PETSC_DIR=$(conda env list | grep pyhyp | awk '{print $3};')
clone 仓库:
git clone https://github.com/mdolab/cgnsutilities.git
cd cgnsutilities
准备配置文件:
cp config/defaults/config.LINUX_GFORTRAN.mk config/config.mk
编译安装:
make
pip install .
cd ..
clone 仓库:
git clone https://github.com/mdolab/pyhyp.git
cd pyhyp
(可选) 替换pyhyp/src/3D/writePlot3D.F90
内容如下,将plot3d输出文件改为unformatted格式
subroutine writePlot3d(fileName)
!***DESCRIPTION
!
! Written by Gaetan Kenway
!
! Abstract: writePLot3d write the current grid to a 3D PLOT3D
! file. It does not make any attempt to do grid
! connectivities or boundary conditions.
!
! Parameters
! ----------
! fileName : Character array
! The name of the plot3d file
use communication
use hypInput
use hypData
implicit none
! Input Arguments
character*(*) :: fileName
! Working variables
integer(kind=intType) :: i, j, k, idim, iPatch, idGlobal, ierr
integer(kind=intType), allocatable :: dims(:,:)
real(kind=realType), allocatable :: blk(:,:,:,:)
if (myid == 0) then
! Open the output file
open (unit=7, file=fileName, form='unformatted')
! Write the number of zones
write (7) nPatch
! Write the zone sizes
allocate(dims(3, nPatch))
do i = 1, nPatch
dims(1, i) = patches(i)%il
dims(2, i) = patches(i)%jl
dims(3, i) = N
end do
write (7) ((dims(idim,i), idim=1,3), i=1,nPatch)
deallocate(dims)
end if
do iPatch = 1, nPatch
if (myid == 0) allocate(blk(patches(iPatch)%il, patches(iPatch)%jl, N, 3))
do idim = 1, 3
do k = 1, N
call VecScatterBegin(rootScatter, X(k), XLocal, INSERT_VALUES, SCATTER_FORWARD, ierr)
call EChk(ierr, __FILE__, __LINE__)
call VecScatterEnd(rootScatter, X(k), XLocal, INSERT_VALUES, SCATTER_FORWARD, ierr)
call EChk(ierr, __FILE__, __LINE__)
if (myid == 0) then
call VecGetArrayF90(xLocal, xx, ierr)
call EChk(ierr, __FILE__, __LINE__)
do j = 1, patches(iPatch)%jl
do i = 1, patches(iPatch)%il
! We will use l_index to get the correct pointer into grid3D
idGlobal = patches(iPatch)%l_index(i, j)
blk(i, j, k, idim) = xx(3 * (idGlobal - 1) + iDim)
end do
end do
call VecRestoreArrayF90(XLocal, xx, ierr)
call EChk(ierr, __FILE__, __LINE__)
end if
end do
end do
if (myid == 0) then
write (7) ((((blk(i,j,k,idim),i=1,patches(iPatch)%il),j=1,patches(iPatch)%jl),k=1,N),idim=1,3)
deallocate(blk)
endif
end do
if (myid == 0) then
! Finally close the file
close (7)
end if
end subroutine writePlot3d
准备配置文件:
cp config/defaults/config.LINUX_GFORTRAN_OPENMPI.mk config/config.mk
编译安装:
make
pip install .
cd ..
安装完成后每次只需要conda activate pyhyp
就会设置好pyhyp的环境,直接正常使用即可。pyhyp仓库中包含多个示例,请自行体验。
2023-03-07: 提供输出plot3d unformatted版本的补丁
2023-02-07:指定numpy版本,解决F2PY问题
2023-01-19:优化步骤,不影响编译结果
2023-01-01:初始版本