Как использовать любой класс из SpiceSharp в C#? Я не умею использовать класс диода в своем коде, но я знаю, как использовать класс резистора и напряжение.

Линия диода не работает, я не умею ее запускать, пожалуйста, помогите, я действительно хочу знать, как инициализировать диодную часть, все работает нормально, только эта часть, когда я ее добавляю, говорит, что модель ISimulation не найдена

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


namespace SpiceSimulation
{
    class Program
    {
        static void Main(string[] args)
        { 
    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
         new Diode("M1", "out", "d", "ISimulation"),//here is my problem
         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

}
}
}

1 ответ

Решение

Ошибка говорит: "Модель ISimulation не найдена" означает, что вы ссылаетесь на модель "ISimulation", которая не принадлежит цепи. Вы можете создатьDiodeModelдля вас диод и добавить его в схему. Например:

var model = new DiodeModel("ISimulation");
model.SetParameter("is", 2.52e-9);
model.SetParameter("rs", 0.568);
model.SetParameter("n", 1.752);
model.SetParameter("cjo", 4e-12);
model.SetParameter("m", 0.4);
model.SetParameter("tt", 20e-9);

var ckt = new Circuit(
     new VoltageSource("V0", "in1", "0", 0.0),
     new VoltageSource("V1", "in", "in1", 12.0),
     new Resistor("R1", "out", "in", 1.0e3),
     model, // <-- Here goes model
     new Diode("M1", "out", "d", model.Name),// <-- The name is taken directly from model
     new Resistor("R2", "0", "d", 2.0e3)

     );

Итак, если я правильно понимаю, DiodeModel - это точный тип вашего диода, который вы собираетесь поместить в схему. Это позволяет рассчитать схему. А модель можно использовать повторно, если у вас есть несколько похожих элементов (например, диодный мост).

Другие вопросы по тегам