You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在C#中使用SpiceSharp的Diode类?初始化报错求助

Fixing the "ISimulation model not found" Error with SpiceSharp Diode Class

Hey there! Let's work through why your Diode initialization is throwing that error and get your simulation running smoothly.

The Core Issue

When using Diode in SpiceSharp, it needs an associated diode model to define its electrical behavior (things like saturation current, ideality factor, etc.). Your current code passes "ISimulation" as the model name, but there's no actual DiodeModel with that name added to your circuit. That's exactly why you're getting the "ISimulation model not found" message.

Step-by-Step Fix

We need to three key things to resolve this:

  1. Create a DiodeModel (we can use default parameters or customize them).
  2. Add this model to your circuit.
  3. Reference the model's name when initializing the Diode.

Here's your corrected code with the changes clearly marked:

using System;
using SpiceSharp;
using SpiceSharp.Components;
using SpiceSharp.Simulations;

namespace SpiceSimulation
{
    class Program
    {
        static void Main(string[] args)
        {
            // 1. Create a diode model (using default parameters here)
            var diodeModel = new DiodeModel("DModel");
            
            var ckt = new Circuit(
                new VoltageSource("V0", "in1", "0", 0.0),//ground
                new VoltageSource("V1", "in", "in1", 12.0),//voltage source 12 volt
                new Resistor("R1", "out", "in", 1.0e3),//resistor 1k
                diodeModel, // 2. Add the model to the circuit
                new Diode("M1", "out", "d", "DModel"),// 3. Reference the valid model name here
                new Resistor("R2", "0", "d", 2.0e3)//resistor 2k
            );
            
            // Create a DC sweep and register to the event for exporting simulation data
            var dc = new DC("dc", "V0", 0.0, 0.0, 0.001);//ground voltage
            dc.ExportSimulationData += (sender, exportDataEventArgs) =>
            {
                Console.WriteLine(exportDataEventArgs.GetVoltage("out"));//get the voltage at this point
            };
            
            // Run the simulation
            dc.Run(ckt);//it will run the circuit
        }
    }
}

Customizing the Diode Model (Optional)

If you need to tweak the diode's characteristics (like setting a specific saturation current), you can modify the model like this:

var diodeModel = new DiodeModel("DModel")
{
    IS = 1e-15, // Saturation current
    N = 1.0,    // Ideality factor
    RS = 0.0    // Series resistance
};

This gives you full control over how the diode behaves in your simulation.

内容的提问来源于stack exchange,提问作者Salim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 21:43:15