|
Dynamic Neural Field Composer 0.0.0
A C++20 library and interactive application for building and simulating Dynamic Neural Field (DNF) architectures.
|
Manages the element registry and drives the simulation loop. More...
#include <simulation.h>
Public Member Functions | |
| void | addElement (const std::shared_ptr< element::Element > &element) |
| void | changeDimensions (const std::string &elementId, const element::ElementDimensions &newDimensions) |
Disconnect all connections from elementId and resize it to newDimensions. | |
| void | clean () |
| Remove all elements and reset the simulation to its initial state. | |
| void | close () |
| Release resources of all elements and reset timing state. | |
| bool | componentExists (const std::string &id, const std::string &componentName) const |
| void | createInteraction (const std::string &stimulusElementId, const std::string &stimulusComponent, const std::string &receivingElementId) const |
Wire stimulusElementId's stimulusComponent as input to receivingElementId. | |
| std::vector< double > | getComponent (const std::string &id, const std::string &componentName) const |
| std::vector< double > * | getComponentPtr (const std::string &id, const std::string &componentName) const |
| double | getDeltaT () const |
| std::shared_ptr< element::Element > | getElement (const std::string &id) const |
| Retrieve an element by its unique name. Throws if not found. | |
| std::shared_ptr< element::Element > | getElement (int index) const |
| Retrieve an element by its registry index. | |
| std::vector< std::shared_ptr< element::Element > > | getElements () const |
| std::vector< std::shared_ptr< element::Element > > | getElementsThatHaveSpecifiedElementAsInput (const std::string &specifiedElement, const std::string &inputComponent="output") const |
Return all elements that list specifiedElement as an input. | |
| int | getHighestElementIndex () const |
| std::string | getIdentifier () const |
Return the simulation's unique identifier (alias for getUniqueIdentifier()). | |
| std::chrono::nanoseconds | getLastStepDuration () const |
Return the wall-clock duration of the most recent step() call. | |
| bool | getMeasureStepDuration () const |
| int | getNumberOfElements () const |
| SimulationRecorder & | getRecorder () |
| Access the recorder to start/stop time-series recordings or take snapshots. | |
| double | getT () const |
| std::chrono::nanoseconds | getTotalRunDuration () const |
Return total wall-clock time since the last init() call. | |
| double | getTZero () const |
| std::string | getUniqueIdentifier () const |
| void | init () |
Initialize all registered elements. Must be called before step(). | |
| bool | isInitialized () const |
Return true if init() has been called and the simulation is ready. | |
| bool | isPaused () const |
| Return true if the simulation is currently paused. | |
| Simulation & | operator= (const Simulation &other) |
| Simulation & | operator= (Simulation &&) noexcept |
| void | pause () |
Pause the simulation (subsequent step() calls are no-ops). | |
| void | read (const std::string &readPath={}) |
| Deserialize the simulation state from a JSON file. | |
| void | removeElement (const std::string &elementId) |
| Remove and destroy the element with the given unique name. | |
| void | renameElement (const std::string &oldName, const std::string &newName) |
| Rename an element. No-op if oldName does not exist or newName is already in use. | |
| void | resetElement (const std::string &idOfElementToReset, const std::shared_ptr< element::Element > &newElement) |
| Replace an existing element with a new one, preserving connections. | |
| void | resume () |
| void | run (double runTime) |
Run the simulation for runTime milliseconds (blocking). | |
| void | runForRealTime (double milliseconds) |
Run the simulation in real-time for milliseconds wall-clock ms. | |
| void | save (const std::string &savePath={}) |
| Serialize the simulation and its elements to a JSON file. | |
| void | setDeltaT (double deltaT) |
| void | setMeasureStepDuration (bool enable) |
| Enable or disable per-step wall-clock timing (default: enabled). Disable for headless/benchmark runs to avoid two steady_clock::now() calls per step. | |
| void | setUniqueIdentifier (const std::string &id) |
| Simulation (const Simulation &other) | |
| Simulation (const std::string &identifier="", double deltaT=1, double tZero=0, double t=0) | |
| Construct a simulation. | |
| Simulation (Simulation &&other) noexcept | |
| void | step () |
Advance all elements by one deltaT. | |
| ~Simulation ()=default | |
Public Attributes | |
| std::chrono::nanoseconds | accumulatedRunDuration { 0 } |
| double | deltaT |
| Integration step size. | |
| std::chrono::nanoseconds | lastStepDuration { 0 } |
| std::chrono::steady_clock::time_point | runSegmentStart {} |
| double | t |
| Current simulation time. | |
| double | tZero |
| Start time. | |
Protected Attributes | |
| std::vector< std::shared_ptr< element::Element > > | elements |
| Ordered element registry. | |
| bool | initialized |
True after init() has been called. | |
| bool | paused |
| True while the simulation is paused. | |
| std::string | uniqueIdentifier |
| Human-readable simulation name. | |
Manages the element registry and drives the simulation loop.
Simulation owns a collection of Element objects. Calling init() prepares all elements; each call to step() advances every element by deltaT. The simulation can be paused, resumed, saved to / loaded from JSON, and queried for per-step and total run timing.
|
explicit |
Construct a simulation.
| identifier | Human-readable name. |
| deltaT | Step size (default 1). |
| tZero | Start time (default 0). |
| t | Initial current time (default 0). |
| dnf_composer::Simulation::Simulation | ( | const Simulation & | other | ) |
|
noexcept |
|
default |
| void dnf_composer::Simulation::addElement | ( | const std::shared_ptr< element::Element > & | element | ) |
| void dnf_composer::Simulation::changeDimensions | ( | const std::string & | elementId, |
| const element::ElementDimensions & | newDimensions | ||
| ) |
Disconnect all connections from elementId and resize it to newDimensions.
| elementId | Unique name of the element to resize. |
| newDimensions | New spatial discretization. |
| void dnf_composer::Simulation::clean | ( | ) |
Remove all elements and reset the simulation to its initial state.
| void dnf_composer::Simulation::close | ( | ) |
Release resources of all elements and reset timing state.
| bool dnf_composer::Simulation::componentExists | ( | const std::string & | id, |
| const std::string & | componentName | ||
| ) | const |
| void dnf_composer::Simulation::createInteraction | ( | const std::string & | stimulusElementId, |
| const std::string & | stimulusComponent, | ||
| const std::string & | receivingElementId | ||
| ) | const |
Wire stimulusElementId's stimulusComponent as input to receivingElementId.
| stimulusElementId | Source element name. |
| stimulusComponent | Component name on the source (e.g. "output"). |
| receivingElementId | Destination element name. |
| std::vector< double > dnf_composer::Simulation::getComponent | ( | const std::string & | id, |
| const std::string & | componentName | ||
| ) | const |
| std::vector< double > * dnf_composer::Simulation::getComponentPtr | ( | const std::string & | id, |
| const std::string & | componentName | ||
| ) | const |
| double dnf_composer::Simulation::getDeltaT | ( | ) | const |
| std::shared_ptr< element::Element > dnf_composer::Simulation::getElement | ( | const std::string & | id | ) | const |
Retrieve an element by its unique name. Throws if not found.
| id | Unique name of the element. |
| std::shared_ptr< element::Element > dnf_composer::Simulation::getElement | ( | int | index | ) | const |
Retrieve an element by its registry index.
| index | Zero-based index into the element list. |
| std::vector< std::shared_ptr< element::Element > > dnf_composer::Simulation::getElements | ( | ) | const |
| std::vector< std::shared_ptr< element::Element > > dnf_composer::Simulation::getElementsThatHaveSpecifiedElementAsInput | ( | const std::string & | specifiedElement, |
| const std::string & | inputComponent = "output" |
||
| ) | const |
Return all elements that list specifiedElement as an input.
| specifiedElement | Name of the element to search for. |
| inputComponent | Component name to match (default "output"). |
| int dnf_composer::Simulation::getHighestElementIndex | ( | ) | const |
| std::string dnf_composer::Simulation::getIdentifier | ( | ) | const |
Return the simulation's unique identifier (alias for getUniqueIdentifier()).
| std::chrono::nanoseconds dnf_composer::Simulation::getLastStepDuration | ( | ) | const |
Return the wall-clock duration of the most recent step() call.
|
inline |
| int dnf_composer::Simulation::getNumberOfElements | ( | ) | const |
|
inline |
Access the recorder to start/stop time-series recordings or take snapshots.
SimulationRecorder. | double dnf_composer::Simulation::getT | ( | ) | const |
| std::chrono::nanoseconds dnf_composer::Simulation::getTotalRunDuration | ( | ) | const |
Return total wall-clock time since the last init() call.
| double dnf_composer::Simulation::getTZero | ( | ) | const |
| std::string dnf_composer::Simulation::getUniqueIdentifier | ( | ) | const |
| void dnf_composer::Simulation::init | ( | ) |
Initialize all registered elements. Must be called before step().
| bool dnf_composer::Simulation::isInitialized | ( | ) | const |
Return true if init() has been called and the simulation is ready.
| bool dnf_composer::Simulation::isPaused | ( | ) | const |
Return true if the simulation is currently paused.
| Simulation & dnf_composer::Simulation::operator= | ( | const Simulation & | other | ) |
|
noexcept |
| void dnf_composer::Simulation::pause | ( | ) |
Pause the simulation (subsequent step() calls are no-ops).
| void dnf_composer::Simulation::read | ( | const std::string & | readPath = {} | ) |
Deserialize the simulation state from a JSON file.
| readPath | Source file path; if empty, a default path is used. |
| void dnf_composer::Simulation::removeElement | ( | const std::string & | elementId | ) |
Remove and destroy the element with the given unique name.
| elementId | Unique name of the element to remove. |
| void dnf_composer::Simulation::renameElement | ( | const std::string & | oldName, |
| const std::string & | newName | ||
| ) |
Rename an element. No-op if oldName does not exist or newName is already in use.
| void dnf_composer::Simulation::resetElement | ( | const std::string & | idOfElementToReset, |
| const std::shared_ptr< element::Element > & | newElement | ||
| ) |
Replace an existing element with a new one, preserving connections.
| idOfElementToReset | Unique name of the element to replace. |
| newElement | Replacement element. |
| void dnf_composer::Simulation::resume | ( | ) |
| void dnf_composer::Simulation::run | ( | double | runTime | ) |
Run the simulation for runTime milliseconds (blocking).
| runTime | Duration to simulate in ms. |
| void dnf_composer::Simulation::runForRealTime | ( | double | milliseconds | ) |
Run the simulation in real-time for milliseconds wall-clock ms.
| milliseconds | Wall-clock duration to run for. |
| void dnf_composer::Simulation::save | ( | const std::string & | savePath = {} | ) |
Serialize the simulation and its elements to a JSON file.
| savePath | Destination file path; if empty, a default path is used. |
| void dnf_composer::Simulation::setDeltaT | ( | double | deltaT | ) |
|
inline |
Enable or disable per-step wall-clock timing (default: enabled). Disable for headless/benchmark runs to avoid two steady_clock::now() calls per step.
| void dnf_composer::Simulation::setUniqueIdentifier | ( | const std::string & | id | ) |
| void dnf_composer::Simulation::step | ( | ) |
Advance all elements by one deltaT.
| std::chrono::nanoseconds dnf_composer::Simulation::accumulatedRunDuration { 0 } |
| double dnf_composer::Simulation::deltaT |
Integration step size.
|
protected |
Ordered element registry.
|
protected |
True after init() has been called.
| std::chrono::nanoseconds dnf_composer::Simulation::lastStepDuration { 0 } |
|
protected |
True while the simulation is paused.
| std::chrono::steady_clock::time_point dnf_composer::Simulation::runSegmentStart {} |
| double dnf_composer::Simulation::t |
Current simulation time.
| double dnf_composer::Simulation::tZero |
Start time.
|
protected |
Human-readable simulation name.