{
  "openapi": "3.1.1",
  "info": {
    "title": "Ohmforge Transient Simulation API",
    "version": "1.0.0",
    "summary": "Simulate a circuit over time: waveforms, Vpp/RMS/frequency, CSV and a chart.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://ohmforgetransient.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Simulate a circuit over time: waveforms, Vpp/RMS/frequency, CSV and a chart.",
        "description": "Runs a transient (time-domain) simulation of a SPICE netlist with trapezoidal or backward-Euler integration, adaptive time steps and breakpoints at source corners. Returns resampled waveforms of the chosen nodes, oscilloscope-style measurements (min, max, Vpp, mean, RMS, frequency, duty cycle, rise time), rating warnings, a chart and CSV.\n\nMethodology:\n- Starts from the DC operating point (or from initial conditions with \"uic\"), then integrates capacitors and inductors with companion models: trapezoidal (2C/h) or backward Euler (C/h); inductors and coupled inductors use branch currents.\n- Each time step is solved with Newton–Raphson. The step size adapts: the difference between the corrector and a linear predictor estimates the local truncation error; failed steps are retried with h/8.\n- Source corners (PULSE edges, PWL points) are breakpoints: the integrator lands on them and restarts with backward Euler to avoid trapezoidal ringing. Behavioural events (555 latch, relay pull-in, fuse, current limit) are localised by step bisection.\n- Returned samples are linearly interpolated onto a uniform grid (output step). Measurements: time-weighted mean and RMS, Vpp, frequency from mid-level crossings with 10 % hysteresis, 10–90 % rise time.\n\nTeaching-grade simulation: device models are simplified (Ebers–Moll BJT, level-1 MOSFET, behavioural op-amps and 555) and part ratings are typical values. Verify real designs on the bench and against manufacturer data before building anything connected to mains voltage.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "ohmforge_transient",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OhmforgeTransientInput"
              },
              "examples": {
                "example1": {
                  "summary": "RC step response (τ = 1 ms)",
                  "value": {
                    "netlist": "* RC step response, tau = 1 ms\nV1 in 0 PULSE(0 1 0 1n 1n 10m 20m)\nR1 in out 1k\nC1 out 0 1u\n.tran 10u 5m\n.end",
                    "probes": [
                      "in",
                      "out"
                    ]
                  }
                },
                "example2": {
                  "summary": "Half-wave rectifier with smoothing",
                  "value": {
                    "netlist": "* Half-wave rectifier with reservoir capacitor\nV1 ac 0 SIN(0 12 50)\nD1 ac out 1N4007\nC1 out 0 470u\nRL out 0 1k\n.tran 50u 100m",
                    "probes": [
                      "ac",
                      "out"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OhmforgeTransientResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "OhmforgeTransientInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "netlist": {
            "title": "SPICE netlist",
            "description": "Subset: R C L V I D Q M E G K, .model, SIN/PULSE/PWL sources, engineering suffixes (k, m, u, n, p, meg). Node 0 is ground. Leave empty when you pass an Ohmforge project instead.",
            "type": "string",
            "maxLength": 60000
          },
          "project": {
            "title": "Ohmforge project JSON (optional)",
            "description": "Alternative to the netlist: a .ohmforge.json project as saved by the app (format \"ohmforge\", version 1).",
            "type": "string",
            "maxLength": 200000
          },
          "tstop": {
            "title": "Stop time",
            "description": "Simulated duration. Empty = use the .tran line of the netlist (or the project's transient settings).",
            "type": "number",
            "minimum": 0,
            "maximum": 1000,
            "x-unit": "s"
          },
          "tstep": {
            "title": "Output step",
            "description": "Spacing of the returned samples (also the largest internal step). Empty = .tran value or stop time / 1000.",
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "x-unit": "s"
          },
          "method": {
            "title": "Integration",
            "type": "string",
            "enum": [
              "trap",
              "be"
            ],
            "default": "trap"
          },
          "uic": {
            "title": "Start from initial conditions (skip the operating point)",
            "description": "Capacitors start at their IC (default 0 V). Needed for oscillators.",
            "type": "boolean",
            "default": false
          },
          "probes": {
            "title": "Nodes to return",
            "description": "Node names; empty = all nodes (max 8 in the chart).",
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 8
          }
        },
        "required": []
      },
      "OhmforgeTransientResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "required": [
              "ok",
              "tstop",
              "tstep",
              "time",
              "waveforms",
              "measurements"
            ],
            "properties": {
              "ok": {
                "type": "boolean"
              },
              "tstop": {
                "type": "number"
              },
              "tstep": {
                "type": "number"
              },
              "method": {
                "type": "string"
              },
              "start": {
                "type": "string"
              },
              "steps": {
                "type": "integer"
              },
              "rejectedSteps": {
                "type": "integer"
              },
              "time": {
                "type": "array",
                "items": {
                  "type": "number"
                }
              },
              "waveforms": {
                "type": "object",
                "additionalProperties": {
                  "type": "array",
                  "items": {
                    "type": "number"
                  }
                }
              },
              "measurements": {
                "type": "object",
                "additionalProperties": {
                  "type": "object",
                  "properties": {
                    "min": {
                      "type": "number"
                    },
                    "max": {
                      "type": "number"
                    },
                    "vpp": {
                      "type": "number"
                    },
                    "mean": {
                      "type": "number"
                    },
                    "rms": {
                      "type": "number"
                    },
                    "frequency": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "duty": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "riseTime": {
                      "type": [
                        "number",
                        "null"
                      ]
                    }
                  }
                }
              },
              "stress": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              },
              "diagnostics": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}