Skip to content

Commit

Permalink
Merge pull request #121 from marcin-golebiowski/master
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
marcin-golebiowski authored Nov 11, 2019
2 parents 5442238 + 5233c51 commit fc694c1
Show file tree
Hide file tree
Showing 56 changed files with 597 additions and 1,260 deletions.
26 changes: 26 additions & 0 deletions src/SpiceSharpParser.IntegrationTests/Examples/Example01.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.IO;
using Xunit;

namespace SpiceSharpParser.IntegrationTests.Examples
{
public class Example01 : BaseTests
{
[Fact]
public void When_Simulated_Expect_NoExceptions()
{
string path = Path.Combine(Directory.GetCurrentDirectory(), "Resources/example01.cir");
var netlistContent = File.ReadAllText(path);

var parser = new SpiceParser();
parser.Settings.Lexing.HasTitle = true;

var parseResult = parser.ParseNetlist(netlistContent);

double[] exports = RunOpSimulation(parseResult.SpiceSharpModel, new [] { "V(N1)", "V(N2)", "V(N3)" });

EqualsWithTol(1.0970919064909939, exports[0]);
EqualsWithTol(0.014696545624995935, exports[1]);
EqualsWithTol(0.014715219080886419, exports[2]);
}
}
}
45 changes: 45 additions & 0 deletions src/SpiceSharpParser.IntegrationTests/Resources/example01.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Example 01

.param a0_entry=0.1
.param b0_entry=0.01
.param density =850
.param viscosity =0.000006
.param rout_entry =0.9
.param rin_entry =0.8
.param r1_entry1 =0.8
.param r2_entry1=0.81
.param r1_entry2 =0.89
.param r2_entry2=0.9
.param FlowRate =0.025

I_M 0 N1 {FlowRate}

X_entry1 N1 0 N2 entry params: a0={a0_entry}, b0={b0_entry}, ro={density}, v={viscosity}, rout={rout_entry},
+rin={rin_entry},r1={r1_entry1},r2={r2_entry1}

X_entry2 N1 0 N3 entry params: a0={a0_entry}, b0={b0_entry}, ro={density}, v={viscosity}, rout={rout_entry},
+rin={rin_entry},r1={r1_entry2},r2={r2_entry2}

.subckt entry m_in m_out v_vel params: a0=1, b0=1, ro=1, v=1, rout=1, rin=1, r1=1, r2=1
.param D0 = {2*a0*b0/(a0+b0)}
.param F1 = {(rout-rin)*a0*(rout+rin)/(r2+r1)}
.param F0 = {(r2-r1)*a0}
.param fraction = {F0/F1}
.func Q(m) {m/ro}
.func vel(m) {Q(m)/(a0*b0)}
.func R(x) {x*D0/v}
*Changed function
.func xi(x) {40*pow(R(x),-0.9) + 90*pow(fraction,-0.003)-80}
Vmas m_in msx {0}
Rmas msx msy 1e-6
*The pressure drop:
Exm msy m_out value={xi(V(v_vel))*ro*V(v_vel)*V(v_vel)/2}
Hmss mss 0 Vmas 1
*Velocity:
Guv 0 v_vel value={vel(V(mss))}
Ruv 0 v_vel 1
.ends

.OP
.SAVE V(N1) V(N2) V(N3)
.end
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<None Remove="Examples\example01.cir" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="SpiceSharp" Version="2.8.0" />
Expand All @@ -29,6 +33,9 @@
</ItemGroup>

<ItemGroup>
<None Update="Resources\example01.cir">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\pwl_reference.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
6 changes: 4 additions & 2 deletions src/SpiceSharpParser.PerformanceTests/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ public void EvaluateDouble()
var randomizer = new Randomizer();
for (var i = 0; i < n; i++)
{
sum += expressionParser.EvaluateValueExpression(
sum += expressionParser.Evaluate(
"1 + 1 + 1 + 1 + 1 + 1 + 1",
new ExpressionContext(
string.Empty,
false,
false,
false,
randomizer));
randomizer),
null,
null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using SpiceSharpParser.Common.Evaluation;
using SpiceSharpParser.Common.Evaluation.Expressions;
using System.Linq;
using SpiceSharp.Simulations;
using SpiceSharpParser.ModelReaders.Netlist.Spice.Context;
using Xunit;

namespace SpiceSharpParser.Tests.Common.Evaluation
Expand All @@ -13,7 +15,7 @@ public void AddExpressionWithoutParameters()
{
var registry = new ExpressionRegistry(false, false);
var evaluator = Substitute.For<IEvaluator>();
evaluator.EvaluateValueExpression(Arg.Any<string>(), Arg.Any<ExpressionContext>()).Returns(1);
evaluator.Evaluate(Arg.Any<Expression>(), Arg.Any<ExpressionContext>(), Arg.Any<Simulation>(), Arg.Any<IReadingContext>()).Returns(1);

registry.Add(new NamedExpression("test", "1"), new System.Collections.Generic.List<string>());

Expand All @@ -24,7 +26,7 @@ public void AddExpressionWithoutParameters()
public void AddExpressionWithParameters()
{
var registry = new ExpressionRegistry(false, false);
registry.Add(new Expression("x+1"), new System.Collections.Generic.List<string>() { "x" });
registry.Add(new DynamicExpression("x+1"), new System.Collections.Generic.List<string>() { "x" });

Assert.Single(registry.GetDependentExpressions("x"));
}
Expand All @@ -33,9 +35,9 @@ public void AddExpressionWithParameters()
public void AddExpressionsWithSingleParameter()
{
var registry = new ExpressionRegistry(false, false);
registry.Add(new Expression("x+1"), new System.Collections.Generic.List<string>() { "x" });
registry.Add(new Expression("y+1"), new System.Collections.Generic.List<string>() { "y" });
registry.Add(new Expression("x+1"), new System.Collections.Generic.List<string>() { "x" });
registry.Add(new DynamicExpression("x+1"), new System.Collections.Generic.List<string>() { "x" });
registry.Add(new DynamicExpression("y+1"), new System.Collections.Generic.List<string>() { "y" });
registry.Add(new DynamicExpression("x+1"), new System.Collections.Generic.List<string>() { "x" });

Assert.Single(registry.GetDependentExpressions("y"));
Assert.Equal(2, registry.GetDependentExpressions("x").Count());
Expand All @@ -45,9 +47,9 @@ public void AddExpressionsWithSingleParameter()
public void AddExpressionsWithMultipleParameter()
{
var registry = new ExpressionRegistry(false, false);
registry.Add(new Expression("x+y+1"), new System.Collections.Generic.List<string>() { "x", "y" });
registry.Add(new Expression("y+x+1"), new System.Collections.Generic.List<string>() { "y", "x" });
registry.Add(new Expression("x+1"), new System.Collections.Generic.List<string>() { "x" });
registry.Add(new DynamicExpression("x+y+1"), new System.Collections.Generic.List<string>() { "x", "y" });
registry.Add(new DynamicExpression("y+x+1"), new System.Collections.Generic.List<string>() { "y", "x" });
registry.Add(new DynamicExpression("x+1"), new System.Collections.Generic.List<string>() { "x" });

Assert.Equal(2, registry.GetDependentExpressions("y").Count());
Assert.Equal(3, registry.GetDependentExpressions("x").Count());
Expand Down
Loading

0 comments on commit fc694c1

Please sign in to comment.