-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from SpiceSharp/cust
Add example for Mosfet + fix old bug in Mosfet generation
- Loading branch information
Showing
6 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
src/SpiceSharpParser.IntegrationTests/Examples/Circuits/MosfetExample.cir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Mosfet circuit | ||
Md 0 1 2 3 my-pmos | ||
.model my-pmos pmos(level = 4) | ||
.END |
28 changes: 28 additions & 0 deletions
28
src/SpiceSharpParser.IntegrationTests/Examples/Extensions/CustomMosfetModelGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using SpiceSharp.Components; | ||
using SpiceSharpParser.ModelReaders.Netlist.Spice.Context.Models; | ||
using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.EntityGenerators; | ||
using SpiceSharpParser.ModelReaders.Netlist.Spice.Readers.EntityGenerators.Models; | ||
|
||
namespace SpiceSharpParser.IntegrationTests.Examples.Extensions | ||
{ | ||
public class CustomMosfetModelGenerator : MosfetModelGenerator | ||
{ | ||
|
||
public CustomMosfetModelGenerator() | ||
{ | ||
Levels.Add(4, (name, type, _) => | ||
{ | ||
var m = new Mosfet3Model(name); | ||
switch (type.ToLower()) | ||
{ | ||
case "nmos": m.SetParameter("nmos", true); break; | ||
case "pmos": m.SetParameter("pmos", true); break; | ||
} | ||
return new Model(name, m, m.Parameters); | ||
}); | ||
} | ||
|
||
|
||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/SpiceSharpParser.IntegrationTests/Examples/Extensions/CustomMosfetModelTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.IO; | ||
using Xunit; | ||
|
||
namespace SpiceSharpParser.IntegrationTests.Examples.Extensions | ||
{ | ||
public class CustomMosfetModelTest : BaseTests | ||
{ | ||
[Fact] | ||
public void When_CustomMosfetModel_Used_NoExceptions() | ||
{ | ||
// Create a model from text file | ||
string path = Path.Combine(Directory.GetCurrentDirectory(), "Examples/Circuits/MosfetExample.cir"); | ||
var netlistContent = File.ReadAllText(path); | ||
var parser = new SpiceNetlistParser(); | ||
parser.Settings.Lexing.HasTitle = true; | ||
var parseResult = parser.ParseNetlist(netlistContent); | ||
|
||
// Convert to Spice# | ||
var spiceSharpReader = new SpiceSharpReader(); | ||
spiceSharpReader.Settings.CaseSensitivity.IsModelTypeCaseSensitive = false; | ||
spiceSharpReader.Settings.Mappings.Models.Map(new[] { "PMOS", "NMOS" }, new CustomMosfetModelGenerator()); | ||
var spiceSharpModel = spiceSharpReader.Read(parseResult.FinalModel); | ||
|
||
Assert.False(spiceSharpModel.ValidationResult.HasError); | ||
Assert.False(spiceSharpModel.ValidationResult.HasWarning); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters