{
  "schemaVersion": 1,
  "slug": "compression-ratio-calculator",
  "category": "automotive",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "62f5f75bc05847be40f43830559503eb8f726288e40e904aa2a2e606f4570bdd",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/compression-ratio-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "CR = (V_s + V_c) ÷ V_c; V_s = π × (bore ÷ 2)² × stroke × 16.387",
    "vars": [
      [
        "bore",
        "bore diameter in inches"
      ],
      [
        "stroke",
        "stroke length in inches"
      ],
      [
        "V_s",
        "swept volume per cylinder in cc"
      ],
      [
        "V_c",
        "clearance volume in cc"
      ],
      [
        "CR",
        "compression ratio"
      ]
    ],
    "note": "Uses swept cylinder volume plus clearance volume. Cylinder count must be a whole number from 1 to 16; dimensions and clearance must be positive."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const empty={sweptVolumeCc:null,totalDisplacement:null,compressionRatio:null,requiredClearance:null};const b=Number(bore),s=Number(stroke),v=Number(clearance),n=Number(cylinders),target=Number(targetRatio);if(![b,s,v,n,target].every(Number.isFinite)||b<=0||s<=0||v<=0||!Number.isInteger(n)||n<1||n>16||target<=1)return{...empty,__error:'inputError'};const swept=Math.PI*(b/2)**2*s*16.387064,ratio=(swept+v)/v,requiredClearance=swept/(target-1);return{sweptVolumeCc:swept,totalDisplacement:swept*n,compressionRatio:ratio,requiredClearance};",
    "inputs": [
      {
        "name": "bore",
        "type": "number",
        "default": 3.5,
        "min": 0.5,
        "max": 12,
        "step": 0.01,
        "slider": true
      },
      {
        "name": "stroke",
        "type": "number",
        "default": 3.5,
        "min": 0.5,
        "max": 12,
        "step": 0.01,
        "slider": true
      },
      {
        "name": "clearance",
        "type": "number",
        "default": 60,
        "min": 1,
        "max": 500,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "cylinders",
        "type": "number",
        "default": 4,
        "min": 1,
        "max": 16,
        "step": 1,
        "slider": true
      },
      {
        "name": "targetRatio",
        "type": "number",
        "default": 10,
        "min": 5,
        "max": 20,
        "step": 0.1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "compressionRatio",
        "precision": 2,
        "unit": ":1"
      },
      {
        "name": "sweptVolumeCc",
        "precision": 1,
        "unit": "cc"
      },
      {
        "name": "totalDisplacement",
        "precision": 0,
        "unit": "cc"
      },
      {
        "name": "requiredClearance",
        "precision": 1,
        "unit": "cc"
      }
    ],
    "interpret": null
  }
}
