BipolarJunctionTransistor CreateBJT(string name, string c, string b, string e, string subst, string model) { // Create the transistor var bjt = new BipolarJunctionTransistor(name, c, b, e, subst, model); return(bjt); }
/// <summary> /// Create a BJT with a model /// </summary> /// <param name="name">Device name</param> /// <param name="c">Collector</param> /// <param name="b">Base</param> /// <param name="e">Emitter</param> /// <param name="subst">Substrate</param> /// <param name="model">Model name</param> /// <param name="modelparams">Model parameters</param> BipolarJunctionTransistor CreateBJT(Identifier name, Identifier c, Identifier b, Identifier e, Identifier subst, Identifier model, string modelparams) { // Create the model BipolarJunctionTransistorModel bjtmodel = new BipolarJunctionTransistorModel(model); ApplyParameters(bjtmodel, modelparams); // Create the transistor BipolarJunctionTransistor bjt = new BipolarJunctionTransistor(name); bjt.Connect(c, b, e, subst); bjt.SetModel(bjtmodel); return(bjt); }
/// <summary> /// Create a BJT with a model /// </summary> /// <param name="name">Device name</param> /// <param name="c">Collector</param> /// <param name="b">Base</param> /// <param name="e">Emitter</param> /// <param name="subst">Substrate</param> /// <param name="model">Model name</param> /// <param name="modelparams">Model parameters</param> BipolarJunctionTransistor CreateBJT(string name, string c, string b, string e, string subst, string model, string modelparams) { // Create the model var bjtmodel = new BipolarJunctionTransistorModel(model); ApplyParameters(bjtmodel, modelparams); // Create the transistor var bjt = new BipolarJunctionTransistor(name); bjt.Connect(c, b, e, subst); bjt.SetModel(bjtmodel); return(bjt); }
public SpiceSharp.Components.Component Generate(string componentIdentifier, string originalName, string type, ParameterCollection parameters, ICircuitContext context) { BipolarJunctionTransistor bjt = new BipolarJunctionTransistor(componentIdentifier); // If the component is of the format QXXX NC NB NE MNAME off we will insert NE again before the model name if (parameters.Count == 5 && parameters[4] is WordParameter w && w.Image == "off") { parameters.Insert(3, parameters[2]); } // If the component is of the format QXXX NC NB NE MNAME we will insert NE again before the model name if (parameters.Count == 4) { parameters.Insert(3, parameters[2]); } context.CreateNodes(bjt, parameters); if (parameters.Count < 5) { context.Result.Validation.Add(new ValidationEntry(ValidationEntrySource.Reader, ValidationEntryLevel.Warning, "Wrong parameters count for BJT", parameters.LineInfo)); return(null); } context.SimulationPreparations.ExecuteActionBeforeSetup((simulation) => { context.ModelsRegistry.SetModel( bjt, simulation, parameters.Get(4), $"Could not find model {parameters.Get(4)} for BJT {originalName}", (BipolarJunctionTransistorModel model) => bjt.Model = model.Name, context.Result); }); for (int i = 5; i < parameters.Count; i++) { var parameter = parameters[i]; if (parameter is SingleParameter s) { if (s is WordParameter) { switch (s.Image.ToLower()) { case "on": bjt.SetParameter("off", false); break; case "off": bjt.SetParameter("on", false); break; default: throw new System.Exception(); } } else { // TODO: Fix this please it's broken ... BaseParameters bp = bjt.ParameterSets.Get <BaseParameters>(); if (!bp.Area.Given) { bp.Area.Value = context.Evaluator.EvaluateDouble(s.Image); } if (!bp.Temperature.Given) { bp.Temperature.Value = context.Evaluator.EvaluateDouble(s.Image); } } } if (parameter is AssignmentParameter asg) { if (asg.Name.ToLower() == "ic") { context.SetParameter(bjt, "ic", asg.Value); } } } return(bjt); }