Skip to content

Commit d622fb4

Browse files
Merge pull request #57 from SpiceSharp/development
v3.1
2 parents 7c84a11 + e361216 commit d622fb4

29 files changed

Lines changed: 425 additions & 243 deletions
Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
1-
# This is a basic workflow to help you get started with Actions
2-
31
name: Publish to NuGet
42

5-
# Controls when the action will run. Triggers the workflow on push or pull request
6-
# events but only for the master branch
73
on:
84
release:
95
branches: [ master ]
106
types: [ published ]
117

12-
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
138
jobs:
14-
# This workflow contains a single job called "build"
159
build:
16-
# The type of runner that the job will run on
17-
runs-on: [ windows-latest ]
10+
runs-on: windows-latest
1811

19-
# Steps represent a sequence of tasks that will be executed as part of the job
2012
steps:
21-
- name: Setup MSBuild environment
22-
uses: microsoft/setup-msbuild@v1.0.2
23-
24-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
25-
- uses: actions/checkout@v2
26-
27-
- name: Restore dependencies
28-
run: dotnet restore SpiceSharpBehavioral\SpiceSharpBehavioral.csproj
13+
- uses: actions/checkout@master
14+
15+
- name: Setup dotnet tooling
16+
uses: actions/setup-dotnet@master
17+
with:
18+
dotnet-version: '5.0.100'
19+
20+
- name: Restore dependencies
21+
run: dotnet restore
2922

30-
- name: Compile Spice# in Release mode
31-
run: msbuild SpiceSharpBehavioral\SpiceSharpBehavioral.csproj -p:Configuration=Release
23+
- name: Compile Spice#
24+
run: dotnet build SpiceSharpBehavioral\SpiceSharpBehavioral.csproj --configuration Release --no-restore
3225

33-
- name: Publish to NuGet
34-
env:
35-
APIKEY: ${{ secrets.NUGET_APIKEY }}
36-
run: dotnet nuget push .\SpiceSharpBehavioral\bin\Release\SpiceSharpBehavioral.*.nupkg -k $env:APIKEY -s "https://api.nuget.org/v3/index.json"
26+
- name: Publish to NuGet
27+
env:
28+
APIKEY: ${{ secrets.NUGET_APIKEY }}
29+
run: dotnet nuget push .\SpiceSharpBehavioral\bin\Release\SpiceSharpBehavioral.*.nupkg -k $env:APIKEY -s "https://api.nuget.org/v3/index.json"
3730

.github/workflows/test-linux.yml

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# This is a basic workflow to help you get started with Actions
2-
31
name: Linux Tests
42

53
# Controls when the action will run. Triggers the workflow on push or pull request
@@ -12,28 +10,22 @@ on:
1210

1311
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1412
jobs:
15-
# This workflow contains a single job called "build"
1613
build:
17-
# The type of runner that the job will run on
18-
runs-on: [ubuntu-latest]
14+
runs-on: ubuntu-latest
1915

20-
# Steps represent a sequence of tasks that will be executed as part of the job
2116
steps:
22-
- uses: docker://mono:latest
23-
24-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
25-
- uses: actions/checkout@v2
26-
17+
- uses: actions/checkout@master
18+
19+
- name: Setup dotnet tooling
20+
uses: actions/setup-dotnet@master
21+
with:
22+
dotnet-version: '5.0.100'
23+
2724
- name: Restore dependencies
2825
run: dotnet restore
2926

30-
- name: Compile Spice#
31-
run: msbuild SpiceSharpBehavioral/SpiceSharpBehavioral.csproj -p:Configuration=Debug
27+
- name: Compile Spice#.Behavioral
28+
run: dotnet build SpiceSharpBehavioral/SpiceSharpBehavioral.csproj --configuration Debug --no-restore
3229

33-
- name: Compile Spice#.Test
34-
run: msbuild SpiceSharpBehavioralTest/SpiceSharpBehavioralTest.csproj -p:Configuration=Debug
35-
36-
- name: Run tests
37-
run: dotnet test SpiceSharpBehavioralTest/bin/Debug/SpiceSharpBehavioralTest.dll
38-
39-
30+
- name: Compile Spice#.Behavioral.Test
31+
run: dotnet test SpiceSharpBehavioralTest/SpiceSharpBehavioralTest.csproj --configuration Debug --no-restore

.github/workflows/test-macos.yml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# This is a basic workflow to help you get started with Actions
2-
31
name: MacOS Tests
42

53
# Controls when the action will run. Triggers the workflow on push or pull request
@@ -12,27 +10,22 @@ on:
1210

1311
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1412
jobs:
15-
# This workflow contains a single job called "build"
1613
build:
17-
# The type of runner that the job will run on
18-
runs-on: [macos-latest]
14+
runs-on: macos-latest
1915

20-
# Steps represent a sequence of tasks that will be executed as part of the job
2116
steps:
22-
- name: Setup Xamarin environment
23-
uses: maxim-lobanov/setup-xamarin@v1.1
24-
25-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26-
- uses: actions/checkout@v2
27-
17+
- uses: actions/checkout@master
18+
19+
- name: Setup dotnet tooling
20+
uses: actions/setup-dotnet@master
21+
with:
22+
dotnet-version: '5.0.100'
23+
2824
- name: Restore dependencies
2925
run: dotnet restore
3026

31-
- name: Compile Spice#
32-
run: msbuild SpiceSharpBehavioral/SpiceSharpBehavioral.csproj -p:Configuration=Debug
27+
- name: Compile Spice#.Behavioral
28+
run: dotnet build SpiceSharpbehavioral/SpiceSharpBehavioral.csproj --configuration Debug --no-restore
3329

34-
- name: Compile Spice#.Test
35-
run: msbuild SpiceSharpBehavioralTest/SpiceSharpBehavioralTest.csproj -p:Configuration=Debug
36-
37-
- name: Run tests
38-
run: dotnet test SpiceSharpBehavioralTest/bin/Debug/SpiceSharpBehavioralTest.dll
30+
- name: Compile Spice#.Behavioral.Test
31+
run: dotnet test SpiceSharpBehavioralTest/SpiceSharpBehavioralTest.csproj --configuration Debug --no-restore

.github/workflows/test-windows.yml

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# This is a basic workflow to help you get started with Actions
2-
31
name: Windows Tests
42

53
# Controls when the action will run. Triggers the workflow on push or pull request
@@ -12,28 +10,22 @@ on:
1210

1311
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1412
jobs:
15-
# This workflow contains a single job called "build"
1613
build:
17-
# The type of runner that the job will run on
18-
runs-on: [windows-latest]
14+
runs-on: windows-latest
1915

20-
# Steps represent a sequence of tasks that will be executed as part of the job
2116
steps:
22-
- name: Setup MSBuild environment
23-
uses: microsoft/setup-msbuild@v1.0.2
24-
25-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26-
- uses: actions/checkout@v2
27-
17+
- uses: actions/checkout@master
18+
19+
- name: Setup dotnet tooling
20+
uses: actions/setup-dotnet@master
21+
with:
22+
dotnet-version: '5.0.100'
23+
2824
- name: Restore dependencies
2925
run: dotnet restore
3026

31-
- name: Compile Spice#
32-
run: msbuild SpiceSharpBehavioral\SpiceSharpBehavioral.csproj -p:Configuration=Debug
33-
34-
- name: Compile Spice#.Test
35-
run: msbuild SpiceSharpBehavioralTest\SpiceSharpBehavioralTest.csproj -p:Configuration=Debug
36-
37-
- name: Run tests
38-
run: dotnet test SpiceSharpBehavioralTest/bin/Debug/SpiceSharpBehavioralTest.dll
27+
- name: Compile Spice#.Behavioral
28+
run: dotnet build SpiceSharpBehavioral/SpiceSharpBehavioral.csproj --configuration Debug --no-restore
3929

30+
- name: Compile Spice#.Behavioral.Test
31+
run: dotnet test SpiceSharpBehavioralTest/SpiceSharpBehavioralTest.csproj --configuration Debug --no-restore

SpiceSharpBehavioral/Components/BehavioralBindingContext.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using SpiceSharp.Algebra;
2+
using SpiceSharp.Attributes;
23
using SpiceSharp.Behaviors;
34
using SpiceSharp.Components.CommonBehaviors;
45
using SpiceSharp.Simulations;
@@ -16,6 +17,10 @@ namespace SpiceSharp.Components.BehavioralComponents
1617
/// A context for behavioral components.
1718
/// </summary>
1819
/// <seealso cref="ComponentBindingContext" />
20+
[BindingContextFor(typeof(BehavioralCapacitor))]
21+
[BindingContextFor(typeof(BehavioralResistor))]
22+
[BindingContextFor(typeof(BehavioralVoltageSource))]
23+
[BindingContextFor(typeof(BehavioralCurrentSource))]
1924
public class BehavioralBindingContext : ComponentBindingContext
2025
{
2126
/// <summary>
@@ -82,27 +87,47 @@ public IVariable<T> MapNode<T>(IVariableFactory<IVariable<T>> factory, VariableN
8287
return factory.GetSharedVariable(node.Name);
8388

8489
case NodeTypes.Current:
85-
var container = Simulation.EntityBehaviors[node.Name];
90+
IBehaviorContainer container;
91+
IBiasingBehavior tmpb;
92+
IFrequencyBehavior tmpf;
93+
94+
// Get the relevant behaviors
95+
if (Simulation.EntityBehaviors.Comparer.Equals(node.Name, Behaviors.Name))
96+
container = Behaviors;
97+
else
98+
container = Simulation.EntityBehaviors[node.Name];
99+
86100
if (container == Behaviors)
87101
{
88102
if (ownBranch == null)
89103
throw new SpiceSharpException($"The behavior for {Entity.Name} does not define a branch current.");
90104
return ownBranch;
91105
}
92106
else if (container.TryGetValue<IBranchedBehavior<T>>(out var branched))
107+
{
108+
// Best-case scenario! Our behaviors define a branched behavior!
93109
return branched.Branch;
94-
else if (typeof(T) == typeof(double) && container.TryGetValue(out IBiasingBehavior tmpb) && tmpb is CurrentSources.Biasing biasing)
110+
}
111+
else if (typeof(T) == typeof(double) && container.TryGetValue(out tmpb) && tmpb is CurrentSources.Biasing biasing)
95112
{
113+
// If whatever is being is asked is the current from a current source, then we also don't have a problem
96114
var result = new FuncVariable<double>($"I({biasing.Name})", () => biasing.Current, Units.Ampere);
97115
return result as IVariable<T>;
98116
}
99-
else if (typeof(T) == typeof(Complex) && container.TryGetValue(out IFrequencyBehavior tmpf) && tmpf is CurrentSources.Frequency frequency)
117+
else if (typeof(T) == typeof(Complex) && container.TryGetValue(out tmpf) && tmpf is CurrentSources.Frequency frequency)
100118
{
119+
// Current source = no problem
101120
var result = new FuncVariable<Complex>($"I({frequency.Name})", () => frequency.ComplexCurrent, Units.Ampere);
102121
return result as IVariable<T>;
103122
}
104123
else
105-
goto default;
124+
{
125+
var result = container.CreatePropertyGetter<T>("i");
126+
if (result == null)
127+
goto default;
128+
SpiceSharpWarning.Warning(this, SpiceSharpBehavioral.Properties.Resources.LooseLinkCurrent.FormatString(container.Name));
129+
return new FuncVariable<T>($"@{container.Name}[i]", result, Units.Ampere);
130+
}
106131

107132
default:
108133
throw new SpiceSharpException($"Could not determine the variable {node.Name}");

SpiceSharpBehavioral/Components/BehavioralCapacitor/BehavioralCapacitor.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
using SpiceSharp.Attributes;
22
using SpiceSharp.Components.BehavioralComponents;
3+
using SpiceSharp.Validation;
4+
using System.Linq;
35

46
namespace SpiceSharp.Components
57
{
68
/// <summary>
79
/// A behavioral capacitor.
810
/// </summary>
911
/// <seealso cref="BehavioralComponent"/>
10-
[Pin(0, "P"), Pin(1, "N")]
11-
public class BehavioralCapacitor : BehavioralComponent
12+
[Pin(0, "P"), Pin(1, "N"), Connected, AutoGeneratedBehaviors]
13+
public partial class BehavioralCapacitor : BehavioralComponent, IRuleSubject
1214
{
1315
/// <summary>
1416
/// The behavioral capacitor base pin count.
@@ -37,5 +39,14 @@ public BehavioralCapacitor(string name, string pos, string neg, string expressio
3739
Connect(pos, neg);
3840
Parameters.Expression = expression;
3941
}
42+
43+
/// <inheritdoc/>
44+
void IRuleSubject.Apply(IRules rules)
45+
{
46+
var p = rules.GetParameterSet<ComponentRuleParameters>();
47+
var nodes = Nodes.Select(name => p.Factory.GetSharedVariable(name)).ToArray();
48+
foreach (var rule in rules.GetRules<IConductiveRule>())
49+
rule.AddPath(this, ConductionTypes.Ac, nodes[0], nodes[1]);
50+
}
4051
}
4152
}

SpiceSharpBehavioral/Components/BehavioralCapacitor/BiasingBehavior.cs renamed to SpiceSharpBehavioral/Components/BehavioralCapacitor/Biasing.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace SpiceSharp.Components.BehavioralCapacitorBehaviors
1313
/// <summary>
1414
/// Biasing behavior for a <see cref="BehavioralCapacitor"/>
1515
/// </summary>
16-
public class BiasingBehavior : Behavior
16+
public class Biasing : Behavior
1717
{
1818
/// <summary>
1919
/// The variables.
@@ -36,11 +36,11 @@ public class BiasingBehavior : Behavior
3636
protected readonly Dictionary<VariableNode, Node> Derivatives;
3737

3838
/// <summary>
39-
/// Initializes a new instance of the <see cref="BiasingBehavior"/> class.
39+
/// Initializes a new instance of the <see cref="Biasing"/> class.
4040
/// </summary>
4141
/// <param name="context">The context.</param>
4242
/// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
43-
public BiasingBehavior(BehavioralBindingContext context)
43+
public Biasing(BehavioralBindingContext context)
4444
: base(context)
4545
{
4646
// Make sure that we have access to the voltage over the behavior

0 commit comments

Comments
 (0)