| name | add-physics-quantity |
|---|---|
| description | Add a new physics quantity type with units, dimensions, operators, and tests to the source-generated system |
| disable-model-invocation | true |
Add a new physics quantity to the source-generated physics system. This is a fully metadata-driven process - no C# code needs to be written manually.
Before starting, gather from the user:
- Quantity name (e.g., "Viscosity", "MagneticFlux")
- Physical dimension symbol (e.g., "M L⁻¹ T⁻¹")
- Dimensional formula (exponents for mass, length, time, temperature, current, amount, luminosity)
- SI unit name and symbol (e.g., "Pascal" / "Pa")
- Which vector forms are needed (magnitude only, or 1D/2D/3D/4D)
- Physics relationships - what other quantities multiply/divide to produce this one
- Any semantic overloads (named aliases like Weight for ForceMagnitude)
File: Semantics.SourceGenerators/Metadata/dimensions.json
Add a new entry to the physicalDimensions array following the existing pattern. Each dimension needs:
name: PascalCase dimension namesymbol: Unicode dimension symboldimensionalFormula: object with exponents for base dimensionsavailableUnits: array of unit names (must match units.json entries)quantities: object defining vector forms (vector0 = magnitude, vector1-4 = directional)integrals: array of{other, result}pairs whereSelf * Other = Resultderivatives: array of{other, result}pairs whereSelf / Other = ResultdotProducts: array for dot product relationships (vector forms only)crossProducts: array for cross product relationships (vector3 forms only)
Important: The generator automatically creates inverse operators. If you define Force * Length = Energy on Force, the generator also creates Energy / Length = Force and Energy / Force = Length on Energy.
File: Semantics.SourceGenerators/Metadata/units.json
Add unit entries to the appropriate unitCategories entry, or create a new category. Each unit needs:
name: PascalCase unit namesymbol: unit symbol stringdescription: brief descriptionsystem: one of "SIBase", "SIDerived", "Imperial", "USCustomary", "CGS", "Other"
File: Semantics.SourceGenerators/Metadata/conversions.json
Add conversion factor entries for converting between unit systems. Each factor needs:
name: descriptive PascalCase name (e.g., "CalorieToJoules")description: includes the exact numeric valuevalue: string representation of the conversion factor
File: Semantics.SourceGenerators/Metadata/domains.json
If the quantity involves physical constants, add them to the relevant domain entry.
cd Semantics.Quantities && dotnet buildThe source generator will create:
- Quantity classes for each vector form in
Generated/ - Updated
PhysicalDimensions.g.cswith dimension metadata - Updated
Units.g.cswith unit definitions - Operator overloads for all defined physics relationships
dotnet testVerify all existing tests still pass and the new quantity types are correctly generated.
- Dimensional formula exponents sum correctly for the physical dimension
- Physics relationships are dimensionally consistent (check both sides of equations)
- Inverse operators are NOT manually added (generator handles them automatically)
- Unit symbols follow standard conventions
-
availableUnitsentries matchunits.jsonunit names exactly - No circular dependencies in physics relationships