Skip to content

Commit

Permalink
Fix bug in fix_property_*, size_peratom_cols needs to be 1 when using…
Browse files Browse the repository at this point in the history
… vprop
  • Loading branch information
shelllbw committed Apr 29, 2024
1 parent 0d703b6 commit 74f54d1
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/MUTATION/fix_mutate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void FixMutate::compute()
if (mask[i] & groupbit) {
if (random->uniform() < prob) {
mask[i] = imutant;
}MUT
}
}
}
}
2 changes: 1 addition & 1 deletion src/NUFEB/fix_divide_bacillus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void FixDivideBacillus::compute()
double imass, jmass;
double ilen, xp1[3], xp2[3];

// double phiz = random->uniform() * 2e-8;
// double phiz = random->uniform() * 2e-8;

double vsphere = four_thirds_pi * atom->radius[i]*atom->radius[i]*atom->radius[i];
double acircle = MY_PI*atom->radius[i]*atom->radius[i];
Expand Down
16 changes: 8 additions & 8 deletions src/NUFEB/fix_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int FixProperty::modify_param(int narg, char **arg)
double FixProperty::memory_usage()
{
double bytes;
if (size_peratom_cols > 0)
if (size_peratom_cols > 1)
bytes = atom->nmax*size_peratom_cols*sizeof(double);
else
bytes = atom->nmax*sizeof(double);
Expand All @@ -93,7 +93,7 @@ double FixProperty::memory_usage()

void FixProperty::grow_arrays(int nmax)
{
if (size_peratom_cols > 0) {
if (size_peratom_cols > 1) {
memory->grow(aprop,nmax,size_peratom_cols,"fix_property:array");
array_atom = aprop;
} else {
Expand All @@ -108,7 +108,7 @@ void FixProperty::grow_arrays(int nmax)

void FixProperty::copy_arrays(int i, int j, int /*delflag*/)
{
if (size_peratom_cols > 0) {
if (size_peratom_cols > 1) {
for (int m = 0; m < size_peratom_cols; m++)
aprop[j][m] = aprop[i][m];
} else {
Expand All @@ -122,7 +122,7 @@ void FixProperty::copy_arrays(int i, int j, int /*delflag*/)

int FixProperty::pack_exchange(int i, double *buf)
{
if (size_peratom_cols > 0) {
if (size_peratom_cols > 1) {
for (int m = 0; m < size_peratom_cols; m++)
buf[m] = aprop[i][m];
} else {
Expand All @@ -137,7 +137,7 @@ int FixProperty::pack_exchange(int i, double *buf)

int FixProperty::unpack_exchange(int nlocal, double *buf)
{
if (size_peratom_cols > 0) {
if (size_peratom_cols > 1) {
for (int m = 0; m < size_peratom_cols; m++)
aprop[nlocal][m] = buf[m];
} else {
Expand All @@ -153,7 +153,7 @@ int FixProperty::unpack_exchange(int nlocal, double *buf)
int FixProperty::pack_restart(int i, double *buf)
{
buf[0] = size_peratom_cols + 1;
if (size_peratom_cols > 0) {
if (size_peratom_cols > 1) {
for (int m = 0; m < size_peratom_cols; m++)
buf[m+1] = aprop[i][m];
} else {
Expand All @@ -174,9 +174,9 @@ void FixProperty::unpack_restart(int nlocal, int nth)
int m = 0;
for (int i = 0; i < nth; i++) m += static_cast<int> (extra[nlocal][m]);
m++;
if (size_peratom_cols > 0) {
if (size_peratom_cols > 1) {
for (int i = 0; i < size_peratom_cols; i++)
aprop[nlocal][i] = extra[nlocal][m];
aprop[nlocal][i] = extra[nlocal][m++];
} else {
vprop[nlocal] = extra[nlocal][m];
}
Expand Down
4 changes: 2 additions & 2 deletions src/NUFEB/fix_property_ancestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ FixPropertyAncestor::FixPropertyAncestor(LAMMPS *lmp, int narg, char **arg) :
if (narg < 3) error->all(FLERR,"Illegal fix property/nufeb/ancestor command");

create_attribute = 1;
// use vprop if size_peratom_cols = 0
size_peratom_cols = 0;
// use vprop if size_peratom_cols = 1
size_peratom_cols = 1;
grow_arrays(atom->nmax);
}

Expand Down
49 changes: 35 additions & 14 deletions src/NUFEB/fix_property_cycletime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
#include "memory.h"
#include "error.h"
#include "update.h"
#include "random_park.h"

using namespace LAMMPS_NS;
using namespace FixConst;

/* ---------------------------------------------------------------------- */

FixPropertyCycletime::FixPropertyCycletime(LAMMPS *lmp, int narg, char **arg) :
FixProperty(lmp, narg, arg)
FixProperty(lmp, narg, arg)
{
if (narg < 3) error->all(FLERR,"Illegal fix nufeb/property/cycletime command");

Expand All @@ -35,6 +36,37 @@ FixPropertyCycletime::FixPropertyCycletime(LAMMPS *lmp, int narg, char **arg) :
// use aprop if size_peratom_cols > 0
size_peratom_cols = 2;
grow_arrays(atom->nmax);

seed = 0;
max_time = 0;
ran_flag = 0;

int iarg = 3;
while (iarg < narg) {
if (strcmp(arg[iarg], "seed") == 0) {
seed = utils::inumeric(FLERR,arg[iarg+1],true,lmp);
random = new RanPark(lmp, seed);
ran_flag = 1;
iarg += 2;
} else if (strcmp(arg[iarg], "max_time") == 0 ) {
max_time = utils::numeric(FLERR,arg[iarg+1],true,lmp);
iarg += 2;
} else {
error->all(FLERR, "Illegal fix nufeb/property/cycletime command");
}
}

for (int i = 0; i < atom->nlocal; i++) {
if (atom->mask[i] & groupbit) {
if (ran_flag > 0) {
aprop[i][0] = random->uniform() * max_time;
aprop[i][1] = aprop[i][0];
} else {
aprop[i][0] = 0.0;
aprop[i][1] = 0.0;
}
}
}
}

/* ---------------------------------------------------------------------- */
Expand All @@ -46,16 +78,6 @@ int FixPropertyCycletime::setmask()
return mask;
}

/* ---------------------------------------------------------------------- */

void FixPropertyCycletime::init()
{
for (int i = 0; i < atom->nlocal; i++) {
aprop[i][0] = 0.0;
aprop[i][1] = 0.0;
}
}

/* ----------------------------------------------------------------------
update cell age
------------------------------------------------------------------------- */
Expand All @@ -67,6 +89,7 @@ void FixPropertyCycletime::biology_nufeb()
for (int i = 0; i < atom->nlocal; i++) {
if (atom->mask[i] & groupbit) {
aprop[i][0] += update->dt;
aprop[i][1] += update->dt;
}
}
}
Expand All @@ -78,7 +101,6 @@ void FixPropertyCycletime::biology_nufeb()
void FixPropertyCycletime::set_arrays(int j)
{
aprop[j][0] = 0.0;
aprop[j][1] = 0.0;
}

/* ----------------------------------------------------------------------
Expand All @@ -87,10 +109,9 @@ void FixPropertyCycletime::set_arrays(int j)
------------------------------------------------------------------------- */
void FixPropertyCycletime::update_arrays(int i, int j)
{
// no need to update j here as this has been done in set_arrary
// when cell divides, record cell cycle time and reset to 0
aprop[i][1] = aprop[i][0];
aprop[i][0] = 0.0;
aprop[j][1] = aprop[i][1];
}

/* ----------------------------------------------------------------------
Expand Down
14 changes: 12 additions & 2 deletions src/NUFEB/fix_property_cycletime.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,27 @@ FixStyle(nufeb/property/cycletime,FixPropertyCycletime)
namespace LAMMPS_NS {

class FixPropertyCycletime : public FixProperty {
public:
public:

FixPropertyCycletime(class LAMMPS *, int, char **);
virtual ~FixPropertyCycletime() {};

void init();
int setmask();
void biology_nufeb();
void set_arrays(int);
void update_arrays(int, int);
double compute_scalar();

// int pack_restart(int, double *);
// void unpack_restart(int, int);
// int size_restart(int);
// int maxsize_restart();

protected:
int seed, ran_flag;
double max_time;

class RanPark *random;
};

}
Expand Down
6 changes: 2 additions & 4 deletions src/NUFEB/fix_property_generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ FixPropertyGeneration::FixPropertyGeneration(LAMMPS *lmp, int narg, char **arg)
if (narg < 3) error->all(FLERR,"Illegal fix nufeb/property/generation command");

create_attribute = 1;
// use vprop if size_peratom_cols = 0
size_peratom_cols = 0;
// use vprop if size_peratom_cols = 1
size_peratom_cols = 1;
grow_arrays(atom->nmax);
}

Expand Down Expand Up @@ -68,9 +68,7 @@ void FixPropertyGeneration::set_arrays(int j)
------------------------------------------------------------------------- */
void FixPropertyGeneration::update_arrays(int i, int j)
{
if (atom->mask[i] & groupbit)
vprop[i]++;
if (atom->mask[j] & groupbit)
vprop[j] = vprop[i];
}

Expand Down
2 changes: 1 addition & 1 deletion src/PLASMID/fix_property_plasmid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ FixPropertyPlasmid::FixPropertyPlasmid(LAMMPS *lmp, int narg, char **arg) :
if (plm_init > plm_max) error->all(FLERR,"Illegal fix nufeb/property/plasmid command: "
"initial plasmid cannot be more than maximum plasmid number");

size_peratom_cols = 0;
size_peratom_cols = 1;
fila_max = plm_max * (plm_max - 1) / 2;

grow_arrays(atom->nmax);
Expand Down

0 comments on commit 74f54d1

Please sign in to comment.