Class Simulation
A template for any simulation.
Inherited Members
Namespace: SpiceSharp.Simulations
Assembly: SpiceSharp.dll
Syntax
public abstract class Simulation : ParameterSetCollection, ISimulation, IStateful, IBehavioral, IParameterSetCollection, IParameterSet
Constructors
Simulation(string)
Initializes a new instance of the Simulation class.
Declaration
protected Simulation(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the simulation. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
Fields
Actions
The bits that are reserved for actions.
Declaration
public const int Actions = -65536
Field Value
Type | Description |
---|---|
int |
AfterExecute
Represents the action after each execution.
Declaration
public const int AfterExecute = 524288
Field Value
Type | Description |
---|---|
int |
AfterSetup
Represents the action after setting up behaviors.
Declaration
public const int AfterSetup = 65536
Field Value
Type | Description |
---|---|
int |
AfterValidation
Represents the action after validating.
Declaration
public const int AfterValidation = 131072
Field Value
Type | Description |
---|---|
int |
BeforeExecute
Represents the action before each execution.
Declaration
public const int BeforeExecute = 262144
Field Value
Type | Description |
---|---|
int |
Exports
The bits that are reserved for exports.
Declaration
public const int Exports = 65535
Field Value
Type | Description |
---|---|
int |
Properties
Behaviors
Gets all behavior types that are used by the class.
Declaration
public virtual 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. |
Name
Gets the name of the ISimulation.
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
string | The name. |
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 virtual IEnumerable<Type> States { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Type> | The states. |
Statistics
Gets the statistics.
Declaration
public SimulationStatistics Statistics { get; }
Property Value
Type | Description |
---|---|
SimulationStatistics | The statistics. |
Status
Gets the current status of the ISimulation.
Declaration
public SimulationStatus Status { get; }
Property Value
Type | Description |
---|---|
SimulationStatus | The current status. |
Methods
CreateBehaviors(IEntityCollection)
Creates all behaviors for the simulation.
Declaration
protected virtual void CreateBehaviors(IEntityCollection entities)
Parameters
Type | Name | Description |
---|---|---|
IEntityCollection | entities | The entities. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
CreateStates()
Creates all the simulation states for the simulation.
Declaration
protected abstract void CreateStates()
Execute(int)
Executes the simulation.
Declaration
protected abstract IEnumerable<int> Execute(int mask)
Parameters
Type | Name | Description |
---|---|---|
int | mask | A bit mask for simulation export identifiers. |
Returns
Type | Description |
---|---|
IEnumerable<int> |
Exceptions
Type | Condition |
---|---|
SpiceSharpException | Thrown if the simulation can't continue. |
Finish()
Finish the simulation.
Declaration
protected abstract void Finish()
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 virtual IEnumerable<int> Rerun(int mask = 65535)
Parameters
Type | Name | Description |
---|---|---|
int | mask | A bit mask for simulation export identifiers. |
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 virtual IEnumerable<int> Run(IEntityCollection entities, int mask = 65535)
Parameters
Type | Name | Description |
---|---|---|
IEntityCollection | entities | The entities. |
int | mask | A bit mask for simulation export identifiers. |
Returns
Type | Description |
---|---|
IEnumerable<int> | An enumerable that yields a type identifier every time new simulation data is available. |
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. |
UsesBehavior(Type)
Checks if the class uses the specified behavior.
Declaration
public virtual 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 virtual 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 virtual bool UsesState<S>() where S : ISimulationState
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
S | The simulation state type. |
Validate(IEntityCollection)
Validates the input.
Declaration
protected abstract void Validate(IEntityCollection entities)
Parameters
Type | Name | Description |
---|---|---|
IEntityCollection | entities | The entities. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
ValidationFailedException | Thrown if the validation failed. |
Validate(IRules, IEntityCollection)
A default implementation for validating entities and behaviors using the specified rules.
Declaration
protected void Validate(IRules rules, IEntityCollection entities)
Parameters
Type | Name | Description |
---|---|---|
IRules | rules | The rules. |
IEntityCollection | entities | The entities. |
Exceptions
Type | Condition |
---|---|
ValidationFailedException | Thrown if the validation failed. |