i use velocity all create 700.0 1245 dist gaussian command in my script. To understand how to create velocity of atom, i read lammps/src/velocity.cpp file in source code.
the code in row 596 is double t = temperature->compute_scalar();.I want to ask which function is called by the compute_scalar method. is it compute_scalar() function in lammps/src/compute_temp.cpp?
It may be that one, it does not have to be. The temperature pointer hold a pointer to a Compute class instance. That can be changed with fix_modify. This is C++ polymorphism at work.
if yes. there is a bug here. the create algorithm is based on formula as follow:
\frac{1}{2} mv^2 = \frac{N_{dof}}{2} kT
where k is boltzman constant and T is temperature.
In lines 232, pointer v points to v in atom variable.
The code from lines 275 to 283 shows the generation of the v variable and multiplies it by a variable in lines 287. So v_{new} = \frac{1}{\sqrt{mass}} v
If i set momentum_flag and rotation_flag to false, the code will not execute zero_momentum and zero_rotation function.
if compute_scalar() in lammps/src/velocity.cpp is equal to compute_scalar() in lammps/src/compute_temp.cpp, then
t = (\frac{1}{\sqrt{mass}} v)^2 * mass * tfactor \\
= v^2 * tfactor
where tfactor = force->mvv2e / (dof * force->boltz);. there is something weird here right?
Not at all. The first part of the loop creates a distribution assuming that all masses are equal, the second part adjusts for different atom masses and resets the atom velocities for atoms in the selected group.
For this distribution now the temperature is computed according to the selected temperature compute style and then the velocities rescaled to yield the target temperature for the selected temperature compute style.
This is what the documentation says it does and I donât see a bug here.
If you still believe there is a bug, you need to provide better proof.
Ok. actually, I think the problem lies in \frac{1}{\sqrt{mass}} and rescale function.
According to \frac{1}{2} mv^2 = \frac{N_{dof}}{2} kT
T = \frac{mv^2}{N_{dof} k} = mv^2\ *\ tfactor
and
v = \sqrt {\frac{N_{dof} kT}{m}} = \sqrt {\frac{T}{m\ *\ tfactor}}
where tfactor = force->mvv2e / (dof * force->boltz)
The rescale() function may rescale v based on equation v = \sqrt {\frac{N_{dof} kT}{m}}. And compute_scalar function in lammps/src/compute_temp.cpp compute temperature T based on T = \frac{mv^2}{N_{dof} k}.
according to the 4th point i mentioned above, t shoud be equal to
The rescale function does not use compute_scalar but the square of the ratio between the temperatures. tfactor is essentially an internal dimension conversion factor that ensures units consistency when computing temperature so that it returns kelvins. It is only to consider in compute_temp and does not come into play in velocity. As far as I can see, the computation of velocity distributions is sound.
Note that you are mixing two things here. On the one hand the computation of the instantaneous temperature that aggregates all the m_iv_i^2 values into one quantity, on the other hand, the scaling of a distribution by a factor \sqrt{\frac{N_dkT}{m_i}} for each element i. These are two different things that are not directly related.
thank you and Mr.akohlmey very very much. you help me a lot.
I also want to ask if dist=gaussian, What are the gaussian distributions of mean and variance for velocity when sum=no, mom=yes, rot=no, bias=no, loop=all, and units=real? or could you give me a formula? Because the document only mentions mean as 0, but does not provide a specific formula for calculating variance, and for some reasons, I need to know what the variance of velocity is.
finally, i thank you and Mr.akohlmey very very much again.
You can work this out for yourself with almost zero calculation time: set up a system of atoms (LAMMPS may have some âargonâ examples in the example folder), give it a velocity command with various options, and print out the velocities into a data file using save_data. You will then have all the velocities to process for any observable quantity of interest. This is more reliable than relying on people on the Internet.
Most of the keywords you cite are not related to the computation of the distribution.
The initial gaussian distribution is zero centered with a standard deviation of 1 and scaled according to what has already been said above as for the uniform distribution.
As @srtee said, the best way to find out what is happening is to play around with the code.
This is one of the worst phrases you can use in an online forum. Either there is a good reason, then you should name it because other otherwise you deny people important background information, or there isnât and then it needs not to be mentioned.
It is pretty much pointless to worry about the details of the initial velocity distribution of an MD simulation because it will re-balance and re-equilibrate instantly as the system is equilibrating (whatever distribution or temperature you apply, it wonât be in equilibrium with the positions, so there will be equilbration) and meaningful data can really only be obtained after the system has properly equilibrated.
After all of this discussion, I am seriously concerned that you are investing a lot of energy into some minor detail that has very little practical impact and meaning.