前言
本文介绍如何在windows11系统中通过WSL安装ubuntu子系统,并配置OpenFOAM-v2106库。
一、通过WSL安装Ubuntu
控制面板
→
\to
→ 程序
→
\to
→ 启用或关闭windows功能
→
\to
→ 开启如下功能
(1) windows虚拟机监控程序平台
(2) 适用于Linux的windows子系统
(3) 虚拟机平台
以管理员权限打开powerShell,并执行如下指令
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
(参考资料:这就是修复 Windows 11 的 WSL 错误的方法)
在microsoft store中搜索 ubuntu,选择并安装 Ubuntu 18.04.6 LTS
二、在 Ubuntu 中配置 OpenFOAM
首先更换ubuntu的软件源,手动更换的方法是
sudo cp /etc/apt/source.list /etc/apt/source.list.bak
sudo vi /etc/apt/source.list
将软件源更换为如下的阿里云和清华源
# 阿里云源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
##測試版源
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
# 源碼
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
##測試版源
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
# 清华大学源
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
##測試版源
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# 源碼
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
##測試版源
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
然后执行软件源的更新操作
sudo apt-get update
从OpenFOAM的官方路径下载OpenFOAM-v2106安装包
Source: https://dl.openfoam.com/source/v2106/OpenFOAM-v2106.tgz
ThirdParty: https://dl.openfoam.com/source/v2106/ThirdParty-v2106.tgz
放在 ~/OpenFOAM路径下并解压到
~/OpenFOAM/OpenFOAM-v2106
~/OpenFOAM/ThirdParty-v2106
接下来安装OpenFOAM-v2106依赖的包
sudo apt-get install build-essential autoconf autotools-dev cmake gawk gnuplot
sudo apt-get install flex libfl-dev libreadline-dev zlib1g-dev openmpi-bin libopenmpi-dev mpi-default-bin mpi-default-dev
sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev
在 ~/.bashrc 中添加OpenFOAM的环境变量
alias of2106='source ~/OpenFOAM/OpenFOAM-v2106/etc/bashrc'
更新环境变量并执行
source ~/.bashrc
of2106
最后,编译OpenFOAM库
foam
./Allwmake -s -l
需要等待较长的时间完成编译。结束之后,测试编译是否成功:
打开一个新的wsl终端,使用 of2106 加载OpenFOAM的环境变量,然后执行下面的命令
icoFoam -help
如果编译成功,将输出如下信息
Usage: icoFoam [OPTIONS]
Options:
-case <dir> Specify case directory to use (instead of cwd)
-decomposeParDict <file>
Use specified file for decomposePar dictionary
-dry-run Check case set-up only using a single time step
-dry-run-write Check case set-up and write only using a single time step
-parallel Run in parallel
-postProcess Execute functionObjects only
-doc Display documentation in browser
-help Display short help and exit
-help-full Display full help and exit
Transient solver for incompressible, laminar flow of Newtonian fluids.
Using: OpenFOAM-v2106 (2106) - visit www.openfoam.com
Build: _c15bfde3cb-20210624
Arch: LSB;label=32;scalar=64
然后可以找一个OpenFOAM自带的case运行一遍,作为最终测试,例如
~/OpenFOAM/OpenFOAM-v2106/tutorials/incompressible/icoFoam/cavity
Contact me
Email: 18810577380@163.com