move file opening step to reax/c function. simplify code.

This commit is contained in:
Axel Kohlmeyer
2021-04-14 16:20:39 -04:00
parent f07fa3d266
commit 89b0227849
5 changed files with 32 additions and 22 deletions

View File

@ -121,6 +121,7 @@ PairReaxC::PairReaxC(LAMMPS *lmp) : Pair(lmp)
system->pair_ptr = this;
system->error_ptr = error;
control->error_ptr = error;
control->lmp_ptr = lmp;
system->omp_active = 0;
@ -314,16 +315,7 @@ void PairReaxC::coeff( int nargs, char **args )
// read ffield file
char *file = args[2];
FILE *fp;
fp = utils::open_potential(file,lmp,nullptr);
if (fp != nullptr)
Read_Force_Field(fp, &(system->reax_param), control);
else {
char str[128];
snprintf(str,128,"Cannot open ReaxFF potential file %s",file);
error->all(FLERR,str);
}
Read_Force_Field(args[2], &(system->reax_param), control);
// read args that map atom types to elements in potential file
// map[i] = which element the Ith atom type is, -1 if "NULL"

View File

@ -31,6 +31,9 @@
#include "reaxc_tool_box.h"
#include "error.h"
#include "utils.h"
using LAMMPS_NS::utils::getsyserror;
char Read_Control_File( char *control_file, control_params* control,
output_controls *out_control )
@ -42,7 +45,9 @@ char Read_Control_File( char *control_file, control_params* control,
/* open control file */
if ((fp = fopen( control_file, "r" ) ) == nullptr) {
control->error_ptr->all(FLERR, "The control file cannot be opened");
control->error_ptr->all(FLERR,fmt::format("The control file {} cannot be "
"opened: {}",control_file,
getsyserror()));
}
/* assign default values */

View File

@ -25,16 +25,22 @@
----------------------------------------------------------------------*/
#include "reaxc_ffield.h"
#include <mpi.h>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include "reaxc_defs.h"
#include "error.h"
#include "reaxc_tool_box.h"
#include "utils.h"
char Read_Force_Field( FILE *fp, reax_interaction *reax,
using LAMMPS_NS::utils::open_potential;
using LAMMPS_NS::utils::getsyserror;
void Read_Force_Field(const char *filename, reax_interaction *reax,
control_params *control )
{
char *s;
@ -46,6 +52,11 @@ char Read_Force_Field( FILE *fp, reax_interaction *reax,
double val;
int me = control->me;
FILE *fp = open_potential(filename,control->lmp_ptr,nullptr);
if (!fp)
control->error_ptr->all(FLERR,fmt::format("Cannot open ReaxFF potential "
"file {}: {}",filename,
getsyserror()));
s = (char*) malloc(sizeof(char)*MAX_LINE);
tmp = (char**) malloc(sizeof(char*)*MAX_TOKENS);
for (i=0; i < MAX_TOKENS; i++)
@ -66,7 +77,7 @@ char Read_Force_Field( FILE *fp, reax_interaction *reax,
fclose(fp);
free(s);
free(tmp);
return 1;
return;
}
reax->gp.n_global = n;
@ -734,6 +745,4 @@ char Read_Force_Field( FILE *fp, reax_interaction *reax,
// close file
fclose(fp);
return SUCCESS;
}

View File

@ -28,8 +28,7 @@
#define __FFIELD_H_
#include "reaxc_types.h"
#include <cstdio>
char Read_Force_Field( FILE*, reax_interaction*, control_params* );
void Read_Force_Field(const char *, reax_interaction *, control_params *);
#endif

View File

@ -32,7 +32,12 @@
#include <cstdio>
#include "accelerator_kokkos.h"
namespace LAMMPS_NS { class Error;}
// forward declarations
namespace LAMMPS_NS {
class Error;
class LAMMPS;
class Pair;
}
#if defined LMP_USER_OMP
#define OMP_TIMING 0
@ -406,8 +411,8 @@ struct _reax_system
boundary_cutoff bndry_cuts;
reax_atom *my_atoms;
class LAMMPS_NS::Error *error_ptr;
class LAMMPS_NS::Pair *pair_ptr;
LAMMPS_NS::Error *error_ptr;
LAMMPS_NS::Pair *pair_ptr;
int my_bonds;
int mincap,minhbonds;
double safezone, saferzone;
@ -486,9 +491,9 @@ typedef struct
int lgflag;
int enobondsflag;
class LAMMPS_NS::Error *error_ptr;
LAMMPS_NS::Error *error_ptr;
LAMMPS_NS::LAMMPS *lmp_ptr;
int me;
} control_params;