setting rmass along with mass

Hello Steve,

Q1) Is there anyway to overload "atom->set_mass" from an "Atom_Vec" class?

Q2) Somehow related to above, is there any particular reason that
LAMMPS does "if (rmass) { ...}" when coming to getting the mass value
instead of "if (rmass_flag){....}"? I'm using LAMMPS as a library and
I sometimes need to switch LAMMPS from getting the mass values from
"atom->rmass" to "atom->mass".

Thank you
Hossein

Hello Steve,

Q1) Is there anyway to overload "atom->set_mass" from an "Atom_Vec" class?

LAMMPS is C++, why should it not be possible?

Q2) Somehow related to above, is there any particular reason that
LAMMPS does "if (rmass) { ...}" when coming to getting the mass value
instead of "if (rmass_flag){....}"? I'm using LAMMPS as a library and
I sometimes need to switch LAMMPS from getting the mass values from
"atom->rmass" to "atom->mass".

rmass and mass are two *different* entities.
mass is the per atom *type* mass, while
rmass is the per atom *index* mass.
you cannot just switch between them, or
you'll have to explain how this would be
a physically meaningful system.

axel.

Re: rmass vs mass. Each atom style uses
one or the other. Most use per-type mass,
but atom_style sphere uses per-atom rmass.

The code has to check internally in many places for
which is valid.

Steve

Axel: I actually mean in which Class should I overload that function,
not that is possible or not. I tried in the atom_vec_my class but that
is the wrong one because "void set_mass(const char *);" is a member
of the atom.h and not "atom->avec".

Physically it makes sense. I want to relax my system first and then
change the masses according to some Weight which does not apply on all
atoms. I have coupled LAMMPS to Finite Elements and the energy is
scaled over a handshake region and in that region I have to scale the
mass and forces.

Steve: I understand the the difference of "mass" and "Rmass". But if
LAMMPS used "Rmass_flag" to check the existence, it would have been
easier for me. Anyways, I'll find a way to do it.

Hossein

Axel: I actually mean in which Class should I overload that function,
not that is possible or not. I tried in the atom_vec_my class but that
is the wrong one because "void set_mass(const char *);" is a member
of the atom.h and not "atom->avec".

set_mass sets the mass value and not rmass.

Physically it makes sense. I want to relax my system first and then
change the masses according to some Weight which does not apply on all
atoms. I have coupled LAMMPS to Finite Elements and the energy is
scaled over a handshake region and in that region I have to scale the
mass and forces.

well, it doesn't make any sense from the
LAMMPS perspective. you cannot have a
mix of mass and rmass. you need either one
or the other, so if you want to do something
like what you say you do, you should use
rmass throughout.

technically rmass is a superset of mass.
since you manipulate per atom masses
according to your algorithm, you can reset
them to whatever you want. you don't really
need a set_mass call, but just set the
rmass array entries to whatever you want
them to be.

Steve: I understand the the difference of "mass" and "Rmass". But if
LAMMPS used "Rmass_flag" to check the existence, it would have been
easier for me. Anyways, I'll find a way to do it.

set mass sets the mass on a per atom type basis.
rmass is set differently.

axel.

Rmass is a flag. If it's NULL there are no per-atom rmass values.
If it's non-NULL, then there are.

What I would suggest you do (maybe you already are),
is add the functions you want to manipulate the mass values stored
inside LAMMPS (either read it or write it) to the library.cpp
file. Those functions define the API for using LAMMPS as a lib,
and they can access any quantities you wish inside LAMMPS.

Thus those functions can hide all the details of how to deal
with rmass vs mass.

Steve

Yes I'm already doing it.
I think "Rmass" is the vector and "Rmass_flag" is the flag for it, am I right?
The problem starts when I create a normal LAMMPS model with my custom
Atom style. So sometimes I want to do something to the model (create
velocity for example) Before setting the "Rmass" from my library. So
it uses the "Rmass" vector and blows up since the masses are not set
up.
I tried to overload the "atom->set_mass" in my custom atom style and
whenever I call set_mass it will fill "Rmass" too. But can't be done
since it is not from that class.
It could be like Only whenever I set "Rmass_flag=1" then all command
that need mass values use "Rmass" otherwise they use per-type mass
"Mass". But, in LAMMPS everywhere it directly checks for "Rmass" and
not "Rmass_flag".
This is maybe little issue in the LAMMPS source...

Yes I'm already doing it.
I think "Rmass" is the vector and "Rmass_flag" is the flag for it, am I right?
The problem starts when I create a normal LAMMPS model with my custom
Atom style. So sometimes I want to do something to the model (create
velocity for example) Before setting the "Rmass" from my library. So
it uses the "Rmass" vector and blows up since the masses are not set
up.

again, i don't see the problem. just use consistently
rmass throughout whenever your atom style is used.
trying to support both at the same time seems
like a "very bad idea(tm)" to me.

I tried to overload the "atom->set_mass" in my custom atom style and
whenever I call set_mass it will fill "Rmass" too. But can't be done
since it is not from that class.

no need to do that. all you need to do is to grab
the pointer to rmass in your library via

rmass = lammps_extract_atom(lmp,"rmass")

and then fill rmass from your library directly,
(provided that it is non-NULL, of course).
no messing with LAMMPS internals needed.

axel.