comsol-mph-analyzer

star 5

COMSOL Multiphysics toolkit for .mph model analysis, input preparation, mesh/geometry editing, and MCP connectivity. Use when (1) user provides a .mph file and wants to understand its contents, (2) preparing simulation inputs or parameter sweeps, (3) modifying .mph parameters without COMSOL, (4) generating Java API code from .mph models, (5) editing mphtxt mesh or STL geometry files (translate, rotate, scale, mirror), (6) converting STL to COMSOL mphtxt format, (7) checking COMSOL installation and MCP readiness, (8) setting up COMSOL MCP server for Claude control. Triggers on: .mph files, COMSOL model, analyze mph, parameter sweep, comsolbatch, mesh editing, STL editing, mphtxt, COMSOL MCP, simulation inputs.

wjgoarxiv By wjgoarxiv schedule Updated 2/26/2026

name: comsol-mph-analyzer description: "COMSOL Multiphysics toolkit for .mph model analysis, input preparation, mesh/geometry editing, and MCP connectivity. Use when (1) user provides a .mph file and wants to understand its contents, (2) preparing simulation inputs or parameter sweeps, (3) modifying .mph parameters without COMSOL, (4) generating Java API code from .mph models, (5) editing mphtxt mesh or STL geometry files (translate, rotate, scale, mirror), (6) converting STL to COMSOL mphtxt format, (7) checking COMSOL installation and MCP readiness, (8) setting up COMSOL MCP server for Claude control. Triggers on: .mph files, COMSOL model, analyze mph, parameter sweep, comsolbatch, mesh editing, STL editing, mphtxt, COMSOL MCP, simulation inputs."

COMSOL Toolkit

4-module toolkit for COMSOL Multiphysics workflows. Python stdlib only (no external packages required).

Module 1: Value Extraction

Extract parameters, physics, materials, species, geometry, and metadata from .mph files.

python scripts/analyze_mph.py model.mph                  # Full report
python scripts/analyze_mph.py model.mph --parameters     # Parameters table
python scripts/analyze_mph.py model.mph --physics        # Physics interfaces
python scripts/analyze_mph.py model.mph --json           # All data as JSON
python scripts/analyze_mph.py model.mph --tree           # Model tree
python scripts/analyze_mph.py model.mph --export-xml DIR # Extract XML/JSON files

See references/mph_format.md for .mph file format details.

Module 2: Input Preparation

Prepare simulation inputs: parameter files, .mph XML modification, Java API code generation.

# Parameter file generation
python scripts/prepare_inputs.py model.mph --extract                          # Extract as JSON
python scripts/prepare_inputs.py model.mph --paramfile out.txt                # comsolbatch format
python scripts/prepare_inputs.py model.mph --paramfile out.txt --set "T_in=950[K]"  # Override
python scripts/prepare_inputs.py model.mph --sweep "T_in=800[K]:50[K]:1000[K]" --paramfile-dir ./sweep/

# Direct .mph XML modification (no COMSOL needed)
python scripts/modify_mph_xml.py input.mph output.mph --set "T_in=950[K]"
python scripts/modify_mph_xml.py input.mph output.mph --from-json overrides.json
python scripts/modify_mph_xml.py input.mph --diff   # Dry run

# Java API code generation
python scripts/generate_java.py model.mph                        # Print to stdout
python scripts/generate_java.py model.mph --output Model.java    # Write to file
python scripts/generate_java.py model.mph --class-name SteamReformer

See references/input_preparation.md for comsolbatch CLI and workflow details.

Module 3: MCP Connectivity

Check COMSOL environment and set up MCP server for Claude-controlled simulation.

python scripts/check_comsol.py          # Diagnostic report
python scripts/check_comsol.py --json   # JSON output

See references/mcp_setup.md for server setup and references/mcp_tools.md for tool reference.

Module 4: 3D Morphology Edit

Edit mphtxt mesh and STL geometry files programmatically.

# mphtxt mesh editing
python scripts/edit_mphtxt_mesh.py mesh.mphtxt --info
python scripts/edit_mphtxt_mesh.py mesh.mphtxt --translate 0.1 0 0 -o out.mphtxt
python scripts/edit_mphtxt_mesh.py mesh.mphtxt --scale 2.0 -o out.mphtxt
python scripts/edit_mphtxt_mesh.py mesh.mphtxt --rotate 90 0 0 1 -o out.mphtxt
python scripts/edit_mphtxt_mesh.py mesh.mphtxt --mirror 1 0 0 -o out.mphtxt

# STL editing
python scripts/edit_stl.py model.stl --info
python scripts/edit_stl.py model.stl --translate 0.1 0 0 --scale 2 -o out.stl
python scripts/edit_stl.py model.stl --rotate 90 0 0 1 -o out.stl
python scripts/edit_stl.py model.stl --to-mphtxt out.mphtxt  # Convert STL -> COMSOL mesh

See references/geometry_formats.md for format specifications.

Capabilities Matrix

Capability COMSOL Required Script
Extract parameters/physics/materials No analyze_mph.py
Generate parameter files No prepare_inputs.py
Modify .mph parameters No modify_mph_xml.py
Generate Java API code No generate_java.py
Check COMSOL environment No check_comsol.py
Edit mphtxt mesh No edit_mphtxt_mesh.py
Edit STL geometry No edit_stl.py
Run simulations via MCP Yes (MCP server)
Compile/run Java models Yes (comsolbatch)

Limitations

  • Cannot read binary .mphbin data (geometry coordinates inside .mph, mesh solutions)
  • Cannot run simulations without COMSOL installation
  • Cannot edit Parasolid geometry (.mphtxt geometry format is binary-encoded)
  • Cannot edit STEP files without cadquery/OCP
  • Password-protected .mph files cannot be analyzed
Install via CLI
npx skills add https://github.com/wjgoarxiv/comsol-mph-analyzer --skill comsol-mph-analyzer
Repository Details
star Stars 5
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator