From 6134164ad384cd1ad14984c05fb148fdbed37b95 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 11 Jul 2021 20:03:52 -0400 Subject: [PATCH] pair style rann does not support per-atom stress or pair_modify nofdotr --- doc/src/pair_rann.rst | 2 + src/ML-RANN/pair_rann.cpp | 48 ++++++++--------- src/ML-RANN/pair_rann.h | 6 +-- unittest/force-styles/test_pair_style.cpp | 65 ++++++++++++----------- 4 files changed, 62 insertions(+), 59 deletions(-) diff --git a/doc/src/pair_rann.rst b/doc/src/pair_rann.rst index b02a81e4b8..a9ad5d9236 100644 --- a/doc/src/pair_rann.rst +++ b/doc/src/pair_rann.rst @@ -382,6 +382,8 @@ Pair style *rann* is part of the ML-RANN package. It is only enabled if LAMMPS package. Additionally, if any spin fingerprint styles are used LAMMPS must be built with the SPIN package as well. +Pair style *rann* does not support computing per-atom stress or using :doc:`pair_modify nofdotr `. + Defaults """""""""""" diff --git a/src/ML-RANN/pair_rann.cpp b/src/ML-RANN/pair_rann.cpp index 2fe8f4d0c1..f0d1dec876 100644 --- a/src/ML-RANN/pair_rann.cpp +++ b/src/ML-RANN/pair_rann.cpp @@ -701,15 +701,22 @@ bool PairRANN::check_potential() { void PairRANN::compute(int eflag, int vflag) { - //perform force/energy computation_ + //perform force/energy computation_ if (dospin) { if (strcmp(update->unit_style,"metal") != 0) error->one(FLERR,"Spin pair styles require metal units"); if (!atom->sp_flag) error->one(FLERR,"Spin pair styles requires atom/spin style"); } - if (eflag || vflag) ev_setup(eflag,vflag); - else evflag = vflag_fdotr = vflag_atom = 0; + ev_init(eflag,vflag); + + // only global virial via fdotr is supported by this pair style + + if (vflag_atom) + error->all(FLERR,"Pair style rann does not support computing per-atom stress"); + if (vflag && !vflag_fdotr) + error->all(FLERR,"Pair style rann does not support 'pair_modify nofdotr'"); + int ii,i,j; int nn = 0; sims = new Simulation[1]; @@ -724,13 +731,11 @@ void PairRANN::compute(int eflag, int vflag) sims->s = atom->sp; } int itype,f,jnum,len; - if (eflag || vflag) ev_setup(eflag,vflag); - else evflag = vflag_fdotr = eflag_global = eflag_atom = 0; if (eflag_global) {eng_vdwl=0;eng_coul=0;} double energy=0; double **force = atom->f; double **fm = atom->fm; - double **virial = vatom; + //loop over atoms for (ii=0;iiinum;ii++) { i = sims->ilist[ii]; @@ -800,12 +805,8 @@ void PairRANN::compute(int eflag, int vflag) sx[j]=sy[j]=sz[j]=0; } } - if (doscreen) { - screen(ii,0,jnum-1); - } - if (allscreen) { - screen_neighbor_list(&jnum); - } + if (doscreen) screening(ii,0,jnum-1); + if (allscreen) screen_neighbor_list(&jnum); //do fingerprints for atom type len = fingerprintperelement[itype]; for (j=0;jilist; @@ -1026,8 +1026,8 @@ void PairRANN::propagateforward(double * energy,double **force,double ** /*viria sum[j] = activation[itype][i]->activation_function(sum[j]); if (i==L-1) { energy[j] = sum[j]; - if (eflag_atom)eatom[i1]=sum[j]; - if (eflag_global) {eng_vdwl +=sum[j];} + if (eflag_atom) eatom[i1]=sum[j]; + if (eflag_global) eng_vdwl +=sum[j]; } //force propagation for (jj=0;jjilist; @@ -1103,8 +1103,8 @@ void PairRANN::propagateforwardspin(double * energy,double **force,double **fm,d sum[j] = activation[itype][i]->activation_function(sum[j]); if (i==L-1) { energy[j] = sum[j]; - if (eflag_atom)eatom[i1]=sum[j]; - if (eflag_global) {eng_vdwl +=sum[j];} + if (eflag_atom) eatom[i1]=sum[j]; + if (eflag_global) eng_vdwl +=sum[j]; } //force propagation for (jj=0;jjrequest(this,instance_me); diff --git a/src/ML-RANN/pair_rann.h b/src/ML-RANN/pair_rann.h index a89e0265b6..ceaa5f445c 100644 --- a/src/ML-RANN/pair_rann.h +++ b/src/ML-RANN/pair_rann.h @@ -149,9 +149,9 @@ namespace LAMMPS_NS { void read_screening(std::vector,std::vector,char*,int); void read_mass(const std::vector &, const std::vector &,const char*,int); bool check_potential();//after finishing reading potential file - void propagateforward(double *,double **,double **,int,int);//called by compute to get force and energy - void propagateforwardspin(double *,double **,double **,double**,int,int);//called by compute to get force and energy - void screen(int,int,int); + void propagateforward(double *,double **,int,int);//called by compute to get force and energy + void propagateforwardspin(double *,double **,double**,int,int);//called by compute to get force and energy + void screening(int,int,int); void cull_neighbor_list(int *,int,int); void screen_neighbor_list(int *); }; diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index d256685659..5fb542735e 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -523,36 +523,39 @@ TEST(PairStyle, plain) EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); if (print_stats) std::cerr << "restart_energy stats:" << stats << std::endl; - if (!verbose) ::testing::internal::CaptureStdout(); - restart_lammps(lmp, test_config, true); - if (!verbose) ::testing::internal::GetCapturedStdout(); + // pair style rann does not support pair_modify nofdotr + if (test_config.pair_style != "rann") { + if (!verbose) ::testing::internal::CaptureStdout(); + restart_lammps(lmp, test_config, true); + if (!verbose) ::testing::internal::GetCapturedStdout(); - f = lmp->atom->f; - tag = lmp->atom->tag; - stats.reset(); - ASSERT_EQ(nlocal + 1, f_ref.size()); - for (int i = 0; i < nlocal; ++i) { - EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); - EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); + f = lmp->atom->f; + tag = lmp->atom->tag; + stats.reset(); + ASSERT_EQ(nlocal + 1, f_ref.size()); + for (int i = 0; i < nlocal; ++i) { + EXPECT_FP_LE_WITH_EPS(f[i][0], f_ref[tag[i]].x, epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][1], f_ref[tag[i]].y, epsilon); + EXPECT_FP_LE_WITH_EPS(f[i][2], f_ref[tag[i]].z, epsilon); + } + if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; + + pair = lmp->force->pair; + stress = pair->virial; + stats.reset(); + EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); + EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); + if (print_stats) std::cerr << "nofdotr_stress stats:" << stats << std::endl; + + stats.reset(); + EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); + EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); + if (print_stats) std::cerr << "nofdotr_energy stats:" << stats << std::endl; } - if (print_stats) std::cerr << "nofdotr_forces stats:" << stats << std::endl; - - pair = lmp->force->pair; - stress = pair->virial; - stats.reset(); - EXPECT_FP_LE_WITH_EPS(stress[0], test_config.init_stress.xx, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[1], test_config.init_stress.yy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[2], test_config.init_stress.zz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[3], test_config.init_stress.xy, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[4], test_config.init_stress.xz, epsilon); - EXPECT_FP_LE_WITH_EPS(stress[5], test_config.init_stress.yz, epsilon); - if (print_stats) std::cerr << "nofdotr_stress stats:" << stats << std::endl; - - stats.reset(); - EXPECT_FP_LE_WITH_EPS(pair->eng_vdwl, test_config.init_vdwl, epsilon); - EXPECT_FP_LE_WITH_EPS(pair->eng_coul, test_config.init_coul, epsilon); - if (print_stats) std::cerr << "nofdotr_energy stats:" << stats << std::endl; if (!verbose) ::testing::internal::CaptureStdout(); data_lammps(lmp, test_config); @@ -1091,9 +1094,9 @@ TEST(PairStyle, intel) // pair styles sw and tersoff and airebo INTEL package variants require newton on, // but that also requires fdotr for /intel - if ((test_config.pair_style != "sw") && (test_config.pair_style != "tersoff") - && (test_config.pair_style != "rebo") && (test_config.pair_style != "airebo") - && (test_config.pair_style != "airebo/morse")) { + if ((test_config.pair_style != "sw") && (test_config.pair_style != "tersoff") && + (test_config.pair_style != "rebo") && (test_config.pair_style != "airebo") && + (test_config.pair_style != "airebo/morse")) { if (!verbose) ::testing::internal::CaptureStdout(); restart_lammps(lmp, test_config, true, true);