Phydrus Documentation 编译源码记录

流程参照了说明文档:Phydrus Documentation

安装Phydrus包

在Anaconda建了一个python 3.7的环境。同时执行了以下代码:

pip install phydrus

检查是否有这些依赖的包:matplotlib >= 3.1 pandas >= 1.1 numpy >= 1.1,没有的话安装。

github下载源码

文档中给出了源码的GitHub仓库:

GitHub - phydrus/source_code: Repository to host the Phydrus optimised Fortran code for the Hydrus-1D Modelx

下载后,解压缩

下载安装MinGW与编译

直接在解压缩的文件下用一下make命令,发现并不可以。要进行gfortran环境的安装与配置。

安装与配置镜像 acmsys2 | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

请访问镜像目录下的 distrib/ 目录

# x86_64
https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/x86_64/
# i686
https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/i686/

找到名为 msys2-<架构>-<日期>.exe 的文件(如 msys2-x86_64-20141113.exe),下载安装即可。

安装完成后,打开

直接运行

sed -i "s#https\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g" /etc/pacman.d/mirrorlist*

安装编译器

pacman -S mingw-w64-x86_64-gcc-fortran

配置环境变量

将bin文件放入系统变量中。例如我的安装路径为 D:\App\msys64,那么我写入系统变量path中的路径就应该为 D:\App\msys64\mingw64\bin

验证

输入gfortran --version验证,如果输出版本号,即为安装成功。(可能需要重启MSYS2 MINGW64,重启后还不行那就是失败了)

编译

cmd中进入到source文件夹

cd D:\Sci\溶质运移模型\phydrus\source_code-main\source

然后执行以下命令,-o后即为输出exe文件的路径

gfortran HYDRUS.FOR INPUT.FOR HYSTER.FOR MATERIAL.FOR OUTPUT.FOR  SINK.FOR SOLUTE.FOR TEMPER.FOR TIME.FOR WATFLOW.FOR -o "D:\Sci\溶质运移模型\phydrus\source_code-main\\hydrus.exe"

python调用

使用一下github上hydrus给的范例,python代码编辑器我使用的是vscode。

import os
import phydrus as ps

# Folder for Hydrus files to be stored
ws = "example_1"
exe = os.path.join(os.getcwd(),"D:/Sci/溶质运移模型/phydrus/source_code-main/hydrus.exe")  
# Description
desc = "Infiltration of Water into a Single-Layered Soil Profile"
# Create model
ml = ps.Model(exe_name=exe, ws_name=ws, name="model", description=desc, mass_units="mmol",
              time_unit="days", length_unit="cm")
ml.basic_info["lFlux"] = True
ml.basic_info["lShort"] = False

ml.add_time_info(tmax=1, print_times=True, nsteps=12, dt=0.001)

ml.add_waterflow(top_bc=0, bot_bc=4)

m = ml.get_empty_material_df(n=1)
m.loc[[1]] = [[0.078, 0.43, 0.036, 1.56, 24.96, 0.5]]
ml.add_material(m)

elements = 100  # Disctretize soil column into n elements
depth = -100  # Depth of the soil column
ihead = -100  # Determine initial Pressure Head
# Create Profile
profile = ps.create_profile(bot=depth, dx=abs(depth / elements), h=ihead)
profile.iloc[0, 1] = 1  # Define initial Pressure Head at the surface
ml.add_profile(profile)  # Add the profile

# Add observation nodes at depth
ml.add_obs_nodes([-20, -40, -60, -80, -100])

ml.write_input()
ml.simulate()

ml.plots.obs_points()

参考文章:

msys2 | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

用 VS Code + MSYS 搞定 Windows 上的 Fortran 开发 (penclub.club)

GitHub - phydrus/phydrus: :sweat_drops: Python implementation of the HYDRUS-1D unsaturated zone model

Phydrus Documentation

  • 34
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值