Related Documentation:
This developer guide gives an example of how to add a new simulation object and integrate this new Component with GENESIS. As an example we implement the pulsegen object of GENESIS 2 that, for simplicity, we will embed as a new component in the Experiment package.
First we create the following source files for the new object in the correct places in Experiment:
pulsegen.c
experiment/pulsegen.h |
These source files will be filled in with the functionality of the GENESIS 2 pulsegen object.
To keep track of all the data for the new object we define a struct(ure) which contains all of our variables. This structure is set up in the header file experiment/pulsegen.h:
struct simobj_PulseGen
{ char *pcName; double dLevel1; double dWidth1; double dDelay1; double dLevel2; double dWidth2; double dDelay2; double dBaseLevel; double dTriggerTime; int iTriggerMode; int iPreviousInput; /// An input value referenced via pointer. double *pdPulseIn; /// solved variables double *pdPulseOut; }; |
Keeping in mind that the new object is going to be used by a simulation, we need appropriate functions for interaction with the scheduler. The most important functions are: creation and set up of the object’s run-time instance, performing the actions during a single simulation step, and freeing the memory allocated by the object during its lifetime.
struct simobj_PulseGen * PulseGenNew(char *pcName);
|
int PulseGenAddVariable(struct simobj_PulseGen *ppg, void *pvOutput);
|
int PulseGenSetFields
( struct simobj_PulseGen *ppg, double dLevel1, double dWidth1, double dDelay1, double dLevel2, double dWidth2, double dDelay2, double dBaseLevel, int iTriggerMode ); |
int PulseGenReset(struct simobj_PulseGen *ppg);
|
int PulseGenSingleStep(struct simobj_PulseGen *ppg, double dTime);
|
int PulseGenFinish(struct simobj_PulseGen *ppg);
|
Before compiling the new simulation object you must add your source files to targets of the Experiment package Makefile.am.
pulsegen.c
|
experiment/pulsegen.h
|
The new simulation object will be compiled into the Experiment library when a make is performed.