如何在Ubuntu系统使用Karamelo(物质点法)开源包

Karamelo项目是Parallel Material Point Method Simulator,原地址为:https://adevaucorbeil.github.io/karamelo/html/GettingStarted.html

2023/2/14更新:

作者已经更新了,ubuntu的版本不进行限制,并且编译很简单。
https://github.com/adevaucorbeil/karamelo
直接看根目录 Install.txt 的编译过程即可,不再赘述。

以下是旧教程,已废弃

首先,Ubuntu系统的版本必须是16.04LTS或者18.04LTS,否则将会运行失败。阿里云的Ubuntu系统镜像下载地址:https://mirrors.aliyun.com/ubuntu-releases/

我使用18.04LTS编译并运行的,下面我将一步一步展示我是如何做的。

1.调出终端,输入:sudo apt-get update ,回车

在这里插入图片描述
2. 在终端里输入:sudo apt-get install git , 回车

在这里插入图片描述
3. 在终端输入:
sudo apt install make gcc g++ libz-dev cmake libopenmpi-dev libeigen3-dev libboost-dev python-dev python-matplotlib ,回车

在这里插入图片描述
4. 在主目录下创建code文件夹,我们将这次的代码全都放进这里面去,当然文件夹的名字是随意的。

在这里插入图片描述
5. 进入code文件夹,在文件夹空白处右键,点击在终端打开,然后在终端里输入:git clone https://github.com/lava/matplotlib-cpp.git ,回车。下载完成以后,进入到matplotlib-cpp文件夹,右键打开终端,输入:git checkout f4ad842e

在这里插入图片描述在这里插入图片描述
4. https://github.com/kanedo/gzstream打开此连接,下载压缩包到code文件夹,解压缩。进入gzstream-master文件夹,右键打开终端,输入make,回车

在这里插入图片描述
7. 在code文件夹打开终端,输入:git clone https://github.com/adevaucorbeil/karamelo.git ,回车,下载完成后进入karamelo-master文件夹,此时,我们就要对编译整个项目进行准备工作了。

CPATH=$CPATH:/usr/include/eigen3:/home/max/code/gzstream-master:/home/max/code/matplotlib-cpp:/usr/include/python2.7
export CPATH
LIBRARY_PATH=$LIBRARY_PATH:/usr/include/eigen3:/home/max/code/gzstream-master:/home/max/code/matplotlib-cpp:/usr/include/python2.7
export LIBRARY_PATH

这四行代码是环境变量,需要根据自己的系统进行修改,实际上需要修改的为:/home/max/code/gzstream-master/home/max/code/matplotlib-cpp 将替换为code文件夹中两个库的路径。

8.替换好环境变量路径以后,在karamelo-master文件夹打开终端,输入:刚才替换好路径的四行代码,回车,再输入cmake -DCMAKE_BUILD_TYPE=release build . ,回车,再输入make ,回车,等待编译完成。

在这里插入图片描述
不要忘记make,图片里没有

9 . 复制下面的代码到一个新建的文本文件,文件名改成two-disks.mpm ,并且创建一个单独的文件夹将此算例放进去,因为运算过程中会产生大量文件。

#####################################################
#               UNITS: MPa, mm, s                   #
#####################################################
E   = 1e+3
nu  = 0.3
rho = 1000
K      = E/(3*(1-2*nu))
mu     = E/(2*(1+nu))
lambda = E*nu/((1+nu)*(1-2*nu))
c      = sqrt(E/rho)
L    = 1
hL   = 0.5*L
A_zy = L*L
FLIP=1.0
#---------- SET METHOD --------------#
method(ulmpm, FLIP, linear, FLIP)
N        = 20     # 20 cells per direction
cellsize = L/N    # cell size
# 2D problem, which the computational domain is
dimension(2,-hL, hL, -hL, hL, cellsize)
# solids (2 balls)
R = 0.2
region(rBall1, cylinder, -hL+R, -hL+R, R)
region(rBall2, cylinder, hL-R, hL-R, R)
material(mat1, linear, rho, E, nu)
#---------- SET SOLID --------------#
ppc1d = 2
solid(sBall1, region, rBall1, ppc1d, mat1, cellsize,0)
solid(sBall2, region, rBall2, ppc1d, mat1, cellsize,0)
#---------- IMPOSE INITIAL CONDITIONS --------------#
group(gBall1, particles, region, rBall1, solid, sBall1)
group(gBall2, particles, region, rBall2, solid, sBall2)
v = 0.1
fix(v0Ball1, initial_velocity_particles, gBall1, v, v, NULL)
fix(v0Ball2, initial_velocity_particles, gBall2, -v, -v, NULL)
#-----------OUTPUT-------------------------------------#
N_log = 50
dumping_interval = N_log*1
dump(dump1, all, particle, dumping_interval, dump_p.*.LAMMPS, x, y, z)
dump(dump2, all, grid, dumping_interval, dump_g.*.LAMMPS, x, y, z)
fix(Ek, kinetic_energy, all)
fix(Es, strain_energy, all)
Etot = Ek_s + Es_s
#----------- RUN --------------------#
set_dt(0.001)
log_modify(custom, step, dt, time, Ek_s, Es_s)
plot(Ek, N_log, time, Ek_s)
plot(Es, N_log, time, Es_s)
plot(Etot, N_log, time, Etot)
save_plot(plot.pdf)
set_output(N_log)
run_time(3.5)

10 . 在包含two-disks.mpm的文件夹打开终端,输入:mpirun -np 4 /home/max/code/karamelo-master/karamelo -i two-disks.mpm ,其中,4代表要用到的cpu线程数。当然,程序的路径也需要根据自己的设备修改。

算例的结果就是下面的样子了。

在这里插入图片描述

有什么讲的不清楚的地方请您在评论区留言。

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值