Class SimulationWrapper
A common wrapper for a simulation. It allows an extra layer of an ISimulation. The wrapper can inject configurations, states, solved variables, etc.
Inherited Members
Namespace: SpiceSharp.Components.Common
Assembly: SpiceSharp.dll
Syntax
public class SimulationWrapper : ISimulation, IStateful, IBehavioral, IParameterSetCollection, IParameterSet
Constructors
SimulationWrapper(ISimulation, IBehaviorContainerCollection, ITypeSet<ISimulationState>)
Initializes a new instance of the SimulationWrapper class.
Declaration
public SimulationWrapper(ISimulation parent, IBehaviorContainerCollection behaviors, ITypeSet<ISimulationState> states)
Parameters
Type | Name | Description |
---|---|---|
ISimulation | parent | The parent. |
IBehaviorContainerCollection | behaviors | The behaviors. |
ITypeSet<ISimulationState> | states | The simulation states. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
Properties
Behaviors
Gets all behavior types that are used by the class.
Declaration
public IEnumerable<Type> Behaviors { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Type> | The behaviors. |
CurrentRun
Gets the index of the current simulation run.
Declaration
public int CurrentRun { get; }
Property Value
Type | Description |
---|---|
int |
EntityBehaviors
Gets the entity behaviors.
Declaration
public IBehaviorContainerCollection EntityBehaviors { get; }
Property Value
Type | Description |
---|---|
IBehaviorContainerCollection | The entity behaviors. |
LocalStates
Gets the local states. These states are returned first!
Declaration
public ITypeSet<ISimulationState> LocalStates { get; }
Property Value
Type | Description |
---|---|
ITypeSet<ISimulationState> | The local states. |
Name
Gets the name of the ISimulation.
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
string | The name. |
ParameterSets
Gets all the parameter sets of this instance.
Declaration
public virtual IEnumerable<IParameterSet> ParameterSets { get; }
Property Value
Type | Description |
---|---|
IEnumerable<IParameterSet> | The parameter sets. |
Parent
Gets the parent simulation.
Declaration
protected ISimulation Parent { get; }
Property Value
Type | Description |
---|---|
ISimulation | The parent simulation. |
Repeat
If set, the simulation is repeated. The property is automatically reset at the start of an execution.
Declaration
public bool Repeat { get; set; }
Property Value
Type | Description |
---|---|
bool |
States
Gets all the states that the class uses.
Declaration
public IEnumerable<Type> States { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Type> | The states. |
Status
Gets the current status of the ISimulation.
Declaration
public SimulationStatus Status { get; }
Property Value
Type | Description |
---|---|
SimulationStatus | The current status. |
Methods
CreateParameterSetter<P>(string)
Creates an action that can set the parameter of the specified type and with the specified name.
Declaration
public virtual Action<P> CreateParameterSetter<P>(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the parameter. |
Returns
Type | Description |
---|---|
Action<P> | An action that can set the parameter value, or |
Type Parameters
Name | Description |
---|---|
P | The parameter value type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
CreatePropertyGetter<P>(string)
Creates a function that can get the value of a property of the specified type and with the specified name.
Declaration
public virtual Func<P> CreatePropertyGetter<P>(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the property. |
Returns
Type | Description |
---|---|
Func<P> | A function that can get the property value, or |
Type Parameters
Name | Description |
---|---|
P | The property value type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
GetParameterSet<P>()
Gets the parameter set of the specified type.
Declaration
public virtual P GetParameterSet<P>() where P : IParameterSet, ICloneable<P>
Returns
Type | Description |
---|---|
P | The parameter set. |
Type Parameters
Name | Description |
---|---|
P | The parameter set type. |
Exceptions
Type | Condition |
---|---|
TypeNotFoundException | Thrown if the parameter set could not be found. |
GetParentState<S>()
Gets the state of the parent simulation of the specified type, bypassing any local states.
Declaration
public S GetParentState<S>() where S : ISimulationState
Returns
Type | Description |
---|---|
S | The state. |
Type Parameters
Name | Description |
---|---|
S | The simulation state type. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the simulation state is not defined. |
GetProperty<P>(string)
Gets the value of a property of the specified type and with the specified name.
Declaration
public virtual P GetProperty<P>(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the property. |
Returns
Type | Description |
---|---|
P | The value of the property. |
Type Parameters
Name | Description |
---|---|
P | The property value type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
ParameterNotFoundException | Thrown if a parameter by the specified name could not be found. |
GetState<S>()
Gets the state of the specified type.
Declaration
public virtual S GetState<S>() where S : ISimulationState
Returns
Type | Description |
---|---|
S | The type, or |
Type Parameters
Name | Description |
---|---|
S | The simulation state type. |
Exceptions
Type | Condition |
---|---|
TypeNotFoundException | Thrown if the simulation state is not defined on this instance. |
Rerun(int)
Reruns the ISimulation with the previous behaviors. Only one enumerable can run at any given time.
Declaration
public IEnumerable<int> Rerun(int exportMask = -1)
Parameters
Type | Name | Description |
---|---|---|
int | exportMask |
Returns
Type | Description |
---|---|
IEnumerable<int> | An enumerable that yields a type identifier every time new simulation data is available. |
Run(IEntityCollection, int)
Runs the ISimulation on the specified IEntityCollection. Only one enumerable can run at any given time.
Declaration
public IEnumerable<int> Run(IEntityCollection entities, int exportMask = -1)
Parameters
Type | Name | Description |
---|---|---|
IEntityCollection | entities | The entities. |
int | exportMask |
Returns
Type | Description |
---|---|
IEnumerable<int> | An enumerable that yields a type identifier every time new simulation data is available. |
Remarks
The behaviors are stored in the specified EntityBehaviors of the SimulationWrapper. This can be a local collection, allowing you to keep a part of the behaviors separate.
SetParameter<P>(string, P)
Sets a parameter in the parameter set of the specified type and with the specified name.
Declaration
public virtual void SetParameter<P>(string name, P value)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the parameter. |
P | value | The value that the parameter should be set to. |
Type Parameters
Name | Description |
---|---|
P | The parameter value type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
ParameterNotFoundException | Thrown if a parameter by the specified name could not be found. |
TryGetParameterSet<P>(out P)
Tries to get the parameter set of the specified type.
Declaration
public virtual bool TryGetParameterSet<P>(out P value) where P : IParameterSet, ICloneable<P>
Parameters
Type | Name | Description |
---|---|---|
P | value | The parameter set. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
P | The parameter set type. |
TryGetParentState<S>(out S)
Tries the state of the get parent simulatio nof the specified type, bypassing any local states.
Declaration
public bool TryGetParentState<S>(out S state) where S : ISimulationState
Parameters
Type | Name | Description |
---|---|---|
S | state | The simulation state. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
S | The simulation state type. |
TryGetProperty<P>(string, out P)
Tries to get the value of a property of the specified type and with the specified name.
Declaration
public virtual bool TryGetProperty<P>(string name, out P value)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the property. |
P | value | The value of the property if the property was found. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
P | The property value type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
TryGetState<S>(out S)
Tries to get a state of the specified type.
Declaration
public virtual bool TryGetState<S>(out S state) where S : ISimulationState
Parameters
Type | Name | Description |
---|---|---|
S | state | The state. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
S | The simulation state type. |
TrySetParameter<P>(string, P)
Tries to set a parameter in the parameter set of the specified type and with the specified name.
Declaration
public virtual bool TrySetParameter<P>(string name, P value)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the parameter. |
P | value | The value that the parameter should be set to. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
P | The parameter value type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
UsesBehavior(Type)
Checks if the class uses the specified behavior.
Declaration
public bool UsesBehavior(Type behaviorType)
Parameters
Type | Name | Description |
---|---|---|
Type | behaviorType |
Returns
Type | Description |
---|---|
bool |
|
UsesBehaviors<B>()
Checks if the class uses the specified behaviors.
Declaration
public bool UsesBehaviors<B>() where B : IBehavior
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
B | The behavior type. |
UsesState<S>()
Checks if the class uses the specified state.
Declaration
public bool UsesState<S>() where S : ISimulationState
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
S | The simulation state type. |