Issue with unfix bond_react and redefinition

Hello,

I’m running into an issue with fix bond_react. I would like to use bond_react several times in a loop, defined a little differently each time.
I’m trying this on the January 4, 2019 version of LAMMPS. I modified one of the examples included in LAMMPS to unfix the relevant fixes and then redefine the fixes the same way.
I expected the simulation to continue to run for another 10000 timesteps but it crashes and I’m not sure why.
I’ve attached the input script (modifiedin.tiny_nylon), output (polyout.txt), data file (tiny_nylon.data), and reaction files.

I would really appreciate any guidance.

Thanks,
Amulya

polyout.txt (19.6 KB)

modifiedin.tiny_nylon (1.38 KB)

rxn1_stp1_unreacted.data_template (1.98 KB)

rxn1_stp1_map (200 Bytes)

rxn1_stp1_reacted.data_template (2.4 KB)

rxn1_stp2_map (181 Bytes)

rxn1_stp2_reacted.data_template (1.59 KB)

rxn1_stp2_unreacted.data_template (1.97 KB)

tiny_nylon.data (21.5 KB)

Thanks for the report. This appears to be the result of some memory mismanagement. Please let me know if PR #1286 results in the expected behavior.

Jake

Hi Jake,

Thanks for fixing this issue! It works as expected and I’m able to do what I wanted to do with bond/react.

Thanks,
Amulya

Hi,

I encountered another issue when trying to implement what I wanted with fix bond/react.

I would like to change the frequency of the search for reactions in bond/react defined each time in a loop.
Somehow the simulation halts or crashes in the middle of a run. When I set the variable as a constant that does not change value each time the simulation runs correctly.

I’ve attached another modified version of the tiny_nylon example included with LAMMPS. Here I define a python variable freq that will be changed within the loop. The simulation crashes near the end of the first iteration after the initial run.

Since the python variable is accepted in the beginning, and the simulation would run correctly if the value of the variable was inputted directly, I’m not sure why this is not working.

My input file is modifiedin.tiny.nylon and the output is polyout.txt. I’ve also attached the other required files.

I would appreciate any suggestions.

Thanks,
Amulya

polyout.txt (31.6 KB)

modifiedin.tiny_nylon (1.83 KB)

rxn1_stp1_map (200 Bytes)

rxn1_stp2_map (181 Bytes)

rxn1_stp2_reacted.data_template (1.59 KB)

rxn1_stp1_unreacted.data_template (1.98 KB)

rxn1_stp1_reacted.data_template (2.4 KB)

rxn1_stp2_unreacted.data_template (1.97 KB)

tiny_nylon.data (21.5 KB)

Hi Amulya,

Wolfgang Verestek (cc’d) recently made a similar modification to bond/react, which might do what you want. I haven’t been able to carefully look at it yet, but perhaps he’ll be willing to share it with you.

Thanks,

Jake

Thanks Jake.

To clarify I’m not looking for a new implementation of bond/react. I just expected to pass a variable to it but it works sometimes but not all the time.

Looking forward to hearing more about this.

Thanks,
Amulya

Thanks Jake.

To clarify I’m not looking for a new implementation of bond/react. I just expected to pass a variable to it but it works sometimes but not all the time.

please note, that in LAMMPS variables can be used in two different ways:
1) immediate expansion as part of the pre-processing and parsing of
input scripts ${varname}
   this works for everything, since the affected code never gets to
see that there was a variable involved, which means, that this will
retain the value of the variable at the time the input was
pre-processed and parsed.
2) variable references to be expanded anew every time it is references v_varname
   version 2) requires explicit support in the style/command for
variables and thus will only work if it is mentioned in the
corresponding documentation

axel.

Hi Amulya,

Inputting variables for bond/react parameters is currently not supported. However, you may try a lammps’ ‘immediate evaluation’ variable, of the form $(…). Note the parenthesis instead of curly bracket.

Thanks,

Jake

I’m passing a variable into bond_react using the ${varname} way. Varname happens to be a python variable though. I think this is supported by bond/react because it runs fine initially but crashes in the middle of a later run.

Thanks,

Amulya

I’m passing a variable into bond_react using the ${varname} way. Varname happens to be a python variable though. I think this is supported by bond/react because it runs fine initially but crashes in the middle of a later run.

as i've mentioned above, this is a "transparent" and "immediate"
variable expansion. fix bond/react doesn't even know, that it was a
variable, as this variable is expanded during the line-by-line
pre-processing of the input. just check out the log file or add the
-echo both flag to the command line.

now, the interesting question is: what is causing the crash? there
must be error messages there must be some indication of where
something goes wrong. it can be inside the variable evaluation, then
you have to debug what you are doing there, or it can be that you are
passing some invalid result to fix bond/react, or you may just be
doing something that is triggering some other problem. hard to say
from remote.

axel.

I tried (varname) which doesn’t work and (v_varname) which gives me the same result as ${varname} which crashes in the middle of a run. Not sure what to do.

Thanks for your suggestion.

-Amulya

I tried \(varname\) which doesn’t work and (v_varname) which gives me the same result as ${varname} which crashes in the middle of a run. Not sure what to do.

nobody can debug "it crashes" without being a mind reader.
so you have to provide more specific information and/or provide a
(simple/fast) way to reliably reproduce it.

axel.

The short code I attached reproduces the problem.

a quick look at the input you posted at the very beginning of this
thread shows some needless complexity.

there is no need to do the convoluted processing with a python
variable and an equal style variable.

simply use:

variable freq index 10 9 8 7 6 5 4 3 2 1

you put the line:

next freq

when you want to get the next entry from the list.

beyond that, i see one bug with fix bond/react that is corrected by
the following change.

$ git diff
  diff --git a/src/USER-MISC/fix_bond_react.cpp
b/src/USER-MISC/fix_bond_react.cpp
  index e7dc816b8..0ecfc1588 100644
  --- a/src/USER-MISC/fix_bond_react.cpp
  +++ b/src/USER-MISC/fix_bond_react.cpp
  @@ -452,7 +452,7 @@ FixBondReact::~FixBondReact()
       delete [] id_fix3;
     }

  - if (id_fix2 == NULL && modify->nfix) modify->delete_fix(id_fix2);
  + if (id_fix2 && modify->nfix) modify->delete_fix(id_fix2);
     delete [] id_fix2;

     delete [] statted_id;

also, (dynamic) groups created by the fix need to be deleted. i am
attaching the updated input script.
with those changes (and jake's previous bugfix), the simulation can
continue to the end. there *still* is some memory corruption detected
when exiting LAMMPS and all internal data structures are freed, but i
cannot figure out where this is originating and it evades detection by
valgrind's memory checker.

axel.

modifiedin.tiny_nylon (1.74 KB)

FYI, i found another bug in fix bond/react that is exposed by defining
and deleting the fix multiple times.
here is the fix. both bugfixes will be included in PR #1282 and the
next LAMMPS patch release (as well as jake's previous fix).

  diff --git a/src/USER-MISC/fix_bond_react.cpp
b/src/USER-MISC/fix_bond_react.cpp
  index e7dc816b8..9bedb66f3 100644
  --- a/src/USER-MISC/fix_bond_react.cpp
  +++ b/src/USER-MISC/fix_bond_react.cpp
  @@ -379,9 +379,6 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int
narg, char **arg) :

   FixBondReact::~FixBondReact()
   {
  - // unregister callbacks to this fix from Atom class
  - atom->delete_callback(id,0);

I know there is no need for the python variable for the simple example, but for my actual use case I will be going back and forth with the frequency variable with the index dependent on the conversion, not just iterating through the list once.

Thanks for your attention to this. I will try out the corrections.

-Amulya

T

Hi Amulya,

please find attached the files Jacob mentioned. Basically I introduced two more keywords for the react … part of the fix assignment:

  • max_rxn value = maxreactions
    maxreactions = maximum number of reactions (positive integer)
    At the beginning of each time step it is checked if the total number of reactions that occurred for react-ID is smaller than maxreactions. Due to the implementation and to not introduce more communication it is a “soft limit”. This means if in one step maxreactions is exceeded all reactions will take place, but in the next step no additional reactions will happen.

  • the fraction of the prob keyword can be an equal style variable “v_variablename”.

In case you want to give it a try copy the two modified files (fix_bond_react.cpp, fix_bond_react.h) to LAMMPS_DIR/src/USER-MISC and recompile. I also added a short example.

@Jacob/Axel

I used the files from GitHub master branch this morning. As I don’t have a GitHub account yet, feel free to include on GitHub if you think it might be useful for others.

Regards

Wolfgang

fix_bond_react.cpp (109 KB)

fix_bond_react.h (8.16 KB)

patch_bond_react.diff (4.6 KB)

bond_react_minimal_example.tar.gz (6.05 KB)

Hi,

Thank you for this information. I thought this could be really useful. However, I’m having trouble running the bond_react_minimal example you provided.
When I run the example the simulation stalls in the middle at step 70. I have attached my output here. There is no error message and the job does not end, but the simulation does not progress beyond this point. Actually, I was running into a similar issue with my own simulations. I’m not sure what I’m doing differently because I’m sure the simulation is supposed to finish all the way.

Thanks for your guidance.

polyout.txt (6 KB)

Hi,

I’m not shure what is causing this behavior. My initial guess, that it is coming from max_rxn as this should stop any further reactions after 5 reactions have happened for rxn1a_r. Please remove the keyword “max_rxn XXX” from the script and see if it runs through properly. The variable for the probability should not be affected by this.

Nevertheless it would be nice if you could tell me a little bit more about your system, compiler etc.

The two systems I have available for testing both run the code properly.

Regards

Wolfgang

When I run the code without max_rxn it runs properly.

I tried compiling with both an intel compiler and a gnu compiler separately.
Neither setup runs the original code properly.

It may be some issue with my hpc setup, I’m not sure.