Drake
DiagramContext< T > Class Template Referencefinal

The DiagramContext is a container for all of the data necessary to uniquely determine the computations performed by a Diagram. More...

#include <systems/framework/diagram_context.h>

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

Public Types

using InputPortIdentifier = std::pair< SubsystemIndex, InputPortIndex >
 Identifies a child subsystem's input port. More...
 
using OutputPortIdentifier = std::pair< SubsystemIndex, OutputPortIndex >
 Identifies a child subsystem's output port. More...
 

Public Member Functions

 DiagramContext (int num_subcontexts)
 Constructs a DiagramContext with the given num_subcontexts, which is final: you cannot resize a DiagramContext after construction. More...
 
void AddSystem (SubsystemIndex index, std::unique_ptr< Context< T >> context, std::unique_ptr< SystemOutput< T >> output)
 Declares a new subsystem in the DiagramContext. More...
 
void ExportInput (const InputPortIdentifier &id)
 Declares that a particular input port of a particular subsystem is an input to the entire Diagram that allocates this Context. More...
 
void Connect (const OutputPortIdentifier &src, const InputPortIdentifier &dest)
 Declares that the output port specified by src is connected to the input port specified by dest. More...
 
void MakeState ()
 Generates the state vector for the entire diagram by wrapping the states of all the constituent diagrams. More...
 
void MakeParameters ()
 Generates the parameters for the entire diagram by wrapping the parameters of all the constituent Systems. More...
 
SystemOutput< T > * GetSubsystemOutput (SubsystemIndex index) const
 Returns the output structure for a given constituent system at index. More...
 
const Context< T > & GetSubsystemContext (SubsystemIndex index) const
 Returns the context structure for a given constituent system index. More...
 
Context< T > & GetMutableSubsystemContext (SubsystemIndex index)
 Returns the context structure for a given subsystem index. More...
 
void set_time (const T &time_sec) override
 Recursively sets the time on this context and all subcontexts. More...
 
void set_accuracy (const optional< double > &accuracy) override
 Recursively sets the accuracy on this context and all subcontexts, overwriting any accuracy value set in any subcontexts. More...
 
int get_num_input_ports () const override
 Returns the number of input ports. More...
 
const State< T > & get_state () const final
 
State< T > & get_mutable_state () final
 
const Parameters< T > & get_parameters () const final
 
Parameters< T > & get_mutable_parameters () final
 
Does not allow copy, move, or assignment.
 DiagramContext (DiagramContext &&)=delete
 
DiagramContextoperator= (const DiagramContext &)=delete
 
DiagramContextoperator= (DiagramContext &&)=delete
 
- Public Member Functions inherited from Context< T >
std::unique_ptr< Context< T > > Clone () const
 Returns a deep copy of this Context. More...
 
 ~Context () override=default
 
const T & get_time () const
 Returns the current time in seconds. More...
 
bool is_stateless () const
 Returns true if the Context has no state. More...
 
bool has_only_continuous_state () const
 Returns true if the Context has continuous state, but no discrete or abstract state. More...
 
bool has_only_discrete_state () const
 Returns true if the Context has discrete state, but no continuous or abstract state. More...
 
int get_num_total_states () const
 Returns the total dimension of all of the basic vector states (as if they were muxed). More...
 
void set_continuous_state (std::unique_ptr< ContinuousState< T >> xc)
 Sets the continuous state to xc, deleting whatever was there before. More...
 
ContinuousState< T > & get_mutable_continuous_state ()
 Returns a mutable reference to the continuous component of the state, which may be of size zero. More...
 
VectorBase< T > & get_mutable_continuous_state_vector ()
 Returns a mutable reference to the continuous state vector, devoid of second-order structure. More...
 
const ContinuousState< T > & get_continuous_state () const
 Returns a const reference to the continuous component of the state, which may be of size zero. More...
 
const VectorBase< T > & get_continuous_state_vector () const
 Returns a reference to the continuous state vector, devoid of second-order structure. More...
 
int get_num_discrete_state_groups () const
 Returns the number of vectors (groups) in the discrete state. More...
 
const DiscreteValues< T > & get_discrete_state () const
 Returns a reference to the entire discrete state, which may consist of multiple discrete state vectors (groups). More...
 
const BasicVector< T > & get_discrete_state_vector () const
 Returns a reference to the only discrete state vector. More...
 
DiscreteValues< T > & get_mutable_discrete_state ()
 Returns a mutable reference to the discrete component of the state, which may be of size zero. More...
 
BasicVector< T > & get_mutable_discrete_state (int index)
 Returns a mutable reference to group (vector) index of the discrete state. More...
 
void set_discrete_state (std::unique_ptr< DiscreteValues< T >> xd)
 Sets the discrete state to xd, deleting whatever was there before. More...
 
const BasicVector< T > & get_discrete_state (int index) const
 Returns a const reference to group (vector) index of the discrete state. More...
 
int get_num_abstract_states () const
 Returns the number of elements in the abstract state. More...
 
const AbstractValuesget_abstract_state () const
 Returns a const reference to the abstract component of the state, which may be of size zero. More...
 
AbstractValuesget_mutable_abstract_state ()
 Returns a mutable reference to the abstract component of the state, which may be of size zero. More...
 
template<typename U >
U & get_mutable_abstract_state (int index)
 Returns a mutable reference to element index of the abstract state. More...
 
void set_abstract_state (std::unique_ptr< AbstractValues > xa)
 Sets the abstract state to xa, deleting whatever was there before. More...
 
template<typename U >
const U & get_abstract_state (int index) const
 Returns a const reference to the abstract component of the state at index. More...
 
FreestandingInputPortValueFixInputPort (int index, std::unique_ptr< AbstractValue > value)
 Connects the input port at index to a FreestandingInputPortValue with the given abstract value. More...
 
FreestandingInputPortValueFixInputPort (int index, std::unique_ptr< BasicVector< T >> vec)
 Connects the input port at index to a FreestandingInputPortValue with the given vector vec. More...
 
FreestandingInputPortValueFixInputPort (int index, const Eigen::Ref< const VectorX< T >> &data)
 Same as above method but starts with an Eigen vector whose contents are used to initialize a BasicVector in the FreestandingInputPortValue. More...
 
const InputPortValueEvalInputPort (const detail::InputPortEvaluatorInterface< T > *evaluator, const InputPortDescriptor< T > &descriptor) const
 Evaluates and returns the value of the input port identified by descriptor, using the given evaluator, which should be the Diagram containing the System that allocated this Context. More...
 
const BasicVector< T > * EvalVectorInput (const detail::InputPortEvaluatorInterface< T > *evaluator, const InputPortDescriptor< T > &descriptor) const
 Evaluates and returns the vector value of the input port with the given descriptor. More...
 
const AbstractValueEvalAbstractInput (const detail::InputPortEvaluatorInterface< T > *evaluator, const InputPortDescriptor< T > &descriptor) const
 Evaluates and returns the abstract value of the input port with the given descriptor. More...
 
template<typename V >
const V * EvalInputValue (const detail::InputPortEvaluatorInterface< T > *evaluator, const InputPortDescriptor< T > &descriptor) const
 Evaluates and returns the data of the input port at index. More...
 
int num_numeric_parameters () const
 Returns the number of vector-valued parameters. More...
 
const BasicVector< T > & get_numeric_parameter (int index) const
 Returns a const reference to the vector-valued parameter at index. More...
 
BasicVector< T > & get_mutable_numeric_parameter (int index)
 Returns a mutable reference to element index of the vector-valued parameters. More...
 
int num_abstract_parameters () const
 Returns the number of abstract-valued parameters. More...
 
const AbstractValueget_abstract_parameter (int index) const
 Returns a const reference to the abstract-valued parameter at index. More...
 
AbstractValueget_mutable_abstract_parameter (int index)
 Returns a mutable reference to element index of the abstract-valued parameters. More...
 
const optional< double > & get_accuracy () const
 Returns the accuracy setting (if any). More...
 
std::unique_ptr< State< T > > CloneState () const
 Returns a deep copy of this Context's State. More...
 
void SetTimeStateAndParametersFrom (const Context< double > &source)
 Initializes this context's time, state, and parameters from the real values in source, regardless of this context's scalar type. More...
 
void set_parent (const Context< T > *parent)
 Declares that parent is the context of the enclosing Diagram. More...
 
template<typename T1 = T>
void VerifyInputPort (const InputPortDescriptor< T1 > &descriptor) const
 Throws an exception unless the given descriptor matches the inputs actually connected to this context in shape. More...
 
 Context (Context &&)=delete
 
Contextoperator= (const Context &)=delete
 
Contextoperator= (Context &&)=delete
 
- Public Member Functions inherited from ContextBase
std::unique_ptr< ContextBaseClone () const
 Creates an identical copy of the concrete context object. More...
 
 ~ContextBase () override
 
void DisableCaching () const
 (Debugging) Disables caching recursively for this context and all its subcontexts. More...
 
void EnableCaching () const
 (Debugging) Re-enables caching recursively for this context and all its subcontexts. More...
 
void SetAllCacheEntriesOutOfDate () const
 (Debugging) Marks all cache entries out of date, recursively for this context and all its subcontexts. More...
 
const std::string & GetSystemName () const final
 (Debugging) Returns the local name of the subsystem for which this is the Context. More...
 
std::string GetSystemPathname () const final
 (Debugging) Returns the full pathname of the subsystem for which this is the Context. More...
 
const Cacheget_cache () const
 Returns a const reference to this subcontext's cache. More...
 
Cacheget_mutable_cache () const
 (Advanced) Returns a mutable reference to this subcontext's cache. More...
 
const DependencyTrackerget_tracker (DependencyTicket ticket) const
 Returns a const reference to a DependencyTracker in this subcontext. More...
 
DependencyTrackerget_mutable_tracker (DependencyTicket ticket)
 Returns a mutable reference to a DependencyTracker in this subcontext. More...
 
const DependencyGraphget_dependency_graph () const
 Returns a const reference to the collection of value trackers within this subcontext. More...
 
DependencyGraphget_mutable_dependency_graph ()
 Returns a mutable reference to the dependency graph. More...
 
 ContextBase (ContextBase &&)=delete
 
ContextBaseoperator= (const ContextBase &)=delete
 
ContextBaseoperator= (ContextBase &&)=delete
 

Protected Member Functions

 DiagramContext (const DiagramContext &source)
 Protected copy constructor takes care of the local data members and all base class members, but doesn't update base class pointers so is not a complete copy. More...
 
const InputPortValueGetInputPortValue (int index) const override
 Returns the input port at the given index, which of course belongs to the subsystem whose input was exposed at that index. More...
 
- Protected Member Functions inherited from Context< T >
 Context ()=default
 
 Context (const Context< T > &)=default
 Copy constructor takes care of base class and Context<T> data members. More...
 
const StepInfo< T > & get_step_info () const
 Returns a const reference to current time and step information. More...
 
StepInfo< T > * get_mutable_step_info ()
 Provides writable access to time and step information, with the side effect of invaliding any computation that is dependent on them. More...
 
- Protected Member Functions inherited from ContextBase
 ContextBase ()
 Default constructor creates an empty ContextBase but initializes all the built-in dependency trackers that are the same in every System (like time, q, all states, all inputs, etc.). More...
 
 ContextBase (const ContextBase &)=default
 Copy constructor takes care of base class data members, but does not fix up base class pointers. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from Context< T >
static std::unique_ptr< Context< T > > CloneWithoutPointers (const Context< T > &source)
 Clones a context but without any of its internal pointers. More...
 
static const InputPortValueGetInputPortValue (const Context< T > &context, int index)
 Allows derived classes to invoke the protected method on subcontexts. More...
 
static void SetInputPortValue (Context< T > *context, int index, std::unique_ptr< InputPortValue > port_value)
 Allows derived classes to invoke the protected method on subcontexts. More...
 
- Static Protected Member Functions inherited from ContextBase
static std::unique_ptr< ContextBaseCloneWithoutPointers (const ContextBase &source)
 Clones a context but without copying any of its internal pointers; the clone's pointers are set to null. More...
 

Detailed Description

template<typename T>
class drake::systems::DiagramContext< T >

The DiagramContext is a container for all of the data necessary to uniquely determine the computations performed by a Diagram.

Specifically, a DiagramContext contains contexts and outputs for all the constituent Systems, wired up as specified by calls to DiagramContext::Connect.

In general, users should not need to interact with a DiagramContext directly. Use the accessors on Diagram instead.

Template Parameters
TThe mathematical type of the context, which must be a valid Eigen scalar.

Member Typedef Documentation

Identifies a child subsystem's input port.

Identifies a child subsystem's output port.

Constructor & Destructor Documentation

DiagramContext ( DiagramContext< T > &&  )
delete
DiagramContext ( int  num_subcontexts)
inlineexplicit

Constructs a DiagramContext with the given num_subcontexts, which is final: you cannot resize a DiagramContext after construction.

The number and ordering of subcontexts is identical to the number and ordering of subsystems in the corresponding Diagram.

DiagramContext ( const DiagramContext< T > &  source)
inlineprotected

Protected copy constructor takes care of the local data members and all base class members, but doesn't update base class pointers so is not a complete copy.

Member Function Documentation

void AddSystem ( SubsystemIndex  index,
std::unique_ptr< Context< T >>  context,
std::unique_ptr< SystemOutput< T >>  output 
)
inline

Declares a new subsystem in the DiagramContext.

Subsystems are identified by number. If the subsystem has already been declared, aborts.

User code should not call this method. It is for use during Diagram context allocation only.

void Connect ( const OutputPortIdentifier src,
const InputPortIdentifier dest 
)
inline

Declares that the output port specified by src is connected to the input port specified by dest.

User code should not call this method. It is for use during Diagram context allocation only.

Here is the call graph for this function:

void ExportInput ( const InputPortIdentifier id)
inline

Declares that a particular input port of a particular subsystem is an input to the entire Diagram that allocates this Context.

Aborts if the subsystem has not been added to the DiagramContext.

User code should not call this method. It is for use during Diagram context allocation only.

Parameters<T>& get_mutable_parameters ( )
inlinefinalvirtual

Implements Context< T >.

State<T>& get_mutable_state ( )
inlinefinalvirtual

Implements Context< T >.

int get_num_input_ports ( ) const
inlineoverridevirtual

Returns the number of input ports.

Implements Context< T >.

const Parameters<T>& get_parameters ( ) const
inlinefinalvirtual

Implements Context< T >.

const State<T>& get_state ( ) const
inlinefinalvirtual

Implements Context< T >.

const InputPortValue* GetInputPortValue ( int  index) const
inlineoverrideprotectedvirtual

Returns the input port at the given index, which of course belongs to the subsystem whose input was exposed at that index.

Implements Context< T >.

Here is the call graph for this function:

Context<T>& GetMutableSubsystemContext ( SubsystemIndex  index)
inline

Returns the context structure for a given subsystem index.

Aborts if index is out of bounds, or if no system has been added to the DiagramContext at that index. TODO(david-german-tri): Rename to get_mutable_subsystem_context.

const Context<T>& GetSubsystemContext ( SubsystemIndex  index) const
inline

Returns the context structure for a given constituent system index.

Aborts if index is out of bounds, or if no system has been added to the DiagramContext at that index. TODO(david-german-tri): Rename to get_subsystem_context.

Here is the caller graph for this function:

SystemOutput<T>* GetSubsystemOutput ( SubsystemIndex  index) const
inline

Returns the output structure for a given constituent system at index.

Aborts if index is out of bounds, or if no system has been added to the DiagramContext at that index.

Here is the caller graph for this function:

void MakeParameters ( )
inline

Generates the parameters for the entire diagram by wrapping the parameters of all the constituent Systems.

The wrapper simply holds pointers to the parameters in the subsystem Contexts. It does not make a copy, or take ownership.

User code should not call this method. It is for use during Diagram context allocation only.

Here is the call graph for this function:

void MakeState ( )
inline

Generates the state vector for the entire diagram by wrapping the states of all the constituent diagrams.

User code should not call this method. It is for use during Diagram context allocation only.

Here is the call graph for this function:

DiagramContext& operator= ( const DiagramContext< T > &  )
delete
DiagramContext& operator= ( DiagramContext< T > &&  )
delete
void set_accuracy ( const optional< double > &  accuracy)
inlineoverridevirtual

Recursively sets the accuracy on this context and all subcontexts, overwriting any accuracy value set in any subcontexts.

Reimplemented from Context< T >.

Here is the call graph for this function:

void set_time ( const T &  time_sec)
inlineoverridevirtual

Recursively sets the time on this context and all subcontexts.

Reimplemented from Context< T >.

Here is the call graph for this function:


The documentation for this class was generated from the following file: