if command

Submitted by clarence91 on Tue, 04/14/2015 - 23:46

Hi,

I am trying to use IF command and I getting this error "ERROR: Unknown command: { (../input.cpp:293) "
if "${typ1atoms} == 0.0" then { variable velcity1 equal 0.0 }

Can anyone please help me?

Thank you.

clarence91 | Wed, 04/15/2015 - 19:47

Thanks a lot for the reply.
Error has been fixed but new issue again. I am using something like this.

variable natoms1 equal count(nve_group,eff)
compute velavg all reduce/region eff sum c_vel1
if "${natoms1} == 0.0" then "variable vtt equal 0.0" else "variable vtt equal (c_velavg/v_natoms1)"

I find the value of "vtt" is always 0 even if (natoms1 != 0).

clarence91 | Wed, 04/15/2015 - 21:38

it should actually be:

variable natoms1 equal count(nve_group,eff)
compute vel1 typ1 property/atom vy
compute velavg all reduce/region eff sum c_vel1
if "${natoms1} == 0.0" then "variable vtt equal 0.0" else "variable vtt equal (c_velavg/v_natoms1)"

I am writing the values to a file:
fix v_ave all print 1 "${t} ${natoms1} ${vtt}" file vt

Please help.
Thank you.

richti83's picture

richti83 | Wed, 04/15/2015 - 22:10

the if command is only executed once. You can use the run every function to periodically check the if condition. but this leads you to a dangling quotation mark problem which I never solved.
Can you explain what you want to achieve, maybe there is a simplier solution.

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

clarence91 | Wed, 04/15/2015 - 23:23

1) I just want to count the number of particles in a specified region based on their types (this task is done.)
2) Define "compute" command with the type of particles in the confined region to know there properties such as velocity, charge etc. and find the average charge or velocity of all the particles based on types.
Actually I was successful with this issue if I consider the whole geometry since number of particles were always >0 whereas if I am talking about some particular region(just above the outlet) then number of particles = 0 initially.

If I am not clear please let me know.
Thank you.

K.cheng | Thu, 04/16/2015 - 04:44

Hi
Maybe you can try to use " compute reduce/region ave "

clarence91 | Thu, 04/16/2015 - 08:00

Hello Cheng,

Thanks for your suggestion.
I am not sure about using "ave" with my case since I have two different type of particles(# of particles in each type might not be same all the time) and I have to calculate the average for each type individually.

Hope you understand, what I mentioned.

richti83's picture

richti83 | Thu, 04/16/2015 - 08:26

You can create a group by type and than use count group. To regroup use the run N every i function when you are inserting over runtime, otherwise the new particles will not be added to group A/B/.

group A type 1
group B type 2
variale n1r1 equal count(A,reg1)
variale n2r1 equal count(B,reg1)
fix output all print 1 "${n1r1},${n2r1}" screen no file counts.txt title "n1r1,n2r1"
run 100000 pre no post no every 10 "group A type 1" &
"group B type 2"

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

clarence91 | Thu, 04/16/2015 - 17:03

Counting particles by type in a region is already fixed, I have no more problems with it.

I am trying hard to calculate the average velocity/charge of particles by type in a region.

clarence91 | Thu, 04/16/2015 - 18:47

Instead of calculating the average using liggghts.
I can post-process in matlab or some other tools.
All I did is, I am writing #.of particles and their properties for each timestep in a new file.

Thanks for your suggestions guys.