From 0679ad8b00ba35e2216ab1d63da9c0ce71765ac9 Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Thu, 9 May 2019 16:18:29 +0100 Subject: [PATCH 001/392] Implemented file reading, no debug --- src/MESOCNT/pair_mesocnt.cpp | 256 +++++++++++++++++++++++++++++++++++ src/MESOCNT/pair_mesocnt.h | 69 ++++++++++ 2 files changed, 325 insertions(+) create mode 100644 src/MESOCNT/pair_mesocnt.cpp create mode 100644 src/MESOCNT/pair_mesocnt.h diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp new file mode 100644 index 0000000000..6736ae2f81 --- /dev/null +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -0,0 +1,256 @@ +#include +#include +#include +#include +#include "pair_mesocnt.h" +#include "atom.h" +#include "comm.h" +#include "force.h" +#include "neighbor.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "update.h" +#include "integrate.h" +#include "respa.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" + +using namespace LAMMPS_NS; +using namespace MathConst; + +#define MAXLINE 1024 + +/* ---------------------------------------------------------------------- */ + +PairMesoCNT::PairMesoCNT(LAMMPS *lmp) : Pair(lmp) +{ + respa_enable = 0; + writedata = 1; + + +} + +/* ---------------------------------------------------------------------- */ + +PairMesoCNT::~PairMesoCNT() +{ + if (allocated) { + memory->destroy(gamma_data); + memory->destroy(u_inf_data); + memory->destroy(delh_u_semi); + memory->destroy(delzeta_phi); + + memory->destroy(u_semi_data); + memory->destroy(phi_data); + memory->destroy(gamma_coeff); + memory->destroy(u_inf_coeff); + + memory->destroy(u_semi_coeff); + memory->destroy(phi_coeff); + } +} + +/* ---------------------------------------------------------------------- */ + +void PairMesoCNT::compute(int eflag, int vflag) +{ + +} + +/* ---------------------------------------------------------------------- */ + + + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +void PairMesoCNT::allocate() +{ + allocated = 1; + + memory->create(gamma_data,gamma_points,"pair:gamma_data"); + memory->create(u_inf_data,pot_points,"pair:u_inf_data"); + memory->create(delh_u_semi,pot_points,"pair:delh_u_semi"); + memory->create(delzeta_phi,pot_points,"pair:delzeta_phi"); + + memory->create(u_semi_data,pot_points,pot_points,"pair:u_semi_data"); + memory->create(phi_data,pot_points,pot_points,"pair:phi_data"); + memory->create(gamma_coeff,gamma_points-1,4,"pair:gamma_coeff"); + memory->create(u_inf_coeff,pot_points-1,4,"pair:u_inf_coeff"); + + memory->create(u_semi_coeff,pot_points,pot_points-1,4,"pair:u_semi_coeff"); + memory->create(phi_coeff,pot_points,pot_points-1,4,"pair:phi_coeff"); +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +void PairMesoCNT::settings(int narg, char **arg) +{ + if (narg != 2) error->all(FLERR,"Illegal pair_style command"); + + gamma_points = force->inumeric(FLERR,arg[0]); + pot_points = force->inumeric(FLERR,arg[1]); +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +void PairMesoCNT::coeff(int narg, char **arg) +{ + if (narg != 9) error->all(FLERR,"Incorrect args for pair coefficients"); + if (!allocated) allocate(); + + sigma = force->numeric(FLERR,arg[2]); + epsilon = force->numeric(FLERR,arg[3]); + n_sigma = force->numeric(FLERR,arg[4]); + + gamma_file = arg[5]; + u_inf_file = arg[6]; + u_semi_file = arg[7]; + phi_file = arg[8]; + + //Parse and bcast data + int me; + MPI_Comm_rank(world,&me); + if (me == 0) { + read_file(gamma_file,gamma_data,&del_gamma,gamma_points); + read_file(u_inf_file,u_inf_data,&del_u_inf,pot_points); + read_file(u_semi_file,u_semi_data,delh_u_semi,&delxi_u_semi,pot_points); + read_file(phi_file,phi_data,delzeta_phi,delh_phi,pot_points); + } + + MPI_Bcast(gamma_data,gamma_points,MPI_DOUBLE,0,world); + MPI_Bcast(u_inf_data,pot_points,MPI_DOUBLE,0,world); + MPI_Bcast(delh_u_semi,pot_points,MPI_DOUBLE,0,world); + MPI_Bcast(delzeta_phi,pot_points,MPI_DOUBLE,0,world); + for(int i = 0; i < pot_points; i++){ + MPI_Bcast(u_semi_data[i],pot_points,MPI_DOUBLE,0,world); + MPI_Bcast(phi_data[i],pot_points,MPI_DOUBLE,0,world); + } + +/* ---------------------------------------------------------------------- */ + +void PairMesoCNT::read_file(char *file, double *data, double *dx, int ninput) +{ + char line[MAXLINE]; + + // open file + + FILE *fp = force->open_potential(file); + if (fp == NULL) { + std::string str("Cannot open file "); + str += file; + error->one(FLERR,str.c_str()); + } + + // read values from file + + int cerror = 0; + int serror = 0; + double x,xtemp; + + utils::sfgets(FLERR,line,MAXLINE,fp,file,error); + for(int i = 0; i < ninput; i++){ + if(i > 0) xtemp = x; + if(NULL == fgets(line,MAXLINE,fp)) + error->one(FLERR,"Premature end of file in pair table"); + if(2 != sscanf(line,"%lg %lg",&x, &data[i])) ++cerror; + if(i > 0){ + if(i == 1) *dx = x - xtemp; + if(*dx != x - xtemp) ++serror; + } + } + + // warn if data was read incompletely, e.g. columns were missing + + if (cerror) { + char str[128]; + sprintf(str,"%d of %d lines in table were incomplete\n" + " or could not be parsed completely",cerror,ninput); + error->warning(FLERR,str); + } + + // warn if spacing between data points is not constant + + if (serror) { + char str[128]; + sprintf(str, "%d spacings were different\n" + " from first entry",serror); + error->warning(FLERR,str); + } + +} + +/* ---------------------------------------------------------------------- */ + +void PairMesoCNT::read_file(char *file, double **data, + double *dx, double *dy, int ninput) +{ + char line[MAXLINE]; + + // open file + + FILE *fp = force->open_potential(file); + if (fp == NULL) { + std::string str("Cannot open file "); + str += file; + error->one(FLERR,str.c_str()); + } + + // read values from file + + int cerror = 0; + int sxerror = 0; + int syerror = 0; + double x,y,xtemp,ytemp; + + utils::sfgets(FLERR,line,MAXLINE,fp,file,error); + for(int i = 0; i < ninput; i++){ + if(i > 0) ytemp = y; + for(int j = 0; j < ninput; j++){ + if(j > 0) xtemp = x; + if(NULL == fgets(line,MAXLINE,fp)) + error->one(FLERR,"Premature end of file in pair table"); + if(3 != sscanf(line,"%lg %lg %lg",&x,&y,&data[j][i])) ++cerror; + if(j > 0){ + if(j == 1) dx[i] = x - xtemp; + if(dx[i] != x - xtemp) ++sxerror; + } + } + if(i > 0){ + if(i == 1) *dy = y - ytemp; + if(*dy != y - ytemp) ++syerror; + } + } + + // warn if data was read incompletely, e.g. columns were missing + + if (cerror) { + char str[128]; + sprintf(str,"%d of %d lines in table were incomplete\n" + " or could not be parsed completely",cerror,ninput); + error->warning(FLERR,str); + } + + // warn if spacing between data points is not constant + + if (sxerror) { + char str[128]; + sprintf(str, "%d spacings in first column were different\n" + " from first block entries",sxerror); + error->warning(FLERR,str); + } + + if (syerror) { + char str[128]; + sprintf(str, "%d spacings in second column were different\n" + " from first entry",syerror); + error->warning(FLERR,str); + } + +} diff --git a/src/MESOCNT/pair_mesocnt.h b/src/MESOCNT/pair_mesocnt.h new file mode 100644 index 0000000000..39de5b8142 --- /dev/null +++ b/src/MESOCNT/pair_mesocnt.h @@ -0,0 +1,69 @@ +#ifdef PAIR_CLASS + +PairStyle(mesocnt, PairMesoCNT) + +#else + +#ifndef LMP_PAIR_MESOCNT_H +#define LMP_PAIR_MESOCNT_H + +#include "pair.h" + +namespace LAMMPS_NS { + +class PairMesoCNT : public Pair { + public: + PairMesoCNT(class LAMMPS *); + ~PairMesoCNT(); + void compute(int, int); + void settings(int, char **); + void coeff(int, char **); + void init_style(); + double init_one(int, int); + void write_restart(FILE *); + void read_restart(FILE *); + + void write_restart_settings(FILE *); + void read_restart_settings(FILE *); + void write_data(FILE *); + void write_data_all(FILE *); + double single(int, int, int, int, double, double, double, double &); + void *extract(const char *, int &); + + protected: + int n, gamma_points, pot_points; + double sigma, epsilon, n_sigma, radius; + double del_gamma, del_u_inf, delxi_u_semi, delh_phi; + double *delh_u_semi, *delzeta_phi; + double *gamma_data, *u_inf_data; + double **u_semi_data, **phi_data; + double **gamma_coeff, **u_inf_coeff; + double ***u_semi_coeff, ***phi_coeff; + char *gamma_file, *u_inf_file, *u_semi_file, *phi_file; + + void allocate(); + + double eval_gamma(double); + double eval_u_inf(double); + double eval_u_semi(double, double); + double eval_u_semi(double, double); + double d_gamma(double); + double d_u_inf(double); + double dh_u_semi(double, double); + double dxi_u_semi(double, double); + double dh_u_semi(double, double); + double dzeta_u_semi(double, double); + + int heaviside(double); + int sgn(double); + + double distance(double, double, double, double, double, double, double); + double cutoff(double, double, double); + + void read_file(char *, double *); + void read_file(char *, double **); +} + +} +#endif +#endif From c4777054df205374bc7d5459aef893d471f7e4da Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Thu, 9 May 2019 20:03:09 +0100 Subject: [PATCH 002/392] Code compiles, 1d spline + derivative implemented --- src/MESOCNT/pair_mesocnt.cpp | 158 +++++++++++++++++++++++++++++++---- src/MESOCNT/pair_mesocnt.h | 45 +++++----- 2 files changed, 159 insertions(+), 44 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index 6736ae2f81..c6c7e6634a 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -15,6 +15,7 @@ #include "math_const.h" #include "memory.h" #include "error.h" +#include "utils.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -37,16 +38,16 @@ PairMesoCNT::~PairMesoCNT() { if (allocated) { memory->destroy(gamma_data); - memory->destroy(u_inf_data); - memory->destroy(delh_u_semi); + memory->destroy(uinf_data); + memory->destroy(delh_usemi); memory->destroy(delzeta_phi); - memory->destroy(u_semi_data); + memory->destroy(usemi_data); memory->destroy(phi_data); memory->destroy(gamma_coeff); - memory->destroy(u_inf_coeff); + memory->destroy(uinf_coeff); - memory->destroy(u_semi_coeff); + memory->destroy(usemi_coeff); memory->destroy(phi_coeff); } } @@ -71,16 +72,16 @@ void PairMesoCNT::allocate() allocated = 1; memory->create(gamma_data,gamma_points,"pair:gamma_data"); - memory->create(u_inf_data,pot_points,"pair:u_inf_data"); - memory->create(delh_u_semi,pot_points,"pair:delh_u_semi"); + memory->create(uinf_data,pot_points,"pair:uinf_data"); + memory->create(delh_usemi,pot_points,"pair:delh_usemi"); memory->create(delzeta_phi,pot_points,"pair:delzeta_phi"); - memory->create(u_semi_data,pot_points,pot_points,"pair:u_semi_data"); + memory->create(usemi_data,pot_points,pot_points,"pair:usemi_data"); memory->create(phi_data,pot_points,pot_points,"pair:phi_data"); memory->create(gamma_coeff,gamma_points-1,4,"pair:gamma_coeff"); - memory->create(u_inf_coeff,pot_points-1,4,"pair:u_inf_coeff"); + memory->create(uinf_coeff,pot_points-1,4,"pair:uinf_coeff"); - memory->create(u_semi_coeff,pot_points,pot_points-1,4,"pair:u_semi_coeff"); + memory->create(usemi_coeff,pot_points,pot_points-1,4,"pair:usemi_coeff"); memory->create(phi_coeff,pot_points,pot_points-1,4,"pair:phi_coeff"); } @@ -110,8 +111,8 @@ void PairMesoCNT::coeff(int narg, char **arg) n_sigma = force->numeric(FLERR,arg[4]); gamma_file = arg[5]; - u_inf_file = arg[6]; - u_semi_file = arg[7]; + uinf_file = arg[6]; + usemi_file = arg[7]; phi_file = arg[8]; //Parse and bcast data @@ -119,20 +120,137 @@ void PairMesoCNT::coeff(int narg, char **arg) MPI_Comm_rank(world,&me); if (me == 0) { read_file(gamma_file,gamma_data,&del_gamma,gamma_points); - read_file(u_inf_file,u_inf_data,&del_u_inf,pot_points); - read_file(u_semi_file,u_semi_data,delh_u_semi,&delxi_u_semi,pot_points); - read_file(phi_file,phi_data,delzeta_phi,delh_phi,pot_points); + read_file(uinf_file,uinf_data,&del_uinf,pot_points); + read_file(usemi_file,usemi_data,delh_usemi,&delxi_usemi,pot_points); + read_file(phi_file,phi_data,delzeta_phi,&delh_phi,pot_points); } MPI_Bcast(gamma_data,gamma_points,MPI_DOUBLE,0,world); - MPI_Bcast(u_inf_data,pot_points,MPI_DOUBLE,0,world); - MPI_Bcast(delh_u_semi,pot_points,MPI_DOUBLE,0,world); + MPI_Bcast(uinf_data,pot_points,MPI_DOUBLE,0,world); + MPI_Bcast(delh_usemi,pot_points,MPI_DOUBLE,0,world); MPI_Bcast(delzeta_phi,pot_points,MPI_DOUBLE,0,world); for(int i = 0; i < pot_points; i++){ - MPI_Bcast(u_semi_data[i],pot_points,MPI_DOUBLE,0,world); + MPI_Bcast(usemi_data[i],pot_points,MPI_DOUBLE,0,world); MPI_Bcast(phi_data[i],pot_points,MPI_DOUBLE,0,world); } + spline_coeff(gamma_data,gamma_coeff,gamma_points); + spline_coeff(uinf_data,uinf_coeff,pot_points); + spline_coeff(usemi_data,usemi_coeff,pot_points); + spline_coeff(phi_data,phi_coeff,pot_points); +} + +/* ---------------------------------------------------------------------- */ + +double PairMesoCNT::spline(double x, double xstart, double dx, + double **coeff, int coeff_size) +{ + int i = floor((x - xstart)/dx); + if(i < 0){ + i = 0; + // warn if argument below spline range + char str[128]; + sprintf(str,"Argument below spline interval",cerror,ninput); + error->warning(FLERR,str); + } + else if(i > coeff_size-1){ + i = coeff_size-1; + // warn if argument above spline range + char str[128]; + sprintf(str,"Argument above spline interval",cerror,ninput); + error->warning(FLERR,str); + } + + double xlo = xstart + i*dx; + double xbar = (x - xlo)/dx; + + return coeff[i][0] + xbar*(coeff[i][1] + + xbar*(coeff[i][2] + xbar*coeff[i][3])); +} + +/* ---------------------------------------------------------------------- */ + +double PairMesoCNT::dspline(double x, double xstart, double dx, + double **coeff, int coeff_size) +{ + int i = floor((x - xstart)/dx); + if(i < 0){ + i = 0; + // warn if argument below spline range + char str[128]; + sprintf(str,"Argument below spline interval",cerror,ninput); + error->warning(FLERR,str); + } + else if(i > coeff_size-1){ + i = coeff_size-1; + // warn if argument above spline range + char str[128]; + sprintf(str,"Argument above spline interval",cerror,ninput); + error->warning(FLERR,str); + } + + double xlo = xstart + i*dx; + double xbar = (x - xlo)/dx; + + return coeff[i][1] + xbar*(2*coeff[i][2] + 3*xbar*coeff[i][3]); +} + +/* ---------------------------------------------------------------------- */ + +void PairMesoCNT::spline_coeff(double *data, double **coeff, int data_size) +{ + for(int i = 0; i < data_size-1; i++){ + if(i == 0){ + coeff[i][0] = data[i]; + coeff[i][1] = data[i+1] - data[i]; + coeff[i][3] = 0.5*(data[i+2] - 2*data[i+1] + data[i]); + coeff[i][2] = -coeff[i][3]; + } + else if(i == data_size-2){ + coeff[i][0] = data[i]; + coeff[i][1] = 0.5*(data[i+1] - data[i-1]); + coeff[i][3] = 0.5*(-data[i+1] + 2*data[i] - data[i-1]); + coeff[i][2] = -2*coeff[i][3]; + } + else{ + coeff[i][0] = data[i]; + coeff[i][1] = 0.5*(data[i+1] - data[i-1]); + coeff[i][2] = 0.5*(-data[i+2] + 4*data[i+1] - 5*data[i] + 2*data[i-1]); + coeff[i][3] = 0.5*(data[i+2] - 3*data[i+1] + 3*data[i] - data[i-1]); + } + } +} + +/* ---------------------------------------------------------------------- */ + +void PairMesoCNT::spline_coeff(double **data, double ***coeff, int data_size) +{ + for(int i = 0; i < data_size; i++){ + for(int j = 0; j < data_size-1; j++){ + if(i == 0){ + coeff[i][j][0] = data[j][i]; + coeff[i][j][1] = data[j+1][i] - data[j][i]; + coeff[i][j][3] = 0.5*(data[j+2][i] - 2*data[j+1][i] + data[j][i]); + coeff[i][j][2] = -coeff[i][j][3]; + } + else if(i == data_size-2){ + coeff[i][j][0] = data[j][i]; + coeff[i][j][1] = 0.5*(data[j+1][i] - data[j-1][i]); + coeff[i][j][3] = 0.5*(-data[j+1][i] + 2*data[j][i] - data[j-1][i]); + coeff[i][j][2] = -2*coeff[i][j][3]; + } + else{ + coeff[i][j][0] = data[j][i]; + coeff[i][j][1] = 0.5*(data[j+1][i] - data[j-1][i]); + coeff[i][j][2] = 0.5*(-data[j+2][i] + 4*data[j+1][i] + - 5*data[j][i] + 2*data[j-1][i]); + coeff[i][j][3] = 0.5*(data[j+2][i] - 3*data[j+1][i] + + 3*data[j][i] - data[j-1][i]); + } + } + } +} + /* ---------------------------------------------------------------------- */ void PairMesoCNT::read_file(char *file, double *data, double *dx, int ninput) @@ -254,3 +372,7 @@ void PairMesoCNT::read_file(char *file, double **data, } } + +/* ---------------------------------------------------------------------- */ + + diff --git a/src/MESOCNT/pair_mesocnt.h b/src/MESOCNT/pair_mesocnt.h index 39de5b8142..13147c3e12 100644 --- a/src/MESOCNT/pair_mesocnt.h +++ b/src/MESOCNT/pair_mesocnt.h @@ -33,36 +33,29 @@ class PairMesoCNT : public Pair { protected: int n, gamma_points, pot_points; double sigma, epsilon, n_sigma, radius; - double del_gamma, del_u_inf, delxi_u_semi, delh_phi; - double *delh_u_semi, *delzeta_phi; - double *gamma_data, *u_inf_data; - double **u_semi_data, **phi_data; - double **gamma_coeff, **u_inf_coeff; - double ***u_semi_coeff, ***phi_coeff; - char *gamma_file, *u_inf_file, *u_semi_file, *phi_file; + double start_gamma, start_uinf, startxi_usemi, starth_phi; + double del_gamma, del_uinf, delxi_usemi, delh_phi; + double *delh_usemi, *delzeta_phi; + double *gamma_data, *uinf_data; + double **usemi_data, **phi_data; + double **gamma_coeff, **uinf_coeff; + double ***usemi_coeff, ***phi_coeff; + char *gamma_file, *uinf_file, *usemi_file, *phi_file; void allocate(); - double eval_gamma(double); - double eval_u_inf(double); - double eval_u_semi(double, double); - double eval_u_semi(double, double); - double d_gamma(double); - double d_u_inf(double); - double dh_u_semi(double, double); - double dxi_u_semi(double, double); - double dh_u_semi(double, double); - double dzeta_u_semi(double, double); + double spline(double, double, double, double **, int); + double spline(double, double, double *, double, double *, double ***, int); + double dspline(double, double, double, double **, int); + double dxspline(double, double, double *, double, double *, double ***, int); + double dyspline(double, double, double *, double, double *, double ***, int); - int heaviside(double); - int sgn(double); - - double distance(double, double, double, double, double, double, double); - double cutoff(double, double, double); - - void read_file(char *, double *); - void read_file(char *, double **); -} + void spline_coeff(double *, double **, int); + void spline_coeff(double **, double ***, int); + + void read_file(char *, double *, double *, int); + void read_file(char *, double **, double *, double *, int); +}; } #endif From b22ae0263feb77d9e9f4c7cc6b02ce7ab9e94e7a Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Fri, 10 May 2019 17:11:56 +0100 Subject: [PATCH 003/392] Geometry parameter calculation implemented --- src/MESOCNT/pair_mesocnt.cpp | 358 +++++++++++++++++++++++++++++++++-- src/MESOCNT/pair_mesocnt.h | 33 ++-- 2 files changed, 362 insertions(+), 29 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index c6c7e6634a..f406166fde 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -13,6 +13,7 @@ #include "integrate.h" #include "respa.h" #include "math_const.h" +#include "math_extra.h" #include "memory.h" #include "error.h" #include "utils.h" @@ -103,17 +104,22 @@ void PairMesoCNT::settings(int narg, char **arg) void PairMesoCNT::coeff(int narg, char **arg) { - if (narg != 9) error->all(FLERR,"Incorrect args for pair coefficients"); + if (narg != 10) error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); - sigma = force->numeric(FLERR,arg[2]); - epsilon = force->numeric(FLERR,arg[3]); - n_sigma = force->numeric(FLERR,arg[4]); + n = force->inumeric(FLERR,arg[2]); + sigma = force->numeric(FLERR,arg[3]); + epsilon = force->numeric(FLERR,arg[4]); + n_sigma = force->numeric(FLERR,arg[5]); - gamma_file = arg[5]; - uinf_file = arg[6]; - usemi_file = arg[7]; - phi_file = arg[8]; + gamma_file = arg[6]; + uinf_file = arg[7]; + usemi_file = arg[8]; + phi_file = arg[9]; + + radius = 1.421*3*n / MY_2PI; + comega = 0.275*(1.0 - 1.0/(1.0 + 0.59*radius)); + ctheta = 0.35 + 0.0226*(radius - 6.785); //Parse and bcast data int me; @@ -150,14 +156,14 @@ double PairMesoCNT::spline(double x, double xstart, double dx, i = 0; // warn if argument below spline range char str[128]; - sprintf(str,"Argument below spline interval",cerror,ninput); + sprintf(str,"Argument below spline interval"); error->warning(FLERR,str); } else if(i > coeff_size-1){ i = coeff_size-1; // warn if argument above spline range char str[128]; - sprintf(str,"Argument above spline interval",cerror,ninput); + sprintf(str,"Argument above spline interval"); error->warning(FLERR,str); } @@ -170,6 +176,66 @@ double PairMesoCNT::spline(double x, double xstart, double dx, /* ---------------------------------------------------------------------- */ +double PairMesoCNT::spline(double x, double y, double *xstart, double ystart, + double *dx, double dy, double ***coeff, int coeff_size) +{ + int i = floor((y - ystart)/dy); + if(i < 0){ + i = 0; + // warn if argument below spline range + char str[128]; + sprintf(str,"Argument below spline interval"); + error->warning(FLERR,str); + } + else if(i > coeff_size-1){ + i = coeff_size-1; + // warn if argument above spline range + char str[128]; + sprintf(str,"Argument above spline interval"); + error->warning(FLERR,str); + } + + double ylo = ystart + i*dy; + double ybar = (y - ylo)/dy; + + // compute coefficients in y + + double a0, a1, a2, a3; + double p0, p1, p2, p3; + + p1 = spline(x,xstart[0],dx[0],coeff[0],coeff_size); + p2 = spline(x,xstart[1],dx[1],coeff[1],coeff_size); + + a0 = p1; + + if(i == 0){ + p3 = spline(x,xstart[2],dx[2],coeff[2],coeff_size); + + a1 = p2 - p1; + a3 = 0.5*(p3 - 2*p2 + p1); + a2 = -a3; + } + else if(i == coeff_size-2){ + p0 = spline(x,xstart[i-1],dx[i-1],coeff[i-1],coeff_size); + + a1 = 0.5*(p2 - p0); + a3 = 0.5*(p2 - 2*p1 + p0); + a2 = -2*a3; + } + else{ + p0 = spline(x,xstart[i-1],dx[i-1],coeff[i-1],coeff_size); + p3 = spline(x,xstart[2],dx[2],coeff[2],coeff_size); + + a1 = 0.5*(p2 - p0); + a2 = 0.5*(-p3 + 4*p2 - 5*p1 + 2*p0); + a3 = 0.5*(p3 - 3*p2 + 3*p1 - p0); + } + + return a0 + ybar*(a1 + ybar*(a2 + a3*ybar)); +} + +/* ---------------------------------------------------------------------- */ + double PairMesoCNT::dspline(double x, double xstart, double dx, double **coeff, int coeff_size) { @@ -178,21 +244,141 @@ double PairMesoCNT::dspline(double x, double xstart, double dx, i = 0; // warn if argument below spline range char str[128]; - sprintf(str,"Argument below spline interval",cerror,ninput); + sprintf(str,"Argument below spline interval"); error->warning(FLERR,str); } else if(i > coeff_size-1){ i = coeff_size-1; // warn if argument above spline range char str[128]; - sprintf(str,"Argument above spline interval",cerror,ninput); + sprintf(str,"Argument above spline interval"); error->warning(FLERR,str); } double xlo = xstart + i*dx; double xbar = (x - xlo)/dx; - return coeff[i][1] + xbar*(2*coeff[i][2] + 3*xbar*coeff[i][3]); + return (coeff[i][1] + xbar*(2*coeff[i][2] + 3*xbar*coeff[i][3])) / dx; +} + +/* ---------------------------------------------------------------------- */ + +double PairMesoCNT::dxspline(double x, double y, double *xstart, double ystart, + double *dx, double dy, double ***coeff, int coeff_size) +{ + int i = floor((y - ystart)/dy); + if(i < 0){ + i = 0; + // warn if argument below spline range + char str[128]; + sprintf(str,"Argument below spline interval"); + error->warning(FLERR,str); + } + else if(i > coeff_size-1){ + i = coeff_size-1; + // warn if argument above spline range + char str[128]; + sprintf(str,"Argument above spline interval"); + error->warning(FLERR,str); + } + + double ylo = ystart + i*dy; + double ybar = (y - ylo)/dy; + + // compute coefficients in y + + double a0, a1, a2, a3; + double p0, p1, p2, p3; + + p1 = dspline(x,xstart[0],dx[0],coeff[0],coeff_size); + p2 = dspline(x,xstart[1],dx[1],coeff[1],coeff_size); + + a0 = p1; + + if(i == 0){ + p3 = dspline(x,xstart[2],dx[2],coeff[2],coeff_size); + + a1 = p2 - p1; + a3 = 0.5*(p3 - 2*p2 + p1); + a2 = -a3; + } + else if(i == coeff_size-2){ + p0 = dspline(x,xstart[i-1],dx[i-1],coeff[i-1],coeff_size); + + a1 = 0.5*(p2 - p0); + a3 = 0.5*(p2 - 2*p1 + p0); + a2 = -2*a3; + } + else{ + p0 = dspline(x,xstart[i-1],dx[i-1],coeff[i-1],coeff_size); + p3 = dspline(x,xstart[2],dx[2],coeff[2],coeff_size); + + a1 = 0.5*(p2 - p0); + a2 = 0.5*(-p3 + 4*p2 - 5*p1 + 2*p0); + a3 = 0.5*(p3 - 3*p2 + 3*p1 - p0); + } + + return a0 + ybar*(a1 + ybar*(a2 + a3*ybar)); +} + +/* ---------------------------------------------------------------------- */ + +double PairMesoCNT::dyspline(double x, double y, double *xstart, double ystart, + double *dx, double dy, double ***coeff, int coeff_size) +{ + int i = floor((y - ystart)/dy); + if(i < 0){ + i = 0; + // warn if argument below spline range + char str[128]; + sprintf(str,"Argument below spline interval"); + error->warning(FLERR,str); + } + else if(i > coeff_size-1){ + i = coeff_size-1; + // warn if argument above spline range + char str[128]; + sprintf(str,"Argument above spline interval"); + error->warning(FLERR,str); + } + + double ylo = ystart + i*dy; + double ybar = (y - ylo)/dy; + + // compute coefficients in y + + double a0, a1, a2, a3; + double p0, p1, p2, p3; + + p1 = spline(x,xstart[0],dx[0],coeff[0],coeff_size); + p2 = spline(x,xstart[1],dx[1],coeff[1],coeff_size); + + a0 = p1; + + if(i == 0){ + p3 = spline(x,xstart[2],dx[2],coeff[2],coeff_size); + + a1 = p2 - p1; + a3 = 0.5*(p3 - 2*p2 + p1); + a2 = -a3; + } + else if(i == coeff_size-2){ + p0 = spline(x,xstart[i-1],dx[i-1],coeff[i-1],coeff_size); + + a1 = 0.5*(p2 - p0); + a3 = 0.5*(p2 - 2*p1 + p0); + a2 = -2*a3; + } + else{ + p0 = spline(x,xstart[i-1],dx[i-1],coeff[i-1],coeff_size); + p3 = spline(x,xstart[2],dx[2],coeff[2],coeff_size); + + a1 = 0.5*(p2 - p0); + a2 = 0.5*(-p3 + 4*p2 - 5*p1 + 2*p0); + a3 = 0.5*(p3 - 3*p2 + 3*p1 - p0); + } + + return (a1 + ybar*(2*a2 + 3*a3*ybar)) / dy; } /* ---------------------------------------------------------------------- */ @@ -375,4 +561,150 @@ void PairMesoCNT::read_file(char *file, double **data, /* ---------------------------------------------------------------------- */ +double PairMesoCNT::uinf(double h, double alpha, double xi1, double xi2) +{ + double salpha = sin(alpha); + double salphasq = salpha*salpha; + if(salphasq < 1.0e-6){ + return (xi2 - xi1) * spline(h,start_uinf,del_uinf,uinf_coeff,pot_points); + } + else{ + double omega = 1.0 / (1.0 - comega*salphasq); + double a = omega * salpha; + double zeta1 = xi1 * a; + double zeta2 = xi2 * a; + double phi1, phi2; + if(zeta1 < 0) phi1 = -spline(-zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + else phi1 = spline(zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + + if(zeta2 < 0) phi2 = -spline(-zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + else phi2 = spline(zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + + double gamma_orth = spline(h,start_gamma,del_gamma, + gamma_coeff,gamma_points); + double gamma = 1.0 + (gamma_orth - 1.0)*salphasq; + + return gamma * (phi2 - phi1) / a; + } +} + +/* ---------------------------------------------------------------------- */ + +double PairMesoCNT::usemi(double h, double alpha, + double xi1, double xi2, double etaend) +{ + double salpha = sin(alpha); + double salphasq = salpha*salpha; + double calpha = cos(alpha); + double omega = 1.0 / (1.0 - comega*salphasq); + double theta = 1.0 - ctheta*salphasq; + + int points = 100; + double delxi = (xi2 - xi1) / (points -1); + + double g, hbar, etabar; + double sum = 0; + + // first and last term in sum + + g = xi1 * omega * salpha; + hbar = sqrt(h*h + g*g); + etabar = xi1 * calpha - theta*etaend; + sum += spline(hbar,etabar,starth_usemi,startxi_usemi, + delh_usemi,delxi_usemi,usemi_coeff,pot_points); + g = xi2 * omega * salpha; + hbar = sqrt(h*h + g*g); + etabar = xi2 * calpha - theta*etaend; + sum += spline(hbar,etabar,starth_usemi,startxi_usemi, + delh_usemi,delxi_usemi,usemi_coeff,pot_points); + sum *= 0.5; + + for(int i = 1; i < points-1; i++){ + double xibar = xi1 + i*delxi; + g * xibar * omega * salpha; + hbar = sqrt(h*h + g*g); + etabar = xibar*calpha - theta*etaend; + sum += spline(hbar,etabar,starth_usemi,startxi_usemi, + delh_usemi,delxi_usemi,usemi_coeff,pot_points); + } + + double gamma_orth = spline(h,start_gamma,del_gamma, + gamma_coeff,gamma_points); + double gamma = 1.0 + (gamma_orth - 1.0)*salphasq; + + return delxi * gamma * sum; +} + +/* ---------------------------------------------------------------------- */ + +void PairMesoCNT::geom(const double *r1, const double *r2, + const double *p1, const double *p2, double *param) +{ + using namespace MathExtra; + double r[3], p[3], delr[3], l[3], m[3], rbar[3], pbar[3], delrbar[3]; + double psil[3], psim[3], dell_psim[3], delpsil_m[3]; + double delr1[3], delr2[3], delp1[3], delp2[3]; + double ex[3], ey[3]; + double psi, frac, taur, taup; + double h, alpha, xi1, xi2, eta1, eta2; + + add3(r1,r2,r); + scale3(0.5,r); + add3(p1,p2,p); + scale3(0.5,p); + + sub3(p,r,delr); + + sub3(r2,r1,l); + normalize3(l,l); + sub3(p2,p1,m); + normalize3(m,m); + + psi = dot3(l,m); + frac = 1.0 / (1.0 - psi*psi); + + copy3(l,psil); + scale3(psi,psil); + copy3(m,psim); + scale3(psi,psim); + + sub3(l,psim,dell_psim); + sub3(psil,m,delpsil_m); + taur = dot3(delr,dell_psim) * frac; + taup = dot3(delr,delpsil_m) * frac; + + scaleadd3(taur,l,r,rbar); + scaleadd3(taup,m,p,pbar); + sub3(pbar,rbar,delrbar); + + h = len3(delrbar); + + copy3(delrbar,ex); + scale3(1/h,ex); + cross3(l,ex,ey); + + if(dot3(m,ey) < 0) alpha = acos(psi); + else alpha = MY_2PI - acos(psi); + + sub3(r1,rbar,delr1); + sub3(r2,rbar,delr2); + xi1 = dot3(delr1,l); + xi2 = dot3(delr2,l); + + sub3(p1,pbar,delp1); + sub3(p2,pbar,delp2); + eta1 = dot3(delp1,m); + eta2 = dot3(delp2,m); + + param[0] = h; + param[1] = alpha; + param[2] = xi1; + param[3] = xi2; + param[4] = eta1; + param[5] = eta2; +} diff --git a/src/MESOCNT/pair_mesocnt.h b/src/MESOCNT/pair_mesocnt.h index 13147c3e12..72ce454bbc 100644 --- a/src/MESOCNT/pair_mesocnt.h +++ b/src/MESOCNT/pair_mesocnt.h @@ -18,23 +18,15 @@ class PairMesoCNT : public Pair { void compute(int, int); void settings(int, char **); void coeff(int, char **); - void init_style(); - double init_one(int, int); - void write_restart(FILE *); - void read_restart(FILE *); - - void write_restart_settings(FILE *); - void read_restart_settings(FILE *); - void write_data(FILE *); - void write_data_all(FILE *); - double single(int, int, int, int, double, double, double, double &); - void *extract(const char *, int &); - + //void init_style(); + //double init_one(int, int); + protected: int n, gamma_points, pot_points; - double sigma, epsilon, n_sigma, radius; + double sigma, epsilon, n_sigma, radius, comega, ctheta; double start_gamma, start_uinf, startxi_usemi, starth_phi; double del_gamma, del_uinf, delxi_usemi, delh_phi; + double *starth_usemi, *startzeta_phi; double *delh_usemi, *delzeta_phi; double *gamma_data, *uinf_data; double **usemi_data, **phi_data; @@ -45,16 +37,25 @@ class PairMesoCNT : public Pair { void allocate(); double spline(double, double, double, double **, int); - double spline(double, double, double *, double, double *, double ***, int); + double spline(double, double, double *, double, double *, + double, double ***, int); double dspline(double, double, double, double **, int); - double dxspline(double, double, double *, double, double *, double ***, int); - double dyspline(double, double, double *, double, double *, double ***, int); + double dxspline(double, double, double *, double, double *, + double, double ***, int); + double dyspline(double, double, double *, double, double *, + double, double ***, int); void spline_coeff(double *, double **, int); void spline_coeff(double **, double ***, int); void read_file(char *, double *, double *, int); void read_file(char *, double **, double *, double *, int); + + double uinf(double, double, double, double); + double usemi(double, double, double, double, double); + + void geom(const double *, const double *, const double *, const double *, + double *); }; } From 9aa17ec81fff1dd82f481f63dcfc20db2ae2680c Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Fri, 10 May 2019 21:50:39 +0100 Subject: [PATCH 004/392] Added first part of forces --- src/MESOCNT/pair_mesocnt.cpp | 133 ++++++++++++++++++++++++++++------- src/MESOCNT/pair_mesocnt.h | 12 ++-- 2 files changed, 116 insertions(+), 29 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index f406166fde..144c3406c6 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -561,16 +561,21 @@ void PairMesoCNT::read_file(char *file, double **data, /* ---------------------------------------------------------------------- */ -double PairMesoCNT::uinf(double h, double alpha, double xi1, double xi2) +double PairMesoCNT::uinf(double *param) { - double salpha = sin(alpha); - double salphasq = salpha*salpha; - if(salphasq < 1.0e-6){ + double h = param[0]; + double alpha = param[1]; + double xi1 = param[2]; + double xi2 = param[3]; + + double sin_alpha = sin(alpha); + double sin_alphasq = sin_alpha*sin_alpha; + if(sin_alphasq < 1.0e-6){ return (xi2 - xi1) * spline(h,start_uinf,del_uinf,uinf_coeff,pot_points); } else{ - double omega = 1.0 / (1.0 - comega*salphasq); - double a = omega * salpha; + double omega = 1.0 / (1.0 - comega*sin_alphasq); + double a = omega * sin_alpha; double zeta1 = xi1 * a; double zeta2 = xi2 * a; @@ -587,7 +592,7 @@ double PairMesoCNT::uinf(double h, double alpha, double xi1, double xi2) double gamma_orth = spline(h,start_gamma,del_gamma, gamma_coeff,gamma_points); - double gamma = 1.0 + (gamma_orth - 1.0)*salphasq; + double gamma = 1.0 + (gamma_orth - 1.0)*sin_alphasq; return gamma * (phi2 - phi1) / a; } @@ -595,14 +600,19 @@ double PairMesoCNT::uinf(double h, double alpha, double xi1, double xi2) /* ---------------------------------------------------------------------- */ -double PairMesoCNT::usemi(double h, double alpha, - double xi1, double xi2, double etaend) +double PairMesoCNT::usemi(double *param) { - double salpha = sin(alpha); - double salphasq = salpha*salpha; - double calpha = cos(alpha); - double omega = 1.0 / (1.0 - comega*salphasq); - double theta = 1.0 - ctheta*salphasq; + double h = param[0]; + double alpha = param[1]; + double xi1 = param[2]; + double xi2 = param[3]; + double etaend = param[4]; + + double sin_alpha = sin(alpha); + double sin_alphasq = sin_alpha*sin_alpha; + double cos_alpha = cos(alpha); + double omega = 1.0 / (1.0 - comega*sin_alphasq); + double theta = 1.0 - ctheta*sin_alphasq; int points = 100; double delxi = (xi2 - xi1) / (points -1); @@ -612,47 +622,121 @@ double PairMesoCNT::usemi(double h, double alpha, // first and last term in sum - g = xi1 * omega * salpha; + g = xi1 * omega * sin_alpha; hbar = sqrt(h*h + g*g); - etabar = xi1 * calpha - theta*etaend; + etabar = xi1 * cos_alpha - theta*etaend; sum += spline(hbar,etabar,starth_usemi,startxi_usemi, delh_usemi,delxi_usemi,usemi_coeff,pot_points); - g = xi2 * omega * salpha; + g = xi2 * omega * sin_alpha; hbar = sqrt(h*h + g*g); - etabar = xi2 * calpha - theta*etaend; + etabar = xi2 * cos_alpha - theta*etaend; sum += spline(hbar,etabar,starth_usemi,startxi_usemi, delh_usemi,delxi_usemi,usemi_coeff,pot_points); sum *= 0.5; + // remaining sum + for(int i = 1; i < points-1; i++){ double xibar = xi1 + i*delxi; - g * xibar * omega * salpha; + g * xibar * omega * sin_alpha; hbar = sqrt(h*h + g*g); - etabar = xibar*calpha - theta*etaend; + etabar = xibar*cos_alpha - theta*etaend; sum += spline(hbar,etabar,starth_usemi,startxi_usemi, delh_usemi,delxi_usemi,usemi_coeff,pot_points); } double gamma_orth = spline(h,start_gamma,del_gamma, gamma_coeff,gamma_points); - double gamma = 1.0 + (gamma_orth - 1.0)*salphasq; + double gamma = 1.0 + (gamma_orth - 1.0)*sin_alphasq; return delxi * gamma * sum; } /* ---------------------------------------------------------------------- */ +void PairMesoCNT::finf(double *param, double **f) +{ + double h = param[0]; + double alpha = param[1]; + double xi1 = param[2]; + double xi2 = param[3]; + + double sin_alpha = sin(alpha); + double sin_alphasq = sin_alpha*sin_alpha; + double sin_alpharec = 1.0 / sin_alpha; + double sin_alpharecsq = sin_alpharec * sin_alpharec; + double cos_alpha = cos(alpha); + double cot_alpha = cos_alpha * sin_alpharec; + + double omega = 1.0 / (1.0 - comega*sin_alphasq); + double domega = 2 * comega * sin_alpha * cos_alpha * omega * omega; + double a1 = omega * sin_alpha; + double a1rec = 1.0 / a1; + + double gamma_orth = spline(h,start_gamma,del_gamma, + gamma_coeff,gamma_points); + double gamma = 1.0 + (gamma_orth - 1.0)*sin_alphasq; + double gammarec = 1.0 / gamma; + double dalpha_gamma = 2 * (gamma_orth - 1) * sin_alpha * cos_alpha; + double dh_gamma = dspline(h,start_gamma,del_gamma, + gamma_coeff,gamma_points) * sin_alphasq; + + + double zeta1 = xi1 * a1; + double zeta2 = xi2 * a1; + double phi1 = spline(zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + double phi2 = spline(zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + double dzeta_phi1 = dxspline(zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + double dzeta_phi2 = dxspline(zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + double diff_dzeta_phi = dzeta_phi2 - dzeta_phi1; + double dh_phi1 = dyspline(zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + double dh_phi2 = dyspline(zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + + double a2 = gamma * a1rec; + double u = a2 * (phi2 - phi1); + double a3 = u * gammarec; + + double dh_u = dh_gamma * a3 + a2 * (dh_phi2 - dh_phi1); + double dalpha_u = dalpha_gamma * a3 + + a2 * (domega*sin_alpha + omega*cos_alpha) + * (gamma*(xi2*dzeta_phi2 - xi1*dzeta_phi1) - u); + + double lrec = 1.0 / (xi2 - xi1); + double cx = h * gamma * sin_alpharecsq * diff_dzeta_phi; + double cy = gamma * cot_alpha * diff_dzeta_phi; + + f[0][0] = lrec * (xi2*dh_u - cx); + f[1][0] = lrec * (-xi1*dh_u + cx); + f[0][1] = lrec * (dalpha_u - xi2*cy); + f[1][1] = lrec * (-dalpha_u + xi2*cy); + f[0][2] = gamma * dzeta_phi1; + f[1][2] = -gamma * dzeta_phi2; +} + +/* ---------------------------------------------------------------------- */ + void PairMesoCNT::geom(const double *r1, const double *r2, - const double *p1, const double *p2, double *param) + const double *p1, const double *p2, + double *param, double **basis) { using namespace MathExtra; double r[3], p[3], delr[3], l[3], m[3], rbar[3], pbar[3], delrbar[3]; double psil[3], psim[3], dell_psim[3], delpsil_m[3]; double delr1[3], delr2[3], delp1[3], delp2[3]; - double ex[3], ey[3]; + double *ex, *ey, *ez; double psi, frac, taur, taup; double h, alpha, xi1, xi2, eta1, eta2; + ex = basis[0]; + ey = basis[1]; + ez = basis[2]; + add3(r1,r2,r); scale3(0.5,r); add3(p1,p2,p); @@ -685,8 +769,9 @@ void PairMesoCNT::geom(const double *r1, const double *r2, h = len3(delrbar); copy3(delrbar,ex); + copy3(l,ez); scale3(1/h,ex); - cross3(l,ex,ey); + cross3(ez,ex,ey); if(dot3(m,ey) < 0) alpha = acos(psi); else alpha = MY_2PI - acos(psi); diff --git a/src/MESOCNT/pair_mesocnt.h b/src/MESOCNT/pair_mesocnt.h index 72ce454bbc..a10beb329d 100644 --- a/src/MESOCNT/pair_mesocnt.h +++ b/src/MESOCNT/pair_mesocnt.h @@ -18,8 +18,8 @@ class PairMesoCNT : public Pair { void compute(int, int); void settings(int, char **); void coeff(int, char **); - //void init_style(); - //double init_one(int, int); + void init_style(); + double init_one(int, int); protected: int n, gamma_points, pot_points; @@ -51,11 +51,13 @@ class PairMesoCNT : public Pair { void read_file(char *, double *, double *, int); void read_file(char *, double **, double *, double *, int); - double uinf(double, double, double, double); - double usemi(double, double, double, double, double); + double uinf(double *); + double usemi(double *); + void finf(double *, double **); + void fsemi(double *, double **); void geom(const double *, const double *, const double *, const double *, - double *); + double *, double **); }; } From 6538629584870cadfc4b67a8e49789c98565abfd Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Sat, 11 May 2019 13:08:17 +0100 Subject: [PATCH 005/392] Added forces, spline ranges for file reading --- src/MESOCNT/pair_mesocnt.cpp | 239 +++++++++++++++++++++++++---------- src/MESOCNT/pair_mesocnt.h | 9 +- 2 files changed, 179 insertions(+), 69 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index 144c3406c6..4af1ca7784 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -22,6 +22,7 @@ using namespace LAMMPS_NS; using namespace MathConst; #define MAXLINE 1024 +#define SMALL 1.0e-6 /* ---------------------------------------------------------------------- */ @@ -125,10 +126,12 @@ void PairMesoCNT::coeff(int narg, char **arg) int me; MPI_Comm_rank(world,&me); if (me == 0) { - read_file(gamma_file,gamma_data,&del_gamma,gamma_points); - read_file(uinf_file,uinf_data,&del_uinf,pot_points); - read_file(usemi_file,usemi_data,delh_usemi,&delxi_usemi,pot_points); - read_file(phi_file,phi_data,delzeta_phi,&delh_phi,pot_points); + read_file(gamma_file,gamma_data,&start_gamma,&del_gamma,gamma_points); + read_file(uinf_file,uinf_data,&start_uinf,&del_uinf,pot_points); + read_file(usemi_file,usemi_data,starth_usemi,&startxi_usemi, + delh_usemi,&delxi_usemi,pot_points); + read_file(phi_file,phi_data,startzeta_phi,&starth_phi, + delzeta_phi,&delh_phi,pot_points); } MPI_Bcast(gamma_data,gamma_points,MPI_DOUBLE,0,world); @@ -439,7 +442,8 @@ void PairMesoCNT::spline_coeff(double **data, double ***coeff, int data_size) /* ---------------------------------------------------------------------- */ -void PairMesoCNT::read_file(char *file, double *data, double *dx, int ninput) +void PairMesoCNT::read_file(char *file, double *data, + double *startx, double *dx, int ninput) { char line[MAXLINE]; @@ -464,6 +468,7 @@ void PairMesoCNT::read_file(char *file, double *data, double *dx, int ninput) if(NULL == fgets(line,MAXLINE,fp)) error->one(FLERR,"Premature end of file in pair table"); if(2 != sscanf(line,"%lg %lg",&x, &data[i])) ++cerror; + if(i == 0) *startx = x; if(i > 0){ if(i == 1) *dx = x - xtemp; if(*dx != x - xtemp) ++serror; @@ -493,7 +498,8 @@ void PairMesoCNT::read_file(char *file, double *data, double *dx, int ninput) /* ---------------------------------------------------------------------- */ void PairMesoCNT::read_file(char *file, double **data, - double *dx, double *dy, int ninput) + double *startx, double *starty, double *dx, double *dy, + int ninput) { char line[MAXLINE]; @@ -514,18 +520,20 @@ void PairMesoCNT::read_file(char *file, double **data, double x,y,xtemp,ytemp; utils::sfgets(FLERR,line,MAXLINE,fp,file,error); - for(int i = 0; i < ninput; i++){ + for(int i = 0; i < ninput; i++){ if(i > 0) ytemp = y; for(int j = 0; j < ninput; j++){ if(j > 0) xtemp = x; if(NULL == fgets(line,MAXLINE,fp)) error->one(FLERR,"Premature end of file in pair table"); if(3 != sscanf(line,"%lg %lg %lg",&x,&y,&data[j][i])) ++cerror; + if(j == 0) startx[i] = x; if(j > 0){ if(j == 1) dx[i] = x - xtemp; if(dx[i] != x - xtemp) ++sxerror; } } + if(i == 0) *starty = y; if(i > 0){ if(i == 1) *dy = y - ytemp; if(*dy != y - ytemp) ++syerror; @@ -570,7 +578,7 @@ double PairMesoCNT::uinf(double *param) double sin_alpha = sin(alpha); double sin_alphasq = sin_alpha*sin_alpha; - if(sin_alphasq < 1.0e-6){ + if(sin_alphasq < SMALL){ return (xi2 - xi1) * spline(h,start_uinf,del_uinf,uinf_coeff,pot_points); } else{ @@ -614,34 +622,24 @@ double PairMesoCNT::usemi(double *param) double omega = 1.0 / (1.0 - comega*sin_alphasq); double theta = 1.0 - ctheta*sin_alphasq; + double a1 = omega * sin_alpha; + double a2 = theta * etaend; + int points = 100; double delxi = (xi2 - xi1) / (points -1); - double g, hbar, etabar; double sum = 0; - // first and last term in sum - - g = xi1 * omega * sin_alpha; - hbar = sqrt(h*h + g*g); - etabar = xi1 * cos_alpha - theta*etaend; - sum += spline(hbar,etabar,starth_usemi,startxi_usemi, - delh_usemi,delxi_usemi,usemi_coeff,pot_points); - g = xi2 * omega * sin_alpha; - hbar = sqrt(h*h + g*g); - etabar = xi2 * cos_alpha - theta*etaend; - sum += spline(hbar,etabar,starth_usemi,startxi_usemi, - delh_usemi,delxi_usemi,usemi_coeff,pot_points); - sum *= 0.5; - - // remaining sum - - for(int i = 1; i < points-1; i++){ + for(int i = 0; i < points; i++){ double xibar = xi1 + i*delxi; - g * xibar * omega * sin_alpha; - hbar = sqrt(h*h + g*g); - etabar = xibar*cos_alpha - theta*etaend; - sum += spline(hbar,etabar,starth_usemi,startxi_usemi, + double g = xibar * a1; + double hbar = sqrt(h*h + g*g); + double zetabar = xibar*cos_alpha - a2; + + double c = 1.0; + if(i == 0 || i == points-1) c = 0.5; + + sum += c * spline(hbar,zetabar,starth_usemi,startxi_usemi, delh_usemi,delxi_usemi,usemi_coeff,pot_points); } @@ -661,17 +659,103 @@ void PairMesoCNT::finf(double *param, double **f) double xi1 = param[2]; double xi2 = param[3]; + double sin_alpha = sin(alpha); + double sin_alphasq = sin_alpha*sin_alpha; + + if(sin_alphasq < SMALL){ + f[0][0] = -0.5*(xi2 - xi1)*dspline(h,start_uinf,del_uinf, + uinf_coeff,pot_points); + f[1][0] = f[0][0]; + f[0][1] = 0; + f[1][1] = 0; + f[0][2] = spline(h,start_uinf,del_uinf,uinf_coeff,pot_points); + f[1][2] = -f[0][2]; + } + else{ + double sin_alpharec = 1.0 / sin_alpha; + double sin_alpharecsq = sin_alpharec * sin_alpharec; + double cos_alpha = cos(alpha); + double cot_alpha = cos_alpha * sin_alpharec; + + double omega = 1.0 / (1.0 - comega*sin_alphasq); + double domega = 2 * comega * sin_alpha * cos_alpha * omega * omega; + double a1 = omega * sin_alpha; + double a1rec = 1.0 / a1; + + double gamma_orth = spline(h,start_gamma,del_gamma, + gamma_coeff,gamma_points); + double gamma = 1.0 + (gamma_orth - 1.0)*sin_alphasq; + double gammarec = 1.0 / gamma; + double dalpha_gamma = 2 * (gamma_orth - 1) * sin_alpha * cos_alpha; + double dh_gamma = dspline(h,start_gamma,del_gamma, + gamma_coeff,gamma_points) * sin_alphasq; + + + double zeta1 = xi1 * a1; + double zeta2 = xi2 * a1; + double phi1 = spline(zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + double phi2 = spline(zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + double dzeta_phi1 = dxspline(zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + double dzeta_phi2 = dxspline(zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + double diff_dzeta_phi = dzeta_phi2 - dzeta_phi1; + double dh_phi1 = dyspline(zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + double dh_phi2 = dyspline(zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + + double a2 = gamma * a1rec; + double u = a2 * (phi2 - phi1); + double a3 = u * gammarec; + + double dh_u = dh_gamma * a3 + a2 * (dh_phi2 - dh_phi1); + double dalpha_u = dalpha_gamma * a3 + + a2 * (domega*sin_alpha + omega*cos_alpha) + * (gamma*(xi2*dzeta_phi2 - xi1*dzeta_phi1) - u); + + double lrec = 1.0 / (xi2 - xi1); + double cx = h * gamma * sin_alpharecsq * diff_dzeta_phi; + double cy = gamma * cot_alpha * diff_dzeta_phi; + + f[0][0] = lrec * (xi2*dh_u - cx); + f[1][0] = lrec * (-xi1*dh_u + cx); + f[0][1] = lrec * (dalpha_u - xi2*cy); + f[1][1] = lrec * (-dalpha_u + xi2*cy); + f[0][2] = gamma * dzeta_phi1; + f[1][2] = -gamma * dzeta_phi2; + } +} + +/* ---------------------------------------------------------------------- */ + +void PairMesoCNT::fsemi(double *param, double **f) +{ + double h = param[0]; + double alpha = param[1]; + double xi1 = param[2]; + double xi2 = param[3]; + double etaend = param[4]; + double sin_alpha = sin(alpha); double sin_alphasq = sin_alpha*sin_alpha; double sin_alpharec = 1.0 / sin_alpha; double sin_alpharecsq = sin_alpharec * sin_alpharec; double cos_alpha = cos(alpha); - double cot_alpha = cos_alpha * sin_alpharec; double omega = 1.0 / (1.0 - comega*sin_alphasq); + double omegasq = omega * omega; double domega = 2 * comega * sin_alpha * cos_alpha * omega * omega; + + double theta = 1.0 - ctheta*sin_alphasq; + double dtheta = -2 * ctheta * sin_alpha * cos_alpha; + double a1 = omega * sin_alpha; + double a1sq = a1 * a1; double a1rec = 1.0 / a1; + double a2 = theta * etaend; double gamma_orth = spline(h,start_gamma,del_gamma, gamma_coeff,gamma_points); @@ -680,43 +764,68 @@ void PairMesoCNT::finf(double *param, double **f) double dalpha_gamma = 2 * (gamma_orth - 1) * sin_alpha * cos_alpha; double dh_gamma = dspline(h,start_gamma,del_gamma, gamma_coeff,gamma_points) * sin_alphasq; - - - double zeta1 = xi1 * a1; - double zeta2 = xi2 * a1; - double phi1 = spline(zeta1,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); - double phi2 = spline(zeta2,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); - double dzeta_phi1 = dxspline(zeta1,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); - double dzeta_phi2 = dxspline(zeta2,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); - double diff_dzeta_phi = dzeta_phi2 - dzeta_phi1; - double dh_phi1 = dyspline(zeta1,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); - double dh_phi2 = dyspline(zeta2,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); - - double a2 = gamma * a1rec; - double u = a2 * (phi2 - phi1); - double a3 = u * gammarec; + + int points = 100; + double delxi = (xi2 - xi1) / (points -1); + double a3 = delxi * gamma; - double dh_u = dh_gamma * a3 + a2 * (dh_phi2 - dh_phi1); - double dalpha_u = dalpha_gamma * a3 - + a2 * (domega*sin_alpha + omega*cos_alpha) - * (gamma*(xi2*dzeta_phi2 - xi1*dzeta_phi1) - u); + double jh = 0; + double jh1 = 0; + double jh2 = 0; + double jxi = 0; + double jxi1 = 0; + double ubar = 0; + + for(int i = 0; i < points; i++){ + double xibar = xi1 + i*delxi; + double g = xibar * a1; + double hbar = sqrt(h*h + g*g); + double zetabar = xibar*cos_alpha - a2; + + double c = 1.0; + if(i == 0 || i == points-1) c = 0.5; + + double u = c * spline(hbar,zetabar,starth_usemi,startxi_usemi, + delh_usemi,delxi_usemi,usemi_coeff,pot_points); + double uh = c / hbar * dxspline(hbar,zetabar,starth_usemi,startxi_usemi, + delh_usemi,delxi_usemi,usemi_coeff,pot_points); + double uxi = c * dyspline(hbar,zetabar,starth_usemi,startxi_usemi, + delh_usemi,delxi_usemi,usemi_coeff,pot_points); + + double uh1 = xibar * uh; + jh += uh; + jh1 += uh1; + jh2 += xibar * uh1; + jxi += uxi; + jxi1 += xibar * uxi; + ubar += u; + } + + jh *= a3; + jh1 *= a3; + jh2 *= a3; + jxi *= a3; + jxi1 *= a3; + ubar *= a3; + + double a4 = gammarec * ubar; + double dh_ubar = dh_gamma*a4 + h*jh; + double dalpha_ubar = dalpha_gamma*a4 + + a1*(domega*sin_alpha + omega*cos_alpha)*jh2 + - sin_alpha * jxi1 - dtheta*etaend*jxi; + + double cx = h * (omegasq*jh1 + cos_alpha*ctheta*jxi); + double cy = sin_alpha * (cos_alpha*omegasq*jh1 + (ctheta-1)*jxi); + double cz1 = a1sq*jh1 + cos_alpha*jxi; + double cz2 = a1sq*jh2 + cos_alpha*jxi1; double lrec = 1.0 / (xi2 - xi1); - double cx = h * gamma * sin_alpharecsq * diff_dzeta_phi; - double cy = gamma * cot_alpha * diff_dzeta_phi; - - f[0][0] = lrec * (xi2*dh_u - cx); - f[1][0] = lrec * (-xi1*dh_u + cx); - f[0][1] = lrec * (dalpha_u - xi2*cy); - f[1][1] = lrec * (-dalpha_u + xi2*cy); - f[0][2] = gamma * dzeta_phi1; - f[1][2] = -gamma * dzeta_phi2; + f[0][0] = lrec * (xi2*dh_ubar - cx); + f[1][0] = lrec * (cx - xi1*dh_ubar); + f[0][1] = lrec * (dalpha_ubar - xi2*cy); + f[1][1] = lrec * (xi1*cy - dalpha_ubar); + f[0][2] = lrec * (cz2 + ubar - xi2*cz1); + f[1][2] = lrec * (xi1*cz1 - cz2 - ubar); } /* ---------------------------------------------------------------------- */ diff --git a/src/MESOCNT/pair_mesocnt.h b/src/MESOCNT/pair_mesocnt.h index a10beb329d..e35f107f0e 100644 --- a/src/MESOCNT/pair_mesocnt.h +++ b/src/MESOCNT/pair_mesocnt.h @@ -48,16 +48,17 @@ class PairMesoCNT : public Pair { void spline_coeff(double *, double **, int); void spline_coeff(double **, double ***, int); - void read_file(char *, double *, double *, int); - void read_file(char *, double **, double *, double *, int); + void read_file(char *, double *, double *, double *, int); + void read_file(char *, double **, double *, double *, + double *, double *, int); double uinf(double *); double usemi(double *); void finf(double *, double **); void fsemi(double *, double **); - void geom(const double *, const double *, const double *, const double *, - double *, double **); + void geom(const double *, const double *, const double *, + const double *, double *, double **); }; } From 565be0baed640dd4f0b958626400956b9087fe0b Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Mon, 13 May 2019 17:24:36 +0100 Subject: [PATCH 006/392] Compute complete, compiles with LAMMPS, pre-debug --- src/MESOCNT/pair_mesocnt.cpp | 240 ++++++++++++++++++++++++++++++++++- src/MESOCNT/pair_mesocnt.h | 6 +- 2 files changed, 244 insertions(+), 2 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index 4af1ca7784..edc62cefe0 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -58,12 +58,210 @@ PairMesoCNT::~PairMesoCNT() void PairMesoCNT::compute(int eflag, int vflag) { + int inum,i1,i2,jj,jj1,jj2,j1num,j2num,numred,inflag,n; + double evdwl; + double *r1,*r2,*p1,*p2,*q1,*q2,*param,**flocal,**basis; + int *ilist,*j1list,*j2list,*numneigh,**firstneigh; + int *redlist,*nchain,*end; + int **chain; + + evdwl = 0.0; + ev_init(eflag,vflag); + + double **x = atom->x; + double **f = atom->f; + int **bondlist = neighbor->bondlist; + int *tag = atom->tag; + int *mol = atom->molecule; + int nbondlist = neighbor->nbondlist; + int nlocal = atom->nlocal; + + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + memory->create(p1,3,"pair:p1"); + memory->create(p2,3,"pair:p2"); + memory->create(q1,3,"pair:q1"); + memory->create(q2,3,"pair:q2"); + memory->create(param,6,"pair:param"); + memory->create(flocal,2,3,"pair:flocal"); + memory->create(basis,3,3,"pair:basis"); + + for(n = 0; n < nbondlist; n++){ + i1 = bondlist[n][0]; + i2 = bondlist[n][1]; + + r1 = x[i1]; + r2 = x[i2]; + + // reduce neighbors to common list + + j1list = firstneigh[i1]; + j2list = firstneigh[i2]; + j1num = numneigh[i1]; + j2num = numneigh[i2]; + + memory->create(redlist,j1num+j2num,"pair:redlist"); + numred = 0; + for(jj1 = 0; jj1 < j1num; jj1++) redlist[numred++] = j1list[jj1]; + for(jj2 = 0; jj2 < j2num; jj2++){ + for(jj1 = 0; jj1 < j1num; jj1++){ + if(j1list[jj1] == j2list[jj2]){ + inflag = 1; + break; + } + } + if(inflag){ + inflag = 0; + continue; + } + redlist[numred++] = j2list[jj2]; + } + + // insertion sort according to atom-id + + for(int mm = 1; mm < numred; mm++){ + int m = mm; + int loc1 = redlist[m-1]; + int loc2 = redlist[m]; + while(m > 0 && tag[loc1] > tag[loc2]){ + loc1 = redlist[m-1]; + loc2 = redlist[m]; + m--; + redlist[m] = loc1; + redlist[m-1]; + } + } + + // split into connected chains + + int cid = 0; + int cnum = 0; + memory->create(chain,numred,numred,"pair:chain"); + memory->create(nchain,numred,"pair:numred"); + for(jj = 0; jj < numred-1; jj++){ + int j = redlist[jj]; + chain[cid][cnum++] = j; + if(abs(tag[j] - tag[j+1]) != 1 || mol[j] != mol[j+1]){ + nchain[cid++] = cnum; + cnum = 0; + } + } + chain[cid][cnum++] = redlist[numred-1]; + nchain[cid++] = cnum; + + // check for ends + + memory->create(end,cid,"pair:end"); + for(int i = 0; i < cid; i++){ + int cn = nchain[i]; + int tag1 = tag[chain[i][0]]; + int tag2 = tag[chain[i][cn-1]]; + if(tag1 == 1) end[i] = 1; + else{ + int idprev = atom->map(tag1-1); + if(idprev == -1 || mol[chain[i][0]] != mol[idprev]) end[i] = 1; + } + if(tag2 == atom->natoms) end[i] = 2; + else{ + int idnext = atom->map(tag2+1); + if(idnext == -1 || mol[chain[i][0]] != mol[idnext]) end[i] = 2; + } + } + + // compute subsitute chains, forces and energies + + using namespace MathExtra; + double w,sumwreq,sumw; + + for(int i = 0; i < cid; i++){ + zero3(p1); + zero3(p2); + sumw = 0; + for(int j = 0; j < nchain[i]-1; j++){ + q1 = x[chain[i][j]]; + q2 = x[chain[i][j+1]]; + w = weight(r1,r2,q1,q2); + sumw += w; + for(int ax = 0; ax < 3; ax++){ + p1[ax] += w * q1[ax]; + p2[ax] += w * q2[ax]; + } + } + sumwreq = 1 / sumw; + scale3(sumwreq,p1); + scale3(sumwreq,p2); + + if(end[i] == 1){ + geom(r1,r2,p1,p2,param,basis); + fsemi(param,flocal); + } + else if(end[i] == 2){ + geom(r1,r2,p2,p1,param,basis); + fsemi(param,flocal); + } + else{ + geom(r1,r2,p2,p1,param,basis); + finf(param,flocal); + } + + if(eflag){ + if(end[i] == 0) evdwl = uinf(param); + else evdwl = usemi(param); + } + + f[i1][0] += flocal[0][0]*basis[0][0] + + flocal[0][1]*basis[0][1] + + flocal[0][2]*basis[0][2]; + f[i1][1] += flocal[0][0]*basis[1][0] + + flocal[0][1]*basis[1][1] + + flocal[0][2]*basis[1][2]; + f[i1][2] += flocal[0][0]*basis[2][0] + + flocal[0][1]*basis[2][1] + + flocal[0][2]*basis[2][2]; + f[i2][0] += flocal[1][0]*basis[0][0] + + flocal[1][1]*basis[0][1] + + flocal[1][2]*basis[0][2]; + f[i2][1] += flocal[1][0]*basis[1][0] + + flocal[1][1]*basis[1][1] + + flocal[1][2]*basis[1][2]; + f[i2][2] += flocal[1][0]*basis[2][0] + + flocal[1][1]*basis[2][1] + + flocal[1][2]*basis[2][2]; + } + + memory->destroy(redlist); + memory->destroy(chain); + memory->destroy(nchain); + memory->destroy(end); + } + + memory->destroy(p1); + memory->destroy(p2); + memory->destroy(q1); + memory->destroy(q2); + memory->destroy(param); + memory->destroy(flocal); + memory->destroy(basis); } /* ---------------------------------------------------------------------- */ +void PairMesoCNT::init_style() +{ + int irequest; + irequest = neighbor->request(this,instance_me); +} +/* ---------------------------------------------------------------------- */ + +double PairMesoCNT::init_one(int i, int j) +{ + return 0; +} /* ---------------------------------------------------------------------- allocate all arrays @@ -119,6 +317,8 @@ void PairMesoCNT::coeff(int narg, char **arg) phi_file = arg[9]; radius = 1.421*3*n / MY_2PI; + radiussq = radius * radius; + rc = 3 * sigma; comega = 0.275*(1.0 - 1.0/(1.0 + 0.59*radius)); ctheta = 0.35 + 0.0226*(radius - 6.785); @@ -135,7 +335,9 @@ void PairMesoCNT::coeff(int narg, char **arg) } MPI_Bcast(gamma_data,gamma_points,MPI_DOUBLE,0,world); - MPI_Bcast(uinf_data,pot_points,MPI_DOUBLE,0,world); + MPI_Bcast(uinf_data,pot_points,MPI_DOUBLE,0,world); + MPI_Bcast(starth_usemi,pot_points,MPI_DOUBLE,0,world); + MPI_Bcast(startzeta_phi,pot_points,MPI_DOUBLE,0,world); MPI_Bcast(delh_usemi,pot_points,MPI_DOUBLE,0,world); MPI_Bcast(delzeta_phi,pot_points,MPI_DOUBLE,0,world); for(int i = 0; i < pot_points; i++){ @@ -902,3 +1104,39 @@ void PairMesoCNT::geom(const double *r1, const double *r2, param[4] = eta1; param[5] = eta2; } + +/* ---------------------------------------------------------------------- */ + +double PairMesoCNT::weight(const double *r1, const double *r2, + const double *p1, const double *p2) +{ + using namespace MathExtra; + double r[3], p[3], delr[3], delp[3], delrp[3]; + double rho, rhoc, rhomin; + + add3(r1,r2,r); + add3(p1,p2,p); + + rhoc = sqrt(0.25*distsq3(r1,r2) + radiussq) + + sqrt(0.25*distsq3(p1,p2) + radiussq) + rc; + rhomin = 1.39 * rhoc; + rho = 0.5 * sqrt(distsq3(r,p)); + + return s((rho - rhomin)/(rhoc - rhomin)); +} + +/* ---------------------------------------------------------------------- */ + +int PairMesoCNT::heaviside(double x) +{ + if(x < 0) return 0; + else return 1; +} + +/* ---------------------------------------------------------------------- */ + +double PairMesoCNT::s(double x) +{ + return heaviside(-x) + heaviside(x)*heaviside(1-x)*(1 - x*x*(3 - 2*x)); +} + diff --git a/src/MESOCNT/pair_mesocnt.h b/src/MESOCNT/pair_mesocnt.h index e35f107f0e..474506c00f 100644 --- a/src/MESOCNT/pair_mesocnt.h +++ b/src/MESOCNT/pair_mesocnt.h @@ -23,7 +23,7 @@ class PairMesoCNT : public Pair { protected: int n, gamma_points, pot_points; - double sigma, epsilon, n_sigma, radius, comega, ctheta; + double sigma, epsilon, n_sigma, radius, radiussq, rc, rc0, comega, ctheta; double start_gamma, start_uinf, startxi_usemi, starth_phi; double del_gamma, del_uinf, delxi_usemi, delh_phi; double *starth_usemi, *startzeta_phi; @@ -59,6 +59,10 @@ class PairMesoCNT : public Pair { void geom(const double *, const double *, const double *, const double *, double *, double **); + double weight(const double *, const double *, + const double *, const double *); + int heaviside(double); + double s(double x); }; } From c8897acf71dc110b8326aa53259bc0b5a3ddcfe8 Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Mon, 13 May 2019 21:24:44 +0100 Subject: [PATCH 007/392] Fixed file reading issue --- src/MESOCNT/pair_mesocnt.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index edc62cefe0..9ba68cb30b 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -316,7 +316,7 @@ void PairMesoCNT::coeff(int narg, char **arg) usemi_file = arg[8]; phi_file = arg[9]; - radius = 1.421*3*n / MY_2PI; + radius = 1.421*3*n / MY_2PI / force->angstrom; radiussq = radius * radius; rc = 3 * sigma; comega = 0.275*(1.0 - 1.0/(1.0 + 0.59*radius)); @@ -328,6 +328,7 @@ void PairMesoCNT::coeff(int narg, char **arg) if (me == 0) { read_file(gamma_file,gamma_data,&start_gamma,&del_gamma,gamma_points); read_file(uinf_file,uinf_data,&start_uinf,&del_uinf,pot_points); + printf("1D files read\n"); read_file(usemi_file,usemi_data,starth_usemi,&startxi_usemi, delh_usemi,&delxi_usemi,pot_points); read_file(phi_file,phi_data,startzeta_phi,&starth_phi, @@ -664,11 +665,13 @@ void PairMesoCNT::read_file(char *file, double *data, int serror = 0; double x,xtemp; - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); for(int i = 0; i < ninput; i++){ if(i > 0) xtemp = x; - if(NULL == fgets(line,MAXLINE,fp)) - error->one(FLERR,"Premature end of file in pair table"); + if(NULL == fgets(line,MAXLINE,fp)){ + std::string str("Premature end of file in pair table "); + str += file; + error->one(FLERR,str.c_str()); + } if(2 != sscanf(line,"%lg %lg",&x, &data[i])) ++cerror; if(i == 0) *startx = x; if(i > 0){ @@ -721,13 +724,15 @@ void PairMesoCNT::read_file(char *file, double **data, int syerror = 0; double x,y,xtemp,ytemp; - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); for(int i = 0; i < ninput; i++){ if(i > 0) ytemp = y; for(int j = 0; j < ninput; j++){ if(j > 0) xtemp = x; - if(NULL == fgets(line,MAXLINE,fp)) - error->one(FLERR,"Premature end of file in pair table"); + if(NULL == fgets(line,MAXLINE,fp)){ + std::string str("Premature end of file in pair table "); + str += file; + error->one(FLERR,str.c_str()); + } if(3 != sscanf(line,"%lg %lg %lg",&x,&y,&data[j][i])) ++cerror; if(j == 0) startx[i] = x; if(j > 0){ From 19e54c23ddd3b6f300c901e35da0b49b851d9db1 Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Tue, 14 May 2019 12:01:28 +0100 Subject: [PATCH 008/392] Added correct units for lengths and energies --- src/MESOCNT/pair_mesocnt.cpp | 111 ++++++++++++++++++++++------------- src/MESOCNT/pair_mesocnt.h | 1 + 2 files changed, 72 insertions(+), 40 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index 9ba68cb30b..9ba5b6bc77 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "pair_mesocnt.h" #include "atom.h" #include "comm.h" @@ -41,6 +42,8 @@ PairMesoCNT::~PairMesoCNT() if (allocated) { memory->destroy(gamma_data); memory->destroy(uinf_data); + memory->destroy(starth_usemi); + memory->destroy(startzeta_phi); memory->destroy(delh_usemi); memory->destroy(delzeta_phi); @@ -273,16 +276,18 @@ void PairMesoCNT::allocate() memory->create(gamma_data,gamma_points,"pair:gamma_data"); memory->create(uinf_data,pot_points,"pair:uinf_data"); + memory->create(starth_usemi,pot_points,"pair:starth_usemi"); + memory->create(startzeta_phi,pot_points,"pair:startzeta_phi"); memory->create(delh_usemi,pot_points,"pair:delh_usemi"); memory->create(delzeta_phi,pot_points,"pair:delzeta_phi"); memory->create(usemi_data,pot_points,pot_points,"pair:usemi_data"); memory->create(phi_data,pot_points,pot_points,"pair:phi_data"); - memory->create(gamma_coeff,gamma_points-1,4,"pair:gamma_coeff"); - memory->create(uinf_coeff,pot_points-1,4,"pair:uinf_coeff"); + memory->create(gamma_coeff,gamma_points,4,"pair:gamma_coeff"); + memory->create(uinf_coeff,pot_points,4,"pair:uinf_coeff"); - memory->create(usemi_coeff,pot_points,pot_points-1,4,"pair:usemi_coeff"); - memory->create(phi_coeff,pot_points,pot_points-1,4,"pair:phi_coeff"); + memory->create(usemi_coeff,pot_points,pot_points,4,"pair:usemi_coeff"); + memory->create(phi_coeff,pot_points,pot_points,4,"pair:phi_coeff"); } /* ---------------------------------------------------------------------- @@ -316,11 +321,17 @@ void PairMesoCNT::coeff(int narg, char **arg) usemi_file = arg[8]; phi_file = arg[9]; - radius = 1.421*3*n / MY_2PI / force->angstrom; + angstrom = force->angstrom; + angstromrec = 1 / angstrom; + qelectron = force->qelectron; + qelectronrec = 1 / qelectron; + forceunit = qelectron * angstromrec; + + radius = 1.421*3*n / MY_2PI * angstrom; radiussq = radius * radius; rc = 3 * sigma; - comega = 0.275*(1.0 - 1.0/(1.0 + 0.59*radius)); - ctheta = 0.35 + 0.0226*(radius - 6.785); + comega = 0.275*(1.0 - 1.0/(1.0 + 0.59*radius/angstrom)); + ctheta = 0.35 + 0.0226*(radius/angstrom - 6.785); //Parse and bcast data int me; @@ -333,6 +344,7 @@ void PairMesoCNT::coeff(int narg, char **arg) delh_usemi,&delxi_usemi,pot_points); read_file(phi_file,phi_data,startzeta_phi,&starth_phi, delzeta_phi,&delh_phi,pot_points); + printf("2D files read\n"); } MPI_Bcast(gamma_data,gamma_points,MPI_DOUBLE,0,world); @@ -346,10 +358,29 @@ void PairMesoCNT::coeff(int narg, char **arg) MPI_Bcast(phi_data[i],pot_points,MPI_DOUBLE,0,world); } + if(me == 0) printf("Arrays broadcast\n"); + spline_coeff(gamma_data,gamma_coeff,gamma_points); spline_coeff(uinf_data,uinf_coeff,pot_points); + if(me == 0) printf("1D splines generated\n"); spline_coeff(usemi_data,usemi_coeff,pot_points); spline_coeff(phi_data,phi_coeff,pot_points); + if(me == 0) printf("2D splines generated\n"); + + if(me == 0){ + std::ofstream outFile; + outFile.open("test.dat"); + for(int i = 0; i < 2001; i++){ + for(int j = 0; j < 2001; j++){ + double x = startzeta_phi[i] + j*delzeta_phi[i]; + double y = starth_phi + i*delh_phi; + double test = spline(x,y,startzeta_phi,starth_phi,delzeta_phi,delh_phi,phi_coeff,pot_points); + outFile << x << " " << y << " " << test << std::endl; + } + } + outFile.close(); + } + } /* ---------------------------------------------------------------------- */ @@ -619,13 +650,13 @@ void PairMesoCNT::spline_coeff(double **data, double ***coeff, int data_size) { for(int i = 0; i < data_size; i++){ for(int j = 0; j < data_size-1; j++){ - if(i == 0){ + if(j == 0){ coeff[i][j][0] = data[j][i]; coeff[i][j][1] = data[j+1][i] - data[j][i]; coeff[i][j][3] = 0.5*(data[j+2][i] - 2*data[j+1][i] + data[j][i]); coeff[i][j][2] = -coeff[i][j][3]; } - else if(i == data_size-2){ + else if(j == data_size-2){ coeff[i][j][0] = data[j][i]; coeff[i][j][1] = 0.5*(data[j+1][i] - data[j-1][i]); coeff[i][j][3] = 0.5*(-data[j+1][i] + 2*data[j][i] - data[j-1][i]); @@ -676,7 +707,7 @@ void PairMesoCNT::read_file(char *file, double *data, if(i == 0) *startx = x; if(i > 0){ if(i == 1) *dx = x - xtemp; - if(*dx != x - xtemp) ++serror; + if((*dx - x + xtemp) / *dx > SMALL) ++serror; } } @@ -737,13 +768,13 @@ void PairMesoCNT::read_file(char *file, double **data, if(j == 0) startx[i] = x; if(j > 0){ if(j == 1) dx[i] = x - xtemp; - if(dx[i] != x - xtemp) ++sxerror; + if((dx[i] - x + xtemp)/dx[i] > SMALL) ++sxerror; } } if(i == 0) *starty = y; if(i > 0){ if(i == 1) *dy = y - ytemp; - if(*dy != y - ytemp) ++syerror; + if((*dy - y + ytemp)/ *dy > SMALL) ++syerror; } } @@ -778,10 +809,10 @@ void PairMesoCNT::read_file(char *file, double **data, double PairMesoCNT::uinf(double *param) { - double h = param[0]; + double h = param[0] * angstromrec; double alpha = param[1]; - double xi1 = param[2]; - double xi2 = param[3]; + double xi1 = param[2] * angstromrec; + double xi2 = param[3] * angstromrec; double sin_alpha = sin(alpha); double sin_alphasq = sin_alpha*sin_alpha; @@ -809,7 +840,7 @@ double PairMesoCNT::uinf(double *param) gamma_coeff,gamma_points); double gamma = 1.0 + (gamma_orth - 1.0)*sin_alphasq; - return gamma * (phi2 - phi1) / a; + return gamma * (phi2 - phi1) * qelectron / a; } } @@ -817,11 +848,11 @@ double PairMesoCNT::uinf(double *param) double PairMesoCNT::usemi(double *param) { - double h = param[0]; + double h = param[0] * angstromrec; double alpha = param[1]; - double xi1 = param[2]; - double xi2 = param[3]; - double etaend = param[4]; + double xi1 = param[2] * angstromrec; + double xi2 = param[3] * angstromrec; + double etaend = param[4] * angstromrec; double sin_alpha = sin(alpha); double sin_alphasq = sin_alpha*sin_alpha; @@ -854,17 +885,17 @@ double PairMesoCNT::usemi(double *param) gamma_coeff,gamma_points); double gamma = 1.0 + (gamma_orth - 1.0)*sin_alphasq; - return delxi * gamma * sum; + return delxi * gamma * sum * qelectron; } /* ---------------------------------------------------------------------- */ void PairMesoCNT::finf(double *param, double **f) { - double h = param[0]; + double h = param[0] * angstromrec; double alpha = param[1]; - double xi1 = param[2]; - double xi2 = param[3]; + double xi1 = param[2] * angstromrec; + double xi2 = param[3] * angstromrec; double sin_alpha = sin(alpha); double sin_alphasq = sin_alpha*sin_alpha; @@ -927,12 +958,12 @@ void PairMesoCNT::finf(double *param, double **f) double cx = h * gamma * sin_alpharecsq * diff_dzeta_phi; double cy = gamma * cot_alpha * diff_dzeta_phi; - f[0][0] = lrec * (xi2*dh_u - cx); - f[1][0] = lrec * (-xi1*dh_u + cx); - f[0][1] = lrec * (dalpha_u - xi2*cy); - f[1][1] = lrec * (-dalpha_u + xi2*cy); - f[0][2] = gamma * dzeta_phi1; - f[1][2] = -gamma * dzeta_phi2; + f[0][0] = lrec * (xi2*dh_u - cx) * forceunit; + f[1][0] = lrec * (-xi1*dh_u + cx) * forceunit; + f[0][1] = lrec * (dalpha_u - xi2*cy) * forceunit; + f[1][1] = lrec * (-dalpha_u + xi2*cy) * forceunit; + f[0][2] = gamma * dzeta_phi1 * forceunit; + f[1][2] = -gamma * dzeta_phi2 * forceunit; } } @@ -940,11 +971,11 @@ void PairMesoCNT::finf(double *param, double **f) void PairMesoCNT::fsemi(double *param, double **f) { - double h = param[0]; + double h = param[0] * angstrom; double alpha = param[1]; - double xi1 = param[2]; - double xi2 = param[3]; - double etaend = param[4]; + double xi1 = param[2] * angstrom; + double xi2 = param[3] * angstrom; + double etaend = param[4] * angstrom; double sin_alpha = sin(alpha); double sin_alphasq = sin_alpha*sin_alpha; @@ -1027,12 +1058,12 @@ void PairMesoCNT::fsemi(double *param, double **f) double cz2 = a1sq*jh2 + cos_alpha*jxi1; double lrec = 1.0 / (xi2 - xi1); - f[0][0] = lrec * (xi2*dh_ubar - cx); - f[1][0] = lrec * (cx - xi1*dh_ubar); - f[0][1] = lrec * (dalpha_ubar - xi2*cy); - f[1][1] = lrec * (xi1*cy - dalpha_ubar); - f[0][2] = lrec * (cz2 + ubar - xi2*cz1); - f[1][2] = lrec * (xi1*cz1 - cz2 - ubar); + f[0][0] = lrec * (xi2*dh_ubar - cx) * forceunit; + f[1][0] = lrec * (cx - xi1*dh_ubar) * forceunit; + f[0][1] = lrec * (dalpha_ubar - xi2*cy) * forceunit; + f[1][1] = lrec * (xi1*cy - dalpha_ubar) * forceunit; + f[0][2] = lrec * (cz2 + ubar - xi2*cz1) * forceunit; + f[1][2] = lrec * (xi1*cz1 - cz2 - ubar) * forceunit; } /* ---------------------------------------------------------------------- */ diff --git a/src/MESOCNT/pair_mesocnt.h b/src/MESOCNT/pair_mesocnt.h index 474506c00f..7aeb660efd 100644 --- a/src/MESOCNT/pair_mesocnt.h +++ b/src/MESOCNT/pair_mesocnt.h @@ -23,6 +23,7 @@ class PairMesoCNT : public Pair { protected: int n, gamma_points, pot_points; + double angstrom, angstromrec, qelectron, qelectronrec, forceunit; double sigma, epsilon, n_sigma, radius, radiussq, rc, rc0, comega, ctheta; double start_gamma, start_uinf, startxi_usemi, starth_phi; double del_gamma, del_uinf, delxi_usemi, delh_phi; From cd55697dfe0e23ef57f21cd8db5bc4d5d266a594 Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Wed, 15 May 2019 12:21:44 +0100 Subject: [PATCH 009/392] splines should work now --- src/MESOCNT/pair_mesocnt.cpp | 162 ++++++++++++++++++++--------------- 1 file changed, 92 insertions(+), 70 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index 9ba5b6bc77..610fdc5f22 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -370,11 +370,11 @@ void PairMesoCNT::coeff(int narg, char **arg) if(me == 0){ std::ofstream outFile; outFile.open("test.dat"); - for(int i = 0; i < 2001; i++){ - for(int j = 0; j < 2001; j++){ - double x = startzeta_phi[i] + j*delzeta_phi[i]; - double y = starth_phi + i*delh_phi; - double test = spline(x,y,startzeta_phi,starth_phi,delzeta_phi,delh_phi,phi_coeff,pot_points); + for(int i = 0; i < 1001; i++){ + for(int j = 0; j < 1001; j++){ + double x = starth_usemi[i] + j*delh_usemi[i]; + double y = startxi_usemi + i*delxi_usemi; + double test = spline(x,y,starth_usemi,startxi_usemi,delh_usemi,delxi_usemi,usemi_coeff,pot_points); outFile << x << " " << y << " " << test << std::endl; } } @@ -390,18 +390,22 @@ double PairMesoCNT::spline(double x, double xstart, double dx, { int i = floor((x - xstart)/dx); if(i < 0){ + if(i < -1){ + // warn if argument below spline range + char str[128]; + sprintf(str,"Argument below spline interval; x: %f; x0: %f", x, xstart); + error->warning(FLERR,str); + } i = 0; - // warn if argument below spline range - char str[128]; - sprintf(str,"Argument below spline interval"); - error->warning(FLERR,str); } else if(i > coeff_size-1){ - i = coeff_size-1; - // warn if argument above spline range - char str[128]; - sprintf(str,"Argument above spline interval"); - error->warning(FLERR,str); + if(i > coeff_size){ + // warn if argument above spline range + char str[128]; + sprintf(str,"Argument above spline interval"); + error->warning(FLERR,str); + } + i = coeff_size - 1; } double xlo = xstart + i*dx; @@ -418,19 +422,23 @@ double PairMesoCNT::spline(double x, double y, double *xstart, double ystart, { int i = floor((y - ystart)/dy); if(i < 0){ + if(i < -1){ + // warn if argument below spline range + char str[128]; + sprintf(str,"Argument below spline interval"); + error->warning(FLERR,str); + } i = 0; - // warn if argument below spline range - char str[128]; - sprintf(str,"Argument below spline interval"); - error->warning(FLERR,str); - } - else if(i > coeff_size-1){ - i = coeff_size-1; - // warn if argument above spline range - char str[128]; - sprintf(str,"Argument above spline interval"); - error->warning(FLERR,str); } + else if(i > coeff_size-2){ + if(i > coeff_size-1){ + // warn if argument above spline range + char str[128]; + sprintf(str,"Argument above spline interval"); + error->warning(FLERR,str); + } + i = coeff_size - 2; + } double ylo = ystart + i*dy; double ybar = (y - ylo)/dy; @@ -440,13 +448,13 @@ double PairMesoCNT::spline(double x, double y, double *xstart, double ystart, double a0, a1, a2, a3; double p0, p1, p2, p3; - p1 = spline(x,xstart[0],dx[0],coeff[0],coeff_size); - p2 = spline(x,xstart[1],dx[1],coeff[1],coeff_size); + p1 = spline(x,xstart[i],dx[i],coeff[i],coeff_size); + p2 = spline(x,xstart[i+1],dx[i+1],coeff[i+1],coeff_size); a0 = p1; if(i == 0){ - p3 = spline(x,xstart[2],dx[2],coeff[2],coeff_size); + p3 = spline(x,xstart[i+2],dx[i+2],coeff[i+2],coeff_size); a1 = p2 - p1; a3 = 0.5*(p3 - 2*p2 + p1); @@ -458,10 +466,12 @@ double PairMesoCNT::spline(double x, double y, double *xstart, double ystart, a1 = 0.5*(p2 - p0); a3 = 0.5*(p2 - 2*p1 + p0); a2 = -2*a3; + printf("p: %f %f %f \n",p0,p1,p2); + printf("x0: %f dx: %f \n",xstart[i+1],dx[i+1]); } else{ p0 = spline(x,xstart[i-1],dx[i-1],coeff[i-1],coeff_size); - p3 = spline(x,xstart[2],dx[2],coeff[2],coeff_size); + p3 = spline(x,xstart[i+2],dx[i+2],coeff[i+2],coeff_size); a1 = 0.5*(p2 - p0); a2 = 0.5*(-p3 + 4*p2 - 5*p1 + 2*p0); @@ -478,19 +488,23 @@ double PairMesoCNT::dspline(double x, double xstart, double dx, { int i = floor((x - xstart)/dx); if(i < 0){ + if(i < -1){ + // warn if argument below spline range + char str[128]; + sprintf(str,"Argument below spline interval"); + error->warning(FLERR,str); + } i = 0; - // warn if argument below spline range - char str[128]; - sprintf(str,"Argument below spline interval"); - error->warning(FLERR,str); } else if(i > coeff_size-1){ - i = coeff_size-1; - // warn if argument above spline range - char str[128]; - sprintf(str,"Argument above spline interval"); - error->warning(FLERR,str); - } + if(i > coeff_size){ + // warn if argument above spline range + char str[128]; + sprintf(str,"Argument above spline interval"); + error->warning(FLERR,str); + } + i = coeff_size - 1; + } double xlo = xstart + i*dx; double xbar = (x - xlo)/dx; @@ -505,19 +519,23 @@ double PairMesoCNT::dxspline(double x, double y, double *xstart, double ystart, { int i = floor((y - ystart)/dy); if(i < 0){ + if(i < -1){ + // warn if argument below spline range + char str[128]; + sprintf(str,"Argument below spline interval"); + error->warning(FLERR,str); + } i = 0; - // warn if argument below spline range - char str[128]; - sprintf(str,"Argument below spline interval"); - error->warning(FLERR,str); - } - else if(i > coeff_size-1){ - i = coeff_size-1; - // warn if argument above spline range - char str[128]; - sprintf(str,"Argument above spline interval"); - error->warning(FLERR,str); } + else if(i > coeff_size-2){ + if(i > coeff_size-1){ + // warn if argument above spline range + char str[128]; + sprintf(str,"Argument above spline interval"); + error->warning(FLERR,str); + } + i = coeff_size - 2; + } double ylo = ystart + i*dy; double ybar = (y - ylo)/dy; @@ -527,13 +545,13 @@ double PairMesoCNT::dxspline(double x, double y, double *xstart, double ystart, double a0, a1, a2, a3; double p0, p1, p2, p3; - p1 = dspline(x,xstart[0],dx[0],coeff[0],coeff_size); - p2 = dspline(x,xstart[1],dx[1],coeff[1],coeff_size); + p1 = dspline(x,xstart[i],dx[i],coeff[i],coeff_size); + p2 = dspline(x,xstart[i+1],dx[i+1],coeff[i+1],coeff_size); a0 = p1; if(i == 0){ - p3 = dspline(x,xstart[2],dx[2],coeff[2],coeff_size); + p3 = dspline(x,xstart[i+2],dx[i+2],coeff[i+2],coeff_size); a1 = p2 - p1; a3 = 0.5*(p3 - 2*p2 + p1); @@ -548,7 +566,7 @@ double PairMesoCNT::dxspline(double x, double y, double *xstart, double ystart, } else{ p0 = dspline(x,xstart[i-1],dx[i-1],coeff[i-1],coeff_size); - p3 = dspline(x,xstart[2],dx[2],coeff[2],coeff_size); + p3 = dspline(x,xstart[i+2],dx[i+2],coeff[i+2],coeff_size); a1 = 0.5*(p2 - p0); a2 = 0.5*(-p3 + 4*p2 - 5*p1 + 2*p0); @@ -565,20 +583,24 @@ double PairMesoCNT::dyspline(double x, double y, double *xstart, double ystart, { int i = floor((y - ystart)/dy); if(i < 0){ + if(i < -1){ + // warn if argument below spline range + char str[128]; + sprintf(str,"Argument below spline interval"); + error->warning(FLERR,str); + } i = 0; - // warn if argument below spline range - char str[128]; - sprintf(str,"Argument below spline interval"); - error->warning(FLERR,str); } - else if(i > coeff_size-1){ - i = coeff_size-1; - // warn if argument above spline range - char str[128]; - sprintf(str,"Argument above spline interval"); - error->warning(FLERR,str); - } - + else if(i > coeff_size-2){ + if(i > coeff_size-1){ + // warn if argument above spline range + char str[128]; + sprintf(str,"Argument above spline interval"); + error->warning(FLERR,str); + } + i = coeff_size - 2; + } + double ylo = ystart + i*dy; double ybar = (y - ylo)/dy; @@ -587,13 +609,13 @@ double PairMesoCNT::dyspline(double x, double y, double *xstart, double ystart, double a0, a1, a2, a3; double p0, p1, p2, p3; - p1 = spline(x,xstart[0],dx[0],coeff[0],coeff_size); - p2 = spline(x,xstart[1],dx[1],coeff[1],coeff_size); + p1 = spline(x,xstart[i],dx[i],coeff[i],coeff_size); + p2 = spline(x,xstart[i+1],dx[i+1],coeff[i+1],coeff_size); a0 = p1; if(i == 0){ - p3 = spline(x,xstart[2],dx[2],coeff[2],coeff_size); + p3 = spline(x,xstart[i+2],dx[i+2],coeff[i+2],coeff_size); a1 = p2 - p1; a3 = 0.5*(p3 - 2*p2 + p1); @@ -608,7 +630,7 @@ double PairMesoCNT::dyspline(double x, double y, double *xstart, double ystart, } else{ p0 = spline(x,xstart[i-1],dx[i-1],coeff[i-1],coeff_size); - p3 = spline(x,xstart[2],dx[2],coeff[2],coeff_size); + p3 = spline(x,xstart[i+2],dx[i+2],coeff[i+2],coeff_size); a1 = 0.5*(p2 - p0); a2 = 0.5*(-p3 + 4*p2 - 5*p1 + 2*p0); From ea43f7d451e6f9aaad92b7f829dfc2c842e879af Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Wed, 15 May 2019 19:52:32 +0100 Subject: [PATCH 010/392] compute runs without crash, produces nans --- src/MESOCNT/pair_mesocnt.cpp | 97 ++++++++++++++++++------------------ src/MESOCNT/pair_mesocnt.h | 1 + 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index 610fdc5f22..80450ac851 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -40,6 +40,9 @@ PairMesoCNT::PairMesoCNT(LAMMPS *lmp) : Pair(lmp) PairMesoCNT::~PairMesoCNT() { if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); + memory->destroy(gamma_data); memory->destroy(uinf_data); memory->destroy(starth_usemi); @@ -79,7 +82,7 @@ void PairMesoCNT::compute(int eflag, int vflag) int *mol = atom->molecule; int nbondlist = neighbor->nbondlist; int nlocal = atom->nlocal; - + inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; @@ -87,8 +90,6 @@ void PairMesoCNT::compute(int eflag, int vflag) memory->create(p1,3,"pair:p1"); memory->create(p2,3,"pair:p2"); - memory->create(q1,3,"pair:q1"); - memory->create(q2,3,"pair:q2"); memory->create(param,6,"pair:param"); memory->create(flocal,2,3,"pair:flocal"); memory->create(basis,3,3,"pair:basis"); @@ -106,6 +107,8 @@ void PairMesoCNT::compute(int eflag, int vflag) j2list = firstneigh[i2]; j1num = numneigh[i1]; j2num = numneigh[i2]; + + if(j1num + j2num == 0) continue; memory->create(redlist,j1num+j2num,"pair:redlist"); numred = 0; @@ -123,7 +126,7 @@ void PairMesoCNT::compute(int eflag, int vflag) } redlist[numred++] = j2list[jj2]; } - + // insertion sort according to atom-id for(int mm = 1; mm < numred; mm++){ @@ -144,7 +147,7 @@ void PairMesoCNT::compute(int eflag, int vflag) int cid = 0; int cnum = 0; memory->create(chain,numred,numred,"pair:chain"); - memory->create(nchain,numred,"pair:numred"); + memory->create(nchain,numred,"pair:nchain"); for(jj = 0; jj < numred-1; jj++){ int j = redlist[jj]; chain[cid][cnum++] = j; @@ -244,11 +247,10 @@ void PairMesoCNT::compute(int eflag, int vflag) memory->destroy(p1); memory->destroy(p2); - memory->destroy(q1); - memory->destroy(q2); memory->destroy(param); memory->destroy(flocal); memory->destroy(basis); + } /* ---------------------------------------------------------------------- */ @@ -263,7 +265,7 @@ void PairMesoCNT::init_style() double PairMesoCNT::init_one(int i, int j) { - return 0; + return cutoff; } /* ---------------------------------------------------------------------- @@ -273,7 +275,15 @@ double PairMesoCNT::init_one(int i, int j) void PairMesoCNT::allocate() { allocated = 1; - + int n = atom->ntypes; + + memory->create(setflag,n+1,n+1,"pair:setflag"); + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + setflag[i][j] = 0; + + memory->create(cutsq,n+1,n+1,"pair:cutsq"); + memory->create(gamma_data,gamma_points,"pair:gamma_data"); memory->create(uinf_data,pot_points,"pair:uinf_data"); memory->create(starth_usemi,pot_points,"pair:starth_usemi"); @@ -339,12 +349,10 @@ void PairMesoCNT::coeff(int narg, char **arg) if (me == 0) { read_file(gamma_file,gamma_data,&start_gamma,&del_gamma,gamma_points); read_file(uinf_file,uinf_data,&start_uinf,&del_uinf,pot_points); - printf("1D files read\n"); read_file(usemi_file,usemi_data,starth_usemi,&startxi_usemi, delh_usemi,&delxi_usemi,pot_points); read_file(phi_file,phi_data,startzeta_phi,&starth_phi, delzeta_phi,&delh_phi,pot_points); - printf("2D files read\n"); } MPI_Bcast(gamma_data,gamma_points,MPI_DOUBLE,0,world); @@ -358,29 +366,22 @@ void PairMesoCNT::coeff(int narg, char **arg) MPI_Bcast(phi_data[i],pot_points,MPI_DOUBLE,0,world); } - if(me == 0) printf("Arrays broadcast\n"); - spline_coeff(gamma_data,gamma_coeff,gamma_points); spline_coeff(uinf_data,uinf_coeff,pot_points); - if(me == 0) printf("1D splines generated\n"); spline_coeff(usemi_data,usemi_coeff,pot_points); spline_coeff(phi_data,phi_coeff,pot_points); - if(me == 0) printf("2D splines generated\n"); - if(me == 0){ - std::ofstream outFile; - outFile.open("test.dat"); - for(int i = 0; i < 1001; i++){ - for(int j = 0; j < 1001; j++){ - double x = starth_usemi[i] + j*delh_usemi[i]; - double y = startxi_usemi + i*delxi_usemi; - double test = spline(x,y,starth_usemi,startxi_usemi,delh_usemi,delxi_usemi,usemi_coeff,pot_points); - outFile << x << " " << y << " " << test << std::endl; + int n = atom->ntypes; + + cutoff = rc + 2*radius; + double cutoffsq = cutoff * cutoff; + + for (int i = 1; i <= n; i++){ + for (int j = i; j <= n; j++){ + setflag[i][j] = 1; + cutsq[i][j] = cutoffsq; } } - outFile.close(); - } - } /* ---------------------------------------------------------------------- */ @@ -393,8 +394,8 @@ double PairMesoCNT::spline(double x, double xstart, double dx, if(i < -1){ // warn if argument below spline range char str[128]; - sprintf(str,"Argument below spline interval; x: %f; x0: %f", x, xstart); - error->warning(FLERR,str); + //sprintf(str,"Argument below spline interval; x: %f; x0: %f", x, xstart); + //error->warning(FLERR,str); } i = 0; } @@ -402,8 +403,8 @@ double PairMesoCNT::spline(double x, double xstart, double dx, if(i > coeff_size){ // warn if argument above spline range char str[128]; - sprintf(str,"Argument above spline interval"); - error->warning(FLERR,str); + //sprintf(str,"Argument above spline interval"); + //error->warning(FLERR,str); } i = coeff_size - 1; } @@ -425,8 +426,8 @@ double PairMesoCNT::spline(double x, double y, double *xstart, double ystart, if(i < -1){ // warn if argument below spline range char str[128]; - sprintf(str,"Argument below spline interval"); - error->warning(FLERR,str); + //sprintf(str,"Argument below spline interval"); + //error->warning(FLERR,str); } i = 0; } @@ -434,8 +435,8 @@ double PairMesoCNT::spline(double x, double y, double *xstart, double ystart, if(i > coeff_size-1){ // warn if argument above spline range char str[128]; - sprintf(str,"Argument above spline interval"); - error->warning(FLERR,str); + //sprintf(str,"Argument above spline interval"); + //error->warning(FLERR,str); } i = coeff_size - 2; } @@ -466,8 +467,6 @@ double PairMesoCNT::spline(double x, double y, double *xstart, double ystart, a1 = 0.5*(p2 - p0); a3 = 0.5*(p2 - 2*p1 + p0); a2 = -2*a3; - printf("p: %f %f %f \n",p0,p1,p2); - printf("x0: %f dx: %f \n",xstart[i+1],dx[i+1]); } else{ p0 = spline(x,xstart[i-1],dx[i-1],coeff[i-1],coeff_size); @@ -491,8 +490,8 @@ double PairMesoCNT::dspline(double x, double xstart, double dx, if(i < -1){ // warn if argument below spline range char str[128]; - sprintf(str,"Argument below spline interval"); - error->warning(FLERR,str); + //sprintf(str,"Argument below spline interval"); + //error->warning(FLERR,str); } i = 0; } @@ -500,8 +499,8 @@ double PairMesoCNT::dspline(double x, double xstart, double dx, if(i > coeff_size){ // warn if argument above spline range char str[128]; - sprintf(str,"Argument above spline interval"); - error->warning(FLERR,str); + //sprintf(str,"Argument above spline interval"); + //error->warning(FLERR,str); } i = coeff_size - 1; } @@ -522,8 +521,8 @@ double PairMesoCNT::dxspline(double x, double y, double *xstart, double ystart, if(i < -1){ // warn if argument below spline range char str[128]; - sprintf(str,"Argument below spline interval"); - error->warning(FLERR,str); + //sprintf(str,"Argument below spline interval"); + //error->warning(FLERR,str); } i = 0; } @@ -531,8 +530,8 @@ double PairMesoCNT::dxspline(double x, double y, double *xstart, double ystart, if(i > coeff_size-1){ // warn if argument above spline range char str[128]; - sprintf(str,"Argument above spline interval"); - error->warning(FLERR,str); + //sprintf(str,"Argument above spline interval"); + //error->warning(FLERR,str); } i = coeff_size - 2; } @@ -586,8 +585,8 @@ double PairMesoCNT::dyspline(double x, double y, double *xstart, double ystart, if(i < -1){ // warn if argument below spline range char str[128]; - sprintf(str,"Argument below spline interval"); - error->warning(FLERR,str); + //sprintf(str,"Argument below spline interval"); + //error->warning(FLERR,str); } i = 0; } @@ -595,8 +594,8 @@ double PairMesoCNT::dyspline(double x, double y, double *xstart, double ystart, if(i > coeff_size-1){ // warn if argument above spline range char str[128]; - sprintf(str,"Argument above spline interval"); - error->warning(FLERR,str); + //sprintf(str,"Argument above spline interval"); + //error->warning(FLERR,str); } i = coeff_size - 2; } diff --git a/src/MESOCNT/pair_mesocnt.h b/src/MESOCNT/pair_mesocnt.h index 7aeb660efd..f8d2cf9264 100644 --- a/src/MESOCNT/pair_mesocnt.h +++ b/src/MESOCNT/pair_mesocnt.h @@ -23,6 +23,7 @@ class PairMesoCNT : public Pair { protected: int n, gamma_points, pot_points; + double cutoff; double angstrom, angstromrec, qelectron, qelectronrec, forceunit; double sigma, epsilon, n_sigma, radius, radiussq, rc, rc0, comega, ctheta; double start_gamma, start_uinf, startxi_usemi, starth_phi; From 474c92e59adf8383f8f715b8dc92dc6d0da7d6d3 Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Wed, 15 May 2019 20:43:32 +0100 Subject: [PATCH 011/392] Fixed nan issues in compute --- src/MESOCNT/pair_mesocnt.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index 80450ac851..91c6771432 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -184,12 +184,19 @@ void PairMesoCNT::compute(int eflag, int vflag) double w,sumwreq,sumw; for(int i = 0; i < cid; i++){ + if(nchain[i] < 2) continue; + zero3(p1); zero3(p2); sumw = 0; for(int j = 0; j < nchain[i]-1; j++){ q1 = x[chain[i][j]]; q2 = x[chain[i][j+1]]; + printf("Vectors q:\n"); + printf("%e %e %e\n",q1[0],q1[1],q1[2]); + printf("%e %e %e\n",q2[0],q2[1],q2[2]); + fflush(stdout); + w = weight(r1,r2,q1,q2); sumw += w; for(int ax = 0; ax < 3; ax++){ @@ -197,10 +204,17 @@ void PairMesoCNT::compute(int eflag, int vflag) p2[ax] += w * q2[ax]; } } + + if(sumw == 0) continue; sumwreq = 1 / sumw; scale3(sumwreq,p1); scale3(sumwreq,p2); + printf("Vectors p:\n"); + printf("%e %e %e\n",p1[0],p1[1],p1[2]); + printf("%e %e %e\n",p2[0],p2[1],p2[2]); + fflush(stdout); + if(end[i] == 1){ geom(r1,r2,p1,p2,param,basis); fsemi(param,flocal); @@ -237,6 +251,11 @@ void PairMesoCNT::compute(int eflag, int vflag) f[i2][2] += flocal[1][0]*basis[2][0] + flocal[1][1]*basis[2][1] + flocal[1][2]*basis[2][2]; + + printf("Forces:\n"); + printf("%e %e %e\n",f[i1][0],f[i1][1],f[i1][2]); + printf("%e %e %e\n",f[i2][0],f[i2][1],f[i2][2]); + fflush(stdout); } memory->destroy(redlist); @@ -394,7 +413,7 @@ double PairMesoCNT::spline(double x, double xstart, double dx, if(i < -1){ // warn if argument below spline range char str[128]; - //sprintf(str,"Argument below spline interval; x: %f; x0: %f", x, xstart); + //sprintf(str,"Argument below spline interval; x: %e; x0: %e", x, xstart); //error->warning(FLERR,str); } i = 0; From 651b3d788a72a8078a44559e76d0152b0c1c58a5 Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Fri, 24 May 2019 20:21:10 +0100 Subject: [PATCH 012/392] Fixed unit errors and most major bugs --- src/MESOCNT/pair_mesocnt.cpp | 193 ++++++++++++++++++++++++----------- src/MESOCNT/pair_mesocnt.h | 2 + 2 files changed, 138 insertions(+), 57 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index 91c6771432..ec5d2d7f75 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -57,6 +57,12 @@ PairMesoCNT::~PairMesoCNT() memory->destroy(usemi_coeff); memory->destroy(phi_coeff); + + memory->destroy(p1); + memory->destroy(p2); + memory->destroy(param); + memory->destroy(flocal); + memory->destroy(basis); } } @@ -64,9 +70,14 @@ PairMesoCNT::~PairMesoCNT() void PairMesoCNT::compute(int eflag, int vflag) { + /* + int rank; + MPI_Comm_rank(MPI_COMM_WORLD,&rank); + */ + int inum,i1,i2,jj,jj1,jj2,j1num,j2num,numred,inflag,n; double evdwl; - double *r1,*r2,*p1,*p2,*q1,*q2,*param,**flocal,**basis; + double *r1,*r2,*q1,*q2; int *ilist,*j1list,*j2list,*numneigh,**firstneigh; int *redlist,*nchain,*end; @@ -88,19 +99,13 @@ void PairMesoCNT::compute(int eflag, int vflag) numneigh = list->numneigh; firstneigh = list->firstneigh; - memory->create(p1,3,"pair:p1"); - memory->create(p2,3,"pair:p2"); - memory->create(param,6,"pair:param"); - memory->create(flocal,2,3,"pair:flocal"); - memory->create(basis,3,3,"pair:basis"); - for(n = 0; n < nbondlist; n++){ i1 = bondlist[n][0]; i2 = bondlist[n][1]; r1 = x[i1]; r2 = x[i2]; - + // reduce neighbors to common list j1list = firstneigh[i1]; @@ -192,10 +197,18 @@ void PairMesoCNT::compute(int eflag, int vflag) for(int j = 0; j < nchain[i]-1; j++){ q1 = x[chain[i][j]]; q2 = x[chain[i][j+1]]; - printf("Vectors q:\n"); + + /* + if(rank == 1){ + printf("Vectors r:\n"); + printf("%e %e %e\n",r1[0],r1[1],r1[2]); + printf("%e %e %e\n",r2[0],r2[1],r2[2]); + printf("Vectors q:\n"); printf("%e %e %e\n",q1[0],q1[1],q1[2]); printf("%e %e %e\n",q2[0],q2[1],q2[2]); fflush(stdout); + } + */ w = weight(r1,r2,q1,q2); sumw += w; @@ -210,21 +223,30 @@ void PairMesoCNT::compute(int eflag, int vflag) scale3(sumwreq,p1); scale3(sumwreq,p2); + /* + if(rank == 1){ + printf("Weight sum:\n"); + printf("%e\n",sumw); printf("Vectors p:\n"); printf("%e %e %e\n",p1[0],p1[1],p1[2]); printf("%e %e %e\n",p2[0],p2[1],p2[2]); fflush(stdout); + } + */ if(end[i] == 1){ geom(r1,r2,p1,p2,param,basis); + if(param[0] > cutoff) continue; fsemi(param,flocal); } else if(end[i] == 2){ geom(r1,r2,p2,p1,param,basis); + if(param[0] > cutoff) continue; fsemi(param,flocal); } else{ geom(r1,r2,p2,p1,param,basis); + if(param[0] > cutoff) continue; finf(param,flocal); } @@ -233,43 +255,61 @@ void PairMesoCNT::compute(int eflag, int vflag) else evdwl = usemi(param); } - f[i1][0] += flocal[0][0]*basis[0][0] - + flocal[0][1]*basis[0][1] - + flocal[0][2]*basis[0][2]; - f[i1][1] += flocal[0][0]*basis[1][0] + double f1x,f1y,f1z,f2x,f2y,f2z; + + f1x = flocal[0][0]*basis[0][0] + + flocal[0][1]*basis[1][0] + + flocal[0][2]*basis[2][0]; + f1y = flocal[0][0]*basis[0][1] + flocal[0][1]*basis[1][1] - + flocal[0][2]*basis[1][2]; - f[i1][2] += flocal[0][0]*basis[2][0] - + flocal[0][1]*basis[2][1] + + flocal[0][2]*basis[2][1]; + f1z = flocal[0][0]*basis[0][2] + + flocal[0][1]*basis[1][2] + flocal[0][2]*basis[2][2]; - f[i2][0] += flocal[1][0]*basis[0][0] - + flocal[1][1]*basis[0][1] - + flocal[1][2]*basis[0][2]; - f[i2][1] += flocal[1][0]*basis[1][0] + f2x = flocal[1][0]*basis[0][0] + + flocal[1][1]*basis[1][0] + + flocal[1][2]*basis[2][0]; + f2y = flocal[1][0]*basis[0][1] + flocal[1][1]*basis[1][1] - + flocal[1][2]*basis[1][2]; - f[i2][2] += flocal[1][0]*basis[2][0] - + flocal[1][1]*basis[2][1] + + flocal[1][2]*basis[2][1]; + f2z = flocal[1][0]*basis[0][2] + + flocal[1][1]*basis[1][2] + flocal[1][2]*basis[2][2]; + f[i1][0] = flocal[0][0]*basis[0][0] + + flocal[0][1]*basis[1][0] + + flocal[0][2]*basis[2][0]; + f[i1][1] = flocal[0][0]*basis[0][1] + + flocal[0][1]*basis[1][1] + + flocal[0][2]*basis[2][1]; + f[i1][2] = flocal[0][0]*basis[0][2] + + flocal[0][1]*basis[1][2] + + flocal[0][2]*basis[2][2]; + f[i2][0] = flocal[1][0]*basis[0][0] + + flocal[1][1]*basis[1][0] + + flocal[1][2]*basis[2][0]; + f[i2][1] = flocal[1][0]*basis[0][1] + + flocal[1][1]*basis[1][1] + + flocal[1][2]*basis[2][1]; + f[i2][2] = flocal[1][0]*basis[0][2] + + flocal[1][1]*basis[1][2] + + flocal[1][2]*basis[2][2]; + + /* printf("Forces:\n"); - printf("%e %e %e\n",f[i1][0],f[i1][1],f[i1][2]); - printf("%e %e %e\n",f[i2][0],f[i2][1],f[i2][2]); + printf("%e %e %e\n",f1x,f1y,f1z); + printf("%e %e %e\n",f2x,f2y,f2z); + printf("Parameters:\n"); + printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); fflush(stdout); + */ } memory->destroy(redlist); memory->destroy(chain); memory->destroy(nchain); memory->destroy(end); - } - - memory->destroy(p1); - memory->destroy(p2); - memory->destroy(param); - memory->destroy(flocal); - memory->destroy(basis); - + } } /* ---------------------------------------------------------------------- */ @@ -317,6 +357,12 @@ void PairMesoCNT::allocate() memory->create(usemi_coeff,pot_points,pot_points,4,"pair:usemi_coeff"); memory->create(phi_coeff,pot_points,pot_points,4,"pair:phi_coeff"); + + memory->create(p1,3,"pair:p1"); + memory->create(p2,3,"pair:p2"); + memory->create(param,6,"pair:param"); + memory->create(flocal,2,3,"pair:flocal"); + memory->create(basis,3,3,"pair:basis"); } /* ---------------------------------------------------------------------- @@ -374,6 +420,15 @@ void PairMesoCNT::coeff(int narg, char **arg) delzeta_phi,&delh_phi,pot_points); } + MPI_Bcast(&start_gamma,1,MPI_DOUBLE,0,world); + MPI_Bcast(&del_gamma,1,MPI_DOUBLE,0,world); + MPI_Bcast(&start_uinf,1,MPI_DOUBLE,0,world); + MPI_Bcast(&del_uinf,1,MPI_DOUBLE,0,world); + MPI_Bcast(&startxi_usemi,1,MPI_DOUBLE,0,world); + MPI_Bcast(&delxi_usemi,1,MPI_DOUBLE,0,world); + MPI_Bcast(&starth_phi,1,MPI_DOUBLE,0,world); + MPI_Bcast(&delh_phi,1,MPI_DOUBLE,0,world); + MPI_Bcast(gamma_data,gamma_points,MPI_DOUBLE,0,world); MPI_Bcast(uinf_data,pot_points,MPI_DOUBLE,0,world); MPI_Bcast(starth_usemi,pot_points,MPI_DOUBLE,0,world); @@ -401,6 +456,7 @@ void PairMesoCNT::coeff(int narg, char **arg) cutsq[i][j] = cutoffsq; } } + } /* ---------------------------------------------------------------------- */ @@ -942,11 +998,12 @@ void PairMesoCNT::finf(double *param, double **f) if(sin_alphasq < SMALL){ f[0][0] = -0.5*(xi2 - xi1)*dspline(h,start_uinf,del_uinf, - uinf_coeff,pot_points); + uinf_coeff,pot_points) * forceunit; f[1][0] = f[0][0]; f[0][1] = 0; f[1][1] = 0; - f[0][2] = spline(h,start_uinf,del_uinf,uinf_coeff,pot_points); + f[0][2] = spline(h,start_uinf,del_uinf,uinf_coeff,pot_points) + * forceunit; f[1][2] = -f[0][2]; } else{ @@ -956,10 +1013,10 @@ void PairMesoCNT::finf(double *param, double **f) double cot_alpha = cos_alpha * sin_alpharec; double omega = 1.0 / (1.0 - comega*sin_alphasq); - double domega = 2 * comega * sin_alpha * cos_alpha * omega * omega; double a1 = omega * sin_alpha; double a1rec = 1.0 / a1; - + double domega = 2 * comega * cos_alpha * a1 * omega; + double gamma_orth = spline(h,start_gamma,del_gamma, gamma_coeff,gamma_points); double gamma = 1.0 + (gamma_orth - 1.0)*sin_alphasq; @@ -971,27 +1028,49 @@ void PairMesoCNT::finf(double *param, double **f) double zeta1 = xi1 * a1; double zeta2 = xi2 * a1; - double phi1 = spline(zeta1,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); - double phi2 = spline(zeta2,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); - double dzeta_phi1 = dxspline(zeta1,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); - double dzeta_phi2 = dxspline(zeta2,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); - double diff_dzeta_phi = dzeta_phi2 - dzeta_phi1; - double dh_phi1 = dyspline(zeta1,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); - double dh_phi2 = dyspline(zeta2,h,startzeta_phi,starth_phi, - delzeta_phi,delh_phi,phi_coeff,pot_points); + double phi1,phi2,dzeta_phi1,dzeta_phi2,dh_phi1,dh_phi2; + if(zeta1 < 0){ + phi1 = -spline(-zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + dzeta_phi1 = -dxspline(-zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + dh_phi1 = -dyspline(-zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + } + else{ + phi1 = spline(zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + dzeta_phi1 = dxspline(zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + dh_phi1 = dyspline(zeta1,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + } + if(zeta2 < 0){ + phi2 = -spline(-zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + dzeta_phi2 = -dxspline(-zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + dh_phi2 = -dyspline(-zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + } + else{ + phi2 = spline(zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + dzeta_phi2 = dxspline(zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + dh_phi2 = dyspline(zeta2,h,startzeta_phi,starth_phi, + delzeta_phi,delh_phi,phi_coeff,pot_points); + } + double diff_dzeta_phi = dzeta_phi2 - dzeta_phi1; + double a2 = gamma * a1rec; double u = a2 * (phi2 - phi1); double a3 = u * gammarec; double dh_u = dh_gamma * a3 + a2 * (dh_phi2 - dh_phi1); double dalpha_u = dalpha_gamma * a3 - + a2 * (domega*sin_alpha + omega*cos_alpha) + + a1rec * (domega*sin_alpha + omega*cos_alpha) * (gamma*(xi2*dzeta_phi2 - xi1*dzeta_phi1) - u); double lrec = 1.0 / (xi2 - xi1); @@ -1001,7 +1080,7 @@ void PairMesoCNT::finf(double *param, double **f) f[0][0] = lrec * (xi2*dh_u - cx) * forceunit; f[1][0] = lrec * (-xi1*dh_u + cx) * forceunit; f[0][1] = lrec * (dalpha_u - xi2*cy) * forceunit; - f[1][1] = lrec * (-dalpha_u + xi2*cy) * forceunit; + f[1][1] = lrec * (-dalpha_u + xi1*cy) * forceunit; f[0][2] = gamma * dzeta_phi1 * forceunit; f[1][2] = -gamma * dzeta_phi2 * forceunit; } @@ -1011,11 +1090,11 @@ void PairMesoCNT::finf(double *param, double **f) void PairMesoCNT::fsemi(double *param, double **f) { - double h = param[0] * angstrom; + double h = param[0] * angstromrec; double alpha = param[1]; - double xi1 = param[2] * angstrom; - double xi2 = param[3] * angstrom; - double etaend = param[4] * angstrom; + double xi1 = param[2] * angstromrec; + double xi2 = param[3] * angstromrec; + double etaend = param[4] * angstromrec; double sin_alpha = sin(alpha); double sin_alphasq = sin_alpha*sin_alpha; @@ -1187,7 +1266,7 @@ double PairMesoCNT::weight(const double *r1, const double *r2, const double *p1, const double *p2) { using namespace MathExtra; - double r[3], p[3], delr[3], delp[3], delrp[3]; + double r[3], p[3]; double rho, rhoc, rhomin; add3(r1,r2,r); diff --git a/src/MESOCNT/pair_mesocnt.h b/src/MESOCNT/pair_mesocnt.h index f8d2cf9264..6b20d906ea 100644 --- a/src/MESOCNT/pair_mesocnt.h +++ b/src/MESOCNT/pair_mesocnt.h @@ -31,8 +31,10 @@ class PairMesoCNT : public Pair { double *starth_usemi, *startzeta_phi; double *delh_usemi, *delzeta_phi; double *gamma_data, *uinf_data; + double *p1, *p2, *param; double **usemi_data, **phi_data; double **gamma_coeff, **uinf_coeff; + double **flocal,**basis; double ***usemi_coeff, ***phi_coeff; char *gamma_file, *uinf_file, *usemi_file, *phi_file; From 9f3923e784ba7f462d2f81ac01e4835b56a79b73 Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Wed, 29 May 2019 18:03:42 +0100 Subject: [PATCH 013/392] Fixed numerous bugs, nealy working? --- src/MESOCNT/pair_mesocnt.cpp | 307 +++++++++++++++++++++++++++-------- src/MESOCNT/pair_mesocnt.h | 2 +- 2 files changed, 238 insertions(+), 71 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index ec5d2d7f75..d904ac8fb4 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -99,9 +99,11 @@ void PairMesoCNT::compute(int eflag, int vflag) numneigh = list->numneigh; firstneigh = list->firstneigh; + //printf("Number of bonds: %d\n",nbondlist); for(n = 0; n < nbondlist; n++){ i1 = bondlist[n][0]; i2 = bondlist[n][1]; + //printf("Local IDs in bond: %d %d\n",i1,i2); r1 = x[i1]; r2 = x[i2]; @@ -113,11 +115,16 @@ void PairMesoCNT::compute(int eflag, int vflag) j1num = numneigh[i1]; j2num = numneigh[i2]; + //printf("Bond neighbours: %d\n",j1num + j2num); + if(j1num + j2num == 0) continue; memory->create(redlist,j1num+j2num,"pair:redlist"); numred = 0; - for(jj1 = 0; jj1 < j1num; jj1++) redlist[numred++] = j1list[jj1]; + for(jj1 = 0; jj1 < j1num; jj1++){ + int ind = j1list[jj1]; + if (ind != i1 && ind != i2) redlist[numred++] = ind; + } for(jj2 = 0; jj2 < j2num; jj2++){ for(jj1 = 0; jj1 < j1num; jj1++){ if(j1list[jj1] == j2list[jj2]){ @@ -129,9 +136,23 @@ void PairMesoCNT::compute(int eflag, int vflag) inflag = 0; continue; } - redlist[numred++] = j2list[jj2]; + int ind = j2list[jj2]; + if (ind != i1 && ind != i2) redlist[numred++] = ind; } + + //printf("Unsorted:\n"); + for(int mm = 0; mm < numred; mm++){ + //printf("%d ",redlist[mm]); + } + //printf("\n"); + //printf("ID:\n"); + for(int mm = 0; mm < numred; mm++){ + //printf("%d ",tag[redlist[mm]]); + } + //printf("\n"); + + // insertion sort according to atom-id for(int mm = 1; mm < numred; mm++){ @@ -139,24 +160,42 @@ void PairMesoCNT::compute(int eflag, int vflag) int loc1 = redlist[m-1]; int loc2 = redlist[m]; while(m > 0 && tag[loc1] > tag[loc2]){ - loc1 = redlist[m-1]; - loc2 = redlist[m]; - m--; redlist[m] = loc1; - redlist[m-1]; + redlist[m-1] = loc2; + m--; + loc1 = redlist[m-1]; + loc2 = redlist[m]; } } + + //printf("Sorted:\n"); + for(int mm = 0; mm < numred; mm++){ + //printf("%d ",redlist[mm]); + } + //printf("\n"); + //printf("ID:\n"); + for(int mm = 0; mm < numred; mm++){ + //printf("%d ",tag[redlist[mm]]); + } + //printf("\n"); + + fflush(stdout); + + // split into connected chains + //printf("Splitting chains\n"); int cid = 0; int cnum = 0; memory->create(chain,numred,numred,"pair:chain"); memory->create(nchain,numred,"pair:nchain"); for(jj = 0; jj < numred-1; jj++){ - int j = redlist[jj]; - chain[cid][cnum++] = j; - if(abs(tag[j] - tag[j+1]) != 1 || mol[j] != mol[j+1]){ + int j1 = redlist[jj]; + int j2 = redlist[jj+1]; + chain[cid][cnum++] = j1; + //printf("%d %d %d %d\n",cid,tag[j1],tag[j2],abs(tag[j1] - tag[j2])); + if(abs(tag[j1] - tag[j2]) != 1 || mol[j1] != mol[j2]){ nchain[cid++] = cnum; cnum = 0; } @@ -164,6 +203,17 @@ void PairMesoCNT::compute(int eflag, int vflag) chain[cid][cnum++] = redlist[numred-1]; nchain[cid++] = cnum; + //printf("Chains:\n"); + for(int i = 0; i < cid; i++){ + int cn = nchain[i]; + //printf("Chain %d: ",i); + for(int j = 0; j < cn; j++){ + //printf("%d ", chain[i][j]); + } + //printf("\n"); + } + fflush(stdout); + // check for ends memory->create(end,cid,"pair:end"); @@ -189,30 +239,31 @@ void PairMesoCNT::compute(int eflag, int vflag) double w,sumwreq,sumw; for(int i = 0; i < cid; i++){ + //printf("Chain length: %d\n",nchain[i]); if(nchain[i] < 2) continue; zero3(p1); zero3(p2); sumw = 0; + + //printf("Vectors r:\n"); + //printf("%e %e %e\n",r1[0],r1[1],r1[2]); + //printf("%e %e %e\n",r2[0],r2[1],r2[2]); + for(int j = 0; j < nchain[i]-1; j++){ q1 = x[chain[i][j]]; q2 = x[chain[i][j+1]]; - - /* - if(rank == 1){ - printf("Vectors r:\n"); - printf("%e %e %e\n",r1[0],r1[1],r1[2]); - printf("%e %e %e\n",r2[0],r2[1],r2[2]); - printf("Vectors q:\n"); - printf("%e %e %e\n",q1[0],q1[1],q1[2]); - printf("%e %e %e\n",q2[0],q2[1],q2[2]); - fflush(stdout); - } - */ - w = weight(r1,r2,q1,q2); + w = weight(r1,r2,q1,q2); sumw += w; - for(int ax = 0; ax < 3; ax++){ + + //printf("Vectors q %d:\n",j); + //printf("%e %e %e\n",q1[0],q1[1],q1[2]); + //printf("%e %e %e\n",q2[0],q2[1],q2[2]); + //printf("Weight: %e\n",w); + fflush(stdout); + + for(int ax = 0; ax < 3; ax++){ p1[ax] += w * q1[ax]; p2[ax] += w * q2[ax]; } @@ -223,32 +274,38 @@ void PairMesoCNT::compute(int eflag, int vflag) scale3(sumwreq,p1); scale3(sumwreq,p2); - /* - if(rank == 1){ - printf("Weight sum:\n"); - printf("%e\n",sumw); - printf("Vectors p:\n"); - printf("%e %e %e\n",p1[0],p1[1],p1[2]); - printf("%e %e %e\n",p2[0],p2[1],p2[2]); + //printf("Weight sum:\n"); + //printf("%e\n",sumw); + //printf("Vectors p:\n"); + //printf("%e %e %e\n",p1[0],p1[1],p1[2]); + //printf("%e %e %e\n",p2[0],p2[1],p2[2]); fflush(stdout); - } - */ + geom(r1,r2,p1,p2,param,basis); + //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); + if(param[0] > cutoff || param[0] < diameter) continue; + finf(param,flocal); + + /* if(end[i] == 1){ geom(r1,r2,p1,p2,param,basis); - if(param[0] > cutoff) continue; + //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); + if(param[0] > cutoff || param[0] < diameter) continue; fsemi(param,flocal); } else if(end[i] == 2){ geom(r1,r2,p2,p1,param,basis); - if(param[0] > cutoff) continue; + //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); + if(param[0] > cutoff || param[0] < diameter) continue; fsemi(param,flocal); } else{ - geom(r1,r2,p2,p1,param,basis); - if(param[0] > cutoff) continue; + geom(r1,r2,p1,p2,param,basis); + //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); + if(param[0] > cutoff || param[0] < diameter) continue; finf(param,flocal); } + */ if(eflag){ if(end[i] == 0) evdwl = uinf(param); @@ -276,33 +333,35 @@ void PairMesoCNT::compute(int eflag, int vflag) + flocal[1][1]*basis[1][2] + flocal[1][2]*basis[2][2]; - f[i1][0] = flocal[0][0]*basis[0][0] + f[i1][0] += flocal[0][0]*basis[0][0] + flocal[0][1]*basis[1][0] + flocal[0][2]*basis[2][0]; - f[i1][1] = flocal[0][0]*basis[0][1] + f[i1][1] += flocal[0][0]*basis[0][1] + flocal[0][1]*basis[1][1] + flocal[0][2]*basis[2][1]; - f[i1][2] = flocal[0][0]*basis[0][2] + f[i1][2] += flocal[0][0]*basis[0][2] + flocal[0][1]*basis[1][2] + flocal[0][2]*basis[2][2]; - f[i2][0] = flocal[1][0]*basis[0][0] + f[i2][0] += flocal[1][0]*basis[0][0] + flocal[1][1]*basis[1][0] + flocal[1][2]*basis[2][0]; - f[i2][1] = flocal[1][0]*basis[0][1] + f[i2][1] += flocal[1][0]*basis[0][1] + flocal[1][1]*basis[1][1] + flocal[1][2]*basis[2][1]; - f[i2][2] = flocal[1][0]*basis[0][2] + f[i2][2] += flocal[1][0]*basis[0][2] + flocal[1][1]*basis[1][2] + flocal[1][2]*basis[2][2]; - - /* - printf("Forces:\n"); - printf("%e %e %e\n",f1x,f1y,f1z); - printf("%e %e %e\n",f2x,f2y,f2z); - printf("Parameters:\n"); - printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); + + //printf("Forces:\n"); + //printf("%e %e %e\n",f1x,f1y,f1z); + //printf("%e %e %e\n",f2x,f2y,f2z); + //printf("Forces local:\n"); + //printf("%e %e %e\n",flocal[0][0],flocal[0][1],flocal[0][2]); + //printf("%e %e %e\n",flocal[1][0],flocal[1][1],flocal[1][2]); + //printf("Parameters:\n"); + //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); fflush(stdout); - */ + } memory->destroy(redlist); @@ -318,6 +377,8 @@ void PairMesoCNT::init_style() { int irequest; irequest = neighbor->request(this,instance_me); + neighbor->requests[irequest]->half = 0; + neighbor->requests[irequest]->full = 1; } /* ---------------------------------------------------------------------- */ @@ -404,9 +465,10 @@ void PairMesoCNT::coeff(int narg, char **arg) radius = 1.421*3*n / MY_2PI * angstrom; radiussq = radius * radius; + diameter = 2 * radius; rc = 3 * sigma; - comega = 0.275*(1.0 - 1.0/(1.0 + 0.59*radius/angstrom)); - ctheta = 0.35 + 0.0226*(radius/angstrom - 6.785); + comega = 0.275*(1.0 - 1.0/(1.0 + 0.59*radius*angstromrec)); + ctheta = 0.35 + 0.0226*(radius*angstromrec - 6.785); //Parse and bcast data int me; @@ -447,9 +509,15 @@ void PairMesoCNT::coeff(int narg, char **arg) int n = atom->ntypes; - cutoff = rc + 2*radius; + cutoff = rc + diameter; double cutoffsq = cutoff * cutoff; + //printf("Radius: %e\n",radius); + //printf("Diameter: %e\n",diameter); + //printf("Sigma: %e\n",sigma); + //printf("Critical distance: %e\n",rc); + //printf("Cutoff: %e\n",cutoff); + for (int i = 1; i <= n; i++){ for (int j = i; j <= n; j++){ setflag[i][j] = 1; @@ -457,6 +525,95 @@ void PairMesoCNT::coeff(int narg, char **arg) } } + std::ofstream outFile1; + std::ofstream outFile2; + std::ofstream outFile3; + outFile1.open("test1.dat"); + outFile2.open("test2.dat"); + outFile3.open("test3.dat"); + double u[1000],f[1000]; + for(int i = 0; i < 1000; i++){ + double angle = 0 + i*1/1000.0 * M_PI; + //double h = diameter + 1.0e-10 + i*0.01e-10; + double h = 1.663866e-09; + double y = 0;//-10e-10 + i*0.02e-10; + double f1x,f1y,f1z,f2x,f2y,f2z; + double r1[3] = {-1.0e-9,y,0}; + double r2[3] = {1.0e-9,y,0}; + double p1[3] = {-1.0e-7*cos(angle),-1.0e-7*sin(angle),h}; + double p2[3] = {1.0e-7*cos(angle),1.0e-7*sin(angle),h}; + double param[6]; + double **basis, **flocal; + memory->create(basis,3,3,"pair:basis"); + memory->create(flocal,2,3,"pair:flocal"); + geom(r1,r2,p1,p2,param,basis); + finf(param,flocal); + f[i] = flocal[0][0]; + u[i] = uinf(param); + memory->destroy(flocal); + memory->destroy(basis); + } + for(int i = 0; i < 1000; i++){ + //double h = diameter + 1.0e-10 + i*0.01e-10; + //double y = -10e-10 + i*0.02e-10; + double h = 1.663866e-09; + double angle = 0 + i*1/1000.0 * M_PI; + outFile1 << angle << " " << u[i] << std::endl; + outFile2 << angle << " " << f[i] << std::endl; + if(i != 0 && i != 999){ + double d = (u[i+1] - u[i-1])/0.04e-10; + outFile3 << angle << " " << d << std::endl; + } + } + outFile1.close(); + outFile2.close(); + outFile3.close(); + + double angle = 0.0/180.0 * M_PI; + double f1x,f1y,f1z,f2x,f2y,f2z; + double r1[3] = {-1.0e-9,0,0}; + double r2[3] = {1.0e-9,0,0}; + double p1[3] = {-1.0e-9*cos(angle),-1.0e-9*sin(angle),1.5e-9}; + double p2[3] = {1.0e-9*cos(angle),1.0e-9*sin(angle),1.5e-9}; + double param[6]; + double **basis, **flocal; + memory->create(basis,3,3,"pair:basis"); + memory->create(flocal,2,3,"pair:flocal"); + geom(r1,r2,p1,p2,param,basis); + finf(param,flocal); + f1x = flocal[0][0]*basis[0][0] + + flocal[0][1]*basis[1][0] + + flocal[0][2]*basis[2][0]; + f1y = flocal[0][0]*basis[0][1] + + flocal[0][1]*basis[1][1] + + flocal[0][2]*basis[2][1]; + f1z = flocal[0][0]*basis[0][2] + + flocal[0][1]*basis[1][2] + + flocal[0][2]*basis[2][2]; + f2x = flocal[1][0]*basis[0][0] + + flocal[1][1]*basis[1][0] + + flocal[1][2]*basis[2][0]; + f2y = flocal[1][0]*basis[0][1] + + flocal[1][1]*basis[1][1] + + flocal[1][2]*basis[2][1]; + f2z = flocal[1][0]*basis[0][2] + + flocal[1][1]*basis[1][2] + + flocal[1][2]*basis[2][2]; + + //printf("Param: %e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); + //printf("Forces: \n"); + //printf("%e %e %e\n",f1x,f1y,f1z); + //printf("%e %e %e\n",f2x,f2y,f2z); + //printf("Forces local:\n"); + //printf("%e %e %e \n", flocal[0][0],flocal[0][1],flocal[0][2]); + //printf("%e %e %e \n", flocal[1][0],flocal[1][1],flocal[1][2]); + //printf("Basis: \n"); + //printf("%e %e %e \n",basis[0][0], basis[0][1], basis[0][2]); + //printf("%e %e %e \n",basis[1][0], basis[1][1], basis[1][2]); + //printf("%e %e %e \n",basis[2][0], basis[2][1], basis[2][2]); + + memory->destroy(basis); + memory->destroy(flocal); } /* ---------------------------------------------------------------------- */ @@ -913,7 +1070,8 @@ double PairMesoCNT::uinf(double *param) double sin_alpha = sin(alpha); double sin_alphasq = sin_alpha*sin_alpha; if(sin_alphasq < SMALL){ - return (xi2 - xi1) * spline(h,start_uinf,del_uinf,uinf_coeff,pot_points); + return (xi2 - xi1) * spline(h,start_uinf,del_uinf,uinf_coeff,pot_points) + * qelectron; } else{ double omega = 1.0 / (1.0 - comega*sin_alphasq); @@ -997,7 +1155,7 @@ void PairMesoCNT::finf(double *param, double **f) double sin_alphasq = sin_alpha*sin_alpha; if(sin_alphasq < SMALL){ - f[0][0] = -0.5*(xi2 - xi1)*dspline(h,start_uinf,del_uinf, + f[0][0] = -0.5*(xi1 - xi2)*dspline(h,start_uinf,del_uinf, uinf_coeff,pot_points) * forceunit; f[1][0] = f[0][0]; f[0][1] = 0; @@ -1032,7 +1190,7 @@ void PairMesoCNT::finf(double *param, double **f) if(zeta1 < 0){ phi1 = -spline(-zeta1,h,startzeta_phi,starth_phi, delzeta_phi,delh_phi,phi_coeff,pot_points); - dzeta_phi1 = -dxspline(-zeta1,h,startzeta_phi,starth_phi, + dzeta_phi1 = dxspline(-zeta1,h,startzeta_phi,starth_phi, delzeta_phi,delh_phi,phi_coeff,pot_points); dh_phi1 = -dyspline(-zeta1,h,startzeta_phi,starth_phi, delzeta_phi,delh_phi,phi_coeff,pot_points); @@ -1048,7 +1206,7 @@ void PairMesoCNT::finf(double *param, double **f) if(zeta2 < 0){ phi2 = -spline(-zeta2,h,startzeta_phi,starth_phi, delzeta_phi,delh_phi,phi_coeff,pot_points); - dzeta_phi2 = -dxspline(-zeta2,h,startzeta_phi,starth_phi, + dzeta_phi2 = dxspline(-zeta2,h,startzeta_phi,starth_phi, delzeta_phi,delh_phi,phi_coeff,pot_points); dh_phi2 = -dyspline(-zeta2,h,startzeta_phi,starth_phi, delzeta_phi,delh_phi,phi_coeff,pot_points); @@ -1177,8 +1335,8 @@ void PairMesoCNT::fsemi(double *param, double **f) double cz2 = a1sq*jh2 + cos_alpha*jxi1; double lrec = 1.0 / (xi2 - xi1); - f[0][0] = lrec * (xi2*dh_ubar - cx) * forceunit; - f[1][0] = lrec * (cx - xi1*dh_ubar) * forceunit; + f[0][0] = lrec * (cx - xi2*dh_ubar) * forceunit; + f[1][0] = lrec * (xi1*dh_ubar - cx) * forceunit; f[0][1] = lrec * (dalpha_ubar - xi2*cy) * forceunit; f[1][1] = lrec * (xi1*cy - dalpha_ubar) * forceunit; f[0][2] = lrec * (cz2 + ubar - xi2*cz1) * forceunit; @@ -1196,7 +1354,7 @@ void PairMesoCNT::geom(const double *r1, const double *r2, double psil[3], psim[3], dell_psim[3], delpsil_m[3]; double delr1[3], delr2[3], delp1[3], delp2[3]; double *ex, *ey, *ez; - double psi, frac, taur, taup; + double psi, denom, frac, taur, taup, rhoe; double h, alpha, xi1, xi2, eta1, eta2; ex = basis[0]; @@ -1214,26 +1372,35 @@ void PairMesoCNT::geom(const double *r1, const double *r2, normalize3(l,l); sub3(p2,p1,m); normalize3(m,m); - + psi = dot3(l,m); - frac = 1.0 / (1.0 - psi*psi); - + if(psi > 1.0) psi = 1.0; + else if(psi < -1.0) psi = -1.0; + denom = 1.0 - psi*psi; + copy3(l,psil); scale3(psi,psil); copy3(m,psim); scale3(psi,psim); - sub3(l,psim,dell_psim); - sub3(psil,m,delpsil_m); - taur = dot3(delr,dell_psim) * frac; - taup = dot3(delr,delpsil_m) * frac; + if(denom < SMALL){ + taur = dot3(delr,l); + taup = 0; + } + else{ + frac = 1.0 / denom; + sub3(l,psim,dell_psim); + sub3(psil,m,delpsil_m); + taur = dot3(delr,dell_psim) * frac; + taup = dot3(delr,delpsil_m) * frac; + } scaleadd3(taur,l,r,rbar); scaleadd3(taup,m,p,pbar); sub3(pbar,rbar,delrbar); - - h = len3(delrbar); + h = len3(delrbar); + copy3(delrbar,ex); copy3(l,ez); scale3(1/h,ex); @@ -1274,7 +1441,7 @@ double PairMesoCNT::weight(const double *r1, const double *r2, rhoc = sqrt(0.25*distsq3(r1,r2) + radiussq) + sqrt(0.25*distsq3(p1,p2) + radiussq) + rc; - rhomin = 1.39 * rhoc; + rhomin = 0.72 * rhoc; rho = 0.5 * sqrt(distsq3(r,p)); return s((rho - rhomin)/(rhoc - rhomin)); diff --git a/src/MESOCNT/pair_mesocnt.h b/src/MESOCNT/pair_mesocnt.h index 6b20d906ea..90743499e0 100644 --- a/src/MESOCNT/pair_mesocnt.h +++ b/src/MESOCNT/pair_mesocnt.h @@ -25,7 +25,7 @@ class PairMesoCNT : public Pair { int n, gamma_points, pot_points; double cutoff; double angstrom, angstromrec, qelectron, qelectronrec, forceunit; - double sigma, epsilon, n_sigma, radius, radiussq, rc, rc0, comega, ctheta; + double sigma, epsilon, n_sigma, radius, radiussq, diameter, rc, rc0, comega, ctheta; double start_gamma, start_uinf, startxi_usemi, starth_phi; double del_gamma, del_uinf, delxi_usemi, delh_phi; double *starth_usemi, *startzeta_phi; From 671d6b90ff3667999b250a1bd2e25356001e5ddc Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Thu, 30 May 2019 19:31:38 +0100 Subject: [PATCH 014/392] Fixed bug where segments wouldnt interact and system was blowing up, workin! --- src/MESOCNT/pair_mesocnt.cpp | 85 +++++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 25 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index d904ac8fb4..e234d35565 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -123,7 +123,8 @@ void PairMesoCNT::compute(int eflag, int vflag) numred = 0; for(jj1 = 0; jj1 < j1num; jj1++){ int ind = j1list[jj1]; - if (ind != i1 && ind != i2) redlist[numred++] = ind; + if (mol[ind] == mol[i1] && abs(tag[ind] - tag[i1]) < 5) continue; + redlist[numred++] = ind; } for(jj2 = 0; jj2 < j2num; jj2++){ for(jj1 = 0; jj1 < j1num; jj1++){ @@ -137,7 +138,8 @@ void PairMesoCNT::compute(int eflag, int vflag) continue; } int ind = j2list[jj2]; - if (ind != i1 && ind != i2) redlist[numred++] = ind; + if (mol[ind] == mol[i2] && abs(tag[ind] - tag[i2]) < 5) continue; + redlist[numred++] = ind; } @@ -221,6 +223,7 @@ void PairMesoCNT::compute(int eflag, int vflag) int cn = nchain[i]; int tag1 = tag[chain[i][0]]; int tag2 = tag[chain[i][cn-1]]; + end[i] = 0; if(tag1 == 1) end[i] = 1; else{ int idprev = atom->map(tag1-1); @@ -245,6 +248,8 @@ void PairMesoCNT::compute(int eflag, int vflag) zero3(p1); zero3(p2); sumw = 0; + double sumindex1 = 0; + double sumindex2 = 0; //printf("Vectors r:\n"); //printf("%e %e %e\n",r1[0],r1[1],r1[2]); @@ -257,6 +262,8 @@ void PairMesoCNT::compute(int eflag, int vflag) w = weight(r1,r2,q1,q2); sumw += w; + sumindex1 += w * chain[i][j]; + sumindex2 += w * chain[i][j+1]; //printf("Vectors q %d:\n",j); //printf("%e %e %e\n",q1[0],q1[1],q1[2]); //printf("%e %e %e\n",q2[0],q2[1],q2[2]); @@ -271,6 +278,8 @@ void PairMesoCNT::compute(int eflag, int vflag) if(sumw == 0) continue; sumwreq = 1 / sumw; + sumindex1 *= sumwreq; + sumindex2 *= sumwreq; scale3(sumwreq,p1); scale3(sumwreq,p2); @@ -281,31 +290,39 @@ void PairMesoCNT::compute(int eflag, int vflag) //printf("%e %e %e\n",p2[0],p2[1],p2[2]); fflush(stdout); + /* geom(r1,r2,p1,p2,param,basis); //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); if(param[0] > cutoff || param[0] < diameter) continue; finf(param,flocal); + */ /* + printf("End index: %d\n",end[i]); + if(end[i] == 1) printf("Chain end: %d\n",tag[chain[i][0]]); + else if(end[i] == 2) printf("Chain end: %d\n",tag[chain[i][nchain[i]-1]]); + */ + + if(end[i] == 1){ geom(r1,r2,p1,p2,param,basis); //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); - if(param[0] > cutoff || param[0] < diameter) continue; + if(param[0] > cutoff) continue; fsemi(param,flocal); } else if(end[i] == 2){ geom(r1,r2,p2,p1,param,basis); //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); - if(param[0] > cutoff || param[0] < diameter) continue; + if(param[0] > cutoff) continue; fsemi(param,flocal); } else{ geom(r1,r2,p1,p2,param,basis); //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); - if(param[0] > cutoff || param[0] < diameter) continue; + if(param[0] > cutoff) continue; finf(param,flocal); } - */ + if(eflag){ if(end[i] == 0) evdwl = uinf(param); @@ -352,16 +369,34 @@ void PairMesoCNT::compute(int eflag, int vflag) + flocal[1][1]*basis[1][2] + flocal[1][2]*basis[2][2]; - //printf("Forces:\n"); - //printf("%e %e %e\n",f1x,f1y,f1z); - //printf("%e %e %e\n",f2x,f2y,f2z); - //printf("Forces local:\n"); - //printf("%e %e %e\n",flocal[0][0],flocal[0][1],flocal[0][2]); - //printf("%e %e %e\n",flocal[1][0],flocal[1][1],flocal[1][2]); - //printf("Parameters:\n"); - //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); - fflush(stdout); + double fabs1 = flocal[0][0]*flocal[0][0] + + flocal[0][1]*flocal[0][1] + + flocal[0][2]*flocal[0][2]; + double fabs2 = flocal[1][0]*flocal[1][0] + + flocal[1][1]*flocal[1][1] + + flocal[1][2]*flocal[1][2]; + /* + printf("Vectors r:\n"); + printf("%e %e %e\n",r1[0],r1[1],r1[2]); + printf("%e %e %e\n",r2[0],r2[1],r2[2]); + printf("Vectors p:\n"); + printf("%e %e %e\n",p1[0],p1[1],p1[2]); + printf("%e %e %e\n",p2[0],p2[1],p2[2]); + //printf("Indices current segments:\n"); + //printf("%d %d\n",i1,i2); + //printf("Indices chain:\n"); + //printf("%e %e\n",sumindex1,sumindex2); + printf("Forces:\n"); + printf("%e %e %e\n",f1x,f1y,f1z); + printf("%e %e %e\n",f2x,f2y,f2z); + printf("Forces local:\n"); + printf("%e %e %e\n",flocal[0][0],flocal[0][1],flocal[0][2]); + printf("%e %e %e\n",flocal[1][0],flocal[1][1],flocal[1][2]); + printf("Parameters:\n"); + printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); + fflush(stdout); + */ } memory->destroy(redlist); @@ -533,13 +568,13 @@ void PairMesoCNT::coeff(int narg, char **arg) outFile3.open("test3.dat"); double u[1000],f[1000]; for(int i = 0; i < 1000; i++){ - double angle = 0 + i*1/1000.0 * M_PI; + double angle = i * 2*M_PI/1000.0; //double h = diameter + 1.0e-10 + i*0.01e-10; double h = 1.663866e-09; double y = 0;//-10e-10 + i*0.02e-10; double f1x,f1y,f1z,f2x,f2y,f2z; double r1[3] = {-1.0e-9,y,0}; - double r2[3] = {1.0e-9,y,0}; + double r2[3] = {1.0-9,y,0}; double p1[3] = {-1.0e-7*cos(angle),-1.0e-7*sin(angle),h}; double p2[3] = {1.0e-7*cos(angle),1.0e-7*sin(angle),h}; double param[6]; @@ -557,7 +592,7 @@ void PairMesoCNT::coeff(int narg, char **arg) //double h = diameter + 1.0e-10 + i*0.01e-10; //double y = -10e-10 + i*0.02e-10; double h = 1.663866e-09; - double angle = 0 + i*1/1000.0 * M_PI; + double angle = 0 + i*2*M_PI/1000.0; outFile1 << angle << " " << u[i] << std::endl; outFile2 << angle << " " << f[i] << std::endl; if(i != 0 && i != 999){ @@ -611,7 +646,7 @@ void PairMesoCNT::coeff(int narg, char **arg) //printf("%e %e %e \n",basis[0][0], basis[0][1], basis[0][2]); //printf("%e %e %e \n",basis[1][0], basis[1][1], basis[1][2]); //printf("%e %e %e \n",basis[2][0], basis[2][1], basis[2][2]); - + memory->destroy(basis); memory->destroy(flocal); } @@ -1155,8 +1190,8 @@ void PairMesoCNT::finf(double *param, double **f) double sin_alphasq = sin_alpha*sin_alpha; if(sin_alphasq < SMALL){ - f[0][0] = -0.5*(xi1 - xi2)*dspline(h,start_uinf,del_uinf, - uinf_coeff,pot_points) * forceunit; + f[0][0] = 0.5 * (xi2 - xi1) * dspline(h,start_uinf,del_uinf, + uinf_coeff,pot_points) * forceunit; f[1][0] = f[0][0]; f[0][1] = 0; f[1][1] = 0; @@ -1262,7 +1297,7 @@ void PairMesoCNT::fsemi(double *param, double **f) double omega = 1.0 / (1.0 - comega*sin_alphasq); double omegasq = omega * omega; - double domega = 2 * comega * sin_alpha * cos_alpha * omega * omega; + double domega = 2 * comega * sin_alpha * cos_alpha * omegasq; double theta = 1.0 - ctheta*sin_alphasq; double dtheta = -2 * ctheta * sin_alpha * cos_alpha; @@ -1281,7 +1316,7 @@ void PairMesoCNT::fsemi(double *param, double **f) gamma_coeff,gamma_points) * sin_alphasq; int points = 100; - double delxi = (xi2 - xi1) / (points -1); + double delxi = (xi2 - xi1) / (points - 1); double a3 = delxi * gamma; double jh = 0; @@ -1335,8 +1370,8 @@ void PairMesoCNT::fsemi(double *param, double **f) double cz2 = a1sq*jh2 + cos_alpha*jxi1; double lrec = 1.0 / (xi2 - xi1); - f[0][0] = lrec * (cx - xi2*dh_ubar) * forceunit; - f[1][0] = lrec * (xi1*dh_ubar - cx) * forceunit; + f[0][0] = lrec * (xi2*dh_ubar - cx) * forceunit; + f[1][0] = lrec * (cx - xi1*dh_ubar) * forceunit; f[0][1] = lrec * (dalpha_ubar - xi2*cy) * forceunit; f[1][1] = lrec * (xi1*cy - dalpha_ubar) * forceunit; f[0][2] = lrec * (cz2 + ubar - xi2*cz1) * forceunit; From 6f72db4535eda8e3b925b09beb89ef3b2a5fb09d Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Mon, 3 Jun 2019 11:01:46 +0100 Subject: [PATCH 015/392] checkpoint for Cottrell --- src/MESOCNT/pair_mesocnt.cpp | 137 ++++++++++++++--------------------- 1 file changed, 56 insertions(+), 81 deletions(-) diff --git a/src/MESOCNT/pair_mesocnt.cpp b/src/MESOCNT/pair_mesocnt.cpp index e234d35565..99b5ee1d2e 100644 --- a/src/MESOCNT/pair_mesocnt.cpp +++ b/src/MESOCNT/pair_mesocnt.cpp @@ -99,11 +99,9 @@ void PairMesoCNT::compute(int eflag, int vflag) numneigh = list->numneigh; firstneigh = list->firstneigh; - //printf("Number of bonds: %d\n",nbondlist); for(n = 0; n < nbondlist; n++){ i1 = bondlist[n][0]; i2 = bondlist[n][1]; - //printf("Local IDs in bond: %d %d\n",i1,i2); r1 = x[i1]; r2 = x[i2]; @@ -115,8 +113,6 @@ void PairMesoCNT::compute(int eflag, int vflag) j1num = numneigh[i1]; j2num = numneigh[i2]; - //printf("Bond neighbours: %d\n",j1num + j2num); - if(j1num + j2num == 0) continue; memory->create(redlist,j1num+j2num,"pair:redlist"); @@ -141,7 +137,8 @@ void PairMesoCNT::compute(int eflag, int vflag) if (mol[ind] == mol[i2] && abs(tag[ind] - tag[i2]) < 5) continue; redlist[numred++] = ind; } - + + if (numred < 2) continue; //printf("Unsorted:\n"); for(int mm = 0; mm < numred; mm++){ @@ -182,7 +179,7 @@ void PairMesoCNT::compute(int eflag, int vflag) } //printf("\n"); - fflush(stdout); + //fflush(stdout); // split into connected chains @@ -196,7 +193,6 @@ void PairMesoCNT::compute(int eflag, int vflag) int j1 = redlist[jj]; int j2 = redlist[jj+1]; chain[cid][cnum++] = j1; - //printf("%d %d %d %d\n",cid,tag[j1],tag[j2],abs(tag[j1] - tag[j2])); if(abs(tag[j1] - tag[j2]) != 1 || mol[j1] != mol[j2]){ nchain[cid++] = cnum; cnum = 0; @@ -205,17 +201,6 @@ void PairMesoCNT::compute(int eflag, int vflag) chain[cid][cnum++] = redlist[numred-1]; nchain[cid++] = cnum; - //printf("Chains:\n"); - for(int i = 0; i < cid; i++){ - int cn = nchain[i]; - //printf("Chain %d: ",i); - for(int j = 0; j < cn; j++){ - //printf("%d ", chain[i][j]); - } - //printf("\n"); - } - fflush(stdout); - // check for ends memory->create(end,cid,"pair:end"); @@ -250,6 +235,7 @@ void PairMesoCNT::compute(int eflag, int vflag) sumw = 0; double sumindex1 = 0; double sumindex2 = 0; + int chainnumber = 0; //printf("Vectors r:\n"); //printf("%e %e %e\n",r1[0],r1[1],r1[2]); @@ -260,65 +246,46 @@ void PairMesoCNT::compute(int eflag, int vflag) q2 = x[chain[i][j+1]]; w = weight(r1,r2,q1,q2); + //if(w < SMALL) continue; + chainnumber++; sumw += w; - - sumindex1 += w * chain[i][j]; - sumindex2 += w * chain[i][j+1]; - //printf("Vectors q %d:\n",j); - //printf("%e %e %e\n",q1[0],q1[1],q1[2]); - //printf("%e %e %e\n",q2[0],q2[1],q2[2]); - //printf("Weight: %e\n",w); - fflush(stdout); - - for(int ax = 0; ax < 3; ax++){ - p1[ax] += w * q1[ax]; - p2[ax] += w * q2[ax]; - } + sumindex1 += w*chain[i][j]; + sumindex2 += w*chain[i][j+1]; + MathExtra::scaleadd3(w,q1,p1,p1); + MathExtra::scaleadd3(w,q2,p2,p2); } - - if(sumw == 0) continue; + if (sumw < SMALL) continue; + sumwreq = 1 / sumw; sumindex1 *= sumwreq; sumindex2 *= sumwreq; scale3(sumwreq,p1); scale3(sumwreq,p2); - - //printf("Weight sum:\n"); - //printf("%e\n",sumw); - //printf("Vectors p:\n"); - //printf("%e %e %e\n",p1[0],p1[1],p1[2]); - //printf("%e %e %e\n",p2[0],p2[1],p2[2]); - fflush(stdout); - - /* - geom(r1,r2,p1,p2,param,basis); - //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); - if(param[0] > cutoff || param[0] < diameter) continue; - finf(param,flocal); - */ - + /* printf("End index: %d\n",end[i]); if(end[i] == 1) printf("Chain end: %d\n",tag[chain[i][0]]); else if(end[i] == 2) printf("Chain end: %d\n",tag[chain[i][nchain[i]-1]]); */ + /* + geom(r1,r2,p1,p2,param,basis); + if(param[0] > cutoff) continue; + finf(param,flocal); + */ if(end[i] == 1){ geom(r1,r2,p1,p2,param,basis); - //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); if(param[0] > cutoff) continue; fsemi(param,flocal); } else if(end[i] == 2){ geom(r1,r2,p2,p1,param,basis); - //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); if(param[0] > cutoff) continue; fsemi(param,flocal); } else{ geom(r1,r2,p1,p2,param,basis); - //printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); if(param[0] > cutoff) continue; finf(param,flocal); } @@ -368,25 +335,21 @@ void PairMesoCNT::compute(int eflag, int vflag) f[i2][2] += flocal[1][0]*basis[0][2] + flocal[1][1]*basis[1][2] + flocal[1][2]*basis[2][2]; - - double fabs1 = flocal[0][0]*flocal[0][0] - + flocal[0][1]*flocal[0][1] - + flocal[0][2]*flocal[0][2]; - double fabs2 = flocal[1][0]*flocal[1][0] - + flocal[1][1]*flocal[1][1] - + flocal[1][2]*flocal[1][2]; - /* + if(false){//update->ntimestep > 2039 && i1 > 500){ + //if(uinf(param)>0){ + printf("Timestep: %d\n",update->ntimestep); printf("Vectors r:\n"); printf("%e %e %e\n",r1[0],r1[1],r1[2]); printf("%e %e %e\n",r2[0],r2[1],r2[2]); printf("Vectors p:\n"); printf("%e %e %e\n",p1[0],p1[1],p1[2]); printf("%e %e %e\n",p2[0],p2[1],p2[2]); - //printf("Indices current segments:\n"); - //printf("%d %d\n",i1,i2); - //printf("Indices chain:\n"); - //printf("%e %e\n",sumindex1,sumindex2); + printf("Indices current segments:\n"); + printf("%d %d\n",i1,i2); + printf("Average indices chain with weight:\n"); + printf("%f %f %f %d\n",sumindex1,sumindex2,sumw,chainnumber); + printf("Energy: %e\n",uinf(param)); printf("Forces:\n"); printf("%e %e %e\n",f1x,f1y,f1z); printf("%e %e %e\n",f2x,f2y,f2z); @@ -395,8 +358,13 @@ void PairMesoCNT::compute(int eflag, int vflag) printf("%e %e %e\n",flocal[1][0],flocal[1][1],flocal[1][2]); printf("Parameters:\n"); printf("%e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); + printf("End index: %d\n",end[i]); + if(end[i] == 1) printf("Chain end: %d\n",tag[chain[i][0]]); + else if(end[i] == 2) printf("Chain end: %d\n",tag[chain[i][nchain[i]-1]]); + printf("\n"); fflush(stdout); - */ + } + } memory->destroy(redlist); @@ -560,23 +528,25 @@ void PairMesoCNT::coeff(int narg, char **arg) } } + /* std::ofstream outFile1; std::ofstream outFile2; std::ofstream outFile3; outFile1.open("test1.dat"); outFile2.open("test2.dat"); outFile3.open("test3.dat"); - double u[1000],f[1000]; + double u[1000][1000],f[1000]; for(int i = 0; i < 1000; i++){ - double angle = i * 2*M_PI/1000.0; - //double h = diameter + 1.0e-10 + i*0.01e-10; - double h = 1.663866e-09; - double y = 0;//-10e-10 + i*0.02e-10; + //double angle = i * 2*M_PI; + for(int j = 0; j < 1000; j++){ + double h = 1.67e-09; + double xpos = -4e-09 + i*8e-12; + double ypos = -1e-09 + j*2e-12; double f1x,f1y,f1z,f2x,f2y,f2z; - double r1[3] = {-1.0e-9,y,0}; - double r2[3] = {1.0-9,y,0}; - double p1[3] = {-1.0e-7*cos(angle),-1.0e-7*sin(angle),h}; - double p2[3] = {1.0e-7*cos(angle),1.0e-7*sin(angle),h}; + double r1[3] = {-0.835e-9 + xpos,ypos,0}; + double r2[3] = {0.835e-9 + xpos,ypos,0}; + double p1[3] = {-1.0e-7,0,h}; + double p2[3] = {1.0e-7,0,h}; double param[6]; double **basis, **flocal; memory->create(basis,3,3,"pair:basis"); @@ -584,21 +554,23 @@ void PairMesoCNT::coeff(int narg, char **arg) geom(r1,r2,p1,p2,param,basis); finf(param,flocal); f[i] = flocal[0][0]; - u[i] = uinf(param); + u[i][j] = uinf(param) / qelectron; memory->destroy(flocal); - memory->destroy(basis); + memory->destroy(basis); + } } for(int i = 0; i < 1000; i++){ //double h = diameter + 1.0e-10 + i*0.01e-10; //double y = -10e-10 + i*0.02e-10; double h = 1.663866e-09; double angle = 0 + i*2*M_PI/1000.0; - outFile1 << angle << " " << u[i] << std::endl; - outFile2 << angle << " " << f[i] << std::endl; - if(i != 0 && i != 999){ - double d = (u[i+1] - u[i-1])/0.04e-10; - outFile3 << angle << " " << d << std::endl; + for(int j = 0; j < 1000; j++){ + double xpos = -4e-9 + i*8e-12; + double ypos = -1e-9 + j*2e-12; + outFile1 << xpos*1.0e10 << " " << ypos*1.0e10 << " " << u[i][j] << std::endl; + //outFile2 << angle << " " << f[i] << std::endl; } + outFile1 << std::endl; } outFile1.close(); outFile2.close(); @@ -634,7 +606,8 @@ void PairMesoCNT::coeff(int narg, char **arg) f2z = flocal[1][0]*basis[0][2] + flocal[1][1]*basis[1][2] + flocal[1][2]*basis[2][2]; - + + */ //printf("Param: %e %e %e %e %e %e\n",param[0],param[1],param[2],param[3],param[4],param[5]); //printf("Forces: \n"); //printf("%e %e %e\n",f1x,f1y,f1z); @@ -647,8 +620,10 @@ void PairMesoCNT::coeff(int narg, char **arg) //printf("%e %e %e \n",basis[1][0], basis[1][1], basis[1][2]); //printf("%e %e %e \n",basis[2][0], basis[2][1], basis[2][2]); + /* memory->destroy(basis); memory->destroy(flocal); + */ } /* ---------------------------------------------------------------------- */ From 8bd17765fd3a0867187455cdee6be25e2d44ea9c Mon Sep 17 00:00:00 2001 From: Philipp Kloza Date: Wed, 5 Jun 2019 11:30:21 +0100 Subject: [PATCH 016/392] added mesocnt in make --- src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 3be4e3e78f..e5848d81d7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -54,7 +54,7 @@ endif # PACKEXT = subset that require an external (downloaded) library PACKAGE = asphere body class2 colloid compress coreshell dipole gpu \ - granular kim kokkos kspace latte manybody mc message misc \ + granular kim kokkos kspace latte manybody mc mesocnt message misc \ molecule mpiio mscg opt peri poems \ python qeq replica rigid shock snap spin srd voronoi From 305607d019526cd2ef193bd52b661a691ee05871 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Wed, 16 Dec 2020 11:27:05 -0500 Subject: [PATCH 017/392] type labels: make space for labels put labels in atom.cpp for easy access --- src/atom.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/atom.h | 2 ++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/atom.cpp b/src/atom.cpp index 7b15b731c7..7cc7f1c8ca 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -83,6 +83,7 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) ntypes = 0; nellipsoids = nlines = ntris = nbodies = 0; nbondtypes = nangletypes = ndihedraltypes = nimpropertypes = 0; + atomtypelabel = bondtypelabel = angletypelabel = dihedraltypelabel = impropertypelabel = NULL; nbonds = nangles = ndihedrals = nimpropers = 0; firstgroupname = nullptr; @@ -1692,6 +1693,67 @@ void Atom::allocate_type_arrays() } } +/* ---------------------------------------------------------------------- + allocate character-based type arrays (labels) of length ntypes + always allocated (for both numeric and character-based type modes) + initialize label with (a string of) its numeric counterpart +------------------------------------------------------------------------- */ + +void Atom::allocate_type_labels() +{ + char *char_type = new char[256]; + + atomtypelabel = (char **) memory->srealloc(atomtypelabel, + ntypes*sizeof(char *),"atom:atomtypelabel"); + for (int i = 0; i < ntypes; i++) { + sprintf(char_type,"%d",i+1); + int n = strlen(char_type) + 1; + atom->atomtypelabel[i] = new char[n]; + strcpy(atom->atomtypelabel[i],char_type); + } + if (force->bond) { + bondtypelabel = (char **) memory->srealloc(bondtypelabel, + nbondtypes*sizeof(char *),"atom:bondtypelabel"); + for (int i = 0; i < nbondtypes; i++) { + sprintf(char_type,"%d",i+1); + int n = strlen(char_type) + 1; + atom->bondtypelabel[i] = new char[n]; + strcpy(atom->bondtypelabel[i],char_type); + } + } + if (force->angle) { + angletypelabel = (char **) memory->srealloc(angletypelabel, + nangletypes*sizeof(char *),"atom:angletypelabel"); + for (int i = 0; i < nangletypes; i++) { + sprintf(char_type,"%d",i+1); + int n = strlen(char_type) + 1; + atom->angletypelabel[i] = new char[n]; + strcpy(atom->angletypelabel[i],char_type); + } + } + if (force->dihedral) { + dihedraltypelabel = (char **) memory->srealloc(dihedraltypelabel, + ndihedraltypes*sizeof(char *),"atom:dihedraltypelabel"); + for (int i = 0; i < ndihedraltypes; i++) { + sprintf(char_type,"%d",i+1); + int n = strlen(char_type) + 1; + atom->dihedraltypelabel[i] = new char[n]; + strcpy(atom->dihedraltypelabel[i],char_type); + } + } + if (force->improper) { + impropertypelabel = (char **) memory->srealloc(impropertypelabel, + nimpropertypes*sizeof(char *),"atom:impropertypelabel"); + for (int i = 0; i < nimpropertypes; i++) { + sprintf(char_type,"%d",i+1); + int n = strlen(char_type) + 1; + atom->impropertypelabel[i] = new char[n]; + strcpy(atom->impropertypelabel[i],char_type); + } + } + delete [] char_type; +} + /* ---------------------------------------------------------------------- set a mass and flag it as set called from reading of data file @@ -2714,4 +2776,3 @@ double Atom::memory_usage() return bytes; } - diff --git a/src/atom.h b/src/atom.h index bc69d3b27a..ad2834a9f7 100644 --- a/src/atom.h +++ b/src/atom.h @@ -52,6 +52,7 @@ class Atom : protected Pointers { bigint nbonds,nangles,ndihedrals,nimpropers; int ntypes,nbondtypes,nangletypes,ndihedraltypes,nimpropertypes; + char **atomtypelabel,**bondtypelabel,**angletypelabel,**dihedraltypelabel,**impropertypelabel; int bond_per_atom,angle_per_atom,dihedral_per_atom,improper_per_atom; int extra_bond_per_atom,extra_angle_per_atom; int extra_dihedral_per_atom,extra_improper_per_atom; @@ -308,6 +309,7 @@ class Atom : protected Pointers { void data_fix_compute_variable(int, int); virtual void allocate_type_arrays(); + void allocate_type_labels(); void set_mass(const char *, int, const char *, int); void set_mass(const char *, int, int, double); void set_mass(const char *, int, int, char **); From e4c7ec6933fd07e54619e940233d5a545189c088 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Wed, 16 Dec 2020 12:26:31 -0500 Subject: [PATCH 018/392] read_data: add atomtypelabels section type labels for atoms --- src/read_data.cpp | 35 +++++++++++++++++++++++++++++++++-- src/read_data.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/read_data.cpp b/src/read_data.cpp index e8eb90dcb1..4eb04d460f 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -52,7 +52,7 @@ using namespace LAMMPS_NS; #define MAXBODY 32 // max # of lines in one body // customize for new sections -#define NSECTIONS 25 // change when add to header::section_keywords +#define NSECTIONS 26 // change when add to header::section_keywords enum{NONE,APPEND,VALUE,MERGE}; @@ -440,6 +440,7 @@ void ReadData::command(int narg, char **arg) else n = static_cast (LB_FACTOR * atom->natoms / comm->nprocs); atom->allocate_type_arrays(); + atom->allocate_type_labels(); atom->deallocate_topology(); // allocate atom arrays to N, rounded up by AtomVec->DELTA @@ -712,6 +713,10 @@ void ReadData::command(int narg, char **arg) if (firstpass) impropercoeffs(1); else skip_lines(nimpropertypes); + } else if (strcmp(keyword,"Atom Type Labels") == 0) { + if (firstpass) atomtypelabels(); + else skip_lines(ntypes); + } else error->all(FLERR,fmt::format("Unknown identifier in data file: {}", keyword)); @@ -939,7 +944,8 @@ void ReadData::header(int firstpass) "Dihedral Coeffs","Improper Coeffs", "BondBond Coeffs","BondAngle Coeffs","MiddleBondTorsion Coeffs", "EndBondTorsion Coeffs","AngleTorsion Coeffs", - "AngleAngleTorsion Coeffs","BondBond13 Coeffs","AngleAngle Coeffs"}; + "AngleAngleTorsion Coeffs","BondBond13 Coeffs","AngleAngle Coeffs", + "Atom Type Labels"}; // skip 1st line of file @@ -1901,6 +1907,31 @@ void ReadData::impropercoeffs(int which) delete [] original; } +/* ---------------------------------------------------------------------- */ + +void ReadData::atomtypelabels() +{ + int n; + char *next; + char *buf = new char[ntypes*MAXLINE]; + + int eof = comm->read_lines_from_file(fp,ntypes,MAXLINE,buf); + if (eof) error->all(FLERR,"Unexpected end of data file"); + + char *typelabel = new char[MAXLINE]; + for (int i = 0; i < ntypes; i++) { + next = strchr(buf,'\n'); + *next = '\0'; + sscanf(buf,"%*d %s",typelabel); + n = strlen(typelabel) + 1; + delete [] atom->atomtypelabel[i]; + atom->atomtypelabel[i] = new char[n]; + strcpy(atom->atomtypelabel[i],typelabel); + buf = next + 1; + } + delete [] typelabel; +} + /* ---------------------------------------------------------------------- read fix section, pass lines to fix to process n = index of fix diff --git a/src/read_data.h b/src/read_data.h index 84c098635a..c8547dbd35 100644 --- a/src/read_data.h +++ b/src/read_data.h @@ -106,6 +106,7 @@ class ReadData : protected Pointers { void anglecoeffs(int); void dihedralcoeffs(int); void impropercoeffs(int); + void atomtypelabels(); void fix(int, char *); }; From af1e96c6df9bd54663f2774bc84a0347ca52fa98 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Wed, 16 Dec 2020 12:43:17 -0500 Subject: [PATCH 019/392] generalize read typelabel function will greatly reduce code # of lines --- src/read_data.cpp | 16 ++++++++-------- src/read_data.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/read_data.cpp b/src/read_data.cpp index 4eb04d460f..9f20f0d777 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -714,7 +714,7 @@ void ReadData::command(int narg, char **arg) else skip_lines(nimpropertypes); } else if (strcmp(keyword,"Atom Type Labels") == 0) { - if (firstpass) atomtypelabels(); + if (firstpass) typelabels(atom->atomtypelabel,ntypes); else skip_lines(ntypes); } else error->all(FLERR,fmt::format("Unknown identifier in data file: {}", @@ -1909,24 +1909,24 @@ void ReadData::impropercoeffs(int which) /* ---------------------------------------------------------------------- */ -void ReadData::atomtypelabels() +void ReadData::typelabels(char **mytypelabel, int myntypes) { int n; char *next; - char *buf = new char[ntypes*MAXLINE]; + char *buf = new char[myntypes*MAXLINE]; - int eof = comm->read_lines_from_file(fp,ntypes,MAXLINE,buf); + int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); char *typelabel = new char[MAXLINE]; - for (int i = 0; i < ntypes; i++) { + for (int i = 0; i < myntypes; i++) { next = strchr(buf,'\n'); *next = '\0'; sscanf(buf,"%*d %s",typelabel); n = strlen(typelabel) + 1; - delete [] atom->atomtypelabel[i]; - atom->atomtypelabel[i] = new char[n]; - strcpy(atom->atomtypelabel[i],typelabel); + delete [] mytypelabel[i]; + mytypelabel[i] = new char[n]; + strcpy(mytypelabel[i],typelabel); buf = next + 1; } delete [] typelabel; diff --git a/src/read_data.h b/src/read_data.h index c8547dbd35..91b1338f9e 100644 --- a/src/read_data.h +++ b/src/read_data.h @@ -106,7 +106,7 @@ class ReadData : protected Pointers { void anglecoeffs(int); void dihedralcoeffs(int); void impropercoeffs(int); - void atomtypelabels(); + void typelabels(char **, int); void fix(int, char *); }; From a0911b7563b12ec9c149769ff84ed75f69436dc1 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Wed, 16 Dec 2020 17:00:05 -0500 Subject: [PATCH 020/392] read_data: add bond, etc. label sections --- src/read_data.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/read_data.cpp b/src/read_data.cpp index 9f20f0d777..3245c4fa1e 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -52,7 +52,7 @@ using namespace LAMMPS_NS; #define MAXBODY 32 // max # of lines in one body // customize for new sections -#define NSECTIONS 26 // change when add to header::section_keywords +#define NSECTIONS 30 // change when add to header::section_keywords enum{NONE,APPEND,VALUE,MERGE}; @@ -717,6 +717,26 @@ void ReadData::command(int narg, char **arg) if (firstpass) typelabels(atom->atomtypelabel,ntypes); else skip_lines(ntypes); + } else if (strcmp(keyword,"Bond Type Labels") == 0) { + if (nbondtypes) + if (firstpass) typelabels(atom->bondtypelabel,nbondtypes); + else skip_lines(nbondtypes); + + } else if (strcmp(keyword,"Angle Type Labels") == 0) { + if (nangletypes) + if (firstpass) typelabels(atom->angletypelabel,nangletypes); + else skip_lines(nangletypes); + + } else if (strcmp(keyword,"Dihedral Type Labels") == 0) { + if (ndihedraltypes) + if (firstpass) typelabels(atom->dihedraltypelabel,ndihedraltypes); + else skip_lines(ndihedraltypes); + + } else if (strcmp(keyword,"Improper Type Labels") == 0) { + if (nimpropertypes) + if (firstpass) typelabels(atom->impropertypelabel,nimpropertypes); + else skip_lines(nimpropertypes); + } else error->all(FLERR,fmt::format("Unknown identifier in data file: {}", keyword)); @@ -945,7 +965,8 @@ void ReadData::header(int firstpass) "BondBond Coeffs","BondAngle Coeffs","MiddleBondTorsion Coeffs", "EndBondTorsion Coeffs","AngleTorsion Coeffs", "AngleAngleTorsion Coeffs","BondBond13 Coeffs","AngleAngle Coeffs", - "Atom Type Labels"}; + "Atom Type Labels","Bond Type Labels","Angle Type Labels", + "Dihedral Type Labels","Improper Type Labels"}; // skip 1st line of file From 767584df3683a1bb8a4d49c30d1a208881255eb5 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Wed, 16 Dec 2020 17:39:07 -0500 Subject: [PATCH 021/392] add find_type function find integer type from type label --- src/atom.cpp | 13 +++++++++++++ src/atom.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/atom.cpp b/src/atom.cpp index 7cc7f1c8ca..0574dc5465 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -1754,6 +1754,19 @@ void Atom::allocate_type_labels() delete [] char_type; } +/* ---------------------------------------------------------------------- + find integer type given a type label + return -1 if type not yet defined +------------------------------------------------------------------------- */ + +int Atom::find_type(char *typelabel, char **typelabelarray, int num_types) +{ + for (int i = 0; i < num_types; i++) { + if (typelabelarray[i] && strcmp(typelabel,typelabelarray[i]) == 0) return i+1; + } + return -1; +} + /* ---------------------------------------------------------------------- set a mass and flag it as set called from reading of data file diff --git a/src/atom.h b/src/atom.h index ad2834a9f7..a4cb651d8a 100644 --- a/src/atom.h +++ b/src/atom.h @@ -310,6 +310,7 @@ class Atom : protected Pointers { virtual void allocate_type_arrays(); void allocate_type_labels(); + int find_type(char *, char **, int); void set_mass(const char *, int, const char *, int); void set_mass(const char *, int, int, double); void set_mass(const char *, int, int, char **); From 40953643ec36308798a74100eff1a283536e8be1 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Wed, 16 Dec 2020 19:13:11 -0500 Subject: [PATCH 022/392] clean up atom.cpp type labels --- src/atom.cpp | 16 +++++++++++++++- src/atom.h | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 0574dc5465..47857f97db 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -83,7 +83,8 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) ntypes = 0; nellipsoids = nlines = ntris = nbodies = 0; nbondtypes = nangletypes = ndihedraltypes = nimpropertypes = 0; - atomtypelabel = bondtypelabel = angletypelabel = dihedraltypelabel = impropertypelabel = NULL; + atomtypelabel = bondtypelabel = angletypelabel = NULL; + dihedraltypelabel = impropertypelabel = NULL; nbonds = nangles = ndihedrals = nimpropers = 0; firstgroupname = nullptr; @@ -308,6 +309,19 @@ Atom::~Atom() for (int i = 0; i < nmolecule; i++) delete molecules[i]; memory->sfree(molecules); + // delete type labels + + for (int i = 0; i < ntypes; i++) delete atomtypelabel[i]; + memory->sfree(atomtypelabel); + for (int i = 0; i < nbondtypes; i++) delete bondtypelabel[i]; + memory->sfree(bondtypelabel); + for (int i = 0; i < nangletypes; i++) delete angletypelabel[i]; + memory->sfree(angletypelabel); + for (int i = 0; i < ndihedraltypes; i++) delete dihedraltypelabel[i]; + memory->sfree(dihedraltypelabel); + for (int i = 0; i < nimpropertypes; i++) delete impropertypelabel[i]; + memory->sfree(impropertypelabel); + // delete per-type arrays delete [] mass; diff --git a/src/atom.h b/src/atom.h index a4cb651d8a..852a74850e 100644 --- a/src/atom.h +++ b/src/atom.h @@ -52,7 +52,8 @@ class Atom : protected Pointers { bigint nbonds,nangles,ndihedrals,nimpropers; int ntypes,nbondtypes,nangletypes,ndihedraltypes,nimpropertypes; - char **atomtypelabel,**bondtypelabel,**angletypelabel,**dihedraltypelabel,**impropertypelabel; + char **atomtypelabel,**bondtypelabel,**angletypelabel; + char **dihedraltypelabel,**impropertypelabel; int bond_per_atom,angle_per_atom,dihedral_per_atom,improper_per_atom; int extra_bond_per_atom,extra_angle_per_atom; int extra_dihedral_per_atom,extra_improper_per_atom; From bc32dfb48005b2e618e6c139251c26715885571a Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Wed, 16 Dec 2020 23:07:58 -0500 Subject: [PATCH 023/392] refactor into label_map class --- src/atom.cpp | 110 ++++++++-------------------------------- src/atom.h | 10 ++-- src/label_map.cpp | 124 ++++++++++++++++++++++++++++++++++++++++++++++ src/label_map.h | 44 ++++++++++++++++ src/read_data.cpp | 13 ++--- 5 files changed, 203 insertions(+), 98 deletions(-) create mode 100644 src/label_map.cpp create mode 100644 src/label_map.h diff --git a/src/atom.cpp b/src/atom.cpp index 47857f97db..832385871f 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -23,6 +23,7 @@ #include "force.h" #include "group.h" #include "input.h" +#include "label_map.h" #include "math_const.h" #include "memory.h" #include "modify.h" @@ -83,8 +84,6 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) ntypes = 0; nellipsoids = nlines = ntris = nbodies = 0; nbondtypes = nangletypes = ndihedraltypes = nimpropertypes = 0; - atomtypelabel = bondtypelabel = angletypelabel = NULL; - dihedraltypelabel = impropertypelabel = NULL; nbonds = nangles = ndihedrals = nimpropers = 0; firstgroupname = nullptr; @@ -203,6 +202,10 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) nmolecule = 0; molecules = nullptr; + // type labels + + lmap = nullptr; + // custom atom arrays nivector = ndvector = 0; @@ -309,18 +312,8 @@ Atom::~Atom() for (int i = 0; i < nmolecule; i++) delete molecules[i]; memory->sfree(molecules); - // delete type labels - - for (int i = 0; i < ntypes; i++) delete atomtypelabel[i]; - memory->sfree(atomtypelabel); - for (int i = 0; i < nbondtypes; i++) delete bondtypelabel[i]; - memory->sfree(bondtypelabel); - for (int i = 0; i < nangletypes; i++) delete angletypelabel[i]; - memory->sfree(angletypelabel); - for (int i = 0; i < ndihedraltypes; i++) delete dihedraltypelabel[i]; - memory->sfree(dihedraltypelabel); - for (int i = 0; i < nimpropertypes; i++) delete impropertypelabel[i]; - memory->sfree(impropertypelabel); + // delete label map + delete lmap; // delete per-type arrays @@ -1707,80 +1700,6 @@ void Atom::allocate_type_arrays() } } -/* ---------------------------------------------------------------------- - allocate character-based type arrays (labels) of length ntypes - always allocated (for both numeric and character-based type modes) - initialize label with (a string of) its numeric counterpart -------------------------------------------------------------------------- */ - -void Atom::allocate_type_labels() -{ - char *char_type = new char[256]; - - atomtypelabel = (char **) memory->srealloc(atomtypelabel, - ntypes*sizeof(char *),"atom:atomtypelabel"); - for (int i = 0; i < ntypes; i++) { - sprintf(char_type,"%d",i+1); - int n = strlen(char_type) + 1; - atom->atomtypelabel[i] = new char[n]; - strcpy(atom->atomtypelabel[i],char_type); - } - if (force->bond) { - bondtypelabel = (char **) memory->srealloc(bondtypelabel, - nbondtypes*sizeof(char *),"atom:bondtypelabel"); - for (int i = 0; i < nbondtypes; i++) { - sprintf(char_type,"%d",i+1); - int n = strlen(char_type) + 1; - atom->bondtypelabel[i] = new char[n]; - strcpy(atom->bondtypelabel[i],char_type); - } - } - if (force->angle) { - angletypelabel = (char **) memory->srealloc(angletypelabel, - nangletypes*sizeof(char *),"atom:angletypelabel"); - for (int i = 0; i < nangletypes; i++) { - sprintf(char_type,"%d",i+1); - int n = strlen(char_type) + 1; - atom->angletypelabel[i] = new char[n]; - strcpy(atom->angletypelabel[i],char_type); - } - } - if (force->dihedral) { - dihedraltypelabel = (char **) memory->srealloc(dihedraltypelabel, - ndihedraltypes*sizeof(char *),"atom:dihedraltypelabel"); - for (int i = 0; i < ndihedraltypes; i++) { - sprintf(char_type,"%d",i+1); - int n = strlen(char_type) + 1; - atom->dihedraltypelabel[i] = new char[n]; - strcpy(atom->dihedraltypelabel[i],char_type); - } - } - if (force->improper) { - impropertypelabel = (char **) memory->srealloc(impropertypelabel, - nimpropertypes*sizeof(char *),"atom:impropertypelabel"); - for (int i = 0; i < nimpropertypes; i++) { - sprintf(char_type,"%d",i+1); - int n = strlen(char_type) + 1; - atom->impropertypelabel[i] = new char[n]; - strcpy(atom->impropertypelabel[i],char_type); - } - } - delete [] char_type; -} - -/* ---------------------------------------------------------------------- - find integer type given a type label - return -1 if type not yet defined -------------------------------------------------------------------------- */ - -int Atom::find_type(char *typelabel, char **typelabelarray, int num_types) -{ - for (int i = 0; i < num_types; i++) { - if (typelabelarray[i] && strcmp(typelabel,typelabelarray[i]) == 0) return i+1; - } - return -1; -} - /* ---------------------------------------------------------------------- set a mass and flag it as set called from reading of data file @@ -2056,6 +1975,21 @@ void Atom::add_molecule_atom(Molecule *onemol, int iatom, } } +/* ---------------------------------------------------------------------- + allocate space for type label map +------------------------------------------------------------------------- */ + +void Atom::add_label_map() +{ + lmap = new LabelMap(lmp); + lmap->natomtypes = ntypes; + lmap->nbondtypes = nbondtypes; + lmap->nangletypes = nangletypes; + lmap->ndihedraltypes = ndihedraltypes; + lmap->nimpropertypes = nimpropertypes; + lmap->allocate_type_labels(); +} + /* ---------------------------------------------------------------------- reorder owned atoms so those in firstgroup appear first called by comm->exchange() if atom_modify first group is set diff --git a/src/atom.h b/src/atom.h index 852a74850e..c418bba705 100644 --- a/src/atom.h +++ b/src/atom.h @@ -52,8 +52,6 @@ class Atom : protected Pointers { bigint nbonds,nangles,ndihedrals,nimpropers; int ntypes,nbondtypes,nangletypes,ndihedraltypes,nimpropertypes; - char **atomtypelabel,**bondtypelabel,**angletypelabel; - char **dihedraltypelabel,**impropertypelabel; int bond_per_atom,angle_per_atom,dihedral_per_atom,improper_per_atom; int extra_bond_per_atom,extra_angle_per_atom; int extra_dihedral_per_atom,extra_improper_per_atom; @@ -230,6 +228,10 @@ class Atom : protected Pointers { int nmolecule; class Molecule **molecules; + // type labels + + class LabelMap *lmap; + // extra peratom info in restart file destined for fix & diag double **extra; @@ -310,8 +312,6 @@ class Atom : protected Pointers { void data_fix_compute_variable(int, int); virtual void allocate_type_arrays(); - void allocate_type_labels(); - int find_type(char *, char **, int); void set_mass(const char *, int, const char *, int); void set_mass(const char *, int, int, double); void set_mass(const char *, int, int, char **); @@ -325,6 +325,8 @@ class Atom : protected Pointers { int find_molecule(char *); void add_molecule_atom(class Molecule *, int, int, tagint); + void add_label_map(); + void first_reorder(); virtual void sort(); diff --git a/src/label_map.cpp b/src/label_map.cpp new file mode 100644 index 0000000000..792d625ab2 --- /dev/null +++ b/src/label_map.cpp @@ -0,0 +1,124 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "label_map.h" + +#include "force.h" +#include "memory.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +LabelMap::LabelMap(LAMMPS *lmp) : Pointers(lmp) +{ + natomtypes = nbondtypes = nangletypes = 0; + ndihedraltypes = nimpropertypes = 0; + + typelabel = btypelabel = atypelabel = NULL; + dtypelabel = itypelabel = NULL; +} + +/* ---------------------------------------------------------------------- */ + +LabelMap::~LabelMap() +{ + // delete type labels + + for (int i = 0; i < natomtypes; i++) delete typelabel[i]; + memory->sfree(typelabel); + for (int i = 0; i < nbondtypes; i++) delete btypelabel[i]; + memory->sfree(btypelabel); + for (int i = 0; i < nangletypes; i++) delete atypelabel[i]; + memory->sfree(atypelabel); + for (int i = 0; i < ndihedraltypes; i++) delete dtypelabel[i]; + memory->sfree(dtypelabel); + for (int i = 0; i < nimpropertypes; i++) delete itypelabel[i]; + memory->sfree(itypelabel); +} + +/* ---------------------------------------------------------------------- + allocate character-based type arrays (labels) of length ntypes + always allocated (for both numeric and character-based type modes) + initialize label with (a string of) its numeric counterpart +------------------------------------------------------------------------- */ + +void LabelMap::allocate_type_labels() +{ + char *char_type = new char[256]; + + typelabel = (char **) memory->srealloc(typelabel, + natomtypes*sizeof(char *),"atom:typelabel"); + for (int i = 0; i < natomtypes; i++) { + sprintf(char_type,"%d",i+1); + int n = strlen(char_type) + 1; + typelabel[i] = new char[n]; + strcpy(typelabel[i],char_type); + } + if (force->bond) { + btypelabel = (char **) memory->srealloc(btypelabel, + nbondtypes*sizeof(char *),"atom:btypelabel"); + for (int i = 0; i < nbondtypes; i++) { + sprintf(char_type,"%d",i+1); + int n = strlen(char_type) + 1; + btypelabel[i] = new char[n]; + strcpy(btypelabel[i],char_type); + } + } + if (force->angle) { + atypelabel = (char **) memory->srealloc(atypelabel, + nangletypes*sizeof(char *),"atom:atypelabel"); + for (int i = 0; i < nangletypes; i++) { + sprintf(char_type,"%d",i+1); + int n = strlen(char_type) + 1; + atypelabel[i] = new char[n]; + strcpy(atypelabel[i],char_type); + } + } + if (force->dihedral) { + dtypelabel = (char **) memory->srealloc(dtypelabel, + ndihedraltypes*sizeof(char *),"atom:dtypelabel"); + for (int i = 0; i < ndihedraltypes; i++) { + sprintf(char_type,"%d",i+1); + int n = strlen(char_type) + 1; + dtypelabel[i] = new char[n]; + strcpy(dtypelabel[i],char_type); + } + } + if (force->improper) { + itypelabel = (char **) memory->srealloc(itypelabel, + nimpropertypes*sizeof(char *),"atom:itypelabel"); + for (int i = 0; i < nimpropertypes; i++) { + sprintf(char_type,"%d",i+1); + int n = strlen(char_type) + 1; + itypelabel[i] = new char[n]; + strcpy(itypelabel[i],char_type); + } + } + delete [] char_type; +} + +/* ---------------------------------------------------------------------- + find integer type given a type label + return -1 if type not yet defined +------------------------------------------------------------------------- */ + +int LabelMap::find_type(char *mytypelabel, char **typelabelarray, int num_types) +{ + for (int i = 0; i < num_types; i++) { + if (typelabelarray[i] && strcmp(mytypelabel,typelabelarray[i]) == 0) return i+1; + } + return -1; +} diff --git a/src/label_map.h b/src/label_map.h new file mode 100644 index 0000000000..2f705c451b --- /dev/null +++ b/src/label_map.h @@ -0,0 +1,44 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifndef LMP_LABEL_MAP_H +#define LMP_LABEL_MAP_H + +#include "pointers.h" // IWYU pragma: export + +namespace LAMMPS_NS { + +class LabelMap : protected Pointers { + public: + int natomtypes,nbondtypes,nangletypes; + int ndihedraltypes,nimpropertypes; + char **typelabel,**btypelabel,**atypelabel; + char **dtypelabel,**itypelabel; + + LabelMap(LAMMPS *lmp); + ~LabelMap(); + + void allocate_type_labels(); + int find_type(char *, char **, int); + + protected: +}; + +} + +#endif + +/* ERROR/WARNING messages: + + +*/ diff --git a/src/read_data.cpp b/src/read_data.cpp index 3245c4fa1e..caf280b278 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -33,6 +33,7 @@ #include "group.h" #include "improper.h" #include "irregular.h" +#include "label_map.h" #include "memory.h" #include "modify.h" #include "molecule.h" @@ -440,7 +441,7 @@ void ReadData::command(int narg, char **arg) else n = static_cast (LB_FACTOR * atom->natoms / comm->nprocs); atom->allocate_type_arrays(); - atom->allocate_type_labels(); + atom->add_label_map(); atom->deallocate_topology(); // allocate atom arrays to N, rounded up by AtomVec->DELTA @@ -714,27 +715,27 @@ void ReadData::command(int narg, char **arg) else skip_lines(nimpropertypes); } else if (strcmp(keyword,"Atom Type Labels") == 0) { - if (firstpass) typelabels(atom->atomtypelabel,ntypes); + if (firstpass) typelabels(atom->lmap->typelabel,ntypes); else skip_lines(ntypes); } else if (strcmp(keyword,"Bond Type Labels") == 0) { if (nbondtypes) - if (firstpass) typelabels(atom->bondtypelabel,nbondtypes); + if (firstpass) typelabels(atom->lmap->btypelabel,nbondtypes); else skip_lines(nbondtypes); } else if (strcmp(keyword,"Angle Type Labels") == 0) { if (nangletypes) - if (firstpass) typelabels(atom->angletypelabel,nangletypes); + if (firstpass) typelabels(atom->lmap->atypelabel,nangletypes); else skip_lines(nangletypes); } else if (strcmp(keyword,"Dihedral Type Labels") == 0) { if (ndihedraltypes) - if (firstpass) typelabels(atom->dihedraltypelabel,ndihedraltypes); + if (firstpass) typelabels(atom->lmap->dtypelabel,ndihedraltypes); else skip_lines(ndihedraltypes); } else if (strcmp(keyword,"Improper Type Labels") == 0) { if (nimpropertypes) - if (firstpass) typelabels(atom->impropertypelabel,nimpropertypes); + if (firstpass) typelabels(atom->lmap->itypelabel,nimpropertypes); else skip_lines(nimpropertypes); } else error->all(FLERR,fmt::format("Unknown identifier in data file: {}", From fef2d178e4da6b347f315faef1c1b82c870fa53e Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Thu, 17 Dec 2020 14:21:42 -0500 Subject: [PATCH 024/392] use vector for type label arrays --- src/label_map.cpp | 78 ++++++++++++++--------------------------------- src/label_map.h | 4 +-- src/read_data.cpp | 7 ++--- src/read_data.h | 2 +- 4 files changed, 28 insertions(+), 63 deletions(-) diff --git a/src/label_map.cpp b/src/label_map.cpp index 792d625ab2..df227ab088 100644 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -26,9 +26,6 @@ LabelMap::LabelMap(LAMMPS *lmp) : Pointers(lmp) { natomtypes = nbondtypes = nangletypes = 0; ndihedraltypes = nimpropertypes = 0; - - typelabel = btypelabel = atypelabel = NULL; - dtypelabel = itypelabel = NULL; } /* ---------------------------------------------------------------------- */ @@ -37,16 +34,11 @@ LabelMap::~LabelMap() { // delete type labels - for (int i = 0; i < natomtypes; i++) delete typelabel[i]; - memory->sfree(typelabel); - for (int i = 0; i < nbondtypes; i++) delete btypelabel[i]; - memory->sfree(btypelabel); - for (int i = 0; i < nangletypes; i++) delete atypelabel[i]; - memory->sfree(atypelabel); - for (int i = 0; i < ndihedraltypes; i++) delete dtypelabel[i]; - memory->sfree(dtypelabel); - for (int i = 0; i < nimpropertypes; i++) delete itypelabel[i]; - memory->sfree(itypelabel); + typelabel.clear(); + btypelabel.clear(); + atypelabel.clear(); + dtypelabel.clear(); + itypelabel.clear(); } /* ---------------------------------------------------------------------- @@ -57,57 +49,33 @@ LabelMap::~LabelMap() void LabelMap::allocate_type_labels() { - char *char_type = new char[256]; + typelabel.resize(natomtypes); + for (int i = 0; i < natomtypes; i++) + typelabel[i] = fmt::format("{}",i); - typelabel = (char **) memory->srealloc(typelabel, - natomtypes*sizeof(char *),"atom:typelabel"); - for (int i = 0; i < natomtypes; i++) { - sprintf(char_type,"%d",i+1); - int n = strlen(char_type) + 1; - typelabel[i] = new char[n]; - strcpy(typelabel[i],char_type); - } if (force->bond) { - btypelabel = (char **) memory->srealloc(btypelabel, - nbondtypes*sizeof(char *),"atom:btypelabel"); - for (int i = 0; i < nbondtypes; i++) { - sprintf(char_type,"%d",i+1); - int n = strlen(char_type) + 1; - btypelabel[i] = new char[n]; - strcpy(btypelabel[i],char_type); - } + btypelabel.resize(nbondtypes); + for (int i = 0; i < nbondtypes; i++) + btypelabel[i] = fmt::format("{}",i); } + if (force->angle) { - atypelabel = (char **) memory->srealloc(atypelabel, - nangletypes*sizeof(char *),"atom:atypelabel"); - for (int i = 0; i < nangletypes; i++) { - sprintf(char_type,"%d",i+1); - int n = strlen(char_type) + 1; - atypelabel[i] = new char[n]; - strcpy(atypelabel[i],char_type); - } + atypelabel.resize(nangletypes); + for (int i = 0; i < nangletypes; i++) + atypelabel[i] = fmt::format("{}",i); } + if (force->dihedral) { - dtypelabel = (char **) memory->srealloc(dtypelabel, - ndihedraltypes*sizeof(char *),"atom:dtypelabel"); - for (int i = 0; i < ndihedraltypes; i++) { - sprintf(char_type,"%d",i+1); - int n = strlen(char_type) + 1; - dtypelabel[i] = new char[n]; - strcpy(dtypelabel[i],char_type); - } + dtypelabel.resize(ndihedraltypes); + for (int i = 0; i < ndihedraltypes; i++) + dtypelabel[i] = fmt::format("{}",i); } + if (force->improper) { - itypelabel = (char **) memory->srealloc(itypelabel, - nimpropertypes*sizeof(char *),"atom:itypelabel"); - for (int i = 0; i < nimpropertypes; i++) { - sprintf(char_type,"%d",i+1); - int n = strlen(char_type) + 1; - itypelabel[i] = new char[n]; - strcpy(itypelabel[i],char_type); - } + itypelabel.resize(nimpropertypes); + for (int i = 0; i < nimpropertypes; i++) + itypelabel[i] = fmt::format("{}",i); } - delete [] char_type; } /* ---------------------------------------------------------------------- diff --git a/src/label_map.h b/src/label_map.h index 2f705c451b..e9d2e65386 100644 --- a/src/label_map.h +++ b/src/label_map.h @@ -22,8 +22,8 @@ class LabelMap : protected Pointers { public: int natomtypes,nbondtypes,nangletypes; int ndihedraltypes,nimpropertypes; - char **typelabel,**btypelabel,**atypelabel; - char **dtypelabel,**itypelabel; + std::vector typelabel,btypelabel,atypelabel; + std::vector dtypelabel,itypelabel; LabelMap(LAMMPS *lmp); ~LabelMap(); diff --git a/src/read_data.cpp b/src/read_data.cpp index caf280b278..90c0123dfa 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -1931,7 +1931,7 @@ void ReadData::impropercoeffs(int which) /* ---------------------------------------------------------------------- */ -void ReadData::typelabels(char **mytypelabel, int myntypes) +void ReadData::typelabels(std::vector &mytypelabel, int myntypes) { int n; char *next; @@ -1945,10 +1945,7 @@ void ReadData::typelabels(char **mytypelabel, int myntypes) next = strchr(buf,'\n'); *next = '\0'; sscanf(buf,"%*d %s",typelabel); - n = strlen(typelabel) + 1; - delete [] mytypelabel[i]; - mytypelabel[i] = new char[n]; - strcpy(mytypelabel[i],typelabel); + mytypelabel[i] = typelabel; buf = next + 1; } delete [] typelabel; diff --git a/src/read_data.h b/src/read_data.h index 91b1338f9e..62266c4c37 100644 --- a/src/read_data.h +++ b/src/read_data.h @@ -106,7 +106,7 @@ class ReadData : protected Pointers { void anglecoeffs(int); void dihedralcoeffs(int); void impropercoeffs(int); - void typelabels(char **, int); + void typelabels(std::vector &, int); void fix(int, char *); }; From 48e1d202fe1b01bea5d42828289f4c2b5177848e Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Thu, 7 Jan 2021 10:37:24 -0500 Subject: [PATCH 025/392] refactor to use read_data local lmap also add errors to enforce order of read_data sections --- doc/src/Errors_messages.rst | 15 ++++++++ src/label_map.cpp | 37 ++++++++++++++++++++ src/label_map.h | 1 + src/read_data.cpp | 68 +++++++++++++++++++++++++++++-------- src/read_data.h | 24 +++++++++++++ 5 files changed, 131 insertions(+), 14 deletions(-) mode change 100644 => 100755 doc/src/Errors_messages.rst mode change 100644 => 100755 src/label_map.cpp mode change 100644 => 100755 src/label_map.h mode change 100644 => 100755 src/read_data.cpp mode change 100644 => 100755 src/read_data.h diff --git a/doc/src/Errors_messages.rst b/doc/src/Errors_messages.rst old mode 100644 new mode 100755 index aa38b3c0ba..3a7dcdc2c9 --- a/doc/src/Errors_messages.rst +++ b/doc/src/Errors_messages.rst @@ -5860,6 +5860,12 @@ Doc page with :doc:`WARNING messages ` *Must not have multiple fixes change box parameter ...* Self-explanatory. +*Must read Angle Type Labels before Angles* + An Angle Type Labels section of a data file must come before the Angles section. + +*Must read Atom Type Labels before Atoms* + An Atom Type Labels section of a data file must come before the Atoms section. + *Must read Atoms before Angles* The Atoms section of a data file must come before an Angles section. @@ -5890,6 +5896,15 @@ Doc page with :doc:`WARNING messages ` The Atoms section of a data file must come before a Velocities section. +*Must read Bond Type Labels before Bonds* + A Bond Type Labels section of a data file must come before the Bonds section. + +*Must read Dihedral Type Labels before Dihedrals* + An Dihedral Type Labels section of a data file must come before the Dihedrals section. + +*Must read Improper Type Labels before Impropers* + An Improper Type Labels section of a data file must come before the Impropers section. + *Must re-specify non-restarted pair style (xxx) after read_restart* For pair styles, that do not store their settings in a restart file, it must be defined with a new 'pair_style' command after read_restart. diff --git a/src/label_map.cpp b/src/label_map.cpp old mode 100644 new mode 100755 index df227ab088..ecbc43c258 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -78,6 +78,43 @@ void LabelMap::allocate_type_labels() } } +/* ---------------------------------------------------------------------- + copy lmap1 to lmap2 +------------------------------------------------------------------------- */ + +void LabelMap::copy_lmap(LabelMap *lmap1, LabelMap *lmap2) +{ + int ncopy; + + ncopy = min(lmap1->natomtypes, lmap2->natomtypes); + for (int i = 0; i < ncopy; i++) + lmap2->typelabel[i] = lmap1->typelabel[i]; + + if (force->bond) { + ncopy = min(lmap1->nbondtypes, lmap2->nbondtypes); + for (int i = 0; i < ncopy; i++) + lmap1->btypelabel[i] = lmap2->btypelabel[i]; + } + + if (force->angle) { + ncopy = min(lmap1->nangletypes, lmap2->nangletypes); + for (int i = 0; i < ncopy; i++) + lmap1->atypelabel[i] = lmap2->atypelabel[i]; + } + + if (force->dihedral) { + ncopy = min(lmap1->ndihedraltypes, lmap2->ndihedraltypes); + for (int i = 0; i < ncopy; i++) + lmap1->dtypelabel[i] = lmap2->dtypelabel[i]; + } + + if (force->improper) { + ncopy = min(lmap1->nimpropertypes, lmap2->nimpropertypes); + for (int i = 0; i < ncopy; i++) + lmap1->itypelabel[i] = lmap2->itypelabel[i]; + } +} + /* ---------------------------------------------------------------------- find integer type given a type label return -1 if type not yet defined diff --git a/src/label_map.h b/src/label_map.h old mode 100644 new mode 100755 index e9d2e65386..aafcc827e5 --- a/src/label_map.h +++ b/src/label_map.h @@ -29,6 +29,7 @@ class LabelMap : protected Pointers { ~LabelMap(); void allocate_type_labels(); + void copy_lmap(class LabelMap *, class LabelMap *); int find_type(char *, char **, int); protected: diff --git a/src/read_data.cpp b/src/read_data.cpp old mode 100644 new mode 100755 index 90c0123dfa..59113d8fca --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -490,6 +490,18 @@ void ReadData::command(int narg, char **arg) domain->set_local_box(); } + // allocate space for type label map + + if (firstpass) { + lmap = new LabelMap(lmp); + lmap->natomtypes = ntypes; + lmap->nbondtypes = nbondtypes; + lmap->nangletypes = nangletypes; + lmap->ndihedraltypes = ndihedraltypes; + lmap->nimpropertypes = nimpropertypes; + lmap->allocate_type_labels(); + } + // customize for new sections // read rest of file in free format @@ -715,28 +727,47 @@ void ReadData::command(int narg, char **arg) else skip_lines(nimpropertypes); } else if (strcmp(keyword,"Atom Type Labels") == 0) { - if (firstpass) typelabels(atom->lmap->typelabel,ntypes); - else skip_lines(ntypes); + if (firstpass) { + if (atomflag == 1) + error->all(FLERR,"Must read Atom Type Labels before Atoms"); + typelabels(lmap->typelabel,ntypes); + } else skip_lines(ntypes); } else if (strcmp(keyword,"Bond Type Labels") == 0) { - if (nbondtypes) - if (firstpass) typelabels(atom->lmap->btypelabel,nbondtypes); - else skip_lines(nbondtypes); + if (nbondtypes) { + if (firstpass) { + if (bondflag == 1) + error->all(FLERR,"Must read Bond Type Labels before Bonds"); + typelabels(lmap->btypelabel,nbondtypes); + } else skip_lines(nbondtypes); + } } else if (strcmp(keyword,"Angle Type Labels") == 0) { - if (nangletypes) - if (firstpass) typelabels(atom->lmap->atypelabel,nangletypes); - else skip_lines(nangletypes); + if (nangletypes) { + if (firstpass) { + if (angleflag == 1) + error->all(FLERR,"Must read Angle Type Labels before Angles"); + typelabels(lmap->atypelabel,nangletypes); + } else skip_lines(nangletypes); + } } else if (strcmp(keyword,"Dihedral Type Labels") == 0) { - if (ndihedraltypes) - if (firstpass) typelabels(atom->lmap->dtypelabel,ndihedraltypes); - else skip_lines(ndihedraltypes); + if (ndihedraltypes) { + if (firstpass) { + if (dihedralflag == 1) + error->all(FLERR,"Must read Dihedral Type Labels before Dihedrals"); + typelabels(lmap->dtypelabel,ndihedraltypes); + } else skip_lines(ndihedraltypes); + } } else if (strcmp(keyword,"Improper Type Labels") == 0) { - if (nimpropertypes) - if (firstpass) typelabels(atom->lmap->itypelabel,nimpropertypes); - else skip_lines(nimpropertypes); + if (nimpropertypes) { + if (firstpass) { + if (improperflag == 1) + error->all(FLERR,"Must read Improper Type Labels before Impropers"); + typelabels(lmap->itypelabel,nimpropertypes); + } else skip_lines(nimpropertypes); + } } else error->all(FLERR,fmt::format("Unknown identifier in data file: {}", keyword)); @@ -1949,6 +1980,15 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes) buf = next + 1; } delete [] typelabel; + + // if first data file, assign this label map to atom class + // else, determine mapping to let labels override numeric types + + if (addflag == NONE) { + lmap->copy_lmap(lmap,atom->lmap); + } else { + ; // get lmap2lmap mapping. ...in progress... + } } /* ---------------------------------------------------------------------- diff --git a/src/read_data.h b/src/read_data.h old mode 100644 new mode 100755 index 62266c4c37..499b08ed9c --- a/src/read_data.h +++ b/src/read_data.h @@ -55,6 +55,10 @@ class ReadData : protected Pointers { bigint nbodies; class AtomVecBody *avec_body; + // type labels + + class LabelMap *lmap; + // box info double boxlo[3],boxhi[3]; @@ -398,6 +402,26 @@ E: Must define improper_style before AngleAngle Coeffs Must use an improper_style command before reading a data file that defines AngleAngle Coeffs. +E: Must read Atom Type Labels before Atoms + +An Atom Type Labels section of a data file must come before the Atoms section. + +E: Must read Bond Type Labels before Bonds + +A Bond Type Labels section of a data file must come before the Bonds section. + +E: Must read Angle Type Labels before Angles + +An Angle Type Labels section of a data file must come before the Angles section. + +E: Must read Dihedral Type Labels before Dihedrals + +An Dihedral Type Labels section of a data file must come before the Dihedrals section. + +E: Must read Improper Type Labels before Impropers + +An Improper Type Labels section of a data file must come before the Impropers section. + E: Unknown identifier in data file: %s A section of the data file cannot be read by LAMMPS. From 73968fb4d89b6454e14d31329474d118501e0cbe Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Thu, 7 Jan 2021 20:15:25 -0500 Subject: [PATCH 026/392] prepare for multiple data files not yet tested --- src/atom.cpp | 1 + src/label_map.cpp | 126 +++++++++++++++++++++++++++++++++++++--------- src/label_map.h | 22 +++++++- src/read_data.cpp | 6 +-- 4 files changed, 127 insertions(+), 28 deletions(-) mode change 100644 => 100755 src/atom.cpp diff --git a/src/atom.cpp b/src/atom.cpp old mode 100644 new mode 100755 index 832385871f..f7dfc13d45 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -313,6 +313,7 @@ Atom::~Atom() memory->sfree(molecules); // delete label map + delete lmap; // delete per-type arrays diff --git a/src/label_map.cpp b/src/label_map.cpp index ecbc43c258..a6b25827ef 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -15,6 +15,7 @@ #include "force.h" #include "memory.h" +#include "error.h" #include @@ -39,6 +40,12 @@ LabelMap::~LabelMap() atypelabel.clear(); dtypelabel.clear(); itypelabel.clear(); + + delete [] lmap2lmap.atom; + delete [] lmap2lmap.bond; + delete [] lmap2lmap.angle; + delete [] lmap2lmap.dihedral; + delete [] lmap2lmap.improper; } /* ---------------------------------------------------------------------- @@ -76,54 +83,127 @@ void LabelMap::allocate_type_labels() for (int i = 0; i < nimpropertypes; i++) itypelabel[i] = fmt::format("{}",i); } + + // allocate space for lmap2lmap + + lmap2lmap.atom = new int[natomtypes]; + lmap2lmap.bond = new int[nbondtypes]; + lmap2lmap.angle = new int[nangletypes]; + lmap2lmap.dihedral = new int[ndihedraltypes]; + lmap2lmap.improper = new int[nimpropertypes]; } /* ---------------------------------------------------------------------- - copy lmap1 to lmap2 + copy another map (lmap2) into this one + if label already exists, leave in place + else, put new label in next available slot ------------------------------------------------------------------------- */ -void LabelMap::copy_lmap(LabelMap *lmap1, LabelMap *lmap2) +void LabelMap::merge_lmap(class LabelMap *lmap2) { - int ncopy; - - ncopy = min(lmap1->natomtypes, lmap2->natomtypes); - for (int i = 0; i < ncopy; i++) - lmap2->typelabel[i] = lmap1->typelabel[i]; + for (int i = 0; i < lmap2->natomtypes; i++) + find_or_create(lmap2->typelabel[i],typelabel,natomtypes); if (force->bond) { - ncopy = min(lmap1->nbondtypes, lmap2->nbondtypes); - for (int i = 0; i < ncopy; i++) - lmap1->btypelabel[i] = lmap2->btypelabel[i]; + for (int i = 0; i < lmap2->nbondtypes; i++) + find_or_create(lmap2->btypelabel[i],btypelabel,nbondtypes); } if (force->angle) { - ncopy = min(lmap1->nangletypes, lmap2->nangletypes); - for (int i = 0; i < ncopy; i++) - lmap1->atypelabel[i] = lmap2->atypelabel[i]; + for (int i = 0; i < lmap2->nangletypes; i++) + find_or_create(lmap2->atypelabel[i],atypelabel,nangletypes); } if (force->dihedral) { - ncopy = min(lmap1->ndihedraltypes, lmap2->ndihedraltypes); - for (int i = 0; i < ncopy; i++) - lmap1->dtypelabel[i] = lmap2->dtypelabel[i]; + for (int i = 0; i < lmap2->ndihedraltypes; i++) + find_or_create(lmap2->dtypelabel[i],dtypelabel,ndihedraltypes); } if (force->improper) { - ncopy = min(lmap1->nimpropertypes, lmap2->nimpropertypes); - for (int i = 0; i < ncopy; i++) - lmap1->itypelabel[i] = lmap2->itypelabel[i]; + for (int i = 0; i < lmap2->nimpropertypes; i++) + find_or_create(lmap2->itypelabel[i],itypelabel,nimpropertypes); } } +/* ---------------------------------------------------------------------- + get mapping between this label map and another (lmap2) + values of lmap2lmap point to equivalent indices in lmap2 +------------------------------------------------------------------------- */ + +void LabelMap::create_lmap2lmap(class LabelMap *lmap2) +{ + int type; + + for (int i = 0; i < natomtypes; i++) { + type = find(typelabel[i],lmap2->typelabel,lmap2->natomtypes); + lmap2lmap.atom[i] = type - 1; + } + + if (force->bond) { + lmap2lmap.bond = new int[nbondtypes]; + for (int i = 0; i < nbondtypes; i++) { + type = find(btypelabel[i],lmap2->btypelabel,lmap2->nbondtypes); + lmap2lmap.bond[i] = type - 1; + } + } + + if (force->angle) { + for (int i = 0; i < nangletypes; i++) { + type = find(atypelabel[i],lmap2->atypelabel,lmap2->nangletypes); + lmap2lmap.angle[i] = type - 1; + } + } + + if (force->dihedral) { + for (int i = 0; i < ndihedraltypes; i++) { + type = find(dtypelabel[i],lmap2->dtypelabel,lmap2->ndihedraltypes); + lmap2lmap.dihedral[i] = type - 1; + } + } + + if (force->improper) { + for (int i = 0; i < nimpropertypes; i++) { + type = find(itypelabel[i],lmap2->itypelabel,lmap2->nimpropertypes); + lmap2lmap.improper[i] = type - 1; + } + } +} + +/* ---------------------------------------------------------------------- + find type label with name or create type if it doesn't exist + return numeric type +------------------------------------------------------------------------- */ + +int LabelMap::find_or_create(std::string mylabel, std::vector labels, int ntypes) +{ + for (int i = 0; i < ntypes; i++) + if (labels[i] == mylabel) return i+1; + + // if no match found, create new label at next available index + // label map assumed to be intialized with numeric index + // user labels are assumed to be alphanumeric (not a number) + + for (int i = 0; i < ntypes; i++) { + if (stoi(labels[i]) != i+1) { + labels[i] = mylabel; + return i+1; + } + } + + // if label cannot be found or created, need more space reserved + + error->all(FLERR,"Topology type exceeds system topology type"); +} + /* ---------------------------------------------------------------------- find integer type given a type label return -1 if type not yet defined ------------------------------------------------------------------------- */ -int LabelMap::find_type(char *mytypelabel, char **typelabelarray, int num_types) +int LabelMap::find(std::string mylabel, std::vector labels, int ntypes) { - for (int i = 0; i < num_types; i++) { - if (typelabelarray[i] && strcmp(mytypelabel,typelabelarray[i]) == 0) return i+1; - } + for (int i = 0; i < ntypes; i++) + if (labels[i] == mylabel) return i+1; + return -1; } diff --git a/src/label_map.h b/src/label_map.h index aafcc827e5..309dce7de2 100755 --- a/src/label_map.h +++ b/src/label_map.h @@ -25,12 +25,26 @@ class LabelMap : protected Pointers { std::vector typelabel,btypelabel,atypelabel; std::vector dtypelabel,itypelabel; + // per-type data struct mapping this label map to another + + struct Lmap2Lmap { + int *atom; + int *bond; + int *angle; + int *dihedral; + int *improper; + }; + + Lmap2Lmap lmap2lmap; + LabelMap(LAMMPS *lmp); ~LabelMap(); void allocate_type_labels(); - void copy_lmap(class LabelMap *, class LabelMap *); - int find_type(char *, char **, int); + void merge_lmap(class LabelMap *); // copy another lmap into this one + void create_lmap2lmap(class LabelMap *); // index mapping between two lmaps + int find_or_create(std::string, std::vector, int); // look up type or create new type + int find(std::string, std::vector, int); // look up type index protected: }; @@ -41,5 +55,9 @@ class LabelMap : protected Pointers { /* ERROR/WARNING messages: +E: Topology type exceeds system topology type + +The number of bond, angle, etc types exceeds the system setting. See +the create_box or read_data command for how to specify these values. */ diff --git a/src/read_data.cpp b/src/read_data.cpp index 59113d8fca..ff09cfe2a8 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -1981,13 +1981,13 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes) } delete [] typelabel; - // if first data file, assign this label map to atom class + // if first data file, assign this read_data label map to atom class // else, determine mapping to let labels override numeric types if (addflag == NONE) { - lmap->copy_lmap(lmap,atom->lmap); + atom->lmap->merge_lmap(lmap); } else { - ; // get lmap2lmap mapping. ...in progress... + lmap->create_lmap2lmap(atom->lmap); } } From d01b19923db22d5aec7894d964a9b456c4b5f582 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Thu, 7 Jan 2021 23:01:15 -0500 Subject: [PATCH 027/392] add write_data support, for testing also refactor label map initialization, memory cleanup --- src/label_map.cpp | 91 +++++++++++++++++++++++++++++++--------------- src/label_map.h | 3 +- src/write_data.cpp | 5 +++ 3 files changed, 69 insertions(+), 30 deletions(-) diff --git a/src/label_map.cpp b/src/label_map.cpp index a6b25827ef..856e7b5ad8 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -36,16 +36,27 @@ LabelMap::~LabelMap() // delete type labels typelabel.clear(); - btypelabel.clear(); - atypelabel.clear(); - dtypelabel.clear(); - itypelabel.clear(); - delete [] lmap2lmap.atom; - delete [] lmap2lmap.bond; - delete [] lmap2lmap.angle; - delete [] lmap2lmap.dihedral; - delete [] lmap2lmap.improper; + + if (force->bond) { + btypelabel.clear(); + delete [] lmap2lmap.bond; + } + + if (force->angle) { + atypelabel.clear(); + delete [] lmap2lmap.angle; + } + + if (force->dihedral) { + dtypelabel.clear(); + delete [] lmap2lmap.dihedral; + } + + if (force->improper) { + itypelabel.clear(); + delete [] lmap2lmap.improper; + } } /* ---------------------------------------------------------------------- @@ -57,40 +68,27 @@ LabelMap::~LabelMap() void LabelMap::allocate_type_labels() { typelabel.resize(natomtypes); - for (int i = 0; i < natomtypes; i++) - typelabel[i] = fmt::format("{}",i); + lmap2lmap.atom = new int[natomtypes]; if (force->bond) { btypelabel.resize(nbondtypes); - for (int i = 0; i < nbondtypes; i++) - btypelabel[i] = fmt::format("{}",i); + lmap2lmap.bond = new int[nbondtypes]; } if (force->angle) { atypelabel.resize(nangletypes); - for (int i = 0; i < nangletypes; i++) - atypelabel[i] = fmt::format("{}",i); + lmap2lmap.angle = new int[nangletypes]; } if (force->dihedral) { dtypelabel.resize(ndihedraltypes); - for (int i = 0; i < ndihedraltypes; i++) - dtypelabel[i] = fmt::format("{}",i); + lmap2lmap.dihedral = new int[ndihedraltypes]; } if (force->improper) { itypelabel.resize(nimpropertypes); - for (int i = 0; i < nimpropertypes; i++) - itypelabel[i] = fmt::format("{}",i); + lmap2lmap.improper = new int[nimpropertypes]; } - - // allocate space for lmap2lmap - - lmap2lmap.atom = new int[natomtypes]; - lmap2lmap.bond = new int[nbondtypes]; - lmap2lmap.angle = new int[nangletypes]; - lmap2lmap.dihedral = new int[ndihedraltypes]; - lmap2lmap.improper = new int[nimpropertypes]; } /* ---------------------------------------------------------------------- @@ -174,7 +172,7 @@ void LabelMap::create_lmap2lmap(class LabelMap *lmap2) return numeric type ------------------------------------------------------------------------- */ -int LabelMap::find_or_create(std::string mylabel, std::vector labels, int ntypes) +int LabelMap::find_or_create(std::string mylabel, std::vector &labels, int ntypes) { for (int i = 0; i < ntypes; i++) if (labels[i] == mylabel) return i+1; @@ -184,7 +182,7 @@ int LabelMap::find_or_create(std::string mylabel, std::vector label // user labels are assumed to be alphanumeric (not a number) for (int i = 0; i < ntypes; i++) { - if (stoi(labels[i]) != i+1) { + if (labels[i].empty()) { labels[i] = mylabel; return i+1; } @@ -207,3 +205,38 @@ int LabelMap::find(std::string mylabel, std::vector labels, int nty return -1; } + +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void LabelMap::write_data(FILE *fp) +{ + fmt::print(fp,"\nAtom Type Labels\n\n"); + for (int i = 0; i < natomtypes; i++) + fmt::print(fp,"{} {}\n",i+1,typelabel[i]); + + if (force->bond) { + fmt::print(fp,"\nBond Type Labels\n\n"); + for (int i = 0; i < nbondtypes; i++) + fmt::print(fp,"{} {}\n",i+1,btypelabel[i]); + } + + if (force->angle) { + fmt::print(fp,"\nAngle Type Labels\n\n"); + for (int i = 0; i < nangletypes; i++) + fmt::print(fp,"{} {}\n",i+1,atypelabel[i]); + } + + if (force->dihedral) { + fmt::print(fp,"\nDihedral Type Labels\n\n"); + for (int i = 0; i < ndihedraltypes; i++) + fmt::print(fp,"{} {}\n",i+1,dtypelabel[i]); + } + + if (force->improper) { + fmt::print(fp,"\nImproper Type Labels\n\n"); + for (int i = 0; i < nimpropertypes; i++) + fmt::print(fp,"{} {}\n",i+1,itypelabel[i]); + } +} diff --git a/src/label_map.h b/src/label_map.h index 309dce7de2..8bf2267d50 100755 --- a/src/label_map.h +++ b/src/label_map.h @@ -43,8 +43,9 @@ class LabelMap : protected Pointers { void allocate_type_labels(); void merge_lmap(class LabelMap *); // copy another lmap into this one void create_lmap2lmap(class LabelMap *); // index mapping between two lmaps - int find_or_create(std::string, std::vector, int); // look up type or create new type + int find_or_create(std::string, std::vector &, int); // look up type or create new type int find(std::string, std::vector, int); // look up type index + void write_data(FILE *); protected: }; diff --git a/src/write_data.cpp b/src/write_data.cpp index 6d10359e8b..4ca0752e72 100644 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -24,6 +24,7 @@ #include "fix.h" #include "force.h" #include "improper.h" +#include "label_map.h" #include "memory.h" #include "modify.h" #include "output.h" @@ -188,6 +189,10 @@ void WriteData::write(const std::string &file) if (coeffflag) force_fields(); } + // label map before Atoms, Bonds, etc. + + if (me == 0) atom->lmap->write_data(fp); // NOTE: always write for now, for testing + // per atom info in Atoms and Velocities sections if (natoms) atoms(); From 03b697a6e01691cae0de52f81ae682d7527d8605 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Fri, 8 Jan 2021 23:22:19 -0500 Subject: [PATCH 028/392] labels: introduce framework for multiple data files subsequent data files merge types with first starting with support for selected atom types sections, will attach small example to PR --- src/atom.cpp | 8 +++-- src/atom.h | 5 ++-- src/label_map.cpp | 74 +++++++++++++++++++--------------------------- src/label_map.h | 5 ++-- src/read_data.cpp | 68 ++++++++++++++++++++++-------------------- src/read_data.h | 6 ++-- src/write_data.cpp | 6 ++-- 7 files changed, 83 insertions(+), 89 deletions(-) mode change 100644 => 100755 src/atom.h diff --git a/src/atom.cpp b/src/atom.cpp index f7dfc13d45..fecb8708be 100755 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -1029,7 +1029,8 @@ void Atom::deallocate_topology() ------------------------------------------------------------------------- */ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset, - int type_offset, int shiftflag, double *shift) + int type_offset, int shiftflag, double *shift, + int labelflag, int *ilabel) { int m,xptr,iptr; imageint imagedata; @@ -1164,6 +1165,7 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset, avec->data_atom(xdata,imagedata,values); if (id_offset) tag[nlocal-1] += id_offset; if (mol_offset) molecule[nlocal-1] += mol_offset; + if (labelflag) type[nlocal-1] = ilabel[type[nlocal-1]-1]; if (type_offset) { type[nlocal-1] += type_offset; if (type[nlocal-1] > ntypes) @@ -1707,7 +1709,8 @@ void Atom::allocate_type_arrays() type_offset may be used when reading multiple data files ------------------------------------------------------------------------- */ -void Atom::set_mass(const char *file, int line, const char *str, int type_offset) +void Atom::set_mass(const char *file, int line, const char *str, int type_offset, + int labelflag, int *ilabel) { if (mass == nullptr) error->all(file,line,"Cannot set mass for this atom style"); @@ -1715,6 +1718,7 @@ void Atom::set_mass(const char *file, int line, const char *str, int type_offset double mass_one; int n = sscanf(str,"%d %lg",&itype,&mass_one); if (n != 2) error->all(file,line,"Invalid mass line in data file"); + if (labelflag) itype = ilabel[itype-1]; itype += type_offset; if (itype < 1 || itype > ntypes) diff --git a/src/atom.h b/src/atom.h old mode 100644 new mode 100755 index c418bba705..d32e300750 --- a/src/atom.h +++ b/src/atom.h @@ -301,7 +301,8 @@ class Atom : protected Pointers { void deallocate_topology(); - void data_atoms(int, char *, tagint, tagint, int, int, double *); + void data_atoms(int, char *, tagint, tagint, int, int, double *, + int, int *); void data_vels(int, char *, tagint); void data_bonds(int, char *, int *, tagint, int); void data_angles(int, char *, int *, tagint, int); @@ -312,7 +313,7 @@ class Atom : protected Pointers { void data_fix_compute_variable(int, int); virtual void allocate_type_arrays(); - void set_mass(const char *, int, const char *, int); + void set_mass(const char *, int, const char *, int, int, int *); void set_mass(const char *, int, int, double); void set_mass(const char *, int, int, char **); void set_mass(double *); diff --git a/src/label_map.cpp b/src/label_map.cpp index 856e7b5ad8..10476417e8 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -97,74 +97,60 @@ void LabelMap::allocate_type_labels() else, put new label in next available slot ------------------------------------------------------------------------- */ -void LabelMap::merge_lmap(class LabelMap *lmap2) +void LabelMap::merge_lmap(LabelMap *lmap2, int mode) { - for (int i = 0; i < lmap2->natomtypes; i++) - find_or_create(lmap2->typelabel[i],typelabel,natomtypes); + if (mode == ATOM) + for (int i = 0; i < lmap2->natomtypes; i++) + find_or_create(lmap2->typelabel[i],typelabel,natomtypes); - if (force->bond) { + if (mode == BOND) for (int i = 0; i < lmap2->nbondtypes; i++) find_or_create(lmap2->btypelabel[i],btypelabel,nbondtypes); - } - if (force->angle) { + if (mode == ANGLE) for (int i = 0; i < lmap2->nangletypes; i++) find_or_create(lmap2->atypelabel[i],atypelabel,nangletypes); - } - if (force->dihedral) { + if (mode == DIHEDRAL) for (int i = 0; i < lmap2->ndihedraltypes; i++) find_or_create(lmap2->dtypelabel[i],dtypelabel,ndihedraltypes); - } - if (force->improper) { + if (mode == IMPROPER) for (int i = 0; i < lmap2->nimpropertypes; i++) find_or_create(lmap2->itypelabel[i],itypelabel,nimpropertypes); - } } /* ---------------------------------------------------------------------- get mapping between this label map and another (lmap2) - values of lmap2lmap point to equivalent indices in lmap2 + values of lmap2lmap point to equivalent types in lmap2 ------------------------------------------------------------------------- */ -void LabelMap::create_lmap2lmap(class LabelMap *lmap2) +void LabelMap::create_lmap2lmap(LabelMap *lmap2, int mode) { - int type; + if (mode == ATOM) + for (int i = 0; i < natomtypes; i++) + lmap2lmap.atom[i] = find(typelabel[i],lmap2->typelabel, + lmap2->natomtypes); - for (int i = 0; i < natomtypes; i++) { - type = find(typelabel[i],lmap2->typelabel,lmap2->natomtypes); - lmap2lmap.atom[i] = type - 1; - } + if (mode == BOND) + for (int i = 0; i < nbondtypes; i++) + lmap2lmap.bond[i] = find(btypelabel[i],lmap2->btypelabel, + lmap2->nbondtypes); - if (force->bond) { - lmap2lmap.bond = new int[nbondtypes]; - for (int i = 0; i < nbondtypes; i++) { - type = find(btypelabel[i],lmap2->btypelabel,lmap2->nbondtypes); - lmap2lmap.bond[i] = type - 1; - } - } + if (mode == ANGLE) + for (int i = 0; i < nangletypes; i++) + lmap2lmap.angle[i] = find(atypelabel[i],lmap2->atypelabel, + lmap2->nangletypes); - if (force->angle) { - for (int i = 0; i < nangletypes; i++) { - type = find(atypelabel[i],lmap2->atypelabel,lmap2->nangletypes); - lmap2lmap.angle[i] = type - 1; - } - } + if (mode == DIHEDRAL) + for (int i = 0; i < ndihedraltypes; i++) + lmap2lmap.dihedral[i] = find(dtypelabel[i],lmap2->dtypelabel, + lmap2->ndihedraltypes); - if (force->dihedral) { - for (int i = 0; i < ndihedraltypes; i++) { - type = find(dtypelabel[i],lmap2->dtypelabel,lmap2->ndihedraltypes); - lmap2lmap.dihedral[i] = type - 1; - } - } - - if (force->improper) { - for (int i = 0; i < nimpropertypes; i++) { - type = find(itypelabel[i],lmap2->itypelabel,lmap2->nimpropertypes); - lmap2lmap.improper[i] = type - 1; - } - } + if (mode == IMPROPER) + for (int i = 0; i < nimpropertypes; i++) + lmap2lmap.improper[i] = find(itypelabel[i],lmap2->itypelabel, + lmap2->nimpropertypes); } /* ---------------------------------------------------------------------- diff --git a/src/label_map.h b/src/label_map.h index 8bf2267d50..4372ebaa86 100755 --- a/src/label_map.h +++ b/src/label_map.h @@ -20,6 +20,7 @@ namespace LAMMPS_NS { class LabelMap : protected Pointers { public: + enum{ATOM,BOND,ANGLE,DIHEDRAL,IMPROPER}; int natomtypes,nbondtypes,nangletypes; int ndihedraltypes,nimpropertypes; std::vector typelabel,btypelabel,atypelabel; @@ -41,8 +42,8 @@ class LabelMap : protected Pointers { ~LabelMap(); void allocate_type_labels(); - void merge_lmap(class LabelMap *); // copy another lmap into this one - void create_lmap2lmap(class LabelMap *); // index mapping between two lmaps + void merge_lmap(class LabelMap *, int); // copy another lmap into this one + void create_lmap2lmap(class LabelMap *, int); // index mapping between two lmaps int find_or_create(std::string, std::vector &, int); // look up type or create new type int find(std::string, std::vector, int); // look up type index void write_data(FILE *); diff --git a/src/read_data.cpp b/src/read_data.cpp index ff09cfe2a8..a7e3f75c3c 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -124,7 +124,7 @@ void ReadData::command(int narg, char **arg) addflag = NONE; coeffflag = 1; id_offset = mol_offset = 0; - offsetflag = shiftflag = 0; + offsetflag = shiftflag = labelflag = 0; toffset = boffset = aoffset = doffset = ioffset = 0; shift[0] = shift[1] = shift[2] = 0.0; extra_atom_types = extra_bond_types = extra_angle_types = @@ -730,7 +730,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (atomflag == 1) error->all(FLERR,"Must read Atom Type Labels before Atoms"); - typelabels(lmap->typelabel,ntypes); + typelabels(lmap->typelabel,ntypes,lmap->ATOM); } else skip_lines(ntypes); } else if (strcmp(keyword,"Bond Type Labels") == 0) { @@ -738,7 +738,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (bondflag == 1) error->all(FLERR,"Must read Bond Type Labels before Bonds"); - typelabels(lmap->btypelabel,nbondtypes); + typelabels(lmap->btypelabel,nbondtypes,lmap->BOND); } else skip_lines(nbondtypes); } @@ -747,7 +747,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (angleflag == 1) error->all(FLERR,"Must read Angle Type Labels before Angles"); - typelabels(lmap->atypelabel,nangletypes); + typelabels(lmap->atypelabel,nangletypes,lmap->ANGLE); } else skip_lines(nangletypes); } @@ -756,7 +756,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (dihedralflag == 1) error->all(FLERR,"Must read Dihedral Type Labels before Dihedrals"); - typelabels(lmap->dtypelabel,ndihedraltypes); + typelabels(lmap->dtypelabel,ndihedraltypes,lmap->DIHEDRAL); } else skip_lines(ndihedraltypes); } @@ -765,7 +765,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (improperflag == 1) error->all(FLERR,"Must read Improper Type Labels before Impropers"); - typelabels(lmap->itypelabel,nimpropertypes); + typelabels(lmap->itypelabel,nimpropertypes,lmap->IMPROPER); } else skip_lines(nimpropertypes); } @@ -1280,7 +1280,8 @@ void ReadData::atoms() nchunk = MIN(natoms-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); - atom->data_atoms(nchunk,buffer,id_offset,mol_offset,toffset,shiftflag,shift); + atom->data_atoms(nchunk,buffer,id_offset,mol_offset,toffset, + shiftflag,shift,labelflag,lmap->lmap2lmap.atom); nread += nchunk; } @@ -1798,7 +1799,7 @@ void ReadData::mass() for (int i = 0; i < ntypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - atom->set_mass(FLERR,buf,toffset); + atom->set_mass(FLERR,buf,toffset,labelflag,lmap->lmap2lmap.atom); buf = next + 1; } delete [] original; @@ -1818,7 +1819,7 @@ void ReadData::paircoeffs() for (int i = 0; i < ntypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - parse_coeffs(buf,nullptr,1,2,toffset); + parse_coeffs(buf,nullptr,1,2,toffset,lmap->lmap2lmap.atom); if (narg == 0) error->all(FLERR,"Unexpected empty line in PairCoeffs section"); force->pair->coeff(narg,arg); @@ -1845,7 +1846,7 @@ void ReadData::pairIJcoeffs() for (j = i; j < ntypes; j++) { next = strchr(buf,'\n'); *next = '\0'; - parse_coeffs(buf,nullptr,0,2,toffset); + parse_coeffs(buf,nullptr,0,2,toffset,lmap->lmap2lmap.atom); if (narg == 0) error->all(FLERR,"Unexpected empty line in PairCoeffs section"); force->pair->coeff(narg,arg); @@ -1870,7 +1871,7 @@ void ReadData::bondcoeffs() for (int i = 0; i < nbondtypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - parse_coeffs(buf,nullptr,0,1,boffset); + parse_coeffs(buf,nullptr,0,1,boffset,lmap->lmap2lmap.bond); if (narg == 0) error->all(FLERR,"Unexpected empty line in BondCoeffs section"); force->bond->coeff(narg,arg); @@ -1895,9 +1896,9 @@ void ReadData::anglecoeffs(int which) for (int i = 0; i < nangletypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - if (which == 0) parse_coeffs(buf,nullptr,0,1,aoffset); - else if (which == 1) parse_coeffs(buf,"bb",0,1,aoffset); - else if (which == 2) parse_coeffs(buf,"ba",0,1,aoffset); + if (which == 0) parse_coeffs(buf,nullptr,0,1,aoffset,lmap->lmap2lmap.angle); + else if (which == 1) parse_coeffs(buf,"bb",0,1,aoffset,lmap->lmap2lmap.angle); + else if (which == 2) parse_coeffs(buf,"ba",0,1,aoffset,lmap->lmap2lmap.angle); if (narg == 0) error->all(FLERR,"Unexpected empty line in AngleCoeffs section"); force->angle->coeff(narg,arg); buf = next + 1; @@ -1921,12 +1922,12 @@ void ReadData::dihedralcoeffs(int which) for (int i = 0; i < ndihedraltypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - if (which == 0) parse_coeffs(buf,nullptr,0,1,doffset); - else if (which == 1) parse_coeffs(buf,"mbt",0,1,doffset); - else if (which == 2) parse_coeffs(buf,"ebt",0,1,doffset); - else if (which == 3) parse_coeffs(buf,"at",0,1,doffset); - else if (which == 4) parse_coeffs(buf,"aat",0,1,doffset); - else if (which == 5) parse_coeffs(buf,"bb13",0,1,doffset); + if (which == 0) parse_coeffs(buf,nullptr,0,1,doffset,lmap->lmap2lmap.dihedral); + else if (which == 1) parse_coeffs(buf,"mbt",0,1,doffset,lmap->lmap2lmap.dihedral); + else if (which == 2) parse_coeffs(buf,"ebt",0,1,doffset,lmap->lmap2lmap.dihedral); + else if (which == 3) parse_coeffs(buf,"at",0,1,doffset,lmap->lmap2lmap.dihedral); + else if (which == 4) parse_coeffs(buf,"aat",0,1,doffset,lmap->lmap2lmap.dihedral); + else if (which == 5) parse_coeffs(buf,"bb13",0,1,doffset,lmap->lmap2lmap.dihedral); if (narg == 0) error->all(FLERR,"Unexpected empty line in DihedralCoeffs section"); force->dihedral->coeff(narg,arg); @@ -1951,8 +1952,8 @@ void ReadData::impropercoeffs(int which) for (int i = 0; i < nimpropertypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - if (which == 0) parse_coeffs(buf,nullptr,0,1,ioffset); - else if (which == 1) parse_coeffs(buf,"aa",0,1,ioffset); + if (which == 0) parse_coeffs(buf,nullptr,0,1,ioffset,lmap->lmap2lmap.improper); + else if (which == 1) parse_coeffs(buf,"aa",0,1,ioffset,lmap->lmap2lmap.improper); if (narg == 0) error->all(FLERR,"Unexpected empty line in ImproperCoeffs section"); force->improper->coeff(narg,arg); buf = next + 1; @@ -1962,12 +1963,14 @@ void ReadData::impropercoeffs(int which) /* ---------------------------------------------------------------------- */ -void ReadData::typelabels(std::vector &mytypelabel, int myntypes) +void ReadData::typelabels(std::vector &mytypelabel, int myntypes, int mode) { int n; char *next; char *buf = new char[myntypes*MAXLINE]; + labelflag = 1; + int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); @@ -1981,14 +1984,12 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes) } delete [] typelabel; - // if first data file, assign this read_data label map to atom class - // else, determine mapping to let labels override numeric types + // merge this read_data label map to atom class + // determine mapping to let labels override numeric types + // valid operations for first or subsequent data files - if (addflag == NONE) { - atom->lmap->merge_lmap(lmap); - } else { - lmap->create_lmap2lmap(atom->lmap); - } + atom->lmap->merge_lmap(lmap,mode); + lmap->create_lmap2lmap(atom->lmap,mode); } /* ---------------------------------------------------------------------- @@ -2151,10 +2152,11 @@ void ReadData::skip_lines(bigint n) else add addstr before 2nd word if dupflag, duplicate 1st word, so pair_coeff "2" becomes "2 2" if noffset, add offset to first noffset args, which are atom/bond/etc types + if labelflag, use ilabel to find the correct remapping of numeric type ------------------------------------------------------------------------- */ -void ReadData::parse_coeffs(char *line, const char *addstr, - int dupflag, int noffset, int offset) +void ReadData::parse_coeffs(char *line, const char *addstr, int dupflag, + int noffset, int offset, int *ilabel) { char *ptr; if ((ptr = strchr(line,'#'))) *ptr = '\0'; @@ -2180,10 +2182,12 @@ void ReadData::parse_coeffs(char *line, const char *addstr, if (noffset) { int value = utils::inumeric(FLERR,arg[0],false,lmp); + if (labelflag) value = ilabel[value-1]; sprintf(argoffset1,"%d",value+offset); arg[0] = argoffset1; if (noffset == 2) { value = utils::inumeric(FLERR,arg[1],false,lmp); + if (labelflag) value = ilabel[value-1]; sprintf(argoffset2,"%d",value+offset); arg[1] = argoffset2; } diff --git a/src/read_data.h b/src/read_data.h index 499b08ed9c..d4dde195e2 100755 --- a/src/read_data.h +++ b/src/read_data.h @@ -67,7 +67,7 @@ class ReadData : protected Pointers { // optional args - int addflag,offsetflag,shiftflag,coeffflag; + int addflag,offsetflag,shiftflag,coeffflag,labelflag; tagint addvalue; int toffset,boffset,aoffset,doffset,ioffset; double shift[3]; @@ -88,7 +88,7 @@ class ReadData : protected Pointers { void header(int); void parse_keyword(int); void skip_lines(bigint); - void parse_coeffs(char *, const char *, int, int, int); + void parse_coeffs(char *, const char *, int, int, int, int *); int style_match(const char *, const char *); void atoms(); @@ -110,7 +110,7 @@ class ReadData : protected Pointers { void anglecoeffs(int); void dihedralcoeffs(int); void impropercoeffs(int); - void typelabels(std::vector &, int); + void typelabels(std::vector &, int, int); void fix(int, char *); }; diff --git a/src/write_data.cpp b/src/write_data.cpp index 4ca0752e72..eae3b469ec 100644 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -182,17 +182,15 @@ void WriteData::write(const std::string &file) } // proc 0 writes header, ntype-length arrays, force fields + // label map must come before coeffs if (me == 0) { header(); + atom->lmap->write_data(fp); // NOTE: always write for now, for testing type_arrays(); if (coeffflag) force_fields(); } - // label map before Atoms, Bonds, etc. - - if (me == 0) atom->lmap->write_data(fp); // NOTE: always write for now, for testing - // per atom info in Atoms and Velocities sections if (natoms) atoms(); From d7fb74f0be991d49f1cc0b0500763be77063ef76 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Mon, 11 Jan 2021 16:00:37 -0500 Subject: [PATCH 029/392] multi-data-file support for bond, angles, diheddral, impropers --- src/atom.cpp | 13 +++++++++---- src/atom.h | 9 +++++---- src/read_data.cpp | 18 +++++++++++++----- src/read_data.h | 7 ++++++- src/write_data.cpp | 2 +- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index fecb8708be..54e5c34b36 100755 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -611,6 +611,7 @@ void Atom::set_atomflag_defaults() // 3rd customization section: customize by adding new flag // identical list as 2nd customization in atom.h + labelmapflag = 0; sphere_flag = ellipsoid_flag = line_flag = tri_flag = body_flag = 0; peri_flag = electron_flag = 0; wavepacket_flag = sph_flag = 0; @@ -1247,7 +1248,7 @@ void Atom::data_vels(int n, char *buf, tagint id_offset) ------------------------------------------------------------------------- */ void Atom::data_bonds(int n, char *buf, int *count, tagint id_offset, - int type_offset) + int type_offset, int labelflag, int *ilabel) { int m,tmp,itype,rv; tagint atom1,atom2; @@ -1265,6 +1266,7 @@ void Atom::data_bonds(int n, char *buf, int *count, tagint id_offset, atom1 += id_offset; atom2 += id_offset; } + if (labelflag) itype = ilabel[itype-1]; itype += type_offset; if ((atom1 <= 0) || (atom1 > map_tag_max) || @@ -1302,7 +1304,7 @@ void Atom::data_bonds(int n, char *buf, int *count, tagint id_offset, ------------------------------------------------------------------------- */ void Atom::data_angles(int n, char *buf, int *count, tagint id_offset, - int type_offset) + int type_offset, int labelflag, int *ilabel) { int m,tmp,itype,rv; tagint atom1,atom2,atom3; @@ -1321,6 +1323,7 @@ void Atom::data_angles(int n, char *buf, int *count, tagint id_offset, atom2 += id_offset; atom3 += id_offset; } + if (labelflag) itype = ilabel[itype-1]; itype += type_offset; if ((atom1 <= 0) || (atom1 > map_tag_max) || @@ -1374,7 +1377,7 @@ void Atom::data_angles(int n, char *buf, int *count, tagint id_offset, ------------------------------------------------------------------------- */ void Atom::data_dihedrals(int n, char *buf, int *count, tagint id_offset, - int type_offset) + int type_offset, int labelflag, int *ilabel) { int m,tmp,itype,rv; tagint atom1,atom2,atom3,atom4; @@ -1395,6 +1398,7 @@ void Atom::data_dihedrals(int n, char *buf, int *count, tagint id_offset, atom3 += id_offset; atom4 += id_offset; } + if (labelflag) itype = ilabel[itype-1]; itype += type_offset; if ((atom1 <= 0) || (atom1 > map_tag_max) || @@ -1465,7 +1469,7 @@ void Atom::data_dihedrals(int n, char *buf, int *count, tagint id_offset, ------------------------------------------------------------------------- */ void Atom::data_impropers(int n, char *buf, int *count, tagint id_offset, - int type_offset) + int type_offset, int labelflag, int *ilabel) { int m,tmp,itype,rv; tagint atom1,atom2,atom3,atom4; @@ -1486,6 +1490,7 @@ void Atom::data_impropers(int n, char *buf, int *count, tagint id_offset, atom3 += id_offset; atom4 += id_offset; } + if (labelflag) itype = ilabel[itype-1]; itype += type_offset; if ((atom1 <= 0) || (atom1 > map_tag_max) || diff --git a/src/atom.h b/src/atom.h index d32e300750..9947f5aea4 100755 --- a/src/atom.h +++ b/src/atom.h @@ -166,6 +166,7 @@ class Atom : protected Pointers { // most are existence flags for per-atom vectors and arrays // 1 if variable is used, 0 if not + int labelmapflag; // type labels int sphere_flag,ellipsoid_flag,line_flag,tri_flag,body_flag; int peri_flag,electron_flag; int wavepacket_flag,sph_flag; @@ -304,10 +305,10 @@ class Atom : protected Pointers { void data_atoms(int, char *, tagint, tagint, int, int, double *, int, int *); void data_vels(int, char *, tagint); - void data_bonds(int, char *, int *, tagint, int); - void data_angles(int, char *, int *, tagint, int); - void data_dihedrals(int, char *, int *, tagint, int); - void data_impropers(int, char *, int *, tagint, int); + void data_bonds(int, char *, int *, tagint, int, int, int *); + void data_angles(int, char *, int *, tagint, int, int, int *); + void data_dihedrals(int, char *, int *, tagint, int, int, int *); + void data_impropers(int, char *, int *, tagint, int, int, int *); void data_bonus(int, char *, AtomVec *, tagint); void data_bodies(int, char *, AtomVec *, tagint); void data_fix_compute_variable(int, int); diff --git a/src/read_data.cpp b/src/read_data.cpp index a7e3f75c3c..eb778c5ec2 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -124,7 +124,7 @@ void ReadData::command(int narg, char **arg) addflag = NONE; coeffflag = 1; id_offset = mol_offset = 0; - offsetflag = shiftflag = labelflag = 0; + offsetflag = shiftflag = settypeflag = labelflag = 0; toffset = boffset = aoffset = doffset = ioffset = 0; shift[0] = shift[1] = shift[2] = 0.0; extra_atom_types = extra_bond_types = extra_angle_types = @@ -1379,7 +1379,8 @@ void ReadData::bonds(int firstpass) nchunk = MIN(nbonds-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); - atom->data_bonds(nchunk,buffer,count,id_offset,boffset); + atom->data_bonds(nchunk,buffer,count,id_offset,boffset, + labelflag,lmap->lmap2lmap.bond); nread += nchunk; } @@ -1453,7 +1454,8 @@ void ReadData::angles(int firstpass) nchunk = MIN(nangles-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); - atom->data_angles(nchunk,buffer,count,id_offset,aoffset); + atom->data_angles(nchunk,buffer,count,id_offset,aoffset, + labelflag,lmap->lmap2lmap.angle); nread += nchunk; } @@ -1527,7 +1529,8 @@ void ReadData::dihedrals(int firstpass) nchunk = MIN(ndihedrals-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); - atom->data_dihedrals(nchunk,buffer,count,id_offset,doffset); + atom->data_dihedrals(nchunk,buffer,count,id_offset,doffset, + labelflag,lmap->lmap2lmap.dihedral); nread += nchunk; } @@ -1601,7 +1604,8 @@ void ReadData::impropers(int firstpass) nchunk = MIN(nimpropers-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); - atom->data_impropers(nchunk,buffer,count,id_offset,ioffset); + atom->data_impropers(nchunk,buffer,count,id_offset,ioffset, + labelflag,lmap->lmap2lmap.improper); nread += nchunk; } @@ -1789,6 +1793,7 @@ void ReadData::bodies(int firstpass, AtomVec *ptr) void ReadData::mass() { + settypeflag = 1; char *next; char *buf = new char[ntypes*MAXLINE]; @@ -1965,11 +1970,13 @@ void ReadData::impropercoeffs(int which) void ReadData::typelabels(std::vector &mytypelabel, int myntypes, int mode) { + if (settypeflag) error->all(FLERR,"Must read Type Labels before any section involving types"); int n; char *next; char *buf = new char[myntypes*MAXLINE]; labelflag = 1; + atom->labelmapflag = 1; int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); @@ -2158,6 +2165,7 @@ void ReadData::skip_lines(bigint n) void ReadData::parse_coeffs(char *line, const char *addstr, int dupflag, int noffset, int offset, int *ilabel) { + settypeflag = 1; char *ptr; if ((ptr = strchr(line,'#'))) *ptr = '\0'; diff --git a/src/read_data.h b/src/read_data.h index d4dde195e2..a2b72d136e 100755 --- a/src/read_data.h +++ b/src/read_data.h @@ -67,7 +67,7 @@ class ReadData : protected Pointers { // optional args - int addflag,offsetflag,shiftflag,coeffflag,labelflag; + int addflag,offsetflag,shiftflag,coeffflag,settypeflag,labelflag; tagint addvalue; int toffset,boffset,aoffset,doffset,ioffset; double shift[3]; @@ -264,6 +264,11 @@ E: Must read Atoms before Bodies The Atoms section of a data file must come before a Bodies section. +E: Must read Type Labels before any section involving types + +All Type Labels sections of a data file must come before any +section that uses per-type values (Masses, Coeffs, etc.). + E: Must define pair_style before Pair Coeffs Must use a pair_style command before reading a data file that defines diff --git a/src/write_data.cpp b/src/write_data.cpp index eae3b469ec..8088203d5e 100644 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -186,7 +186,7 @@ void WriteData::write(const std::string &file) if (me == 0) { header(); - atom->lmap->write_data(fp); // NOTE: always write for now, for testing + if (atom->labelmapflag) atom->lmap->write_data(fp); type_arrays(); if (coeffflag) force_fields(); } From 93c33ac4f4b36fabdbe3e83793052d22f16a6bb1 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Tue, 12 Jan 2021 17:52:55 -0500 Subject: [PATCH 030/392] type label support for molecule files replace types directly for molecule files --- src/label_map.cpp | 29 +++++++++-------------------- src/molecule.cpp | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/label_map.cpp b/src/label_map.cpp index 10476417e8..cf7223bf0b 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -36,27 +36,16 @@ LabelMap::~LabelMap() // delete type labels typelabel.clear(); + btypelabel.clear(); + atypelabel.clear(); + dtypelabel.clear(); + itypelabel.clear(); + delete [] lmap2lmap.atom; - - if (force->bond) { - btypelabel.clear(); - delete [] lmap2lmap.bond; - } - - if (force->angle) { - atypelabel.clear(); - delete [] lmap2lmap.angle; - } - - if (force->dihedral) { - dtypelabel.clear(); - delete [] lmap2lmap.dihedral; - } - - if (force->improper) { - itypelabel.clear(); - delete [] lmap2lmap.improper; - } + delete [] lmap2lmap.bond; + delete [] lmap2lmap.angle; + delete [] lmap2lmap.dihedral; + delete [] lmap2lmap.improper; } /* ---------------------------------------------------------------------- diff --git a/src/molecule.cpp b/src/molecule.cpp index d85cf47c71..ce7e97fd9a 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -20,6 +20,7 @@ #include "domain.h" #include "error.h" #include "force.h" +#include "label_map.h" #include "math_extra.h" #include "math_eigen.h" #include "memory.h" @@ -713,6 +714,7 @@ void Molecule::coords(char *line) void Molecule::types(char *line) { + std::string typestr; for (int i = 0; i < natoms; i++) count[i] = 0; try { for (int i = 0; i < natoms; i++) { @@ -724,7 +726,11 @@ void Molecule::types(char *line) int iatom = values.next_int() - 1; if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Types section in molecule file"); count[iatom]++; - type[iatom] = values.next_int(); + typestr = values.next_string(); + if (atom->labelmapflag) { + type[iatom] = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes); + if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file"); + } else type[iatom] = utils::inumeric(FLERR,typestr.c_str(),false,lmp); type[iatom] += toffset; } } catch (TokenizerException &e) { @@ -917,6 +923,7 @@ void Molecule::bonds(int flag, char *line) { int itype; tagint m,atom1,atom2; + std::string typestr; int newton_bond = force->newton_bond; if (flag == 0) @@ -931,7 +938,11 @@ void Molecule::bonds(int flag, char *line) ValueTokenizer values(line); if (values.count() != 4) error->one(FLERR,"Invalid Bonds section in molecule file"); values.next_int(); - itype = values.next_int(); + typestr = values.next_string(); + if (atom->labelmapflag) { + itype = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes); + if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file"); + } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); atom2 = values.next_tagint(); } catch (TokenizerException &e) { @@ -985,6 +996,7 @@ void Molecule::angles(int flag, char *line) { int itype; tagint m,atom1,atom2,atom3; + std::string typestr; int newton_bond = force->newton_bond; if (flag == 0) @@ -999,7 +1011,11 @@ void Molecule::angles(int flag, char *line) ValueTokenizer values(line); if (values.count() != 5) error->one(FLERR,"Invalid Angles section in molecule file"); values.next_int(); - itype = values.next_int(); + typestr = values.next_string(); + if (atom->labelmapflag) { + itype = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes); + if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file"); + } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); atom2 = values.next_tagint(); atom3 = values.next_tagint(); @@ -1069,6 +1085,7 @@ void Molecule::dihedrals(int flag, char *line) { int itype; tagint m,atom1,atom2,atom3,atom4; + std::string typestr; int newton_bond = force->newton_bond; if (flag == 0) @@ -1083,7 +1100,11 @@ void Molecule::dihedrals(int flag, char *line) ValueTokenizer values(line); if (values.count() != 6) error->one(FLERR,"Invalid Dihedrals section in molecule file"); values.next_int(); - itype = values.next_int(); + typestr = values.next_string(); + if (atom->labelmapflag) { + itype = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes); + if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file"); + } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); atom2 = values.next_tagint(); atom3 = values.next_tagint(); @@ -1168,6 +1189,7 @@ void Molecule::impropers(int flag, char *line) { int itype; tagint m,atom1,atom2,atom3,atom4; + std::string typestr; int newton_bond = force->newton_bond; if (flag == 0) @@ -1182,7 +1204,11 @@ void Molecule::impropers(int flag, char *line) ValueTokenizer values(line); if (values.count() != 6) error->one(FLERR,"Invalid Impropers section in molecule file"); values.next_int(); - itype = values.next_int(); + typestr = values.next_string(); + if (atom->labelmapflag) { + itype = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes); + if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file"); + } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); atom2 = values.next_tagint(); atom3 = values.next_tagint(); From e138cf2476dce4e294282b65bf4b222934d7b428 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Fri, 15 Jan 2021 21:46:40 -0500 Subject: [PATCH 031/392] add labelmap command --- src/input.cpp | 10 ++++++++++ src/input.h | 1 + src/label_map.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/label_map.h | 1 + src/read_data.cpp | 1 - 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/input.cpp b/src/input.cpp index abdc3775ce..ba38112ac8 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -29,6 +29,7 @@ #include "group.h" #include "improper.h" #include "kspace.h" +#include "label_map.h" #include "memory.h" #include "min.h" #include "modify.h" @@ -738,6 +739,7 @@ int Input::execute_command() else if (!strcmp(command,"improper_style")) improper_style(); else if (!strcmp(command,"kspace_modify")) kspace_modify(); else if (!strcmp(command,"kspace_style")) kspace_style(); + else if (!strcmp(command,"labelmap")) labelmap(); else if (!strcmp(command,"lattice")) lattice(); else if (!strcmp(command,"mass")) mass(); else if (!strcmp(command,"min_modify")) min_modify(); @@ -1552,6 +1554,14 @@ void Input::kspace_style() force->create_kspace(arg[0],1); if (force->kspace) force->kspace->settings(narg-1,&arg[1]); } +/* ---------------------------------------------------------------------- */ + +void Input::labelmap() +{ + if (domain->box_exist == 0) + error->all(FLERR,"Labelmap command before simulation box is defined"); + atom->lmap->modify_lmap(narg,arg); +} /* ---------------------------------------------------------------------- */ diff --git a/src/input.h b/src/input.h index b8ffb276f9..e275981d32 100644 --- a/src/input.h +++ b/src/input.h @@ -113,6 +113,7 @@ class Input : protected Pointers { void improper_style(); void kspace_modify(); void kspace_style(); + void labelmap(); void lattice(); void mass(); void min_modify(); diff --git a/src/label_map.cpp b/src/label_map.cpp index cf7223bf0b..9c5db1af01 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -80,6 +80,42 @@ void LabelMap::allocate_type_labels() } } +/* ---------------------------------------------------------------------- + labelmap command in input script +------------------------------------------------------------------------- */ + +void LabelMap::modify_lmap(int narg, char **arg) +{ + if (narg < 3 || narg % 2 == 0) error->all(FLERR,"Illegal labelmap command"); + + int ntypes; + std::vector *labels; + if (!strcmp(arg[0],"atom")) { + ntypes = natomtypes; + labels = &typelabel; + } else if (!strcmp(arg[0],"bond")) { + ntypes = nbondtypes; + labels = &btypelabel; + } else if (!strcmp(arg[0],"angle")) { + ntypes = nangletypes; + labels = &atypelabel; + } else if (!strcmp(arg[0],"dihedral")) { + ntypes = ndihedraltypes; + labels = &dtypelabel; + } else if (!strcmp(arg[0],"improper")) { + ntypes = nimpropertypes; + labels = &itypelabel; + } else error->all(FLERR,"Illegal labelmap command"); + + int itype; + int iarg = 1; + while (iarg < narg) { + itype = utils::inumeric(FLERR,arg[iarg++],false,lmp); + if (itype > ntypes) error->all(FLERR,"Topology type exceeds system topology type"); + (*labels)[itype-1] = arg[iarg++]; + } +} + /* ---------------------------------------------------------------------- copy another map (lmap2) into this one if label already exists, leave in place diff --git a/src/label_map.h b/src/label_map.h index 4372ebaa86..a01f238fc3 100755 --- a/src/label_map.h +++ b/src/label_map.h @@ -42,6 +42,7 @@ class LabelMap : protected Pointers { ~LabelMap(); void allocate_type_labels(); + void modify_lmap(int, char **); void merge_lmap(class LabelMap *, int); // copy another lmap into this one void create_lmap2lmap(class LabelMap *, int); // index mapping between two lmaps int find_or_create(std::string, std::vector &, int); // look up type or create new type diff --git a/src/read_data.cpp b/src/read_data.cpp index eb778c5ec2..a8581668aa 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -1971,7 +1971,6 @@ void ReadData::impropercoeffs(int which) void ReadData::typelabels(std::vector &mytypelabel, int myntypes, int mode) { if (settypeflag) error->all(FLERR,"Must read Type Labels before any section involving types"); - int n; char *next; char *buf = new char[myntypes*MAXLINE]; From 739dc46fab0b79c416c3202287abd6781a8b8938 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Tue, 19 Jan 2021 21:52:22 -0500 Subject: [PATCH 032/392] type labels: restart support --- src/atom.cpp | 1 + src/input.cpp | 0 src/input.h | 0 src/label_map.cpp | 129 ++++++++++++++++++++++++++++++++++++------ src/label_map.h | 20 +++++-- src/lmprestart.h | 2 +- src/molecule.cpp | 0 src/molecule.h | 0 src/read_data.cpp | 3 +- src/read_restart.cpp | 6 ++ src/write_data.cpp | 0 src/write_data.h | 0 src/write_restart.cpp | 5 ++ src/write_restart.h | 0 14 files changed, 140 insertions(+), 26 deletions(-) mode change 100644 => 100755 src/input.cpp mode change 100644 => 100755 src/input.h mode change 100644 => 100755 src/molecule.cpp mode change 100644 => 100755 src/molecule.h mode change 100644 => 100755 src/write_data.cpp mode change 100644 => 100755 src/write_data.h mode change 100644 => 100755 src/write_restart.cpp mode change 100644 => 100755 src/write_restart.h diff --git a/src/atom.cpp b/src/atom.cpp index 54e5c34b36..8a5bacc645 100755 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -1991,6 +1991,7 @@ void Atom::add_molecule_atom(Molecule *onemol, int iatom, void Atom::add_label_map() { + labelmapflag = 1; lmap = new LabelMap(lmp); lmap->natomtypes = ntypes; lmap->nbondtypes = nbondtypes; diff --git a/src/input.cpp b/src/input.cpp old mode 100644 new mode 100755 diff --git a/src/input.h b/src/input.h old mode 100644 new mode 100755 diff --git a/src/label_map.cpp b/src/label_map.cpp index 9c5db1af01..5031a8fc9c 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -25,6 +25,7 @@ using namespace LAMMPS_NS; LabelMap::LabelMap(LAMMPS *lmp) : Pointers(lmp) { + MPI_Comm_rank(world,&me); natomtypes = nbondtypes = nangletypes = 0; ndihedraltypes = nimpropertypes = 0; } @@ -50,8 +51,6 @@ LabelMap::~LabelMap() /* ---------------------------------------------------------------------- allocate character-based type arrays (labels) of length ntypes - always allocated (for both numeric and character-based type modes) - initialize label with (a string of) its numeric counterpart ------------------------------------------------------------------------- */ void LabelMap::allocate_type_labels() @@ -59,25 +58,17 @@ void LabelMap::allocate_type_labels() typelabel.resize(natomtypes); lmap2lmap.atom = new int[natomtypes]; - if (force->bond) { - btypelabel.resize(nbondtypes); - lmap2lmap.bond = new int[nbondtypes]; - } + btypelabel.resize(nbondtypes); + lmap2lmap.bond = new int[nbondtypes]; - if (force->angle) { - atypelabel.resize(nangletypes); - lmap2lmap.angle = new int[nangletypes]; - } + atypelabel.resize(nangletypes); + lmap2lmap.angle = new int[nangletypes]; - if (force->dihedral) { - dtypelabel.resize(ndihedraltypes); - lmap2lmap.dihedral = new int[ndihedraltypes]; - } + dtypelabel.resize(ndihedraltypes); + lmap2lmap.dihedral = new int[ndihedraltypes]; - if (force->improper) { - itypelabel.resize(nimpropertypes); - lmap2lmap.improper = new int[nimpropertypes]; - } + itypelabel.resize(nimpropertypes); + lmap2lmap.improper = new int[nimpropertypes]; } /* ---------------------------------------------------------------------- @@ -251,3 +242,105 @@ void LabelMap::write_data(FILE *fp) fmt::print(fp,"{} {}\n",i+1,itypelabel[i]); } } + +/* ---------------------------------------------------------------------- + proc 0 reads from restart file, bcasts +------------------------------------------------------------------------- */ + +void LabelMap::read_restart(FILE *fp) +{ + char *charlabel; + + for (int i = 0; i < natomtypes; i++) { + charlabel = read_string(fp); + typelabel[i] = charlabel; + delete [] charlabel; + } + + for (int i = 0; i < nbondtypes; i++) { + charlabel = read_string(fp); + btypelabel[i] = charlabel; + delete [] charlabel; + } + + for (int i = 0; i < nangletypes; i++) { + charlabel = read_string(fp); + atypelabel[i] = charlabel; + delete [] charlabel; + } + + for (int i = 0; i < ndihedraltypes; i++) { + charlabel = read_string(fp); + dtypelabel[i] = charlabel; + delete [] charlabel; + } + + for (int i = 0; i < nimpropertypes; i++) { + charlabel = read_string(fp); + itypelabel[i] = charlabel; + delete [] charlabel; + } +} + +/* ---------------------------------------------------------------------- + proc 0 writes to restart file +------------------------------------------------------------------------- */ + +void LabelMap::write_restart(FILE *fp) +{ + for (int i = 0; i < natomtypes; i++) + write_string(typelabel[i],fp); + + for (int i = 0; i < nbondtypes; i++) + write_string(btypelabel[i],fp); + + for (int i = 0; i < nangletypes; i++) + write_string(atypelabel[i],fp); + + for (int i = 0; i < ndihedraltypes; i++) + write_string(dtypelabel[i],fp); + + for (int i = 0; i < nimpropertypes; i++) + write_string(itypelabel[i],fp); +} + +/* ---------------------------------------------------------------------- + read a char string (including nullptr) and bcast it + str is allocated here, ptr is returned, caller must deallocate +------------------------------------------------------------------------- */ + +char *LabelMap::read_string(FILE *fp) +{ + int n = read_int(fp); + if (n < 0) error->all(FLERR,"Illegal size string or corrupt restart"); + char *value = new char[n]; + if (me == 0) utils::sfread(FLERR,value,sizeof(char),n,fp,nullptr,error); + MPI_Bcast(value,n,MPI_CHAR,0,world); + return value; +} + +/* ---------------------------------------------------------------------- + write a flag and a C-style char string (including the terminating null + byte) into the restart file +------------------------------------------------------------------------- */ + +void LabelMap::write_string(std::string str, FILE *fp) +{ + const char *cstr = str.c_str(); + int n = strlen(cstr) + 1; + fwrite(&n,sizeof(int),1,fp); + fwrite(cstr,sizeof(char),n,fp); +} + +/* ---------------------------------------------------------------------- + read an int from restart file and bcast it +------------------------------------------------------------------------- */ + +int LabelMap::read_int(FILE *fp) +{ + int value; + if ((me == 0) && (fread(&value,sizeof(int),1,fp) < 1)) + value = -1; + MPI_Bcast(&value,1,MPI_INT,0,world); + return value; +} diff --git a/src/label_map.h b/src/label_map.h index a01f238fc3..978923252e 100755 --- a/src/label_map.h +++ b/src/label_map.h @@ -43,13 +43,23 @@ class LabelMap : protected Pointers { void allocate_type_labels(); void modify_lmap(int, char **); - void merge_lmap(class LabelMap *, int); // copy another lmap into this one - void create_lmap2lmap(class LabelMap *, int); // index mapping between two lmaps + void merge_lmap(class LabelMap *, int); // copy another lmap into this one + void create_lmap2lmap(class LabelMap *, int); // index mapping between two lmaps int find_or_create(std::string, std::vector &, int); // look up type or create new type - int find(std::string, std::vector, int); // look up type index - void write_data(FILE *); + int find(std::string, std::vector, int); // look up type index - protected: + // input/output for atom class label map + + void write_data(FILE *); + void read_restart(FILE *fp); + void write_restart(FILE *); + + private: + int me; + + char *read_string(FILE *); + void write_string(std::string, FILE *); + int read_int(FILE *); }; } diff --git a/src/lmprestart.h b/src/lmprestart.h index ecdd272d81..4b542d946c 100644 --- a/src/lmprestart.h +++ b/src/lmprestart.h @@ -37,7 +37,7 @@ enum{VERSION,SMALLINT,TAGINT,BIGINT, COMM_MODE,COMM_CUTOFF,COMM_VEL,NO_PAIR, EXTRA_BOND_PER_ATOM,EXTRA_ANGLE_PER_ATOM,EXTRA_DIHEDRAL_PER_ATOM, EXTRA_IMPROPER_PER_ATOM,EXTRA_SPECIAL_PER_ATOM,ATOM_MAXSPECIAL, - NELLIPSOIDS,NLINES,NTRIS,NBODIES}; + NELLIPSOIDS,NLINES,NTRIS,NBODIES,LABELMAP}; #define LB_FACTOR 1.1 diff --git a/src/molecule.cpp b/src/molecule.cpp old mode 100644 new mode 100755 diff --git a/src/molecule.h b/src/molecule.h old mode 100644 new mode 100755 diff --git a/src/read_data.cpp b/src/read_data.cpp index a8581668aa..9734539492 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -441,7 +441,6 @@ void ReadData::command(int narg, char **arg) else n = static_cast (LB_FACTOR * atom->natoms / comm->nprocs); atom->allocate_type_arrays(); - atom->add_label_map(); atom->deallocate_topology(); // allocate atom arrays to N, rounded up by AtomVec->DELTA @@ -1975,7 +1974,7 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i char *buf = new char[myntypes*MAXLINE]; labelflag = 1; - atom->labelmapflag = 1; + if (atom->labelmapflag == 0) atom->add_label_map(); int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); diff --git a/src/read_restart.cpp b/src/read_restart.cpp index 9e8fbce91c..89994abab5 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -26,6 +26,7 @@ #include "group.h" #include "improper.h" #include "irregular.h" +#include "label_map.h" #include "memory.h" #include "modify.h" #include "mpiio.h" @@ -929,6 +930,11 @@ void ReadRestart::type_arrays() atom->set_mass(mass); delete [] mass; + } else if (flag == LABELMAP) { + read_int(); + atom->add_label_map(); + atom->lmap->read_restart(fp); + } else error->all(FLERR, "Invalid flag in type arrays section of restart file"); diff --git a/src/write_data.cpp b/src/write_data.cpp old mode 100644 new mode 100755 diff --git a/src/write_data.h b/src/write_data.h old mode 100644 new mode 100755 diff --git a/src/write_restart.cpp b/src/write_restart.cpp old mode 100644 new mode 100755 index afe1d2d528..f97cdcd966 --- a/src/write_restart.cpp +++ b/src/write_restart.cpp @@ -25,6 +25,7 @@ #include "force.h" #include "group.h" #include "improper.h" +#include "label_map.h" #include "memory.h" #include "modify.h" #include "mpiio.h" @@ -520,6 +521,10 @@ void WriteRestart::header() void WriteRestart::type_arrays() { if (atom->mass) write_double_vec(MASS,atom->ntypes,&atom->mass[1]); + if (atom->labelmapflag) { + write_int(LABELMAP,atom->labelmapflag); + atom->lmap->write_restart(fp); + } // -1 flag signals end of type arrays diff --git a/src/write_restart.h b/src/write_restart.h old mode 100644 new mode 100755 From a0c4fac42842fc1cca41746d252f1ccbc7636782 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Tue, 19 Jan 2021 22:56:06 -0500 Subject: [PATCH 033/392] assume type labels begin with letter --- src/input.cpp | 1 + src/label_map.cpp | 5 ++++- src/molecule.cpp | 35 ++++++++++++++++++++--------------- src/read_data.cpp | 3 ++- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index ba38112ac8..e409111090 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -1560,6 +1560,7 @@ void Input::labelmap() { if (domain->box_exist == 0) error->all(FLERR,"Labelmap command before simulation box is defined"); + if (!atom->labelmapflag) atom->add_label_map(); atom->lmap->modify_lmap(narg,arg); } diff --git a/src/label_map.cpp b/src/label_map.cpp index 5031a8fc9c..8ea9ae94e6 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -100,10 +100,13 @@ void LabelMap::modify_lmap(int narg, char **arg) int itype; int iarg = 1; + char *charlabel; while (iarg < narg) { itype = utils::inumeric(FLERR,arg[iarg++],false,lmp); + charlabel = arg[iarg++]; if (itype > ntypes) error->all(FLERR,"Topology type exceeds system topology type"); - (*labels)[itype-1] = arg[iarg++]; + if (!isalpha(charlabel[0])) error->all(FLERR,"Type labels must begin with a letter"); + (*labels)[itype-1] = charlabel; } } diff --git a/src/molecule.cpp b/src/molecule.cpp index ce7e97fd9a..e0a20ff6af 100755 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -727,9 +727,10 @@ void Molecule::types(char *line) if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Types section in molecule file"); count[iatom]++; typestr = values.next_string(); - if (atom->labelmapflag) { - type[iatom] = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes); - if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file"); + if (isalpha(typestr[0])) { + if (!atom->labelmapflag) error->one(FLERR,"Invalid Types section in molecule file"); + type[iatom] = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes); + if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file"); } else type[iatom] = utils::inumeric(FLERR,typestr.c_str(),false,lmp); type[iatom] += toffset; } @@ -939,9 +940,10 @@ void Molecule::bonds(int flag, char *line) if (values.count() != 4) error->one(FLERR,"Invalid Bonds section in molecule file"); values.next_int(); typestr = values.next_string(); - if (atom->labelmapflag) { - itype = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes); - if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file"); + if (isalpha(typestr[0])) { + if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in molecule file"); + itype = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes); + if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); atom2 = values.next_tagint(); @@ -1012,9 +1014,10 @@ void Molecule::angles(int flag, char *line) if (values.count() != 5) error->one(FLERR,"Invalid Angles section in molecule file"); values.next_int(); typestr = values.next_string(); - if (atom->labelmapflag) { - itype = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes); - if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file"); + if (isalpha(typestr[0])) { + if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in molecule file"); + itype = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes); + if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); atom2 = values.next_tagint(); @@ -1101,9 +1104,10 @@ void Molecule::dihedrals(int flag, char *line) if (values.count() != 6) error->one(FLERR,"Invalid Dihedrals section in molecule file"); values.next_int(); typestr = values.next_string(); - if (atom->labelmapflag) { - itype = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes); - if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file"); + if (isalpha(typestr[0])) { + if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in molecule file"); + itype = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes); + if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); atom2 = values.next_tagint(); @@ -1205,9 +1209,10 @@ void Molecule::impropers(int flag, char *line) if (values.count() != 6) error->one(FLERR,"Invalid Impropers section in molecule file"); values.next_int(); typestr = values.next_string(); - if (atom->labelmapflag) { - itype = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes); - if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file"); + if (isalpha(typestr[0])) { + if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in molecule file"); + itype = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes); + if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); atom2 = values.next_tagint(); diff --git a/src/read_data.cpp b/src/read_data.cpp index 9734539492..f493be0977 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -1974,7 +1974,7 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i char *buf = new char[myntypes*MAXLINE]; labelflag = 1; - if (atom->labelmapflag == 0) atom->add_label_map(); + if (!atom->labelmapflag) atom->add_label_map(); int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); @@ -1984,6 +1984,7 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i next = strchr(buf,'\n'); *next = '\0'; sscanf(buf,"%*d %s",typelabel); + if (!isalpha(typelabel[0])) error->all(FLERR,"Type labels must begin with a letter"); mytypelabel[i] = typelabel; buf = next + 1; } From 532242f5e1aee696154a103b4193803a393294fa Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Tue, 19 Jan 2021 23:55:32 -0500 Subject: [PATCH 034/392] begin docs --- doc/src/labelmap.rst | 76 +++++++++++++++++++++++++++++++++++++++++++ doc/src/molecule.rst | 17 +++++++--- doc/src/read_data.rst | 61 ++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 5 deletions(-) create mode 100755 doc/src/labelmap.rst mode change 100644 => 100755 doc/src/molecule.rst mode change 100644 => 100755 doc/src/read_data.rst diff --git a/doc/src/labelmap.rst b/doc/src/labelmap.rst new file mode 100755 index 0000000000..a73f06652e --- /dev/null +++ b/doc/src/labelmap.rst @@ -0,0 +1,76 @@ +.. index:: labelmap + +labelmap command +================== + +Syntax +"""""" + +.. code-block:: LAMMPS + + labelmap interaction numeric-type type-label ... + +* interaction = *atom* or *bond* or *angle* or *dihedral* or *improper* +* one or more numeric-type/type-label pairs may be appended + +Examples +"""""""" + +.. code-block:: LAMMPS + + labelmap atom 3 carbon + labelmap bond 1 c1,c2 2 c1,hc + +Description +""""""""""" + +Define or replace the alphanumeric type label associated with a +numeric atom, bond, angle, dihedral or improper type. Type labels are +strings that can be assigned to each interaction type. Pairing each +numeric type used by LAMMPS with a character-based type can be +helpful in a variety of situations. For example, type labels can make +various inputs more readable and compatible with other inputs (data +files, molecule templates, etc.), particularly if your model's force +field uses alphanumeric atom types. Type label maps can also be +defined by :doc:`data files ` using the relevant Type Label +sections. + +.. note:: + + If substituting numeric types with type labels is currently + supported by a given command, this feature will be mentioned on + that command's doc page. + +.. note:: + + Type labels must begin with a letter. + +The label map of only one type of interaction (atom, bond, etc.) may +be modified by a given *labelmap* command. Any number of +numeric-type/type-label pairs may follow. If a type label already +exists for a given numeric type, it will be overwritten. Assigning the +same type label to multiple numeric types is permitted; how this +ambiguity is treated may depend on the feature utilizing type labels. +There does not need to be a type label associated with every numeric +type; in this case, those types without a label must be referenced by +their numeric type. + +---------- + +Restrictions +"""""""""""" + +This command must come after the simulation box is defined by a +:doc:`read_data `, :doc:`read_restart `, or +:doc:`create_box ` command. + +Related commands +"""""""""""""""" + +:doc:`read_data `, :doc:`write_data `, +:doc:`molecule `, :doc:`fix bond/react ` + +Default +""""""" + +The option default is no type label map. diff --git a/doc/src/molecule.rst b/doc/src/molecule.rst old mode 100644 new mode 100755 index b86983766d..bc16aeb9a4 --- a/doc/src/molecule.rst +++ b/doc/src/molecule.rst @@ -173,6 +173,13 @@ These are the allowed section keywords for the body of the file. * *Special Bond Counts, Special Bonds* = special neighbor info * *Shake Flags, Shake Atoms, Shake Bond Types* = SHAKE info +For the Types, Bonds, Angles, Dihedrals, and Impropers sections, each +atom, bond, etc. type can be listed either as a number (numeric type) +or as an alphanumeric :doc:`type label `. Type labels must +begin with letter, and a label map must have previously been defined +by a :doc:`labelmap ` or :doc:`read_data ` +command. + If a Bonds section is specified then the Special Bond Counts and Special Bonds sections can also be used, if desired, to explicitly list the 1-2, 1-3, 1-4 neighbors within the molecule topology (see @@ -222,7 +229,7 @@ order. * one line per atom * line syntax: ID type -* type = atom type of atom +* type = atom type of atom (1-Natomtype, or type label) ---------- @@ -289,7 +296,7 @@ included, the default mass for each atom is derived from its volume * one line per bond * line syntax: ID type atom1 atom2 -* type = bond type (1-Nbondtype) +* type = bond type (1-Nbondtype, or type label) * atom1,atom2 = IDs of atoms in bond The IDs for the two atoms in each bond should be values @@ -301,7 +308,7 @@ from 1 to Natoms, where Natoms = # of atoms in the molecule. * one line per angle * line syntax: ID type atom1 atom2 atom3 -* type = angle type (1-Nangletype) +* type = angle type (1-Nangletype, or type label) * atom1,atom2,atom3 = IDs of atoms in angle The IDs for the three atoms in each angle should be values from 1 to @@ -315,7 +322,7 @@ which the angle is computed) is the atom2 in the list. * one line per dihedral * line syntax: ID type atom1 atom2 atom3 atom4 -* type = dihedral type (1-Ndihedraltype) +* type = dihedral type (1-Ndihedraltype, or type label) * atom1,atom2,atom3,atom4 = IDs of atoms in dihedral The IDs for the four atoms in each dihedral should be values from 1 to @@ -328,7 +335,7 @@ ordered linearly within the dihedral. * one line per improper * line syntax: ID type atom1 atom2 atom3 atom4 -* type = improper type (1-Nimpropertype) +* type = improper type (1-Nimpropertype, or type label) * atom1,atom2,atom3,atom4 = IDs of atoms in improper The IDs for the four atoms in each improper should be values from 1 to diff --git a/doc/src/read_data.rst b/doc/src/read_data.rst old mode 100644 new mode 100755 index 5d74d9c28b..3e32a96c53 --- a/doc/src/read_data.rst +++ b/doc/src/read_data.rst @@ -472,6 +472,7 @@ These are the section keywords for the body of the file. * *Atoms, Velocities, Masses, Ellipsoids, Lines, Triangles, Bodies* = atom-property sections * *Bonds, Angles, Dihedrals, Impropers* = molecular topology sections +* *Atom Type Labels, Bond Type Labels, Angle Type Labels, Dihedral Type Labels, Improper Type Labels* = type label map * *Pair Coeffs, PairIJ Coeffs, Bond Coeffs, Angle Coeffs, Dihedral Coeffs, Improper Coeffs* = force field sections * *BondBond Coeffs, BondAngle Coeffs, MiddleBondTorsion Coeffs, EndBondTorsion Coeffs, AngleTorsion Coeffs, AngleAngleTorsion Coeffs, BondBond13 Coeffs, AngleAngle Coeffs* = class 2 force field sections @@ -531,6 +532,18 @@ input script. ---------- +*Angle Type Labels* section: + +* one line per angle type +* line syntax: ID label + + .. parsed-literal:: + + ID = angle type (1-N) + label = alphanumeric type label (see the :doc:`labelmap ` command) + +---------- + *AngleAngle Coeffs* section: * one line per improper type @@ -592,6 +605,18 @@ integers (1, not 1.0). ---------- +*Atom Type Labels* section: + +* one line per atom type +* line syntax: ID label + + .. parsed-literal:: + + ID = atom type (1-N) + label = alphanumeric type label (see the :doc:`labelmap ` command) + +---------- + *Atoms* section: * one line per atom @@ -917,6 +942,18 @@ script. ---------- +*Bond Type Labels* section: + +* one line per bond type +* line syntax: ID label + + .. parsed-literal:: + + ID = bond type (1-N) + label = alphanumeric type label (see the :doc:`labelmap ` command) + +---------- + *BondAngle Coeffs* section: * one line per angle type @@ -999,6 +1036,18 @@ Coefficients can also be set via the ---------- +*Dihedral Type Labels* section: + +* one line per dihedral type +* line syntax: ID label + + .. parsed-literal:: + + ID = dihedral type (1-N) + label = alphanumeric type label (see the :doc:`labelmap ` command) + +---------- + *Dihedrals* section: * one line per dihedral @@ -1100,6 +1149,18 @@ Coefficients can also be set via the ---------- +*Improper Type Labels* section: + +* one line per improper type +* line syntax: ID label + + .. parsed-literal:: + + ID = improper type (1-N) + label = alphanumeric type label (see the :doc:`labelmap ` command) + +---------- + *Impropers* section: * one line per improper From 67c23520155e190e4bf365178511eef4c6ec2012 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Fri, 22 Jan 2021 21:47:48 -0500 Subject: [PATCH 035/392] actually assume type labels don't start with number --- src/molecule.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/molecule.cpp b/src/molecule.cpp index e0a20ff6af..7556239aed 100755 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -727,7 +727,7 @@ void Molecule::types(char *line) if (iatom < 0 || iatom >= natoms) error->one(FLERR,"Invalid Types section in molecule file"); count[iatom]++; typestr = values.next_string(); - if (isalpha(typestr[0])) { + if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Types section in molecule file"); type[iatom] = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes); if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file"); @@ -940,7 +940,7 @@ void Molecule::bonds(int flag, char *line) if (values.count() != 4) error->one(FLERR,"Invalid Bonds section in molecule file"); values.next_int(); typestr = values.next_string(); - if (isalpha(typestr[0])) { + if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in molecule file"); itype = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes); if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file"); @@ -1014,7 +1014,7 @@ void Molecule::angles(int flag, char *line) if (values.count() != 5) error->one(FLERR,"Invalid Angles section in molecule file"); values.next_int(); typestr = values.next_string(); - if (isalpha(typestr[0])) { + if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in molecule file"); itype = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes); if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file"); @@ -1104,7 +1104,7 @@ void Molecule::dihedrals(int flag, char *line) if (values.count() != 6) error->one(FLERR,"Invalid Dihedrals section in molecule file"); values.next_int(); typestr = values.next_string(); - if (isalpha(typestr[0])) { + if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in molecule file"); itype = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes); if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file"); @@ -1209,7 +1209,7 @@ void Molecule::impropers(int flag, char *line) if (values.count() != 6) error->one(FLERR,"Invalid Impropers section in molecule file"); values.next_int(); typestr = values.next_string(); - if (isalpha(typestr[0])) { + if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in molecule file"); itype = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes); if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file"); From c7215b54be33d3b8bf630c831461fa8357c691dd Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Sat, 23 Jan 2021 17:28:11 -0500 Subject: [PATCH 036/392] add labelmap function to variable command --- src/variable.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++-- src/variable.h | 2 ++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index c339700787..e63940e768 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -24,6 +24,7 @@ #include "info.h" #include "input.h" #include "lmppython.h" +#include "label_map.h" #include "math_const.h" #include "memory.h" #include "modify.h" @@ -2067,7 +2068,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) } else { // ---------------- - // math or group or special function + // math or group or special or labelmap function // ---------------- if (str[i] == '(') { @@ -2081,7 +2082,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) argstack,nargstack,ivar)); else if (special_function(word,contents,tree,treestack,ntreestack, argstack,nargstack,ivar)); - else print_var_error(FLERR,fmt::format("Invalid math/group/special " + else if (labelmap_function(word,contents,tree,treestack,ntreestack, + argstack,nargstack,ivar)); + else print_var_error(FLERR,fmt::format("Invalid math/group/special/labelmap " "function '{}()'in variable " "formula", word),ivar); delete [] contents; @@ -4508,6 +4511,69 @@ int Variable::special_function(char *word, char *contents, Tree **tree, return 1; } +/* ---------------------------------------------------------------------- + process a type label function in formula + push result (numeric type) onto tree or arg stack + word = interaction type + contents = str between parentheses (one type label) + return 0 if not a match, 1 if successfully processed + customize by adding a label map function: + label(typelabel),blabel(typelabel),alabel(typelabel), + dlabel(typelabel),ilabel(typelabel) +------------------------------------------------------------------------- */ + +int Variable::labelmap_function(char *word, char *contents, Tree **tree, + Tree **treestack, int &ntreestack, + double *argstack, int &nargstack, int ivar) +{ + // word not a match to any label map function + + if (strcmp(word,"label") && strcmp(word,"blabel") && + strcmp(word,"alabel") && strcmp(word,"dlabel") && + strcmp(word,"ilabel")) + return 0; + + if (!atom->labelmapflag) + print_var_error(FLERR,"Invalid type label in " + "variable formula",ivar); + + int value; + std::string typestr = contents; + + if (strcmp(word,"label") == 0) { + value = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes); + + } else if (strcmp(word,"blabel") == 0) { + value = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes); + + } else if (strcmp(word,"alabel") == 0) { + value = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes); + + } else if (strcmp(word,"dlabel") == 0) { + value = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes); + + } else if (strcmp(word,"ilabel") == 0) { + value = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes); + } + + if (value == -1) + print_var_error(FLERR,"Invalid type label in " + "variable formula",ivar); + + // save value in tree or on argstack + + if (tree) { + Tree *newtree = new Tree(); + newtree->type = VALUE; + newtree->value = value; + newtree->first = newtree->second = nullptr; + newtree->nextra = 0; + treestack[ntreestack++] = newtree; + } else argstack[nargstack++] = value; + + return 1; +} + /* ---------------------------------------------------------------------- extract a global value from a per-atom quantity in a formula flag = 0 -> word is an atom vector diff --git a/src/variable.h b/src/variable.h index 2519bc7ac9..7ecabc0afe 100644 --- a/src/variable.h +++ b/src/variable.h @@ -118,6 +118,8 @@ class Variable : protected Pointers { int region_function(char *, int); int special_function(char *, char *, Tree **, Tree **, int &, double *, int &, int); + int labelmap_function(char *, char *, Tree **, Tree **, + int &, double *, int &, int); void peratom2global(int, char *, double *, int, tagint, Tree **, Tree **, int &, double *, int &); int is_atom_vector(char *); From 5d2e3b3ecbf67bb4de29457ea4dfb6c0b28364bd Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Mon, 25 Jan 2021 20:08:25 -0500 Subject: [PATCH 037/392] direct support for coeff commands pair_coeff, bond_coeff, angle_coeff, dihedral_coeff, improper_coeff --- src/input.cpp | 32 ++++++++++++++++++++++++++++++++ src/input.h | 1 + src/label_map.cpp | 47 +++++++++++++++++++++++++++++++++++------------ src/label_map.h | 3 ++- src/molecule.cpp | 10 +++++----- src/variable.cpp | 10 +++++----- 6 files changed, 80 insertions(+), 23 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index e409111090..1974c2b4f5 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -659,6 +659,32 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag) strcpy(str,str2); } +/* ---------------------------------------------------------------------- + substitute type labels with numeric value + reallocate str to hold expanded version if necessary + if type already starts with a number, do not modify +------------------------------------------------------------------------- */ + +void Input::readtype(char *&str, int mode) +{ + if (isdigit(str[0])) return; + if (!atom->labelmapflag) error->all(FLERR,fmt::format("Invalid type {}",str)); + + int type,max,max2; + std::string labelstr; + char typechar[256]; + + labelstr = str; + type = atom->lmap->find(labelstr,mode); + if (type == -1) error->all(FLERR,fmt::format("Invalid type {}",str)); + sprintf(typechar,"%d",type); + + max = strlen(str) + 1; + max2 = strlen(typechar) + 1; + if (max2 > max) reallocate(str,max,max2); + strcpy(str,typechar); +} + /* ---------------------------------------------------------------------- return number of triple quotes in line ------------------------------------------------------------------------- */ @@ -1303,6 +1329,7 @@ void Input::angle_coeff() error->all(FLERR,"Angle_coeff command before angle_style is defined"); if (atom->avec->angles_allow == 0) error->all(FLERR,"Angle_coeff command when no angles allowed"); + readtype(arg[0],atom->lmap->ANGLE); force->angle->coeff(narg,arg); } @@ -1344,6 +1371,7 @@ void Input::bond_coeff() error->all(FLERR,"Bond_coeff command before bond_style is defined"); if (atom->avec->bonds_allow == 0) error->all(FLERR,"Bond_coeff command when no bonds allowed"); + readtype(arg[0],atom->lmap->BOND); force->bond->coeff(narg,arg); } @@ -1447,6 +1475,7 @@ void Input::dihedral_coeff() error->all(FLERR,"Dihedral_coeff command before dihedral_style is defined"); if (atom->avec->dihedrals_allow == 0) error->all(FLERR,"Dihedral_coeff command when no dihedrals allowed"); + readtype(arg[0],atom->lmap->DIHEDRAL); force->dihedral->coeff(narg,arg); } @@ -1524,6 +1553,7 @@ void Input::improper_coeff() error->all(FLERR,"Improper_coeff command before improper_style is defined"); if (atom->avec->impropers_allow == 0) error->all(FLERR,"Improper_coeff command when no impropers allowed"); + readtype(arg[0],atom->lmap->IMPROPER); force->improper->coeff(narg,arg); } @@ -1701,6 +1731,8 @@ void Input::pair_coeff() error->all(FLERR,"Pair_coeff command before simulation box is defined"); if (force->pair == nullptr) error->all(FLERR,"Pair_coeff command before pair_style is defined"); + readtype(arg[0],atom->lmap->ATOM); + readtype(arg[1],atom->lmap->ATOM); force->pair->coeff(narg,arg); } diff --git a/src/input.h b/src/input.h index e275981d32..a5a4b2b341 100755 --- a/src/input.h +++ b/src/input.h @@ -38,6 +38,7 @@ class Input : protected Pointers { char *one(const std::string&); // process a single command void substitute(char *&, char *&, int &, int &, int); // substitute for variables in a string + void readtype(char *&, int); // substitute type label with numeric type void write_echo(const std::string &); // send text to active echo file pointers protected: diff --git a/src/label_map.cpp b/src/label_map.cpp index 8ea9ae94e6..b23af8f97f 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -148,28 +148,28 @@ void LabelMap::create_lmap2lmap(LabelMap *lmap2, int mode) { if (mode == ATOM) for (int i = 0; i < natomtypes; i++) - lmap2lmap.atom[i] = find(typelabel[i],lmap2->typelabel, - lmap2->natomtypes); + lmap2lmap.atom[i] = search(typelabel[i],lmap2->typelabel, + lmap2->natomtypes); if (mode == BOND) for (int i = 0; i < nbondtypes; i++) - lmap2lmap.bond[i] = find(btypelabel[i],lmap2->btypelabel, - lmap2->nbondtypes); + lmap2lmap.bond[i] = search(btypelabel[i],lmap2->btypelabel, + lmap2->nbondtypes); if (mode == ANGLE) for (int i = 0; i < nangletypes; i++) - lmap2lmap.angle[i] = find(atypelabel[i],lmap2->atypelabel, - lmap2->nangletypes); + lmap2lmap.angle[i] = search(atypelabel[i],lmap2->atypelabel, + lmap2->nangletypes); if (mode == DIHEDRAL) for (int i = 0; i < ndihedraltypes; i++) - lmap2lmap.dihedral[i] = find(dtypelabel[i],lmap2->dtypelabel, - lmap2->ndihedraltypes); + lmap2lmap.dihedral[i] = search(dtypelabel[i],lmap2->dtypelabel, + lmap2->ndihedraltypes); if (mode == IMPROPER) for (int i = 0; i < nimpropertypes; i++) - lmap2lmap.improper[i] = find(itypelabel[i],lmap2->itypelabel, - lmap2->nimpropertypes); + lmap2lmap.improper[i] = search(itypelabel[i],lmap2->itypelabel, + lmap2->nimpropertypes); } /* ---------------------------------------------------------------------- @@ -199,11 +199,34 @@ int LabelMap::find_or_create(std::string mylabel, std::vector &labe } /* ---------------------------------------------------------------------- - find integer type given a type label + return numeric type given a type label return -1 if type not yet defined ------------------------------------------------------------------------- */ -int LabelMap::find(std::string mylabel, std::vector labels, int ntypes) +int LabelMap::find(std::string mylabel, int mode) +{ + if (mode == ATOM) + return search(mylabel,typelabel,natomtypes); + + if (mode == BOND) + return search(mylabel,btypelabel,nbondtypes); + + if (mode == ANGLE) + return search(mylabel,atypelabel,nangletypes); + + if (mode == DIHEDRAL) + return search(mylabel,dtypelabel,ndihedraltypes); + + if (mode == IMPROPER) + return search(mylabel,itypelabel,nimpropertypes); +} + +/* ---------------------------------------------------------------------- + get index+1 given vector of strings + return -1 if type not yet defined +------------------------------------------------------------------------- */ + +int LabelMap::search(std::string mylabel, std::vector labels, int ntypes) { for (int i = 0; i < ntypes; i++) if (labels[i] == mylabel) return i+1; diff --git a/src/label_map.h b/src/label_map.h index 978923252e..11c3f19443 100755 --- a/src/label_map.h +++ b/src/label_map.h @@ -46,7 +46,8 @@ class LabelMap : protected Pointers { void merge_lmap(class LabelMap *, int); // copy another lmap into this one void create_lmap2lmap(class LabelMap *, int); // index mapping between two lmaps int find_or_create(std::string, std::vector &, int); // look up type or create new type - int find(std::string, std::vector, int); // look up type index + int find(std::string, int); // find numeric type of type label + int search(std::string, std::vector, int); // look up type index // input/output for atom class label map diff --git a/src/molecule.cpp b/src/molecule.cpp index 7556239aed..4c4a3bfba3 100755 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -729,7 +729,7 @@ void Molecule::types(char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Types section in molecule file"); - type[iatom] = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes); + type[iatom] = atom->lmap->find(typestr,atom->lmap->ATOM); if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file"); } else type[iatom] = utils::inumeric(FLERR,typestr.c_str(),false,lmp); type[iatom] += toffset; @@ -942,7 +942,7 @@ void Molecule::bonds(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in molecule file"); - itype = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes); + itype = atom->lmap->find(typestr,atom->lmap->BOND); if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1016,7 +1016,7 @@ void Molecule::angles(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in molecule file"); - itype = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes); + itype = atom->lmap->find(typestr,atom->lmap->ANGLE); if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1106,7 +1106,7 @@ void Molecule::dihedrals(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in molecule file"); - itype = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes); + itype = atom->lmap->find(typestr,atom->lmap->DIHEDRAL); if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1211,7 +1211,7 @@ void Molecule::impropers(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in molecule file"); - itype = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes); + itype = atom->lmap->find(typestr,atom->lmap->IMPROPER); if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); diff --git a/src/variable.cpp b/src/variable.cpp index e63940e768..fdd60de1a0 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -4541,19 +4541,19 @@ int Variable::labelmap_function(char *word, char *contents, Tree **tree, std::string typestr = contents; if (strcmp(word,"label") == 0) { - value = atom->lmap->find(typestr,atom->lmap->typelabel,atom->ntypes); + value = atom->lmap->find(typestr,atom->lmap->ATOM); } else if (strcmp(word,"blabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->btypelabel,atom->nbondtypes); + value = atom->lmap->find(typestr,atom->lmap->BOND); } else if (strcmp(word,"alabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->atypelabel,atom->nangletypes); + value = atom->lmap->find(typestr,atom->lmap->ANGLE); } else if (strcmp(word,"dlabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->dtypelabel,atom->ndihedraltypes); + value = atom->lmap->find(typestr,atom->lmap->DIHEDRAL); } else if (strcmp(word,"ilabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->itypelabel,atom->nimpropertypes); + value = atom->lmap->find(typestr,atom->lmap->IMPROPER); } if (value == -1) From 0b4256e67a5cd080fd48f9428fce409a95df38bb Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Tue, 26 Jan 2021 22:55:19 -0500 Subject: [PATCH 038/392] valid numeric type strings can include * --- src/input.cpp | 7 +++++-- src/label_map.cpp | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index 1974c2b4f5..8129ed47f8 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -662,12 +662,15 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag) /* ---------------------------------------------------------------------- substitute type labels with numeric value reallocate str to hold expanded version if necessary - if type already starts with a number, do not modify + if type is a valid numerical string (can include *), do not modify ------------------------------------------------------------------------- */ void Input::readtype(char *&str, int mode) { - if (isdigit(str[0])) return; + int numflag = 1; + for (int i = 0; i < strlen(str); i++) + if (!isdigit(str[i]) && str[i] != '*') numflag = 0; + if (numflag) return; if (!atom->labelmapflag) error->all(FLERR,fmt::format("Invalid type {}",str)); int type,max,max2; diff --git a/src/label_map.cpp b/src/label_map.cpp index b23af8f97f..8cd15ed64b 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -219,6 +219,8 @@ int LabelMap::find(std::string mylabel, int mode) if (mode == IMPROPER) return search(mylabel,itypelabel,nimpropertypes); + + return -1; } /* ---------------------------------------------------------------------- From add904ea4ef46a2c53310eb77e1f20a33e2801f8 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Thu, 28 Jan 2021 10:53:44 -0500 Subject: [PATCH 039/392] labelmap doc update, for reference --- doc/src/labelmap.rst | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/doc/src/labelmap.rst b/doc/src/labelmap.rst index a73f06652e..c64d7b3fb5 100755 --- a/doc/src/labelmap.rst +++ b/doc/src/labelmap.rst @@ -19,7 +19,7 @@ Examples .. code-block:: LAMMPS labelmap atom 3 carbon - labelmap bond 1 c1,c2 2 c1,hc + labelmap bond 1 [c1][c2] 2 [c1][hc] Description """"""""""" @@ -39,11 +39,12 @@ sections. If substituting numeric types with type labels is currently supported by a given command, this feature will be mentioned on - that command's doc page. + that command's doc page. Or, for input script commands, type labels + can be processed using :doc:`variable ` syntax. .. note:: - Type labels must begin with a letter. + Type labels cannot start with a number. The label map of only one type of interaction (atom, bond, etc.) may be modified by a given *labelmap* command. Any number of @@ -55,6 +56,17 @@ There does not need to be a type label associated with every numeric type; in this case, those types without a label must be referenced by their numeric type. +For certain features, it is necessary to be able to extract the +atom types that make up a given bond, angle, dihedral or improper. The +standard way to write multi-atom interaction types is to enclose the +constituent atom types in brackets. For example, a bond type between +atom type 'C' and 'H' is written as: + +.. code-block:: LAMMPS + + bond_style harmonic + bond_coeff [C][H] 80.0 1.2 + ---------- Restrictions From 797555b5ce80726eb4de2b1e44f58bc61af672ac Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Thu, 28 Jan 2021 23:44:02 -0500 Subject: [PATCH 040/392] toward multiple maps --- src/atom.cpp | 42 +++++++++++++++++++++++++++++++----------- src/atom.h | 9 ++++++--- src/input.cpp | 18 +++++++++--------- src/label_map.cpp | 31 ++++++++++++++++--------------- src/label_map.h | 2 +- src/molecule.cpp | 11 +++++------ src/read_data.cpp | 16 ++++++++-------- src/read_restart.cpp | 4 ++-- src/variable.cpp | 11 +++++------ src/write_data.cpp | 2 +- src/write_restart.cpp | 2 +- 11 files changed, 85 insertions(+), 63 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 8a5bacc645..8e8c1a2bb8 100755 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -204,7 +204,7 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) // type labels - lmap = nullptr; + lmaps = nullptr; // custom atom arrays @@ -312,9 +312,10 @@ Atom::~Atom() for (int i = 0; i < nmolecule; i++) delete molecules[i]; memory->sfree(molecules); - // delete label map + // delete label maps - delete lmap; + for (int i = 0; i < nlmap; i++) delete lmaps[i]; + memory->sfree(lmaps); // delete per-type arrays @@ -1989,16 +1990,35 @@ void Atom::add_molecule_atom(Molecule *onemol, int iatom, allocate space for type label map ------------------------------------------------------------------------- */ -void Atom::add_label_map() +void Atom::add_label_map(char *mapID) { labelmapflag = 1; - lmap = new LabelMap(lmp); - lmap->natomtypes = ntypes; - lmap->nbondtypes = nbondtypes; - lmap->nangletypes = nangletypes; - lmap->ndihedraltypes = ndihedraltypes; - lmap->nimpropertypes = nimpropertypes; - lmap->allocate_type_labels(); + lmaps = (LabelMap **) + memory->srealloc(lmaps,(nlmap+1)*sizeof(LabelMap *), + "atom::lmaps"); + lmaps[nlmap] = new LabelMap(lmp); + lmaps[nlmap]->id = mapID; + lmaps[nlmap]->natomtypes = ntypes; + lmaps[nlmap]->nbondtypes = nbondtypes; + lmaps[nlmap]->nangletypes = nangletypes; + lmaps[nlmap]->ndihedraltypes = ndihedraltypes; + lmaps[nlmap]->nimpropertypes = nimpropertypes; + lmaps[nlmap]->allocate_type_labels(); + nlmap++; +} + +/* ---------------------------------------------------------------------- + find label, first parsing prefix for label map-ID + return -1 if does not exist +------------------------------------------------------------------------- */ + +int Atom::find_label(std::string label, int mode) +{ + // find label map ... in progress + int ilmap; + ilmap = 0; + + return lmaps[ilmap]->find(label,mode); } /* ---------------------------------------------------------------------- diff --git a/src/atom.h b/src/atom.h index 9947f5aea4..94741261b0 100755 --- a/src/atom.h +++ b/src/atom.h @@ -32,6 +32,7 @@ class Atom : protected Pointers { enum{DOUBLE,INT,BIGINT}; enum{GROW=0,RESTART=1,BORDER=2}; enum{ATOMIC=0,MOLECULAR=1,TEMPLATE=2}; + enum{ATOM=0,BOND=1,ANGLE=2,DIHEDRAL=3,IMPROPER=4}; enum{MAP_NONE=0,MAP_ARRAY=1,MAP_HASH=2,MAP_YES=3}; // atom counts @@ -229,9 +230,10 @@ class Atom : protected Pointers { int nmolecule; class Molecule **molecules; - // type labels + // type label maps - class LabelMap *lmap; + int nlmap; + class LabelMap **lmaps; // extra peratom info in restart file destined for fix & diag @@ -327,7 +329,8 @@ class Atom : protected Pointers { int find_molecule(char *); void add_molecule_atom(class Molecule *, int, int, tagint); - void add_label_map(); + void add_label_map(char *); + int find_label(std::string, int); void first_reorder(); virtual void sort(); diff --git a/src/input.cpp b/src/input.cpp index 8129ed47f8..31cd037e8e 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -678,7 +678,7 @@ void Input::readtype(char *&str, int mode) char typechar[256]; labelstr = str; - type = atom->lmap->find(labelstr,mode); + type = atom->find_label(labelstr,mode); if (type == -1) error->all(FLERR,fmt::format("Invalid type {}",str)); sprintf(typechar,"%d",type); @@ -1332,7 +1332,7 @@ void Input::angle_coeff() error->all(FLERR,"Angle_coeff command before angle_style is defined"); if (atom->avec->angles_allow == 0) error->all(FLERR,"Angle_coeff command when no angles allowed"); - readtype(arg[0],atom->lmap->ANGLE); + readtype(arg[0],atom->ANGLE); force->angle->coeff(narg,arg); } @@ -1374,7 +1374,7 @@ void Input::bond_coeff() error->all(FLERR,"Bond_coeff command before bond_style is defined"); if (atom->avec->bonds_allow == 0) error->all(FLERR,"Bond_coeff command when no bonds allowed"); - readtype(arg[0],atom->lmap->BOND); + readtype(arg[0],atom->BOND); force->bond->coeff(narg,arg); } @@ -1478,7 +1478,7 @@ void Input::dihedral_coeff() error->all(FLERR,"Dihedral_coeff command before dihedral_style is defined"); if (atom->avec->dihedrals_allow == 0) error->all(FLERR,"Dihedral_coeff command when no dihedrals allowed"); - readtype(arg[0],atom->lmap->DIHEDRAL); + readtype(arg[0],atom->DIHEDRAL); force->dihedral->coeff(narg,arg); } @@ -1556,7 +1556,7 @@ void Input::improper_coeff() error->all(FLERR,"Improper_coeff command before improper_style is defined"); if (atom->avec->impropers_allow == 0) error->all(FLERR,"Improper_coeff command when no impropers allowed"); - readtype(arg[0],atom->lmap->IMPROPER); + readtype(arg[0],atom->IMPROPER); force->improper->coeff(narg,arg); } @@ -1593,8 +1593,8 @@ void Input::labelmap() { if (domain->box_exist == 0) error->all(FLERR,"Labelmap command before simulation box is defined"); - if (!atom->labelmapflag) atom->add_label_map(); - atom->lmap->modify_lmap(narg,arg); + if (!atom->labelmapflag) atom->add_label_map(""); + atom->lmaps[0]->modify_lmap(narg,arg); } /* ---------------------------------------------------------------------- */ @@ -1734,8 +1734,8 @@ void Input::pair_coeff() error->all(FLERR,"Pair_coeff command before simulation box is defined"); if (force->pair == nullptr) error->all(FLERR,"Pair_coeff command before pair_style is defined"); - readtype(arg[0],atom->lmap->ATOM); - readtype(arg[1],atom->lmap->ATOM); + readtype(arg[0],atom->ATOM); + readtype(arg[1],atom->ATOM); force->pair->coeff(narg,arg); } diff --git a/src/label_map.cpp b/src/label_map.cpp index 8cd15ed64b..e8ce7ecfc7 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -13,6 +13,7 @@ #include "label_map.h" +#include "atom.h" #include "force.h" #include "memory.h" #include "error.h" @@ -118,23 +119,23 @@ void LabelMap::modify_lmap(int narg, char **arg) void LabelMap::merge_lmap(LabelMap *lmap2, int mode) { - if (mode == ATOM) + if (mode == atom->ATOM) for (int i = 0; i < lmap2->natomtypes; i++) find_or_create(lmap2->typelabel[i],typelabel,natomtypes); - if (mode == BOND) + if (mode == atom->BOND) for (int i = 0; i < lmap2->nbondtypes; i++) find_or_create(lmap2->btypelabel[i],btypelabel,nbondtypes); - if (mode == ANGLE) + if (mode == atom->ANGLE) for (int i = 0; i < lmap2->nangletypes; i++) find_or_create(lmap2->atypelabel[i],atypelabel,nangletypes); - if (mode == DIHEDRAL) + if (mode == atom->DIHEDRAL) for (int i = 0; i < lmap2->ndihedraltypes; i++) find_or_create(lmap2->dtypelabel[i],dtypelabel,ndihedraltypes); - if (mode == IMPROPER) + if (mode == atom->IMPROPER) for (int i = 0; i < lmap2->nimpropertypes; i++) find_or_create(lmap2->itypelabel[i],itypelabel,nimpropertypes); } @@ -146,27 +147,27 @@ void LabelMap::merge_lmap(LabelMap *lmap2, int mode) void LabelMap::create_lmap2lmap(LabelMap *lmap2, int mode) { - if (mode == ATOM) + if (mode == atom->ATOM) for (int i = 0; i < natomtypes; i++) lmap2lmap.atom[i] = search(typelabel[i],lmap2->typelabel, lmap2->natomtypes); - if (mode == BOND) + if (mode == atom->BOND) for (int i = 0; i < nbondtypes; i++) lmap2lmap.bond[i] = search(btypelabel[i],lmap2->btypelabel, lmap2->nbondtypes); - if (mode == ANGLE) + if (mode == atom->ANGLE) for (int i = 0; i < nangletypes; i++) lmap2lmap.angle[i] = search(atypelabel[i],lmap2->atypelabel, lmap2->nangletypes); - if (mode == DIHEDRAL) + if (mode == atom->DIHEDRAL) for (int i = 0; i < ndihedraltypes; i++) lmap2lmap.dihedral[i] = search(dtypelabel[i],lmap2->dtypelabel, lmap2->ndihedraltypes); - if (mode == IMPROPER) + if (mode == atom->IMPROPER) for (int i = 0; i < nimpropertypes; i++) lmap2lmap.improper[i] = search(itypelabel[i],lmap2->itypelabel, lmap2->nimpropertypes); @@ -205,19 +206,19 @@ int LabelMap::find_or_create(std::string mylabel, std::vector &labe int LabelMap::find(std::string mylabel, int mode) { - if (mode == ATOM) + if (mode == atom->ATOM) return search(mylabel,typelabel,natomtypes); - if (mode == BOND) + if (mode == atom->BOND) return search(mylabel,btypelabel,nbondtypes); - if (mode == ANGLE) + if (mode == atom->ANGLE) return search(mylabel,atypelabel,nangletypes); - if (mode == DIHEDRAL) + if (mode == atom->DIHEDRAL) return search(mylabel,dtypelabel,ndihedraltypes); - if (mode == IMPROPER) + if (mode == atom->IMPROPER) return search(mylabel,itypelabel,nimpropertypes); return -1; diff --git a/src/label_map.h b/src/label_map.h index 11c3f19443..402fd210f5 100755 --- a/src/label_map.h +++ b/src/label_map.h @@ -20,9 +20,9 @@ namespace LAMMPS_NS { class LabelMap : protected Pointers { public: - enum{ATOM,BOND,ANGLE,DIHEDRAL,IMPROPER}; int natomtypes,nbondtypes,nangletypes; int ndihedraltypes,nimpropertypes; + std::string id; std::vector typelabel,btypelabel,atypelabel; std::vector dtypelabel,itypelabel; diff --git a/src/molecule.cpp b/src/molecule.cpp index 4c4a3bfba3..0bec25e183 100755 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -20,7 +20,6 @@ #include "domain.h" #include "error.h" #include "force.h" -#include "label_map.h" #include "math_extra.h" #include "math_eigen.h" #include "memory.h" @@ -729,7 +728,7 @@ void Molecule::types(char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Types section in molecule file"); - type[iatom] = atom->lmap->find(typestr,atom->lmap->ATOM); + type[iatom] = atom->find_label(typestr,atom->ATOM); if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file"); } else type[iatom] = utils::inumeric(FLERR,typestr.c_str(),false,lmp); type[iatom] += toffset; @@ -942,7 +941,7 @@ void Molecule::bonds(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in molecule file"); - itype = atom->lmap->find(typestr,atom->lmap->BOND); + itype = atom->find_label(typestr,atom->BOND); if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1016,7 +1015,7 @@ void Molecule::angles(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in molecule file"); - itype = atom->lmap->find(typestr,atom->lmap->ANGLE); + itype = atom->find_label(typestr,atom->ANGLE); if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1106,7 +1105,7 @@ void Molecule::dihedrals(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in molecule file"); - itype = atom->lmap->find(typestr,atom->lmap->DIHEDRAL); + itype = atom->find_label(typestr,atom->DIHEDRAL); if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1211,7 +1210,7 @@ void Molecule::impropers(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in molecule file"); - itype = atom->lmap->find(typestr,atom->lmap->IMPROPER); + itype = atom->find_label(typestr,atom->IMPROPER); if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); diff --git a/src/read_data.cpp b/src/read_data.cpp index f493be0977..fd60a2b9b2 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -729,7 +729,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (atomflag == 1) error->all(FLERR,"Must read Atom Type Labels before Atoms"); - typelabels(lmap->typelabel,ntypes,lmap->ATOM); + typelabels(lmap->typelabel,ntypes,atom->ATOM); } else skip_lines(ntypes); } else if (strcmp(keyword,"Bond Type Labels") == 0) { @@ -737,7 +737,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (bondflag == 1) error->all(FLERR,"Must read Bond Type Labels before Bonds"); - typelabels(lmap->btypelabel,nbondtypes,lmap->BOND); + typelabels(lmap->btypelabel,nbondtypes,atom->BOND); } else skip_lines(nbondtypes); } @@ -746,7 +746,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (angleflag == 1) error->all(FLERR,"Must read Angle Type Labels before Angles"); - typelabels(lmap->atypelabel,nangletypes,lmap->ANGLE); + typelabels(lmap->atypelabel,nangletypes,atom->ANGLE); } else skip_lines(nangletypes); } @@ -755,7 +755,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (dihedralflag == 1) error->all(FLERR,"Must read Dihedral Type Labels before Dihedrals"); - typelabels(lmap->dtypelabel,ndihedraltypes,lmap->DIHEDRAL); + typelabels(lmap->dtypelabel,ndihedraltypes,atom->DIHEDRAL); } else skip_lines(ndihedraltypes); } @@ -764,7 +764,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (improperflag == 1) error->all(FLERR,"Must read Improper Type Labels before Impropers"); - typelabels(lmap->itypelabel,nimpropertypes,lmap->IMPROPER); + typelabels(lmap->itypelabel,nimpropertypes,atom->IMPROPER); } else skip_lines(nimpropertypes); } @@ -1974,7 +1974,7 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i char *buf = new char[myntypes*MAXLINE]; labelflag = 1; - if (!atom->labelmapflag) atom->add_label_map(); + if (!atom->labelmapflag) atom->add_label_map(""); int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); @@ -1994,8 +1994,8 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i // determine mapping to let labels override numeric types // valid operations for first or subsequent data files - atom->lmap->merge_lmap(lmap,mode); - lmap->create_lmap2lmap(atom->lmap,mode); + atom->lmaps[0]->merge_lmap(lmap,mode); + lmap->create_lmap2lmap(atom->lmaps[0],mode); } /* ---------------------------------------------------------------------- diff --git a/src/read_restart.cpp b/src/read_restart.cpp index 89994abab5..d3b3f70b4a 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -932,8 +932,8 @@ void ReadRestart::type_arrays() } else if (flag == LABELMAP) { read_int(); - atom->add_label_map(); - atom->lmap->read_restart(fp); + atom->add_label_map(""); + atom->lmaps[0]->read_restart(fp); } else error->all(FLERR, "Invalid flag in type arrays section of restart file"); diff --git a/src/variable.cpp b/src/variable.cpp index fdd60de1a0..ddc5365caa 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -24,7 +24,6 @@ #include "info.h" #include "input.h" #include "lmppython.h" -#include "label_map.h" #include "math_const.h" #include "memory.h" #include "modify.h" @@ -4541,19 +4540,19 @@ int Variable::labelmap_function(char *word, char *contents, Tree **tree, std::string typestr = contents; if (strcmp(word,"label") == 0) { - value = atom->lmap->find(typestr,atom->lmap->ATOM); + value = atom->find_label(typestr,atom->ATOM); } else if (strcmp(word,"blabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->BOND); + value = atom->find_label(typestr,atom->BOND); } else if (strcmp(word,"alabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->ANGLE); + value = atom->find_label(typestr,atom->ANGLE); } else if (strcmp(word,"dlabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->DIHEDRAL); + value = atom->find_label(typestr,atom->DIHEDRAL); } else if (strcmp(word,"ilabel") == 0) { - value = atom->lmap->find(typestr,atom->lmap->IMPROPER); + value = atom->find_label(typestr,atom->IMPROPER); } if (value == -1) diff --git a/src/write_data.cpp b/src/write_data.cpp index 8088203d5e..4a94f12500 100755 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -186,7 +186,7 @@ void WriteData::write(const std::string &file) if (me == 0) { header(); - if (atom->labelmapflag) atom->lmap->write_data(fp); + if (atom->labelmapflag) atom->lmaps[0]->write_data(fp); type_arrays(); if (coeffflag) force_fields(); } diff --git a/src/write_restart.cpp b/src/write_restart.cpp index f97cdcd966..31ac06db1a 100755 --- a/src/write_restart.cpp +++ b/src/write_restart.cpp @@ -523,7 +523,7 @@ void WriteRestart::type_arrays() if (atom->mass) write_double_vec(MASS,atom->ntypes,&atom->mass[1]); if (atom->labelmapflag) { write_int(LABELMAP,atom->labelmapflag); - atom->lmap->write_restart(fp); + atom->lmaps[0]->write_restart(fp); } // -1 flag signals end of type arrays From 8e255f619b5414e93ac1e5d87f4186485fbf0648 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Fri, 29 Jan 2021 19:12:26 -0500 Subject: [PATCH 041/392] compiler issues --- src/atom.cpp | 2 +- src/atom.h | 2 +- src/input.cpp | 5 +++-- src/read_data.cpp | 2 +- src/read_restart.cpp | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 8e8c1a2bb8..5d3b960731 100755 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -1990,7 +1990,7 @@ void Atom::add_molecule_atom(Molecule *onemol, int iatom, allocate space for type label map ------------------------------------------------------------------------- */ -void Atom::add_label_map(char *mapID) +void Atom::add_label_map(std::string mapID) { labelmapflag = 1; lmaps = (LabelMap **) diff --git a/src/atom.h b/src/atom.h index 94741261b0..4eb62bdfe4 100755 --- a/src/atom.h +++ b/src/atom.h @@ -329,7 +329,7 @@ class Atom : protected Pointers { int find_molecule(char *); void add_molecule_atom(class Molecule *, int, int, tagint); - void add_label_map(char *); + void add_label_map(std::string mapID = ""); int find_label(std::string, int); void first_reorder(); diff --git a/src/input.cpp b/src/input.cpp index 31cd037e8e..e51643fbfa 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -668,7 +668,8 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag) void Input::readtype(char *&str, int mode) { int numflag = 1; - for (int i = 0; i < strlen(str); i++) + int n = strlen(str); + for (int i = 0; i < n; i++) if (!isdigit(str[i]) && str[i] != '*') numflag = 0; if (numflag) return; if (!atom->labelmapflag) error->all(FLERR,fmt::format("Invalid type {}",str)); @@ -1593,7 +1594,7 @@ void Input::labelmap() { if (domain->box_exist == 0) error->all(FLERR,"Labelmap command before simulation box is defined"); - if (!atom->labelmapflag) atom->add_label_map(""); + if (!atom->labelmapflag) atom->add_label_map(); atom->lmaps[0]->modify_lmap(narg,arg); } diff --git a/src/read_data.cpp b/src/read_data.cpp index fd60a2b9b2..35c4ebb49b 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -1974,7 +1974,7 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i char *buf = new char[myntypes*MAXLINE]; labelflag = 1; - if (!atom->labelmapflag) atom->add_label_map(""); + if (!atom->labelmapflag) atom->add_label_map(); int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); diff --git a/src/read_restart.cpp b/src/read_restart.cpp index d3b3f70b4a..fcfadb6d22 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -932,7 +932,7 @@ void ReadRestart::type_arrays() } else if (flag == LABELMAP) { read_int(); - atom->add_label_map(""); + atom->add_label_map(); atom->lmaps[0]->read_restart(fp); } else error->all(FLERR, From f6fe554b475ef51e2ec88feabad07b7fc9cd7010 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Fri, 29 Jan 2021 22:38:33 -0500 Subject: [PATCH 042/392] basic support for auxiliary label maps can be created with labelmap via mapID keyword referenced like mymapID::C where C is an atom type, for example --- src/atom.cpp | 30 ++++++++++++++++++++++++++---- src/atom.h | 3 ++- src/input.cpp | 18 +++++++++++++++++- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 5d3b960731..d80984bd1a 100755 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -204,6 +204,7 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) // type labels + nlmap = 0; lmaps = nullptr; // custom atom arrays @@ -1990,7 +1991,7 @@ void Atom::add_molecule_atom(Molecule *onemol, int iatom, allocate space for type label map ------------------------------------------------------------------------- */ -void Atom::add_label_map(std::string mapID) +int Atom::add_label_map(std::string mapID) { labelmapflag = 1; lmaps = (LabelMap **) @@ -2005,6 +2006,7 @@ void Atom::add_label_map(std::string mapID) lmaps[nlmap]->nimpropertypes = nimpropertypes; lmaps[nlmap]->allocate_type_labels(); nlmap++; + return nlmap - 1; } /* ---------------------------------------------------------------------- @@ -2014,13 +2016,33 @@ void Atom::add_label_map(std::string mapID) int Atom::find_label(std::string label, int mode) { - // find label map ... in progress - int ilmap; - ilmap = 0; + int ilmap = 0; + + // check for auxiliary map prefix + + int pos = label.find("::"); + if (pos != std::string::npos) { + ilmap = find_labelmap(label.substr(0,pos)); + if (ilmap == -1) return -1; + label = label.substr(pos+2); + } return lmaps[ilmap]->find(label,mode); } +/* ---------------------------------------------------------------------- + find first label map in set with ID + return -1 if does not exist +------------------------------------------------------------------------- */ + +int Atom::find_labelmap(std::string id) +{ + int ilmap; + for (ilmap = 0; ilmap < nlmap; ilmap++) + if (id == lmaps[ilmap]->id) return ilmap; + return -1; +} + /* ---------------------------------------------------------------------- reorder owned atoms so those in firstgroup appear first called by comm->exchange() if atom_modify first group is set diff --git a/src/atom.h b/src/atom.h index 4eb62bdfe4..e65b755a3c 100755 --- a/src/atom.h +++ b/src/atom.h @@ -329,8 +329,9 @@ class Atom : protected Pointers { int find_molecule(char *); void add_molecule_atom(class Molecule *, int, int, tagint); - void add_label_map(std::string mapID = ""); + int add_label_map(std::string mapID = ""); int find_label(std::string, int); + int find_labelmap(std::string); void first_reorder(); virtual void sort(); diff --git a/src/input.cpp b/src/input.cpp index e51643fbfa..f80f7d9415 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -1592,10 +1592,26 @@ void Input::kspace_style() void Input::labelmap() { + if (narg < 2 || (narg % 2 == 0)) error->all(FLERR,"Illegal labelmap command"); if (domain->box_exist == 0) error->all(FLERR,"Labelmap command before simulation box is defined"); + if (!atom->labelmapflag) atom->add_label_map(); - atom->lmaps[0]->modify_lmap(narg,arg); + + int ilmap = 0; + std::string mapid; + for (int i = 1; i < narg; i++) { + if (strcmp(arg[i],"mapID") == 0) { + mapid = arg[i+1]; + ilmap = atom->find_labelmap(mapid); + if (ilmap == -1) ilmap = atom->add_label_map(mapid); + if (narg > i+2) error->all(FLERR,"Illegal labelmap command"); + narg = i - 2; + break; + } + i++; + } + atom->lmaps[ilmap]->modify_lmap(narg,arg); } /* ---------------------------------------------------------------------- */ From e3a6afe1ab9d87e9a237c106a6e4d3f6b0d49516 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Fri, 29 Jan 2021 23:38:25 -0500 Subject: [PATCH 043/392] labelmap map/assign docs --- doc/src/labelmap.rst | 30 ++++++++++++++++++++++++++---- doc/src/molecule.rst | 4 ++-- doc/src/write_data.rst | 0 src/input.cpp | 2 +- 4 files changed, 29 insertions(+), 7 deletions(-) mode change 100644 => 100755 doc/src/write_data.rst diff --git a/doc/src/labelmap.rst b/doc/src/labelmap.rst index c64d7b3fb5..7d9ec89166 100755 --- a/doc/src/labelmap.rst +++ b/doc/src/labelmap.rst @@ -8,10 +8,16 @@ Syntax .. code-block:: LAMMPS - labelmap interaction numeric-type type-label ... + labelmap interaction numeric-type type-label ... keyword values * interaction = *atom* or *bond* or *angle* or *dihedral* or *improper* * one or more numeric-type/type-label pairs may be appended +* keyword = *map/assign* + + .. parsed-literal:: + + *map/assign* value = mapID + mapID = name of auxiliary label map Examples """""""" @@ -31,9 +37,9 @@ numeric type used by LAMMPS with a character-based type can be helpful in a variety of situations. For example, type labels can make various inputs more readable and compatible with other inputs (data files, molecule templates, etc.), particularly if your model's force -field uses alphanumeric atom types. Type label maps can also be -defined by :doc:`data files ` using the relevant Type Label -sections. +field uses alphanumeric atom types. The default type label map can +also be defined by :doc:`data files ` using the relevant +Type Label sections. .. note:: @@ -67,6 +73,22 @@ atom type 'C' and 'H' is written as: bond_style harmonic bond_coeff [C][H] 80.0 1.2 +In some circumstances, it may be helpful to define extra label maps in +addition to the default one. An auxiliary label map can be created and +populated using the *map/assign* keyword. Type labels of auxiliary +label maps can be referenced by prefixing the type label with the +mapID followed by "::". For example, a type label "C" assigned to a +label map named "Map2" can be created and referenced as follows: + +.. code-block:: LAMMPS + + labelmap bond 1 [C][H] map/assign Map2 + bond_coeff Map2::[C][H] 80.0 1.2 + +Auxiliary label maps are not written to restart or data files. Due to +the syntax for auxiliary maps, type labels cannot contain the +substring "::". The default label map has no prefix. + ---------- Restrictions diff --git a/doc/src/molecule.rst b/doc/src/molecule.rst index bc16aeb9a4..a1c215cb63 100755 --- a/doc/src/molecule.rst +++ b/doc/src/molecule.rst @@ -175,8 +175,8 @@ These are the allowed section keywords for the body of the file. For the Types, Bonds, Angles, Dihedrals, and Impropers sections, each atom, bond, etc. type can be listed either as a number (numeric type) -or as an alphanumeric :doc:`type label `. Type labels must -begin with letter, and a label map must have previously been defined +or as an alphanumeric :doc:`type label `. Type labels cannot +start with a number, and a label map must have previously been defined by a :doc:`labelmap ` or :doc:`read_data ` command. diff --git a/doc/src/write_data.rst b/doc/src/write_data.rst old mode 100644 new mode 100755 diff --git a/src/input.cpp b/src/input.cpp index f80f7d9415..a260d01ef2 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -1601,7 +1601,7 @@ void Input::labelmap() int ilmap = 0; std::string mapid; for (int i = 1; i < narg; i++) { - if (strcmp(arg[i],"mapID") == 0) { + if (strcmp(arg[i],"map/assign") == 0) { mapid = arg[i+1]; ilmap = atom->find_labelmap(mapid); if (ilmap == -1) ilmap = atom->add_label_map(mapid); From 2ee6e8f58276425e0004c358d8c132417acd5371 Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sat, 30 Jan 2021 21:22:49 -0500 Subject: [PATCH 044/392] more docs also, relax I <= J requirement for pair_coeff, as 'required' by type labels --- doc/src/angle_coeff.rst | 11 ++++---- doc/src/bond_coeff.rst | 13 +++++---- doc/src/dihedral_coeff.rst | 11 ++++---- doc/src/improper_coeff.rst | 17 ++++++------ doc/src/pair_coeff.rst | 30 ++++++++++---------- doc/src/read_data.rst | 56 ++++++++++++++++++++++++++++++++++---- doc/src/variable.rst | 15 ++++++++++ src/input.cpp | 16 +++++++++++ src/label_map.cpp | 2 +- 9 files changed, 126 insertions(+), 45 deletions(-) diff --git a/doc/src/angle_coeff.rst b/doc/src/angle_coeff.rst index 07048c1432..b1424266b5 100644 --- a/doc/src/angle_coeff.rst +++ b/doc/src/angle_coeff.rst @@ -10,7 +10,7 @@ Syntax angle_coeff N args -* N = angle type (see asterisk form below) +* N = numeric angle type (see asterisk form below), or type label * args = coefficients for one or more angle types Examples @@ -31,10 +31,11 @@ Angle coefficients can also be set in the data file read by the :doc:`read_data ` command or in a restart file. N can be specified in one of two ways. An explicit numeric value can -be used, as in the first example above. Or a wild-card asterisk can be -used to set the coefficients for multiple angle types. This takes the -form "\*" or "\*n" or "n\*" or "m\*n". If N = the number of angle types, -then an asterisk with no numeric values means all types from 1 to N. A +be used, as in the first example above. Or N can be a :doc:`type label `. +For numeric values only, a wild-card asterisk can be used to set the +coefficients for multiple angle types. This takes the form "\*" or +"\*n" or "n\*" or "m\*n". If N = the number of angle types, then an +asterisk with no numeric values means all types from 1 to N. A leading asterisk means all types from 1 to n (inclusive). A trailing asterisk means all types from n to N (inclusive). A middle asterisk means all types from m to n (inclusive). diff --git a/doc/src/bond_coeff.rst b/doc/src/bond_coeff.rst index 84a949a018..6e3f4f96be 100644 --- a/doc/src/bond_coeff.rst +++ b/doc/src/bond_coeff.rst @@ -10,7 +10,7 @@ Syntax bond_coeff N args -* N = bond type (see asterisk form below) +* N = numeric bond type (see asterisk form below), or type label * args = coefficients for one or more bond types Examples @@ -31,11 +31,12 @@ The number and meaning of the coefficients depends on the bond style. Bond coefficients can also be set in the data file read by the :doc:`read_data ` command or in a restart file. -N can be specified in one of two ways. An explicit numeric value can -be used, as in the first example above. Or a wild-card asterisk can be -used to set the coefficients for multiple bond types. This takes the -form "\*" or "\*n" or "n\*" or "m\*n". If N = the number of bond types, -then an asterisk with no numeric values means all types from 1 to N. A +N can be specified in one of several ways. An explicit numeric value can +be used, as in the first example above. Or N can be a :doc:`type label `. +For numeric values only, a wild-card asterisk can be used to set the +coefficients for multiple bond types. This takes the form "\*" or +"\*n" or "n\*" or "m\*n". If N = the number of bond types, then an +asterisk with no numeric values means all types from 1 to N. A leading asterisk means all types from 1 to n (inclusive). A trailing asterisk means all types from n to N (inclusive). A middle asterisk means all types from m to n (inclusive). diff --git a/doc/src/dihedral_coeff.rst b/doc/src/dihedral_coeff.rst index b60c3c3d6c..1e6dbc91ff 100644 --- a/doc/src/dihedral_coeff.rst +++ b/doc/src/dihedral_coeff.rst @@ -10,7 +10,7 @@ Syntax dihedral_coeff N args -* N = dihedral type (see asterisk form below) +* N = numeric dihedral type (see asterisk form below), or type label * args = coefficients for one or more dihedral types Examples @@ -31,10 +31,11 @@ Dihedral coefficients can also be set in the data file read by the :doc:`read_data ` command or in a restart file. N can be specified in one of two ways. An explicit numeric value can -be used, as in the first example above. Or a wild-card asterisk can be -used to set the coefficients for multiple dihedral types. This takes the -form "\*" or "\*n" or "n\*" or "m\*n". If N = the number of dihedral types, -then an asterisk with no numeric values means all types from 1 to N. A +be used, as in the first example above. Or N can be a :doc:`type label `. +For numeric values only, a wild-card asterisk can be used to set the +coefficients for multiple dihedral types. This takes the form "\*" or +"\*n" or "n\*" or "m\*n". If N = the number of dihedral types, then +an asterisk with no numeric values means all types from 1 to N. A leading asterisk means all types from 1 to n (inclusive). A trailing asterisk means all types from n to N (inclusive). A middle asterisk means all types from m to n (inclusive). diff --git a/doc/src/improper_coeff.rst b/doc/src/improper_coeff.rst index c7a79571a4..f0f1d48f2c 100644 --- a/doc/src/improper_coeff.rst +++ b/doc/src/improper_coeff.rst @@ -10,7 +10,7 @@ Syntax improper_coeff N args -* N = improper type (see asterisk form below) +* N = numeric improper type (see asterisk form below), or type label * args = coefficients for one or more improper types Examples @@ -32,13 +32,14 @@ file read by the :doc:`read_data ` command or in a restart file. N can be specified in one of two ways. An explicit numeric value can -be used, as in the first example above. Or a wild-card asterisk can be -used to set the coefficients for multiple improper types. This takes -the form "\*" or "\*n" or "n\*" or "m\*n". If N = the number of improper -types, then an asterisk with no numeric values means all types from 1 -to N. A leading asterisk means all types from 1 to n (inclusive). A -trailing asterisk means all types from n to N (inclusive). A middle -asterisk means all types from m to n (inclusive). +be used, as in the first example above. Or N can be a :doc:`type label `. +For numeric values only, a wild-card asterisk can be used to set the +coefficients for multiple improper types. This takes the form "\*" or +"\*n" or "n\*" or "m\*n". If N = the number of improper types, then +an asterisk with no numeric values means all types from 1 to N. A +leading asterisk means all types from 1 to n (inclusive). A trailing +asterisk means all types from n to N (inclusive). A middle asterisk +means all types from m to n (inclusive). Note that using an improper_coeff command can override a previous setting for the same improper type. For example, these commands set diff --git a/doc/src/pair_coeff.rst b/doc/src/pair_coeff.rst index ea62d839ab..6395ed889a 100644 --- a/doc/src/pair_coeff.rst +++ b/doc/src/pair_coeff.rst @@ -10,7 +10,7 @@ Syntax pair_coeff I J args -* I,J = atom types (see asterisk form below) +* I,J = numeric atom types (see asterisk form below), or type labels * args = coefficients for one or more pairs of atom types Examples @@ -34,20 +34,22 @@ atom types. The number and meaning of the coefficients depends on the pair style. Pair coefficients can also be set in the data file read by the :doc:`read_data ` command or in a restart file. -I and J can be specified in one of two ways. Explicit numeric values -can be used for each, as in the first example above. I <= J is -required. LAMMPS sets the coefficients for the symmetric J,I -interaction to the same values. +I and J can be specified in one of several ways. Explicit numeric +values can be used for each, as in the first example above. Or, one +or both of the types in the I,J pair may be a :doc:`type label `. +LAMMPS sets the coefficients for the symmetric J,I interaction to the +same values. -A wildcard asterisk can be used in place of or in conjunction with the -I,J arguments to set the coefficients for multiple pairs of atom -types. This takes the form "\*" or "\*n" or "n\*" or "m\*n". If N = the -number of atom types, then an asterisk with no numeric values means all -types from 1 to N. A leading asterisk means all types from 1 to n -(inclusive). A trailing asterisk means all types from n to N -(inclusive). A middle asterisk means all types from m to n -(inclusive). Note that only type pairs with I <= J are considered; if -asterisks imply type pairs where J < I, they are ignored. +For numeric values only, a wildcard asterisk can be used in place of +or in conjunction with the I,J arguments to set the coefficients for +multiple pairs of atom types. This takes the form "\*" or "\*n" or +"n\*" or "m\*n". If N = the number of atom types, then an asterisk +with no numeric values means all types from 1 to N. A leading +asterisk means all types from 1 to n (inclusive). A trailing asterisk +means all types from n to N (inclusive). A middle asterisk means all +types from m to n (inclusive). Note that only type pairs with I <= J +are considered; if asterisks imply type pairs where J < I, they are +ignored. Note that a pair_coeff command can override a previous setting for the same I,J pair. For example, these commands set the coeffs for all I,J diff --git a/doc/src/read_data.rst b/doc/src/read_data.rst index 3e32a96c53..847b44057d 100755 --- a/doc/src/read_data.rst +++ b/doc/src/read_data.rst @@ -540,7 +540,13 @@ input script. .. parsed-literal:: ID = angle type (1-N) - label = alphanumeric type label (see the :doc:`labelmap ` command) + label = alphanumeric type label + +See the *Atom Type Labels* section for more details about how angle +types are interpreted when reading one or more data files that contain +angle type label sections. See the :doc:`labelmap ` command +for a discussion about how to format angle type labels and use type +label maps. ---------- @@ -612,8 +618,28 @@ integers (1, not 1.0). .. parsed-literal:: - ID = atom type (1-N) - label = alphanumeric type label (see the :doc:`labelmap ` command) + ID = numeric atom type (1-N) + label = alphanumeric type label + +Type labels can be used to make data files more general, by defining +atom, bond, etc. types in terms of user-provided strings instead of +numbers. If a type label section exists for a given interaction, the +numeric types listed in the *Atoms*, *Bonds*, etc. section are first +converted into their corresponding type label before being read into +LAMMPS; type labels cannot be directly substituted for numeric types +used in data files. Data files can also be used to populate the +default label map; if the type label does not already exist, the type +label is created as a new type and assigned to the default label map. +The corresponding interaction coefficients listed in the data file are +associated to this type. When reading multiple data files, or if the +default label map already exists, there must be enough space in the +per-type data arrays to create new types; see the *extra/atom/types* +keyword for how to reserve extra space for new types. Note that, in +this case, the numeric-to-label mapping within a data file does not +necessary correspond to that of the simulation; the :doc:`write_data ` +command can be used to print out the default label map at a given +point in a simulation. See the :doc:`labelmap ` command for +more discussion on how to use type label maps. ---------- @@ -950,7 +976,13 @@ script. .. parsed-literal:: ID = bond type (1-N) - label = alphanumeric type label (see the :doc:`labelmap ` command) + label = alphanumeric type label + +See the *Atom Type Labels* section for more details about how bond +types are interpreted when reading one or more data files that contain +bond type label sections. See the :doc:`labelmap ` command +for a discussion about how to format bond type labels and use type +label maps. ---------- @@ -1044,7 +1076,13 @@ Coefficients can also be set via the .. parsed-literal:: ID = dihedral type (1-N) - label = alphanumeric type label (see the :doc:`labelmap ` command) + label = alphanumeric type label + +See the *Atom Type Labels* section for more details about how dihedral +types are interpreted when reading one or more data files that contain +dihedral type label sections. See the :doc:`labelmap ` +command for a discussion about how to format dihedral type labels and +use type label maps. ---------- @@ -1157,7 +1195,13 @@ Coefficients can also be set via the .. parsed-literal:: ID = improper type (1-N) - label = alphanumeric type label (see the :doc:`labelmap ` command) + label = alphanumeric type label + +See the *Atom Type Labels* section for more details about how improper +types are interpreted when reading one or more data files that contain +improper type label sections. See the :doc:`labelmap ` +command for a discussion about how to format improper type labels and +use type label maps. ---------- diff --git a/doc/src/variable.rst b/doc/src/variable.rst index ea6b7ef8ec..fe07f3672f 100644 --- a/doc/src/variable.rst +++ b/doc/src/variable.rst @@ -66,6 +66,7 @@ Syntax angmom(group,dim,region), torque(group,dim,region), inertia(group,dimdim,region), omega(group,dim,region) special functions = sum(x), min(x), max(x), ave(x), trap(x), slope(x), gmask(x), rmask(x), grmask(x,y), next(x) + labelmap functions = label(typelabel), blabel(typelabel), alabel(typelabel), dlabel(typelabel), ilabel(typelabel) feature functions = is_active(category,feature,exact), is_defined(category,id,exact) atom value = id[i], mass[i], type[i], mol[i], x[i], y[i], z[i], vx[i], vy[i], vz[i], fx[i], fy[i], fz[i], q[i] atom vector = id, mass, type, mol, x, y, z, vx, vy, vz, fx, fy, fz, q @@ -481,6 +482,8 @@ references, and references to other variables. +--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Special functions | sum(x), min(x), max(x), ave(x), trap(x), slope(x), gmask(x), rmask(x), grmask(x,y), next(x) | +--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| Labelmap functions | label(typelabel), blabel(typelabel), alabel(typelabel), dlabel(typelabel), ilabel(typelabel) | ++--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Atom values | id[i], mass[i], type[i], mol[i], x[i], y[i], z[i], vx[i], vy[i], vz[i], fx[i], fy[i], fz[i], q[i] | +--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Atom vectors | id, mass, type, mol, x, y, z, vx, vy, vz, fx, fy, fz, q | @@ -901,6 +904,18 @@ operates. ---------- +Labelmap Functions +----------------- + +Labelmap functions convert type labels into numeric types, using label +maps created by the :doc:`labelmap ` or :doc:`read_data ` +commands. Their argument must be a valid type label, and they return +the corresponding integer numeric type. The argument for the *label()*\ , +*blabel()*\ , *alabel()*\ , *dlabel()*\ , and *ilabel()*\ , must be +an atom, bond, angle, dihedral, or improper type label, respectively. + +---------- + Feature Functions ----------------- diff --git a/src/input.cpp b/src/input.cpp index a260d01ef2..a9c8685c2f 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -1753,6 +1753,22 @@ void Input::pair_coeff() error->all(FLERR,"Pair_coeff command before pair_style is defined"); readtype(arg[0],atom->ATOM); readtype(arg[1],atom->ATOM); + + // if arg[1] < arg[0], and neither contain a wildcard, reorder + + int itype,jtype; + int *ptr; + char *str; + if (strchr(arg[0],'*') == nullptr && strchr(arg[1],'*') == nullptr) { + itype = utils::numeric(FLERR,arg[0],false,lmp); + jtype = utils::numeric(FLERR,arg[1],false,lmp); + if (jtype < itype) { + str = arg[0]; + arg[0] = arg[1]; + arg[1] = str; + } + } + force->pair->coeff(narg,arg); } diff --git a/src/label_map.cpp b/src/label_map.cpp index e8ce7ecfc7..4c9e5724e9 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -106,7 +106,7 @@ void LabelMap::modify_lmap(int narg, char **arg) itype = utils::inumeric(FLERR,arg[iarg++],false,lmp); charlabel = arg[iarg++]; if (itype > ntypes) error->all(FLERR,"Topology type exceeds system topology type"); - if (!isalpha(charlabel[0])) error->all(FLERR,"Type labels must begin with a letter"); + if (isdigit(charlabel[0])) error->all(FLERR,"Type labels must begin with a letter"); (*labels)[itype-1] = charlabel; } } From b92adfaf6f39da5f1c5daf7defedbd09f74f6c19 Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sun, 31 Jan 2021 14:59:10 -0500 Subject: [PATCH 045/392] pointer and style issues --- src/input.cpp | 40 +++++++++++++++++++++++++++------------- src/input.h | 2 +- src/label_map.cpp | 30 +++++++++++++++--------------- src/molecule.cpp | 10 +++++----- src/read_data.cpp | 10 +++++----- src/variable.cpp | 10 +++++----- 6 files changed, 58 insertions(+), 44 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index a9c8685c2f..5965cc907a 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -662,16 +662,17 @@ void Input::substitute(char *&str, char *&str2, int &max, int &max2, int flag) /* ---------------------------------------------------------------------- substitute type labels with numeric value reallocate str to hold expanded version if necessary - if type is a valid numerical string (can include *), do not modify + return flag if new pointer, caller will need to delete [] + if type is a valid numerical string (can include '*'), do not modify ------------------------------------------------------------------------- */ -void Input::readtype(char *&str, int mode) +int Input::readtype(char *&str, int mode) { int numflag = 1; int n = strlen(str); for (int i = 0; i < n; i++) if (!isdigit(str[i]) && str[i] != '*') numflag = 0; - if (numflag) return; + if (numflag) return 0; if (!atom->labelmapflag) error->all(FLERR,fmt::format("Invalid type {}",str)); int type,max,max2; @@ -685,8 +686,13 @@ void Input::readtype(char *&str, int mode) max = strlen(str) + 1; max2 = strlen(typechar) + 1; - if (max2 > max) reallocate(str,max,max2); - strcpy(str,typechar); + if (max2 > max) { + str = new char[max2]; + strcpy(str,typechar); + return 1; + } else strcpy(str,typechar); + + return 0; } /* ---------------------------------------------------------------------- @@ -1333,8 +1339,9 @@ void Input::angle_coeff() error->all(FLERR,"Angle_coeff command before angle_style is defined"); if (atom->avec->angles_allow == 0) error->all(FLERR,"Angle_coeff command when no angles allowed"); - readtype(arg[0],atom->ANGLE); + int newflag = readtype(arg[0],Atom::ANGLE); force->angle->coeff(narg,arg); + if (newflag) delete [] arg[0]; } /* ---------------------------------------------------------------------- */ @@ -1375,8 +1382,9 @@ void Input::bond_coeff() error->all(FLERR,"Bond_coeff command before bond_style is defined"); if (atom->avec->bonds_allow == 0) error->all(FLERR,"Bond_coeff command when no bonds allowed"); - readtype(arg[0],atom->BOND); + int newflag = readtype(arg[0],Atom::BOND); force->bond->coeff(narg,arg); + if (newflag) delete [] arg[0]; } /* ---------------------------------------------------------------------- */ @@ -1479,8 +1487,9 @@ void Input::dihedral_coeff() error->all(FLERR,"Dihedral_coeff command before dihedral_style is defined"); if (atom->avec->dihedrals_allow == 0) error->all(FLERR,"Dihedral_coeff command when no dihedrals allowed"); - readtype(arg[0],atom->DIHEDRAL); + int newflag = readtype(arg[0],Atom::DIHEDRAL); force->dihedral->coeff(narg,arg); + if (newflag) delete [] arg[0]; } /* ---------------------------------------------------------------------- */ @@ -1557,8 +1566,9 @@ void Input::improper_coeff() error->all(FLERR,"Improper_coeff command before improper_style is defined"); if (atom->avec->impropers_allow == 0) error->all(FLERR,"Improper_coeff command when no impropers allowed"); - readtype(arg[0],atom->IMPROPER); + int newflag = readtype(arg[0],Atom::IMPROPER); force->improper->coeff(narg,arg); + if (newflag) delete [] arg[0]; } /* ---------------------------------------------------------------------- */ @@ -1751,13 +1761,12 @@ void Input::pair_coeff() error->all(FLERR,"Pair_coeff command before simulation box is defined"); if (force->pair == nullptr) error->all(FLERR,"Pair_coeff command before pair_style is defined"); - readtype(arg[0],atom->ATOM); - readtype(arg[1],atom->ATOM); + int newflag0 = readtype(arg[0],Atom::ATOM); + int newflag1 = readtype(arg[1],Atom::ATOM); // if arg[1] < arg[0], and neither contain a wildcard, reorder - int itype,jtype; - int *ptr; + int tmpflag,itype,jtype; char *str; if (strchr(arg[0],'*') == nullptr && strchr(arg[1],'*') == nullptr) { itype = utils::numeric(FLERR,arg[0],false,lmp); @@ -1766,10 +1775,15 @@ void Input::pair_coeff() str = arg[0]; arg[0] = arg[1]; arg[1] = str; + tmpflag = newflag0; + newflag0 = newflag1; + newflag1 = tmpflag; } } force->pair->coeff(narg,arg); + if (newflag0) delete [] arg[0]; + if (newflag1) delete [] arg[1]; } /* ---------------------------------------------------------------------- */ diff --git a/src/input.h b/src/input.h index a5a4b2b341..a216437978 100755 --- a/src/input.h +++ b/src/input.h @@ -38,7 +38,7 @@ class Input : protected Pointers { char *one(const std::string&); // process a single command void substitute(char *&, char *&, int &, int &, int); // substitute for variables in a string - void readtype(char *&, int); // substitute type label with numeric type + int readtype(char *&, int); // substitute type label with numeric type void write_echo(const std::string &); // send text to active echo file pointers protected: diff --git a/src/label_map.cpp b/src/label_map.cpp index 4c9e5724e9..438c0172e4 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -119,23 +119,23 @@ void LabelMap::modify_lmap(int narg, char **arg) void LabelMap::merge_lmap(LabelMap *lmap2, int mode) { - if (mode == atom->ATOM) + if (mode == Atom::ATOM) for (int i = 0; i < lmap2->natomtypes; i++) find_or_create(lmap2->typelabel[i],typelabel,natomtypes); - if (mode == atom->BOND) + if (mode == Atom::BOND) for (int i = 0; i < lmap2->nbondtypes; i++) find_or_create(lmap2->btypelabel[i],btypelabel,nbondtypes); - if (mode == atom->ANGLE) + if (mode == Atom::ANGLE) for (int i = 0; i < lmap2->nangletypes; i++) find_or_create(lmap2->atypelabel[i],atypelabel,nangletypes); - if (mode == atom->DIHEDRAL) + if (mode == Atom::DIHEDRAL) for (int i = 0; i < lmap2->ndihedraltypes; i++) find_or_create(lmap2->dtypelabel[i],dtypelabel,ndihedraltypes); - if (mode == atom->IMPROPER) + if (mode == Atom::IMPROPER) for (int i = 0; i < lmap2->nimpropertypes; i++) find_or_create(lmap2->itypelabel[i],itypelabel,nimpropertypes); } @@ -147,27 +147,27 @@ void LabelMap::merge_lmap(LabelMap *lmap2, int mode) void LabelMap::create_lmap2lmap(LabelMap *lmap2, int mode) { - if (mode == atom->ATOM) + if (mode == Atom::ATOM) for (int i = 0; i < natomtypes; i++) lmap2lmap.atom[i] = search(typelabel[i],lmap2->typelabel, lmap2->natomtypes); - if (mode == atom->BOND) + if (mode == Atom::BOND) for (int i = 0; i < nbondtypes; i++) lmap2lmap.bond[i] = search(btypelabel[i],lmap2->btypelabel, lmap2->nbondtypes); - if (mode == atom->ANGLE) + if (mode == Atom::ANGLE) for (int i = 0; i < nangletypes; i++) lmap2lmap.angle[i] = search(atypelabel[i],lmap2->atypelabel, lmap2->nangletypes); - if (mode == atom->DIHEDRAL) + if (mode == Atom::DIHEDRAL) for (int i = 0; i < ndihedraltypes; i++) lmap2lmap.dihedral[i] = search(dtypelabel[i],lmap2->dtypelabel, lmap2->ndihedraltypes); - if (mode == atom->IMPROPER) + if (mode == Atom::IMPROPER) for (int i = 0; i < nimpropertypes; i++) lmap2lmap.improper[i] = search(itypelabel[i],lmap2->itypelabel, lmap2->nimpropertypes); @@ -206,19 +206,19 @@ int LabelMap::find_or_create(std::string mylabel, std::vector &labe int LabelMap::find(std::string mylabel, int mode) { - if (mode == atom->ATOM) + if (mode == Atom::ATOM) return search(mylabel,typelabel,natomtypes); - if (mode == atom->BOND) + if (mode == Atom::BOND) return search(mylabel,btypelabel,nbondtypes); - if (mode == atom->ANGLE) + if (mode == Atom::ANGLE) return search(mylabel,atypelabel,nangletypes); - if (mode == atom->DIHEDRAL) + if (mode == Atom::DIHEDRAL) return search(mylabel,dtypelabel,ndihedraltypes); - if (mode == atom->IMPROPER) + if (mode == Atom::IMPROPER) return search(mylabel,itypelabel,nimpropertypes); return -1; diff --git a/src/molecule.cpp b/src/molecule.cpp index 0bec25e183..22bb0ac0e4 100755 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -728,7 +728,7 @@ void Molecule::types(char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Types section in molecule file"); - type[iatom] = atom->find_label(typestr,atom->ATOM); + type[iatom] = atom->find_label(typestr,Atom::ATOM); if (type[iatom] == -1) error->one(FLERR,"Invalid Types section in molecule file"); } else type[iatom] = utils::inumeric(FLERR,typestr.c_str(),false,lmp); type[iatom] += toffset; @@ -941,7 +941,7 @@ void Molecule::bonds(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Bonds section in molecule file"); - itype = atom->find_label(typestr,atom->BOND); + itype = atom->find_label(typestr,Atom::BOND); if (itype == -1) error->one(FLERR,"Invalid Bonds section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1015,7 +1015,7 @@ void Molecule::angles(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Angles section in molecule file"); - itype = atom->find_label(typestr,atom->ANGLE); + itype = atom->find_label(typestr,Atom::ANGLE); if (itype == -1) error->one(FLERR,"Invalid Angles section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1105,7 +1105,7 @@ void Molecule::dihedrals(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Dihedrals section in molecule file"); - itype = atom->find_label(typestr,atom->DIHEDRAL); + itype = atom->find_label(typestr,Atom::DIHEDRAL); if (itype == -1) error->one(FLERR,"Invalid Dihedrals section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); @@ -1210,7 +1210,7 @@ void Molecule::impropers(int flag, char *line) typestr = values.next_string(); if (!isdigit(typestr[0])) { if (!atom->labelmapflag) error->one(FLERR,"Invalid Impropers section in molecule file"); - itype = atom->find_label(typestr,atom->IMPROPER); + itype = atom->find_label(typestr,Atom::IMPROPER); if (itype == -1) error->one(FLERR,"Invalid Impropers section in molecule file"); } else itype = utils::inumeric(FLERR,typestr.c_str(),false,lmp); atom1 = values.next_tagint(); diff --git a/src/read_data.cpp b/src/read_data.cpp index 35c4ebb49b..276379972d 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -729,7 +729,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (atomflag == 1) error->all(FLERR,"Must read Atom Type Labels before Atoms"); - typelabels(lmap->typelabel,ntypes,atom->ATOM); + typelabels(lmap->typelabel,ntypes,Atom::ATOM); } else skip_lines(ntypes); } else if (strcmp(keyword,"Bond Type Labels") == 0) { @@ -737,7 +737,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (bondflag == 1) error->all(FLERR,"Must read Bond Type Labels before Bonds"); - typelabels(lmap->btypelabel,nbondtypes,atom->BOND); + typelabels(lmap->btypelabel,nbondtypes,Atom::BOND); } else skip_lines(nbondtypes); } @@ -746,7 +746,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (angleflag == 1) error->all(FLERR,"Must read Angle Type Labels before Angles"); - typelabels(lmap->atypelabel,nangletypes,atom->ANGLE); + typelabels(lmap->atypelabel,nangletypes,Atom::ANGLE); } else skip_lines(nangletypes); } @@ -755,7 +755,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (dihedralflag == 1) error->all(FLERR,"Must read Dihedral Type Labels before Dihedrals"); - typelabels(lmap->dtypelabel,ndihedraltypes,atom->DIHEDRAL); + typelabels(lmap->dtypelabel,ndihedraltypes,Atom::DIHEDRAL); } else skip_lines(ndihedraltypes); } @@ -764,7 +764,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (improperflag == 1) error->all(FLERR,"Must read Improper Type Labels before Impropers"); - typelabels(lmap->itypelabel,nimpropertypes,atom->IMPROPER); + typelabels(lmap->itypelabel,nimpropertypes,Atom::IMPROPER); } else skip_lines(nimpropertypes); } diff --git a/src/variable.cpp b/src/variable.cpp index ddc5365caa..47feaa5acf 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -4540,19 +4540,19 @@ int Variable::labelmap_function(char *word, char *contents, Tree **tree, std::string typestr = contents; if (strcmp(word,"label") == 0) { - value = atom->find_label(typestr,atom->ATOM); + value = atom->find_label(typestr,Atom::ATOM); } else if (strcmp(word,"blabel") == 0) { - value = atom->find_label(typestr,atom->BOND); + value = atom->find_label(typestr,Atom::BOND); } else if (strcmp(word,"alabel") == 0) { - value = atom->find_label(typestr,atom->ANGLE); + value = atom->find_label(typestr,Atom::ANGLE); } else if (strcmp(word,"dlabel") == 0) { - value = atom->find_label(typestr,atom->DIHEDRAL); + value = atom->find_label(typestr,Atom::DIHEDRAL); } else if (strcmp(word,"ilabel") == 0) { - value = atom->find_label(typestr,atom->IMPROPER); + value = atom->find_label(typestr,Atom::IMPROPER); } if (value == -1) From 4f219a94aadaf555bee38fecbc528307ec85278f Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sun, 31 Jan 2021 16:37:09 -0500 Subject: [PATCH 046/392] nolabel for write_data also bug fixes --- doc/src/labelmap.rst | 3 ++- doc/src/variable.rst | 5 +++-- doc/src/write_data.rst | 7 ++++++- src/input.cpp | 2 +- src/label_map.cpp | 2 +- src/read_data.cpp | 2 +- src/write_data.cpp | 6 +++++- src/write_data.h | 1 + 8 files changed, 20 insertions(+), 8 deletions(-) diff --git a/doc/src/labelmap.rst b/doc/src/labelmap.rst index 7d9ec89166..4fd67798b2 100755 --- a/doc/src/labelmap.rst +++ b/doc/src/labelmap.rst @@ -46,7 +46,8 @@ Type Label sections. If substituting numeric types with type labels is currently supported by a given command, this feature will be mentioned on that command's doc page. Or, for input script commands, type labels - can be processed using :doc:`variable ` syntax. + can be processed using :doc:`variable ` syntax using + labelmap functions. .. note:: diff --git a/doc/src/variable.rst b/doc/src/variable.rst index fe07f3672f..19438aa0e5 100644 --- a/doc/src/variable.rst +++ b/doc/src/variable.rst @@ -911,8 +911,9 @@ Labelmap functions convert type labels into numeric types, using label maps created by the :doc:`labelmap ` or :doc:`read_data ` commands. Their argument must be a valid type label, and they return the corresponding integer numeric type. The argument for the *label()*\ , -*blabel()*\ , *alabel()*\ , *dlabel()*\ , and *ilabel()*\ , must be -an atom, bond, angle, dihedral, or improper type label, respectively. +*blabel()*\ , *alabel()*\ , *dlabel()*\ , and *ilabel()* functions, +must be an atom, bond, angle, dihedral, or improper type label, +respectively. ---------- diff --git a/doc/src/write_data.rst b/doc/src/write_data.rst index 0aa26f8bbf..3e52322111 100755 --- a/doc/src/write_data.rst +++ b/doc/src/write_data.rst @@ -12,12 +12,13 @@ Syntax * file = name of data file to write out * zero or more keyword/value pairs may be appended -* keyword = *pair* or *nocoeff* +* keyword = *pair* or *nocoeff* or *nofix* or *nolabelmap* .. parsed-literal:: *nocoeff* = do not write out force field info *nofix* = do not write out extra sections read by fixes + *nolabelmap* = do not write out the default label map *pair* value = *ii* or *ij* *ii* = write one line of pair coefficient info per atom type *ij* = write one line of pair coefficient info per IJ atom type pair @@ -105,6 +106,10 @@ should be written to the data file (see the *fix* option of the option excludes sections for user-created per-atom properties from :doc:`fix property/atom `. +The *nolabelmap* keyword requests that the default label map should +not be written to the data file (see the Type Label sections of +:doc:`read_data ` command for details). + The *pair* keyword lets you specify in what format the pair coefficient information is written into the data file. If the value is specified as *ii*\ , then one line per atom type is written, to diff --git a/src/input.cpp b/src/input.cpp index 5965cc907a..bf8faa8856 100755 --- a/src/input.cpp +++ b/src/input.cpp @@ -1616,7 +1616,7 @@ void Input::labelmap() ilmap = atom->find_labelmap(mapid); if (ilmap == -1) ilmap = atom->add_label_map(mapid); if (narg > i+2) error->all(FLERR,"Illegal labelmap command"); - narg = i - 2; + narg = narg - 2; break; } i++; diff --git a/src/label_map.cpp b/src/label_map.cpp index 438c0172e4..0096105e7b 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -106,7 +106,7 @@ void LabelMap::modify_lmap(int narg, char **arg) itype = utils::inumeric(FLERR,arg[iarg++],false,lmp); charlabel = arg[iarg++]; if (itype > ntypes) error->all(FLERR,"Topology type exceeds system topology type"); - if (isdigit(charlabel[0])) error->all(FLERR,"Type labels must begin with a letter"); + if (isdigit(charlabel[0])) error->all(FLERR,"Type labels cannot start with a number"); (*labels)[itype-1] = charlabel; } } diff --git a/src/read_data.cpp b/src/read_data.cpp index 276379972d..06f7dfa1fd 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -1984,7 +1984,7 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i next = strchr(buf,'\n'); *next = '\0'; sscanf(buf,"%*d %s",typelabel); - if (!isalpha(typelabel[0])) error->all(FLERR,"Type labels must begin with a letter"); + if (isdigit(typelabel[0])) error->all(FLERR,"Type labels cannot start with a number"); mytypelabel[i] = typelabel; buf = next + 1; } diff --git a/src/write_data.cpp b/src/write_data.cpp index 4a94f12500..737320dc7f 100755 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -72,6 +72,7 @@ void WriteData::command(int narg, char **arg) pairflag = II; coeffflag = 1; fixflag = 1; + lmapflag = 1; int noinit = 0; int iarg = 1; @@ -91,6 +92,9 @@ void WriteData::command(int narg, char **arg) } else if (strcmp(arg[iarg],"nofix") == 0) { fixflag = 0; iarg++; + } else if (strcmp(arg[iarg],"nolabelmap") == 0) { + lmapflag = 0; + iarg++; } else error->all(FLERR,"Illegal write_data command"); } @@ -186,7 +190,7 @@ void WriteData::write(const std::string &file) if (me == 0) { header(); - if (atom->labelmapflag) atom->lmaps[0]->write_data(fp); + if (lmapflag && atom->labelmapflag) atom->lmaps[0]->write_data(fp); type_arrays(); if (coeffflag) force_fields(); } diff --git a/src/write_data.h b/src/write_data.h index a4e71c9cda..19b544c84d 100755 --- a/src/write_data.h +++ b/src/write_data.h @@ -35,6 +35,7 @@ class WriteData : protected Pointers { int pairflag; int coeffflag; int fixflag; + int lmapflag; FILE *fp; bigint nbonds_local,nbonds; bigint nangles_local,nangles; From ffa46ad95184dab5bfbc0dfe553cee14ffb5372a Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sun, 31 Jan 2021 20:44:19 -0500 Subject: [PATCH 047/392] preempt some read/write data file bugs currently, require all type labels (for all interactions) to be defined, if any are, when reading data files --- doc/src/read_data.rst | 31 +++++++++++++++++-------------- doc/src/write_data.rst | 4 +++- src/label_map.cpp | 34 ++++++++++++++++++++++++++++++++++ src/label_map.h | 1 + src/read_data.cpp | 25 ++++++++++++++++++++++++- 5 files changed, 79 insertions(+), 16 deletions(-) diff --git a/doc/src/read_data.rst b/doc/src/read_data.rst index 847b44057d..16c98794a1 100755 --- a/doc/src/read_data.rst +++ b/doc/src/read_data.rst @@ -623,20 +623,23 @@ integers (1, not 1.0). Type labels can be used to make data files more general, by defining atom, bond, etc. types in terms of user-provided strings instead of -numbers. If a type label section exists for a given interaction, the -numeric types listed in the *Atoms*, *Bonds*, etc. section are first -converted into their corresponding type label before being read into -LAMMPS; type labels cannot be directly substituted for numeric types -used in data files. Data files can also be used to populate the -default label map; if the type label does not already exist, the type -label is created as a new type and assigned to the default label map. -The corresponding interaction coefficients listed in the data file are -associated to this type. When reading multiple data files, or if the -default label map already exists, there must be enough space in the -per-type data arrays to create new types; see the *extra/atom/types* -keyword for how to reserve extra space for new types. Note that, in -this case, the numeric-to-label mapping within a data file does not -necessary correspond to that of the simulation; the :doc:`write_data ` +numbers. If a type label section exists for any one interaction +(atom, bond, angle, dihedral or improper), then all types must be +assigned a type label for all interactions. All type label sections +must come before any section that includes types. The numeric types +listed in the *Atoms*, *Bonds*, etc. section are first converted into +their corresponding type label before being read into LAMMPS; type +labels cannot be directly substituted for numeric types used in data +files. Data files assign all types to the default label map; if the +type label does not already exist, the type label is created as a new +type and assigned to the default label map. The corresponding +interaction coefficients listed in the data file are associated to +this type. There must be enough space in the per-type data +arrays to create new types; see the *extra/atom/types* keyword for how +to reserve extra space for new types, e.g., when reading multiple data +files. Note that, in this case, the numeric-to-label mapping within a +data file does not necessary correspond to that of the simulation; +once the default label map is fully defined, the :doc:`write_data ` command can be used to print out the default label map at a given point in a simulation. See the :doc:`labelmap ` command for more discussion on how to use type label maps. diff --git a/doc/src/write_data.rst b/doc/src/write_data.rst index 3e52322111..e6edd1d36a 100755 --- a/doc/src/write_data.rst +++ b/doc/src/write_data.rst @@ -108,7 +108,9 @@ from :doc:`fix property/atom `. The *nolabelmap* keyword requests that the default label map should not be written to the data file (see the Type Label sections of -:doc:`read_data ` command for details). +:doc:`read_data ` command for details). By default, if the +default label map is fully defined, i.e. every atom, bond, etc. type +has an associated type label, it is written to the data file. The *pair* keyword lets you specify in what format the pair coefficient information is written into the data file. If the value diff --git a/src/label_map.cpp b/src/label_map.cpp index 0096105e7b..b7a8479737 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -237,12 +237,46 @@ int LabelMap::search(std::string mylabel, std::vector labels, int n return -1; } +/* ---------------------------------------------------------------------- + check if all types have been assigned a type label +------------------------------------------------------------------------- */ + +int LabelMap::is_complete() +{ + for (int i = 0; i < natomtypes; i++) + if (typelabel[i].empty()) return 0; + + if (force->bond) + for (int i = 0; i < nbondtypes; i++) + if (btypelabel[i].empty()) return 0; + + if (force->angle) + for (int i = 0; i < nangletypes; i++) + if (atypelabel[i].empty()) return 0; + + if (force->dihedral) + for (int i = 0; i < ndihedraltypes; i++) + if (dtypelabel[i].empty()) return 0; + + if (force->improper) + for (int i = 0; i < nimpropertypes; i++) + if (itypelabel[i].empty()) return 0; + + return 1; +} + /* ---------------------------------------------------------------------- proc 0 writes to data file ------------------------------------------------------------------------- */ void LabelMap::write_data(FILE *fp) { + if (!is_complete()) { + error->warning(FLERR,"Default label map is incomplete. " + "Assign all type labels to write to data file."); + return; + } + fmt::print(fp,"\nAtom Type Labels\n\n"); for (int i = 0; i < natomtypes; i++) fmt::print(fp,"{} {}\n",i+1,typelabel[i]); diff --git a/src/label_map.h b/src/label_map.h index 402fd210f5..5553402e9b 100755 --- a/src/label_map.h +++ b/src/label_map.h @@ -48,6 +48,7 @@ class LabelMap : protected Pointers { int find_or_create(std::string, std::vector &, int); // look up type or create new type int find(std::string, int); // find numeric type of type label int search(std::string, std::vector, int); // look up type index + int is_complete(); // check if all types are assigned // input/output for atom class label map diff --git a/src/read_data.cpp b/src/read_data.cpp index 06f7dfa1fd..f444012403 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -1279,6 +1279,9 @@ void ReadData::atoms() nchunk = MIN(natoms-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (labelflag && !lmap->is_complete()) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); atom->data_atoms(nchunk,buffer,id_offset,mol_offset,toffset, shiftflag,shift,labelflag,lmap->lmap2lmap.atom); nread += nchunk; @@ -1378,6 +1381,9 @@ void ReadData::bonds(int firstpass) nchunk = MIN(nbonds-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (labelflag && !lmap->is_complete()) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); atom->data_bonds(nchunk,buffer,count,id_offset,boffset, labelflag,lmap->lmap2lmap.bond); nread += nchunk; @@ -1453,6 +1459,9 @@ void ReadData::angles(int firstpass) nchunk = MIN(nangles-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (labelflag && !lmap->is_complete()) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); atom->data_angles(nchunk,buffer,count,id_offset,aoffset, labelflag,lmap->lmap2lmap.angle); nread += nchunk; @@ -1528,6 +1537,9 @@ void ReadData::dihedrals(int firstpass) nchunk = MIN(ndihedrals-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (labelflag && !lmap->is_complete()) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); atom->data_dihedrals(nchunk,buffer,count,id_offset,doffset, labelflag,lmap->lmap2lmap.dihedral); nread += nchunk; @@ -1603,6 +1615,9 @@ void ReadData::impropers(int firstpass) nchunk = MIN(nimpropers-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (labelflag && !lmap->is_complete()) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); atom->data_impropers(nchunk,buffer,count,id_offset,ioffset, labelflag,lmap->lmap2lmap.improper); nread += nchunk; @@ -1798,6 +1813,9 @@ void ReadData::mass() int eof = comm->read_lines_from_file(fp,ntypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (labelflag && !lmap->is_complete()) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); char *original = buf; for (int i = 0; i < ntypes; i++) { @@ -1983,7 +2001,8 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i for (int i = 0; i < myntypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - sscanf(buf,"%*d %s",typelabel); + int rv = sscanf(buf,"%*d %s",typelabel); + if (rv != 1) error->all(FLERR,"Invalid data file section: Type Labels"); if (isdigit(typelabel[0])) error->all(FLERR,"Type labels cannot start with a number"); mytypelabel[i] = typelabel; buf = next + 1; @@ -2164,6 +2183,10 @@ void ReadData::skip_lines(bigint n) void ReadData::parse_coeffs(char *line, const char *addstr, int dupflag, int noffset, int offset, int *ilabel) { + if (labelflag && !lmap->is_complete()) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); + settypeflag = 1; char *ptr; if ((ptr = strchr(line,'#'))) *ptr = '\0'; From e21c63192aca42727c904339446b7cd5ec57f83a Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sat, 20 Mar 2021 22:58:52 -0400 Subject: [PATCH 048/392] relax a requirement relax requirement that all labels for all interactions must be defined --- doc/src/read_data.rst | 6 +-- doc/src/write_data.rst | 6 ++- src/label_map.cpp | 31 ++++++------ src/label_map.h | 2 +- src/read_data.cpp | 108 ++++++++++++++++++++++++++++------------- src/read_data.h | 5 +- 6 files changed, 98 insertions(+), 60 deletions(-) diff --git a/doc/src/read_data.rst b/doc/src/read_data.rst index 16c98794a1..223b0ea6d8 100755 --- a/doc/src/read_data.rst +++ b/doc/src/read_data.rst @@ -623,10 +623,10 @@ integers (1, not 1.0). Type labels can be used to make data files more general, by defining atom, bond, etc. types in terms of user-provided strings instead of -numbers. If a type label section exists for any one interaction +numbers. If a type label section exists for a given interaction (atom, bond, angle, dihedral or improper), then all types must be -assigned a type label for all interactions. All type label sections -must come before any section that includes types. The numeric types +assigned a type label for that interaction. Type label sections must +come before any section that utilizes that type. The numeric types listed in the *Atoms*, *Bonds*, etc. section are first converted into their corresponding type label before being read into LAMMPS; type labels cannot be directly substituted for numeric types used in data diff --git a/doc/src/write_data.rst b/doc/src/write_data.rst index e6edd1d36a..6a0a532237 100755 --- a/doc/src/write_data.rst +++ b/doc/src/write_data.rst @@ -109,8 +109,10 @@ from :doc:`fix property/atom `. The *nolabelmap* keyword requests that the default label map should not be written to the data file (see the Type Label sections of :doc:`read_data ` command for details). By default, if the -default label map is fully defined, i.e. every atom, bond, etc. type -has an associated type label, it is written to the data file. +default label map is fully defined for a given interaction, i.e. every +atom, bond, angle, dihedral or improper type has an associated type +label, then a type label section for that interaction is written to +the data file. The *pair* keyword lets you specify in what format the pair coefficient information is written into the data file. If the value diff --git a/src/label_map.cpp b/src/label_map.cpp index b7a8479737..948521dbbb 100755 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -241,24 +241,25 @@ int LabelMap::search(std::string mylabel, std::vector labels, int n check if all types have been assigned a type label ------------------------------------------------------------------------- */ -int LabelMap::is_complete() +int LabelMap::is_complete(int mode) { + if (mode == Atom::ATOM) for (int i = 0; i < natomtypes; i++) if (typelabel[i].empty()) return 0; - if (force->bond) + if (force->bond && mode == Atom::BOND) for (int i = 0; i < nbondtypes; i++) if (btypelabel[i].empty()) return 0; - if (force->angle) + if (force->angle && mode == Atom::ANGLE) for (int i = 0; i < nangletypes; i++) if (atypelabel[i].empty()) return 0; - if (force->dihedral) + if (force->dihedral && mode == Atom::DIHEDRAL) for (int i = 0; i < ndihedraltypes; i++) if (dtypelabel[i].empty()) return 0; - if (force->improper) + if (force->improper && mode == Atom::IMPROPER) for (int i = 0; i < nimpropertypes; i++) if (itypelabel[i].empty()) return 0; @@ -271,35 +272,31 @@ int LabelMap::is_complete() void LabelMap::write_data(FILE *fp) { - if (!is_complete()) { - error->warning(FLERR,"Default label map is incomplete. " - "Assign all type labels to write to data file."); - return; + if (is_complete(Atom::ATOM)) { + fmt::print(fp,"\nAtom Type Labels\n\n"); + for (int i = 0; i < natomtypes; i++) + fmt::print(fp,"{} {}\n",i+1,typelabel[i]); } - fmt::print(fp,"\nAtom Type Labels\n\n"); - for (int i = 0; i < natomtypes; i++) - fmt::print(fp,"{} {}\n",i+1,typelabel[i]); - - if (force->bond) { + if (force->bond && is_complete(Atom::BOND)) { fmt::print(fp,"\nBond Type Labels\n\n"); for (int i = 0; i < nbondtypes; i++) fmt::print(fp,"{} {}\n",i+1,btypelabel[i]); } - if (force->angle) { + if (force->angle && is_complete(Atom::ANGLE)) { fmt::print(fp,"\nAngle Type Labels\n\n"); for (int i = 0; i < nangletypes; i++) fmt::print(fp,"{} {}\n",i+1,atypelabel[i]); } - if (force->dihedral) { + if (force->dihedral && is_complete(Atom::DIHEDRAL)) { fmt::print(fp,"\nDihedral Type Labels\n\n"); for (int i = 0; i < ndihedraltypes; i++) fmt::print(fp,"{} {}\n",i+1,dtypelabel[i]); } - if (force->improper) { + if (force->improper && is_complete(Atom::IMPROPER)) { fmt::print(fp,"\nImproper Type Labels\n\n"); for (int i = 0; i < nimpropertypes; i++) fmt::print(fp,"{} {}\n",i+1,itypelabel[i]); diff --git a/src/label_map.h b/src/label_map.h index 5553402e9b..d5a1d44c75 100755 --- a/src/label_map.h +++ b/src/label_map.h @@ -48,7 +48,7 @@ class LabelMap : protected Pointers { int find_or_create(std::string, std::vector &, int); // look up type or create new type int find(std::string, int); // find numeric type of type label int search(std::string, std::vector, int); // look up type index - int is_complete(); // check if all types are assigned + int is_complete(int); // check if all types are assigned // input/output for atom class label map diff --git a/src/read_data.cpp b/src/read_data.cpp index f444012403..ac5e97af1a 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -124,7 +124,8 @@ void ReadData::command(int narg, char **arg) addflag = NONE; coeffflag = 1; id_offset = mol_offset = 0; - offsetflag = shiftflag = settypeflag = labelflag = 0; + offsetflag = shiftflag = settypeflag = 0; + tlabelflag = blabelflag = alabelflag = dlabelflag = ilabelflag = 0; toffset = boffset = aoffset = doffset = ioffset = 0; shift[0] = shift[1] = shift[2] = 0.0; extra_atom_types = extra_bond_types = extra_angle_types = @@ -729,6 +730,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (atomflag == 1) error->all(FLERR,"Must read Atom Type Labels before Atoms"); + tlabelflag = 1; typelabels(lmap->typelabel,ntypes,Atom::ATOM); } else skip_lines(ntypes); @@ -737,6 +739,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (bondflag == 1) error->all(FLERR,"Must read Bond Type Labels before Bonds"); + blabelflag = 1; typelabels(lmap->btypelabel,nbondtypes,Atom::BOND); } else skip_lines(nbondtypes); } @@ -746,6 +749,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (angleflag == 1) error->all(FLERR,"Must read Angle Type Labels before Angles"); + alabelflag = 1; typelabels(lmap->atypelabel,nangletypes,Atom::ANGLE); } else skip_lines(nangletypes); } @@ -755,6 +759,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (dihedralflag == 1) error->all(FLERR,"Must read Dihedral Type Labels before Dihedrals"); + dlabelflag = 1; typelabels(lmap->dtypelabel,ndihedraltypes,Atom::DIHEDRAL); } else skip_lines(ndihedraltypes); } @@ -764,6 +769,7 @@ void ReadData::command(int narg, char **arg) if (firstpass) { if (improperflag == 1) error->all(FLERR,"Must read Improper Type Labels before Impropers"); + ilabelflag = 1; typelabels(lmap->itypelabel,nimpropertypes,Atom::IMPROPER); } else skip_lines(nimpropertypes); } @@ -1279,11 +1285,11 @@ void ReadData::atoms() nchunk = MIN(natoms-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); - if (labelflag && !lmap->is_complete()) + if (tlabelflag && !lmap->is_complete(Atom::ATOM)) error->all(FLERR,"Label map is incomplete. " "All types must be assigned a type label."); atom->data_atoms(nchunk,buffer,id_offset,mol_offset,toffset, - shiftflag,shift,labelflag,lmap->lmap2lmap.atom); + shiftflag,shift,tlabelflag,lmap->lmap2lmap.atom); nread += nchunk; } @@ -1381,11 +1387,11 @@ void ReadData::bonds(int firstpass) nchunk = MIN(nbonds-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); - if (labelflag && !lmap->is_complete()) + if (blabelflag && !lmap->is_complete(Atom::BOND)) error->all(FLERR,"Label map is incomplete. " "All types must be assigned a type label."); atom->data_bonds(nchunk,buffer,count,id_offset,boffset, - labelflag,lmap->lmap2lmap.bond); + blabelflag,lmap->lmap2lmap.bond); nread += nchunk; } @@ -1459,11 +1465,11 @@ void ReadData::angles(int firstpass) nchunk = MIN(nangles-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); - if (labelflag && !lmap->is_complete()) + if (alabelflag && !lmap->is_complete(Atom::ANGLE)) error->all(FLERR,"Label map is incomplete. " "All types must be assigned a type label."); atom->data_angles(nchunk,buffer,count,id_offset,aoffset, - labelflag,lmap->lmap2lmap.angle); + alabelflag,lmap->lmap2lmap.angle); nread += nchunk; } @@ -1537,11 +1543,11 @@ void ReadData::dihedrals(int firstpass) nchunk = MIN(ndihedrals-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); - if (labelflag && !lmap->is_complete()) + if (dlabelflag && !lmap->is_complete(Atom::DIHEDRAL)) error->all(FLERR,"Label map is incomplete. " "All types must be assigned a type label."); atom->data_dihedrals(nchunk,buffer,count,id_offset,doffset, - labelflag,lmap->lmap2lmap.dihedral); + dlabelflag,lmap->lmap2lmap.dihedral); nread += nchunk; } @@ -1615,11 +1621,11 @@ void ReadData::impropers(int firstpass) nchunk = MIN(nimpropers-nread,CHUNK); eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); if (eof) error->all(FLERR,"Unexpected end of data file"); - if (labelflag && !lmap->is_complete()) + if (ilabelflag && !lmap->is_complete(Atom::IMPROPER)) error->all(FLERR,"Label map is incomplete. " "All types must be assigned a type label."); atom->data_impropers(nchunk,buffer,count,id_offset,ioffset, - labelflag,lmap->lmap2lmap.improper); + ilabelflag,lmap->lmap2lmap.improper); nread += nchunk; } @@ -1813,7 +1819,7 @@ void ReadData::mass() int eof = comm->read_lines_from_file(fp,ntypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); - if (labelflag && !lmap->is_complete()) + if (tlabelflag && !lmap->is_complete(Atom::ATOM)) error->all(FLERR,"Label map is incomplete. " "All types must be assigned a type label."); @@ -1821,7 +1827,7 @@ void ReadData::mass() for (int i = 0; i < ntypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - atom->set_mass(FLERR,buf,toffset,labelflag,lmap->lmap2lmap.atom); + atom->set_mass(FLERR,buf,toffset,tlabelflag,lmap->lmap2lmap.atom); buf = next + 1; } delete [] original; @@ -1837,11 +1843,16 @@ void ReadData::paircoeffs() int eof = comm->read_lines_from_file(fp,ntypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (tlabelflag && !lmap->is_complete(Atom::ATOM)) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); + char *original = buf; for (int i = 0; i < ntypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - parse_coeffs(buf,nullptr,1,2,toffset,lmap->lmap2lmap.atom); + parse_coeffs(buf,nullptr,1,2,toffset,tlabelflag, + lmap->lmap2lmap.atom); if (narg == 0) error->all(FLERR,"Unexpected empty line in PairCoeffs section"); force->pair->coeff(narg,arg); @@ -1863,12 +1874,17 @@ void ReadData::pairIJcoeffs() int eof = comm->read_lines_from_file(fp,nsq,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (tlabelflag && !lmap->is_complete(Atom::ATOM)) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); + char *original = buf; for (i = 0; i < ntypes; i++) for (j = i; j < ntypes; j++) { next = strchr(buf,'\n'); *next = '\0'; - parse_coeffs(buf,nullptr,0,2,toffset,lmap->lmap2lmap.atom); + parse_coeffs(buf,nullptr,0,2,toffset,tlabelflag, + lmap->lmap2lmap.atom); if (narg == 0) error->all(FLERR,"Unexpected empty line in PairCoeffs section"); force->pair->coeff(narg,arg); @@ -1889,11 +1905,15 @@ void ReadData::bondcoeffs() int eof = comm->read_lines_from_file(fp,nbondtypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (blabelflag && !lmap->is_complete(Atom::BOND)) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); + char *original = buf; for (int i = 0; i < nbondtypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - parse_coeffs(buf,nullptr,0,1,boffset,lmap->lmap2lmap.bond); + parse_coeffs(buf,nullptr,0,1,boffset,blabelflag,lmap->lmap2lmap.bond); if (narg == 0) error->all(FLERR,"Unexpected empty line in BondCoeffs section"); force->bond->coeff(narg,arg); @@ -1914,13 +1934,20 @@ void ReadData::anglecoeffs(int which) int eof = comm->read_lines_from_file(fp,nangletypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (alabelflag && !lmap->is_complete(Atom::ANGLE)) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); + char *original = buf; for (int i = 0; i < nangletypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - if (which == 0) parse_coeffs(buf,nullptr,0,1,aoffset,lmap->lmap2lmap.angle); - else if (which == 1) parse_coeffs(buf,"bb",0,1,aoffset,lmap->lmap2lmap.angle); - else if (which == 2) parse_coeffs(buf,"ba",0,1,aoffset,lmap->lmap2lmap.angle); + if (which == 0) parse_coeffs(buf,nullptr,0,1,aoffset,alabelflag, + lmap->lmap2lmap.angle); + else if (which == 1) parse_coeffs(buf,"bb",0,1,aoffset,alabelflag, + lmap->lmap2lmap.angle); + else if (which == 2) parse_coeffs(buf,"ba",0,1,aoffset,alabelflag, + lmap->lmap2lmap.angle); if (narg == 0) error->all(FLERR,"Unexpected empty line in AngleCoeffs section"); force->angle->coeff(narg,arg); buf = next + 1; @@ -1940,16 +1967,26 @@ void ReadData::dihedralcoeffs(int which) int eof = comm->read_lines_from_file(fp,ndihedraltypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (dlabelflag && !lmap->is_complete(Atom::DIHEDRAL)) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); + char *original = buf; for (int i = 0; i < ndihedraltypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - if (which == 0) parse_coeffs(buf,nullptr,0,1,doffset,lmap->lmap2lmap.dihedral); - else if (which == 1) parse_coeffs(buf,"mbt",0,1,doffset,lmap->lmap2lmap.dihedral); - else if (which == 2) parse_coeffs(buf,"ebt",0,1,doffset,lmap->lmap2lmap.dihedral); - else if (which == 3) parse_coeffs(buf,"at",0,1,doffset,lmap->lmap2lmap.dihedral); - else if (which == 4) parse_coeffs(buf,"aat",0,1,doffset,lmap->lmap2lmap.dihedral); - else if (which == 5) parse_coeffs(buf,"bb13",0,1,doffset,lmap->lmap2lmap.dihedral); + if (which == 0) parse_coeffs(buf,nullptr,0,1,doffset,dlabelflag, + lmap->lmap2lmap.dihedral); + else if (which == 1) parse_coeffs(buf,"mbt",0,1,doffset,dlabelflag, + lmap->lmap2lmap.dihedral); + else if (which == 2) parse_coeffs(buf,"ebt",0,1,doffset,dlabelflag, + lmap->lmap2lmap.dihedral); + else if (which == 3) parse_coeffs(buf,"at",0,1,doffset,dlabelflag, + lmap->lmap2lmap.dihedral); + else if (which == 4) parse_coeffs(buf,"aat",0,1,doffset,dlabelflag, + lmap->lmap2lmap.dihedral); + else if (which == 5) parse_coeffs(buf,"bb13",0,1,doffset,dlabelflag, + lmap->lmap2lmap.dihedral); if (narg == 0) error->all(FLERR,"Unexpected empty line in DihedralCoeffs section"); force->dihedral->coeff(narg,arg); @@ -1970,12 +2007,18 @@ void ReadData::impropercoeffs(int which) int eof = comm->read_lines_from_file(fp,nimpropertypes,MAXLINE,buf); if (eof) error->all(FLERR,"Unexpected end of data file"); + if (ilabelflag && !lmap->is_complete(Atom::IMPROPER)) + error->all(FLERR,"Label map is incomplete. " + "All types must be assigned a type label."); + char *original = buf; for (int i = 0; i < nimpropertypes; i++) { next = strchr(buf,'\n'); *next = '\0'; - if (which == 0) parse_coeffs(buf,nullptr,0,1,ioffset,lmap->lmap2lmap.improper); - else if (which == 1) parse_coeffs(buf,"aa",0,1,ioffset,lmap->lmap2lmap.improper); + if (which == 0) parse_coeffs(buf,nullptr,0,1,ioffset,ilabelflag, + lmap->lmap2lmap.improper); + else if (which == 1) parse_coeffs(buf,"aa",0,1,ioffset,ilabelflag, + lmap->lmap2lmap.improper); if (narg == 0) error->all(FLERR,"Unexpected empty line in ImproperCoeffs section"); force->improper->coeff(narg,arg); buf = next + 1; @@ -1991,7 +2034,6 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i char *next; char *buf = new char[myntypes*MAXLINE]; - labelflag = 1; if (!atom->labelmapflag) atom->add_label_map(); int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf); @@ -2181,12 +2223,8 @@ void ReadData::skip_lines(bigint n) ------------------------------------------------------------------------- */ void ReadData::parse_coeffs(char *line, const char *addstr, int dupflag, - int noffset, int offset, int *ilabel) + int noffset, int offset, int labelmode, int *ilabel) { - if (labelflag && !lmap->is_complete()) - error->all(FLERR,"Label map is incomplete. " - "All types must be assigned a type label."); - settypeflag = 1; char *ptr; if ((ptr = strchr(line,'#'))) *ptr = '\0'; @@ -2212,12 +2250,12 @@ void ReadData::parse_coeffs(char *line, const char *addstr, int dupflag, if (noffset) { int value = utils::inumeric(FLERR,arg[0],false,lmp); - if (labelflag) value = ilabel[value-1]; + if (labelmode) value = ilabel[value-1]; sprintf(argoffset1,"%d",value+offset); arg[0] = argoffset1; if (noffset == 2) { value = utils::inumeric(FLERR,arg[1],false,lmp); - if (labelflag) value = ilabel[value-1]; + if (labelmode) value = ilabel[value-1]; sprintf(argoffset2,"%d",value+offset); arg[1] = argoffset2; } diff --git a/src/read_data.h b/src/read_data.h index a2b72d136e..8f761ce88c 100755 --- a/src/read_data.h +++ b/src/read_data.h @@ -67,7 +67,8 @@ class ReadData : protected Pointers { // optional args - int addflag,offsetflag,shiftflag,coeffflag,settypeflag,labelflag; + int addflag,offsetflag,shiftflag,coeffflag,settypeflag; + int tlabelflag,blabelflag,alabelflag,dlabelflag,ilabelflag; tagint addvalue; int toffset,boffset,aoffset,doffset,ioffset; double shift[3]; @@ -88,7 +89,7 @@ class ReadData : protected Pointers { void header(int); void parse_keyword(int); void skip_lines(bigint); - void parse_coeffs(char *, const char *, int, int, int, int *); + void parse_coeffs(char *, const char *, int, int, int, int, int *); int style_match(const char *, const char *); void atoms(); From 0d1270112f1674e1111894d9db9b8cf3b32d0eff Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Tue, 27 Apr 2021 15:35:10 -0400 Subject: [PATCH 049/392] rebase --- src/read_data.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/read_data.cpp b/src/read_data.cpp index c033d2528f..adfce65384 100755 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -2049,7 +2049,7 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i if (!atom->labelmapflag) atom->add_label_map(); - int eof = comm->read_lines_from_file(fp,myntypes,MAXLINE,buf); + int eof = utils::read_lines_from_file(fp,myntypes,MAXLINE,buf,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); char *typelabel = new char[MAXLINE]; From 0beac58e216c2b8aed500c67cac0a2ed06dcfa33 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Tue, 27 Apr 2021 15:38:39 -0400 Subject: [PATCH 050/392] some file permissions --- src/atom.cpp | 0 src/atom.h | 0 src/input.cpp | 0 src/input.h | 0 src/label_map.cpp | 0 src/label_map.h | 0 src/molecule.cpp | 0 src/molecule.h | 0 src/read_data.cpp | 0 src/read_data.h | 0 src/write_data.cpp | 0 src/write_data.h | 0 src/write_restart.cpp | 0 src/write_restart.h | 0 14 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/atom.cpp mode change 100755 => 100644 src/atom.h mode change 100755 => 100644 src/input.cpp mode change 100755 => 100644 src/input.h mode change 100755 => 100644 src/label_map.cpp mode change 100755 => 100644 src/label_map.h mode change 100755 => 100644 src/molecule.cpp mode change 100755 => 100644 src/molecule.h mode change 100755 => 100644 src/read_data.cpp mode change 100755 => 100644 src/read_data.h mode change 100755 => 100644 src/write_data.cpp mode change 100755 => 100644 src/write_data.h mode change 100755 => 100644 src/write_restart.cpp mode change 100755 => 100644 src/write_restart.h diff --git a/src/atom.cpp b/src/atom.cpp old mode 100755 new mode 100644 diff --git a/src/atom.h b/src/atom.h old mode 100755 new mode 100644 diff --git a/src/input.cpp b/src/input.cpp old mode 100755 new mode 100644 diff --git a/src/input.h b/src/input.h old mode 100755 new mode 100644 diff --git a/src/label_map.cpp b/src/label_map.cpp old mode 100755 new mode 100644 diff --git a/src/label_map.h b/src/label_map.h old mode 100755 new mode 100644 diff --git a/src/molecule.cpp b/src/molecule.cpp old mode 100755 new mode 100644 diff --git a/src/molecule.h b/src/molecule.h old mode 100755 new mode 100644 diff --git a/src/read_data.cpp b/src/read_data.cpp old mode 100755 new mode 100644 diff --git a/src/read_data.h b/src/read_data.h old mode 100755 new mode 100644 diff --git a/src/write_data.cpp b/src/write_data.cpp old mode 100755 new mode 100644 diff --git a/src/write_data.h b/src/write_data.h old mode 100755 new mode 100644 diff --git a/src/write_restart.cpp b/src/write_restart.cpp old mode 100755 new mode 100644 diff --git a/src/write_restart.h b/src/write_restart.h old mode 100755 new mode 100644 From 26fe17a379acdbf364b712fb5ace2e9478176491 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Tue, 27 Apr 2021 15:51:25 -0400 Subject: [PATCH 051/392] doc file permissions --- doc/src/labelmap.rst | 0 doc/src/molecule.rst | 0 doc/src/read_data.rst | 0 doc/src/write_data.rst | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 doc/src/labelmap.rst mode change 100755 => 100644 doc/src/molecule.rst mode change 100755 => 100644 doc/src/read_data.rst mode change 100755 => 100644 doc/src/write_data.rst diff --git a/doc/src/labelmap.rst b/doc/src/labelmap.rst old mode 100755 new mode 100644 diff --git a/doc/src/molecule.rst b/doc/src/molecule.rst old mode 100755 new mode 100644 diff --git a/doc/src/read_data.rst b/doc/src/read_data.rst old mode 100755 new mode 100644 diff --git a/doc/src/write_data.rst b/doc/src/write_data.rst old mode 100755 new mode 100644 From bf223a92b106038270bd98c11128589adafdb748 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Mon, 7 Jun 2021 23:13:55 -0400 Subject: [PATCH 052/392] update URL --- src/label_map.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/label_map.h b/src/label_map.h index d5a1d44c75..43f4a68a4e 100644 --- a/src/label_map.h +++ b/src/label_map.h @@ -1,6 +1,6 @@ /* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, Sandia National Laboratories + https://www.lammps.org/, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract From 5d30b7cc758a63f432710531758a5af8e0b49802 Mon Sep 17 00:00:00 2001 From: Jacob Gissinger Date: Fri, 20 Aug 2021 11:35:17 -0400 Subject: [PATCH 053/392] correct reverted URL --- src/label_map.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/label_map.cpp b/src/label_map.cpp index 948521dbbb..ef22748f0c 100644 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -1,13 +1,13 @@ /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories + https://www.lammps.org/, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov - + Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. - + See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ From edfac22f3939b4d19f6e6a208fb719aec4e51c20 Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sat, 28 Aug 2021 15:56:14 -0400 Subject: [PATCH 054/392] memory leak --- src/read_data.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/read_data.cpp b/src/read_data.cpp index 59958fe99f..6e16bbc58e 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -2052,6 +2052,7 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i int eof = utils::read_lines_from_file(fp,myntypes,MAXLINE,buf,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); + char *original = buf; char *typelabel = new char[MAXLINE]; for (int i = 0; i < myntypes; i++) { next = strchr(buf,'\n'); @@ -2062,6 +2063,7 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i mytypelabel[i] = typelabel; buf = next + 1; } + delete [] original; delete [] typelabel; // merge this read_data label map to atom class From 5be5a158de40763aaff906642389224c08a9be12 Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Wed, 1 Sep 2021 12:33:47 -0500 Subject: [PATCH 055/392] passing strings by reference --- src/atom.cpp | 12 ++++++------ src/atom.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 4c99f998c1..52b591ed1f 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -2054,7 +2054,7 @@ void Atom::add_molecule_atom(Molecule *onemol, int iatom, allocate space for type label map ------------------------------------------------------------------------- */ -int Atom::add_label_map(std::string mapID) +int Atom::add_label_map(const std::string &mapID) { labelmapflag = 1; lmaps = (LabelMap **) @@ -2077,7 +2077,7 @@ int Atom::add_label_map(std::string mapID) return -1 if does not exist ------------------------------------------------------------------------- */ -int Atom::find_label(std::string label, int mode) +int Atom::find_label(const std::string &label, int mode) { int ilmap = 0; @@ -2087,7 +2087,8 @@ int Atom::find_label(std::string label, int mode) if (pos != std::string::npos) { ilmap = find_labelmap(label.substr(0,pos)); if (ilmap == -1) return -1; - label = label.substr(pos+2); + auto slabel = label.substr(pos+2); + return lmaps[ilmap]->find(slabel,mode); } return lmaps[ilmap]->find(label,mode); @@ -2098,10 +2099,9 @@ int Atom::find_label(std::string label, int mode) return -1 if does not exist ------------------------------------------------------------------------- */ -int Atom::find_labelmap(std::string id) +int Atom::find_labelmap(const std::string &id) { - int ilmap; - for (ilmap = 0; ilmap < nlmap; ilmap++) + for (int ilmap = 0; ilmap < nlmap; ilmap++) if (id == lmaps[ilmap]->id) return ilmap; return -1; } diff --git a/src/atom.h b/src/atom.h index 5afbcde8c1..a87c4f4b04 100644 --- a/src/atom.h +++ b/src/atom.h @@ -337,9 +337,9 @@ class Atom : protected Pointers { int find_molecule(char *); void add_molecule_atom(class Molecule *, int, int, tagint); - int add_label_map(std::string mapID = ""); - int find_label(std::string, int); - int find_labelmap(std::string); + int add_label_map(const std::string &mapID = ""); + int find_label(const std::string &, int); + int find_labelmap(const std::string &); void first_reorder(); virtual void sort(); From f4634511fdaf9bb558052a5ec76d4ee00e7b1f28 Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Wed, 1 Sep 2021 12:34:36 -0500 Subject: [PATCH 056/392] minor --- src/input.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index b236b1dae9..a9c31ec8ea 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -689,15 +689,14 @@ int Input::readtype(char *&str, int mode) if (!atom->labelmapflag) error->all(FLERR,fmt::format("Invalid type {}",str)); int type,max,max2; - std::string labelstr; char typechar[256]; + std::string labelstr(str); - labelstr = str; type = atom->find_label(labelstr,mode); if (type == -1) error->all(FLERR,fmt::format("Invalid type {}",str)); sprintf(typechar,"%d",type); - max = strlen(str) + 1; + max = n + 1; max2 = strlen(typechar) + 1; if (max2 > max) { str = new char[max2]; From e1e13a9563db26c41f3d937079dfe5b67643b170 Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Wed, 1 Sep 2021 12:54:57 -0500 Subject: [PATCH 057/392] remove extra white space --- src/input.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index a9c31ec8ea..dcc8d81098 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1359,7 +1359,7 @@ void Input::angle_coeff() error->all(FLERR,"Angle_coeff command when no angles allowed"); int newflag = readtype(arg[0],Atom::ANGLE); force->angle->coeff(narg,arg); - if (newflag) delete [] arg[0]; + if (newflag) delete[] arg[0]; } /* ---------------------------------------------------------------------- */ @@ -1402,7 +1402,7 @@ void Input::bond_coeff() error->all(FLERR,"Bond_coeff command when no bonds allowed"); int newflag = readtype(arg[0],Atom::BOND); force->bond->coeff(narg,arg); - if (newflag) delete [] arg[0]; + if (newflag) delete[] arg[0]; } /* ---------------------------------------------------------------------- */ @@ -1507,7 +1507,7 @@ void Input::dihedral_coeff() error->all(FLERR,"Dihedral_coeff command when no dihedrals allowed"); int newflag = readtype(arg[0],Atom::DIHEDRAL); force->dihedral->coeff(narg,arg); - if (newflag) delete [] arg[0]; + if (newflag) delete[] arg[0]; } /* ---------------------------------------------------------------------- */ @@ -1586,7 +1586,7 @@ void Input::improper_coeff() error->all(FLERR,"Improper_coeff command when no impropers allowed"); int newflag = readtype(arg[0],Atom::IMPROPER); force->improper->coeff(narg,arg); - if (newflag) delete [] arg[0]; + if (newflag) delete[] arg[0]; } /* ---------------------------------------------------------------------- */ @@ -1804,8 +1804,8 @@ void Input::pair_coeff() } force->pair->coeff(narg,arg); - if (newflag0) delete [] arg[0]; - if (newflag1) delete [] arg[1]; + if (newflag0) delete[] arg[0]; + if (newflag1) delete[] arg[1]; } /* ---------------------------------------------------------------------- */ From 83d86f7d6932933a680d6d8c90bcd86e4ea032c0 Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Wed, 1 Sep 2021 12:55:48 -0500 Subject: [PATCH 058/392] remove extra white space --- src/label_map.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/label_map.cpp b/src/label_map.cpp index ef22748f0c..5a95196d0e 100644 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -43,11 +43,11 @@ LabelMap::~LabelMap() dtypelabel.clear(); itypelabel.clear(); - delete [] lmap2lmap.atom; - delete [] lmap2lmap.bond; - delete [] lmap2lmap.angle; - delete [] lmap2lmap.dihedral; - delete [] lmap2lmap.improper; + delete[] lmap2lmap.atom; + delete[] lmap2lmap.bond; + delete[] lmap2lmap.angle; + delete[] lmap2lmap.dihedral; + delete[] lmap2lmap.improper; } /* ---------------------------------------------------------------------- @@ -314,31 +314,31 @@ void LabelMap::read_restart(FILE *fp) for (int i = 0; i < natomtypes; i++) { charlabel = read_string(fp); typelabel[i] = charlabel; - delete [] charlabel; + delete[] charlabel; } for (int i = 0; i < nbondtypes; i++) { charlabel = read_string(fp); btypelabel[i] = charlabel; - delete [] charlabel; + delete[] charlabel; } for (int i = 0; i < nangletypes; i++) { charlabel = read_string(fp); atypelabel[i] = charlabel; - delete [] charlabel; + delete[] charlabel; } for (int i = 0; i < ndihedraltypes; i++) { charlabel = read_string(fp); dtypelabel[i] = charlabel; - delete [] charlabel; + delete[] charlabel; } for (int i = 0; i < nimpropertypes; i++) { charlabel = read_string(fp); itypelabel[i] = charlabel; - delete [] charlabel; + delete[] charlabel; } } From cad3a5ca510efefcbea479e813e4ed5b4068154e Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Wed, 1 Sep 2021 12:57:20 -0500 Subject: [PATCH 059/392] minor --- src/label_map.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/label_map.cpp b/src/label_map.cpp index 5a95196d0e..71850a4b44 100644 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -35,14 +35,6 @@ LabelMap::LabelMap(LAMMPS *lmp) : Pointers(lmp) LabelMap::~LabelMap() { - // delete type labels - - typelabel.clear(); - btypelabel.clear(); - atypelabel.clear(); - dtypelabel.clear(); - itypelabel.clear(); - delete[] lmap2lmap.atom; delete[] lmap2lmap.bond; delete[] lmap2lmap.angle; From ee166cbe85a4448848f717d8085dbfe1f53351ae Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Wed, 1 Sep 2021 13:15:41 -0500 Subject: [PATCH 060/392] remove extra white space --- src/read_data.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/read_data.cpp b/src/read_data.cpp index 6e16bbc58e..cd2d12a292 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -93,15 +93,15 @@ ReadData::ReadData(LAMMPS *lmp) : Command(lmp) ReadData::~ReadData() { - delete [] line; - delete [] keyword; - delete [] style; - delete [] buffer; + delete[] line; + delete[] keyword; + delete[] style; + delete[] buffer; memory->sfree(coeffarg); for (int i = 0; i < nfix; i++) { - delete [] fix_header[i]; - delete [] fix_section[i]; + delete[] fix_header[i]; + delete[] fix_section[i]; } memory->destroy(fix_index); memory->sfree(fix_header); @@ -1843,7 +1843,7 @@ void ReadData::mass() atom->set_mass(FLERR,buf,toffset,tlabelflag,lmap->lmap2lmap.atom); buf = next + 1; } - delete [] original; + delete[] original; } /* ---------------------------------------------------------------------- */ @@ -1871,7 +1871,7 @@ void ReadData::paircoeffs() force->pair->coeff(ncoeffarg,coeffarg); buf = next + 1; } - delete [] original; + delete[] original; } /* ---------------------------------------------------------------------- */ @@ -1903,7 +1903,7 @@ void ReadData::pairIJcoeffs() force->pair->coeff(ncoeffarg,coeffarg); buf = next + 1; } - delete [] original; + delete[] original; } /* ---------------------------------------------------------------------- */ @@ -1932,7 +1932,7 @@ void ReadData::bondcoeffs() force->bond->coeff(ncoeffarg,coeffarg); buf = next + 1; } - delete [] original; + delete[] original; } /* ---------------------------------------------------------------------- */ @@ -1965,7 +1965,7 @@ void ReadData::anglecoeffs(int which) force->angle->coeff(ncoeffarg,coeffarg); buf = next + 1; } - delete [] original; + delete[] original; } /* ---------------------------------------------------------------------- */ @@ -2005,7 +2005,7 @@ void ReadData::dihedralcoeffs(int which) force->dihedral->coeff(ncoeffarg,coeffarg); buf = next + 1; } - delete [] original; + delete[] original; } /* ---------------------------------------------------------------------- */ @@ -2036,7 +2036,7 @@ void ReadData::impropercoeffs(int which) force->improper->coeff(ncoeffarg,coeffarg); buf = next + 1; } - delete [] original; + delete[] original; } /* ---------------------------------------------------------------------- */ @@ -2063,8 +2063,8 @@ void ReadData::typelabels(std::vector &mytypelabel, int myntypes, i mytypelabel[i] = typelabel; buf = next + 1; } - delete [] original; - delete [] typelabel; + delete[] original; + delete[] typelabel; // merge this read_data label map to atom class // determine mapping to let labels override numeric types From f2e06777dea2f72ba794b157a3b3bda5ec99f7cb Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Fri, 3 Sep 2021 13:38:14 -0500 Subject: [PATCH 061/392] remove processor rank (me) and use the communicator value (comm->me) --- src/label_map.cpp | 11 +++++------ src/label_map.h | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/label_map.cpp b/src/label_map.cpp index 71850a4b44..96b6efd5ae 100644 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -2,18 +2,19 @@ LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov - + Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. - + See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ #include "label_map.h" #include "atom.h" +#include "comm.h" #include "force.h" #include "memory.h" #include "error.h" @@ -26,7 +27,6 @@ using namespace LAMMPS_NS; LabelMap::LabelMap(LAMMPS *lmp) : Pointers(lmp) { - MPI_Comm_rank(world,&me); natomtypes = nbondtypes = nangletypes = 0; ndihedraltypes = nimpropertypes = 0; } @@ -366,7 +366,7 @@ char *LabelMap::read_string(FILE *fp) int n = read_int(fp); if (n < 0) error->all(FLERR,"Illegal size string or corrupt restart"); char *value = new char[n]; - if (me == 0) utils::sfread(FLERR,value,sizeof(char),n,fp,nullptr,error); + if (comm->me == 0) utils::sfread(FLERR,value,sizeof(char),n,fp,nullptr,error); MPI_Bcast(value,n,MPI_CHAR,0,world); return value; } @@ -391,8 +391,7 @@ void LabelMap::write_string(std::string str, FILE *fp) int LabelMap::read_int(FILE *fp) { int value; - if ((me == 0) && (fread(&value,sizeof(int),1,fp) < 1)) - value = -1; + if ((comm->me == 0) && (fread(&value,sizeof(int),1,fp) < 1)) value = -1; MPI_Bcast(&value,1,MPI_INT,0,world); return value; } diff --git a/src/label_map.h b/src/label_map.h index 43f4a68a4e..2f852faa69 100644 --- a/src/label_map.h +++ b/src/label_map.h @@ -57,8 +57,6 @@ class LabelMap : protected Pointers { void write_restart(FILE *); private: - int me; - char *read_string(FILE *); void write_string(std::string, FILE *); int read_int(FILE *); From aeec0f0e86f9d7b1f5b263ea5cc5f648bbe5f8d8 Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Fri, 3 Sep 2021 13:42:59 -0500 Subject: [PATCH 062/392] wrap the lines --- src/label_map.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/label_map.cpp b/src/label_map.cpp index 96b6efd5ae..ff11d13567 100644 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -97,8 +97,10 @@ void LabelMap::modify_lmap(int narg, char **arg) while (iarg < narg) { itype = utils::inumeric(FLERR,arg[iarg++],false,lmp); charlabel = arg[iarg++]; - if (itype > ntypes) error->all(FLERR,"Topology type exceeds system topology type"); - if (isdigit(charlabel[0])) error->all(FLERR,"Type labels cannot start with a number"); + if (itype > ntypes) + error->all(FLERR,"Topology type exceeds system topology type"); + if (isdigit(charlabel[0])) + error->all(FLERR,"Type labels cannot start with a number"); (*labels)[itype-1] = charlabel; } } @@ -170,7 +172,8 @@ void LabelMap::create_lmap2lmap(LabelMap *lmap2, int mode) return numeric type ------------------------------------------------------------------------- */ -int LabelMap::find_or_create(std::string mylabel, std::vector &labels, int ntypes) +int LabelMap::find_or_create(std::string mylabel, + std::vector &labels, int ntypes) { for (int i = 0; i < ntypes; i++) if (labels[i] == mylabel) return i+1; @@ -221,7 +224,8 @@ int LabelMap::find(std::string mylabel, int mode) return -1 if type not yet defined ------------------------------------------------------------------------- */ -int LabelMap::search(std::string mylabel, std::vector labels, int ntypes) +int LabelMap::search(std::string mylabel, + std::vector labels, int ntypes) { for (int i = 0; i < ntypes; i++) if (labels[i] == mylabel) return i+1; @@ -366,7 +370,8 @@ char *LabelMap::read_string(FILE *fp) int n = read_int(fp); if (n < 0) error->all(FLERR,"Illegal size string or corrupt restart"); char *value = new char[n]; - if (comm->me == 0) utils::sfread(FLERR,value,sizeof(char),n,fp,nullptr,error); + if (comm->me == 0) + utils::sfread(FLERR,value,sizeof(char),n,fp,nullptr,error); MPI_Bcast(value,n,MPI_CHAR,0,world); return value; } From 257a7fe9cab855181b37fb3b95c5040180a66362 Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Fri, 3 Sep 2021 13:59:23 -0500 Subject: [PATCH 063/392] passing strings by reference --- src/label_map.cpp | 14 ++++++++------ src/label_map.h | 14 +++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/label_map.cpp b/src/label_map.cpp index ff11d13567..8bb91d3c32 100644 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -172,7 +172,7 @@ void LabelMap::create_lmap2lmap(LabelMap *lmap2, int mode) return numeric type ------------------------------------------------------------------------- */ -int LabelMap::find_or_create(std::string mylabel, +int LabelMap::find_or_create(const std::string &mylabel, std::vector &labels, int ntypes) { for (int i = 0; i < ntypes; i++) @@ -190,8 +190,10 @@ int LabelMap::find_or_create(std::string mylabel, } // if label cannot be found or created, need more space reserved - error->all(FLERR,"Topology type exceeds system topology type"); + + // never reaches here, just to prevent compiler warning + return -1; } /* ---------------------------------------------------------------------- @@ -199,7 +201,7 @@ int LabelMap::find_or_create(std::string mylabel, return -1 if type not yet defined ------------------------------------------------------------------------- */ -int LabelMap::find(std::string mylabel, int mode) +int LabelMap::find(const std::string &mylabel, int mode) { if (mode == Atom::ATOM) return search(mylabel,typelabel,natomtypes); @@ -224,8 +226,8 @@ int LabelMap::find(std::string mylabel, int mode) return -1 if type not yet defined ------------------------------------------------------------------------- */ -int LabelMap::search(std::string mylabel, - std::vector labels, int ntypes) +int LabelMap::search(const std::string &mylabel, + const std::vector &labels, int ntypes) { for (int i = 0; i < ntypes; i++) if (labels[i] == mylabel) return i+1; @@ -381,7 +383,7 @@ char *LabelMap::read_string(FILE *fp) byte) into the restart file ------------------------------------------------------------------------- */ -void LabelMap::write_string(std::string str, FILE *fp) +void LabelMap::write_string(const std::string &str, FILE *fp) { const char *cstr = str.c_str(); int n = strlen(cstr) + 1; diff --git a/src/label_map.h b/src/label_map.h index 2f852faa69..5724b1e070 100644 --- a/src/label_map.h +++ b/src/label_map.h @@ -43,12 +43,12 @@ class LabelMap : protected Pointers { void allocate_type_labels(); void modify_lmap(int, char **); - void merge_lmap(class LabelMap *, int); // copy another lmap into this one - void create_lmap2lmap(class LabelMap *, int); // index mapping between two lmaps - int find_or_create(std::string, std::vector &, int); // look up type or create new type - int find(std::string, int); // find numeric type of type label - int search(std::string, std::vector, int); // look up type index - int is_complete(int); // check if all types are assigned + void merge_lmap(class LabelMap *, int); // copy another lmap into this one + void create_lmap2lmap(class LabelMap *, int); // index mapping between two lmaps + int find_or_create(const std::string &, std::vector &, int); // look up type or create new type + int find(const std::string &, int); // find numeric type of type label + int search(const std::string &, const std::vector &, int); // look up type index + int is_complete(int); // check if all types are assigned // input/output for atom class label map @@ -58,7 +58,7 @@ class LabelMap : protected Pointers { private: char *read_string(FILE *); - void write_string(std::string, FILE *); + void write_string(const std::string &, FILE *); int read_int(FILE *); }; From d4930df46481b41358bb91887ba3d524cee1510f Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Fri, 3 Sep 2021 14:51:19 -0500 Subject: [PATCH 064/392] correct the return value type --- src/atom.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 52b591ed1f..c701d4207a 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -2079,19 +2079,17 @@ int Atom::add_label_map(const std::string &mapID) int Atom::find_label(const std::string &label, int mode) { - int ilmap = 0; - // check for auxiliary map prefix - int pos = label.find("::"); + std::string::size_type pos = label.find("::"); if (pos != std::string::npos) { - ilmap = find_labelmap(label.substr(0,pos)); + int ilmap = find_labelmap(label.substr(0,pos)); if (ilmap == -1) return -1; auto slabel = label.substr(pos+2); return lmaps[ilmap]->find(slabel,mode); } - return lmaps[ilmap]->find(label,mode); + return lmaps[0]->find(label,mode); } /* ---------------------------------------------------------------------- From 262b029d10e899716aafca8d578bbc3074b44d0e Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Fri, 3 Sep 2021 15:01:53 -0500 Subject: [PATCH 065/392] add a space after comments following LAMMPS convention --- src/label_map.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/label_map.cpp b/src/label_map.cpp index 8bb91d3c32..cf486a2dad 100644 --- a/src/label_map.cpp +++ b/src/label_map.cpp @@ -190,9 +190,11 @@ int LabelMap::find_or_create(const std::string &mylabel, } // if label cannot be found or created, need more space reserved + error->all(FLERR,"Topology type exceeds system topology type"); // never reaches here, just to prevent compiler warning + return -1; } From 860421d084c34db3f37b1809bea08fcfb4f7497d Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Fri, 3 Sep 2021 15:03:48 -0500 Subject: [PATCH 066/392] add labelmap command to the command list --- doc/src/Commands_all.rst | 1 + doc/src/commands_list.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/src/Commands_all.rst b/doc/src/Commands_all.rst index c708228be7..2176cf377f 100644 --- a/doc/src/Commands_all.rst +++ b/doc/src/Commands_all.rst @@ -64,6 +64,7 @@ An alphabetic list of all general LAMMPS commands. * :doc:`kspace_modify ` * :doc:`kspace_style ` * :doc:`label