Drake
Diagram< T > Class Template Reference

Diagram is a System composed of one or more constituent Systems, arranged in a directed graph where the vertices are the constituent Systems themselves, and the edges connect the output of one constituent System to the input of another. More...

#include <systems/framework/diagram.h>

Inheritance diagram for Diagram< T >:
[legend]
Collaboration diagram for Diagram< T >:
[legend]

## Public Types

typedef std::pair< const System< T > *, intPortIdentifier

## Public Member Functions

template<typename U >
Diagram (const Diagram< U > &other)
Scalar-converting copy constructor. See System Scalar Conversion. More...

~Diagram () override

std::vector< const systems::System< T > * > GetSystems () const
Returns the list of contained Systems. More...

std::multimap< int, intGetDirectFeedthroughs () const final
Reports all direct feedthroughs from input ports to output ports. More...

std::unique_ptr< CompositeEventCollection< T > > AllocateCompositeEventCollection () const final
Allocates a DiagramEventCollection for this Diagram. More...

std::unique_ptr< Context< T > > AllocateContext () const override
Allocates a context, initialized with the correct numbers of concrete input ports and state variables for this System. More...

void SetDefaultState (const Context< T > &context, State< T > *state) const override
Assigns default values to all elements of the state. More...

void SetDefaultParameters (const Context< T > &context, Parameters< T > *params) const override
Assigns default values to all parameters. More...

void SetRandomState (const Context< T > &context, State< T > *state, RandomGenerator *generator) const override
Assigns random values to all elements of the state. More...

void SetRandomParameters (const Context< T > &context, Parameters< T > *params, RandomGenerator *generator) const override
Assigns random values to all parameters. More...

std::unique_ptr< SystemOutput< T > > AllocateOutput (const Context< T > &context) const override
Returns a container that can hold the values of all of this System's output ports. More...

std::unique_ptr< ContinuousState< T > > AllocateTimeDerivatives () const override
Aggregates the time derivatives from each subsystem into a DiagramTimeDerivatives. More...

std::unique_ptr< DiscreteValues< T > > AllocateDiscreteVariables () const override
Aggregates the discrete update variables from each subsystem into a DiagramDiscreteVariables. More...

void DoCalcTimeDerivatives (const Context< T > &context, ContinuousState< T > *derivatives) const override
Override this if you have any continuous state variables xc in your concrete System to calculate their time derivatives. More...

const ContinuousState< T > * GetSubsystemDerivatives (const ContinuousState< T > &derivatives, const System< T > *subsystem) const
Retrieves the state derivatives for a particular subsystem from the derivatives for the entire diagram. More...

const Context< T > & GetSubsystemContext (const System< T > &subsystem, const Context< T > &context) const
Returns a constant reference to the subcontext that corresponds to the system subsystem. More...

Context< T > & GetMutableSubsystemContext (const System< T > &subsystem, Context< T > *context) const
Returns the subcontext that corresponds to the system subsystem. More...

const CompositeEventCollection< T > & GetSubsystemCompositeEventCollection (const System< T > &subsystem, const CompositeEventCollection< T > &events) const
Returns the const subsystem composite event collection from events that corresponds to subsystem. More...

CompositeEventCollection< T > & GetMutableSubsystemCompositeEventCollection (const System< T > &subsystem, CompositeEventCollection< T > *events) const
Returns the mutable subsystem composite event collection that corresponds to subsystem. More...

State< T > & GetMutableSubsystemState (const System< T > &subsystem, Context< T > *context) const
Retrieves the state for a particular subsystem from the context for the entire diagram. More...

State< T > & GetMutableSubsystemState (const System< T > &subsystem, State< T > *state) const
Retrieves the state for a particular subsystem from the state for the entire diagram. More...

const State< T > & GetSubsystemState (const System< T > &subsystem, const State< T > &state) const
Retrieves the state for a particular subsystem from the state for the entire diagram. More...

void GetPath (std::stringstream *output) const override
Returns the full path of this Diagram in the tree of Diagrams. More...

void EvaluateSubsystemInputPort (const Context< T > *context, const InputPortDescriptor< T > &descriptor) const override
Evaluates the value of the subsystem input port with the given id in the given context. More...

int GetSystemIndexOrAbort (const System< T > *sys) const
Returns the index of the given sys in this diagram, or aborts if sys is not a member of the diagram. More...

Does not allow copy, move, or assignment
Diagram (const Diagram &)=delete

Diagramoperator= (const Diagram &)=delete

Diagram (Diagram &&)=delete

Diagramoperator= (Diagram &&)=delete

Graphviz methods
void GetGraphvizFragment (std::stringstream *dot) const override
Returns a Graphviz fragment describing this Diagram. More...

void GetGraphvizInputPortToken (const InputPortDescriptor< T > &port, std::stringstream *dot) const override
Appends a fragment to the dot stream identifying the graphviz node representing port. More...

void GetGraphvizOutputPortToken (const OutputPort< T > &port, std::stringstream *dot) const override
Appends a fragment to the dot stream identifying the graphviz node representing port. More...

Public Member Functions inherited from System< T >
virtual ~System ()

void GetWitnessFunctions (const Context< T > &context, std::vector< const WitnessFunction< T > * > *w) const
Gets the witness functions active at the beginning of a continuous time interval. More...

EvaluateWitness (const Context< T > &context, const WitnessFunction< T > &witness_func) const
Evaluates a witness function at the given context. More...

std::string GetSystemIdString () const
Returns a string suitable for identifying this particular System in error messages, when it is a subsystem of a larger Diagram. More...

System (const System &)=delete

Systemoperator= (const System &)=delete

System (System &&)=delete

Systemoperator= (System &&)=delete

std::unique_ptr< BasicVector< T > > AllocateInputVector (const InputPortDescriptor< T > &descriptor) const
Given a port descriptor, allocates the vector storage. More...

std::unique_ptr< AbstractValueAllocateInputAbstract (const InputPortDescriptor< T > &descriptor) const
Given a port descriptor, allocates the abstract storage. More...

std::unique_ptr< Context< T > > CreateDefaultContext () const
This convenience method allocates a context using AllocateContext() and sets its default values using SetDefaultContext(). More...

void SetDefaultContext (Context< T > *context) const

void SetRandomContext (Context< T > *context, RandomGenerator *generator) const

void AllocateFreestandingInputs (Context< T > *context) const
For each input port, allocates a freestanding input of the concrete type that this System requires, and binds it to the port, disconnecting any prior input. More...

bool HasAnyDirectFeedthrough () const
Returns true if any of the inputs to the system might be directly fed through to any of its outputs and false otherwise. More...

bool HasDirectFeedthrough (int output_port) const
Returns true if there might be direct-feedthrough from any input port to the given output_port, and false otherwise. More...

bool HasDirectFeedthrough (int input_port, int output_port) const
Returns true if there might be direct-feedthrough from the given input_port to the given output_port, and false otherwise. More...

void Publish (const Context< T > &context, const EventCollection< PublishEvent< T >> &events) const
This method is the public entry point for dispatching all publish event handlers. More...

void Publish (const Context< T > &context) const
Forces a publish on the system, given a context. More...

const T & EvalConservativePower (const Context< T > &context) const
Returns a reference to the cached value of the conservative power. More...

const T & EvalNonConservativePower (const Context< T > &context) const
Returns a reference to the cached value of the non-conservative power. More...

template<template< typename > class Vec = BasicVector>
const Vec< T > * EvalVectorInput (const Context< T > &context, int port_index) const
Causes the vector-valued input port with the given port_index to become up-to-date, delegating to our parent Diagram if necessary. More...

Eigen::VectorBlock< const VectorX< T > > EvalEigenVectorInput (const Context< T > &context, int port_index) const
Causes the vector-valued input port with the given port_index to become up-to-date, delegating to our parent Diagram if necessary. More...

const AbstractValueEvalAbstractInput (const Context< T > &context, int port_index) const
Causes the abstract-valued input port with the given port_index to become up-to-date, delegating to our parent Diagram if necessary. More...

template<typename V >
const V * EvalInputValue (const Context< T > &context, int port_index) const
Causes the abstract-valued input port with the given port_index to become up-to-date, delegating to our parent Diagram if necessary. More...

int get_num_constraint_equations (const Context< T > &context) const
Gets the number of constraint equations for this system using the given context (useful in case the number of constraints is dependent upon the current state (as might be the case with a system modeled using piecewise differential algebraic equations). More...

Eigen::VectorXd EvalConstraintEquations (const Context< T > &context) const
Evaluates the constraint equations for the system at the generalized coordinates and generalized velocity specified by the context. More...

Eigen::VectorXd EvalConstraintEquationsDot (const Context< T > &context) const
Computes the time derivative of each constraint equation, evaluated at the generalized coordinates and generalized velocity specified by the context. More...

Eigen::VectorXd CalcVelocityChangeFromConstraintImpulses (const Context< T > &context, const Eigen::MatrixXd &J, const Eigen::VectorXd &lambda) const
Computes the change in velocity from applying the given constraint forces to the system at the given context. More...

double CalcConstraintErrorNorm (const Context< T > &context, const Eigen::VectorXd &error) const
Computes the norm on constraint error (used as a metric for comparing errors between the outputs of algebraic equations applied to two different state variable instances). More...

void CalcTimeDerivatives (const Context< T > &context, ContinuousState< T > *derivatives) const
Calculates the time derivatives xcdot of the continuous state xc. More...

void CalcDiscreteVariableUpdates (const Context< T > &context, const EventCollection< DiscreteUpdateEvent< T >> &events, DiscreteValues< T > *discrete_state) const
This method is the public entry point for dispatching all discrete variable update event handlers. More...

void CalcDiscreteVariableUpdates (const Context< T > &context, DiscreteValues< T > *discrete_state) const
This method forces a discrete update on the system given a context, and the updated discrete state is stored in discrete_state. More...

void CalcUnrestrictedUpdate (const Context< T > &context, const EventCollection< UnrestrictedUpdateEvent< T >> &events, State< T > *state) const
This method is the public entry point for dispatching all unrestricted update event handlers. More...

void CalcUnrestrictedUpdate (const Context< T > &context, State< T > *state) const
This method forces an unrestricted update on the system given a context, and the updated state is stored in discrete_state. More...

CalcNextUpdateTime (const Context< T > &context, CompositeEventCollection< T > *events) const
This method is called by a Simulator during its calculation of the size of the next continuous step to attempt. More...

void GetPerStepEvents (const Context< T > &context, CompositeEventCollection< T > *events) const
This method is called by Simulator::Initialize() to gather all update and publish events that are to be handled in StepTo() at the point before Simulator integrates continuous state. More...

void GetInitializationEvents (const Context< T > &context, CompositeEventCollection< T > *events) const
This method is called by Simulator::Initialize() to gather all update and publish events that need to be handled at initialization before the simulator starts integration. More...

optional< typename Event< T >::PeriodicAttribute > GetUniquePeriodicDiscreteUpdateAttribute () const
Gets whether there exists a unique periodic attribute that triggers one or more discrete update events (and, if so, returns that unique periodic attribute). More...

std::map< typename Event< T >::PeriodicAttribute, std::vector< const Event< T > * >, PeriodicAttributeComparator< T > > GetPeriodicEvents () const
Gets all periodic triggered events for a system. More...

void CalcOutput (const Context< T > &context, SystemOutput< T > *outputs) const
Utility method that computes for every output port i the value y(i) that should result from the current contents of the given Context. More...

CalcPotentialEnergy (const Context< T > &context) const
Calculates and returns the potential energy current stored in the configuration provided in context. More...

CalcKineticEnergy (const Context< T > &context) const
Calculates and returns the kinetic energy currently present in the motion provided in the given Context. More...

CalcConservativePower (const Context< T > &context) const
Calculates and returns the rate at which mechanical energy is being converted from potential energy to kinetic energy by this system in the given Context. More...

CalcNonConservativePower (const Context< T > &context) const
Calculates and returns the rate at which mechanical energy is being generated (positive) or dissipated (negative) other than by conversion between potential and kinetic energy (in the given Context). More...

void MapVelocityToQDot (const Context< T > &context, const VectorBase< T > &generalized_velocity, VectorBase< T > *qdot) const
Transforms a given generalized velocity v to the time derivative qdot of the generalized configuration q taken from the supplied Context. More...

void MapVelocityToQDot (const Context< T > &context, const Eigen::Ref< const VectorX< T >> &generalized_velocity, VectorBase< T > *qdot) const
Transforms the given generalized velocity to the time derivative of generalized configuration. More...

void MapQDotToVelocity (const Context< T > &context, const VectorBase< T > &qdot, VectorBase< T > *generalized_velocity) const
Transforms the time derivative qdot of the generalized configuration q to generalized velocities v. More...

void MapQDotToVelocity (const Context< T > &context, const Eigen::Ref< const VectorX< T >> &qdot, VectorBase< T > *generalized_velocity) const
Transforms the given time derivative qdot of generalized configuration q to generalized velocity v. More...

void set_name (const std::string &name)
Sets the name of the system. More...

std::string get_name () const
Returns the name last supplied to set_name(), or empty if set_name() was never called. More...

std::string GetMemoryObjectName () const
Returns a name for this System based on a stringification of its type name and memory address. More...

void GetPath (std::stringstream *output) const
Writes the full path of this System in the tree of Systems to output. More...

std::string GetPath () const

int get_num_input_ports () const
Returns the number of input ports of the system. More...

int get_num_output_ports () const
Returns the number of output ports of the system. More...

const InputPortDescriptor< T > & get_input_port (int port_index) const
Returns the descriptor of the input port at index port_index. More...

const OutputPort< T > & get_output_port (int port_index) const
Returns the output port at index port_index. More...

int get_num_constraints () const
Returns the number of constraints specified for the system. More...

const SystemConstraint< T > & get_constraint (SystemConstraintIndex constraint_index) const
Returns the constraint at index constraint_index. More...

bool CheckSystemConstraintsSatisfied (const Context< T > &context, double tol) const
Returns true if context satisfies all of the registered SystemConstraints with tolerance tol. More...

int get_num_total_inputs () const
Returns the total dimension of all of the input ports (as if they were muxed). More...

int get_num_total_outputs () const
Returns the total dimension of all of the output ports (as if they were muxed). More...

void CheckValidOutput (const SystemOutput< T > *output) const
Checks that output is consistent with the number and size of output ports declared by the system. More...

template<typename T1 = T>
void CheckValidContext (const Context< T1 > &context) const
Checks that context is consistent for this System template. More...

VectorX< T > CopyContinuousStateVector (const Context< T > &context) const
Returns a copy of the continuous state vector xc into an Eigen vector. More...

void set_parent (const detail::InputPortEvaluatorInterface< T > *parent)
Declares that parent is the immediately enclosing Diagram. More...

std::string GetGraphvizString () const
Returns a Graphviz string describing this System. More...

int64_t GetGraphvizId () const
Returns an opaque integer that uniquely identifies this system in the Graphviz output. More...

void FixInputPortsFrom (const System< double > &other_system, const Context< double > &other_context, Context< T > *target_context) const
Fixes all of the input ports in target_context to their current values in other_context, as evaluated by other_system. More...

const SystemScalarConverterget_system_scalar_converter () const
(Advanced) Returns the SystemScalarConverter for this object. More...

std::unique_ptr< System< AutoDiffXd > > ToAutoDiffXd () const
Creates a deep copy of this System, transmogrified to use the autodiff scalar type, with a dynamic-sized vector of partial derivatives. More...

std::unique_ptr< System< AutoDiffXd > > ToAutoDiffXdMaybe () const
Creates a deep copy of this system exactly like ToAutoDiffXd(), but returns nullptr if this System does not support autodiff, instead of throwing an exception. More...

std::unique_ptr< System< symbolic::Expression > > ToSymbolic () const
Creates a deep copy of this System, transmogrified to use the symbolic scalar type. More...

std::unique_ptr< System< symbolic::Expression > > ToSymbolicMaybe () const
Creates a deep copy of this system exactly like ToSymbolic(), but returns nullptr if this System does not support symbolic, instead of throwing an exception. More...

Public Member Functions inherited from InputPortEvaluatorInterface< T >
InputPortEvaluatorInterface ()

virtual ~InputPortEvaluatorInterface ()

InputPortEvaluatorInterface (const InputPortEvaluatorInterface &)=delete

InputPortEvaluatorInterfaceoperator= (const InputPortEvaluatorInterface &)=delete

InputPortEvaluatorInterface (InputPortEvaluatorInterface &&)=delete

InputPortEvaluatorInterfaceoperator= (InputPortEvaluatorInterface &&)=delete

## Protected Member Functions

Diagram ()
Constructs an uninitialized Diagram. More...

Diagram (SystemScalarConverter converter)
(Advanced) Constructs an uninitialized Diagram. More...

DoEvaluateWitness (const Context< T > &context, const WitnessFunction< T > &witness_func) const final
For the subsystem associated with witness_func, gets its subcontext from context, passes the subcontext to witness_func' Evaulate method and returns the result. More...

void AddTriggeredWitnessFunctionToCompositeEventCollection (const WitnessFunction< T > &witness_func, CompositeEventCollection< T > *events) const final
For the subsystem associated with witness_func, gets its mutable sub composite event collection from events, and passes it to witness_func's AddEvent method. More...

void DoGetWitnessFunctions (const Context< T > &context, std::vector< const WitnessFunction< T > * > *witnesses) const final
Provides witness functions of subsystems that are active at the beginning of a continuous time interval. More...

Context< T > * DoGetMutableTargetSystemContext (const System< T > &target_system, Context< T > *context) const final
Returns a pointer to mutable context if target_system is a sub system of this, nullptr is returned otherwise. More...

const Context< T > * DoGetTargetSystemContext (const System< T > &target_system, const Context< T > *context) const final
Returns a pointer to const context if target_system is a subsystem of this, nullptr is returned otherwise. More...

State< T > * DoGetMutableTargetSystemState (const System< T > &target_system, State< T > *state) const final
Returns a pointer to mutable state if target_system is a subsystem of this, nullptr is returned otherwise. More...

const State< T > * DoGetTargetSystemState (const System< T > &target_system, const State< T > *state) const final
Returns a pointer to const state if target_system is a subsystem of this, nullptr is returned otherwise. More...

CompositeEventCollection< T > * DoGetMutableTargetSystemCompositeEventCollection (const System< T > &target_system, CompositeEventCollection< T > *events) const final
Returns a pointer to mutable composite event collection if target_system is a subsystem of this, nullptr is returned otherwise. More...

const CompositeEventCollection< T > * DoGetTargetSystemCompositeEventCollection (const System< T > &target_system, const CompositeEventCollection< T > *events) const final
Returns a pointer to const composite event collection if target_system is a subsystem of this, nullptr is returned otherwise. More...

void DoMapVelocityToQDot (const Context< T > &context, const Eigen::Ref< const VectorX< T >> &generalized_velocity, VectorBase< T > *qdot) const override
The generalized_velocity vector must have the same size and ordering as the generalized velocity in the ContinuousState that this Diagram reserves in its context. More...

void DoMapQDotToVelocity (const Context< T > &context, const Eigen::Ref< const VectorX< T >> &qdot, VectorBase< T > *generalized_velocity) const override
The generalized_velocity vector must have the same size and ordering as the generalized velocity in the ContinuousState that this Diagram reserves in its context. More...

void DoCalcNextUpdateTime (const Context< T > &context, CompositeEventCollection< T > *event_info, T *time) const override
Computes the next update time based on the configured actions, for scalar types that are arithmetic, or aborts for scalar types that are not arithmetic. More...

BasicVector< T > * DoAllocateInputVector (const InputPortDescriptor< T > &descriptor) const override
Allocates an input vector of the leaf type that the System requires on the port specified by descriptor. More...

AbstractValueDoAllocateInputAbstract (const InputPortDescriptor< T > &descriptor) const override
Allocates an abstract input of the leaf type that the System requires on the port specified by descriptor. More...

Protected Member Functions inherited from System< T >
SystemConstraintIndex AddConstraint (std::unique_ptr< SystemConstraint< T >> constraint)
Adds an already-created constraint to the list of constraints for this System. More...

const EventCollection< PublishEvent< T > > & get_forced_publish_events () const

const EventCollection< DiscreteUpdateEvent< T > > & get_forced_discrete_update_events () const

const EventCollection< UnrestrictedUpdateEvent< T > > & get_forced_unrestricted_update_events () const

void set_forced_publish_events (std::unique_ptr< EventCollection< PublishEvent< T >>> forced)

void set_forced_discrete_update_events (std::unique_ptr< EventCollection< DiscreteUpdateEvent< T >>> forced)

void set_forced_unrestricted_update_events (std::unique_ptr< EventCollection< UnrestrictedUpdateEvent< T >>> forced)

System (SystemScalarConverter converter)
Constructs an empty System base class object, possibly supporting scalar-type conversion support (AutoDiff, etc.) using converter. More...

const InputPortDescriptor< T > & DeclareInputPort (PortDataType type, int size, optional< RandomDistribution > random_type=nullopt)
Adds a port with the specified type and size to the input topology. More...

const InputPortDescriptor< T > & DeclareAbstractInputPort ()
Adds an abstract-valued port to the input topology. More...

void CreateOutputPort (std::unique_ptr< OutputPort< T >> port)

virtual T DoCalcPotentialEnergy (const Context< T > &context) const
Override this method for physical systems to calculate the potential energy currently stored in the configuration provided in the given Context. More...

virtual T DoCalcKineticEnergy (const Context< T > &context) const
Override this method for physical systems to calculate the kinetic energy currently present in the motion provided in the given Context. More...

virtual T DoCalcConservativePower (const Context< T > &context) const
Override this method to return the rate at which mechanical energy is being converted from potential energy to kinetic energy by this system in the given Context. More...

virtual T DoCalcNonConservativePower (const Context< T > &context) const
Override this method to return the rate at which mechanical energy is being generated (positive) or dissipated (negative) other than by conversion between potential and kinetic energy (in the given Context). More...

virtual int do_get_num_constraint_equations (const Context< T > &context) const
Gets the number of constraint equations for this system from the given context. More...

virtual Eigen::VectorXd DoEvalConstraintEquations (const Context< T > &context) const
Evaluates the constraint equations for the system at the generalized coordinates and generalized velocity specified by the context. More...

virtual Eigen::VectorXd DoEvalConstraintEquationsDot (const Context< T > &context) const
Computes the time derivative of each constraint equation, evaluated at the generalized coordinates and generalized velocity specified by the context. More...

virtual Eigen::VectorXd DoCalcVelocityChangeFromConstraintImpulses (const Context< T > &context, const Eigen::MatrixXd &J, const Eigen::VectorXd &lambda) const
Computes the change in velocity from applying the given constraint forces to the system at the given context. More...

virtual double DoCalcConstraintErrorNorm (const Context< T > &context, const Eigen::VectorXd &error) const
Computes the norm of the constraint error. More...

Eigen::VectorBlock< VectorX< T > > GetMutableOutputVector (SystemOutput< T > *output, int port_index) const
Returns a mutable Eigen expression for a vector valued output port with index port_index in this system. More...

void EvalInputPort (const Context< T > &context, int port_index) const
Causes an InputPortValue in the context to become up-to-date, delegating to the parent Diagram if necessary. More...

## Friends

class DiagramBuilder< T >

template<typename >
class Diagram

Static Public Member Functions inherited from System< T >
template<template< typename > class S = ::drake::systems::System>
static std::unique_ptr< S< AutoDiffXd > > ToAutoDiffXd (const S< T > &from)
Creates a deep copy of from, transmogrified to use the autodiff scalar type, with a dynamic-sized vector of partial derivatives. More...

template<template< typename > class S = ::drake::systems::System>
static std::unique_ptr< S< symbolic::Expression > > ToSymbolic (const S< T > &from)
Creates a deep copy of from, transmogrified to use the symbolic scalar type. More...

## Detailed Description

### template<typename T> class drake::systems::Diagram< T >

Diagram is a System composed of one or more constituent Systems, arranged in a directed graph where the vertices are the constituent Systems themselves, and the edges connect the output of one constituent System to the input of another.

To construct a Diagram, use a DiagramBuilder.

Each System in the Diagram must have a unique, non-empty name.

Template Parameters
 T The mathematical scalar type. Must be a valid Eigen scalar.

## Member Typedef Documentation

 typedef std::pair*, int> PortIdentifier

## Constructor & Destructor Documentation

 Diagram ( const Diagram< T > & )
delete
 Diagram ( Diagram< T > && )
delete
 Diagram ( const Diagram< U > & other )
inlineexplicit

Scalar-converting copy constructor. See System Scalar Conversion.

 ~Diagram ( )
inlineoverride
 Diagram ( )
inlineprotected

Constructs an uninitialized Diagram.

Subclasses that use this constructor are obligated to call DiagramBuilder::BuildInto(this). Provides scalar- type conversion support only if every contained subsystem provides the same support.

 Diagram ( SystemScalarConverter converter )
inlineexplicitprotected

Subclasses that use this constructor are obligated to call DiagramBuilder::BuildInto(this).

Declares scalar-type conversion support using converter. Support for a given pair of types T, U to convert from and to will be enabled only if every contained subsystem supports that pair.

See System Scalar Conversion for detailed background and examples related to scalar-type conversion support.

## Member Function Documentation

 void AddTriggeredWitnessFunctionToCompositeEventCollection ( const WitnessFunction< T > & witness_func, CompositeEventCollection< T > * events ) const
inlinefinalprotectedvirtual

For the subsystem associated with witness_func, gets its mutable sub composite event collection from events, and passes it to witness_func's AddEvent method.

Aborts if the subsystem is not part of this Diagram.

Implements System< T >.

 std::unique_ptr > AllocateCompositeEventCollection ( ) const
inlinefinalvirtual
 std::unique_ptr > AllocateContext ( ) const
inlineoverridevirtual

Allocates a context, initialized with the correct numbers of concrete input ports and state variables for this System.

Since input port pointers are not owned by the context, they should simply be initialized to nullptr.

Implements System< T >.

 std::unique_ptr > AllocateDiscreteVariables ( ) const
inlineoverridevirtual

Aggregates the discrete update variables from each subsystem into a DiagramDiscreteVariables.

Reimplemented from System< T >.

 std::unique_ptr > AllocateOutput ( const Context< T > & context ) const
inlineoverridevirtual

Returns a container that can hold the values of all of this System's output ports.

It is sized with the number of output ports and uses each output port's allocation method to provide an object of the right type for that port. A Context is provided as an argument to support some specialized use cases. Most typical System implementations should ignore it.

Implements System< T >.

 std::unique_ptr > AllocateTimeDerivatives ( ) const
inlineoverridevirtual

Aggregates the time derivatives from each subsystem into a DiagramTimeDerivatives.

Reimplemented from System< T >.

 AbstractValue* DoAllocateInputAbstract ( const InputPortDescriptor< T > & descriptor ) const
inlineoverrideprotectedvirtual

Allocates an abstract input of the leaf type that the System requires on the port specified by descriptor.

Caller owns the returned memory.

Implements System< T >.

 BasicVector* DoAllocateInputVector ( const InputPortDescriptor< T > & descriptor ) const
inlineoverrideprotectedvirtual

Allocates an input vector of the leaf type that the System requires on the port specified by descriptor.

Caller owns the returned memory.

Implements System< T >.

 void DoCalcNextUpdateTime ( const Context< T > & context, CompositeEventCollection< T > * event_info, T * time ) const
inlineoverrideprotectedvirtual

Computes the next update time based on the configured actions, for scalar types that are arithmetic, or aborts for scalar types that are not arithmetic.

Reimplemented from System< T >.

 void DoCalcTimeDerivatives ( const Context< T > & context, ContinuousState< T > * derivatives ) const
inlineoverridevirtual

Override this if you have any continuous state variables xc in your concrete System to calculate their time derivatives.

The derivatives vector will correspond elementwise with the state vector Context.state.continuous_state.get_state(). Thus, if the state in the Context has second-order structure xc=[q,v,z], that same structure applies to the derivatives.

This method is called only from the public non-virtual CalcTimeDerivatives() which will already have error-checked the parameters so you don't have to. In particular, implementations may assume that the given Context is valid for this System; that the derivatives pointer is non-null, and that the referenced object has the same constituent structure as was produced by AllocateTimeDerivatives().

The default implementation does nothing if the derivatives vector is size zero and aborts otherwise.

Reimplemented from System< T >.

 T DoEvaluateWitness ( const Context< T > & context, const WitnessFunction< T > & witness_func ) const
inlinefinalprotectedvirtual

For the subsystem associated with witness_func, gets its subcontext from context, passes the subcontext to witness_func' Evaulate method and returns the result.

Aborts if the subsystem is not part of this Diagram.

Implements System< T >.

 CompositeEventCollection* DoGetMutableTargetSystemCompositeEventCollection ( const System< T > & target_system, CompositeEventCollection< T > * events ) const
inlinefinalprotected

Returns a pointer to mutable composite event collection if target_system is a subsystem of this, nullptr is returned otherwise.

 Context* DoGetMutableTargetSystemContext ( const System< T > & target_system, Context< T > * context ) const
inlinefinalprotected

Returns a pointer to mutable context if target_system is a sub system of this, nullptr is returned otherwise.

 State* DoGetMutableTargetSystemState ( const System< T > & target_system, State< T > * state ) const
inlinefinalprotected

Returns a pointer to mutable state if target_system is a subsystem of this, nullptr is returned otherwise.

 const CompositeEventCollection* DoGetTargetSystemCompositeEventCollection ( const System< T > & target_system, const CompositeEventCollection< T > * events ) const
inlinefinalprotected

Returns a pointer to const composite event collection if target_system is a subsystem of this, nullptr is returned otherwise.

 const Context* DoGetTargetSystemContext ( const System< T > & target_system, const Context< T > * context ) const
inlinefinalprotected

Returns a pointer to const context if target_system is a subsystem of this, nullptr is returned otherwise.

 const State* DoGetTargetSystemState ( const System< T > & target_system, const State< T > * state ) const
inlinefinalprotected

Returns a pointer to const state if target_system is a subsystem of this, nullptr is returned otherwise.

 void DoGetWitnessFunctions ( const Context< T > & context, std::vector< const WitnessFunction< T > * > * witnesses ) const
inlinefinalprotectedvirtual

Provides witness functions of subsystems that are active at the beginning of a continuous time interval.

The vector of witness functions is not ordered in a particular manner.

Reimplemented from System< T >.

 void DoMapQDotToVelocity ( const Context< T > & context, const Eigen::Ref< const VectorX< T >> & qdot, VectorBase< T > * generalized_velocity ) const
inlineoverrideprotectedvirtual

The generalized_velocity vector must have the same size and ordering as the generalized velocity in the ContinuousState that this Diagram reserves in its context.

Reimplemented from System< T >.

 void DoMapVelocityToQDot ( const Context< T > & context, const Eigen::Ref< const VectorX< T >> & generalized_velocity, VectorBase< T > * qdot ) const
inlineoverrideprotectedvirtual

The generalized_velocity vector must have the same size and ordering as the generalized velocity in the ContinuousState that this Diagram reserves in its context.

Reimplemented from System< T >.

 void EvaluateSubsystemInputPort ( const Context< T > * context, const InputPortDescriptor< T > & descriptor ) const
inlineoverridevirtual

Evaluates the value of the subsystem input port with the given id in the given context.

Satisfies InputPortEvaluatorInterface.

This is a framework implementation detail. User code should not call this function.

Implements InputPortEvaluatorInterface< T >.

 std::multimap GetDirectFeedthroughs ( ) const
inlinefinalvirtual

Reports all direct feedthroughs from input ports to output ports.

For a system with m input ports: I = i₀, i₁, ..., iₘ₋₁, and n output ports, O = o₀, o₁, ..., oₙ₋₁, the return map will contain pairs (u, v) such that

• 0 ≤ u < m,
• 0 ≤ v < n,
• and there might be a direct feedthrough from input iᵤ to each output oᵥ.

Implements System< T >.

 void GetGraphvizFragment ( std::stringstream * dot ) const
inlineoverridevirtual

Returns a Graphviz fragment describing this Diagram.

To obtain a complete Graphviz graph, call System<T>::GetGraphvizString.

Reimplemented from System< T >.

 void GetGraphvizInputPortToken ( const InputPortDescriptor< T > & port, std::stringstream * dot ) const
inlineoverridevirtual

Appends a fragment to the dot stream identifying the graphviz node representing port.

Does nothing by default.

Reimplemented from System< T >.

 void GetGraphvizOutputPortToken ( const OutputPort< T > & port, std::stringstream * dot ) const
inlineoverridevirtual

Appends a fragment to the dot stream identifying the graphviz node representing port.

Does nothing by default.

Reimplemented from System< T >.

 CompositeEventCollection& GetMutableSubsystemCompositeEventCollection ( const System< T > & subsystem, CompositeEventCollection< T > * events ) const
inline

Returns the mutable subsystem composite event collection that corresponds to subsystem.

Aborts if subsystem is not a subsystem of this diagram.

 Context& GetMutableSubsystemContext ( const System< T > & subsystem, Context< T > * context ) const
inline

Returns the subcontext that corresponds to the system subsystem.

Classes inheriting from Diagram need access to this method in order to pass their constituent subsystems the apropriate subcontext. Aborts if subsystem is not actually a subsystem of this diagram.

Here is the caller graph for this function:

 State& GetMutableSubsystemState ( const System< T > & subsystem, Context< T > * context ) const
inline

Retrieves the state for a particular subsystem from the context for the entire diagram.

Invalidates all entries in that subsystem's cache that depend on State. Aborts if subsystem is not actually a subsystem of this diagram.

TODO(david-german-tri): Provide finer-grained accessors for finer-grained invalidation.

 State& GetMutableSubsystemState ( const System< T > & subsystem, State< T > * state ) const
inline

Retrieves the state for a particular subsystem from the state for the entire diagram.

Aborts if subsystem is not actually a subsystem of this diagram.

 void GetPath ( std::stringstream * output ) const
inlineoverridevirtual

Returns the full path of this Diagram in the tree of Diagrams.

Implemented here to satisfy InputPortEvaluatorInterface, although we want the exact same behavior as in System.

Implements InputPortEvaluatorInterface< T >.

 const CompositeEventCollection& GetSubsystemCompositeEventCollection ( const System< T > & subsystem, const CompositeEventCollection< T > & events ) const
inline

Returns the const subsystem composite event collection from events that corresponds to subsystem.

Aborts if subsystem is not a subsystem of this diagram.

 const Context& GetSubsystemContext ( const System< T > & subsystem, const Context< T > & context ) const
inline

Returns a constant reference to the subcontext that corresponds to the system subsystem.

Classes inheriting from Diagram need access to this method in order to pass their constituent subsystems the apropriate subcontext. Aborts if subsystem is not actually a subsystem of this diagram.

Here is the caller graph for this function:

 const ContinuousState* GetSubsystemDerivatives ( const ContinuousState< T > & derivatives, const System< T > * subsystem ) const
inline

Retrieves the state derivatives for a particular subsystem from the derivatives for the entire diagram.

Aborts if subsystem is not actually a subsystem of this diagram. Returns nullptr if subsystem is stateless.

 const State& GetSubsystemState ( const System< T > & subsystem, const State< T > & state ) const
inline

Retrieves the state for a particular subsystem from the state for the entire diagram.

Aborts if subsystem is not actually a subsystem of this diagram.

 int GetSystemIndexOrAbort ( const System< T > * sys ) const
inline

Returns the index of the given sys in this diagram, or aborts if sys is not a member of the diagram.

 std::vector*> GetSystems ( ) const
inline

Returns the list of contained Systems.

 Diagram& operator= ( Diagram< T > && )
delete
 Diagram& operator= ( const Diagram< T > & )
delete
 void SetDefaultParameters ( const Context< T > & context, Parameters< T > * parameters ) const
inlineoverridevirtual

Assigns default values to all parameters.

Overrides must not change the number of parameters.

Implements System< T >.

 void SetDefaultState ( const Context< T > & context, State< T > * state ) const
inlineoverridevirtual

Assigns default values to all elements of the state.

Overrides must not change the number of state variables.

Implements System< T >.

 void SetRandomParameters ( const Context< T > & context, Parameters< T > * parameters, RandomGenerator * generator ) const
inlineoverridevirtual

Assigns random values to all parameters.

This default implementation calls SetDefaultParameters; override this method to provide random parameters using the stdc++ random library, e.g.:

std::uniform_real_distribution<T> uniform();
parameters->get_mutable_numeric_parameter(0)
->SetAtIndex(0, uniform(*generator));

Overrides must not change the number of state variables.

Stochastic Systems

Reimplemented from System< T >.

 void SetRandomState ( const Context< T > & context, State< T > * state, RandomGenerator * generator ) const
inlineoverridevirtual

Assigns random values to all elements of the state.

This default implementation calls SetDefaultState; override this method to provide random initial conditions using the stdc++ random library, e.g.:

std::normal_distribution<T> gaussian();
state->get_mutable_continuous_state()->get_mutable_vector()
->SetAtIndex(0, gaussian(*generator));

Overrides must not change the number of state variables.