Adding a new per atom variable in the source code

Dear all,

I’d like to add a new per atom property (vector or scalar) to lammps I can read/write to it via the atom->“myNewVariable” pointer and dump it via the dump/custom. If possible I’d look to add it to the source code and access it through the c library interface.

I’ve seen this come by in a few presentation slides on the web but I’m not sure how to proceed.

Can I just append it to the compute_property_atom and dump/custom files or do I need to do more. Sorry if this has already has been posted in the list. I’ve tried several search queries but haven’t found the answer I’m looking for.

Thanks in advance for your help.

Kind regards,

Victor Koppejan

Dear all,

I'd like to add a new per atom property (vector or scalar) to lammps I
can read/write to it via the atom->"myNewVariable" pointer and dump it via
the dump/custom. If possible I'd look to add it to the source code and
access it through the c library interface.

I've seen this come by in a few presentation slides on the web but I'm not
sure how to proceed.

Can I just append it to the compute_property_atom and dump/custom files or
do I need to do more. Sorry if this has already has been posted in the
list. I've tried several search queries but haven't found the answer I'm
looking for.

before changing the source code (you would have to create a new atom style
and make corresponding changes to the atom class), you should try using fix
property/atom instead, which can add arbitrary per atom variables. you can
look them up with atom->find_custom()

but perhaps you should first give some more explanation about what you are
trying to achieve. many times in the past, where people have asked for
similar things, fix proper/atom turned out to be overkill and other,
simpler approaches would be preferable.

​axel.​

Dear Axel,

Thanks for the reply. Pardon me not replying in the same style, I can’t change my webmail interface to do so.

I’ve got using lammps as a shared lib which is called from openfoam. Kinda like CFDEM-LIGGGHTS but with the perks of modern lammps features such as mpi load balancing and openmp threading (kudos for creating that, it helps me a lot in optimizing MPI communication).

I want to pass information from openfoam to lammps (interpolated field values, velocity, pressure gradient etc) and save them in a lammps dump file using dump/custom. The idea here is I can use the lammps parallel IO when running on 100+ mpi ranks.

At the moment I have a fix that applies fluid forces such as drag, virtual mass force and others to the particles and this works ok. All the variables are transferred through additional library functions.

The options I see now are

  • Making a new atom style which include the desired properties (but let’s try to avoid that)
  • Setting up the variables in the lammps input script (easy but error prone, I’d prefer the next option)
  • Sending commands to lammps from OpenFOAM via the lammps_command function to create vars and use the find_custom() you mentioned

The reason I like the last option is it allows me to automate the the creation of new vars, dump file content and freq on the openfoam side.

If you have any other ideas I’d love to hear them.

For the future (ie coming years) I think I’ll switch to a python based PDE solver and use one of the python interfaces to lammps. For now I’d like to finish what I’ve done so far and use it for my remaining compute budget on the cluster.

Regards,

Victor

Dear Axel,

Thanks for the reply. Pardon me not replying in the same style, I can't
change my webmail interface to do so.

I've got using lammps as a shared lib which is called from openfoam. Kinda
like CFDEM-LIGGGHTS but with the perks of modern lammps features such as
mpi load balancing and openmp threading (kudos for creating that, it helps
me a lot in optimizing MPI communication).

I want to pass information from openfoam to lammps (interpolated field
values, velocity, pressure gradient etc) and save them in a lammps dump
file using dump/custom. The idea here is I can use the lammps parallel IO
when running on 100+ mpi ranks.

At the moment I have a fix that applies fluid forces such as drag, virtual
mass force and others to the particles and this works ok. All the variables
are transferred through additional library functions.

The options I see now are

- Making a new atom style which include the desired properties (but let's
try to avoid that)
- Setting up the variables in the lammps input script (easy but error
prone, I'd prefer the next option)
- Sending commands to lammps from OpenFOAM via the lammps_command function
to create vars and use the find_custom() you mentioned

The reason I like the last option is it allows me to automate the the
creation of new vars, dump file content and freq on the openfoam side.

If you have any other ideas I'd love to hear them.

​if you have the data already available in your custom fix, you can just
expose it from the fix directly.
if you set the following flags in the fix constructor:

peratom_flag = 1;
size_peratom_cols = nvalues;

​with nvalues being the number of custom values per atom. then ​you just
need to allocate and fill the Fix::array array with the suitable data and
you are done.
now you can access all that data in dumps via f_ID[1], f_ID[2], f_ID[3],
etc. or simply f_ID[*] for all of them.

have a look at, for example, fix_ave_atom.cpp, which acquires all kinds of
per-atom data from computes, fixes, and variables, averages them and
exposes them to dumps with the same interface. if you strip out the parts
where the data is retrieved, it is fairly simple to follow. in your case,
you may not even need the parts where the averaged data is migrated between
processors with the atoms, just ensure that Fix::array is properly resized
as needed and then copy over the data.

​axel.​