New fix to calculate particle flux

Hi,

I am trying to calculate the flux of particles in the z-direction at different positions. Therefore, I
wrote a new fix because my previous attempts using python functions didn’t work.

I create different regions in the input script (l1,l2,… of (liquid) and v1,v2,… of (vapor))
and use the fix flux to check whether an atom went into or out of the regions by comparing the previous and current atom positions.

Furthermore, for each combination of l* and v* region, I create a new atom property (INT type) and set the atoms in the liquid region to value 1,
vapor region to 2 and all others 0. I will use this to study evaporation/condensation coefficients in liquid vapor systems.

Fix flux procedure:
constructor:

  • get input arguments and count the number of regions starting with character l (nliquid) and v (nvapor)

post_constructor():

  • create fix_store_state to save previous positions of atoms
  • add atom property of type INT for each liquid/vapor region combinations (e.g. 10 liquid regions and 5 vapor regions implies 10*5 combinations).

atom->add_custom(idname,0), idname=idfix_l*_v* e.g. t4_l1_v2

init():

  • set atom properties (type INT) depending on the region. 1 if atom is in liquid, 2 if in vapor else 0
    end_of_step():
  • count the flux depending on which flag is set (out,coll,evap,cond). The first 2 are based on the previous and current positions
    the last two also depends on where the atoms “came from (that is why I need the atom properties)”.

I tried this fix in LAMMPS (7 Aug 2019) and it works if the number of liquid and vapor regions create in the input script is not to big, i.e. variable a=b=50.
However, if I change this to a=70 and b=60 I receive the following error after 42 steps,

realloc(): invalid next size
[MWolf:01470] *** Process received signal ***
[MWolf:01470] Signal: Aborted (6)
[MWolf:01470] Signal code: (-6)
[MWolf:01470] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x12890)[0x7f57223be890]
[MWolf:01470] [ 1] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7)[0x7f57213c8e97]
[MWolf:01470] [ 2] /lib/x86_64-linux-gnu/libc.so.6(abort+0x141)[0x7f57213ca801]
[MWolf:01470] [ 3] /lib/x86_64-linux-gnu/libc.so.6(+0x89897)[0x7f5721413897]
[MWolf:01470] [ 4] /lib/x86_64-linux-gnu/libc.so.6(+0x9090a)[0x7f572141a90a]
[MWolf:01470] [ 5] /lib/x86_64-linux-gnu/libc.so.6(+0x959b4)[0x7f572141f9b4]
[MWolf:01470] [ 6] /lib/x86_64-linux-gnu/libc.so.6(realloc+0x36b)[0x7f5721422f9b]
[MWolf:01470] [ 7] lmp_mpi(_ZN9LAMMPS_NS6Memory8sreallocEPvlPKc+0x71)[0x55c692417521]
[MWolf:01470] [ 8] lmp_mpi(_ZN9LAMMPS_NS9CommBrick8exchangeEv+0x3d4)[0x55c6924af0b4]
[MWolf:01470] [ 9] lmp_mpi(_ZN9LAMMPS_NS6Verlet3runEi+0x499)[0x55c69278fd99]
[MWolf:01470] [10] lmp_mpi(_ZN9LAMMPS_NS3Run7commandEiPPc+0x891)[0x55c692258601]
[MWolf:01470] [11] lmp_mpi(_ZN9LAMMPS_NS5Input15command_creatorINS_3RunEEEvPNS_6LAMMPSEiPPc+0x3e)[0x55c6921f068e]
[MWolf:01470] [12] lmp_mpi(_ZN9LAMMPS_NS5Input15execute_commandEv+0xa01)[0x55c6921ee621]
[MWolf:01470] [13] lmp_mpi(_ZN9LAMMPS_NS5Input4fileEv+0x165)[0x55c6921eefb5]
[MWolf:01470] [14] lmp_mpi(main+0x48)[0x55c692179a28]
[MWolf:01470] [15] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f57213abb97]
[MWolf:01470] [16] lmp_mpi(_start+0x2a)[0x55c692179a9a]
[MWolf:01470] *** End of error message ***

With a=b=60, after 42 steps nothing happens (no error message) and I need to stop the process myself.

Since this is the first fix I write, I am not sure if my fix follows the lammps structure. There is obviously something
going wrong and I don’t know if it possible what I want. Maybe I have not enough memory?

If I run on 1 processors everything works well even with a=b=200.

Thanks,

Moritz

Attached: input.in, fix_flux.ccp, fix_flux.h

input.in (1.16 KB)

fix_flux.cpp (12 KB)

fix_flux.h (1.54 KB)

Hoi Moritz!

It looks like LAMMPS is running out of memory because the error is triggered by realloc.
"…

  • add atom property of type INT for each liquid/vapor region combinations (e.g. 10 liquid regions and 5 vapor regions implies 10*5 combinations).
    …"
    This sounds like a likely culprit. You probably will have to restructure your bookkeeping to use less memory. I am not sure why you need a property for each combination? Can’t you use a single int (maybe a BIGINT) to uniquely identify the region an atom is in?

Hoi Moritz!

It looks like LAMMPS is running out of memory because the error is triggered by realloc.

this error message usually happens with memory corruption, i.e. something has written beyond the bounds of the allocated storage and corrupted the “guard data” that the malloc library places there to check on memory management integrity.

axel.

Hoi Stefan,

I think I solved the problem by adding to the

constructor():

comm_border = nvalue

atom->add_callback(2)

and destructor()
atom->delete_callback(id,2)

I don’t get any error anymore but I haven’t run a proper liquid/vapor simulation yet.

Basically, I want to calculate the flux of particles at different positions along the liquid-vapor interphase.
I.e. count the number of particles moving towards the vapor phase or in opposite direction towards the liquid phase at

certain z-positions (which is zlo of the vapor regions). For this, I don’t need the atom properties.
However, I want to know where the particles came from when they move towards the vapor or liquid phase(region). For this, I need the properties.
Not all particles moving into the vapor region came from the liquid. Some particles came from the vapor and reflected in the interphase region and returned to the vapor.
They didn’t go into the liquid region. I hope it is clear.

I agree that it is probably not the most elegant way but I wanted to use the available lammps commands and functions.