Use when a task mentions MechSys, tdem, tlbmdem, DEM/Particle/Voronoi optimization, CUDA DEM tests, LBM-DEM, or the MechSys simulation library in this workspace.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of mechsys?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/axtal-mechsys-mechsys)
---
name: mechsys
description: Use when a task mentions MechSys, tdem, tlbmdem, DEM/Particle/Voronoi optimization, CUDA DEM tests, LBM-DEM, or the MechSys simulation library in this workspace.
whenToUse: Any request to inspect, build, benchmark, debug, optimize, or document this MechSys checkout, especially its CPU DEM, CUDA DEM, LBM-DEM, or FLBM paths.
---
# MechSys
This is the visible, downloadable copy of the MechSys skill. DSH discovers
`.agents/skills/mechsys/SKILL.md`; keep the two files in sync.
This is the project-local skill for the MechSys checkout. It is discovered
automatically from `.agents/skills/mechsys`; do not install a separate plugin
just to provide this static guidance.
The authoritative context is:
1. `AGENTS.md` — automatic, concise agent rules.
2. `MECHSYS_HANDBOOK.md` — architecture, build/run commands, exactness
procedure, benchmarks, and known traps.
3. `MEMORY.md` — distilled experience and a short verification checklist.
4. The optimization reports:
- `CPU_DEM_OPTIMIZATION_CHANGES.md`
- `CUDA_OPTIMIZATION_CHANGES.md`
- `REDUCED_TEST_CU_03_PERFORMANCE.md`
- `MPM_OPTIMIZATION_CHANGES.md`
- `CUDA_MPM_OPTIMIZATION_CHANGES.md`
Read the relevant documents before making substantive changes, and update them
when a durable lesson or corrected benchmark is learned.
## Non-negotiable rules
- Do not assume a given checkout or `HEAD` contains the optimized state.
Check `git status`, the reports, and compare against a clean baseline
created from the chosen commit.
- CPU DEM exactness is checked at `Nproc=1` by comparing HDF5 **datasets**, not
whole-file MD5. Expect `neq []` and matching printed energies.
- Preserve candidate-list order and the original `Distance` arithmetic in the
contact path. Do not sort the lists.
- The CPU Verlet cutoff is `Rsum + 4.0*ContactDispGlobal()`. Do not lower it
without a new safe derivation and an exact comparison.
- Broadphase bounds must be conservative. If in doubt, remove a
rejection rather than risk a missed contact.
- CUDA `test_cu_03/04` use `atomicAdd`; the baseline is non-deterministic. Do
not claim bitwise equality for those GPU runs. `Nthread=512` fails for the
current large test; tested range is up to 384.
- CPU MPM exactness is dataset-bitwise at `Nproc=1`; at `Nproc>1` node sums may
reorder. Keep the `Node` hot cache line, the first-touch `VNodes` list and the
cached shape-function multiplication order (see `MPM_OPTIMIZATION_CHANGES.md`).
- CUDA MPM keeps hot node fields in SoA arrays; scatter builds the touched-node
list, reset uses the previous list, and the final `cudaDeviceSynchronize()` in
`Solve` must stay. `ParticleCU` has 64 node slots (cubic limit); GPU atomics
mean no general bitwise claim. The standalone `MPM::Domain::Solve` CPDI
branch is implemented and `tmpm01`/`tmpm_cu_01` now exercise the CPDI
beam; LBMMPM still uses CPU `MPMDOM.OneStepCPI`. See
`CUDA_MPM_OPTIMIZATION_CHANGES.md`.
- Device `F` addressing uses `FLBM::FIDX(Ncells,Nneigh,il,k,ic)` from
`lib/flbm/lbm.cuh`; do not duplicate the direction-major index formula in
test kernels.
- The device 3x3 solver is `Mat3::SolAlt` in `lib/linalg/matvec.h`; do not
duplicate it in LBMMPM kernels.
- LBMMPM CUDA is D3Q15-only and leaves `MPMDOM.OneStepCPI` on the CPU. The
facet marking pass must precede the force pass; build with `--fmad=false`
(CMake targets do) so `Gamma` edge classification matches CPU `SolAlt`.
`Solve` must imprint once after `UpLoadDevice` before the first output, or
`frame 0000` lacks the initial body `Gamma`. Compare HDF5 datasets, not
whole files: at `frame 0000` datasets are exact but HDF5 metadata differs;
after one step the trajectories are not bitwise. `Re`/velocity and t01
deflection agree reasonably; GPU `CD` is not validated because corner `h`
uses `atomicAdd` and a different update order. The 2026-11-06 pass fuses
Rho/Vel into `cudaCollideMPM`, precomputes `1/Cs`/`1/rho`, and defers the
limiter stores; do not replace the fixed-point limiter with a single
`alpha=1` scan (negative-noneq directions can cross later). Full t02
window `Solve` 4.993 -> 4.062 s, full t01 window 10.664 -> 8.938 s.
Keep `pValidNumberPrev`: removing it changed the non-CPDI `tmpm_cu_01`
`.res` by `8.74e-3 m` with no speedup.
- Keep the separate `pTranslate` + `pRotate` fallback. Making fused movement
unconditional broke `test_cu_04`.
- The outer solve loop owns `Time`/`iter`; publish them to CUDA with `SetClock`.
Do not add independent clock increments in DEM or LBM substeps.
- After changing `lib/dem/*`, build at least one CPU target, one CUDA target,
and the relevant LBM-DEM target.
## Rotation caches
`Particle` owns `wrot = Rotation(w,Q)` and `Qc = Conjugate(Q)`. They are
refreshed by `CalcProps`, `InitializeVelocity`, `Rotate`, `UpdateContacts`, and
after a user `Setup` callback.
- CUDA `UploadParticle` copies the host caches; it does not recompute them.
- CUDA `DnloadParticle` copies the device caches back.
- The built-in device movement kernels refresh the device caches after
changing `Q`/`w`.
- A custom GPU movement/rotation kernel that changes `Q`/`w` must refresh
`DPar[].wrot`/`DPar[].Qc` itself.
- Host code that assigns `Q`/`w` directly and bypasses the normal paths must
call `Particle::UpdateRotCache()` before using the caches.
## Build and run
From the repository root:
```bash
cd tdem
make -j8 test_periodic
make -j8 test_cu_01 test_cu_02 test_cu_03 test_cu_04
./test_periodic ../benchmarks/cpu_voronoi/tper_small 8
cd ../tlbmdem
make -j8 tlbmdem01 tlbmdem02
make -j8 tlbmdem_cu_01
```
`test_periodic` takes a FileKey prefix (the `.inp` suffix is appended).
`test_cu_03` takes `Nproc`, Verlet distance, and threads per block:
`./test_cu_03 1 0.05 128`. Full LBM-DEM and CUDA tests are long; use a
temporary reduced copy for smoke tests and do not modify the checked-in test
just to shorten it.
For one-off cases, use the configured standalone compiler:
`./mechsyscc case.cu` from the repository root (or the equivalent
`mechsyscc` in the current installation).
## FLBM / GPU fluid cases
- `lib/flbm/Domain.h` is the fluid LBM; `lib/flbm/lbm.cuh` holds the CUDA
kernels. Use `D2Q9` with `iVec3_t(nx,ny,1)` for a 2-D GPU run.
- The GPU streaming kernel resets `BForce` every step. A constant body force
must be written back to `dom.pBForce` on the device in the `Setup` callback
before collision; setting the host array once is not enough.
- `dom.Nthread` controls the CUDA block size. The `Nproc` argument of
`Domain::Solve` affects host packing/transfers on the GPU path.
- Both active paths (CPU `StreamSC`, GPU fused stream) report the raw second
moment `u = sum_k f_k c_k/rho`; the `+0.5*dt*BForce` velocity is only in the
unused `StreamEFS_SRT`. Do not apply a blind half-force correction - measure
it. A forced channel with bounce-back walls returns the analytical parabola
plus a constant slip `-c(tau)a`, `c = 1/(8 nu) - 6 nu + 1/2`.
- Keep one-off FLBM cases outside the checkout; do not add them to `tflbm/`
unless they belong in the library test suite.
- Obstacle channel case: `/home/sergio/tflbm_triangle/tclbm_obstacle.cu`
(`--shape=rect|tri`, `Re=u_mean*D/nu`, `D=40`, 640x201). Walls are rows 0 and
`ny-1`, so `L=ny-2` and the mirror is `j <-> ny-1-j`; `L=ny-1` breaks
symmetry. At Re=40 both wakes are steady and symmetric: `Lr/D=1.88`
(60x40 rectangle) and `2.88` (triangle); no shedding up to Re=100 at 20%
blockage. `animate.py` writes the GIF with Pillow (no ffmpeg installed).
## After every prompt
This repository is a long-running engineering notebook. Before the final
response, evaluate whether the prompt produced a new durable fact:
- short invariant or operational rule -> `AGENTS.md`;
- architecture, command, exactness procedure, or trap ->
`MECHSYS_HANDBOOK.md`;
- distilled experience or checklist -> `MEMORY.md`;
- design or measurement -> the relevant optimization report;
- task-triggered guidance -> this skill and its mirror, kept in sync.
Record only durable, verified facts, with the exact input, thread count, and
time window for benchmarks. Do not add transient logs or guesses, and do not
manufacture an edit when nothing was learned. Run `git diff --check`; never
commit or push unless explicitly asked. Mention the memory file changed in the
final response, or state that no update was needed.
## Reporting
Report measured wall times, separate solve time from total wall time, and
explicitly distinguish what compiled, what ran, what matched a baseline, and
what was faster. If a verification was not done, say so.