Skip to content

Add agent skill for generating nekRS case files from physics descriptions#699

Draft
mahdikooshkbaghi wants to merge 2 commits into
Nek5000:masterfrom
mahdikooshkbaghi:udf-skill-generator
Draft

Add agent skill for generating nekRS case files from physics descriptions#699
mahdikooshkbaghi wants to merge 2 commits into
Nek5000:masterfrom
mahdikooshkbaghi:udf-skill-generator

Conversation

@mahdikooshkbaghi

@mahdikooshkbaghi mahdikooshkbaghi commented Apr 5, 2026

Copy link
Copy Markdown

Summary

Adds an Agent Skill that generates nekRS simulation case files (.par, .udf, .oudf) from natural language physics descriptions. Users describe their simulation setup (Reynolds number, boundary conditions, turbulence model, fluid properties, etc.) and the skill produces ready-to-run case files following established codebase patterns.

This is a first version of this skill and it can improve based on feedbacks and edge cases.

What's included

.claude/skills/udf-generator/
├── SKILL.md                           # Workflow, gotchas, templates
└── references/
    ├── PAR_REFERENCE.md               # Complete .par file keys and valid values
    ├── UDF_PATTERNS.md                # UDF callback patterns by physics type
    └── BOUNDARY_CONDITIONS.md         # bcData struct, BC function signatures

Supported physics categories

  • Laminar / Stokes flow
  • Turbulent flow (DNS/LES with regularization)
  • RANS k-tau SST (with inlet turbulence, optional temperature)
  • Heat transfer (constant and variable properties, conjugate HT)
  • Low-Mach variable density
  • Moving mesh (ALE)
  • Lagrangian particle tracking

How it works

  1. Extracts flow conditions, boundary types, and models from the user's prompt
  2. Asks clarifying questions for missing critical information
  3. Generates .par, .udf, and .oudf files under examples/<caseName>/
  4. Validates cross-file consistency (boundary maps, scalar names, field handlers)

All generated code follows patterns from existing examples (periodicHill, ethier, turbPipePeriodic, etc.) and respects project conventions (include paths, IC sizing, compile-time constants via kernelInfo.define()).

Provides an agent skill that generates .udf, .par, and .oudf files
from user physics descriptions (Reynolds number, boundary conditions,
turbulence models, etc.). Includes reference material for par file
options, UDF callback patterns, and boundary condition signatures.
- Fix include paths to match existing examples (short form)
- Use kernelInfo.define() for constant BCs instead of usrwrk
- Add RANS patterns: minimal, inlet turbulence, with temperature
- Use fieldOffsetSum for velocity IC vectors
- Add gotchas: stopAt, userSections, CFL defaults, no dead code
- Update minimal .par template with CASEDATA section
@mahdikooshkbaghi mahdikooshkbaghi changed the title Udf skill generator Add agent skill for generating nekRS case files from physics descriptions Apr 5, 2026
@mahdikooshkbaghi mahdikooshkbaghi marked this pull request as draft April 5, 2026 22:32
@mahdikooshkbaghi

Copy link
Copy Markdown
Author

Skill Demo

Here is a demo in case this PR for skills is merged to main.

In this demo we:

  1. Create a new branch locally (turbulent-pipe-with-skills)
  2. Prompt Claude Code with the simulation conditions using the /udf-generator skill
  3. The skill asks clarifying questions if something is missing, and flags inconsistencies (e.g., in this case it caught a Reynolds
    number mismatch between the stated Re and the given fluid properties)
  4. The agent first asks permission to create a directory under examples/ for the case, then writes the complete .par and .udf files

Here are the files that generated for the following prompt:

/udf-generator Set up a nekRS case for turbulent incompressible flow in a pipe.
    Reynolds number is 8000 based on pipe diameter D=4mm.
    The fluid is air at 150°C (density ~0.835 kg/m³, dynamic viscosity ~2.38e-5 Pa·s).
    Inlet velocity is 15 m/s with a uniform profile.
    Boundary conditions: inflow (udfDirichlet), outflow (zeroNeumann), and no-slip wall (zeroDirichlet).
    Use RANS k-tau SST turbulence model with inlet turbulence intensity of 6%.
    Name the case turbulent_pipe.

turbulen_pipe.udf: https://github.com/mahdikooshkbaghi/nekRS/blob/turbulent-pipe-with-skills/examples/turbulent_pipe/turbulent_pipe.udf

turbulent_pipe.par: https://github.com/mahdikooshkbaghi/nekRS/blob/turbulent-pipe-with-skills/examples/turbulent_pipe/turbulent_pipe.par

Notes:

  • The skill can be triggered manually with the /udf-generator slash command, but Claude is usually smart enough to trigger it automatically when the prompt matches.

  • Portability to other coding agents
    This skill can easily be used with other coding agents like gemini-cli, codex, open-code, etc. A couple of approaches:

udf-generator-skill.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant