Error while new fix compilation- Doesnt give a type

​Hi Lammps users,

I have written a new fix for my use, and while compiling the LAMMPS source code, I am getting an error which says, ‘FixTest (name of my fix) doesnt give a type’. What could be the error due to?

The error ​points at below

FixTest::FixTest(LAMMPS *lmp, int narg, char **arg) : PairLJCut(lmp, narg, arg)

^

Thanks,

Peetak

Is your FixTest a derived class of the class PairLJCut? Most likely not…

I want it to be a derived class because I wish to use some values defined within it to be used in the fix. Can I not define it like that? Is there a problem with my definition?

No. You must have defined it as a Fix class in your header file – so it cannot be a derived class of a Pair class.

What is it that you wish to do with your FixTest? There are many examples on how a fix class can access data from a pair class: one being fix_adapt.cpp

Okay. Thanks for correcting my mistake.

Yes, I wish to do exactly that. So to access data from pair_lj_cut.cpp I should use the pair class in the following way-matrix being the new pointer storing per atom information in pair_lj_cut.cpp file.

Based on the example in fix_adapt.cpp

double *ad;
void *ptr = ad->pair->extract(ad->matrix);

Should this work out?

Okay. Thanks for correcting my mistake.

Yes, I wish to do exactly that. So to access data from pair_lj_cut.cpp I
should use the pair class in the following way-*matrix* being the new
pointer storing per atom information in pair_lj_cut.cpp file.

Based on the example in fix_adapt.cpp

double *ad;
void *ptr = ad->pair->extract(ad->matrix);

Should this work out?

​no. this look as blatantly wrong as your previous line of code.
where did you learn C++ programming? and reading C++ code?

ad *has* to be some king of struct (or class) and the Pair::extract()
prototype requires two arguments, one C-style string and an integer.
also, this cannot work without programming the corresponding functionality
into the pair style.

my recommendation to you is: find somebody that actually *can* read and
program C++ code and collaborate with this person about getting this
feature implemented. but also show this person previous recommendations
from the list about how to do what you are interested in, because your
approach is obvious the worst of the suggested choices.

axel.

Hey,

you're trying to dereference a double* named ad and
access something termed 'matrix' - why should this work?

What do you mean by "*this* should work out"?
You can compile & run your code on your machine
for testing purposes, right?

Best,
S.

Hi Axel,

I am working on this project. I had a question based on your reply which is as follows.

I am modifying the fix_adapt.cpp file as below.

In FixAdapt::setmask(), I have set the mask to POST_FORCE() because I wish to extract the values pairwise force calculations. I have declared another instance of the class FixAdapt::setup_post_force(int vflag) and used the extract function with two arguments, string and integer. I have declared setup_post_force in the header file for fix adapt.

I also went to pair_lj_cut.cpp and under the PairLJCut::extract class, declared another if condition for a string to return a pointer value.

The idea is to call for the fix adapt function from the input file so that I can check if the value of the pointer from pair_lj_cut is being indeed extracted. I have some print commands to that effect to check if the code indeed goes into the required loops.

Will this be an acceptable approach in going ahead with the implementation?

Hi Axel,

I am working on this project. I had a question based on your reply which
is as follows.

I am modifying the fix_adapt.cpp file as below.

​why modify fix adapt? why not simply write a new fix that does *only* what
you want to do?

In FixAdapt::setmask(), I have set the mask to POST_FORCE() because I wish

to extract the values pairwise force calculations. I have declared another
instance of the class FixAdapt::setup_post_force(int vflag) and used the
extract function with two arguments, string and integer. I have declared
setup_post_force in the header file for fix adapt.

I also went to pair_lj_cut.cpp and under the PairLJCut::extract class,
declared another if condition for a string to return a pointer value.

The idea is to call for the fix adapt function from the input file so that
I can check if the value of the pointer from pair_lj_cut is being indeed
extracted. I have some print commands to that effect to check if the code
indeed goes into the required loops.

​this sounds confused and as if you still don't have a sufficient
understand​ing of how LAMMPS works internally.

Will this be an acceptable approach in going ahead with the implementation?

​you may be able to make it work, but what you describe is a very ugly and
hackish approach. you may get it to work, but don't expect any love or
support from people like me, that already have to spend too much of their
time cleaning up such hackish and ill-designed code.

i think that, both, steve and i have recommended to rather write a compute
similar to those in the USER-TALLY package, as that would transparently
generate a callback into the pairwise force loop and would automatically
work without modifying any existing pair style codes and be compatible with
most pairwise additive potentials out of the box.

​the choice of what is acceptable to you is yours. one of the reasons why
LAMMPS is open source is to give you that choice​, but have to accept that
others have the same choice in who to help with modifying such a package.
you still got infinitely more than what you paid for. :wink:

axel.

Hi Axel,

I agree with you. This approach isnt quite working out very well. Even though I can get the pair-wise interaction values extracted, I have to do some velocity scaling on it- which will become more difficult with the current approach.

I will try and understand USER-TALLY packages and try to write a new similar- compute method as you suggested.

Thanks for your thoughts,

Dev