help in lammps

Dear Dr Axel
thanks for reply,
about your 7th answer : my y and z component of electric field will get undefined when y and z become both zero .there are some terms like y/sqrt(y^2+ z^2) and I want to put them equal to zeros.that’s my problem how to avoid them become zero.

Any help would be appreciated.

Best

I want to define an electric field consisted of two parts:
variable p2 atom “y^2+z^2”
if "p2 = 0 " then “fix h a efield v_Ex 0 0”
else &
“fix h a efield v_Ex v_Ey v_Ez”
so I have two different fields,I already know that I can’t use v_x in if command and it should be as $x but I can’t use $x in atom style

​this is wrong ​and confusing on so many levels, i don’t really know where to begin:

on ‘if “p2 = 0”’ :

  1. “=” is not for comparing equality, “==” is.

  2. you are comparing strings, p2 is not referring to the p2 variable

  3. it is a very bad idea to compare floating point numbers (which is what v_p2 would evaluate to) for equality due to the idiosyncrasies of floating point math

  4. the if statement is a global comparison that is only evaluated when the input line is processed, so it doesn’t make sense to use a variable that may change later

  5. the purpose of the if statement is apparently, apply one fix definition to all atoms when the condition is true and the other fix to atoms when the condition is false. that is not how LAMMPS works. the fix commands creates a global instance of the fix. you can select which atoms it applies to via groups. using the if statement this way is against the entire logic of LAMMPS scripting.

  6. this is implied in the previous point, but it makes not sense at all to use an atom style variable in a global context.

on using two different fields:

  1. it is not clear whether you want to decide which atoms to assign the two fields dynamically during the run or is this a one time choice. the latter case is easy to handle: define two groups, define two fixes each working on one of the two groups. the former case is a bad idea. you’ll having a step function in the force which will result in all kinds of artefacts, e.g. density anomalies around the singularity.

​8) of course, if you absolutely insist, you can implement this kind of thing in LAMMPS, and you only need one fix for it, as you can use boolean expressions in atom and equal style variables​. they will evaluate to either 0.0 or 1.0 depending on whether the expression is false or true. so just multiplying an optional component with the boolean expression with turn it on or off automatically.

​on “$x vs v_x”:

  1. i honestly don’t understand what you mean by this, but since you have pretty much misunderstood everything else related to what you quoted as script code, it is safe to assume that you are misunderstanding something here as well.​

pls help me.

​you have to help yourself first. and a lot. ​from what you present, you have to reread the documentation with much more care and revisit all the details that you have misunderstood. you obviously are trying something that is far too advanced for you level of understanding. that is bound to send you on the road to frustration, confusion and ultimately doom.

axel.

Dear Dr Axel
thanks for reply,
about your 7th answer : my y and z component of electric field will get
undefined when y and z become both zero .there are some terms like
y/sqrt(y^2+ z^2) and I want to put them equal to zeros.that's my problem
how to avoid them become zero.

this is trivial to do.​ ​just add a very small number, e.g. 1.0e-100​, to
the denominator.

axel.