Skip to content

Commit

Permalink
Merge pull request #57 from SpiceSharp/development
Browse files Browse the repository at this point in the history
v3.1
  • Loading branch information
svenboulanger authored Apr 24, 2021
2 parents 7c84a11 + e361216 commit d622fb4
Show file tree
Hide file tree
Showing 29 changed files with 425 additions and 243 deletions.
39 changes: 16 additions & 23 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
# This is a basic workflow to help you get started with Actions

name: Publish to NuGet

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
release:
branches: [ master ]
types: [ published ]

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

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Setup MSBuild environment
uses: microsoft/setup-msbuild@v1.0.2

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Restore dependencies
run: dotnet restore SpiceSharpBehavioral\SpiceSharpBehavioral.csproj
- uses: actions/checkout@master

- name: Setup dotnet tooling
uses: actions/setup-dotnet@master
with:
dotnet-version: '5.0.100'

- name: Restore dependencies
run: dotnet restore

- name: Compile Spice# in Release mode
run: msbuild SpiceSharpBehavioral\SpiceSharpBehavioral.csproj -p:Configuration=Release
- name: Compile Spice#
run: dotnet build SpiceSharpBehavioral\SpiceSharpBehavioral.csproj --configuration Release --no-restore

- name: Publish to NuGet
env:
APIKEY: ${{ secrets.NUGET_APIKEY }}
run: dotnet nuget push .\SpiceSharpBehavioral\bin\Release\SpiceSharpBehavioral.*.nupkg -k $env:APIKEY -s "https://api.nuget.org/v3/index.json"
- name: Publish to NuGet
env:
APIKEY: ${{ secrets.NUGET_APIKEY }}
run: dotnet nuget push .\SpiceSharpBehavioral\bin\Release\SpiceSharpBehavioral.*.nupkg -k $env:APIKEY -s "https://api.nuget.org/v3/index.json"

32 changes: 12 additions & 20 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# This is a basic workflow to help you get started with Actions

name: Linux Tests

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

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

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: docker://mono:latest

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- uses: actions/checkout@master

- name: Setup dotnet tooling
uses: actions/setup-dotnet@master
with:
dotnet-version: '5.0.100'

- name: Restore dependencies
run: dotnet restore

- name: Compile Spice#
run: msbuild SpiceSharpBehavioral/SpiceSharpBehavioral.csproj -p:Configuration=Debug
- name: Compile Spice#.Behavioral
run: dotnet build SpiceSharpBehavioral/SpiceSharpBehavioral.csproj --configuration Debug --no-restore

- name: Compile Spice#.Test
run: msbuild SpiceSharpBehavioralTest/SpiceSharpBehavioralTest.csproj -p:Configuration=Debug

- name: Run tests
run: dotnet test SpiceSharpBehavioralTest/bin/Debug/SpiceSharpBehavioralTest.dll


- name: Compile Spice#.Behavioral.Test
run: dotnet test SpiceSharpBehavioralTest/SpiceSharpBehavioralTest.csproj --configuration Debug --no-restore
31 changes: 12 additions & 19 deletions .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# This is a basic workflow to help you get started with Actions

name: MacOS Tests

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

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

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Setup Xamarin environment
uses: maxim-lobanov/setup-xamarin@v1.1

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- uses: actions/checkout@master

- name: Setup dotnet tooling
uses: actions/setup-dotnet@master
with:
dotnet-version: '5.0.100'

- name: Restore dependencies
run: dotnet restore

- name: Compile Spice#
run: msbuild SpiceSharpBehavioral/SpiceSharpBehavioral.csproj -p:Configuration=Debug
- name: Compile Spice#.Behavioral
run: dotnet build SpiceSharpbehavioral/SpiceSharpBehavioral.csproj --configuration Debug --no-restore

- name: Compile Spice#.Test
run: msbuild SpiceSharpBehavioralTest/SpiceSharpBehavioralTest.csproj -p:Configuration=Debug

- name: Run tests
run: dotnet test SpiceSharpBehavioralTest/bin/Debug/SpiceSharpBehavioralTest.dll
- name: Compile Spice#.Behavioral.Test
run: dotnet test SpiceSharpBehavioralTest/SpiceSharpBehavioralTest.csproj --configuration Debug --no-restore
32 changes: 12 additions & 20 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# This is a basic workflow to help you get started with Actions

name: Windows Tests

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

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

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Setup MSBuild environment
uses: microsoft/setup-msbuild@v1.0.2

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- uses: actions/checkout@master

- name: Setup dotnet tooling
uses: actions/setup-dotnet@master
with:
dotnet-version: '5.0.100'

- name: Restore dependencies
run: dotnet restore

- name: Compile Spice#
run: msbuild SpiceSharpBehavioral\SpiceSharpBehavioral.csproj -p:Configuration=Debug

- name: Compile Spice#.Test
run: msbuild SpiceSharpBehavioralTest\SpiceSharpBehavioralTest.csproj -p:Configuration=Debug

- name: Run tests
run: dotnet test SpiceSharpBehavioralTest/bin/Debug/SpiceSharpBehavioralTest.dll
- name: Compile Spice#.Behavioral
run: dotnet build SpiceSharpBehavioral/SpiceSharpBehavioral.csproj --configuration Debug --no-restore

- name: Compile Spice#.Behavioral.Test
run: dotnet test SpiceSharpBehavioralTest/SpiceSharpBehavioralTest.csproj --configuration Debug --no-restore
33 changes: 29 additions & 4 deletions SpiceSharpBehavioral/Components/BehavioralBindingContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SpiceSharp.Algebra;
using SpiceSharp.Attributes;
using SpiceSharp.Behaviors;
using SpiceSharp.Components.CommonBehaviors;
using SpiceSharp.Simulations;
Expand All @@ -16,6 +17,10 @@ namespace SpiceSharp.Components.BehavioralComponents
/// A context for behavioral components.
/// </summary>
/// <seealso cref="ComponentBindingContext" />
[BindingContextFor(typeof(BehavioralCapacitor))]
[BindingContextFor(typeof(BehavioralResistor))]
[BindingContextFor(typeof(BehavioralVoltageSource))]
[BindingContextFor(typeof(BehavioralCurrentSource))]
public class BehavioralBindingContext : ComponentBindingContext
{
/// <summary>
Expand Down Expand Up @@ -82,27 +87,47 @@ public IVariable<T> MapNode<T>(IVariableFactory<IVariable<T>> factory, VariableN
return factory.GetSharedVariable(node.Name);

case NodeTypes.Current:
var container = Simulation.EntityBehaviors[node.Name];
IBehaviorContainer container;
IBiasingBehavior tmpb;
IFrequencyBehavior tmpf;

// Get the relevant behaviors
if (Simulation.EntityBehaviors.Comparer.Equals(node.Name, Behaviors.Name))
container = Behaviors;
else
container = Simulation.EntityBehaviors[node.Name];

if (container == Behaviors)
{
if (ownBranch == null)
throw new SpiceSharpException($"The behavior for {Entity.Name} does not define a branch current.");
return ownBranch;
}
else if (container.TryGetValue<IBranchedBehavior<T>>(out var branched))
{
// Best-case scenario! Our behaviors define a branched behavior!
return branched.Branch;
else if (typeof(T) == typeof(double) && container.TryGetValue(out IBiasingBehavior tmpb) && tmpb is CurrentSources.Biasing biasing)
}
else if (typeof(T) == typeof(double) && container.TryGetValue(out tmpb) && tmpb is CurrentSources.Biasing biasing)
{
// If whatever is being is asked is the current from a current source, then we also don't have a problem
var result = new FuncVariable<double>($"I({biasing.Name})", () => biasing.Current, Units.Ampere);
return result as IVariable<T>;
}
else if (typeof(T) == typeof(Complex) && container.TryGetValue(out IFrequencyBehavior tmpf) && tmpf is CurrentSources.Frequency frequency)
else if (typeof(T) == typeof(Complex) && container.TryGetValue(out tmpf) && tmpf is CurrentSources.Frequency frequency)
{
// Current source = no problem
var result = new FuncVariable<Complex>($"I({frequency.Name})", () => frequency.ComplexCurrent, Units.Ampere);
return result as IVariable<T>;
}
else
goto default;
{
var result = container.CreatePropertyGetter<T>("i");
if (result == null)
goto default;
SpiceSharpWarning.Warning(this, SpiceSharpBehavioral.Properties.Resources.LooseLinkCurrent.FormatString(container.Name));
return new FuncVariable<T>($"@{container.Name}[i]", result, Units.Ampere);
}

default:
throw new SpiceSharpException($"Could not determine the variable {node.Name}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using SpiceSharp.Attributes;
using SpiceSharp.Components.BehavioralComponents;
using SpiceSharp.Validation;
using System.Linq;

namespace SpiceSharp.Components
{
/// <summary>
/// A behavioral capacitor.
/// </summary>
/// <seealso cref="BehavioralComponent"/>
[Pin(0, "P"), Pin(1, "N")]
public class BehavioralCapacitor : BehavioralComponent
[Pin(0, "P"), Pin(1, "N"), Connected, AutoGeneratedBehaviors]
public partial class BehavioralCapacitor : BehavioralComponent, IRuleSubject
{
/// <summary>
/// The behavioral capacitor base pin count.
Expand Down Expand Up @@ -37,5 +39,14 @@ public BehavioralCapacitor(string name, string pos, string neg, string expressio
Connect(pos, neg);
Parameters.Expression = expression;
}

/// <inheritdoc/>
void IRuleSubject.Apply(IRules rules)
{
var p = rules.GetParameterSet<ComponentRuleParameters>();
var nodes = Nodes.Select(name => p.Factory.GetSharedVariable(name)).ToArray();
foreach (var rule in rules.GetRules<IConductiveRule>())
rule.AddPath(this, ConductionTypes.Ac, nodes[0], nodes[1]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace SpiceSharp.Components.BehavioralCapacitorBehaviors
/// <summary>
/// Biasing behavior for a <see cref="BehavioralCapacitor"/>
/// </summary>
public class BiasingBehavior : Behavior
public class Biasing : Behavior
{
/// <summary>
/// The variables.
Expand All @@ -36,11 +36,11 @@ public class BiasingBehavior : Behavior
protected readonly Dictionary<VariableNode, Node> Derivatives;

/// <summary>
/// Initializes a new instance of the <see cref="BiasingBehavior"/> class.
/// Initializes a new instance of the <see cref="Biasing"/> class.
/// </summary>
/// <param name="context">The context.</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is <c>null</c>.</exception>
public BiasingBehavior(BehavioralBindingContext context)
public Biasing(BehavioralBindingContext context)
: base(context)
{
// Make sure that we have access to the voltage over the behavior
Expand Down
Loading

0 comments on commit d622fb4

Please sign in to comment.