0%

MOAB for both PyNE and DAGMC

当前版本的Trelis dagmc插件使用的是MOAB5.1,混用不同版本的MOAB可能会导致Trelis模型导出失败。因此,MOAB5.1依然是需要的。
然而当前版本的PyNE, DAGMC和OpenMC都默认使用MOAB5.3.0了。因此,这篇博客记录在我工作电脑上同时安装MOAB5.1及MOAB5.3.0的实践。
为了配合非结构网格的转换,我需要使用netCDF支持,netCDF安装方法:

1
sudo apt-get install libnetcdf-dev libnetcdff-dev libeigen3-dev

Install MOAB5.1

当前版本的MOAB5.1,我需要的功能有:
- mbconvert
- 动态链接库
- netcdf配合非结构网格转换功能
因此,安装过程中可以不需要并行、pymoab等功能。下面假设将MOAB5.1安装在$HOME/opt/MOAB5.1中。

1
2
3
4
5
6
7
8
9
10
11
12
13
cd $HOME/opt
mkdir MOAB5.1
cd MOAB5.1
export MOAB51_DIR=$HOME/opt/MOAB5.1
git clone --branch 5.1.0 --single-branch https://bitbucket.org/fathomteam/moab moab
cd moab
autoreconf -fi
cd ..
mkdir -p build
cd build
cmake ../moab/ -DENABLE_MPI=OFF -DENABLE_PYMOAB=OFF -DCMAKE_INSTALL_PREFIX=$MOAB51_DIR -DENABLE_HDF5=ON -DBUILD_SHARED_LIBS=ON -DENABLE_NETCDF=ON
make
make install

Install MOAB5.3.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cd $HOME/opt
mkdir MOAB5.3.0
cd MOAB5.3.0
export MOAB_DIR=$HOME/opt/MOAB5.3.0
git clone --depth 1 --single-branch -b 5.3.0 https://bitbucket.org/fathomteam/moab moab
mkdir -p build
cd build
cmake ../moab/ -DENABLE_PYMOAB=ON -DCMAKE_INSTALL_PREFIX=$MOAB_DIR -DENABLE_HDF5=ON -DBUILD_SHARED_LIBS=ON -DENABLE_NETCDF=ON -DENABLE_BLASLAPACK=OFF -DENABLE_FORTRAN=OFF
make
make install
echo "export LD_LIBRARY_PATH=$MOAB_DIR/lib:\$LD_LIBRARY_PATH" >> ~/.bashrc
echo "export LIBRARY_PATH=$MOAB_DIR/lib:\$LIBRARY_PATH" >> ~/.bashrc
echo "export CPLUS_INCLUDE_PATH=$MOAB_DIR/include:\$CPLUS_INCLUDE_PATH" >> ~/.bashrc
echo "export C_INCLUDE_PATH=$MOAB_DIR/include:\$C_INCLUDE_PATH" >> ~/.bashrc
echo "export PYTHONPATH=$MOAB_DIR/lib/python3.10/site-packages:$PYTHONPATH" >> ~/.bashrc
source ~/.bashrc

静态库

当需要MOAB的静态库时,把cmake的参数中,设置’-DENABLE_PYMOAB=OFF -DBUILD_SHARED_LIBS=OFF’,其他不变即可。

版本切换

同时安装两个版本的MOAB,使用时可能会因为当前版本不对而出现错误。为了方便切换需要的版本,我进行如下设置:
将下面的这个alias加到$HOME/.bashrc中。

1
alias load_moab51='export LD_LIBRARY_PATH=$MOAB51_DIR/lib:$LD_LIBRARY_PATH && export PATH=$PATH:$MOAB51_DIR/bin'

新打开的Terminal默认使用MOAB5.2,当需要使用MOAB5.1的功能时,执行下面命令即可:

1
load_moab51

Problems

  • I installed MOAB5.1 with pymoab for Python3.6. The pymoab package files are under “…/lib/python3.6/site-packages/“, however, there missed a file “site.py”. It leads to an import error (i.e., python can’t find pymoab module).
    • Solution: install a MOAB5.1 pymoab for python2, and then copy the site.py to “…/lib/python3.6/site-packages/“#. Then problem fixed. This problem happens only on one of my machine, reason not know yet.
  • 安装MOAB5.1后,再安装MOAB5.3,可能出现与上一个问题类似的情况,MOAB5.1的PyMOAB没有正确安装,同样是”…/lib/python3.6/site-packages/“下缺少一个”site.py”文件。从其他地方拷贝一个”site.py”文件到MOAB5.2/lib/python3.6/site-packages/“下就可以解决问题了。
  • Ubuntu22.04之后,Python3是默认Python解释器,配合python-is-python3,可以避免pymoab安装在错误的版本。注意安装使用的python版本,注意PYTHONPATH中的python3.6/8/10。