[lammps-users] Inputs to modify_params in code


I am trying to invoke modify_params for a dump (to change output frequency) from within a custom fix. I verified that my_dump_id was found, but there is a segmentation fault that occurs when modify_params is invoked. I believe it has to do with the arguments to modify_params, but I could not figure out exactly what went wrong. Any help is greatly appreciated.

int idump = output->find_dump(“my_dump_id”);
Dump *dumptarget = output->dump[idump];
char *a = “every”;
char *b = “1”;
char *ab[] = {a,b};
char **arg_dump_modify = ab;
if(dumptarget) dumptarget->modify_params(2,arg_dump_modify);
else error->all(FLERR,“Could not find my_dump_id”);

Thank you,

To debug a segmentation fault you should be using a debugger. since you are doing your own programming, learning to use a debugger is a valuable skill and worth the time and effort it requires to acquire it. The most likely cause of a segfault is that you are declaring read-only string constants as writable strings. most compilers will warn about this. If the functionality in LAMMPS you are calling needs to modify the string before applying it, then you will get a segmentation fault.

As for modifying the dump frequency during a run, there should not be a need to do what you do. it may not work as expected, anyway. most operations that need to be executed as commands between runs, may not work if executed during a run. most classes precompute some data and cache settings.
Instead what you should be doing is to define the output step with an equal style variable. This variable is evaluated when a dump frame is written and tells the dump class when the next frame should be written (this is a requirement). If you want to modify the frequency then you only need to write an equal style variable expression that references an internal style variable and update the value of that internal variable from your code. or you could have your custom fix return a global scalar that is the next timestep and then reference that from the equal style variable.