Macro definition in Modify.cpp

Dear all,

I’m trying to find out the implementation of commands in input script. Here is the macros defined in Modify.cpp file, add_fix():

#define FIX_CLASS
#define FixStyle(key,Class)
fix_creators[#key] = &create_fix_instance;
#include “style_fix.h”
#undef FixStyle
#undef FIX_CLASS

My understanding is that all the fix derived classes are defined here since we can replace #include ‘style_fix.h’ with codes in other relevant files. Am I right? Then what will happen with the FixStyle(key, Class) definition? How does it work? Can someone help me out? Thanks

Dear all,

I'm trying to find out the implementation of commands in input script. Here
is the macros defined in Modify.cpp file, add_fix():

#define FIX_CLASS
#define FixStyle(key,Class) \
  fix_creators[#key] = &create_fix_instance<Class>;
#include "style_fix.h"
#undef FixStyle
#undef FIX_CLASS

My understanding is that all the fix derived classes are defined here since

"defined" is not the correct term. this macro in combination with the
style_fix.h file will generate an if/else cascade that allows to match
a keyword against the list of available keywords and then trigger the
*instantiation* of a class (or some other action).
the style_fix.h file is automatically updated during the compilation
procedure to include all fix style definitions that are "installed".
the actuall *definition* of the individual styles is in their
respective header files.

we can replace #include 'style_fix.h' with codes in other relevant files. Am

what do you mean by replace?

I right? Then what will happen with the FixStyle(key, Class) definition? How
does it work? Can someone help me out? Thanks

have you read the developer's guide? if you read the "how to modify
LAMMPS" part of the manual, the developer's guide and know C/C++, it
should be fairly self evident. it seems to me, that you are not really
looking at the code, but are just guessing and that your guess is not
correct.

a simple way to see what is happening would be to just run the
preprocessor for this piece of code and look at the resulting output
whre this piece of code:

  // fill map with fixes listed in style_fix.h

  fix_map = new std::map<std::string,FixCreator>();

#define FIX_CLASS
#define FixStyle(key,Class) \
  (*fix_map)[#key] = &fix_creator<Class>;
#include "style_fix.h"
#undef FixStyle
#undef FIX_CLASS

turns into this code:

  fix_map = new std::map<std::string,FixCreator>();

(*fix_map)["adapt"] = &fix_creator<FixAdapt>;
(*fix_map)["addforce"] = &fix_creator<FixAddForce>;
(*fix_map)["addtorque"] = &fix_creator<FixAddTorque>;
(*fix_map)["append/atoms"] = &fix_creator<FixAppendAtoms>;
(*fix_map)["ave/atom"] = &fix_creator<FixAveAtom>;
(*fix_map)["ave/correlate"] = &fix_creator<FixAveCorrelate>;
(*fix_map)["aveforce"] = &fix_creator<FixAveForce>;
(*fix_map)["ave/histo"] = &fix_creator<FixAveHisto>;

and so on.

axel.

Thanks for your help, Axel. I’m a new user of Lammps and I didn’t use C++ before. I will try your suggestions. Thanks again.