LAMMPS MACHDYN 包 compute smd/ulsph/strain 命令详解:ULSPH 粒子对数应变张量的计算与输出
LAMMPS MACHDYN 包 compute smd/ulsph/strain 命令详解:ULSPH 粒子对数应变张量的计算与输出
本篇指南围绕 LAMMPS MACHDYN(Smooth Mach Dynamics)包中的 compute smd/ulsph/strain 命令展开,介绍其语法、输出格式与底层实现原理。该命令为使用 updated Lagrangian SPH(更新拉格朗日 SPH,简称 ULSPH)对风格的粒子输出对数应变张量,是分析大变形流体/固体材料变形状态的关键后处理工具。读者阅读后能够:正确声明该 compute、理解 6 分量应变张量的物理含义与无量纲输出约定、掌握通过 dump/thermo 提取该张量的方法,并了解其数据来源(atom->smd_data_9 累加场)与 pair smd/ulsph 的协作机制。
命令语法与示例
compute smd/ulsph/strain 的语法与其他 LAMMPS compute 命令一致,只有三个必填参数:
compute ID group-ID smd/ulsph/strain
ID:compute 的用户自定义标识符,用于后续c_ID[...]引用;group-ID:需要计算应变的粒子组;smd/ulsph/strain:该 compute 的 style 名称。
最小示例:
compute 1 all smd/ulsph/strain
该命令声明后,会为组内每个粒子计算一个逐粒子(per-atom)张量,供 dump、thermo、fix 等一切接受 per-particle 数值作为输入的 LAMMPS 命令使用。关于 per-particle 输出的整体机制,可参考 Howto output 页面。
功能定位:对数应变张量
该 compute 定义了一个计算任务,输出对数应变张量(logarithmic strain tensor),它只对通过 updated Lagrangian SPH 对风格相互作用的粒子有效。这与 MACHDYN 包中另一支 Total-Lagrangian SPH(TLSPH)形成对照——TLSPH 对应的 compute smd/tlsph/strain 输出的是 Green-Lagrange 应变张量:
| compute 命令 | 对应 SPH 对风格 | 输出张量 | 参考构型 |
|---|---|---|---|
smd/ulsph/strain |
pair smd/ulsph(updated Lagrangian) |
对数应变 | 随粒子运动更新的当前构型 |
smd/tlsph/strain |
pair smd/tlsph(total Lagrangian) |
Green-Lagrange 应变 | 固定的初始构型 |
在 MACHDYN 框架中,两者分别服务于“流体 / 大变形体用 ULSPH、固体用 TLSPH”的典型分工。例如 fluid_structure_interaction 示例 中,水柱采用 pair_style smd/ulsph(更新拉格朗日格式),固体物体采用 pair smd/tlsph(总拉格朗日格式),而 compute 的选择与对风格一一对应。
MACHDYN 用户手册
Smooth Mach Dynamics 的完整理论背景与使用指南见随仓库分发的 PDF 手册:MACHDYN_LAMMPS_userguide.pdf。
输出信息:6 分量的对称应变张量
该 compute 输出一个逐粒子张量,每个粒子的结果是一个 6 分量向量,对应对称应变张量的独立分量,排列顺序为:
| 下标 | 分量 | 含义 |
|---|---|---|
| 1 | xx |
法向应变(x 方向) |
| 2 | yy |
法向应变(y 方向) |
| 3 | zz |
法向应变(z 方向) |
| 4 | xy |
剪切应变(x–y 平面) |
| 5 | xz |
剪切应变(x–z 平面) |
| 6 | yz |
剪切应变(y–z 平面) |
所有数值为无量纲(dimensionless),不受 units 设置影响。这与应变作为长度之比的定义一致,也与其他 MACHDYN 应变类 compute(如 smd/tlsph/strain)的输出约定相同。
在 dump 中逐分量输出时,可用如下写法:
dump d1 all custom 100 dump.strain id type x y z &
c_1[1] c_1[2] c_1[3] c_1[4] c_1[5] c_1[6]
其中 c_1[...] 中的 1 即 compute 1 all smd/ulsph/strain 的 ID。也可通过 thermo_style custom 结合 compute reduce 输出组平均值,例如:
compute sxx all reduce sum c_1[1]
从源码看数据流:应变从何处来
要正确使用该 compute,有必要理解它的底层数据来源。看实现文件 compute_smd_ulsph_strain.cpp:
- 构造函数要求
narg == 3,即只有compute ID group-ID smd/ulsph/strain三个参数,多余参数会触发Illegal compute smd/tlsph_strain command错误; - 声明
peratom_flag = 1与size_peratom_cols = 6,即逐粒子、每粒子 6 列; compute_peratom()中直接读取atom->smd_data_9(atom->smd_data_9是 atom 数据中的 9 维 per-atom 数组,见 atom.h),将其前 6 个元素拷贝到strainVector[i][0..5];- 组外粒子(mask 不匹配)的应变分量被清零。
关键点是:该 compute 本身不求解应变,它只是把 smd_data_9 中已累加好的对数应变“读出来”。真正的应变累积发生在 pair_smd_ulsph.cpp 的 PairULSPH::PreCompute() 中:
// accumulate strain increments
// we abuse the atom array "atom_data_9" for this purpose
D = update->dt * 0.5 * (L[i] + L[i].transpose());
atom_data9[i][0] += D(0, 0); // xx
atom_data9[i][1] += D(1, 1); // yy
atom_data9[i][2] += D(2, 2); // zz
atom_data9[i][3] += D(0, 1); // xy
atom_data9[i][4] += D(0, 2); // xz
atom_data9[i][5] += D(1, 2); // yz
这段代码位于 pair_smd_ulsph.cpp。可以看到:
- 每个时间步,ULSPH 对风格由速度梯度
L = ∇v构造对称化应变率张量D = 0.5·(L + Lᵀ); - 乘以当前时间步长
update->dt得到应变增量,逐时步累加到atom_data9的前 6 个分量中; - 因此该 compute 输出的是从开始运行(或应变清零)至今的累积对数应变,而不是瞬时应变率——瞬时变化率请使用相关的 compute smd/ulsph/strain/rate,它通过
force->pair->extract("smd/ulsph/velocityGradient_ptr", ...)读取速度梯度并即时计算0.5·(L + Lᵀ)。
这也解释了该 compute 的两个隐含前提:
- 必须启用速度梯度计算:ULSPH 对风格默认关闭速度梯度(
velocity_gradient_required = false),只有设置了*VELOCITY_GRADIENT关键字或使用强度/粘度模型时才开启(见 pair_smd_ulsph.cpp)。要输出有意义的应变,pair 设置中应包含*VELOCITY_GRADIENT; - 必须存在匹配的对风格:若对风格不提供相关数据,
compute smd/ulsph/strain/rate会直接报错“could not access any velocity gradients. Are the matching pair styles present?”,smd/ulsph/strain同理只对pair smd/ulsph粒子有意义。
从 compute_smd_ulsph_strain.h 的注册宏 ComputeStyle(smd/ulsph/strain, ComputeSMDULSPHstrain) 可以确认,该命令在 MACHDYN 包中通过 ComputeStyle 工厂机制注册,随包一同编译。
限制条件
使用 compute smd/ulsph/strain 必须满足:
- 需要 MACHDYN 包:该 compute 是 MACHDYN 包的一部分,仅当 LAMMPS 以该包编译时才可用。构建方法参见 Build package 页面(CMake 下通常为
-D PKG_MACHDYN=yes,传统 make 下为make yes-machdyn); - 仅适用于 ULSPH 粒子:只能对与 updated Lagrangian SPH 对风格(
pair smd/ulsph)相互作用的粒子使用。对 TLSPH 粒子请改用 compute smd/tlsph/strain,对其它对风格粒子该输出无意义(返回 0 或无数据); - 该 compute 没有额外的关键字或默认参数(
Default: none)。
参数解析与错误检查
从 compute_smd_ulsph_strain.cpp 可见,构造函数用 narg != 3 严格校验参数个数;init() 中还会通过 modify->get_compute_by_style("^smd/ulsph/strain$") 检查是否同时声明了多个同名 compute,若有多个会给出警告。这些是排错时值得留意的细节。
实战:在 ULSPH 模拟中输出应变
下面结合仓库中的 ULSPH 示例,给出一个可运行的完整脉络。参考 funnel_flow 示例(STL 几何中的 ULSPH 水流)与 fluid_structure_interaction 示例(ULSPH 水 + TLSPH 固体的流固耦合),一个声明 smd/ulsph/strain 的典型片段为:
units si
atom_style smd
comm_modify vel yes
newton off
# ULSPH 对风格:开启速度梯度计算(应变输出依赖它)
pair_style hybrid/overlay smd/ulsph *DENSITY_CONTINUITY *VELOCITY_GRADIENT *NO_GRADIENT_CORRECTION &
smd/tri_surface 1.0
pair_coeff 1 1 smd/ulsph *COMMON ${rho} ${c0} ${q1} ${cp} ${hg} &
*EOS_TAIT 2 &
*END
# 时间积分:ULSPH 粒子必须使用对应的积分 fix
fix dtfix all smd/adjust_dt 0.1
fix integration all smd/integrate_ulsph adjust_radius 1.01 10 15
# 声明应变 compute
compute strain all smd/ulsph/strain
# 输出:每个粒子的 6 个应变分量
dump d_strain all custom 100 dump.strain id type x y z &
c_strain[1] c_strain[2] c_strain[3] &
c_strain[4] c_strain[5] c_strain[6]
dump_modify d_strain first yes
要点归纳:
comm_modify vel yes必须开启:ULSPH 需要交换速度信息以构造速度梯度;smd/integrate_ulsph是 ULSPH 粒子的标准积分器(见 fix_smd_integrate_ulsph.h),adjust_radius 1.01 10 15为可选的自适应光滑半径参数;- 应变是时步累积量:若要对比不同阶段的变形,注意合理设置 dump 频率与
run步数; - 应变分量均为无量纲数,可在 dump 后直接用 Ovito / ParaView 等工具按 6 分量绘制应变场云图。
相关命令
- compute smd/tlsph/strain:TLSPH 粒子的 Green-Lagrange 应变(参考构型固定,适用于固体);
compute smd/ulsph/strain/rate:ULSPH 应变率张量(瞬时值,读取对风格的velocityGradient_ptr);compute smd/ulsph/stress、compute smd/ulsph/effm:ULSPH 应力张量与等效弹性模量,可与应变配合构成完整的本构输出;compute smd/tlsph/strain/rate、compute smd/tlsph/stress:TLSPH 侧的对应输出。
小结
compute smd/ulsph/strain 是 MACHDYN 包中读取 ULSPH 粒子累积对数应变的标准接口:它以 6 分量对称张量形式输出无量纲应变,数据由 pair smd/ulsph 在 PreCompute() 中逐时步累加进 atom->smd_data_9,本 compute 仅负责按组筛选与导出。使用前请确认:LAMMPS 已编译 MACHDYN 包、对风格为 pair smd/ulsph 且开启了 *VELOCITY_GRADIENT(或强度/粘度模型)、积分器为 fix smd/integrate_ulsph。遵循这些前提,即可在大变形 SPH 模拟中稳定地追踪每个粒子的累积变形状态。