Conditional Statment

Hello Everyone.

I’m trying to use an if-condition to check for a variable that is updated with the number of steps (i.e A new value each step) but the if command only accepts a constant value to evaluate the Boolean condition. I’m aware of the fix halt command but I do not want to interrupt the run and continue it. Is there is a way to do this ? or a way to update the variable itself inside the if condition but still define it inside the condition statement using “${}” since it does not accept “v_”.

Regards

Hello,

Here’s a similar discussion

https://lammps.sandia.gov/threads/msg45037.html

Your description makes no sense. So I suspect that you are misunderstanding how the if command works and how it is applied.

Can you provide a more detailed description of what you are trying to achieve and how you expect it to work?

Axel

But that is about a case that fix halt is supposed to replace in a more flexible and efficient way.
Axel

I’ve one Sample that is moving with a specified velocity and my aim is to output a data file when it crosses special locations in the simulation box. I use the bound(Sample,xmin) variable to get the sample xmin dimension and the condition should be when xmin = some defined location.

The if statement does not check for the condition every N steps. It reads the first “xmin” only. So, I’m trying to find a way to make a conditional-every N step check.

The fix halt command would do it absolutely. However, I want to capture the whole process in a movie and using fix halt will exit the run and therefore the rendering.
Another concern is the second run command to continue the simulation, will it start from where the latest position of the sample ?

Regards, Apologies if the explanation was not enough. I try to save words so I do not waste the time of the researchers trying to help :slight_smile:

I’ve one Sample that is moving with a specified velocity and my aim is to output a data file when it crosses special locations in the simulation box. I use the bound(Sample,xmin) variable to get the sample xmin dimension and the condition should be when xmin = some defined location.

The if statement does not check for the condition every N steps. It reads the first “xmin” only. So, I’m trying to find a way to make a conditional-every N step check.

as I suspected, the main issue is that you don’t understand the processing of the LAMMPS input script. Like a programming language it is evaluated line by line. So the if statement only applies immediately. all *_style commands as well as dump, compute, fix, region, group will create/replace internally a C++ class instance that will then be referred to or executed during a run or minimize or similar command. you have three options to have actions happening during a run: use the every option to the run command (which will break down the run into even sized chunks and run them individually) or use the fix python/invoke to regularly invoke python command or use the fix halt command to stop the run, do some commands and then continue using the “start and stop or upto options”. python function can issue LAMMPS commands through the python wrapper of the library interface, but commands are disallowed during a run since they often require operations that reinitialize the state of the system, which must not happen during a run.

The fix halt command would do it absolutely. However, I want to capture the whole process in a movie and using fix halt will exit the run and therefore the rendering.

that is not correct. a dump style will hold the file stream open until you issue an undump command or the simulation exits completely and all class instances are deleted.

Another concern is the second run command to continue the simulation, will it start from where the latest position of the sample ?

yes, it will continue as is. if you don’t do any “disruptive” changes, you can use the “pre no” option to run to avoid a full initialization and an additional force evaluation.
in combination with the “upto” and “start/stop” keywords, a run can continue without disruption. please study the details in the run command documentation.

Regards, Apologies if the explanation was not enough. I try to save words so I do not waste the time of the researchers trying to help :slight_smile:

sorry, but that is not helping. quite the contrary. if you provide too much information or too many details, it is easy and fast to skip over them. having to speculate and trying to figure out what is going on with limited information and having to play 20 questions to find out the real reason and the motivation is about the most annoying thing when responding to mailing list e-mails. after many years, one can often guess what is going on, but never say with certainty.

in short, when posting to the list with questions about how to operate/use a command or a command not performing as expected also provide the following:

  • which LAMMPS version is used (or even better the output of ./lmp -h from the top to the “List of individual style options included…” line.
  • what platform/OS this is being run on and what the command line for running LAMMPS is
  • a minimal input example that reproduces the issue quickly and without requiring many resources (best modifications made to an existing example of the LAMMPS distribution, so only the modified input file needs to be provided)
  • parts the output of that example run where things don’t behave as documented or expected

a more comprehensive list of suggestions for posting to the mailing list is here: https://lammps.sandia.gov/guidelines.html

Axel.