Template Class SystemModel

Inheritance Relationships

Base Type

Class Documentation

template<typename scalar_type, typename index_type>
class SystemModel : public GridKit::PhasorDynamics::Component<scalar_type, index_type>

Prototype for a system model class.

This class maps component data to system data and implements Model::Evaluator for the system model. This is still work in progress and code is not optimized.

Todo:

Address thread safety for the system model methods.

Public Functions

SystemModel()

Constructor for the system model.

SystemModel(const SystemModelData<RealT, IdxT> &data)

Construct a new System Model object.

Parameters:

data[in] - Data structure with complete system data

Pre:

SystemModelData contains consistent connectivity information and physically meaningful model parameters.

Post:

All component models in SystemModelData are created, and correctly connected into the system model.

virtual ~SystemModel()

Destructor for the system model.

If the SystemModel owns the components, it needs to delete them upon destructor call.

virtual int setGridKitComponentID(IdxT component_id) override

Set component ID.

Note

Should default to 0. The system model could be used as a component in a larger system that would need to set this value.

virtual int allocate() override

Allocate buses, components, and system objects.

This method first allocates bus objects, then component objects, and computes system size (number of unknowns). Once the size is computed, system global objects are allocated.

Post:

size_ >= 1

virtual int verify() const override

Verify all components are configured correctly.

This method accumulates and returns the number of errors given by components. It should return 0 when all is well.

virtual int initialize() override

Initialize buses first, then all the other components.

Buses must be initialized before other components, because other components may write to buses during the initialization.

Also, generators may write to control devices (e.g. governors, exciters, etc.) during the initialization.

Todo:

Implement writting to system vectors in a thread-safe way.

Note

Currently assuming each component stores variables contiguously in memory and that these are simply concateneted in the global system.

Pre:

All buses and components must be allocated at this point.

Pre:

Bus variables are written before component variables in the system variable vector.

virtual bool hasJacobian() override

Check components for Jacobian availability.

Returns:

true

Returns:

false

void initializeMonitor()

Add monitors from buses and components and start monitor.

virtual void startMonitor() override

Get monitor ready for output.

virtual void stopMonitor() override

Tell monitor to wrap up.

virtual bool monitoring() const override

Is there something to monitor? Defaults to false

virtual void printMonitoredVariables() const override

Print variables at current state.

virtual int tagDifferentiable() override

Todo:

Tagging differential variables

Identify what variables in the system of differential-algebraic equations are differential variables, i.e. their derivatives appear in the equations.

virtual int evaluateResidual() override

Compute system residual vector.

First, update bus and component variables from the system solution vector. Next, evaluate residuals in buses and components, and then copy values to the global residual vector.

Todo:

Here, components write to local values, which are then copied to global system vectors. Make components write to the system vectors directly.

Warning

Residuals must be computed for buses, before component residuals are computed. Buses own residuals for currents Ir and Ii, but the contributions to these residuals come from components. Buses assign their residual values, while components add to those values by in-place adition. This is why (for now) bus residuals need to be computed first.

virtual int evaluateJacobian() override

Evaluate system Jacobian.

First, initialize bus Jacobians to 0. Then, evaluate component Jacobians (internal block and bus Jacobian contributions). Once component Jacobians are evaluated, store the result in the system Jacobian. Finally, store bus Jacobians into the system Jacobian after all component have added their contributions.

Todo:

split the initial assembly from updating values. This will the slow otherwise.

inline virtual CsrMatrixT *getCsrJacobian() const override

Return a pointer to the CSR Jacobian.

Todo:

Remove this and use CsrMatirx for jac_

void updateVariables()

Update variables in buses and components.

virtual void updateTime(RealT t, RealT a) override

Update time.

void addBus(BusT *bus)

Add bus.

Add bus at the end of the bus array and map bus ID with GridKit’s ID for the bus

void addSignal(SignalT *signal)

Add signal.

Add signal at the end of the signals array and map signal ID with GridKit’s ID for the signal

void addComponent(ComponentT *component)

Add component.

Add component at the end of the components array and set GridKit’s component ID

Todo:

: No integer user-facing component_id for now, but we could map GridKit’s component ID to the disambiguation_string

void addFault(ComponentT *component)

Add fault.

The fault is added to the components array, and we keep a map to its location, so it can easily be accessed.

void setSystemBase(RealT freq_system_base, RealT va_system_base)

Set system bases and propagate them to existing components.

Parameters:
  • freq_system_base[in] - System frequency base in Hz.

  • va_system_base[in] - System power base in VA.

BusT *getBus(IdxT bus_id)

Return pointer to a bus.

SignalT *getSignal(IdxT signal_id)

Return pointer to a signal.

ComponentT *getComponent(IdxT gridkit_component_id)

Return pointer to a component.

BusFault<ScalarT, IdxT> *getBusFault(IdxT fault_id)

Return pointer to a bus fault model.

This function is used to provide easier access to setting and clearing faults from the SystemModel interface.