Skip to content

Commit a20b2de

Browse files
committed
Support for lmin, lmax, wmin, wmax.
1 parent f4aee41 commit a20b2de

24 files changed

Lines changed: 982 additions & 10 deletions
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using SpiceSharp.Attributes;
2+
using SpiceSharp.Behaviors;
3+
using SpiceSharp.Components;
4+
using SpiceSharp.Entities;
5+
using SpiceSharp.Simulations;
6+
using System.Collections.Generic;
7+
8+
namespace SpiceSharpBSIM.Components.Semiconductors.BSIM.BSIM3Behaviors
9+
{
10+
/// <summary>
11+
/// A binding context for an aggregate model.
12+
/// </summary>
13+
[BindingContextFor(typeof(BSIM3AggregateModel))]
14+
public class AggregateModelBindingContext : BindingContext
15+
{
16+
private readonly HashSet<IBehaviorContainer> _set;
17+
18+
/// <summary>
19+
/// Gets the models
20+
/// </summary>
21+
public IEnumerable<IBehaviorContainer> Models => _set;
22+
23+
/// <summary>
24+
/// Creates a binding context for aggregate models.
25+
/// </summary>
26+
/// <param name="aggregateModel">The model</param>
27+
/// <param name="simulation">The simulation.</param>
28+
/// <param name="behaviors">The behaviors.</param>
29+
public AggregateModelBindingContext(BSIM3AggregateModel aggregateModel,
30+
ISimulation simulation,
31+
IBehaviorContainer behaviors)
32+
: base(aggregateModel, simulation, behaviors)
33+
{
34+
// First make the behaviors for all sub-models
35+
_set = new HashSet<IBehaviorContainer>();
36+
foreach (var model in aggregateModel.Models)
37+
{
38+
// Create the behaviors for the different models
39+
model.CreateBehaviors(simulation);
40+
_set.Add(simulation.EntityBehaviors[model.Name]);
41+
}
42+
}
43+
}
44+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using SpiceSharp;
2+
using SpiceSharp.Attributes;
3+
using SpiceSharp.Behaviors;
4+
using SpiceSharp.Components;
5+
using System.Collections.Generic;
6+
7+
namespace SpiceSharpBSIM.Components.Semiconductors.BSIM.BSIM3Behaviors
8+
{
9+
/// <summary>
10+
/// A temperature behavior for a <see cref="BSIM3AggregateModel"/>.
11+
/// </summary>
12+
[BehaviorFor(typeof(BSIM3AggregateModel)), AddBehaviorIfNo(typeof(ITemperatureBehavior))]
13+
public class AggregateModelTemperatureBehavior : Behavior, ITemperatureBehavior
14+
{
15+
private readonly List<ModelTemperatureBehavior> _modelTemperatureBehaviors;
16+
17+
/// <summary>
18+
/// Creates a new <see cref="AggregateModelTemperatureBehavior"/>.
19+
/// </summary>
20+
/// <param name="context">The binding context.</param>
21+
public AggregateModelTemperatureBehavior(AggregateModelBindingContext context)
22+
: base(context)
23+
{
24+
_modelTemperatureBehaviors = [];
25+
foreach (var behaviors in context.Models)
26+
{
27+
// We require the model temperature behavior to exist.
28+
var behavior = behaviors.GetValue<ModelTemperatureBehavior>();
29+
_modelTemperatureBehaviors.Add(behavior);
30+
}
31+
}
32+
33+
/// <summary>
34+
/// Gets a model for a given size.
35+
/// </summary>
36+
/// <param name="width">The width.</param>
37+
/// <param name="length">The length.</param>
38+
/// <returns>Returns the model behavior.</returns>
39+
/// <exception cref="SpiceSharpException">Thrown if no valid model could be found.</exception>
40+
public ModelTemperatureBehavior GetModel(double width, double length)
41+
{
42+
foreach (var behavior in _modelTemperatureBehaviors)
43+
{
44+
if (behavior.Parameters.Lmin.Given && length < behavior.Parameters.Lmin)
45+
continue;
46+
if (behavior.Parameters.Lmax.Given && length > behavior.Parameters.Lmax)
47+
continue;
48+
if (behavior.Parameters.Wmin.Given && width < behavior.Parameters.Wmin)
49+
continue;
50+
if (behavior.Parameters.Wmax.Given && width > behavior.Parameters.Wmax)
51+
continue;
52+
return behavior;
53+
}
54+
throw new SpiceSharpException($"There is no model that can be used for sizes W={width} and L={length}.");
55+
}
56+
57+
/// <inheritdoc />
58+
public void Temperature()
59+
{
60+
// The models have been created already, so no need to do anything here.
61+
}
62+
}
63+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using SpiceSharp.Attributes;
2+
using SpiceSharp.Entities;
3+
using System.Collections.Generic;
4+
5+
namespace SpiceSharp.Components
6+
{
7+
/// <summary>
8+
/// An aggregate for <see cref="BSIM3Model"/> that have
9+
/// different lmin/lmax/wmin/wmax parameters.
10+
/// </summary>
11+
[AutoGeneratedBehaviors]
12+
public partial class BSIM3AggregateModel : Entity
13+
{
14+
/// <summary>
15+
/// Gets the models in the aggregate model based on sizes.
16+
/// </summary>
17+
public HashSet<BSIM3Model> Models { get; } = [];
18+
19+
/// <summary>
20+
/// Creates an aggregate model.
21+
/// </summary>
22+
/// <param name="name">The name.</param>
23+
public BSIM3AggregateModel(string name)
24+
: base(name)
25+
{
26+
}
27+
28+
/// <summary>
29+
/// Creates an aggregate model based on sizes.
30+
/// </summary>
31+
/// <param name="name"></param>
32+
/// <param name="models"></param>
33+
public BSIM3AggregateModel(string name, IEnumerable<BSIM3Model> models)
34+
: base(name)
35+
{
36+
foreach (var model in models)
37+
Models.Add(model);
38+
}
39+
40+
/// <inheritdoc />
41+
public override IEntity Clone()
42+
{
43+
var n = new BSIM3AggregateModel(Name);
44+
foreach (var model in Models)
45+
n.Models.Add((BSIM3Model)model.Clone());
46+
return n;
47+
}
48+
}
49+
}

SpiceSharpBSIM/Components/Semiconductors/BSIM/BSIM3Behaviors/ModelParameters.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using SpiceSharp;
22
using SpiceSharp.Attributes;
3+
using SpiceSharp.Components;
34
using SpiceSharp.ParameterSets;
45

56
namespace SpiceSharpBSIM.Components.Semiconductors.BSIM.BSIM3Behaviors

SpiceSharpBSIM/Components/Semiconductors/BSIM/BSIM3Behaviors/TemperatureBehavior.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,29 @@ public class TemperatureBehavior : Behavior, ITemperatureBehavior, IParameterize
5252
public double Vjdm { get; private set; }
5353
public double IsEvjdm { get; private set; }
5454

55+
/// <summary>
56+
/// Gets the name of the model
57+
/// </summary>
58+
[ParameterName("model"), ParameterInfo("The name of the model.")]
59+
public string ModelName => ModelTemperature.Name;
60+
5561
/// <summary>
5662
/// Constructor
5763
/// </summary>
5864
public TemperatureBehavior(ComponentBindingContext context)
5965
: base(context)
6066
{
6167
Parameters = context.GetParameterSet<BaseParameters>();
62-
ModelParameters = context.ModelBehaviors.GetParameterSet<ModelParameters>();
63-
ModelTemperature = context.ModelBehaviors.GetValue<ModelTemperatureBehavior>();
68+
if (context.ModelBehaviors.TryGetValue<AggregateModelTemperatureBehavior>(out var aggregateBehavior))
69+
{
70+
ModelTemperature = aggregateBehavior.GetModel(Parameters.Width, Parameters.Length);
71+
ModelParameters = ModelTemperature.Parameters;
72+
}
73+
else
74+
{
75+
ModelParameters = context.ModelBehaviors.GetParameterSet<ModelParameters>();
76+
ModelTemperature = context.ModelBehaviors.GetValue<ModelTemperatureBehavior>();
77+
}
6478
Setup();
6579
}
6680

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using SpiceSharp.Attributes;
2+
using SpiceSharp.Behaviors;
3+
using SpiceSharp.Components;
4+
using SpiceSharp.Entities;
5+
using SpiceSharp.Simulations;
6+
using System.Collections.Generic;
7+
8+
namespace SpiceSharpBSIM.Components.Semiconductors.BSIM.BSIM3v0Behaviors
9+
{
10+
/// <summary>
11+
/// A binding context for an aggregate model.
12+
/// </summary>
13+
[BindingContextFor(typeof(BSIM3v0AggregateModel))]
14+
public class AggregateModelBindingContext : BindingContext
15+
{
16+
private readonly HashSet<IBehaviorContainer> _set;
17+
18+
/// <summary>
19+
/// Gets the models
20+
/// </summary>
21+
public IEnumerable<IBehaviorContainer> Models => _set;
22+
23+
/// <summary>
24+
/// Creates a binding context for aggregate models.
25+
/// </summary>
26+
/// <param name="aggregateModel">The model</param>
27+
/// <param name="simulation">The simulation.</param>
28+
/// <param name="behaviors">The behaviors.</param>
29+
public AggregateModelBindingContext(BSIM3v0AggregateModel aggregateModel,
30+
ISimulation simulation,
31+
IBehaviorContainer behaviors)
32+
: base(aggregateModel, simulation, behaviors)
33+
{
34+
// First make the behaviors for all sub-models
35+
_set = new HashSet<IBehaviorContainer>();
36+
foreach (var model in aggregateModel.Models)
37+
{
38+
// Create the behaviors for the different models
39+
model.CreateBehaviors(simulation);
40+
_set.Add(simulation.EntityBehaviors[model.Name]);
41+
}
42+
}
43+
}
44+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using SpiceSharp;
2+
using SpiceSharp.Attributes;
3+
using SpiceSharp.Behaviors;
4+
using SpiceSharp.Components;
5+
using System.Collections.Generic;
6+
7+
namespace SpiceSharpBSIM.Components.Semiconductors.BSIM.BSIM3v0Behaviors
8+
{
9+
/// <summary>
10+
/// A temperature behavior for a <see cref="BSIM3AggregateModel"/>.
11+
/// </summary>
12+
[BehaviorFor(typeof(BSIM3v0AggregateModel)), AddBehaviorIfNo(typeof(ITemperatureBehavior))]
13+
public class AggregateModelTemperatureBehavior : Behavior, ITemperatureBehavior
14+
{
15+
private readonly List<ModelTemperatureBehavior> _modelTemperatureBehaviors;
16+
17+
/// <summary>
18+
/// Creates a new <see cref="AggregateModelTemperatureBehavior"/>.
19+
/// </summary>
20+
/// <param name="context">The binding context.</param>
21+
public AggregateModelTemperatureBehavior(AggregateModelBindingContext context)
22+
: base(context)
23+
{
24+
_modelTemperatureBehaviors = [];
25+
foreach (var behaviors in context.Models)
26+
{
27+
// We require the model temperature behavior to exist.
28+
var behavior = behaviors.GetValue<ModelTemperatureBehavior>();
29+
_modelTemperatureBehaviors.Add(behavior);
30+
}
31+
}
32+
33+
/// <summary>
34+
/// Gets a model for a given size.
35+
/// </summary>
36+
/// <param name="width">The width.</param>
37+
/// <param name="length">The length.</param>
38+
/// <returns>Returns the model behavior.</returns>
39+
/// <exception cref="SpiceSharpException">Thrown if no valid model could be found.</exception>
40+
public ModelTemperatureBehavior GetModel(double width, double length)
41+
{
42+
foreach (var behavior in _modelTemperatureBehaviors)
43+
{
44+
if (behavior.Parameters.Lmin.Given && length < behavior.Parameters.Lmin)
45+
continue;
46+
if (behavior.Parameters.Lmax.Given && length > behavior.Parameters.Lmax)
47+
continue;
48+
if (behavior.Parameters.Wmin.Given && width < behavior.Parameters.Wmin)
49+
continue;
50+
if (behavior.Parameters.Wmax.Given && width > behavior.Parameters.Wmax)
51+
continue;
52+
return behavior;
53+
}
54+
throw new SpiceSharpException($"There is no model that can be used for sizes W={width} and L={length}.");
55+
}
56+
57+
/// <inheritdoc />
58+
public void Temperature()
59+
{
60+
// The models have been created already, so no need to do anything here.
61+
}
62+
}
63+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using SpiceSharp.Attributes;
2+
using SpiceSharp.Entities;
3+
using System.Collections.Generic;
4+
5+
namespace SpiceSharp.Components
6+
{
7+
/// <summary>
8+
/// An aggregate for <see cref="BSIM3v0Model"/> that have
9+
/// different lmin/lmax/wmin/wmax parameters.
10+
/// </summary>
11+
[AutoGeneratedBehaviors]
12+
public partial class BSIM3v0AggregateModel : Entity
13+
{
14+
/// <summary>
15+
/// Gets the models in the aggregate model based on sizes.
16+
/// </summary>
17+
public HashSet<BSIM3v0Model> Models { get; } = [];
18+
19+
/// <summary>
20+
/// Creates an aggregate model.
21+
/// </summary>
22+
/// <param name="name">The name.</param>
23+
public BSIM3v0AggregateModel(string name)
24+
: base(name)
25+
{
26+
}
27+
28+
/// <summary>
29+
/// Creates an aggregate model based on sizes.
30+
/// </summary>
31+
/// <param name="name"></param>
32+
/// <param name="models"></param>
33+
public BSIM3v0AggregateModel(string name, IEnumerable<BSIM3v0Model> models)
34+
: base(name)
35+
{
36+
foreach (var model in models)
37+
Models.Add(model);
38+
}
39+
40+
/// <inheritdoc />
41+
public override IEntity Clone()
42+
{
43+
var n = new BSIM3v0AggregateModel(Name);
44+
foreach (var model in Models)
45+
n.Models.Add((BSIM3v0Model)model.Clone());
46+
return n;
47+
}
48+
}
49+
}

SpiceSharpBSIM/Components/Semiconductors/BSIM/BSIM3v0Behaviors/TemperatureBehavior.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public class TemperatureBehavior : Behavior, ITemperatureBehavior, IParameterize
3636

3737
protected double _drainConductance, _sourceConductance, _cgso, _cgdo;
3838

39+
/// <summary>
40+
/// Gets the name of the model
41+
/// </summary>
42+
[ParameterName("model"), ParameterInfo("The name of the model.")]
43+
public string ModelName => ModelTemperature.Name;
44+
3945
/// <summary>
4046
/// Creates a new <see cref="TemperatureBehavior"/>.
4147
/// </summary>
@@ -45,8 +51,16 @@ public TemperatureBehavior(ComponentBindingContext context)
4551
{
4652
_temperature = context.GetState<ITemperatureSimulationState>();
4753
Parameters = context.GetParameterSet<BaseParameters>();
48-
ModelTemperature = context.ModelBehaviors.GetValue<ModelTemperatureBehavior>();
49-
ModelParameters = context.ModelBehaviors.GetParameterSet<ModelParameters>();
54+
if (context.ModelBehaviors.TryGetValue<AggregateModelTemperatureBehavior>(out var aggregateBehavior))
55+
{
56+
ModelTemperature = aggregateBehavior.GetModel(Parameters.W, Parameters.L);
57+
ModelParameters = ModelTemperature.Parameters;
58+
}
59+
else
60+
{
61+
ModelParameters = context.ModelBehaviors.GetParameterSet<ModelParameters>();
62+
ModelTemperature = context.ModelBehaviors.GetValue<ModelTemperatureBehavior>();
63+
}
5064
}
5165

5266
/// <summary>

0 commit comments

Comments
 (0)