adding/declaring arrays

Hi Lammps users,

Sort of a dumb question, but I'm struggling with adding two arrays to
pair_tersoff. I need to add a 1d-integer array of length [inum] and a
2d-integer array of [inum][12]. I called these nc and nn.

I tried to use the create_2d_int_array() function and also tried to make
my own create_1d_int_array() but I get errors when trying to recompile. I
think I must be missing something very obvious in the variable
declaration. My background is in fortran so figuring out the memory
management has been a bit of a challenge.

Do I need to add these variables to tersoff.h?

pair_tersoff.cpp: In destructor �virtual
LAMMPS_NS::PairTersoff::~PairTersoff()�:
pair_tersoff.cpp:71: error: �nc� was not declared in this scope
pair_tersoff.cpp:72: error: �nn� was not declared in this scope
pair_tersoff.cpp: In member function �virtual void
LAMMPS_NS::PairTersoff::compute(int, int)�:
pair_tersoff.cpp:134: error: invalid types �int*[double]� for array subscript

Any advice would be greatly appreciated!
Best,
John

hi john,

Hi Lammps users,

Sort of a dumb question, but I'm struggling with adding two arrays to
pair_tersoff. I need to add a 1d-integer array of length [inum] and a
2d-integer array of [inum][12]. I called these nc and nn.

I tried to use the create_2d_int_array() function and also tried to make
my own create_1d_int_array() but I get errors when trying to recompile. I

either you are using an outdated version of lammps
or you didn't see that those methods don't exist.

think I must be missing something very obvious in the variable
declaration. My background is in fortran so figuring out the memory
management has been a bit of a challenge.

sorry, but some basic understanding of c++ is essential if you want to
implement something that is more than just changing a formula.
the memory class in lammps is convenient but thus very different
from what is done elsewhere.

Do I need to add these variables to tersoff.h?

you never, _ever_, modify original files in LAMMPS.
if you want to write a different version of tersoff, then
you need to generate a new class. that can be a copy
or tersoff or a class that is derived from the tersoff class
and then replaces whatever methods are different.

any, hack and forget kind of approach will end in disaster.

pair_tersoff.cpp: In destructor ‘virtual
LAMMPS_NS::PairTersoff::~PairTersoff()’:
pair_tersoff.cpp:71: error: ‘nc’ was not declared in this scope
pair_tersoff.cpp:72: error: ‘nn’ was not declared in this scope

the error says what is wrong. if you want pointer variables
to be accessible from inside all of the methods of a class,
they have to be class members. preferably private.

pair_tersoff.cpp: In member function ‘virtual void
LAMMPS_NS::PairTersoff::compute(int, int)’:
pair_tersoff.cpp:134: error: invalid types ‘int*[double]’ for array subscript

ouch. this is a big blunder. you must not use a floating
point variable as array index.

cheers,
    axel.