-3

The diode line is not working, I dont how to run it please help, i really want to know how to initialize the diode part, everything works fine, only this part when i add it it says ISimulation model not found

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

}
}
}
Salim
  • 1
  • 2
  • I have no clue what all of that means, but check the tests provided in the git, so you can find some more help there. E.g. [htis page with Diode tests](https://github.com/SpiceSharp/SpiceSharp/blob/master/SpiceSharpTest/Simulations/DCTests.cs) – ASpirin Aug 19 '20 at 12:42

1 Answers1

2

Error says: "ISimulation model not found" means you are referencing the model "ISimulation", which is not belongs to circuit. You can create a DiodeModel for you diode and add it into the circuit. For example:

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)

     );

So if I understand correctly, DiodeModel, is the exact type of your Diode, that you are going to place onto the circuit. That allows circuit to be calculated. And a model can be reused in case you have a number of similar elements (e.g. diode bridge)

ASpirin
  • 3,601
  • 1
  • 23
  • 32
  • yes that's true, but the issue here i don't know what to put instead of the "ISimulation", I did so many choices, like "diode", "0","Diode","DiodeModel".... nothing worked – Salim Aug 19 '20 at 19:06
  • In fact it doesn't matter unless it fits to the name of model provided, check the sample, important parts marked with `<--` sign. I've provided. I would suggest to put there real names like `1N914`. – ASpirin Aug 19 '20 at 20:28
  • Omg! How you got this? It worked!, a lot of thanks to you for your help, thanks.. I really need to know how you got this so I can understand the rest of the components – Salim Aug 21 '20 at 03:00
  • Check the supplier [git repository](https://github.com/SpiceSharp/SpiceSharp). I've got an example [from here](https://github.com/SpiceSharp/SpiceSharp/blob/master/SpiceSharpTest/Simulations/DCTests.cs#L70) and would suggest to take a look into [the folder](https://github.com/SpiceSharp/SpiceSharp/tree/master/SpiceSharpTest) – ASpirin Aug 21 '20 at 06:33