Dynamic Neural Field Composer 0.0.0
A C++20 library and interactive application for building and simulating Dynamic Neural Field (DNF) architectures.
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
dnf_composer::Simulation Class Reference

Manages the element registry and drives the simulation loop. More...

#include <simulation.h>

Inheritance diagram for dnf_composer::Simulation:
Collaboration diagram for dnf_composer::Simulation:

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::ElementgetElement (const std::string &id) const
 Retrieve an element by its unique name. Throws if not found.
 
std::shared_ptr< element::ElementgetElement (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
 
SimulationRecordergetRecorder ()
 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.
 
Simulationoperator= (const Simulation &other)
 
Simulationoperator= (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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Simulation() [1/3]

dnf_composer::Simulation::Simulation ( const std::string &  identifier = "",
double  deltaT = 1,
double  tZero = 0,
double  t = 0 
)
explicit

Construct a simulation.

Parameters
identifierHuman-readable name.
deltaTStep size (default 1).
tZeroStart time (default 0).
tInitial current time (default 0).
Here is the call graph for this function:

◆ Simulation() [2/3]

dnf_composer::Simulation::Simulation ( const Simulation other)

◆ Simulation() [3/3]

dnf_composer::Simulation::Simulation ( Simulation &&  other)
noexcept

◆ ~Simulation()

dnf_composer::Simulation::~Simulation ( )
default

Member Function Documentation

◆ addElement()

void dnf_composer::Simulation::addElement ( const std::shared_ptr< element::Element > &  element)

◆ changeDimensions()

void dnf_composer::Simulation::changeDimensions ( const std::string &  elementId,
const element::ElementDimensions newDimensions 
)

Disconnect all connections from elementId and resize it to newDimensions.

Parameters
elementIdUnique name of the element to resize.
newDimensionsNew spatial discretization.
Here is the call graph for this function:

◆ clean()

void dnf_composer::Simulation::clean ( )

Remove all elements and reset the simulation to its initial state.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ close()

void dnf_composer::Simulation::close ( )

Release resources of all elements and reset timing state.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ componentExists()

bool dnf_composer::Simulation::componentExists ( const std::string &  id,
const std::string &  componentName 
) const
Here is the call graph for this function:

◆ createInteraction()

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.

Parameters
stimulusElementIdSource element name.
stimulusComponentComponent name on the source (e.g. "output").
receivingElementIdDestination element name.
Here is the call graph for this function:

◆ getComponent()

std::vector< double > dnf_composer::Simulation::getComponent ( const std::string &  id,
const std::string &  componentName 
) const
Here is the call graph for this function:

◆ getComponentPtr()

std::vector< double > * dnf_composer::Simulation::getComponentPtr ( const std::string &  id,
const std::string &  componentName 
) const
Here is the call graph for this function:

◆ getDeltaT()

double dnf_composer::Simulation::getDeltaT ( ) const

◆ getElement() [1/2]

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.

Parameters
idUnique name of the element.
Here is the caller graph for this function:

◆ getElement() [2/2]

std::shared_ptr< element::Element > dnf_composer::Simulation::getElement ( int  index) const

Retrieve an element by its registry index.

Parameters
indexZero-based index into the element list.

◆ getElements()

std::vector< std::shared_ptr< element::Element > > dnf_composer::Simulation::getElements ( ) const

◆ getElementsThatHaveSpecifiedElementAsInput()

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.

Parameters
specifiedElementName of the element to search for.
inputComponentComponent name to match (default "output").

◆ getHighestElementIndex()

int dnf_composer::Simulation::getHighestElementIndex ( ) const

◆ getIdentifier()

std::string dnf_composer::Simulation::getIdentifier ( ) const

Return the simulation's unique identifier (alias for getUniqueIdentifier()).

◆ getLastStepDuration()

std::chrono::nanoseconds dnf_composer::Simulation::getLastStepDuration ( ) const

Return the wall-clock duration of the most recent step() call.

◆ getMeasureStepDuration()

bool dnf_composer::Simulation::getMeasureStepDuration ( ) const
inline

◆ getNumberOfElements()

int dnf_composer::Simulation::getNumberOfElements ( ) const

◆ getRecorder()

SimulationRecorder & dnf_composer::Simulation::getRecorder ( )
inline

Access the recorder to start/stop time-series recordings or take snapshots.

Returns
Non-const reference to the internal SimulationRecorder.
See also
SimulationRecorder

◆ getT()

double dnf_composer::Simulation::getT ( ) const

◆ getTotalRunDuration()

std::chrono::nanoseconds dnf_composer::Simulation::getTotalRunDuration ( ) const

Return total wall-clock time since the last init() call.

◆ getTZero()

double dnf_composer::Simulation::getTZero ( ) const

◆ getUniqueIdentifier()

std::string dnf_composer::Simulation::getUniqueIdentifier ( ) const

◆ init()

void dnf_composer::Simulation::init ( )

Initialize all registered elements. Must be called before step().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInitialized()

bool dnf_composer::Simulation::isInitialized ( ) const

Return true if init() has been called and the simulation is ready.

◆ isPaused()

bool dnf_composer::Simulation::isPaused ( ) const

Return true if the simulation is currently paused.

◆ operator=() [1/2]

Simulation & dnf_composer::Simulation::operator= ( const Simulation other)

◆ operator=() [2/2]

Simulation & dnf_composer::Simulation::operator= ( Simulation &&  other)
noexcept

◆ pause()

void dnf_composer::Simulation::pause ( )

Pause the simulation (subsequent step() calls are no-ops).

Here is the caller graph for this function:

◆ read()

void dnf_composer::Simulation::read ( const std::string &  readPath = {})

Deserialize the simulation state from a JSON file.

Parameters
readPathSource file path; if empty, a default path is used.
Here is the call graph for this function:

◆ removeElement()

void dnf_composer::Simulation::removeElement ( const std::string &  elementId)

Remove and destroy the element with the given unique name.

Parameters
elementIdUnique name of the element to remove.

◆ renameElement()

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.

Here is the call graph for this function:

◆ resetElement()

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.

Parameters
idOfElementToResetUnique name of the element to replace.
newElementReplacement element.

◆ resume()

void dnf_composer::Simulation::resume ( )

◆ run()

void dnf_composer::Simulation::run ( double  runTime)

Run the simulation for runTime milliseconds (blocking).

Parameters
runTimeDuration to simulate in ms.
Here is the call graph for this function:

◆ runForRealTime()

void dnf_composer::Simulation::runForRealTime ( double  milliseconds)

Run the simulation in real-time for milliseconds wall-clock ms.

Parameters
millisecondsWall-clock duration to run for.
Here is the call graph for this function:

◆ save()

void dnf_composer::Simulation::save ( const std::string &  savePath = {})

Serialize the simulation and its elements to a JSON file.

Parameters
savePathDestination file path; if empty, a default path is used.
Here is the call graph for this function:

◆ setDeltaT()

void dnf_composer::Simulation::setDeltaT ( double  deltaT)

◆ setMeasureStepDuration()

void dnf_composer::Simulation::setMeasureStepDuration ( bool  enable)
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.

◆ setUniqueIdentifier()

void dnf_composer::Simulation::setUniqueIdentifier ( const std::string &  id)

◆ step()

void dnf_composer::Simulation::step ( )

Advance all elements by one deltaT.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ accumulatedRunDuration

std::chrono::nanoseconds dnf_composer::Simulation::accumulatedRunDuration { 0 }

◆ deltaT

double dnf_composer::Simulation::deltaT

Integration step size.

◆ elements

std::vector<std::shared_ptr<element::Element> > dnf_composer::Simulation::elements
protected

Ordered element registry.

◆ initialized

bool dnf_composer::Simulation::initialized
protected

True after init() has been called.

◆ lastStepDuration

std::chrono::nanoseconds dnf_composer::Simulation::lastStepDuration { 0 }

◆ paused

bool dnf_composer::Simulation::paused
protected

True while the simulation is paused.

◆ runSegmentStart

std::chrono::steady_clock::time_point dnf_composer::Simulation::runSegmentStart {}

◆ t

double dnf_composer::Simulation::t

Current simulation time.

◆ tZero

double dnf_composer::Simulation::tZero

Start time.

◆ uniqueIdentifier

std::string dnf_composer::Simulation::uniqueIdentifier
protected

Human-readable simulation name.


The documentation for this class was generated from the following files: