44 const T&
get_time()
const {
return get_step_info().time_sec; }
48 get_mutable_step_info()->time_sec =
time_sec;
55 if (index < 0 || index >= get_num_input_ports()) {
56 throw std::out_of_range(
"Input port out of range.");
59 inputs_[index] = std::move(port);
81 if (index >= get_num_input_ports()) {
82 throw std::out_of_range(
"Input port out of range.");
84 if (inputs_[index] ==
nullptr) {
87 return inputs_[index]->get_vector_data();
109 std::unique_ptr<Context<T>>
Clone()
const {
110 return std::unique_ptr<Context<T>>(DoClone());
122 const int num_q = xc.get_generalized_position().size();
123 const int num_v = xc.get_generalized_velocity().size();
124 const int num_z = xc.get_misc_continuous_state().size();
132 for (
const auto& port : this->inputs_) {
133 context->inputs_.emplace_back(
135 port->get_vector_data()->Clone(), port->get_sample_time_sec()));
139 *context->get_mutable_step_info() = this->get_step_info();
146 const StepInfo<T>& get_step_info()
const {
return step_info_; }
152 StepInfo<T>* get_mutable_step_info() {
return &step_info_; }
164 std::vector<std::unique_ptr<InputPort<T>>> inputs_;
VectorInterface is a pure abstract interface that real-valued signals between Systems must satisfy...
Definition: vector_interface.h:25
virtual Context< T > * DoClone() const
The Context implementation for Diagrams must override this method, since the state of a Diagram will ...
Definition: context.h:117
const State< T > & get_state() const
Definition: context.h:90
std::unique_ptr< Context< T > > Clone() const
Returns a deep copy of this Context.
Definition: context.h:109
std::unique_ptr< LeafStateVector< T > > Clone() const
Copies the entire state to a new LeafStateVector.
Definition: leaf_state_vector.h:23
void ClearInputPorts()
Removes all the input ports, and deregisters them from the output ports on which they depend...
Definition: context.h:64
Cache< T > * get_mutable_cache() const
Access to the cache is always read-write, and is permitted even on const references to the Context...
Definition: context.h:104
Definition: constants.h:3
void set_time(const T &time_sec)
Set the current time in seconds.
Definition: context.h:47
State< T > * get_mutable_state()
Returns writable access to the State.
Definition: context.h:94
The Context is a container for all of the data necessary to uniquely determine the computations perfo...
Definition: context.h:38
int get_num_input_ports() const
Definition: context.h:75
virtual ~Context()
Definition: context.h:41
Context()
Definition: context.h:40
T time_sec
The time, in seconds.
Definition: context.h:23
const T & get_time() const
Returns the current time in seconds.
Definition: context.h:44
void SetNumInputPorts(int n)
Clears the input ports and allocates n new input ports, not connected to anything.
Definition: context.h:70
LeafStateVector is an abstract class template that implements StateVector for leaf Systems...
Definition: leaf_state_vector.h:17
The State is a container for all the data comprising the complete state of a particular System at a p...
Definition: state.h:140
const Cache< T > & get_cache() const
Returns a const reference to the Cache, which is expected to contain precalculated values of interest...
Definition: context.h:99
const VectorInterface< T > * get_vector_input(int index) const
Returns the vector data of the input port at index.
Definition: context.h:80
Contains information about the independent variable including time and step number.
Definition: context.h:19
The ContinuousState is a container for all the State variables that are unique to continuous Systems...
Definition: state.h:22
void SetInputPort(int index, std::unique_ptr< InputPort< T >> port)
Connects the input port port to this Context at the given index.
Definition: context.h:54