Dear Everyone:
I write a new fix class for lammps.
in my fix class, what i am dong is simple: Firstly, I need the potential energy of the whole system , so i add a method of post_force() in the fix class
and getting the potential energy like this double potential=pe->compute_scalar()
(of course ,something is done in the setup part of this class)
int icompute=modify->find_compute(“thermo_pe”);
if(icompute <0)
error->all(FLERR,“pe ID for fix its does not exist”);
pe=modify->compute[icompute];
secondly, I changed the force of the system by the number of potential
and I compiled the lammps without any error,
but when I am doing some calculations,
I find that when I use the “thermo 1” in the input file , everything is ok , as I expected
but when I use another number other than 1 ,like “thermo 2”, " thermo 20", lammps exit with error : Energy was not tallied on needed timestep …/compute_pe.cpp:75
I read some information from the Web and this problem seems having some relationship with function modify->clearstep_compute() and addstep_compute() which I didn’t use in my fix class.
but I am still very confused and I don’t know how to fix this problem.
Thank you for any suggestions!
Dear Everyone:
I write a new fix class for lammps.
in my fix class, what i am dong is simple: Firstly, I need the potential energy of the whole system , so i add a method of post_force() in the fix class
and getting the potential energy like this double potential=pe->compute_scalar()
(of course ,something is done in the setup part of this class)
int icompute=modify->find_compute(“thermo_pe”);
if(icompute <0)
error->all(FLERR,“pe ID for fix its does not exist”);
pe=modify->compute[icompute];
secondly, I changed the force of the system by the number of potential
and I compiled the lammps without any error,
but when I am doing some calculations,
I find that when I use the “thermo 1” in the input file , everything is ok , as I expected
but when I use another number other than 1 ,like “thermo 2”, " thermo 20", lammps exit with error : Energy was not tallied on needed timestep …/compute_pe.cpp:75
I read some information from the Web and this problem seems having some relationship with function modify->clearstep_compute() and addstep_compute() which I didn’t use in my fix class.
but I am still very confused and I don’t know how to fix this problem.
The pe->compute_scalar() call can only compute the total potential energy, if that information has been collected during the force computation
, i.e. before your fix is called. thus you need to add pe->addstep(update->ntimestep+1) at the end of your post_force() and setup() methods, so that the collection of potential energy is triggered at the next force computation. there is no need of using pe->clearstep(), this is only required, if you want to force the recomputation of the compute, but that would only work, if the compute style is completely self-contained.
With thermo 1
the energy collection is always enabled and thus
youdon’t
get the error.
axel.
Thank you Axel, my fix class works now.
But I have an additional question: if I have two fix classes in my simulation, both of which require the potential energy(or temperature)
of the system at the same state. How to avoid use the pe-> compute_scalar() twice?
or what is in the lammps already takes care of this problem?
thank you again for your reply.
Geng Sun
Thank you Axel, my fix class works now.
But I have an additional question: if I have two fix classes in my
simulation, both of which require the potential energy(or temperature)
of the system at the same state. How to avoid use the pe->
compute_scalar() twice?
why would you need to do that?
or what is in the lammps already takes care of this problem?
the explanation is in my previous answer.
axel.