40 #include <Eigen/Dense>
94 return _var(Eigen::seq(0, Eigen::placeholders::last));
104 const auto i = indexer(obj);
117 const size_t id = obj->
id();
118 if ((
id >= _indexes.size()) || (_indexes[
id] < 0)) {
119 throw moordyn::invalid_value_error(
"Missing instance");
121 return Eigen::Index(_indexes[
id]);
124 inline const std::vector<Eigen::Index> indexer(
125 std::vector<moordyn::Instance*> obj)
127 std::vector<Eigen::Index> slcs;
128 slcs.reserve(obj.size());
130 slcs.push_back(indexer(o));
148 std::vector<uint64_t> Serialize(
void);
156 uint64_t* Deserialize(
const uint64_t* data);
178 void copy(
const State& visitor);
185 inline std::vector<int> make_indexes()
187 std::vector<int> indexes;
188 for (
size_t i = 0; i < _objs.size(); i++) {
189 size_t key = _objs[i]->id();
190 if (indexes.size() <= key) {
191 indexes.resize(key + 1, -1);
202 std::vector<moordyn::Instance*> _objs;
205 std::vector<int> _indexes;
216 out.resize(v.rows());
217 for (
unsigned int i = 0; i < v.rows(); i++) {
218 out(i).resize(v(i).rows(), v(i).cols());
234 out.resize(v.rows());
235 for (
unsigned int i = 0; i < v.rows(); i++) {
236 out(i).resize(v(i).rows(), v(i).cols());
245 return v.topLeftCorner(v.rows(), v.cols()) * f;
#define DECLDIR
Prefix to export C functions on the compiled library.
Definition: MoorDynAPI.h:68
A generic instance.
Definition: Instance.hpp:55
virtual const size_t stateN() const
Get the number of state variables required by this instance.
Definition: Instance.hpp:101
const size_t id() const
Get the unique identifier of this instance.
Definition: Instance.hpp:76
virtual const size_t stateDims() const
Get the dimension of the state variable.
Definition: Instance.hpp:108
A Logging utility.
Definition: Log.hpp:149
A base class for all the entities that must save/load data to/from disk.
Definition: IO.hpp:60
The collection of state variables of the whole system.
Definition: State.hpp:54
const Eigen::Index indexer(moordyn::Instance *obj)
Get the index within a state var for a particular instance.
Definition: State.hpp:115
InstanceStateVarView get(moordyn::Instance *obj)
Get the state variables associated to an instance.
Definition: State.hpp:102
State(const State &rhs)
Copy constructor.
Definition: State.hpp:67
~State()
Destructor.
Definition: State.hpp:75
State & operator=(const State &rhs)
Assignment operator.
Definition: State.hpp:161
StateVarView get()
Get the state variables.
Definition: State.hpp:92
State(moordyn::Log *log)
Constructor.
Definition: State.hpp:59
MoorDyn2 C++ API namespace.
Definition: Body.cpp:27
Eigen::Block< InstanceStateVar, Eigen::Dynamic > InstanceStateVarView
View of the State variables for a particular instance.
Definition: Misc.hpp:167
Eigen::VectorBlock< StateVar, Eigen::Dynamic > StateVarView
View of the State variable.
Definition: Misc.hpp:171
Eigen::Matrix< InstanceStateVar, Eigen::Dynamic, 1 > StateVar
State variable.
Definition: Misc.hpp:169
double real
Real numbers wrapper. It is either double or float.
Definition: Misc.hpp:118