Provides non-templatized functionality shared by the templatized System classes.
Terminology: in general a Drake System is a tree structure composed of "subsystems", which are themselves System objects. The corresponding Context is a parallel tree structure composed of "subcontexts", which are themselves Context objects. There is a one-to-one correspondence between subsystems and subcontexts. Within a given System (Context), its child subsystems (subcontexts) are indexed using a SubsystemIndex; there is no separate SubcontextIndex since the numbering must be identical.
#include <drake/systems/framework/system_base.h>
Classes | |
struct | ContextSizes |
Return type for get_context_sizes(). More... | |
struct | GraphvizFragment |
(Advanced) The return type of GetGraphvizFragment(). More... | |
struct | GraphvizFragmentParams |
(Advanced) The arguments to the protected method DoGetGraphvizFragment(). More... | |
Public Member Functions | |
~SystemBase () override | |
void | set_name (const std::string &name) |
Sets the name of the system. More... | |
const std::string & | get_name () const |
Returns the name last supplied to set_name(), if any. More... | |
std::string | GetMemoryObjectName () const |
Returns a name for this System based on a stringification of its type name and memory address. More... | |
const std::string & | GetSystemName () const final |
Returns a human-readable name for this system, for use in messages and logging. More... | |
std::string | GetSystemPathname () const final |
Generates and returns a human-readable full path name of this subsystem, for use in messages and logging. More... | |
std::string | GetSystemType () const final |
Returns the most-derived type of this concrete System object as a human-readable string suitable for use in error messages. More... | |
std::unique_ptr< ContextBase > | AllocateContext () const |
Returns a Context suitable for use with this System. More... | |
int | num_input_ports () const |
Returns the number of input ports currently allocated in this System. More... | |
int | num_output_ports () const |
Returns the number of output ports currently allocated in this System. More... | |
const InputPortBase & | get_input_port_base (InputPortIndex port_index) const |
Returns a reference to an InputPort given its port_index . More... | |
const OutputPortBase & | get_output_port_base (OutputPortIndex port_index) const |
Returns a reference to an OutputPort given its port_index . More... | |
int | num_total_inputs () const |
Returns the total dimension of all of the vector-valued input ports (as if they were muxed). More... | |
int | num_total_outputs () const |
Returns the total dimension of all of the vector-valued output ports (as if they were muxed). More... | |
virtual std::multimap< int, int > | GetDirectFeedthroughs () const =0 |
Reports all direct feedthroughs from input ports to output ports. More... | |
int | num_cache_entries () const |
Returns the number nc of cache entries currently allocated in this System. More... | |
const CacheEntry & | get_cache_entry (CacheIndex index) const |
Returns a reference to a CacheEntry given its index . More... | |
CacheEntry & | get_mutable_cache_entry (CacheIndex index) |
(Advanced) Returns a mutable reference to a CacheEntry given its index . More... | |
int | num_continuous_states () const |
Returns the number of declared continuous state variables. More... | |
int | num_discrete_state_groups () const |
Returns the number of declared discrete state groups (each group is a vector-valued discrete state variable). More... | |
int | num_abstract_states () const |
Returns the number of declared abstract state variables. More... | |
int | num_numeric_parameter_groups () const |
Returns the number of declared numeric parameters (each of these is a vector-valued parameter). More... | |
int | num_abstract_parameters () const |
Returns the number of declared abstract parameters. More... | |
int | implicit_time_derivatives_residual_size () const |
Returns the size of the implicit time derivatives residual vector. More... | |
void | ValidateContext (const ContextBase &context) const final |
Checks whether the given context was created for this system. More... | |
void | ValidateContext (const ContextBase *context) const |
Checks whether the given context was created for this system. More... | |
template<class Clazz > | |
void | ValidateCreatedForThisSystem (const Clazz &object) const |
Checks whether the given object was created for this system. More... | |
Does not allow copy, move, or assignment | |
SystemBase (const SystemBase &)=delete | |
SystemBase & | operator= (const SystemBase &)=delete |
SystemBase (SystemBase &&)=delete | |
SystemBase & | operator= (SystemBase &&)=delete |
Graphviz methods | |
std::string | GetGraphvizString (std::optional< int > max_depth={}, const std::map< std::string, std::string > &options={}) const |
Returns a Graphviz string describing this System. More... | |
GraphvizFragment | GetGraphvizFragment (std::optional< int > max_depth={}, const std::map< std::string, std::string > &options={}) const |
(Advanced) Like GetGraphvizString() but does not wrap the string in a digraph { … } . More... | |
Input port evaluation (deprecated) | |
These deprecated methods provide scalar type-independent evaluation of a System input port in a particular Context. Instead of these, prefer to use InputPort::Eval(), acquiring the port with If necessary, the methods here first cause the port's value to become up to date, then they return a reference to the now-up-to-date value in the given Context. Specified preconditions for these methods operate as follows: The preconditions will be checked in Debug builds but some or all might not be checked in Release builds for performance reasons. If we do check, and a precondition is violated, an std::exception will be thrown with a helpful message.
| |
const AbstractValue * | EvalAbstractInput (const ContextBase &context, int port_index) const |
Returns the value of the input port with the given port_index as an AbstractValue, which is permitted for ports of any type. More... | |
template<typename V > | |
const V * | EvalInputValue (const ContextBase &context, int port_index) const |
Returns the value of an abstract-valued input port with the given port_index as a value of known type V . More... | |
Protected Member Functions | |
SystemBase ()=default | |
(Internal use only). More... | |
void | AddInputPort (std::unique_ptr< InputPortBase > port) |
(Internal use only) Adds an already-constructed input port to this System. More... | |
void | AddOutputPort (std::unique_ptr< OutputPortBase > port) |
(Internal use only) Adds an already-constructed output port to this System. More... | |
std::string | NextInputPortName (std::variant< std::string, UseDefaultName > given_name) const |
(Internal use only) Returns a name for the next input port, using the given name if it isn't kUseDefaultName, otherwise making up a name like "u3" from the next available input port index. More... | |
std::string | NextOutputPortName (std::variant< std::string, UseDefaultName > given_name) const |
(Internal use only) Returns a name for the next output port, using the given name if it isn't kUseDefaultName, otherwise making up a name like "y3" from the next available output port index. More... | |
void | AddDiscreteStateGroup (DiscreteStateIndex index) |
(Internal use only) Assigns a ticket to a new discrete variable group with the given index . More... | |
void | AddAbstractState (AbstractStateIndex index) |
(Internal use only) Assigns a ticket to a new abstract state variable with the given index . More... | |
void | AddNumericParameter (NumericParameterIndex index) |
(Internal use only) Assigns a ticket to a new numeric parameter with the given index . More... | |
void | AddAbstractParameter (AbstractParameterIndex index) |
(Internal use only) Assigns a ticket to a new abstract parameter with the given index . More... | |
CacheEntry & | DeclareCacheEntryWithKnownTicket (DependencyTicket known_ticket, std::string description, ValueProducer value_producer, std::set< DependencyTicket > prerequisites_of_calc={ all_sources_ticket()}) |
(Internal use only) This is for cache entries associated with pre-defined tickets, for example the cache entry for time derivatives. More... | |
const internal::SystemParentServiceInterface * | get_parent_service () const |
Returns a pointer to the service interface of the immediately enclosing Diagram if one has been set, otherwise nullptr. More... | |
DependencyTicket | assign_next_dependency_ticket () |
(Internal use only) Assigns the next unused dependency ticket number, unique only within a particular system. More... | |
bool | IsObviouslyNotInputDependent (DependencyTicket dependency_ticket) const |
(Internal use only) Checks if a ticket depends on (any) input port. More... | |
virtual std::function< void(const AbstractValue &)> | MakeFixInputPortTypeChecker (InputPortIndex port_index) const =0 |
(Internal use only) Given a port_index , returns a function to be called when validating Context::FixInputPort requests. More... | |
const AbstractValue * | EvalAbstractInputImpl (const char *func, const ContextBase &context, InputPortIndex port_index) const |
(Internal use only) Shared code for updating an input port and returning a pointer to its abstract value, or nullptr if the port is not connected. More... | |
void | ThrowNegativePortIndex (const char *func, int port_index) const |
Throws std::exception to report a negative port_index that was passed to API method func . More... | |
void | ThrowInputPortIndexOutOfRange (const char *func, InputPortIndex port_index) const |
Throws std::exception to report bad input port_index that was passed to API method func . More... | |
void | ThrowOutputPortIndexOutOfRange (const char *func, OutputPortIndex port_index) const |
Throws std::exception to report bad output port_index that was passed to API method func . More... | |
void | ThrowNotAVectorInputPort (const char *func, InputPortIndex port_index) const |
Throws std::exception because someone misused API method func , that is only allowed for declared-vector input ports, on an abstract port whose index is given here. More... | |
void | ThrowInputPortHasWrongType (const char *func, InputPortIndex port_index, const std::string &expected_type, const std::string &actual_type) const |
Throws std::exception because someone called API method func claiming the input port had some value type that was wrong. More... | |
void | ThrowCantEvaluateInputPort (const char *func, InputPortIndex port_index) const |
Throws std::exception because someone called API method func , that requires this input port to be evaluatable, but the port was neither fixed nor connected. More... | |
const InputPortBase & | GetInputPortBaseOrThrow (const char *func, int port_index, bool warn_deprecated) const |
(Internal use only) Returns the InputPortBase at index port_index , throwing std::exception we don't like the port index. More... | |
const OutputPortBase & | GetOutputPortBaseOrThrow (const char *func, int port_index, bool warn_deprecated) const |
(Internal use only) Returns the OutputPortBase at index port_index , throwing std::exception if we don't like the port index. More... | |
void | ThrowValidateContextMismatch (const ContextBase &) const |
(Internal use only) Throws std::exception with a message that the sanity check(s) given by ValidateContext have failed. More... | |
virtual std::string | GetUnsupportedScalarConversionMessage (const std::type_info &source_type, const std::type_info &destination_type) const |
(Internal use only) Returns the message to use for a std::exception in the case of unsupported scalar type conversions. More... | |
void | InitializeContextBase (ContextBase *context) const |
This method must be invoked from within derived class DoAllocateContext() implementations right after the concrete Context object has been allocated. More... | |
virtual std::unique_ptr< ContextBase > | DoAllocateContext () const =0 |
Derived class implementations should allocate a suitable concrete Context type, then invoke the above InitializeContextBase() method. More... | |
const ContextSizes & | get_context_sizes () const |
Obtains access to the declared Context partition sizes as accumulated during LeafSystem or Diagram construction . More... | |
ContextSizes & | get_mutable_context_sizes () |
Obtains mutable access to the Context sizes struct. More... | |
void | set_implicit_time_derivatives_residual_size (int n) |
Allows a LeafSystem to override the default size for the implicit time derivatives residual and a Diagram to sum up the total size. More... | |
internal::SystemId | get_system_id () const |
(Internal) Gets the id used to tag context data as being created by this system. More... | |
virtual GraphvizFragment | DoGetGraphvizFragment (const GraphvizFragmentParams ¶ms) const |
The NVI implementation of GetGraphvizFragment() for subclasses to override if desired. More... | |
Declare cache entries | |
Methods in this section are used by derived classes to declare cache entries for their own internal computations. (Other cache entries are provided automatically for well-known computations such as output ports and time derivatives.) Cache entries may contain values of any type, however the type for any particular cache entry is fixed after first allocation. Every cache entry must have an allocator function PrerequisitesCorrect runtime caching behavior depends critically on understanding the dependencies of the cache entry's Currently it is not possible for Drake to infer prerequisites accurately and automatically from inspection of the
A technique you can use to ensure that prerequisites have been properly specified is to make use of the Context's DisableCaching() method, which causes cache values to be recalculated unconditionally. You should get identical results with caching enabled or disabled, with speed being the only difference. You can also disable caching for individual cache entries in a Context, or specify that individual cache entries should be disabled by default when they are first allocated.
Which signature to use?Although the allocator and calculator functions ultimately satisfy generic function signatures defined by a ValueProducer, we provide a variety of Because cache entry values are ultimately stored in AbstractValue objects, the underlying types must be suitable. That means the type must be copy constructible or cloneable. For methods below that are not given an explicit model value or construction ("make") method, the underlying type must also be default constructible.
| |
CacheEntry & | DeclareCacheEntry (std::string description, ValueProducer value_producer, std::set< DependencyTicket > prerequisites_of_calc={ all_sources_ticket()}) |
Declares a new CacheEntry in this System using the most generic form of the calculation function. More... | |
template<class MySystem , class MyContext , typename ValueType > | |
CacheEntry & | DeclareCacheEntry (std::string description, const ValueType &model_value, void(MySystem::*calc)(const MyContext &, ValueType *) const, std::set< DependencyTicket > prerequisites_of_calc={ all_sources_ticket()}) |
Declares a cache entry by specifying a model value of concrete type ValueType and a calculator function that is a class member function (method) with signature: More... | |
template<class MySystem , class MyContext , typename ValueType > | |
CacheEntry & | DeclareCacheEntry (std::string description, void(MySystem::*calc)(const MyContext &, ValueType *) const, std::set< DependencyTicket > prerequisites_of_calc={ all_sources_ticket()}) |
Declares a cache entry by specifying only a calculator function that is a class member function (method) with signature: More... | |
Static Protected Member Functions | |
static void | set_parent_service (SystemBase *child, const internal::SystemParentServiceInterface *parent_service) |
(Internal use only) Declares that parent_service is the service interface of the Diagram that owns this subsystem. More... | |
static void | ThrowInputPortHasWrongType (const char *func, const std::string &system_pathname, InputPortIndex, const std::string &port_name, const std::string &expected_type, const std::string &actual_type) |
Throws std::exception because someone called API method func claiming the input port had some value type that was wrong. More... | |
static const ContextSizes & | get_context_sizes (const SystemBase &system) |
Allows Diagram to access protected get_context_sizes() recursively on its subsystems. More... | |
Friends | |
class | internal::DiagramSystemBaseAttorney |
Dependency tickets | |
Use these tickets to declare well-known sources as prerequisites of a downstream computation such as an output port, derivative, update, or cache entry. The ticket numbers for the built-in sources are the same for all systems. For time and accuracy they refer to the same global resource; otherwise they refer to the specified sources within the referencing system. A dependency ticket for a more specific resource (a particular input or output port, a discrete variable group, abstract state variable, a parameter, or a cache entry) is allocated and stored with the resource when it is declared. Usually the tickets are obtained directly from the resource but you can recover them with methods here knowing only the resource index. | |
DependencyTicket | discrete_state_ticket (DiscreteStateIndex index) const |
Returns a ticket indicating dependence on a particular discrete state variable xdᵢ (may be a vector). More... | |
DependencyTicket | abstract_state_ticket (AbstractStateIndex index) const |
Returns a ticket indicating dependence on a particular abstract state variable xaᵢ. More... | |
DependencyTicket | numeric_parameter_ticket (NumericParameterIndex index) const |
Returns a ticket indicating dependence on a particular numeric parameter pnᵢ (may be a vector). More... | |
DependencyTicket | abstract_parameter_ticket (AbstractParameterIndex index) const |
Returns a ticket indicating dependence on a particular abstract parameter paᵢ. More... | |
DependencyTicket | input_port_ticket (InputPortIndex index) const |
Returns a ticket indicating dependence on input port uᵢ indicated by index . More... | |
DependencyTicket | cache_entry_ticket (CacheIndex index) const |
Returns a ticket indicating dependence on the cache entry indicated by index . More... | |
DependencyTicket | output_port_ticket (OutputPortIndex index) const |
(Internal use only) Returns a ticket indicating dependence on the output port indicated by index . More... | |
static DependencyTicket | nothing_ticket () |
Returns a ticket indicating that a computation does not depend on any source value; that is, it is a constant. More... | |
static DependencyTicket | time_ticket () |
Returns a ticket indicating dependence on time. More... | |
static DependencyTicket | accuracy_ticket () |
Returns a ticket indicating dependence on the accuracy setting in the Context. More... | |
static DependencyTicket | q_ticket () |
Returns a ticket indicating that a computation depends on configuration state variables q. More... | |
static DependencyTicket | v_ticket () |
Returns a ticket indicating dependence on velocity state variables v. More... | |
static DependencyTicket | z_ticket () |
Returns a ticket indicating dependence on any or all of the miscellaneous continuous state variables z. More... | |
static DependencyTicket | xc_ticket () |
Returns a ticket indicating dependence on all of the continuous state variables q, v, or z. More... | |
static DependencyTicket | xd_ticket () |
Returns a ticket indicating dependence on all of the numerical discrete state variables, in any discrete variable group. More... | |
static DependencyTicket | xa_ticket () |
Returns a ticket indicating dependence on all of the abstract state variables in the current Context. More... | |
static DependencyTicket | all_state_ticket () |
Returns a ticket indicating dependence on all state variables x in this system, including continuous variables xc, discrete (numeric) variables xd, and abstract state variables xa. More... | |
static DependencyTicket | pn_ticket () |
Returns a ticket indicating dependence on all of the numerical parameters in the current Context. More... | |
static DependencyTicket | pa_ticket () |
Returns a ticket indicating dependence on all of the abstract parameters pa in the current Context. More... | |
static DependencyTicket | all_parameters_ticket () |
Returns a ticket indicating dependence on all parameters p in this system, including numeric parameters pn, and abstract parameters pa. More... | |
static DependencyTicket | all_input_ports_ticket () |
Returns a ticket indicating dependence on all input ports u of this system. More... | |
static DependencyTicket | all_sources_except_input_ports_ticket () |
Returns a ticket indicating dependence on every possible independent source value except input ports. More... | |
static DependencyTicket | all_sources_ticket () |
Returns a ticket indicating dependence on every possible independent source value, including time, accuracy, state, input ports, and parameters (but not cache entries). More... | |
static DependencyTicket | configuration_ticket () |
Returns a ticket indicating dependence on all source values that may affect configuration-dependent computations. More... | |
static DependencyTicket | kinematics_ticket () |
Returns a ticket indicating dependence on all source values that may affect configuration- or velocity-dependent computations. More... | |
static DependencyTicket | xcdot_ticket () |
Returns a ticket for the cache entry that holds time derivatives of the continuous variables. More... | |
static DependencyTicket | pe_ticket () |
Returns a ticket for the cache entry that holds the potential energy calculation. More... | |
static DependencyTicket | ke_ticket () |
Returns a ticket for the cache entry that holds the kinetic energy calculation. More... | |
static DependencyTicket | pc_ticket () |
Returns a ticket for the cache entry that holds the conservative power calculation. More... | |
static DependencyTicket | pnc_ticket () |
Returns a ticket for the cache entry that holds the non-conservative power calculation. More... | |
static DependencyTicket | xd_unique_periodic_update_ticket () |
(Internal use only) Returns a ticket for the cache entry that holds the unique periodic discrete update computation. More... | |
|
delete |
|
delete |
|
override |
|
protecteddefault |
(Internal use only).
DependencyTicket abstract_parameter_ticket | ( | AbstractParameterIndex | index | ) | const |
Returns a ticket indicating dependence on a particular abstract parameter paᵢ.
DependencyTicket abstract_state_ticket | ( | AbstractStateIndex | index | ) | const |
Returns a ticket indicating dependence on a particular abstract state variable xaᵢ.
|
static |
Returns a ticket indicating dependence on the accuracy setting in the Context.
This is the same ticket for all systems and refers to the same accuracy value.
|
protected |
(Internal use only) Assigns a ticket to a new abstract parameter with the given index
.
|
protected |
(Internal use only) Assigns a ticket to a new abstract state variable with the given index
.
|
protected |
(Internal use only) Assigns a ticket to a new discrete variable group with the given index
.
|
protected |
(Internal use only) Adds an already-constructed input port to this System.
Insists that the port already contains a reference to this System, and that the port's index is already set to the next available input port index for this System, that the port name is unique (just within this System), and that the port name is non-empty.
|
protected |
(Internal use only) Assigns a ticket to a new numeric parameter with the given index
.
|
protected |
(Internal use only) Adds an already-constructed output port to this System.
Insists that the port already contains a reference to this System, and that the port's index is already set to the next available output port index for this System, and that the name of the port is unique.
std::exception | if the name of the output port is not unique. |
|
static |
Returns a ticket indicating dependence on all input ports u of this system.
|
static |
Returns a ticket indicating dependence on all parameters p in this system, including numeric parameters pn, and abstract parameters pa.
|
static |
Returns a ticket indicating dependence on every possible independent source value except input ports.
This can be helpful in avoiding the incorrect appearance of algebraic loops in a Diagram (those always involve apparent input port dependencies). For an output port, use this ticket plus tickets for just the input ports on which the output computation actually depends. The sources included in this ticket are: time, accuracy, state, and parameters. Note that dependencies on cache entries are not included here. Usually that won't matter since cache entries typically depend on at least one of time, accuracy, state, or parameters so will be invalidated for the same reason the current computation is. However, for a computation that depends on a cache entry that depends only on input ports, be sure that you have included those input ports in the dependency list, or include a direct dependency on the cache entry.
|
static |
Returns a ticket indicating dependence on every possible independent source value, including time, accuracy, state, input ports, and parameters (but not cache entries).
This is the default dependency for computations that have not specified anything more refined. It is equivalent to the set {all_sources_except_input_ports_ticket(), all_input_ports_ticket()}
.
|
static |
Returns a ticket indicating dependence on all state variables x in this system, including continuous variables xc, discrete (numeric) variables xd, and abstract state variables xa.
This does not imply dependence on time, accuracy, parameters, or inputs; those must be specified separately. If you mean to express dependence on all possible value sources, use all_sources_ticket() instead.
std::unique_ptr<ContextBase> AllocateContext | ( | ) | const |
|
protected |
(Internal use only) Assigns the next unused dependency ticket number, unique only within a particular system.
Each call to this method increments the ticket number.
DependencyTicket cache_entry_ticket | ( | CacheIndex | index | ) | const |
Returns a ticket indicating dependence on the cache entry indicated by index
.
Note that cache entries are not included in the all_sources
ticket so must be listed separately.
index
selects an existing cache entry in this System.
|
static |
Returns a ticket indicating dependence on all source values that may affect configuration-dependent computations.
In particular, this category does not include time, generalized velocities v, miscellaneous continuous state variables z, or input ports. Generalized coordinates q are included, as well as any discrete state variables that have been declared as configuration variables, and configuration-affecting parameters. Finally we assume that the accuracy setting may affect some configuration-dependent computations. Examples: a parameter that affects length may change the computation of an end-effector location. A change in accuracy requirement may require recomputation of an iterative approximation of contact forces.
|
protected |
Declares a new CacheEntry in this System using the most generic form of the calculation function.
Prefer one of the more convenient signatures below if you can. The new cache entry is assigned a unique CacheIndex and DependencyTicket, which can be obtained from the returned CacheEntry.
[in] | description | A human-readable description of this cache entry, most useful for debugging and documentation. Not interpreted in any way by Drake; it is retained by the cache entry and used to generate the description for the corresponding CacheEntryValue in the Context. |
[in] | value_producer | Provides the computation that maps from a given Context to the current value that this cache entry should have, as well as a way to allocate storage prior to the computation. |
[in] | prerequisites_of_calc | Provides the DependencyTicket list containing a ticket for every Context value on which calc_function may depend when it computes its result. Defaults to {all_sources_ticket()} if unspecified. If the cache value is truly independent of the Context (rare!) say so explicitly by providing the list {nothing_ticket()} ; an explicitly empty list {} is forbidden. |
std::exception | if given an explicitly empty prerequisite list. |
|
protected |
Declares a cache entry by specifying a model value of concrete type ValueType
and a calculator function that is a class member function (method) with signature:
where MySystem
is a class derived from SystemBase
, MyContext
is a class derived from ContextBase
, and ValueType
is any concrete type such that Value<ValueType>
is permitted. (The method names are arbitrary.) Template arguments will be deduced and do not need to be specified. See the primary DeclareCacheEntry() signature above for more information about the parameters and behavior.
|
protected |
Declares a cache entry by specifying only a calculator function that is a class member function (method) with signature:
where MySystem
is a class derived from SystemBase
and MyContext
is a class derived from ContextBase
. ValueType
is a concrete type such that (a) Value<ValueType>
is permitted, and (b) ValueType
is default constructible. That allows us to create a model value using Value<ValueType>{}
(value initialized so numerical types will be zeroed in the model). (The method name is arbitrary.) Template arguments will be deduced and do not need to be specified. See the first DeclareCacheEntry() signature above for more information about the parameters and behavior.
ValueType
default constructor each time it is called.
|
protected |
(Internal use only) This is for cache entries associated with pre-defined tickets, for example the cache entry for time derivatives.
See the public API for the most-general DeclareCacheEntry() signature for the meanings of the other parameters here.
DependencyTicket discrete_state_ticket | ( | DiscreteStateIndex | index | ) | const |
Returns a ticket indicating dependence on a particular discrete state variable xdᵢ (may be a vector).
(We sometimes refer to this as a "discrete variable group".)
|
protectedpure virtual |
Derived class implementations should allocate a suitable concrete Context type, then invoke the above InitializeContextBase() method.
A Diagram must then invoke AllocateContext() to obtain each of the subcontexts for its DiagramContext, and must set up inter-subcontext dependencies among its children and between itself and its children. Then context resources such as parameters and state should be allocated.
Implemented in LeafSystem< T >, LeafSystem< Element::T >, LeafSystem< double >, and LeafSystem< AutoDiffXd >.
|
protectedvirtual |
The NVI implementation of GetGraphvizFragment() for subclasses to override if desired.
The default behavior should be sufficient in most cases.
Reimplemented in Diagram< T >, and Diagram< double >.
const AbstractValue* EvalAbstractInput | ( | const ContextBase & | context, |
int | port_index | ||
) | const |
Returns the value of the input port with the given port_index
as an AbstractValue, which is permitted for ports of any type.
Causes the value to become up to date first if necessary, delegating to our parent Diagram. Returns a pointer to the port's value, or nullptr if the port is not connected. If you know the actual type, use one of the more-specific signatures.
port_index
selects an existing input port of this System.
|
protected |
(Internal use only) Shared code for updating an input port and returning a pointer to its abstract value, or nullptr if the port is not connected.
func
should be the user-visible API function name obtained with func.
const V* EvalInputValue | ( | const ContextBase & | context, |
int | port_index | ||
) | const |
Returns the value of an abstract-valued input port with the given port_index
as a value of known type V
.
Causes the value to become up to date first if necessary. See EvalAbstractInput() for more information.
The result is returned as a pointer to the input port's value of type V
, or nullptr if the port is not connected.
port_index
selects an existing input port of this System. AbstractValue::get_value<V>
.V | The type of data expected. |
const CacheEntry& get_cache_entry | ( | CacheIndex | index | ) | const |
Returns a reference to a CacheEntry given its index
.
|
protected |
Obtains access to the declared Context partition sizes as accumulated during LeafSystem or Diagram construction .
|
staticprotected |
Allows Diagram to access protected get_context_sizes() recursively on its subsystems.
const InputPortBase& get_input_port_base | ( | InputPortIndex | port_index | ) | const |
CacheEntry& get_mutable_cache_entry | ( | CacheIndex | index | ) |
(Advanced) Returns a mutable reference to a CacheEntry given its index
.
Note that you do not need mutable access to a CacheEntry to modify its value in a Context, so most users should not use this method.
|
protected |
Obtains mutable access to the Context sizes struct.
Should be used only during LeafSystem or Diagram construction.
const std::string& get_name | ( | ) | const |
Returns the name last supplied to set_name(), if any.
Diagrams built with DiagramBuilder will always have a default name for every contained subsystem for which no user-provided name is available. Systems created by copying with a scalar type change have the same name as the source system. An empty string is returned if no name has been set.
const OutputPortBase& get_output_port_base | ( | OutputPortIndex | port_index | ) | const |
Returns a reference to an OutputPort given its port_index
.
port_index
selects an existing output port of this System.
|
protected |
Returns a pointer to the service interface of the immediately enclosing Diagram if one has been set, otherwise nullptr.
|
protected |
(Internal) Gets the id used to tag context data as being created by this system.
See System Compatibility.
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
See DeclareLeafOutputPort documentation for how leaf systems can report their feedthrough.
Implemented in Diagram< T >, Diagram< double >, LeafSystem< T >, LeafSystem< Element::T >, LeafSystem< double >, and LeafSystem< AutoDiffXd >.
GraphvizFragment GetGraphvizFragment | ( | std::optional< int > | max_depth = {} , |
const std::map< std::string, std::string > & | options = {} |
||
) | const |
(Advanced) Like GetGraphvizString() but does not wrap the string in a digraph { … }
.
This is useful when merging the fragment into another graph, and is how Diagram obtains the Graphviz content for its subsystems. The parameters are identical to GetGraphvizString(). The return value contains additional metadata beyond the Graphviz content, to better support merging.
std::string GetGraphvizString | ( | std::optional< int > | max_depth = {} , |
const std::map< std::string, std::string > & | options = {} |
||
) | const |
Returns a Graphviz string describing this System.
To render the string, use the Graphviz tool, dot
.
Notes about the display conventions:
name=...
.max_depth | Sets a limit to the depth of nested diagrams to visualize. Use zero to render a diagram as a single system block. |
options | Arbitrary strings to request alterations to the output. Options that are unknown will be silently skipped. These options are often bespoke flags that are only understood by particular systems, but Drake has one built-in flag that is generally applicable: "split" . When set to "I/O" , the system will be added as two nodes with all inputs on one node and all outputs on the other; this is useful for systems that might otherwise cause problematic visual cycles. |
Options are applied only to this immediate system; they are not inherited by the subsystems of a Diagram. To specify an option for a Diagram's subsystem, prefix the option name with the subsystem's path, e.g., use "plant/split"="I/O"
to set the "split"
option on the subsystem named "plant"
.
|
protected |
(Internal use only) Returns the InputPortBase at index port_index
, throwing std::exception we don't like the port index.
The name of the public API method that received the bad index is provided in func
and is included in the error message. The warn_deprecated
governs whether or not a deprecation warning should occur when the port_index
is deprecated; calls made on behalf of the user should pass true
; calls made on behalf or the framework internals should pass false
.
std::string GetMemoryObjectName | ( | ) | const |
Returns a name for this System based on a stringification of its type name and memory address.
This is intended for use in diagnostic output and should not be used for behavioral logic, because the stringification of the type name may produce differing results across platforms and because the address can vary from run to run.
|
protected |
(Internal use only) Returns the OutputPortBase at index port_index
, throwing std::exception if we don't like the port index.
The name of the public API method that received the bad index is provided in func
and is included in the error message. The warn_deprecated
governs whether or not a deprecation warning should occur when the port_index
is deprecated; calls made on behalf of the user should pass true
; calls made on behalf or the framework internals should pass false
.
|
final |
Returns a human-readable name for this system, for use in messages and logging.
This will be the same as returned by get_name(), unless that would be an empty string. In that case we return a non-unique placeholder name, currently just "_" (a lone underscore).
|
final |
Generates and returns a human-readable full path name of this subsystem, for use in messages and logging.
The name starts from the root System, with "::" delimiters between parent and child subsystems, with the individual subsystems represented by their names as returned by GetSystemName().
|
final |
Returns the most-derived type of this concrete System object as a human-readable string suitable for use in error messages.
The format is as generated by NiceTypeName and will include namespace qualification if present.
|
protectedvirtual |
(Internal use only) Returns the message to use for a std::exception in the case of unsupported scalar type conversions.
Reimplemented in Diagram< T >, and Diagram< double >.
int implicit_time_derivatives_residual_size | ( | ) | const |
Returns the size of the implicit time derivatives residual vector.
By default this is the same as num_continuous_states() but a LeafSystem can change it during construction via LeafSystem::DeclareImplicitTimeDerivativesResidualSize().
|
protected |
This method must be invoked from within derived class DoAllocateContext() implementations right after the concrete Context object has been allocated.
It allocates cache entries, sets up all intra-Context dependencies, and marks the ContextBase as initialized so that we can verify proper derived-class behavior.
DependencyTicket input_port_ticket | ( | InputPortIndex | index | ) | const |
Returns a ticket indicating dependence on input port uᵢ indicated by index
.
index
selects an existing input port of this System.
|
protected |
(Internal use only) Checks if a ticket depends on (any) input port.
When this returns "true" the ticket MUST NOT depend on input. When this returns "false", it just means that we're not sure. This is intended to be an inexpensive check, withough searching the entire graph.
|
static |
Returns a ticket for the cache entry that holds the kinetic energy calculation.
|
static |
Returns a ticket indicating dependence on all source values that may affect configuration- or velocity-dependent computations.
This ticket depends on the configuration_ticket defined above, and adds in velocity-affecting source values. This does not include time or input ports.
|
protectedpure virtual |
(Internal use only) Given a port_index
, returns a function to be called when validating Context::FixInputPort requests.
The function should attempt to throw an exception if the input AbstractValue is invalid, so that errors can be reported at Fix-time instead of EvalInput-time.
|
protected |
(Internal use only) Returns a name for the next input port, using the given name if it isn't kUseDefaultName, otherwise making up a name like "u3" from the next available input port index.
given_name
must not be empty.
|
protected |
(Internal use only) Returns a name for the next output port, using the given name if it isn't kUseDefaultName, otherwise making up a name like "y3" from the next available output port index.
given_name
must not be empty.
|
static |
Returns a ticket indicating that a computation does not depend on any source value; that is, it is a constant.
If this appears in a prerequisite list, it must be the only entry.
int num_abstract_parameters | ( | ) | const |
Returns the number of declared abstract parameters.
int num_abstract_states | ( | ) | const |
Returns the number of declared abstract state variables.
int num_cache_entries | ( | ) | const |
Returns the number nc of cache entries currently allocated in this System.
These are indexed from 0 to nc-1.
int num_continuous_states | ( | ) | const |
Returns the number of declared continuous state variables.
int num_discrete_state_groups | ( | ) | const |
Returns the number of declared discrete state groups (each group is a vector-valued discrete state variable).
int num_input_ports | ( | ) | const |
Returns the number of input ports currently allocated in this System.
These are indexed from 0 to num_input_ports()-1.
int num_numeric_parameter_groups | ( | ) | const |
Returns the number of declared numeric parameters (each of these is a vector-valued parameter).
int num_output_ports | ( | ) | const |
Returns the number of output ports currently allocated in this System.
These are indexed from 0 to num_output_ports()-1.
int num_total_inputs | ( | ) | const |
Returns the total dimension of all of the vector-valued input ports (as if they were muxed).
int num_total_outputs | ( | ) | const |
Returns the total dimension of all of the vector-valued output ports (as if they were muxed).
DependencyTicket numeric_parameter_ticket | ( | NumericParameterIndex | index | ) | const |
Returns a ticket indicating dependence on a particular numeric parameter pnᵢ (may be a vector).
|
delete |
|
delete |
DependencyTicket output_port_ticket | ( | OutputPortIndex | index | ) | const |
(Internal use only) Returns a ticket indicating dependence on the output port indicated by index
.
No user-definable quantities in a system can meaningfully depend on that system's own output ports.
index
selects an existing output port of this System.
|
static |
Returns a ticket indicating dependence on all of the abstract parameters pa in the current Context.
|
static |
Returns a ticket for the cache entry that holds the conservative power calculation.
|
static |
Returns a ticket for the cache entry that holds the potential energy calculation.
|
static |
Returns a ticket indicating dependence on all of the numerical parameters in the current Context.
|
static |
Returns a ticket for the cache entry that holds the non-conservative power calculation.
|
static |
Returns a ticket indicating that a computation depends on configuration state variables q.
There is no ticket representing just one of the state variables qᵢ.
|
protected |
Allows a LeafSystem to override the default size for the implicit time derivatives residual and a Diagram to sum up the total size.
If no value is set, the default size is n=num_continuous_states().
[in] | n | The size of the residual vector output argument of System::CalcImplicitTimeDerivativesResidual(). If n <= 0 restore to the default, num_continuous_states(). |
void set_name | ( | const std::string & | name | ) |
Sets the name of the system.
Do not use the path delimiter character ':' in the name. When creating a Diagram, names of sibling subsystems should be unique. DiagramBuilder uses this method to assign a unique default name if none is provided.
|
staticprotected |
(Internal use only) Declares that parent_service
is the service interface of the Diagram that owns this subsystem.
Aborts if the parent service has already been set to something else.
|
protected |
Throws std::exception because someone called API method func
, that requires this input port to be evaluatable, but the port was neither fixed nor connected.
|
protected |
Throws std::exception because someone called API method func
claiming the input port had some value type that was wrong.
|
staticprotected |
Throws std::exception because someone called API method func
claiming the input port had some value type that was wrong.
|
protected |
Throws std::exception to report bad input port_index
that was passed to API method func
.
|
protected |
Throws std::exception to report a negative port_index
that was passed to API method func
.
Caller must ensure that the function name makes it clear what kind of port we're complaining about.
|
protected |
Throws std::exception because someone misused API method func
, that is only allowed for declared-vector input ports, on an abstract port whose index is given here.
|
protected |
Throws std::exception to report bad output port_index
that was passed to API method func
.
|
protected |
(Internal use only) Throws std::exception with a message that the sanity check(s) given by ValidateContext have failed.
|
static |
Returns a ticket indicating dependence on time.
This is the same ticket for all systems and refers to the same time value.
|
static |
Returns a ticket indicating dependence on velocity state variables v.
This does not also indicate a dependence on configuration variables q – you must list that explicitly or use kinematics_ticket() instead. There is no ticket representing just one of the state variables vᵢ.
|
final |
Checks whether the given context was created for this system.
std::exception | if the System Ids don't match. |
void ValidateContext | ( | const ContextBase * | context | ) | const |
Checks whether the given context was created for this system.
std::exception | if the System Ids don't match. |
std::exception | if context is null. |
void ValidateCreatedForThisSystem | ( | const Clazz & | object | ) | const |
|
static |
Returns a ticket indicating dependence on all of the abstract state variables in the current Context.
|
static |
Returns a ticket indicating dependence on all of the continuous state variables q, v, or z.
|
static |
Returns a ticket for the cache entry that holds time derivatives of the continuous variables.
|
static |
Returns a ticket indicating dependence on all of the numerical discrete state variables, in any discrete variable group.
|
static |
(Internal use only) Returns a ticket for the cache entry that holds the unique periodic discrete update computation.
|
static |
Returns a ticket indicating dependence on any or all of the miscellaneous continuous state variables z.
There is no ticket representing just one of the state variables zᵢ.
|
friend |