Hopsan
|
Functions | |
double | readNode (const size_t idx) const |
Reads a value from the connected node. | |
virtual double | readNode (const size_t idx, const size_t subPortIdx) const |
Reads a value from the connected node. | |
void | writeNode (const size_t idx, const double value) |
Writes a value to the connected node. | |
virtual void | writeNode (const size_t idx, const double value, const size_t subPortIdx) |
Writes a value to the connected node. | |
double | readNode (const size_t idx, const size_t subPortIdx) const |
Reads a value from the connected node. | |
void | writeNode (const size_t idx, const double value, const size_t subPortIdx) |
Writes a value to the connected node. | |
virtual void | initialize () |
The initialize function must be overloaded in each component, it is used to initialize the component just before simulation begins. | |
virtual void | simulateOneTimestep () |
Simulates one time step. This component must be overloaded en each component. | |
virtual void | finalize () |
Optional function that is called after every simulation, can be used to clean up memory allocation made in initialize. | |
void | stopSimulation (const HString &rReason="") |
Terminate/stop a running initialization or simulation. | |
double * | getSafeNodeDataPtr (Port *pPort, const int dataId) |
Get a pointer to the node data variable, (Port pointer version) | |
double * | getSafeNodeDataPtr (const HString &rPortName, const int dataId) |
Get a pointer to the node data variable, (Port name version) | |
double * | getSafeMultiPortNodeDataPtr (Port *pPort, const size_t portIdx, const int dataId) |
Get a pointer to node data in a subport in a multiport. | |
double * | getSafeMultiPortNodeDataPtr (Port *pPort, const size_t portIdx, const int dataId, const double defaultValue) |
Get a pointer to node data in a subport in a multiport (also setting initial value at the same time) | |
double | readNodeSafe (const HString &rPortName, const HString &rDataName, const size_t subPortIdx=0) |
Read value based on the port and node data name. | |
double | readNodeSafe (const HString &rPortName, const size_t dataId, const size_t subPortIdx=0) |
Read value based on the port name and node data id. | |
void | writeNodeSafe (const HString &rPortName, const HString &rDataName, const double value, const size_t subPortIdx=0) |
Write node data based on port and data name. | |
void | writeNodeSafe (const HString &rPortName, const size_t dataId, const double value, const size_t subPortIdx=0) |
Write node data based on port and data id. | |
virtual double | readNodeSafe (const size_t idx, const size_t subPortIdx=0) const |
Reads a value from the connected node. | |
virtual void | writeNodeSafe (const size_t idx, const double value, const size_t subPortIdx=0) |
Writes a value to the connected node. | |
double | readNodeSafe (const size_t idx, const size_t subPortIdx) const |
Reads a value from the connected node. | |
void | writeNodeSafe (const size_t idx, const double value, const size_t subPortIdx) |
Writes a value to the connected node. | |
|
protectedvirtual |
Optional function that is called after every simulation, can be used to clean up memory allocation made in initialize.
Reimplemented in ComponentSystem.
double * getSafeMultiPortNodeDataPtr | ( | Port * | pPort, |
const size_t | portIdx, | ||
const int | dataId ) |
Get a pointer to node data in a subport in a multiport.
[in] | pPort | A pointer to the port from which to fetch NodeData pointer |
[in] | portIdx | The index of the subport in a multiport |
[in] | dataId | The enum id for the node value to fetch pointer to |
double * getSafeMultiPortNodeDataPtr | ( | Port * | pPort, |
const size_t | portIdx, | ||
const int | dataId, | ||
const double | defaultValue ) |
Get a pointer to node data in a subport in a multiport (also setting initial value at the same time)
[in] | pPort | A pointer to the port from which to fetch NodeData pointer |
[in] | portIdx | The index of the subport in a multiport |
[in] | dataId | The enum id for the node value to fetch pointer to |
[in] | defaultValue | The initial value to set for this node data |
double * getSafeNodeDataPtr | ( | const HString & | rPortName, |
const int | dataId ) |
Get a pointer to the node data variable, (Port name version)
The safe in this version means that a dummy pointer will be returned if the desired one was not found, this prevents crash and the need to check that return pointer is ok, giving cleaner component code An error message is given if the desired data was not found
[in] | rPortName | The name of the port from which to fetch the node data pointer |
[in] | dataId | The enum id for the node value to fetch pointer to, (Ex: ModeHydraulic::Pressure) |
double * getSafeNodeDataPtr | ( | Port * | pPort, |
const int | dataId ) |
Get a pointer to the node data variable, (Port pointer version)
The safe in this version means that a dummy pointer will be returned if the desired one was not found, this prevents crash and the need to check that return pointer is ok, giving cleaner component code An error message is given if the desired data was not found
[in] | pPort | A pointer to the port from which to fetch the node data pointer |
[in] | dataId | The enum id for the node value to fetch pointer to, (Ex: ModeHydraulic::Pressure) |
|
protectedvirtual |
The initialize function must be overloaded in each component, it is used to initialize the component just before simulation begins.
In this function you should get node data ptrs and calculate initial values to write to the nodes You are not allowed to reconnect internal connections in this function, as other components may already have initialized and fetch data pointers to ports/nodes in this component
Reimplemented in DummyComponent.
|
inlinevirtual |
Reads a value from the connected node.
[in] | idx | The data id of the data to read |
[in] | subPortIdx | The subPort to read from (range is NOT checked) |
Reimplemented from Port.
|
inline |
Reads a value from the connected node.
[in] | idx | The data id of the data to read |
|
inlinevirtual |
Reads a value from the connected node.
[in] | idx | The data id of the data to read |
[in] | subPortIdx | (Ignored on non multi ports) |
Reimplemented in MultiPort.
double readNodeSafe | ( | const HString & | rPortName, |
const HString & | rDataName, | ||
const size_t | subPortIdx = 0 ) |
Read value based on the port and node data name.
It searches for data based on strings, this make it unsuitable for use during simulation but it is suitable during initialize when port pointers are not desired/available This function will also check so that the desired data actually exist in the requested node, error message will be sent if it does not
[in] | rPortName | The port to write data to |
[in] | rDataName | The data variable name for the data to be written |
[in] | subPortIdx | The index of a multiport subport |
double readNodeSafe | ( | const HString & | rPortName, |
const size_t | dataId, | ||
const size_t | subPortIdx = 0 ) |
Read value based on the port name and node data id.
It searches for data based on strings, this make it unsuitable for use during simulation but it is suitable during initialize when port pointers are not desired/available This function will only check if node data id is within range in the node, not if the data actually exist
[in] | rPortName | The port to write data to |
[in] | dataId | The data variable id for the data to be written |
[in] | subPortIdx | The index of a multiport subport |
|
virtual |
Reads a value from the connected node.
[in] | idx | The data id of the data to read |
[in] | subPortIdx | The subPort index in the multi port |
Safe but slow version, will not crash if idx out of bounds
Reimplemented from Port.
|
virtual |
Reads a value from the connected node.
[in] | idx | The data id of the data to read |
[in] | subPortIdx | The subPort index of a port in a multiport, (ignored if not a multiport) |
Safe but slow version, will not crash if idx out of bounds
Reimplemented in MultiPort.
|
protectedvirtual |
Simulates one time step. This component must be overloaded en each component.
This is the function where all the component model equations should be written. This function is called once for every time step
Reimplemented in DummyComponent.
void stopSimulation | ( | const HString & | rReason = "" | ) |
Terminate/stop a running initialization or simulation.
[in] | rReason | An optional HString describing the reason for the stop |
Typically used inside components simulateOneTimestep method
|
inlinevirtual |
Writes a value to the connected node.
[in] | idx | The data id of the data to write |
[in] | value | The value to write |
[in] | subPortIdx | The subPort to write to (range is NOT checked) |
Reimplemented from Port.
|
inline |
Writes a value to the connected node.
[in] | idx | The data id of the data to write |
[in] | value | The value to write |
|
inlinevirtual |
Writes a value to the connected node.
[in] | idx | The data id of the data to write |
[in] | value | The value to write |
[in] | subPortIdx | (Ignored on non multi ports) |
Reimplemented in MultiPort.
void writeNodeSafe | ( | const HString & | rPortName, |
const HString & | rDataName, | ||
const double | value, | ||
const size_t | subPortIdx = 0 ) |
Write node data based on port and data name.
It searches for data based on strings, this make it unsuitable for use during simulation but it is suitable during initialize when port pointers are not desired/available This function will also check so that the desired data actually exist in the requested node, error message will be sent if it does not
[in] | rPortName | The port to write data to |
[in] | rDataName | The data variable name for the data to be written |
[in] | value | The value to write |
[in] | subPortIdx | The index of a multiport subport |
void writeNodeSafe | ( | const HString & | rPortName, |
const size_t | dataId, | ||
const double | value, | ||
const size_t | subPortIdx = 0 ) |
Write node data based on port and data id.
It searches for data based on strings, this make it unsuitable for use during simulation but it is suitable during initialize when port pointers are not desired/available This function will only check if node data id is within range in the node, not if the data actually exist
[in] | rPortName | The port to write data to |
[in] | dataId | The data variable id for the data to be written |
[in] | value | The value to write |
[in] | subPortIdx | The index of a multiport subport |
|
virtual |
Writes a value to the connected node.
[in] | idx | The data id of the data to write (Such as NodeHydraulic::Pressure) |
[in] | value | The value of the data to read |
[in] | subPortIdx | The subport to write to, (range check is performed) |
Safe but slow version, will not crash if idx out of bounds
Reimplemented from Port.
|
virtual |
Writes a value to the connected node.
[in] | idx | The data id of the data to write (Such as NodeHydraulic::Pressure) |
[in] | value | The value of the data to read |
[in] | subPortIdx | Ignored for non multi ports |
Safe but slow version, will not crash if idx out of bounds