How to implement a function of controlling running time?

The basics of how to develop, test, and use models.
Post Reply
ted
Site Admin
Posts: 6384
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Post by ted »

One way is to redefine the run() procedure (see chapter 7 of The NEURON Book).
Insert this statement at the end of your program:

Code: Select all

load_file("customrun.hoc")
Then make a hoc file called customrun.hoc and put this in it:

Code: Select all

how_much_longer = 5 // or however many milliseconds the simulation should run

func keepgoing() {
  // here you put your code that decides if the simulation should continue
  if (your code decides that the simulation should continue) // this line is pseudocode
    return 1
  } else {
    return 0
  }
}

proc run() {
  stdinit()
  while (keepgoing()) {
    continuerun(t + how_much_longer)
  }
}
ted
Site Admin
Posts: 6384
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Post by ted »

Thank me when you know for sure that it works.
ted
Site Admin
Posts: 6384
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Post by ted »

A few things to keep in mind:
1. fadvance is a procedure, so it should be called fadvance().
2. If "dosomething" changes model parameters or state variables, the
simulation will not work with adaptive integration unless cvode is reinitialized.
3. If the purpose of "dosomething" is simply to decide whether to continue
the simulation or to stop, and the decision hangs on whether some variable
reaches a critical level, it would be more efficient to use a NetCon to
monitor that variable for threshold crossing, and use that NetCon's record()
method to execute the statement
stoprun = 1
Post Reply