Comments (17)
Thank you for using Spice#.
What you are trying to use is behavioral modeling. In many spice simulators you are able to specify arbitrary functions in text format. This means that you need a parser to execute that arbitrary function expression, which I have deliberately left out of this core package.
As I see it you have three options:
- You can create a custom component that fills the Y-matrix and Rhs-vector, similar to all other components in the package. This is probably the most performant solution, but you will also need an understanding of the technical details of Spice#, Modified Nodal Analysis and Newton-Raphson.
- You can try using Spice#.Parser. It has some functionality for parsing netlists like the one you showed.
- You can wait for
Spice#.Behavioral
. I am currently working on a library for behavioral modeling.
from spicesharp.
Thank you for providing Spice# and also for quick answer.
Is it possible to get circuit from parser and merge it in Spice# like subcircuit?
Do you have expected date of the first version of Spice#.Behavioral?
from spicesharp.
@user4githvb I think it's possible to get a subciruit from parser and merge it. Please give me two days to try this out first.
from spicesharp.
Starting with version 2.7, it is also possible to instantiate a circuit into another circuit like a subcircuit directly from the core package. But unfortunately I haven't updated the documentation yet. You can basically use:
var ckt = new Circuit();
// Assume you already have a subckt (also a Circuit object)
ckt.Instantiate(new InstanceData(subckt, "myinstance"));
// If you want to map some subcircuit nodes onto global nodes, you can use:
var instanceData = new ComponentInstanceData(subckt, "mymappedinstance");
instanceData.NodeMap.Add("0", "0");
instanceData.NodeMap.Add("VDD", "VDD");
instanceData.NodeMap.Add("m_in", "N1");
instanceData.NodeMap.Add("m_out", "N2");
ckt.Instantiate(instanceData);
Instantiate()
will clone a circuit and merge the cloned circuit with the target circuit. This is the expected behavior when treating a circuit like a subcircuit. Merge()
will just merge all entities of a circuit with the target circuit by reference. Unlike instantiating, changing entity parameters in the original circuit will also affect the entities in the merged circuit as they are shared.
But if you intend to use Spice#.Parser, you may just want to use the parser for everything! Spice#.Behavioral is actively being developed. I am hoping to publish a first version on GitHub in a week or two.
from spicesharp.
With SpiceParser I have issue with my example as well as with diode example (from tutorial):
var netlist = string.Join(Environment.NewLine,
"Diode circuit",
"D1 OUT 0 1N914",
"V1 OUT 0 0",
".model 1N914 D(Is=2.52e-9 Rs=0.568 N=1.752 Cjo=4e-12 M=0.4 tt=20e-9)",
".DC V1 -1 1 10e-3",
".SAVE i(V1)",
".END");
// Parsing part - SpiceSharpParser
var parser = new SpiceParser();
var parseResult = parser.ParseNetlist(netlist);
var spiceSharpModel = parseResult.SpiceSharpModel;
Method not found: 'Boolean SpiceSharp.Circuits.Entity.SetParameter(System.String, Double, System.Collections.Generic.IEqualityComparer`1)'.
from spicesharp.
@user4githvb Most likely you are using new version of SpiceSharp. SpiceSharpParser is at the moment compatible with older version.
Please clean nuget packages, remove SpiceSharp, install SpiceSharpParser again. It should also include SpiceSharp with the right version.
from spicesharp.
That was the issue - but now I will not be able to instanciate subcircuits - I guess I need to wait for Spice#.Behavioral
I will just check custom component method but I feel that is quite demanding. Thank you for help
from spicesharp.
@user4githvb I will publish new version of Parser for you today. It will include SpiceSparp 2.7.
from spicesharp.
@user4githvb I will publish tomorrow. Sorry about that. There are some problems with integration tests.
from spicesharp.
Now parser works fine - thank You thank You very much.
from spicesharp.
Hello. Any neews on Spice#.Behavioral?
from spicesharp.
Hi,
The basic framework for regular voltage and current sources work for DC analysis. It took a little bit more time than expected because there was some extra complexity that I overlooked, but it works since yesterday. I am now working on the other behaviors (time behavior and frequency behavior), which should not take too long. I am hoping to complete it this weekend.
Yours sincerely,
Sven
from spicesharp.
@user4githvb Any problems with Spice#.Parser ?
from spicesharp.
:) thank You
from spicesharp.
I used this way with parser - I completed proof of concept - I had different result comapred to Spice - I abandoned work due to the fact that we have concluded that maybe better wait for Spice# to evaluate. We wanted not to have Spice Code in the #code due to maintanance reasons.
from spicesharp.
@user4githvb Could you be so kind and provide more details about your results and the test?
I would like to fix parser if it's possible to have same results.
from spicesharp.
@user4githvb Spice#.Behavioral has been created. I should mention that given the complexity of the project, it is possibly unstable. We should test it thoroughly in the future. If you have any issues, don't hesitate to post an issue there.
Once the project stabilizes, I will upload it to NuGet, but fow now please checkout from the repository directly please.
from spicesharp.
Related Issues (20)
- Determine Stepsize of Transient Analysis HOT 2
- Is there a way to continuously simulate Transient? HOT 2
- NullReferenceException when calling dc.Run() in 3.0.x versions HOT 11
- Impossible to specify a node comparer for simulations
- Question: Watt/Power Meter Implementation HOT 4
- Wrong validation of parameter values that are "smaller than"
- Validation of TemperatureCelsius property in SpiceSharp.Components.JFETs.Parameters class HOT 1
- Bug in OctaveSweep class HOT 1
- Diode model issue HOT 5
- Question: Can we use this in Unity? HOT 2
- Voltage across diodes does not work as expected HOT 1
- Any way to create wire? HOT 2
- Astable Multivibrator HOT 2
- Time to get Transient simulation HOT 4
- Digital Components (NAND, NOR, flip flops, 555 Timer...) HOT 1
- CVD model for zener diode? HOT 1
- Problems when simulating transformer HOT 4
- Pausing and Resuming simulation HOT 6
- Not sure why this is failing to validate HOT 4
- VoltageSwitch does not support negative hysteresis HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spicesharp.