如何在 C# 中使用来自 SpiceSharp 的任何 class?我无法在我的代码中使用二极管 class,但我知道如何使用电阻器 class 和电压
How to use any class from SpiceSharp in c#? I'm not able how to use diode class in my code, but I know how to use the resistor class and voltage
二极管线不工作,我不知道如何运行请帮忙,我真的很想知道如何初始化二极管部分,一切正常,只有这部分当我添加它时说未找到仿真模型
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
}
}
}
错误提示:“找不到 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 就是您要放置到电路中的二极管的确切类型。这允许计算电路。如果您有许多相似的元件(例如二极管电桥)
,则可以重复使用模型
二极管线不工作,我不知道如何运行请帮忙,我真的很想知道如何初始化二极管部分,一切正常,只有这部分当我添加它时说未找到仿真模型
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
}
}
}
错误提示:“找不到 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 就是您要放置到电路中的二极管的确切类型。这允许计算电路。如果您有许多相似的元件(例如二极管电桥)
,则可以重复使用模型