A question about the variable reading

Hello, everyone. I have a question about the variable reading as following: If there is a variable corrdnated with timestep and contained in the fix command, during the runtime, would LAMMPS update the variable and fix command to continue or keep the initial data running till the final timestep?

This is too vague a question to answer. Please provide a specific example.

LAMMPS has variable expansion (which happens during parsing of the input and is invisible to commands) and variable references which will trigger evaluation of the variable when used. This gets even more complicated when variables use results from other variables, which can - again - be done in either way and thus have a different outcome.

1 Like

Thanks @akohlmey . And this is a part of my codes, maybe it could be helpful to figure out my qustion:

variable time equal time
variable indensity equal sin(2PIv_time)
fix 0 top conp 100 bottom 1.979 ${indensity} log_conp etypes 1 4 ffield

I difined a time-correlated variable ‘indensity’ and cite it in the fix command in the lines. Initially, I wander whether the fix command will update itself during the running time. Having seen your answer, I think the fix command could update and apply to LAMMPS along with the changes of ‘indensity’.

You quoted text doesn’t render correctly. Does it read correctly for you?

Please read and follow the guidelines posted here: Please Read This First: Guidelines and Suggestions for posting LAMMPS questions

1 Like

I’m sorry for disturbing you with the trifles, this is the code with correct format:

variable time equal time
variable indensity equal sin(2*PI*v_time)
fix 0 tw conp 100 bw 1.979 ${indensity} log_conp etypes 1 4 ffield

Thank you again, sincerely.

You are using a “variable substitution” here, i.e. ${indensity}. As mentioned before and documented in the manual, your fix conp command never gets to “see” that there is a variable. Instead the variable is substituted during input processing with the value of the variable at the time (i.e. probably 0).

To have access to the changing value of a variable during a run, a command has to be programmed to support this and accept a variable reference, i.e. “v_name” instead of “${name}”. Whether a command or style accepts variables for certain arguments is documented in the respective documentation page. If there is no mention, it is not supported. In some cases, e.g. pair_coeff, bond_coeff etc. the variable change requires even more effort and you need to use fix adapt (for fix adapt/fep).

1 Like

Thank for your patient and comprehensive answer, it contributes a lot to me. Your earnest attitude and straightaway words makes up an important part of this community. As a LAMMPS beginners, I really appriciate for all your works on this, and have the utmost respect for you. :handshake: