blockfactory
0.8
A framework for wrapping algorithms for dataflow programming
|
Basic abstract class for wrapping generic algorithms. More...
#include <Block.h>
Basic abstract class for wrapping generic algorithms.
This class is aimed to wrap generic algorithms and it represents the most basic component of BlockFactory
.
The entire execution of a generic algorithm can be split in the following major steps:
Considering that the main aim of this framework at its beginning was the integration with Simulink, it contains other methods for exposing the algorithm as a Simulink block.
A generic application is the composition of many algorithms sharing and processing each other data. Every algorithm is represented by a core::Block, and the data shared with other blocks is carried by core::Signal.
The block is generally unaware of the data that it will process, and it is only interested in knowing how many input / output signals are connected, their size and data type. Blocks have the concept of ports, which are the connections between external core::Signal and the block itself.
This kind of information is set by a core::BlockInformation object, and it is specific to the framework where the algorithm runs (e.g. standalone C++ code, Simulink, etc).
Beyond this, an algorithm often needs parameters. This class provides functionalities to gather them in a core::Parameters object.
You can create a new block by deriving from this class and implementing at least all the abstract methods.
Type | Index | Rows | Cols | Name |
---|---|---|---|---|
ParameterType::STRING | 0 | 1 | 1 | "className" |
ParameterType::STRING | 1 | 1 | 1 | "libName" |
Public Member Functions | |
virtual | ~Block ()=default |
Destructor. More... | |
std::string | getUniqueName (const BlockInformation *blockInfo) const |
Get the unique name of the block instance. More... | |
virtual unsigned | numberOfParameters () |
Returns the number of configuration parameters needed by this block. More... | |
virtual std::vector< std::string > | additionalBlockOptions () |
Returns the vector of additional block options. More... | |
virtual unsigned | numberOfDiscreteStates () |
Returns the number of discrete states of the block. More... | |
virtual unsigned | numberOfContinuousStates () |
Returns the number of continuous states of the block. More... | |
virtual bool | updateDiscreteState (const BlockInformation *blockInfo) |
Update the internal discrete state. More... | |
virtual bool | stateDerivative (const BlockInformation *blockInfo) |
Update the internal continuous state. More... | |
virtual bool | parameterAtIndexIsTunable (unsigned index) |
Specify if the parameter at the specified index is tunable. More... | |
virtual bool | parseParameters (BlockInformation *blockInfo) |
Parse the parameters stored into the core::BlockInformation object. More... | |
bool | getParameters (blockfactory::core::Parameters ¶ms) const |
Gather all the stored parameters. More... | |
virtual bool | configureSizeAndPorts (BlockInformation *blockInfo) |
Configure the input and output ports. More... | |
virtual bool | initialize (BlockInformation *blockInfo) |
Initialize the block. More... | |
virtual bool | initializeInitialConditions (const BlockInformation *blockInfo) |
Initialize block initial conditions. More... | |
virtual bool | terminate (const BlockInformation *blockInfo) |
Cleanup block resources. More... | |
virtual bool | output (const BlockInformation *blockInfo)=0 |
Compute the output of the block. More... | |
Static Public Attributes | |
static constexpr unsigned | NumberOfParameters = 2 |
Number of parameters of core::Block. More... | |
Protected Attributes | |
Parameters | m_parameters |
Container for block parameters. You can get this member using Block::getParameters. More... | |
|
virtualdefault |
Destructor.
|
virtual |
Returns the vector of additional block options.
Implement this method if you want to store in the Block additional options that can be parsed later from BlockInformation::optionFromKey.
|
virtual |
Configure the input and output ports.
Implement this method to set information about number and size of input and output ports. The terminology port
comes as Simulink inheritage, and it marks the connection of a signal (which resides in some buffer in the program memory) to the block input or output.
These information will be used later (e.g. in the core::Block::initialize and core::Block::output) for preallocating resources and accessing data knowing its size in advance.
blockInfo
will persist.blockInfo | The pointer to a BlockInformation object. |
bool blockfactory::core::Block::getParameters | ( | blockfactory::core::Parameters & | params | ) | const |
Gather all the stored parameters.
After the parameters have been successfully stored and parsed using the core::Block::parseParameter, you can gather them using this method.
[out] | params | A core::Parameters object containing block parameters. |
std::string blockfactory::core::Block::getUniqueName | ( | const BlockInformation * | blockInfo | ) | const |
Get the unique name of the block instance.
blockInfo | The pointer to a BlockInformation object. |
|
virtual |
Initialize the block.
Implement this method to initialize and allocate the resources the algorithm needs during its execution.
blockInfo | The pointer to a BlockInformation object. |
|
virtual |
Initialize block initial conditions.
Implement this method to specify block initial conditions. Its execution will happen after block::Block::initialize and before the first call of core::Block::output. The default is an empty implementation.
blockInfo | The pointer to a BlockInformation object. |
|
virtual |
Returns the number of continuous states of the block.
The base implementation returns 0, i.e. no continuous states.
|
virtual |
Returns the number of discrete states of the block.
The base implementation returns 0, i.e. no discrete states.
|
virtual |
Returns the number of configuration parameters needed by this block.
|
pure virtual |
Compute the output of the block.
This method is called at every iteration of the model. Implement here a single step of the algorithm.
blockInfo | The pointer to a BlockInformation object. |
|
virtual |
Specify if the parameter at the specified index is tunable.
Tunable means that it can be changed during the simulation. Usually parameters are defined before the beginning of the simulation and they stay constant for all its duration.
index | Index of the parameter. |
|
virtual |
Parse the parameters stored into the core::BlockInformation object.
Implement this method to create the metadata of the parameters your block needs (using core::ParameterMetadata), store them into the blockInfo object with core::BlockInformation::addParameterMetadata, and parse them using core::BlockInformation::parseParameters.
An example of the implementation is the following:
blockInfo | The pointer to a BlockInformation object. |
|
virtual |
Update the internal continuous state.
blockInfo | The pointer to a BlockInformation object. |
|
virtual |
Cleanup block resources.
This method is called during the termination of the execution. Implement this method to deallocate all the memory requested during the previous steps or to perform other terminating operations.
blockInfo | The pointer to a BlockInformation object. |
|
virtual |
Update the internal discrete state.
i.e. x[i+1] = f(x[i])
blockInfo | The pointer to a BlockInformation object. |
|
protected |
Container for block parameters. You can get this member using Block::getParameters.
|
static |
Number of parameters of core::Block.
Static variable matching Block::numberOfParameters. It might be useful to define parametric constants for parameter indices in child blocks.