You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`RunAC(string netlist)` → returns `Dictionary<string, List<(double Frequency, double Value)>>` (no AC helper in `BaseTests.cs` — implement using `((AC)simulation).Frequency`)
84
84
-`RunTran(string netlist)` → returns `Dictionary<string, List<(double Time, double Value)>>`
85
85
-`GetMeasurements(string netlist)` → returns `Dictionary<string, double>` of successful .MEAS results
86
+
-`AssertMeasurement(SpiceSharpModel model, string name, double expectedValue)` → checks measurement exists, succeeded, and value is within tolerance (RelTol=1e-3, AbsTol=1e-12). Mirrors `BaseTests.AssertMeasurement` from `src/SpiceSharpParser.IntegrationTests/BaseTests.cs`.
87
+
-`AssertMeasurementSuccess(SpiceSharpModel model, string name)` → checks measurement exists and succeeded (for measurements where you only care it found a value)
86
88
- Each method handles: parse → read → validate → attach exports → run with InvokeEvents → collect results
87
89
88
90
3. Verify the toolchain by writing and running a trivial RC filter test with assertions.
@@ -250,14 +252,26 @@ Title Line (required, first line)
250
252
251
253
**Devices**: R, C, L, K (mutual inductance), D (diode), Q (BJT), M (MOSFET), J (JFET), V (voltage source), I (current source), E (VCVS), F (CCCS), G (VCCS), H (CCVS), B (behavioral), S (voltage switch), W (current switch), T (transmission line)
252
254
255
+
**Behavioral Sources (B element)**
256
+
B elements define voltage or current as arbitrary expressions of other circuit variables:
257
+
```spice
258
+
B1 out 0 V={V(in1)*V(in2)} * Voltage = product of two node voltages (ideal multiplier)
259
+
B2 out 0 I={V(ctrl)/1k} * Current = voltage-controlled (ideal VCCS)
B4 out 0 V={V(in)*sin(6.28*1e6*TIME)} * Time-dependent (ideal mixer/modulator)
262
+
```
263
+
B elements are the recommended approach for modeling ideal functional blocks (op-amps, multipliers, comparators, VCOs) when full transistor-level simulation is unnecessary or impractical. See `src/SpiceSharpParser.IntegrationTests/AnalogBehavioralModeling/` tests for more examples.
**Expressions**: Use `{expression}` syntax in component values when `.PARAM` defines the variables (e.g., `R1 in out {Rval*2}` with `.PARAM Rval=1k`). Expressions support arithmetic, built-in math functions, and references to other parameters.
// ... attach EventExportData handlers for these exports ...
544
+
varcodes=simulation.Run(model.Circuit, -1);
545
+
codes=simulation.InvokeEvents(codes);
546
+
codes.ToArray();
547
+
}
548
+
```
549
+
The `RunOP`/`RunDC`/`RunAC`/`RunTran` helpers assume a single simulation of the expected type.
550
+
506
551
7.**Extract sweep/time/frequency values** per simulation type:
507
552
- DC sweep value: `((DC)simulation).GetCurrentSweepValue().Last()`
508
553
- AC frequency: `((AC)simulation).Frequency` (cast to `AC`, not `FrequencySimulation`)
509
554
- TRAN time: `((Transient)simulation).Time`
510
555
511
556
8.**Measurements**: `model.Measurements` is a `ConcurrentDictionary<string, List<MeasurementResult>>`. Each `MeasurementResult` has `.Success`, `.Value`, and `.Name`. Always check `.Success` before reading `.Value`.
512
557
558
+
### Tolerance Comparison Patterns
559
+
560
+
**For spec verification** (values from requirements.md):
561
+
Use `Assert.InRange(actual, min, max)` with explicit bounds from the spec table.
562
+
563
+
**For reference function comparison** (comparing simulation output against an analytical formula):
564
+
Use the relative+absolute tolerance pattern from `BaseTests.cs`:
This handles both large and small values correctly — the relative term (1e-3) dominates for large values, while the absolute term (1e-12) prevents false failures near zero.
571
+
513
572
### AC Analysis: Voltage Export Types
514
573
515
574
In AC analysis, voltages are complex numbers. The export type in `.SAVE` determines what value you get:
@@ -727,6 +786,8 @@ SpiceSharp has no built-in op-amp device. You must build from discrete transisto
727
786
728
787
### Convergence Tips
729
788
- Start with `.OPTIONS reltol=1e-3 abstol=1e-12 gmin=1e-12`
789
+
- For circuits that fail to find a DC operating point, increase iteration limits: `.OPTIONS itl1=200` (default ~100)
0 commit comments