simplify format handling

This commit is contained in:
Axel Kohlmeyer
2021-07-29 15:26:29 -04:00
parent dcff3d70e0
commit b108da3e5c
3 changed files with 31 additions and 56 deletions

View File

@ -18,18 +18,19 @@
#include "fix_ipi.h" #include "fix_ipi.h"
#include <cstring>
#include "atom.h" #include "atom.h"
#include "force.h" #include "comm.h"
#include "update.h" #include "compute.h"
#include "domain.h"
#include "error.h" #include "error.h"
#include "force.h"
#include "irregular.h"
#include "kspace.h" #include "kspace.h"
#include "modify.h" #include "modify.h"
#include "compute.h"
#include "comm.h"
#include "neighbor.h" #include "neighbor.h"
#include "irregular.h" #include "update.h"
#include "domain.h"
#include <cstring>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace FixConst; using namespace FixConst;
@ -83,15 +84,13 @@ static void open_socket(int &sockfd, int inet, int port, char* host,
// fetches information on the host // fetches information on the host
struct addrinfo hints, *res; struct addrinfo hints, *res;
char service[256];
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_PASSIVE; hints.ai_flags = AI_PASSIVE;
sprintf(service,"%d",port); // convert the port number to a string ai_err = getaddrinfo(host, std::to_string(port).c_str(), &hints, &res);
ai_err = getaddrinfo(host, service, &hints, &res);
if (ai_err!=0) if (ai_err!=0)
error->one(FLERR,"Error fetching host data. Wrong host name?"); error->one(FLERR,"Error fetching host data. Wrong host name?");

View File

@ -246,10 +246,8 @@ void FixSRP::setup_pre_force(int /*zz*/)
int nadd_all = 0, ndel_all = 0; int nadd_all = 0, ndel_all = 0;
MPI_Allreduce(&ndel,&ndel_all,1,MPI_INT,MPI_SUM,world); MPI_Allreduce(&ndel,&ndel_all,1,MPI_INT,MPI_SUM,world);
MPI_Allreduce(&nadd,&nadd_all,1,MPI_INT,MPI_SUM,world); MPI_Allreduce(&nadd,&nadd_all,1,MPI_INT,MPI_SUM,world);
if (comm->me == 0) { if (comm->me == 0)
sprintf(str, "Removed/inserted %d/%d bond particles.", ndel_all,nadd_all); error->message(FLERR,"Removed/inserted {}/{} bond particles.", ndel_all,nadd_all);
error->message(FLERR,str);
}
// check ghost comm distances // check ghost comm distances
// warn and change if shorter from estimate // warn and change if shorter from estimate
@ -276,11 +274,9 @@ void FixSRP::setup_pre_force(int /*zz*/)
cutghostmin = comm->cutghost[2]/length2; cutghostmin = comm->cutghost[2]/length2;
// stop if cutghost is insufficient // stop if cutghost is insufficient
if (cutneighmax_srp > cutghostmin) { if (cutneighmax_srp > cutghostmin)
sprintf(str, "Communication cutoff too small for fix srp. " error->all(FLERR,"Communication cutoff too small for fix srp. "
"Need %f, current %f.", cutneighmax_srp, cutghostmin); "Need {:.8}, current {:.8}", cutneighmax_srp, cutghostmin);
error->all(FLERR,str);
}
// assign tags for new atoms, update map // assign tags for new atoms, update map
atom->tag_extend(); atom->tag_extend();
@ -515,14 +511,8 @@ void FixSRP::post_run()
bigint ndelete = natoms_previous - atom->natoms; bigint ndelete = natoms_previous - atom->natoms;
if (comm->me == 0) { if (comm->me == 0)
if (screen) fprintf(screen,"Deleted " BIGINT_FORMAT utils::logmesg(lmp,"Deleted {} atoms, new total = {}\n",ndelete,atom->natoms);
" atoms, new total = " BIGINT_FORMAT "\n",
ndelete,atom->natoms);
if (logfile) fprintf(logfile,"Deleted " BIGINT_FORMAT
" atoms, new total = " BIGINT_FORMAT "\n",
ndelete,atom->natoms);
}
// verlet calls box_too_small_check() in post_run // verlet calls box_too_small_check() in post_run
// this check maps all bond partners // this check maps all bond partners

View File

@ -28,24 +28,23 @@ Please contact Timothy Sirk for questions (tim.sirk@us.army.mil).
#include "pair_srp.h" #include "pair_srp.h"
#include <cmath>
#include <cstring>
#include "atom.h" #include "atom.h"
#include "citeme.h"
#include "comm.h" #include "comm.h"
#include "force.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "memory.h"
#include "error.h"
#include "domain.h" #include "domain.h"
#include "modify.h" #include "error.h"
#include "fix.h" #include "fix.h"
#include "fix_srp.h" #include "fix_srp.h"
#include "thermo.h" #include "force.h"
#include "memory.h"
#include "modify.h"
#include "neigh_list.h"
#include "neighbor.h"
#include "output.h" #include "output.h"
#include "citeme.h" #include "thermo.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
@ -79,26 +78,15 @@ PairSRP::PairSRP(LAMMPS *lmp) : Pair(lmp)
nextra = 1; nextra = 1;
segment = nullptr; segment = nullptr;
// generate unique fix-id for this pair style instance // create fix SRP instance here with unique fix id
fix_id = strdup("XX_FIX_SRP");
fix_id[0] = '0' + srp_instance / 10;
fix_id[1] = '0' + srp_instance % 10;
++srp_instance;
// create fix SRP instance here
// similar to granular pair styles with history, // similar to granular pair styles with history,
// this should be early enough that FixSRP::pre_exchange() // this should be early enough that FixSRP::pre_exchange()
// will be invoked before other fixes that migrate atoms // will be invoked before other fixes that migrate atoms
// this is checked for in FixSRP // this is checked for in FixSRP
char **fixarg = new char*[3]; modify->add_fix(fmt::format("{:02d}_FIX_SRP all SRP",srp_instance));
fixarg[0] = fix_id;
fixarg[1] = (char *) "all";
fixarg[2] = (char *) "SRP";
modify->add_fix(3,fixarg);
f_srp = (FixSRP *) modify->fix[modify->nfix-1]; f_srp = (FixSRP *) modify->fix[modify->nfix-1];
delete [] fixarg; ++srp_instance;
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -468,10 +456,8 @@ void PairSRP::init_style()
if (f_srp != (FixSRP *)modify->fix[ifix]) if (f_srp != (FixSRP *)modify->fix[ifix])
error->all(FLERR,"Fix SRP has been changed unexpectedly"); error->all(FLERR,"Fix SRP has been changed unexpectedly");
if (comm->me == 0) { if (comm->me == 0)
if (screen) fprintf(screen,"Using type %d for bond particles\n",bptype); utils::logmesg(lmp,"Using type {} for bond particles\n",bptype);
if (logfile) fprintf(logfile,"Using type %d for bond particles\n",bptype);
}
// set bond and bond particle types in fix srp // set bond and bond particle types in fix srp
// bonds of this type will be represented by bond particles // bonds of this type will be represented by bond particles