Is there a way to determine the total number of multispheres in a simulation? The compute multisphere can provide properties (xcm, vcm, etc.), but it does not give a total count. I am running LIGGGHTS through the Python interface in parallel, and I need to know how many multispheres there are locally on each processor. In library.cpp, there are the lines to access total atoms and local atoms -
if (strcmp(name,"natoms") == 0) return (void *) &lmp->atom->natoms;
if (strcmp(name,"nlocal") == 0) return (void *) &lmp->atom->nlocal;
Is there a similar command that I can add that would give me these same values for multispheres? I suppose compute multisphere could alternatively be changed to include a count property.
My bigger issue is knowing the size of the vectors or arrays I get in Python when I use lig.extract_compute. Say I want to loop through all x locations of multispheres. In parallel, I have no way of knowing how many multispheres are on each processor at any given time. In the code snippets below, I just assume I have 10 multispheres and assign those values to my numpy array x. How can I determine what the value of 10 really should be so that I loop through all multispheres on the processor? This value also changes throughout the simulation as multispheres migrate across processors.
LIGGGHTS scripts line:
compute mx all multisphere property xcm
Python script lines:
x = np.zeros(10)
xcm = lig.extract_compute("mx",2,2)
for j in range(0,10):
x[j] = xcm[j][0]
Thanks!
Daniel Queteschiner | Thu, 10/21/2021 - 11:59
FixMultisphere::n_body()
I would add smth. similar to
https://github.com/CFDEMproject/LIGGGHTS-PUBLIC/blob/master/src/library_...
but instead of
return fix_ms->ntypes();
call
return fix_ms->n_body();
for the local number of multisphere bodies or
return fix_ms->n_body_all();
for the global number of multisphere bodies
RonMexico | Thu, 10/21/2021 - 19:58
Solution
Great suggestion. To close the loop on the thread, here is what I did -
In library.cpp I added
int lammps_nbody_ms(void *ptr, const char *name)
{
LAMMPS *lmp = (LAMMPS *) ptr;
FixMultisphere *fix_ms = static_cast(lmp->modify->find_fix_style("multisphere",0));
if(!fix_ms) return 0;
if (strcmp(name,"nbody") == 0) return fix_ms->n_body();
if (strcmp(name,"nbody_all") == 0) return fix_ms->n_body_all();
return 0;
}
In library.h I added
int lammps_nbody_ms(void *, const char *);
In liggghts.py I added
def nbody_ms(self,name):
if self.pyVersion[0] == 3:
name = name.encode()
return self.lib.lammps_nbody_ms(self.lmp,name)