Does fix change the energy is the system?

Hello, I am trying to add a new fix, which is similar to fix/wall, to lammps.
I find fix/wall overloads post_force in fix.h, is this function used to compute the forces on atoms (it modifies array f of an atom) ?
However, I can’t find any function computing the energy (the interaction energy between particles and the wall). Maybe the interaction energy is not important, so we don’t need to compute it ?

The Fix::post_force() functions do indeed add forces to the per-atom force arrays, if they so choose. This function is invoked after all forces from Pair, Bond, Angle, Dihedral, Improper, and Kspace classes have been added (if those classes have indeed be instantiated by a corresponding style command).

Tallying the energy contribution from fixes is a bit complicated. Whether this is done or not can be set with the fix_modify energy command. The actual adding of the (total) energy is done in the Modify::energy_global() function, which in turn executes the Fix::compute_scalar() function of the fix. Thus all fixes that do support computing the energy contribution from the fix have to implement the compute_scalar function accordingly. In the case of wall fixes, this is even less obvious, since multiple wall fixes share code in the FixWall base class. The actual fix style (e.g. FixWallHarmonic) store the (per MPI processor) energy in the ewall array at index 0.

Thanks for your explanation.
If I just want to constrain the positions of some atoms, is that ok if I only overload Fix::post_force() and don’t compute the interaction energy bewteen atoms and the wall ?

It is impossible to give specific advice with only such a vague description of what you intend to do.
From your description so far it sounds as if the fix you are writing would not even be needed.
It also sounds like you have not done yet your due diligence and read the LAMMPS paper and studied the information in the Programmer’s guide section of the LAMMPS manual with sufficient care.

What is ok or not is ultimately a decision that you have to make (I am not going to run simulations with your custom version of LAMMPS but you are). All that we can provide is the framework and explanations of the overall design of the program. As mentioned above, you seem to be not sufficiently familiar with it, since your questions suggest that you are making assumptions about how LAMMPS is working that are not correct.

OK, Thanks.
In fact I want to use charge density calculated by VASP to constrain the atoms’ positions. The atoms can’t appear on the place where the charge density is lagre. Fix/wall calculates the interaction energy between particles and wall, but we only need the wall to constrain the atoms, so I wonder whether it’s necessary to calculate the interaction energy.