This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ESPDComponents is a Julia library for modeling physical systems (thermal, mechanical, electrical) using the Dyad modeling language. Dyad is a domain-specific language that compiles to Julia code using ModelingToolkit.jl for symbolic equation handling and simulation.
Critical: The generated/ directory contains auto-generated Julia code from Dyad source files. Never edit files in the generated/ directory directly - they will be overwritten by the Dyad compiler. Always modify the .dyad source files in the dyad/ directory instead.
-
Dyad Models (
dyad/*.dyad) - Source of truth for component definitions- Written in declarative Dyad language
- Define components with parameters, variables, and relations (equations)
- Include metadata for tests, visualizations, and UI placement
- Organized into subdirectories (e.g.,
dyad/TestModule/,dyad/Lectures/)
-
Generated Julia Code (
generated/*.jl) - Auto-generated, do not editgenerated/definitions.jl- ModelingToolkit component definitionsgenerated/experiments.jl- Analysis/simulation definitionsgenerated/types.jl- Type definitionsgenerated/tests.jl- Test cases from Dyad metadatagenerated/precompilation.jl- Precompilation directivesgenerated/module.jl- Entry point that includes all generated files- Subdirectories mirror
dyad/structure (e.g.,generated/Lectures/,generated/TestModule/)
-
Module Entry (
src/ESPDComponents.jl)- Thin wrapper that includes
generated/module.jl - The actual module logic lives in generated code
- Thin wrapper that includes
A typical Dyad component includes:
- Parameters: Configurable inputs with types and defaults (e.g.,
parameter T_inf::Temperature = 300) - Variables: State variables that evolve over time (e.g.,
variable T::Temperature) - Relations: Differential equations and constraints (e.g.,
m * c_p * der(T) = h * A * (T_inf - T)) - Initial conditions: Set in relations block (e.g.,
initial T = T0) - Metadata: JSON-formatted test cases, placement info, visualization specs
Analysis blocks define simulation experiments:
analysis World
extends TransientAnalysis(stop = 10)
model = Hello(T_inf = T_inf, h = h)
parameter T_inf::Temperature = 300
parameter h::CoefficientOfHeatTransfer = 0.7
end
These become callable Julia functions returning simulation results.
# Start Julia REPL (in VS Code: "Julia: Start REPL" from command palette)
julia
# In Julia REPL, enter package mode
]
# Install dependencies (first time only, may take a while)
pkg> instantiate
# Exit package mode
<Backspace># In Julia package mode
pkg> test
# Or from Julia REPL
julia> using Pkg; Pkg.test()Tests are defined in Dyad metadata and auto-generated to generated/tests.jl. The test harness is in test/runtests.jl.
# Load the module
using ESPDComponents
# Run a simulation (analysis name becomes a function)
result = World()
# Run with custom parameters
result = World(stop=20, k=4)
# Visualize results
using Plots
plot(result)
# Plot specific analysis with parameters
plot(World(stop=20, k=4))# List available signals/artifacts
using DyadInterface
Dict(string(s) => DyadInterface.artifacts(result, s) for s in DyadInterface.artifacts(result))
# Get metadata about result
res_meta = AnalysisSolutionMetadata(result)
println(res_meta.allowed_symbols)# Create custom Plotly visualization
vizdef = PlotlyVisualizationSpec(
res_meta.allowed_symbols[[2, 1]],
(;),
[Attribute("tstart", "start time", 0.0)]
)
customizable_visualization(result, vizdef)See: https://help.juliahub.com/dyad/dev/manual/advanced/custom_analysis.html#Customizable-Visualizations
- ModelingToolkit.jl: Symbolic equation system for physical modeling
- DyadInterface.jl: Interface between Dyad and Julia
- DyadExampleComponents.jl: Pre-built components (MassSpringDamper, RoadData, etc.)
- BlockComponents.jl: Signal processing blocks (Gain, Add, Derivative, Integrator, etc.)
- TranslationalComponents.jl: Linear mechanical components (Force, PositionSensor, etc.)
- RotationalComponents.jl: Rotational mechanical components
- OrdinaryDiffEqDefault.jl: ODE solver
- Plots.jl: Visualization
-
Edit the
.dyadfile in thedyad/directory -
The Dyad Studio VS Code extension automatically recompiles to
generated/ -
Reload the Julia module:
# In Julia REPL using Pkg; Pkg.activate(".") using ESPDComponents
-
Run tests or simulations to verify changes
The analysis/ directory contains Pluto.jl notebooks for interactive exploration:
analysis/active-suspension.pluto.jl- ActiveSuspension model analysis
To use:
utilize pluto notebook MCP server for cell and code manipulation, for validation use execute_code tool, to learn how to use Pluto use learn_pluto_basic tool
- "Method not found" errors: The generated code may be stale. Check that Dyad Studio has recompiled after your changes to
.dyadfiles. - Precompilation is slow: First-time compilation of ModelingToolkit and differential equation solvers can take several minutes.
- Simulation is slow on first run: Julia uses JIT compilation, so the first simulation run compiles the specific numerical code. Subsequent runs will be fast.