| Message: Re: The Strangest Problem I've ever met | Not Logged In (login) |
|
You most definitely do not want to open and read a file during EVERY call to GetFieldValue() -- this will slow your simulation down by a truly enormous factor! You consider "only 3 or 4 min" to be "quickly" -- I routinely track hundreds of particles per second for many meters through magnetic field maps. Even a single sprintf() or sscanf() during tracking slows it down unacceptably.
Arrange the code so you open and read the files ONCE during initialization and keep the results around to use in GetFieldValue(). It is generally better (more general, easier to modify) to use a single file with a field map, rather than multiple files. A good design has the field map file describe its own geometrical structure (boundaries of the map, grid within the map, units, etc.) and the code uses this rather than hard-coded values for the geometry. I strongly recommend an ASCII format, so you can edit it easily, and can write conversion programs from the output of an EM modeling program (superfish, tosca, ...) to the format your simulation reads. Field maps of several tens of megabytes are not a problem on modern computers. Whenever a track reaches the edge of the world, the track is killed. Similarly, when a track stops (kinetic energy goes to 0 or below a limit set in the program) it is killed unless there is an applicable physics process that makes it get captured or decay (which also kills the track). Just think about it -- how could a track possibly be tracked outside the known world? Or tracked forever while stopped? Normally, when all tracks have been processed (i.e. tracked until they are killed), the run is ended and the program exits. But you must do this in your main program, as in the examples.
|
| Inline Depth: | Outline Depth: | Add message: |
|
to: |