Accessing the particles_were_in_contact var from outside of surface_model

Submitted by Thorsager on Thu, 12/02/2021 - 14:47

Hi,
In essence I want to create a LIGGGHTS fix for superquadric collision diagnostics. And to do that I would like to access the stored enum that is set in surface_model_superquadric.h which details if particles were in contact last iteration.
This is to avoid doing the intersection check again, as that is both unnecessary to do twice and computationally expensive.

This value is however accessed through the contact_history with the help of an offset which is private. And while there are tags stored in pair_gran.history_arg it is protected, and I could not find any method to access the corresponding offset.
So I made one which works:
//"in pair_gran.h"
int get_history_offset(std::string name, std::string newtonflag)
{
for (int i = 0; i < history_arg.size(); ++i)
{
if (!history_arg[i].name.compare(name))
if (!history_arg[i].newtonflag.compare(newtonflag))
return i;
}
return -1;
}

Only it would feel better if I did not have to modify any existing source file, and that the lack of this functionality might be intentional? Or that it should be implemented in some other way, or that it already exists in some other form which I have missed.

Either way it would be nice with some confirmation or guidance on how to approach this in the best way?

Cheers,
Thorsager

Daniel Queteschiner | Thu, 12/02/2021 - 17:56

I had to access contact history as well when I was implementing a particle replacement model for fragmentation and I came up with basically the same solution:
particle-particle:
https://github.com/ParticulateFlow/LIGGGHTS-PFM/blob/master/src/pair_gra...
particle-wall:
https://github.com/ParticulateFlow/LIGGGHTS-PFM/blob/master/src/fix_wall...

getting the index in the Fix::init() method:
https://github.com/ParticulateFlow/LIGGGHTS-PFM/blob/master/src/fix_brea...
using it for instance in Fix::preforce() to set some history values:
https://github.com/ParticulateFlow/LIGGGHTS-PFM/blob/master/src/fix_brea...
or in Fix::end_of_step() to get some values:
https://github.com/ParticulateFlow/LIGGGHTS-PFM/blob/master/src/fix_brea...