Win11-WSL-Ubuntu22.04-openmc 从源码编译安装

一、WSL 安装 Ubuntu22.04

  1. 启用 WSL

  2. 打开 Microsoft Store,安装 Ubuntu22.04

  3. 设置源,更新
    ref: https://linuxmirrors.cn/use/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 用户权限
sudo -i

# 安装 LinuxMirrors:
bash <(curl -sSL https://linuxmirrors.cn/main.sh)

# 恢复原始设置:
# bash <(curl -sSL https://linuxmirrors.cn/main.sh) --use-official-source true

# Docker 源:
# bash <(curl -sSL https://linuxmirrors.cn/docker.sh)

sudo apt update
sudo apt upgrade

  1. 安装 ZSH、oh-my-zsh

参考 zsh & oh-my-zsh 安装配置

1
2
3
4
5
6
7
8
9
sudo apt install zsh
sh -c "$(wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh -O -)"

# sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

source ~/.zshrc

二、编译安装 openmc

ref: https://docs.openmc.org/en/stable/quickinstall.html

  1. 参照 Manually Installing from Source, 安装编译所需的基础库
1
sudo apt install g++ cmake libhdf5-dev libpng-dev
  1. 编译 build
1
2
3
4
5
6
git clone --recurse-submodules https://github.com/openmc-dev/openmc.git
cd openmc
mkdir build && cd build
cmake ..
make
sudo make install
  1. 创建虚拟环境,安装 openmc 库
1
2
3
4
5
6
7
8
9
10
11
12
python3 -V
sudo apt install python3-pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

# 创建虚拟环境
sudo apt install python3-venv
python3 -m venv ~/openmc-venv
source ~/openmc-venv/bin/activate

# 安装 openmc
python3 -m pip install .

  1. 下载材料数据集
1
2
3
4
5
git clone https://github.com/openmc-dev/data openmc-dev_data

cd openmc-dev_data
python3 convert_nndc71.py

cross_sections.xml 的路径加入环境变量,或直接在openmc程序中设置:

1
2
3
4
5
6
7
# code /home/xxxx/.local/lib/python3.10/site-packages/openmc/config.py
config['cross_sections'] = "/home/xxxx/openmc-dev_data/nndc-b7.1-hdf5/cross_sections.xml"

# 或者 直接加在程序前面
import openmc
openmc.config["cross_sections"] = "/home/bo/openmc_data/nndc-b7.1-hdf5/cross_sections.xml"