Skip to content

Commit

Permalink
Restoed original LAMMPS files to be up do date with lammps/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
abkein committed Jan 11, 2025
1 parent e84682e commit d41a0d4
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 98 deletions.
2 changes: 1 addition & 1 deletion src/atom_vec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ int AtomVec::unpack_restart(double *buf)
set other values to defaults
------------------------------------------------------------------------- */

void AtomVec::create_atom(int itype, const double * const coord)
void AtomVec::create_atom(int itype, double * coord)
{
int m, n, datatype, cols;
void *pdata;
Expand Down
2 changes: 1 addition & 1 deletion src/atom_vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class AtomVec : protected Pointers {
virtual int pack_restart_bonus(int, double *) { return 0; }
virtual int unpack_restart_bonus(int, double *) { return 0; }

virtual void create_atom(int, const double * const);
virtual void create_atom(int, double *);
virtual void create_atom_post(int) {}

virtual void data_atom(double *, imageint, const std::vector<std::string> &, std::string &);
Expand Down
2 changes: 1 addition & 1 deletion src/domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ void Domain::lamda2x(double *lamda, double *x)
x and lamda can point to same 3-vector
------------------------------------------------------------------------- */

void Domain::x2lamda(const double * const x, double *lamda)
void Domain::x2lamda(double * x, double *lamda)
{
double delta[3];
delta[0] = x[0] - boxlo[0];
Expand Down
2 changes: 1 addition & 1 deletion src/domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class Domain : protected Pointers {
virtual void x2lamda(int);
virtual void x2lamda(int, int);
virtual void lamda2x(double *, double *);
virtual void x2lamda(const double * const, double *);
virtual void x2lamda(double *, double *);
int inside(double *);
int inside_nonperiodic(double *);
void x2lamda(double *, double *, double *, double *);
Expand Down
96 changes: 13 additions & 83 deletions src/fix_cluster_crush_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ FixClusterCrushDelete::FixClusterCrushDelete(LAMMPS* lmp, int narg, char** arg)
vdist = DIST::DIST_GAUSSIAN;
iarg += 2;

} else if (::strcmp(arg[iarg], "placement_scheme") == 0) {
// Placement scheme
if (::strcmp(arg[iarg+1], "inplace") == 0) {
placement_scheme = PLACEMENT_SCHEME::INPLACE;
} else if (::strcmp(arg[iarg+1], "migrate") == 0) {
placement_scheme = PLACEMENT_SCHEME::MIGRATE;
} else {
error->all(FLERR, "{}: unknown placement scheme: {}", style, arg[iarg+1]);
}
iarg += 2;

} else if (::strcmp(arg[iarg], "noscreen") == 0) {
// Do not output to screen
screenflag = 0;
Expand Down Expand Up @@ -222,8 +211,6 @@ FixClusterCrushDelete::FixClusterCrushDelete(LAMMPS* lmp, int narg, char** arg)

// further setup and error check

if (placement_scheme == PLACEMENT_SCHEME::MIGRATE) { pre_exchange_migrate = 1; }

// Get temp compute
auto temp_computes = lmp->modify->get_compute_by_style("temp");
if (temp_computes.empty()) { error->all(FLERR, "{}: Cannot find compute with style 'temp'.", style); }
Expand Down Expand Up @@ -412,18 +399,18 @@ void FixClusterCrushDelete::pre_exchange()
to_insert += atoms2move_total;
int to_insert_prev = to_insert;

if (to_insert > 0) { add(); }
int ninserted = 0;
if (to_insert > 0) { ninserted = add(); }
to_insert -= ninserted;

bigint nblocal = atom->nlocal;
::MPI_Allreduce(&nblocal, &atom->natoms, 1, MPI_LMP_BIGINT, MPI_SUM, world);

// if (comm->me == 0) { utils::logmesg(lmp, "{}: {} — fix cluster/crush: {}\n", update->ntimestep, atom->natoms, getCurrentTime()); }

if (comm->me == 0) {
// print status
if (screenflag != 0) { utils::logmesg(lmp, "Crushed {} clusters -> deleted {} atoms.\n", clusters2crush_total, atoms2move_total); }
if (fileflag != 0) {
fmt::print(fp, "{},{},{},{},{},{}\n", update->ntimestep, atom->natoms, clusters2crush_total, atoms2move_total, to_insert_prev - to_insert,
fmt::print(fp, "{},{},{},{},{},{}\n", update->ntimestep, atom->natoms, clusters2crush_total, atoms2move_total, ninserted,
to_insert);
::fflush(fp);
}
Expand All @@ -445,12 +432,11 @@ void FixClusterCrushDelete::deleteAtoms(int atoms2move_local) noexcept(true)

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

void FixClusterCrushDelete::add()
int FixClusterCrushDelete::add() const
{
int warnflag = 0;
double _coord[3];
double r[3];
double vnew[3];
// double r[3];

// clear ghost count (and atom map) and any ghost bonus data
// internal to AtomVec
Expand Down Expand Up @@ -558,40 +544,17 @@ void FixClusterCrushDelete::add()
atom->map_set();
}

if (placement_scheme == PLACEMENT_SCHEME::MIGRATE) {
// move atoms back inside simulation box and to new processors
// use remap() instead of pbc() in case atoms moved a long distance
// use irregular() in case atoms moved a long distance

double** x = atom->x;
imageint* image = atom->image;
for (int i = 0; i < atom->nlocal; i++) domain->remap(x[i], image[i]);

if (domain->triclinic) domain->x2lamda(atom->nlocal);
domain->reset_box();
auto irregular = new Irregular(lmp);
irregular->migrate_atoms(1);
delete irregular;
if (domain->triclinic) domain->lamda2x(atom->nlocal);
}

if (comm->me == 0) { utils::logmesg(lmp, "{}: {}: {} atoms were inserted\n", style, update->ntimestep, ninserted); }

atom->tag_check();

to_insert -= ninserted;
return ninserted;
}

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

int FixClusterCrushDelete::placement_check_me(const double* const newcoord, const double* const sublo, const double* const subhi, int nparticle, int nattempt) const {
int flag = 0;

if (placement_scheme == PLACEMENT_SCHEME::MIGRATE) { return flag = comm->me == 0 ? 1 : 0; }

if (newcoord[0] > sublo[0] && newcoord[0] < subhi[0] &&
newcoord[1] > sublo[1] && newcoord[1] < subhi[1] &&
newcoord[2] > sublo[2] && newcoord[2] < subhi[2]) flag = 1;
if (newcoord[0] >= sublo[0] && newcoord[0] < subhi[0] &&
newcoord[1] >= sublo[1] && newcoord[1] < subhi[1] &&
newcoord[2] >= sublo[2] && newcoord[2] < subhi[2]) flag = 1;
else if (domain->dimension == 3 && newcoord[2] >= domain->boxhi[2]) {
if (comm->layout != Comm::LAYOUT_TILED) {
if (comm->myloc[2] == comm->procgrid[2]-1 &&
Expand All @@ -612,45 +575,12 @@ int FixClusterCrushDelete::placement_check_me(const double* const newcoord, cons
}
}

check_coord_diff(newcoord, nparticle, nattempt, "placement_check");
return flag;
}

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

void FixClusterCrushDelete::check_coord_diff(const double* const newcoord, int nparticle, int nattempt, const char *name) const noexcept {
double multiplier = 1. / comm->nprocs;
double coordaverage[3] = {0, 0, 0};
double coordsum[3] = {0, 0, 0};
int min_seed = 0;
int max_seed = 0;
::MPI_Allreduce(newcoord, coordaverage, 3, MPI_DOUBLE, MPI_SUM, world);
::MPI_Allreduce(&xrandom->seed, &min_seed, 1, MPI_INT, MPI_MIN, world);
::MPI_Allreduce(&xrandom->seed, &max_seed, 1, MPI_INT, MPI_MAX, world);
coordaverage[0] *= multiplier;
coordaverage[1] *= multiplier;
coordaverage[2] *= multiplier;
coordaverage[0] -= newcoord[0];
coordaverage[1] -= newcoord[1];
coordaverage[2] -= newcoord[2];
coordaverage[0] *= coordaverage[0];
coordaverage[1] *= coordaverage[1];
coordaverage[2] *= coordaverage[2];
::MPI_Allreduce(coordaverage, coordsum, 3, MPI_DOUBLE, MPI_SUM, world);
coordsum[0] *= multiplier * multiplier;
coordsum[1] *= multiplier * multiplier;
coordsum[2] *= multiplier * multiplier;
coordsum[0] = ::sqrt(coordsum[0]);
coordsum[1] = ::sqrt(coordsum[1]);
coordsum[2] = ::sqrt(coordsum[2]);
if (comm->me == 0) {
utils::logmesg(lmp, "{}-{}-{}-{}: Coordinate stddev: ({}, {}, {}), seeds are {}\n", update->ntimestep, nparticle, nattempt, name, coordsum[0], coordsum[1], coordsum[2], min_seed == max_seed ? "sync" : "desync");
}
}

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

void FixClusterCrushDelete::create_atom(const double* const coord, bigint tag) noexcept
void FixClusterCrushDelete::create_atom(const double* const coord, bigint tag) const noexcept
{
atom->avec->create_atom(ntype, coord);
int n = atom->nlocal - 1;
Expand Down Expand Up @@ -691,7 +621,7 @@ const double* const FixClusterCrushDelete::gen_pos(double* const coord, int npar
} else {
error->all(FLERR, "{}: Unknown particle distribution", style);
}
check_coord_diff(coord, nparticle, nattempt, "generation");
// check_coord_diff(coord, nparticle, nattempt, "generation");
return coord;
}

Expand Down Expand Up @@ -777,7 +707,7 @@ void FixClusterCrushDelete::postDelete() noexcept(true)
first set x,y,z values in internal variables
------------------------------------------------------------------------- */

int FixClusterCrushDelete::vartest(double x, double y, double z)
int FixClusterCrushDelete::vartest(double x, double y, double z) const noexcept
{
if (xstr != nullptr) { input->variable->internal_set(vars[0], x); }
if (ystr != nullptr) { input->variable->internal_set(vars[1], y); }
Expand Down
9 changes: 3 additions & 6 deletions src/fix_cluster_crush_delete.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ FixStyle(cluster/crush/delete,FixClusterCrushDelete);
#include <array>

enum class DIST {DIST_UNIFORM,DIST_GAUSSIAN};
enum class PLACEMENT_SCHEME {INPLACE,MIGRATE};

namespace LAMMPS_NS {
class FixClusterCrushDelete : public Fix {
Expand Down Expand Up @@ -61,7 +60,6 @@ class FixClusterCrushDelete : public Fix {
int maxtry = 1000;
int ntype = 0;
int groupid = 0;
PLACEMENT_SCHEME placement_scheme = PLACEMENT_SCHEME::INPLACE;

//velocity and coordinates
bool fix_temp = false;
Expand All @@ -79,12 +77,11 @@ class FixClusterCrushDelete : public Fix {
void deleteAtoms(int atoms2move_local) noexcept(true);
void postDelete() noexcept(true);

void add();
int add() const;
const double* const gen_pos(double* const coord, int nparticle, int nattempt) const noexcept;
int vartest(double x, double y, double z);
int vartest(double x, double y, double z) const noexcept;
bool check_overlap(const double* const coord) const noexcept;
void create_atom(const double* const coord, bigint tag) noexcept;
void check_coord_diff(const double* const newcoord, int nparticle, int nattempt, const char* name) const noexcept;
void create_atom(const double* const coord, bigint tag) const noexcept;
int placement_check_me(const double* const newcoord, const double* const sublo, const double* const subhi, int nparticle, int nattempt) const;
};

Expand Down
2 changes: 1 addition & 1 deletion src/random_park.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class RanPark : protected Pointers {
void reset(int, double *);
int state();

int seed, save;
private:
int seed, save;
double second;
};

Expand Down
5 changes: 1 addition & 4 deletions src/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
#include "output.h"
#include "timer.h"
#include "update.h"
#include <cstring>

#include "tim.hpp"
#include "atom.h"
#include "comm.h"
#include <cstring>

using namespace LAMMPS_NS;

Expand Down

0 comments on commit d41a0d4

Please sign in to comment.