From 95797d643b91d99f543bb5c04cf22df7dd3afffb Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 15:31:04 +0200 Subject: [PATCH 001/120] addition of extract & reinit methods in improper.h --- src/improper.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/improper.h b/src/improper.h index f65ba3bdbc..0f539bdece 100644 --- a/src/improper.h +++ b/src/improper.h @@ -37,6 +37,9 @@ class Improper : protected Pointers { // CENTROID_AVAIL = different and implemented // CENTROID_NOTAVAIL = different, not yet implemented + int reinitflag; // 0 if not compatible with fix adapt + // extract() method may still need to be added + int symmatoms[4]; // symmetry atom(s) of improper style // value of 0: interchangable atoms // value of 1: central atom @@ -67,6 +70,8 @@ class Improper : protected Pointers { du = 0.0; du2 = 0.0; } + virtual void *extract(const char *, int &) { return nullptr; } + void reinit(); protected: int suffix_flag; // suffix compatibility flag From feea204f7c0062e4bcc767fc9c1ee6ee9907a593 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 15:37:59 +0200 Subject: [PATCH 002/120] implement reinit & set reinitflag flag to 1 --- src/improper.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/improper.cpp b/src/improper.cpp index 3476bcdb50..136e913dd0 100644 --- a/src/improper.cpp +++ b/src/improper.cpp @@ -30,6 +30,7 @@ Improper::Improper(LAMMPS *_lmp) : Pointers(_lmp) { energy = 0.0; writedata = 0; + reinitflag = 1; for (int i = 0; i < 4; i++) symmatoms[i] = 0; allocated = 0; @@ -421,3 +422,15 @@ double Improper::memory_usage() bytes += (double) comm->nthreads * maxvatom * 6 * sizeof(double); return bytes; } + +/* ----------------------------------------------------------------------- + reset all type-based improper params via init() +-------------------------------------------------------------------------- */ + +void Improper::reinit() +{ + if (!reinitflag) + error->all(FLERR, "Fix adapt interface to this improper style not supported"); + + init(); +} From dda23a20b70c59b2a13d3c10c8c0673e994163d5 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 15:39:46 +0200 Subject: [PATCH 003/120] define extract for improper harmonic --- src/MOLECULE/improper_harmonic.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MOLECULE/improper_harmonic.h b/src/MOLECULE/improper_harmonic.h index 89ebe49dec..a0047c28f2 100644 --- a/src/MOLECULE/improper_harmonic.h +++ b/src/MOLECULE/improper_harmonic.h @@ -33,6 +33,7 @@ class ImproperHarmonic : public Improper { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; protected: double *k, *chi; From a2508fef13f817f29f3482b96ea232cb2d2e04e7 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 15:41:20 +0200 Subject: [PATCH 004/120] implement extract in improper harmonic --- src/MOLECULE/improper_harmonic.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/MOLECULE/improper_harmonic.cpp b/src/MOLECULE/improper_harmonic.cpp index 06647fb93b..b9fda62343 100644 --- a/src/MOLECULE/improper_harmonic.cpp +++ b/src/MOLECULE/improper_harmonic.cpp @@ -276,3 +276,15 @@ void ImproperHarmonic::write_data(FILE *fp) for (int i = 1; i <= atom->nimpropertypes; i++) fprintf(fp, "%d %g %g\n", i, k[i], RAD2DEG * chi[i]); } + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperHarmonic::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k; + if (strcmp(str, "chi") == 0) return (void *) chi; + return nullptr; +} From 43d9d6af3e4c85b591fe21906146382d9bef1b3c Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 15:44:12 +0200 Subject: [PATCH 005/120] Update fix_adapt.h --- src/fix_adapt.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fix_adapt.h b/src/fix_adapt.h index 20964a8b12..9f064a163e 100644 --- a/src/fix_adapt.h +++ b/src/fix_adapt.h @@ -44,7 +44,7 @@ class FixAdapt : public Fix { private: int nadapt, resetflag, scaleflag, massflag; - int anypair, anybond, anyangle; + int anypair, anybond, anyangle, anyimproper; int nlevels_respa; char *id_fix_diam, *id_fix_chg; class FixStoreAtom *fix_diam, *fix_chg; @@ -57,8 +57,9 @@ class FixAdapt : public Fix { char *pstyle, *pparam; char *bstyle, *bparam; char *astyle, *aparam; + char *istyle, *iparam; int ilo, ihi, jlo, jhi; - int pdim, bdim, adim; + int pdim, bdim, adim, idim; double *scalar, scalar_orig; double *vector, *vector_orig; double **array, **array_orig; @@ -66,6 +67,7 @@ class FixAdapt : public Fix { class Pair *pair; class Bond *bond; class Angle *angle; + class Improper *improper; }; Adapt *adapt; From 84dbfa3e0d513bb33168294be15da70be799f470 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 15:46:29 +0200 Subject: [PATCH 006/120] include files in fix_adapt.cpp --- src/fix_adapt.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fix_adapt.cpp b/src/fix_adapt.cpp index 9144ecde71..24c09d5081 100644 --- a/src/fix_adapt.cpp +++ b/src/fix_adapt.cpp @@ -24,6 +24,8 @@ #include "fix_store_atom.h" #include "force.h" #include "group.h" +#include "improper.h" +#include "improper_hybrid.h" #include "input.h" #include "kspace.h" #include "math_const.h" @@ -41,7 +43,7 @@ using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -enum{PAIR, KSPACE, ATOM, BOND, ANGLE}; +enum{PAIR, KSPACE, ATOM, BOND, ANGLE, IMPROPER}; enum{DIAMETER, CHARGE}; /* ---------------------------------------------------------------------- */ From 36c2770383a4d48ac0478bb3c4577e2411718311 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:06:55 +0200 Subject: [PATCH 007/120] define extract for improper cvff --- src/MOLECULE/improper_cvff.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MOLECULE/improper_cvff.h b/src/MOLECULE/improper_cvff.h index ff550fe9e8..07ff607417 100644 --- a/src/MOLECULE/improper_cvff.h +++ b/src/MOLECULE/improper_cvff.h @@ -33,6 +33,7 @@ class ImproperCvff : public Improper { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; protected: double *k; From a21b92f4deb6ba501db15824149b9aa1e64da4c2 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:08:24 +0200 Subject: [PATCH 008/120] implement extract in improper cvff --- src/MOLECULE/improper_cvff.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/MOLECULE/improper_cvff.cpp b/src/MOLECULE/improper_cvff.cpp index ad8f709541..533bbddf5b 100644 --- a/src/MOLECULE/improper_cvff.cpp +++ b/src/MOLECULE/improper_cvff.cpp @@ -337,3 +337,16 @@ void ImproperCvff::write_data(FILE *fp) for (int i = 1; i <= atom->nimpropertypes; i++) fprintf(fp, "%d %g %d %d\n", i, k[i], sign[i], multiplicity[i]); } + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperHarmonic::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k; + if (strcmp(str, "sign") == 0) return (void *) sign; + if (strcmp(str, "multiplicity") == 0) return (void *) multiplicity; + return nullptr; +} From 59915a3b6aa0309242129659996682510a13b1fd Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:09:07 +0200 Subject: [PATCH 009/120] define extract in improper umbrella --- src/MOLECULE/improper_umbrella.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MOLECULE/improper_umbrella.h b/src/MOLECULE/improper_umbrella.h index 9441810861..a6791ffe20 100644 --- a/src/MOLECULE/improper_umbrella.h +++ b/src/MOLECULE/improper_umbrella.h @@ -33,6 +33,7 @@ class ImproperUmbrella : public Improper { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; protected: double *kw, *w0, *C; From 5233b21c21737140d74cb97873a0dc2256092807 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:11:38 +0200 Subject: [PATCH 010/120] implement extract in improper umbrella --- src/MOLECULE/improper_umbrella.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/MOLECULE/improper_umbrella.cpp b/src/MOLECULE/improper_umbrella.cpp index 1558adc337..a4c6fbca42 100644 --- a/src/MOLECULE/improper_umbrella.cpp +++ b/src/MOLECULE/improper_umbrella.cpp @@ -322,3 +322,16 @@ void ImproperUmbrella::write_data(FILE *fp) for (int i = 1; i <= atom->nimpropertypes; i++) fprintf(fp, "%d %g %g\n", i, kw[i], RAD2DEG * w0[i]); } + + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperUmbrella::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "kw") == 0) return (void *) kw; + if (strcmp(str, "w0") == 0) return (void *) w0; + return nullptr; +} From 7df94e179cdd12d6bac5930de7c26ecb8f567cb0 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:12:22 +0200 Subject: [PATCH 011/120] fix error in improper_cvff.cpp --- src/MOLECULE/improper_cvff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MOLECULE/improper_cvff.cpp b/src/MOLECULE/improper_cvff.cpp index 533bbddf5b..bb9836393c 100644 --- a/src/MOLECULE/improper_cvff.cpp +++ b/src/MOLECULE/improper_cvff.cpp @@ -342,7 +342,7 @@ void ImproperCvff::write_data(FILE *fp) return ptr to internal members upon request ------------------------------------------------------------------------ */ -void *ImproperHarmonic::extract(const char *str, int &dim) +void *ImproperCvff::extract(const char *str, int &dim) { dim = 1; if (strcmp(str, "k") == 0) return (void *) k; From de6f17c0ced95a96dbd9c28b4a75578a9bcc9f63 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:13:56 +0200 Subject: [PATCH 012/120] define extract for improper cossq --- src/EXTRA-MOLECULE/improper_cossq.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/EXTRA-MOLECULE/improper_cossq.h b/src/EXTRA-MOLECULE/improper_cossq.h index cc7e94ca5c..bcc12e654f 100644 --- a/src/EXTRA-MOLECULE/improper_cossq.h +++ b/src/EXTRA-MOLECULE/improper_cossq.h @@ -33,6 +33,7 @@ class ImproperCossq : public Improper { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; protected: double *k, *chi; From ca6ab28536e9757e4964b071b459f735fa691f53 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:14:54 +0200 Subject: [PATCH 013/120] implement extract for improper cossq --- src/EXTRA-MOLECULE/improper_cossq.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/EXTRA-MOLECULE/improper_cossq.cpp b/src/EXTRA-MOLECULE/improper_cossq.cpp index 864ec28927..a25d324261 100644 --- a/src/EXTRA-MOLECULE/improper_cossq.cpp +++ b/src/EXTRA-MOLECULE/improper_cossq.cpp @@ -308,3 +308,15 @@ void ImproperCossq::write_data(FILE *fp) for (int i = 1; i <= atom->nimpropertypes; i++) fprintf(fp,"%d %g %g\n",i,k[i],chi[i]/MY_PI*180.0); } + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperCossq::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k; + if (strcmp(str, "chi") == 0) return (void *) chi; + return nullptr; +} From 01d091d8d6e426205be2ee6db4acce8748364c31 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:15:36 +0200 Subject: [PATCH 014/120] define extract for improper ring --- src/EXTRA-MOLECULE/improper_ring.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/EXTRA-MOLECULE/improper_ring.h b/src/EXTRA-MOLECULE/improper_ring.h index db8a681f75..0c68b4e15a 100644 --- a/src/EXTRA-MOLECULE/improper_ring.h +++ b/src/EXTRA-MOLECULE/improper_ring.h @@ -33,6 +33,7 @@ class ImproperRing : public Improper { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; protected: double *k, *chi; From 61a29f542129bc98adf09d4695f333dd190a96dd Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:16:41 +0200 Subject: [PATCH 015/120] implement extract for improper ring --- src/EXTRA-MOLECULE/improper_ring.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/EXTRA-MOLECULE/improper_ring.cpp b/src/EXTRA-MOLECULE/improper_ring.cpp index 3d8b672e1e..ac5f0eb237 100644 --- a/src/EXTRA-MOLECULE/improper_ring.cpp +++ b/src/EXTRA-MOLECULE/improper_ring.cpp @@ -349,3 +349,16 @@ void ImproperRing::write_data(FILE *fp) for (int i = 1; i <= atom->nimpropertypes; i++) fprintf(fp,"%d %g %g\n",i,k[i],acos(chi[i])/MY_PI*180.0); } + + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperRing::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k; + if (strcmp(str, "chi") == 0) return (void *) chi; + return nullptr; +} From 60181e2a8abd2b5ccae74ed59202ab7c6892c839 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:17:17 +0200 Subject: [PATCH 016/120] define extract for improper distance --- src/EXTRA-MOLECULE/improper_distance.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/EXTRA-MOLECULE/improper_distance.h b/src/EXTRA-MOLECULE/improper_distance.h index b0bfaea6e6..67d5cacc46 100644 --- a/src/EXTRA-MOLECULE/improper_distance.h +++ b/src/EXTRA-MOLECULE/improper_distance.h @@ -33,6 +33,7 @@ class ImproperDistance : public Improper { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; private: double *k, *chi; From 52457d6c1e66d6c1d98a8735cd4e4566f22d5130 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:18:13 +0200 Subject: [PATCH 017/120] implement extract for improper distance --- src/EXTRA-MOLECULE/improper_distance.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/EXTRA-MOLECULE/improper_distance.cpp b/src/EXTRA-MOLECULE/improper_distance.cpp index 934eeb285d..2eb30c7f2b 100644 --- a/src/EXTRA-MOLECULE/improper_distance.cpp +++ b/src/EXTRA-MOLECULE/improper_distance.cpp @@ -268,3 +268,16 @@ void ImproperDistance::write_data(FILE *fp) for (int i = 1; i <= atom->nimpropertypes; i++) fprintf(fp,"%d %g %g\n",i,k[i],chi[i]); } + + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperDistance::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k; + if (strcmp(str, "chi") == 0) return (void *) chi; + return nullptr; +} From 3cd0871083e61f05f81222f06b8e84682b48d24d Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:20:42 +0200 Subject: [PATCH 018/120] define extract for improper inversion_harmonic --- src/MOFFF/improper_inversion_harmonic.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MOFFF/improper_inversion_harmonic.h b/src/MOFFF/improper_inversion_harmonic.h index 2ad1bceba1..eabb91194f 100644 --- a/src/MOFFF/improper_inversion_harmonic.h +++ b/src/MOFFF/improper_inversion_harmonic.h @@ -33,6 +33,7 @@ class ImproperInversionHarmonic : public Improper { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; protected: double *kw, *w0; From 62e7698a445bb4ee4cfbb3ab057a160953fd3332 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:21:46 +0200 Subject: [PATCH 019/120] implement extract in improper inversion_harmonic --- src/MOFFF/improper_inversion_harmonic.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/MOFFF/improper_inversion_harmonic.cpp b/src/MOFFF/improper_inversion_harmonic.cpp index c0de968626..681811594b 100644 --- a/src/MOFFF/improper_inversion_harmonic.cpp +++ b/src/MOFFF/improper_inversion_harmonic.cpp @@ -332,3 +332,15 @@ void ImproperInversionHarmonic::write_data(FILE *fp) for (int i = 1; i <= atom->nimpropertypes; i++) fprintf(fp,"%d %g %g\n",i,kw[i],w0[i]/MY_PI*180.0); } + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperInversionHarmonic::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "kw") == 0) return (void *) kw; + if (strcmp(str, "w0") == 0) return (void *) w0; + return nullptr; +} From ee7b0840ef2a637f7692185a4e24e19d834631c2 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:22:50 +0200 Subject: [PATCH 020/120] define extract for improper sqdistharm --- src/YAFF/improper_sqdistharm.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/YAFF/improper_sqdistharm.h b/src/YAFF/improper_sqdistharm.h index 4cd89a294e..d8d4131362 100644 --- a/src/YAFF/improper_sqdistharm.h +++ b/src/YAFF/improper_sqdistharm.h @@ -32,6 +32,7 @@ class ImproperSQDistHarm : public Improper { void coeff(int, char **) override; void write_restart(FILE *) override; void read_restart(FILE *) override; + void *extract(const char *, int &) override; private: double *k, *chi; From 34e89bed4c9cebbca327a7375108d789e1fed7ee Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:23:40 +0200 Subject: [PATCH 021/120] implement extract in improper sqdistharm --- src/YAFF/improper_sqdistharm.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/YAFF/improper_sqdistharm.cpp b/src/YAFF/improper_sqdistharm.cpp index f4beab3587..038063eae8 100644 --- a/src/YAFF/improper_sqdistharm.cpp +++ b/src/YAFF/improper_sqdistharm.cpp @@ -267,3 +267,15 @@ void ImproperSQDistHarm::read_restart(FILE *fp) for (int i = 1; i <= atom->nimpropertypes; i++) setflag[i] = 1; } + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperSQDistHarm::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k; + if (strcmp(str, "chi") == 0) return (void *) chi; + return nullptr; +} From 676add28fe4fd5a38f69edf091b1efd1653fadf0 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:24:13 +0200 Subject: [PATCH 022/120] define extract in improper distharm --- src/YAFF/improper_distharm.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/YAFF/improper_distharm.h b/src/YAFF/improper_distharm.h index 911bbadb0d..6896af3e15 100644 --- a/src/YAFF/improper_distharm.h +++ b/src/YAFF/improper_distharm.h @@ -32,6 +32,7 @@ class ImproperDistHarm : public Improper { void coeff(int, char **) override; void write_restart(FILE *) override; void read_restart(FILE *) override; + void *extract(const char *, int &) override; private: double *k, *chi; From ea9166d1757fb60a500d99151ec569934b3a3046 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 17:24:52 +0200 Subject: [PATCH 023/120] implement extract in improper distharm --- src/YAFF/improper_distharm.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/YAFF/improper_distharm.cpp b/src/YAFF/improper_distharm.cpp index 257cbce1b3..c2d7381fd9 100644 --- a/src/YAFF/improper_distharm.cpp +++ b/src/YAFF/improper_distharm.cpp @@ -267,3 +267,15 @@ void ImproperDistHarm::read_restart(FILE *fp) for (int i = 1; i <= atom->nimpropertypes; i++) setflag[i] = 1; } + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperDistHarm::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k; + if (strcmp(str, "chi") == 0) return (void *) chi; + return nullptr; +} From 24f40c7db413761541f1790362aeba75ce584783 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 21:13:38 +0200 Subject: [PATCH 024/120] Update unit test in improper-cvff.yaml --- unittest/force-styles/tests/improper-cvff.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-cvff.yaml b/unittest/force-styles/tests/improper-cvff.yaml index 3a300de4d6..729768dc89 100644 --- a/unittest/force-styles/tests/improper-cvff.yaml +++ b/unittest/force-styles/tests/improper-cvff.yaml @@ -13,7 +13,10 @@ improper_style: cvff improper_coeff: ! | 1 75.0 -1 5 2 45.0 +1 2 -extract: ! "" +extract: ! | + k 1 + sign 1 + multiplicity 1 natoms: 29 init_energy: 89.33266688553577 init_stress: ! |2- From 61f40123004fa09676f413d184a3cce6b1d0bc38 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 21:14:46 +0200 Subject: [PATCH 025/120] Update unit test in improper-harmonic.yaml --- unittest/force-styles/tests/improper-harmonic.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-harmonic.yaml b/unittest/force-styles/tests/improper-harmonic.yaml index 7ac0dbe06e..a7d2d44b64 100644 --- a/unittest/force-styles/tests/improper-harmonic.yaml +++ b/unittest/force-styles/tests/improper-harmonic.yaml @@ -13,7 +13,9 @@ improper_style: harmonic improper_coeff: ! | 1 75.0 120.2 2 45.0 59.5 -extract: ! "" +extract: ! | + k 1 + chi 1 natoms: 29 init_energy: 369.34096479618404 init_stress: ! |2- From 72d2b70125dd823f0bc320316e56980bd461f9c6 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 21:15:28 +0200 Subject: [PATCH 026/120] Update unit test in improper-ring.yaml --- unittest/force-styles/tests/improper-ring.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-ring.yaml b/unittest/force-styles/tests/improper-ring.yaml index 6a824f9699..31e8c2ac62 100644 --- a/unittest/force-styles/tests/improper-ring.yaml +++ b/unittest/force-styles/tests/improper-ring.yaml @@ -13,7 +13,9 @@ improper_style: ring improper_coeff: ! | 1 75.0 120.2 2 45.0 59.5 -extract: ! "" +extract: ! | + k 1 + chi 1 natoms: 29 init_energy: 31535.23771704055 init_stress: ! |- From 22898fc8fc6037e052f09ccd97cb075c0f3a52b0 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 21:16:33 +0200 Subject: [PATCH 027/120] Update unit test in improper-distharm.yaml --- unittest/force-styles/tests/improper-distharm.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-distharm.yaml b/unittest/force-styles/tests/improper-distharm.yaml index e2916d3d74..5a3f4e08a5 100644 --- a/unittest/force-styles/tests/improper-distharm.yaml +++ b/unittest/force-styles/tests/improper-distharm.yaml @@ -13,7 +13,9 @@ improper_style: distharm improper_coeff: ! | 1 75.0 5.5 2 45.0 6.2 -extract: ! "" +extract: ! | + k 1 + chi 1 natoms: 29 init_energy: 3973.601605432119 init_stress: ! |2- From 33f50574880ca544dc0bce12dfcd7446a83b5f06 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 21:17:27 +0200 Subject: [PATCH 028/120] Update unit test in improper-distance.yaml --- unittest/force-styles/tests/improper-distance.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-distance.yaml b/unittest/force-styles/tests/improper-distance.yaml index 91df7b7bae..800c19ce06 100644 --- a/unittest/force-styles/tests/improper-distance.yaml +++ b/unittest/force-styles/tests/improper-distance.yaml @@ -13,7 +13,9 @@ improper_style: distance improper_coeff: ! | 1 75.0 120.2 2 45.0 59.5 -extract: ! "" +extract: ! | + k 1 + chi 1 natoms: 29 init_energy: 0.0747454910197192 init_stress: ! |- From f9b7013af36c69ec8be902f54682ad3fac6062dc Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 21:18:53 +0200 Subject: [PATCH 029/120] Update unit test in improper-sqdistharm.yaml --- unittest/force-styles/tests/improper-sqdistharm.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-sqdistharm.yaml b/unittest/force-styles/tests/improper-sqdistharm.yaml index 8bf671efbd..74ff07bb9a 100644 --- a/unittest/force-styles/tests/improper-sqdistharm.yaml +++ b/unittest/force-styles/tests/improper-sqdistharm.yaml @@ -13,7 +13,9 @@ improper_style: sqdistharm improper_coeff: ! | 1 75.0 5.5 2 45.0 6.2 -extract: ! "" +extract: ! | + k 1 + chi 1 natoms: 29 init_energy: 3997.62616072489 init_stress: ! |2- From c918c7b5475f56561493036686e58a57100906af Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 21:20:41 +0200 Subject: [PATCH 030/120] Update unit test in improper-inversion_harmonic.yaml --- unittest/force-styles/tests/improper-inversion_harmonic.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-inversion_harmonic.yaml b/unittest/force-styles/tests/improper-inversion_harmonic.yaml index 73eade4958..7697908c23 100644 --- a/unittest/force-styles/tests/improper-inversion_harmonic.yaml +++ b/unittest/force-styles/tests/improper-inversion_harmonic.yaml @@ -13,7 +13,9 @@ improper_style: inversion/harmonic improper_coeff: ! | 1 75.0 0.1 2 45.0 1.0 -extract: ! "" +extract: ! | + kw 1 + w0 1 natoms: 29 init_energy: 0.35230115027159387 init_stress: ! |- From ced5fd32404788703cd768b03b443d73c78dbb0a Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 21:22:05 +0200 Subject: [PATCH 031/120] Update unit test in improper-umbrella.yaml --- unittest/force-styles/tests/improper-umbrella.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-umbrella.yaml b/unittest/force-styles/tests/improper-umbrella.yaml index ff6822e9d8..604c039c28 100644 --- a/unittest/force-styles/tests/improper-umbrella.yaml +++ b/unittest/force-styles/tests/improper-umbrella.yaml @@ -13,7 +13,9 @@ improper_style: umbrella improper_coeff: ! | 1 75.0 120.2 2 45.0 59.5 -extract: ! "" +extract: ! | + kw 1 + w0 1 natoms: 29 init_energy: 120.51735030260785 init_stress: ! |2- From 2440564befe12b04455eb5254b032f1b63c8a934 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Thu, 6 Feb 2025 21:23:36 +0200 Subject: [PATCH 032/120] Update unit test in improper-cossq.yaml --- unittest/force-styles/tests/improper-cossq.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-cossq.yaml b/unittest/force-styles/tests/improper-cossq.yaml index 4faaa2214a..567e45da55 100644 --- a/unittest/force-styles/tests/improper-cossq.yaml +++ b/unittest/force-styles/tests/improper-cossq.yaml @@ -13,7 +13,9 @@ improper_style: cossq improper_coeff: ! | 1 75.0 120.2 2 45.0 59.5 -extract: ! "" +extract: ! | + k 1 + chi 1 natoms: 29 init_energy: 47.901206451962224 init_stress: ! |- From 909796b85817d58a18b451228943a1885d2d6e31 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Fri, 7 Feb 2025 09:28:18 +0200 Subject: [PATCH 033/120] define extract for improper class2 --- src/CLASS2/improper_class2.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CLASS2/improper_class2.h b/src/CLASS2/improper_class2.h index 6102ef945c..3e30c8be53 100644 --- a/src/CLASS2/improper_class2.h +++ b/src/CLASS2/improper_class2.h @@ -33,6 +33,7 @@ class ImproperClass2 : public Improper { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; protected: double *k0, *chi0; From 26e1b5d10188b5a5c569ea3665fc78323f8f7314 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Fri, 7 Feb 2025 09:29:41 +0200 Subject: [PATCH 034/120] implement extract in improper_class2.cpp --- src/CLASS2/improper_class2.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/CLASS2/improper_class2.cpp b/src/CLASS2/improper_class2.cpp index 73f21600bb..a59648c79c 100644 --- a/src/CLASS2/improper_class2.cpp +++ b/src/CLASS2/improper_class2.cpp @@ -843,3 +843,15 @@ void ImproperClass2::write_data(FILE *fp) aa_theta0_1[i]*180.0/MY_PI,aa_theta0_2[i]*180.0/MY_PI, aa_theta0_3[i]*180.0/MY_PI); } + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperClass2::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k0") == 0) return (void *) k0; + if (strcmp(str, "chi0") == 0) return (void *) chi0; + return nullptr; +} From d384de354abbfdec6418049a7fbfb6d9d8e06d79 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Fri, 7 Feb 2025 09:31:28 +0200 Subject: [PATCH 035/120] Update unit test in improper-class2.yaml --- unittest/force-styles/tests/improper-class2.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-class2.yaml b/unittest/force-styles/tests/improper-class2.yaml index 4350441eeb..d60ae48602 100644 --- a/unittest/force-styles/tests/improper-class2.yaml +++ b/unittest/force-styles/tests/improper-class2.yaml @@ -14,7 +14,9 @@ improper_coeff: ! | 1 75.0 169 2 45.0 10 * aa 75 42 31 125.4 130.01 115.06 -extract: ! "" +extract: ! | + k0 1 + chi0 1 natoms: 29 init_energy: 1375.7372366975192 init_stress: ! |- From 38d28fb426e23b7aa10b52b8203406ffb04f5b43 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sat, 8 Feb 2025 18:55:33 +0200 Subject: [PATCH 036/120] define extract for improper amoeba --- src/AMOEBA/improper_amoeba.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AMOEBA/improper_amoeba.h b/src/AMOEBA/improper_amoeba.h index d5a783a82f..f997b61629 100644 --- a/src/AMOEBA/improper_amoeba.h +++ b/src/AMOEBA/improper_amoeba.h @@ -34,6 +34,7 @@ class ImproperAmoeba : public Improper { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; protected: int disable; From 66117414ddfa404842467d2b1a06460ad64d18c9 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sat, 8 Feb 2025 18:56:38 +0200 Subject: [PATCH 037/120] implement extract in improper_amoeba.cpp --- src/AMOEBA/improper_amoeba.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/AMOEBA/improper_amoeba.cpp b/src/AMOEBA/improper_amoeba.cpp index cbc7fbd8d2..60e16deba2 100644 --- a/src/AMOEBA/improper_amoeba.cpp +++ b/src/AMOEBA/improper_amoeba.cpp @@ -337,3 +337,14 @@ void ImproperAmoeba::write_data(FILE *fp) for (int i = 1; i <= atom->nimpropertypes; i++) fprintf(fp,"%d %g\n",i,k[i]); } + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperAmoeba::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k; + return nullptr; +} From 2a2a7a3113b439218795b95cccd5806ae988c049 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sat, 8 Feb 2025 19:01:56 +0200 Subject: [PATCH 038/120] define extract in improper_fourier.h --- src/EXTRA-MOLECULE/improper_fourier.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/EXTRA-MOLECULE/improper_fourier.h b/src/EXTRA-MOLECULE/improper_fourier.h index 96354b6818..a4ec0d6096 100644 --- a/src/EXTRA-MOLECULE/improper_fourier.h +++ b/src/EXTRA-MOLECULE/improper_fourier.h @@ -33,6 +33,7 @@ class ImproperFourier : public Improper { void write_restart(FILE *) override; void read_restart(FILE *) override; void write_data(FILE *) override; + void *extract(const char *, int &) override; protected: double *k, *C0, *C1, *C2; From e954bdfc14d979e13e3b55153d02fca6d3551b3a Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sat, 8 Feb 2025 19:04:43 +0200 Subject: [PATCH 039/120] implement extract in improper_fourier.cpp --- src/EXTRA-MOLECULE/improper_fourier.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/EXTRA-MOLECULE/improper_fourier.cpp b/src/EXTRA-MOLECULE/improper_fourier.cpp index 1db8b3697c..71af2c804d 100644 --- a/src/EXTRA-MOLECULE/improper_fourier.cpp +++ b/src/EXTRA-MOLECULE/improper_fourier.cpp @@ -337,3 +337,17 @@ void ImproperFourier::write_data(FILE *fp) for (int i = 1; i <= atom->nimpropertypes; i++) fprintf(fp,"%d %g %g %g %g %d\n",i,k[i],C0[i],C1[i],C2[i],all[i]); } + +/* ---------------------------------------------------------------------- + return ptr to internal members upon request +------------------------------------------------------------------------ */ + +void *ImproperFourier::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str, "k") == 0) return (void *) k; + if (strcmp(str, "C0") == 0) return (void *) C0; + if (strcmp(str, "C1") == 0) return (void *) C1; + if (strcmp(str, "C2") == 0) return (void *) C2; + return nullptr; +} From 49b5e89258539a33b9d8869dc7f3e104f09dd2f0 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sat, 8 Feb 2025 19:06:08 +0200 Subject: [PATCH 040/120] Update unit test in improper-fourier.yaml --- unittest/force-styles/tests/improper-fourier.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-fourier.yaml b/unittest/force-styles/tests/improper-fourier.yaml index 278698a190..096d9c0fa1 100644 --- a/unittest/force-styles/tests/improper-fourier.yaml +++ b/unittest/force-styles/tests/improper-fourier.yaml @@ -13,7 +13,11 @@ improper_style: fourier improper_coeff: ! | 1 75.0 0.9 0.2 0.3 1 2 45.0 0.5 0.1 0.8 0 -extract: ! "" +extract: ! | + k 1 + C0 1 + C1 1 + C2 1 natoms: 29 init_energy: 376.7915390602297 init_stress: ! |2- From e4a16556dbbb8a1ea258bf0c2ffedf876f47fa29 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sun, 9 Feb 2025 14:26:28 +0200 Subject: [PATCH 041/120] implement the actual code to adapt improper parameters in fix_adapt.cpp --- src/fix_adapt.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/src/fix_adapt.cpp b/src/fix_adapt.cpp index 24c09d5081..08bc7263c4 100644 --- a/src/fix_adapt.cpp +++ b/src/fix_adapt.cpp @@ -50,7 +50,7 @@ enum{DIAMETER, CHARGE}; FixAdapt::FixAdapt(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), nadapt(0), anypair(0), anybond(0), anyangle(0), - id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr) + anyimproper(0), id_fix_diam(nullptr), id_fix_chg(nullptr), adapt(nullptr) { if (narg < 5) utils::missing_cmd_args(FLERR,"fix adapt", error); nevery = utils::inumeric(FLERR,arg[3],false,lmp); @@ -85,6 +85,10 @@ FixAdapt::FixAdapt(LAMMPS *lmp, int narg, char **arg) : if (iarg+5 > narg) utils::missing_cmd_args(FLERR,"fix adapt angle", error); nadapt++; iarg += 5; + } else if (strcmp(arg[iarg],"improper") == 0) { + if (iarg+5 > narg) utils::missing_cmd_args(FLERR,"fix adapt improper", error); + nadapt++; + iarg += 5; } else break; } @@ -151,6 +155,19 @@ FixAdapt::FixAdapt(LAMMPS *lmp, int narg, char **arg) : nadapt++; iarg += 5; + } else if (strcmp(arg[iarg],"improper") == 0) { + adapt[nadapt].which = IMPROPER; + adapt[nadapt].improper = nullptr; + adapt[nadapt].istyle = utils::strdup(arg[iarg+1]); + adapt[nadapt].iparam = utils::strdup(arg[iarg+2]); + utils::bounds_typelabel(FLERR, arg[iarg+3], 1, atom->nimpropertypes, + adapt[nadapt].ilo, adapt[nadapt].ihi, lmp, Atom::IMPROPER); + if (utils::strmatch(arg[iarg+4],"^v_")) { + adapt[nadapt].var = utils::strdup(arg[iarg+4]+2); + } else error->all(FLERR,"Argument #{} must be variable not {}", iarg+5, arg[iarg+4]); + nadapt++; + iarg += 5; + } else if (strcmp(arg[iarg],"kspace") == 0) { adapt[nadapt].which = KSPACE; if (utils::strmatch(arg[iarg+1],"^v_")) { @@ -225,6 +242,13 @@ FixAdapt::FixAdapt(LAMMPS *lmp, int narg, char **arg) : n = atom->nangletypes; for (int m = 0; m < nadapt; ++m) if (adapt[m].which == ANGLE) memory->create(adapt[m].vector_orig,n+1,"adapt:vector_orig"); + + // allocate improper style arrays: + + n = atom->nimpropertypes; + for (int m = 0; m < nadapt; ++m) + if (adapt[m].which == IMPROPER) memory->create(adapt[m].vector_orig,n+1,"adapt:vector_orig"); + } /* ---------------------------------------------------------------------- */ @@ -245,6 +269,10 @@ FixAdapt::~FixAdapt() delete[] adapt[m].astyle; delete[] adapt[m].aparam; memory->destroy(adapt[m].vector_orig); + } else if (adapt[m].which == IMPROPER) { + delete[] adapt[m].istyle; + delete[] adapt[m].iparam; + memory->destroy(adapt[m].vector_orig); } } delete[] adapt; @@ -338,6 +366,7 @@ void FixAdapt::init() anypair = 0; anybond = 0; anyangle = 0; + anyimproper = 0; for (int m = 0; m < nadapt; m++) { Adapt *ad = &adapt[m]; @@ -471,6 +500,40 @@ void FixAdapt::init() delete[] astyle; + } else if (ad->which == IMPROPER) { + ad->improper = nullptr; + anyimproper = 1; + + char *istyle = utils::strdup(ad->istyle); + if (lmp->suffix_enable) + ad->improper = force->improper_match(fmt::format("{}/{}",istyle,lmp->suffix)); + + if (ad->improper == nullptr) ad->improper = force->improper_match(istyle); + if (ad->improper == nullptr ) + error->all(FLERR,"Fix adapt improper style {} does not exist", istyle); + + void *ptr = ad->improper->extract(ad->iparam,ad->idim); + + if (ptr == nullptr) + error->all(FLERR,"Fix adapt improper style parameter {} not supported", ad->iparam); + + // for improper styles, use a vector + + if (ad->idim == 1) ad->vector = (double *) ptr; + + if (utils::strmatch(force->improper_style,"^hybrid")) { + auto improper = dynamic_cast(force->improper); + if (improper) { + for (i = ad->ilo; i <= ad->ihi; i++) { + if (!improper->check_itype(i,istyle)) + error->all(FLERR,"Fix adapt type improper range is not valid " + "for improper hybrid sub-style {}", istyle); + } + } + } + + delete[] istyle; + } else if (ad->which == KSPACE) { if (force->kspace == nullptr) error->all(FLERR,"Fix adapt expected a kspace style but none was defined"); @@ -496,7 +559,7 @@ void FixAdapt::init() if (restart_reset) restart_reset = 0; - // make copy of original pair/bond/angle array values + // make copy of original pair/bond/angle/improper array values for (int m = 0; m < nadapt; m++) { Adapt *ad = &adapt[m]; @@ -516,6 +579,11 @@ void FixAdapt::init() ad->vector_orig[i] = ad->vector[i]; } + } else if (ad->which == IMPROPER && ad->idim == 1) { + for (i = ad->ilo; i <= ad->ihi; ++i ) + ad->vector_orig[i] = ad->vector[i]; + } + } // fixes that store initial per-atom values @@ -629,6 +697,18 @@ void FixAdapt::change_settings() ad->vector[i] = value; } + // set improper type array values: + + } else if (ad->which == IMPROPER) { + if (ad->idim == 1) { + if (scaleflag) + for (i = ad->ilo; i <= ad->ihi; ++i ) + ad->vector[i] = value*ad->vector_orig[i]; + else + for (i = ad->ilo; i <= ad->ihi; ++i ) + ad->vector[i] = value; + } + // set kspace scale factor } else if (ad->which == KSPACE) { @@ -704,6 +784,7 @@ void FixAdapt::change_settings() if (anypair) force->pair->reinit(); if (anybond) force->bond->reinit(); if (anyangle) force->angle->reinit(); + if (anyimproper) force->improper->reinit(); // reset KSpace charges if charges have changed @@ -738,6 +819,12 @@ void FixAdapt::restore_settings() ad->vector[i] = ad->vector_orig[i]; } + } else if (ad->which == IMPROPER) { + if (ad->idim == 1) { + for (int i = ad->ilo; i <= ad->ihi; i++) + ad->vector[i] = ad->vector_orig[i]; + } + } else if (ad->which == KSPACE) { *kspace_scale = 1.0; @@ -778,6 +865,7 @@ void FixAdapt::restore_settings() if (anypair) force->pair->reinit(); if (anybond) force->bond->reinit(); if (anyangle) force->angle->reinit(); + if (anyimproper) force->improper->reinit(); if (chgflag && force->kspace) force->kspace->qsum_qsq(); } From f7a43b94a61ac4dc900260eec5c7d9574337de0e Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sun, 9 Feb 2025 14:39:48 +0200 Subject: [PATCH 042/120] =?UTF-8?q?fix=20error:=20=E2=80=98else=E2=80=99?= =?UTF-8?q?=20without=20a=20previous=20=E2=80=98if=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fix_adapt.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fix_adapt.cpp b/src/fix_adapt.cpp index 08bc7263c4..c5f8f64857 100644 --- a/src/fix_adapt.cpp +++ b/src/fix_adapt.cpp @@ -577,7 +577,6 @@ void FixAdapt::init() } else if (ad->which == ANGLE && ad->adim == 1) { for (i = ad->ilo; i <= ad->ihi; ++i ) ad->vector_orig[i] = ad->vector[i]; - } } else if (ad->which == IMPROPER && ad->idim == 1) { for (i = ad->ilo; i <= ad->ihi; ++i ) From c0ef702af550d0ff90bdb2acffc3f950621bdba0 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sun, 9 Feb 2025 14:46:18 +0200 Subject: [PATCH 043/120] define chech_itype in improper_hybrid.h --- src/improper_hybrid.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/improper_hybrid.h b/src/improper_hybrid.h index 89a4664da2..86df8ea9d0 100644 --- a/src/improper_hybrid.h +++ b/src/improper_hybrid.h @@ -40,6 +40,8 @@ class ImproperHybrid : public Improper { void read_restart(FILE *) override; double memory_usage() override; + int check_itype(int, char *); + protected: int *map; // which style each improper type points to From fe3c8487de194c4391fc557c95a891d053dc72cb Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sun, 9 Feb 2025 14:48:10 +0200 Subject: [PATCH 044/120] implement check_itype in improper_hybrid.cpp --- src/improper_hybrid.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/improper_hybrid.cpp b/src/improper_hybrid.cpp index 5337f062b4..1edfe5ceb7 100644 --- a/src/improper_hybrid.cpp +++ b/src/improper_hybrid.cpp @@ -320,6 +320,14 @@ void ImproperHybrid::init_style() if (styles[m]) styles[m]->init_style(); } +/* ---------------------------------------------------------------------- */ + +int ImproperHybrid::check_itype(int itype, char *substyle) +{ + if (strcmp(keywords[map[itype]], substyle) == 0) return 1; + return 0; +} + /* ---------------------------------------------------------------------- proc 0 writes to restart file ------------------------------------------------------------------------- */ From d11c8b3e1e498984a1219478c6f7a230cfa9e3ac Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sun, 9 Feb 2025 15:08:02 +0200 Subject: [PATCH 045/120] Update text for improper style in fix_adapt.rst Update text though a table with the potentials is not included --- doc/src/fix_adapt.rst | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index 93bd8da041..44a096b6ac 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -14,7 +14,7 @@ Syntax * adapt = style name of this fix command * N = adapt simulation settings every this many timesteps * one or more attribute/arg pairs may be appended -* attribute = *pair* or *bond* or *angle* or *kspace* or *atom* +* attribute = *pair* or *bond* or *angle* or *improper* or *kspace* or *atom* .. parsed-literal:: @@ -33,6 +33,11 @@ Syntax aparam = parameter to adapt over time I = type angle to set parameter for (integer or type label) v_name = variable with name that calculates value of aparam + *improper* args = istyle iparam I v_name + istyle = improper style name (e.g., cvff) + iparam = parameter to adapt over time + I = type improper to set parameter for (integer or type label) + v_name = variable with name that calculates value of iparam *kspace* arg = v_name v_name = variable with name that calculates scale factor on :math:`k`-space terms *atom* args = atomparam v_name @@ -418,6 +423,30 @@ this fix uses to reset theta0 needs to generate values in radians. ---------- +.. versionadded:: TBD + +The *improper* keyword uses the specified variable to change the value of +an improper coefficient over time, very similar to how the *angle* keyword +operates. The only difference is that now an improper coefficient for a +given improper type is adapted. + +A wild-card asterisk can be used in place of or in conjunction with the +improper type argument to set the coefficients for multiple improper types. +This takes the form "\*" or "\*n" or "m\*" or "m\*n". If :math:`N` is +the number of improper types, then an asterisk with no numeric values means +all types from 1 to :math:`N`. A leading asterisk means all types from +1 to n (inclusive). A trailing asterisk means all types from m to +:math:`N` (inclusive). A middle asterisk means all types from m to n +(inclusive). + +If :doc:`improper_style hybrid ` is used, *istyle* should be a +sub-style name. The improper styles that currently work with fix adapt are: + +Note that internally, chi0 is stored in radians, so the variable +this fix uses to reset chi0 needs to generate values in radians. + +---------- + The *kspace* keyword used the specified variable as a scale factor on the energy, forces, virial calculated by whatever :math:`k`-space solver is defined by the :doc:`kspace_style ` command. If the From 7cf3ff588ed4d00ad41b4c23f51667e458ea482a Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sun, 9 Feb 2025 16:54:15 +0200 Subject: [PATCH 046/120] include table with impropers in fix_adapt.rst --- doc/src/fix_adapt.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index 44a096b6ac..5e44238c7e 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -442,6 +442,32 @@ all types from 1 to :math:`N`. A leading asterisk means all types from If :doc:`improper_style hybrid ` is used, *istyle* should be a sub-style name. The improper styles that currently work with fix adapt are: ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`amoeba ` | k | type impropers | ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`class2 ` | k0,chi0 | type impropers | ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`cossq ` | k,chi | type impropers | ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`cvff ` | k,sign,multiplicity | type impropers | ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`distance ` | k,chi | type impropers | ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`distharm ` | k,chi | type impropers | ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`fourier ` | k,C0,C1,C2 | type impropers | ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`harmonic ` | k,chi | type impropers | ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`inversion/harmonic ` | kw,w0 | type impropers | ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`ring ` | k,chi | type impropers | ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`umbrella ` | kw,w0 | type impropers | ++---------------------------------------------------------+----------------------+----------------+ +| :doc:`sqdistharm ` | k,chi | type impropers | ++---------------------------------------------------------+----------------------+----------------+ + Note that internally, chi0 is stored in radians, so the variable this fix uses to reset chi0 needs to generate values in radians. From 6abdedc75b26105a5fb46967ebb16c1a6bfa41b9 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 18:34:15 +0200 Subject: [PATCH 047/120] change chi to chi0 in improper-harmonic.yaml --- unittest/force-styles/tests/improper-harmonic.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-harmonic.yaml b/unittest/force-styles/tests/improper-harmonic.yaml index a7d2d44b64..7b2e14ee9e 100644 --- a/unittest/force-styles/tests/improper-harmonic.yaml +++ b/unittest/force-styles/tests/improper-harmonic.yaml @@ -15,7 +15,7 @@ improper_coeff: ! | 2 45.0 59.5 extract: ! | k 1 - chi 1 + chi0 1 natoms: 29 init_energy: 369.34096479618404 init_stress: ! |2- From ec0afc3fdfefbc4b157bcd42cac6035f5077dcbb Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 18:35:37 +0200 Subject: [PATCH 048/120] change chi to chi0 in improper_harmonic.h --- src/MOLECULE/improper_harmonic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MOLECULE/improper_harmonic.h b/src/MOLECULE/improper_harmonic.h index a0047c28f2..05cb992011 100644 --- a/src/MOLECULE/improper_harmonic.h +++ b/src/MOLECULE/improper_harmonic.h @@ -36,7 +36,7 @@ class ImproperHarmonic : public Improper { void *extract(const char *, int &) override; protected: - double *k, *chi; + double *k, *chi0; virtual void allocate(); }; From f6e39d14b0ba261c4f46cc1dcd7b2683f8cee9cd Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 18:37:47 +0200 Subject: [PATCH 049/120] change chi to chi0 in improper_harmonic.cpp --- src/MOLECULE/improper_harmonic.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/MOLECULE/improper_harmonic.cpp b/src/MOLECULE/improper_harmonic.cpp index b9fda62343..3e4bb35940 100644 --- a/src/MOLECULE/improper_harmonic.cpp +++ b/src/MOLECULE/improper_harmonic.cpp @@ -48,7 +48,7 @@ ImproperHarmonic::~ImproperHarmonic() if (allocated && !copymode) { memory->destroy(setflag); memory->destroy(k); - memory->destroy(chi); + memory->destroy(chi0); } } @@ -131,7 +131,7 @@ void ImproperHarmonic::compute(int eflag, int vflag) // force & energy - domega = acos(c) - chi[type]; + domega = acos(c) - chi0[type]; a = k[type] * domega; if (eflag) eimproper = a * domega; @@ -206,7 +206,7 @@ void ImproperHarmonic::allocate() const int np1 = atom->nimpropertypes + 1; memory->create(k, np1, "improper:k"); - memory->create(chi, np1, "improper:chi"); + memory->create(chi0, np1, "improper:chi0"); memory->create(setflag, np1, "improper:setflag"); for (int i = 1; i < np1; i++) setflag[i] = 0; } @@ -226,12 +226,12 @@ void ImproperHarmonic::coeff(int narg, char **arg) double k_one = utils::numeric(FLERR, arg[1], false, lmp); double chi_one = utils::numeric(FLERR, arg[2], false, lmp); - // convert chi from degrees to radians + // convert chi0 from degrees to radians int count = 0; for (int i = ilo; i <= ihi; i++) { k[i] = k_one; - chi[i] = DEG2RAD * chi_one; + chi0[i] = DEG2RAD * chi_one; setflag[i] = 1; count++; } @@ -246,7 +246,7 @@ void ImproperHarmonic::coeff(int narg, char **arg) void ImproperHarmonic::write_restart(FILE *fp) { fwrite(&k[1], sizeof(double), atom->nimpropertypes, fp); - fwrite(&chi[1], sizeof(double), atom->nimpropertypes, fp); + fwrite(&chi0[1], sizeof(double), atom->nimpropertypes, fp); } /* ---------------------------------------------------------------------- @@ -259,10 +259,10 @@ void ImproperHarmonic::read_restart(FILE *fp) if (comm->me == 0) { utils::sfread(FLERR, &k[1], sizeof(double), atom->nimpropertypes, fp, nullptr, error); - utils::sfread(FLERR, &chi[1], sizeof(double), atom->nimpropertypes, fp, nullptr, error); + utils::sfread(FLERR, &chi0[1], sizeof(double), atom->nimpropertypes, fp, nullptr, error); } MPI_Bcast(&k[1], atom->nimpropertypes, MPI_DOUBLE, 0, world); - MPI_Bcast(&chi[1], atom->nimpropertypes, MPI_DOUBLE, 0, world); + MPI_Bcast(&chi0[1], atom->nimpropertypes, MPI_DOUBLE, 0, world); for (int i = 1; i <= atom->nimpropertypes; i++) setflag[i] = 1; } @@ -274,7 +274,7 @@ void ImproperHarmonic::read_restart(FILE *fp) void ImproperHarmonic::write_data(FILE *fp) { for (int i = 1; i <= atom->nimpropertypes; i++) - fprintf(fp, "%d %g %g\n", i, k[i], RAD2DEG * chi[i]); + fprintf(fp, "%d %g %g\n", i, k[i], RAD2DEG * chi0[i]); } /* ---------------------------------------------------------------------- @@ -285,6 +285,6 @@ void *ImproperHarmonic::extract(const char *str, int &dim) { dim = 1; if (strcmp(str, "k") == 0) return (void *) k; - if (strcmp(str, "chi") == 0) return (void *) chi; + if (strcmp(str, "chi0") == 0) return (void *) chi0; return nullptr; } From 261cc13f991ade766f7635c482b0eb23767a7d71 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 18:39:13 +0200 Subject: [PATCH 050/120] Update fix_adapt.rst --- doc/src/fix_adapt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index 5e44238c7e..5c4eb63212 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -457,7 +457,7 @@ sub-style name. The improper styles that currently work with fix adapt are: +---------------------------------------------------------+----------------------+----------------+ | :doc:`fourier ` | k,C0,C1,C2 | type impropers | +---------------------------------------------------------+----------------------+----------------+ -| :doc:`harmonic ` | k,chi | type impropers | +| :doc:`harmonic ` | k,chi0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ | :doc:`inversion/harmonic ` | kw,w0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ From 8dfb967accd5e5bbf9a5eba166a7f364531a27cc Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 18:42:07 +0200 Subject: [PATCH 051/120] change chi to chi0 in improper-cossq.yaml --- unittest/force-styles/tests/improper-cossq.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-cossq.yaml b/unittest/force-styles/tests/improper-cossq.yaml index 567e45da55..2e2767d368 100644 --- a/unittest/force-styles/tests/improper-cossq.yaml +++ b/unittest/force-styles/tests/improper-cossq.yaml @@ -15,7 +15,7 @@ improper_coeff: ! | 2 45.0 59.5 extract: ! | k 1 - chi 1 + chi0 1 natoms: 29 init_energy: 47.901206451962224 init_stress: ! |- From 9bce6662b429236de95ab2f3edc15ed7bef51ec1 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 18:42:55 +0200 Subject: [PATCH 052/120] change chi to chi0 in improper_cossq.h --- src/EXTRA-MOLECULE/improper_cossq.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EXTRA-MOLECULE/improper_cossq.h b/src/EXTRA-MOLECULE/improper_cossq.h index bcc12e654f..485ba3a9cb 100644 --- a/src/EXTRA-MOLECULE/improper_cossq.h +++ b/src/EXTRA-MOLECULE/improper_cossq.h @@ -36,7 +36,7 @@ class ImproperCossq : public Improper { void *extract(const char *, int &) override; protected: - double *k, *chi; + double *k, *chi0; void allocate(); }; From e90d5133cc57f12f2f92ebc5bd5595c612972619 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 18:44:40 +0200 Subject: [PATCH 053/120] change chi to chi0 in improper_cossq.cpp --- src/EXTRA-MOLECULE/improper_cossq.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/EXTRA-MOLECULE/improper_cossq.cpp b/src/EXTRA-MOLECULE/improper_cossq.cpp index a25d324261..75ab4e26fa 100644 --- a/src/EXTRA-MOLECULE/improper_cossq.cpp +++ b/src/EXTRA-MOLECULE/improper_cossq.cpp @@ -51,7 +51,7 @@ ImproperCossq::~ImproperCossq() if (allocated) { memory->destroy(setflag); memory->destroy(k); - memory->destroy(chi); + memory->destroy(chi0); } } @@ -114,7 +114,7 @@ void ImproperCossq::compute(int eflag, int vflag) /* Calculate the angle: */ double torangle = acos(cosphi); - cosphi = cos(torangle - chi[type]); + cosphi = cos(torangle - chi0[type]); if (eflag) eimproper = 0.5 * k[type] * cosphi * cosphi; @@ -237,7 +237,7 @@ void ImproperCossq::allocate() int n = atom->nimpropertypes; memory->create(k,n+1,"improper:k"); - memory->create(chi,n+1,"improper:chi"); + memory->create(chi0,n+1,"improper:chi0"); memory->create(setflag,n+1,"improper:setflag"); for (int i = 1; i <= n; i++) setflag[i] = 0; @@ -265,7 +265,7 @@ void ImproperCossq::coeff(int narg, char **arg) int count = 0; for (int i = ilo; i <= ihi; i++) { k[i] = k_one; - chi[i] = ((chi_one * MY_PI)/180.0); + chi0[i] = ((chi_one * MY_PI)/180.0); setflag[i] = 1; count++; } @@ -279,7 +279,7 @@ void ImproperCossq::coeff(int narg, char **arg) void ImproperCossq::write_restart(FILE *fp) { fwrite(&k[1],sizeof(double),atom->nimpropertypes,fp); - fwrite(&chi[1],sizeof(double),atom->nimpropertypes,fp); + fwrite(&chi0[1],sizeof(double),atom->nimpropertypes,fp); } /* ---------------------------------------------------------------------- @@ -291,10 +291,10 @@ void ImproperCossq::read_restart(FILE *fp) if (comm->me == 0) { utils::sfread(FLERR,&k[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); - utils::sfread(FLERR,&chi[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); + utils::sfread(FLERR,&chi0[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); } MPI_Bcast(&k[1],atom->nimpropertypes,MPI_DOUBLE,0,world); - MPI_Bcast(&chi[1],atom->nimpropertypes,MPI_DOUBLE,0,world); + MPI_Bcast(&chi0[1],atom->nimpropertypes,MPI_DOUBLE,0,world); for (int i = 1; i <= atom->nimpropertypes; i++) setflag[i] = 1; } @@ -306,7 +306,7 @@ void ImproperCossq::read_restart(FILE *fp) void ImproperCossq::write_data(FILE *fp) { for (int i = 1; i <= atom->nimpropertypes; i++) - fprintf(fp,"%d %g %g\n",i,k[i],chi[i]/MY_PI*180.0); + fprintf(fp,"%d %g %g\n",i,k[i],chi0[i]/MY_PI*180.0); } /* ---------------------------------------------------------------------- @@ -317,6 +317,6 @@ void *ImproperCossq::extract(const char *str, int &dim) { dim = 1; if (strcmp(str, "k") == 0) return (void *) k; - if (strcmp(str, "chi") == 0) return (void *) chi; + if (strcmp(str, "chi0") == 0) return (void *) chi0; return nullptr; } From 5251ba146507767c6d1fcce82592038954f79593 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 18:45:40 +0200 Subject: [PATCH 054/120] change chi to chi0 in fix_adapt.rst --- doc/src/fix_adapt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index 5c4eb63212..bd5cc628df 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -447,7 +447,7 @@ sub-style name. The improper styles that currently work with fix adapt are: +---------------------------------------------------------+----------------------+----------------+ | :doc:`class2 ` | k0,chi0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ -| :doc:`cossq ` | k,chi | type impropers | +| :doc:`cossq ` | k,chi0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ | :doc:`cvff ` | k,sign,multiplicity | type impropers | +---------------------------------------------------------+----------------------+----------------+ From 7fe804d19d24ebd1cf50c90d0cc0cf526e4b4564 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 19:00:21 +0200 Subject: [PATCH 055/120] change chi to chi0 in improper_cossq_omp.cpp --- src/OPENMP/improper_cossq_omp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OPENMP/improper_cossq_omp.cpp b/src/OPENMP/improper_cossq_omp.cpp index 4ccc0d730a..7f294522fa 100644 --- a/src/OPENMP/improper_cossq_omp.cpp +++ b/src/OPENMP/improper_cossq_omp.cpp @@ -134,7 +134,7 @@ void ImproperCossqOMP::eval(int nfrom, int nto, ThrData * const thr) /* Calculate the angle: */ double torangle = acos(cosphi); - cosphi = cos(torangle - chi[type]); + cosphi = cos(torangle - chi0[type]); if (EFLAG) eimproper = 0.5 * k[type] * cosphi * cosphi; From 3f5c54e362e25baeef8746ec06c5fdebf19bbfb4 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 19:00:55 +0200 Subject: [PATCH 056/120] change chi to chi0 in improper_harmonic_omp.cpp --- src/OPENMP/improper_harmonic_omp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OPENMP/improper_harmonic_omp.cpp b/src/OPENMP/improper_harmonic_omp.cpp index 12c2699663..15b1af6934 100644 --- a/src/OPENMP/improper_harmonic_omp.cpp +++ b/src/OPENMP/improper_harmonic_omp.cpp @@ -156,7 +156,7 @@ void ImproperHarmonicOMP::eval(int nfrom, int nto, ThrData * const thr) // force & energy - domega = acos(c) - chi[type]; + domega = acos(c) - chi0[type]; a = k[type] * domega; if (EFLAG) eimproper = a*domega; From 0c80ec5e0de8ed306bee284f7d0f302e59131e7e Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 19:06:14 +0200 Subject: [PATCH 057/120] change chi to chi0 in improper_harmonic_kokkos.cpp --- src/KOKKOS/improper_harmonic_kokkos.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/KOKKOS/improper_harmonic_kokkos.cpp b/src/KOKKOS/improper_harmonic_kokkos.cpp index 89ca31b9ca..88cb8b66e8 100644 --- a/src/KOKKOS/improper_harmonic_kokkos.cpp +++ b/src/KOKKOS/improper_harmonic_kokkos.cpp @@ -304,7 +304,7 @@ void ImproperHarmonicKokkos::allocate() int n = atom->nimpropertypes; k_k = Kokkos::DualView("ImproperHarmonic::k",n+1); - k_chi = Kokkos::DualView("ImproperHarmonic::chi",n+1); + k_chi = Kokkos::DualView("ImproperHarmonic::chi0",n+1); d_k = k_k.template view(); d_chi = k_chi.template view(); @@ -322,7 +322,7 @@ void ImproperHarmonicKokkos::coeff(int narg, char **arg) int n = atom->nimpropertypes; for (int i = 1; i <= n; i++) { k_k.h_view[i] = k[i]; - k_chi.h_view[i] = chi[i]; + k_chi.h_view[i] = chi0[i]; } k_k.modify_host(); @@ -341,7 +341,7 @@ void ImproperHarmonicKokkos::read_restart(FILE *fp) int n = atom->nimpropertypes; for (int i = 1; i <= n; i++) { k_k.h_view[i] = k[i]; - k_chi.h_view[i] = chi[i]; + k_chi.h_view[i] = chi0[i]; } k_k.modify_host(); From 2b46abc31cb0464a905327cd62e4e6c24460efb8 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 19:15:58 +0200 Subject: [PATCH 058/120] change chi to d0 in improper-distharm.yaml --- unittest/force-styles/tests/improper-distharm.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-distharm.yaml b/unittest/force-styles/tests/improper-distharm.yaml index 5a3f4e08a5..1ae48c8488 100644 --- a/unittest/force-styles/tests/improper-distharm.yaml +++ b/unittest/force-styles/tests/improper-distharm.yaml @@ -15,7 +15,7 @@ improper_coeff: ! | 2 45.0 6.2 extract: ! | k 1 - chi 1 + d0 1 natoms: 29 init_energy: 3973.601605432119 init_stress: ! |2- From f738690cb5f12e6ec7489ebe9a4d3b0222c1e520 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 19:16:47 +0200 Subject: [PATCH 059/120] change chi to d0 in improper_distharm.h --- src/YAFF/improper_distharm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/YAFF/improper_distharm.h b/src/YAFF/improper_distharm.h index 6896af3e15..f43a13cae9 100644 --- a/src/YAFF/improper_distharm.h +++ b/src/YAFF/improper_distharm.h @@ -35,7 +35,7 @@ class ImproperDistHarm : public Improper { void *extract(const char *, int &) override; private: - double *k, *chi; + double *k, *d0; void allocate(); }; From 70acd78048b40e4defe1812f12ad93e096835e1e Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 19:18:58 +0200 Subject: [PATCH 060/120] change chi to d0 in improper_distharm.cpp --- src/YAFF/improper_distharm.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/YAFF/improper_distharm.cpp b/src/YAFF/improper_distharm.cpp index c2d7381fd9..ec92ff4c42 100644 --- a/src/YAFF/improper_distharm.cpp +++ b/src/YAFF/improper_distharm.cpp @@ -46,7 +46,7 @@ ImproperDistHarm::~ImproperDistHarm() if (allocated) { memory->destroy(setflag); memory->destroy(k); - memory->destroy(chi); + memory->destroy(d0); } } @@ -137,8 +137,8 @@ void ImproperDistHarm::compute(int eflag, int vflag) da = -(xna*xad + yna*yad + zna*zad); - domega = k[type]*(da - chi[type])*(da - chi[type]); - a = 2.0* k[type]*(da - chi[type]); + domega = k[type]*(da - d0[type])*(da - d0[type]); + a = 2.0* k[type]*(da - d0[type]); if (eflag) eimproper = domega; @@ -204,7 +204,7 @@ void ImproperDistHarm::allocate() int n = atom->nimpropertypes; memory->create(k,n+1,"improper:k"); - memory->create(chi,n+1,"improper:chi"); + memory->create(d0,n+1,"improper:d0"); memory->create(setflag,n+1,"improper:setflag"); for (int i = 1; i <= n; i++) setflag[i] = 0; @@ -224,15 +224,12 @@ void ImproperDistHarm::coeff(int narg, char **arg) utils::bounds(FLERR,arg[0],1,atom->nimpropertypes,ilo,ihi,error); double k_one = utils::numeric(FLERR,arg[1],false,lmp); - double chi_one = utils::numeric(FLERR,arg[2],false,lmp); - - // convert chi from degrees to radians + double d0_one = utils::numeric(FLERR,arg[2],false,lmp); int count = 0; for (int i = ilo; i <= ihi; i++) { k[i] = k_one; - //chi[i] = chi_one/180.0 * PI; - chi[i] = chi_one; + d0[i] = d0_one; setflag[i] = 1; count++; } @@ -247,7 +244,7 @@ void ImproperDistHarm::coeff(int narg, char **arg) void ImproperDistHarm::write_restart(FILE *fp) { fwrite(&k[1],sizeof(double),atom->nimpropertypes,fp); - fwrite(&chi[1],sizeof(double),atom->nimpropertypes,fp); + fwrite(&d0[1],sizeof(double),atom->nimpropertypes,fp); } /* ---------------------------------------------------------------------- @@ -260,10 +257,10 @@ void ImproperDistHarm::read_restart(FILE *fp) if (comm->me == 0) { utils::sfread(FLERR,&k[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); - utils::sfread(FLERR,&chi[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); + utils::sfread(FLERR,&d0[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); } MPI_Bcast(&k[1],atom->nimpropertypes,MPI_DOUBLE,0,world); - MPI_Bcast(&chi[1],atom->nimpropertypes,MPI_DOUBLE,0,world); + MPI_Bcast(&d0[1],atom->nimpropertypes,MPI_DOUBLE,0,world); for (int i = 1; i <= atom->nimpropertypes; i++) setflag[i] = 1; } @@ -276,6 +273,6 @@ void *ImproperDistHarm::extract(const char *str, int &dim) { dim = 1; if (strcmp(str, "k") == 0) return (void *) k; - if (strcmp(str, "chi") == 0) return (void *) chi; + if (strcmp(str, "d0") == 0) return (void *) d0; return nullptr; } From 7ae9ef75d847c25cd42d4aa221612f8432e36960 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 19:20:26 +0200 Subject: [PATCH 061/120] Update fix_adapt.rst --- doc/src/fix_adapt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index bd5cc628df..d4a1cb6f6e 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -453,7 +453,7 @@ sub-style name. The improper styles that currently work with fix adapt are: +---------------------------------------------------------+----------------------+----------------+ | :doc:`distance ` | k,chi | type impropers | +---------------------------------------------------------+----------------------+----------------+ -| :doc:`distharm ` | k,chi | type impropers | +| :doc:`distharm ` | k,d0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ | :doc:`fourier ` | k,C0,C1,C2 | type impropers | +---------------------------------------------------------+----------------------+----------------+ From dc83bd30841974c8806b297d3e4240574001ef06 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 20:18:13 +0200 Subject: [PATCH 062/120] rename chi to theta0 in improper-ring.yaml --- unittest/force-styles/tests/improper-ring.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-ring.yaml b/unittest/force-styles/tests/improper-ring.yaml index 31e8c2ac62..48cb944af3 100644 --- a/unittest/force-styles/tests/improper-ring.yaml +++ b/unittest/force-styles/tests/improper-ring.yaml @@ -15,7 +15,7 @@ improper_coeff: ! | 2 45.0 59.5 extract: ! | k 1 - chi 1 + theta0 1 natoms: 29 init_energy: 31535.23771704055 init_stress: ! |- From e88946935c4c76d26b9b214bb167927e540230b8 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 20:19:13 +0200 Subject: [PATCH 063/120] rename chi to theta0 in extract improper_ring.cpp --- src/EXTRA-MOLECULE/improper_ring.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EXTRA-MOLECULE/improper_ring.cpp b/src/EXTRA-MOLECULE/improper_ring.cpp index ac5f0eb237..82381486cf 100644 --- a/src/EXTRA-MOLECULE/improper_ring.cpp +++ b/src/EXTRA-MOLECULE/improper_ring.cpp @@ -359,6 +359,6 @@ void *ImproperRing::extract(const char *str, int &dim) { dim = 1; if (strcmp(str, "k") == 0) return (void *) k; - if (strcmp(str, "chi") == 0) return (void *) chi; + if (strcmp(str, "theta0") == 0) return (void *) chi; return nullptr; } From 18cd31d811c362222eed44fcffd422948c6c654f Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Mon, 10 Feb 2025 20:22:32 +0200 Subject: [PATCH 064/120] Update fix_adapt.rst --- doc/src/fix_adapt.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index d4a1cb6f6e..107e93194f 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -461,15 +461,15 @@ sub-style name. The improper styles that currently work with fix adapt are: +---------------------------------------------------------+----------------------+----------------+ | :doc:`inversion/harmonic ` | kw,w0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ -| :doc:`ring ` | k,chi | type impropers | +| :doc:`ring ` | k,theta0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ | :doc:`umbrella ` | kw,w0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ | :doc:`sqdistharm ` | k,chi | type impropers | +---------------------------------------------------------+----------------------+----------------+ -Note that internally, chi0 is stored in radians, so the variable -this fix uses to reset chi0 needs to generate values in radians. +Note that internally, chi0 and theta0 are stored in radians, so the variable +this fix use to reset chi0 or theta0 needs to generate values in radians. ---------- From 7e0f067b74f85cdc8f603de2575e7539cd497ec9 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 15:41:22 +0200 Subject: [PATCH 065/120] rename k0 to k in improper_class2.cpp --- src/CLASS2/improper_class2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CLASS2/improper_class2.cpp b/src/CLASS2/improper_class2.cpp index a59648c79c..cd774883d6 100644 --- a/src/CLASS2/improper_class2.cpp +++ b/src/CLASS2/improper_class2.cpp @@ -851,7 +851,7 @@ void ImproperClass2::write_data(FILE *fp) void *ImproperClass2::extract(const char *str, int &dim) { dim = 1; - if (strcmp(str, "k0") == 0) return (void *) k0; + if (strcmp(str, "k") == 0) return (void *) k0; if (strcmp(str, "chi0") == 0) return (void *) chi0; return nullptr; } From 11b95655f8b6dcf171b021e1813c18fde0218803 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 15:42:30 +0200 Subject: [PATCH 066/120] rename k0 to k in improper-class2.yaml --- unittest/force-styles/tests/improper-class2.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-class2.yaml b/unittest/force-styles/tests/improper-class2.yaml index d60ae48602..eba334a1e6 100644 --- a/unittest/force-styles/tests/improper-class2.yaml +++ b/unittest/force-styles/tests/improper-class2.yaml @@ -15,7 +15,7 @@ improper_coeff: ! | 2 45.0 10 * aa 75 42 31 125.4 130.01 115.06 extract: ! | - k0 1 + k 1 chi0 1 natoms: 29 init_energy: 1375.7372366975192 From a320a52804d828d80b0d2df63e465b3e6ab39006 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 15:44:55 +0200 Subject: [PATCH 067/120] Update fix_adapt.rst --- doc/src/fix_adapt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index 107e93194f..c0f95bd1ef 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -445,7 +445,7 @@ sub-style name. The improper styles that currently work with fix adapt are: +---------------------------------------------------------+----------------------+----------------+ | :doc:`amoeba ` | k | type impropers | +---------------------------------------------------------+----------------------+----------------+ -| :doc:`class2 ` | k0,chi0 | type impropers | +| :doc:`class2 ` | k,chi0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ | :doc:`cossq ` | k,chi0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ From bac4eec31b462826018006b6696b69106b716877 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 15:47:58 +0200 Subject: [PATCH 068/120] rename sign and multplicity in improper_cvff.cpp --- src/MOLECULE/improper_cvff.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MOLECULE/improper_cvff.cpp b/src/MOLECULE/improper_cvff.cpp index bb9836393c..b2e6185dcf 100644 --- a/src/MOLECULE/improper_cvff.cpp +++ b/src/MOLECULE/improper_cvff.cpp @@ -346,7 +346,7 @@ void *ImproperCvff::extract(const char *str, int &dim) { dim = 1; if (strcmp(str, "k") == 0) return (void *) k; - if (strcmp(str, "sign") == 0) return (void *) sign; - if (strcmp(str, "multiplicity") == 0) return (void *) multiplicity; + if (strcmp(str, "d") == 0) return (void *) sign; + if (strcmp(str, "n") == 0) return (void *) multiplicity; return nullptr; } From c9b46891671f1bbd0e1e1e67993a3e6d6127476f Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 15:48:50 +0200 Subject: [PATCH 069/120] rename sign and multiplicity in improper-cvff.yaml --- unittest/force-styles/tests/improper-cvff.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/force-styles/tests/improper-cvff.yaml b/unittest/force-styles/tests/improper-cvff.yaml index 729768dc89..be18107884 100644 --- a/unittest/force-styles/tests/improper-cvff.yaml +++ b/unittest/force-styles/tests/improper-cvff.yaml @@ -15,8 +15,8 @@ improper_coeff: ! | 2 45.0 +1 2 extract: ! | k 1 - sign 1 - multiplicity 1 + d 1 + n 1 natoms: 29 init_energy: 89.33266688553577 init_stress: ! |2- From 503243631289274447551096ee47547f1ef55d84 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 15:49:46 +0200 Subject: [PATCH 070/120] Update fix_adapt.rst --- doc/src/fix_adapt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index c0f95bd1ef..c1807142d1 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -449,7 +449,7 @@ sub-style name. The improper styles that currently work with fix adapt are: +---------------------------------------------------------+----------------------+----------------+ | :doc:`cossq ` | k,chi0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ -| :doc:`cvff ` | k,sign,multiplicity | type impropers | +| :doc:`cvff ` | k,d,n | type impropers | +---------------------------------------------------------+----------------------+----------------+ | :doc:`distance ` | k,chi | type impropers | +---------------------------------------------------------+----------------------+----------------+ From 94dd03d43cd130b8437404ddf4f30ab895958e0f Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 15:52:20 +0200 Subject: [PATCH 071/120] rename kw to k in improper_umbrella.cpp --- src/MOLECULE/improper_umbrella.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MOLECULE/improper_umbrella.cpp b/src/MOLECULE/improper_umbrella.cpp index a4c6fbca42..6491900d05 100644 --- a/src/MOLECULE/improper_umbrella.cpp +++ b/src/MOLECULE/improper_umbrella.cpp @@ -331,7 +331,7 @@ void ImproperUmbrella::write_data(FILE *fp) void *ImproperUmbrella::extract(const char *str, int &dim) { dim = 1; - if (strcmp(str, "kw") == 0) return (void *) kw; + if (strcmp(str, "k") == 0) return (void *) kw; if (strcmp(str, "w0") == 0) return (void *) w0; return nullptr; } From c66ca60f655939a8755b15c6ddc655ba0ce37275 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 15:53:14 +0200 Subject: [PATCH 072/120] rename kw to k in improper-umbrella.yaml --- unittest/force-styles/tests/improper-umbrella.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-umbrella.yaml b/unittest/force-styles/tests/improper-umbrella.yaml index 604c039c28..61557813c8 100644 --- a/unittest/force-styles/tests/improper-umbrella.yaml +++ b/unittest/force-styles/tests/improper-umbrella.yaml @@ -14,7 +14,7 @@ improper_coeff: ! | 1 75.0 120.2 2 45.0 59.5 extract: ! | - kw 1 + k 1 w0 1 natoms: 29 init_energy: 120.51735030260785 From 757eb8bf58a7f39e08b1ed85388fa6b0358d4d0c Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 15:53:58 +0200 Subject: [PATCH 073/120] Update fix_adapt.rst --- doc/src/fix_adapt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index c1807142d1..314078c187 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -463,7 +463,7 @@ sub-style name. The improper styles that currently work with fix adapt are: +---------------------------------------------------------+----------------------+----------------+ | :doc:`ring ` | k,theta0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ -| :doc:`umbrella ` | kw,w0 | type impropers | +| :doc:`umbrella ` | k,w0 | type impropers | +---------------------------------------------------------+----------------------+----------------+ | :doc:`sqdistharm ` | k,chi | type impropers | +---------------------------------------------------------+----------------------+----------------+ From 8bba7ff10f27ad2c8c8992ba9fbcdf790706c24c Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 15:58:07 +0200 Subject: [PATCH 074/120] rename kw to k in improper_inversion_harmonic.cpp --- src/MOFFF/improper_inversion_harmonic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MOFFF/improper_inversion_harmonic.cpp b/src/MOFFF/improper_inversion_harmonic.cpp index 681811594b..61180447f3 100644 --- a/src/MOFFF/improper_inversion_harmonic.cpp +++ b/src/MOFFF/improper_inversion_harmonic.cpp @@ -340,7 +340,7 @@ void ImproperInversionHarmonic::write_data(FILE *fp) void *ImproperInversionHarmonic::extract(const char *str, int &dim) { dim = 1; - if (strcmp(str, "kw") == 0) return (void *) kw; + if (strcmp(str, "k") == 0) return (void *) kw; if (strcmp(str, "w0") == 0) return (void *) w0; return nullptr; } From fb6a1ad603da7629655b3fbf83c3dbce3fb3181c Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 15:58:47 +0200 Subject: [PATCH 075/120] rename kw to k in improper-inversion_harmonic.yaml --- unittest/force-styles/tests/improper-inversion_harmonic.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/improper-inversion_harmonic.yaml b/unittest/force-styles/tests/improper-inversion_harmonic.yaml index 7697908c23..44fd09763d 100644 --- a/unittest/force-styles/tests/improper-inversion_harmonic.yaml +++ b/unittest/force-styles/tests/improper-inversion_harmonic.yaml @@ -14,7 +14,7 @@ improper_coeff: ! | 1 75.0 0.1 2 45.0 1.0 extract: ! | - kw 1 + k 1 w0 1 natoms: 29 init_energy: 0.35230115027159387 From 1d974a51c08b33fb4ca0a7866843033de80155e3 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 16:00:39 +0200 Subject: [PATCH 076/120] Update fix_adapt.rst --- doc/src/fix_adapt.rst | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index 314078c187..286ec0350c 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -442,31 +442,31 @@ all types from 1 to :math:`N`. A leading asterisk means all types from If :doc:`improper_style hybrid ` is used, *istyle* should be a sub-style name. The improper styles that currently work with fix adapt are: -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`amoeba ` | k | type impropers | -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`class2 ` | k,chi0 | type impropers | -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`cossq ` | k,chi0 | type impropers | -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`cvff ` | k,d,n | type impropers | -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`distance ` | k,chi | type impropers | -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`distharm ` | k,d0 | type impropers | -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`fourier ` | k,C0,C1,C2 | type impropers | -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`harmonic ` | k,chi0 | type impropers | -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`inversion/harmonic ` | kw,w0 | type impropers | -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`ring ` | k,theta0 | type impropers | -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`umbrella ` | k,w0 | type impropers | -+---------------------------------------------------------+----------------------+----------------+ -| :doc:`sqdistharm ` | k,chi | type impropers | -+---------------------------------------------------------+----------------------+----------------+ ++---------------------------------------------------------+----------------+----------------+ +| :doc:`amoeba ` | k | type impropers | ++---------------------------------------------------------+----------------+----------------+ +| :doc:`class2 ` | k,chi0 | type impropers | ++---------------------------------------------------------+----------------+----------------+ +| :doc:`cossq ` | k,chi0 | type impropers | ++---------------------------------------------------------+----------------+----------------+ +| :doc:`cvff ` | k,d,n | type impropers | ++---------------------------------------------------------+----------------+----------------+ +| :doc:`distance ` | k,chi | type impropers | ++---------------------------------------------------------+----------------+----------------+ +| :doc:`distharm ` | k,d0 | type impropers | ++---------------------------------------------------------+----------------+----------------+ +| :doc:`fourier ` | k,C0,C1,C2 | type impropers | ++---------------------------------------------------------+----------------+----------------+ +| :doc:`harmonic ` | k,chi0 | type impropers | ++---------------------------------------------------------+----------------+----------------+ +| :doc:`inversion/harmonic ` | k,w0 | type impropers | ++---------------------------------------------------------+----------------+----------------+ +| :doc:`ring ` | k,theta0 | type impropers | ++---------------------------------------------------------+----------------+----------------+ +| :doc:`umbrella ` | k,w0 | type impropers | ++---------------------------------------------------------+----------------+----------------+ +| :doc:`sqdistharm ` | k,chi | type impropers | ++---------------------------------------------------------+----------------+----------------+ Note that internally, chi0 and theta0 are stored in radians, so the variable this fix use to reset chi0 or theta0 needs to generate values in radians. From a708a5046841e02c02952f2801f1c6d0250d8133 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 16:03:03 +0200 Subject: [PATCH 077/120] rename k and chi in improper_distance.cpp --- src/EXTRA-MOLECULE/improper_distance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EXTRA-MOLECULE/improper_distance.cpp b/src/EXTRA-MOLECULE/improper_distance.cpp index 2eb30c7f2b..ed88b9e3b4 100644 --- a/src/EXTRA-MOLECULE/improper_distance.cpp +++ b/src/EXTRA-MOLECULE/improper_distance.cpp @@ -277,7 +277,7 @@ void ImproperDistance::write_data(FILE *fp) void *ImproperDistance::extract(const char *str, int &dim) { dim = 1; - if (strcmp(str, "k") == 0) return (void *) k; - if (strcmp(str, "chi") == 0) return (void *) chi; + if (strcmp(str, "k2") == 0) return (void *) k; + if (strcmp(str, "k4") == 0) return (void *) chi; return nullptr; } From ed9b22cb0ea516dc0a3c3c6e5f21164035b98453 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 16:03:42 +0200 Subject: [PATCH 078/120] rename k and chi in improper-distance.yaml --- unittest/force-styles/tests/improper-distance.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/force-styles/tests/improper-distance.yaml b/unittest/force-styles/tests/improper-distance.yaml index 800c19ce06..3c64d4af52 100644 --- a/unittest/force-styles/tests/improper-distance.yaml +++ b/unittest/force-styles/tests/improper-distance.yaml @@ -14,8 +14,8 @@ improper_coeff: ! | 1 75.0 120.2 2 45.0 59.5 extract: ! | - k 1 - chi 1 + k2 1 + k4 1 natoms: 29 init_energy: 0.0747454910197192 init_stress: ! |- From b94d82d7b1c635e0c13943bd0e9f251348742cee Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 16:04:33 +0200 Subject: [PATCH 079/120] rename k anc chi in fix_adapt.rst --- doc/src/fix_adapt.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index 286ec0350c..1f3aef976c 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -451,7 +451,7 @@ sub-style name. The improper styles that currently work with fix adapt are: +---------------------------------------------------------+----------------+----------------+ | :doc:`cvff ` | k,d,n | type impropers | +---------------------------------------------------------+----------------+----------------+ -| :doc:`distance ` | k,chi | type impropers | +| :doc:`distance ` | k2,k4 | type impropers | +---------------------------------------------------------+----------------+----------------+ | :doc:`distharm ` | k,d0 | type impropers | +---------------------------------------------------------+----------------+----------------+ From afaff7199bc9505e88fee646afdea7d1ad32e13f Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 16:11:52 +0200 Subject: [PATCH 080/120] revert changes in improper_cossq_omp.cpp - they are not needed --- src/OPENMP/improper_cossq_omp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OPENMP/improper_cossq_omp.cpp b/src/OPENMP/improper_cossq_omp.cpp index 7f294522fa..4ccc0d730a 100644 --- a/src/OPENMP/improper_cossq_omp.cpp +++ b/src/OPENMP/improper_cossq_omp.cpp @@ -134,7 +134,7 @@ void ImproperCossqOMP::eval(int nfrom, int nto, ThrData * const thr) /* Calculate the angle: */ double torangle = acos(cosphi); - cosphi = cos(torangle - chi0[type]); + cosphi = cos(torangle - chi[type]); if (EFLAG) eimproper = 0.5 * k[type] * cosphi * cosphi; From c263c9a534e91251c045a10caddc4d267347731c Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 16:12:34 +0200 Subject: [PATCH 081/120] revert changes in improper_cossq.h --- src/EXTRA-MOLECULE/improper_cossq.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EXTRA-MOLECULE/improper_cossq.h b/src/EXTRA-MOLECULE/improper_cossq.h index 485ba3a9cb..bcc12e654f 100644 --- a/src/EXTRA-MOLECULE/improper_cossq.h +++ b/src/EXTRA-MOLECULE/improper_cossq.h @@ -36,7 +36,7 @@ class ImproperCossq : public Improper { void *extract(const char *, int &) override; protected: - double *k, *chi0; + double *k, *chi; void allocate(); }; From 7be7ffbaf1eb538c6225e3f2f0627a8e1f45effa Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 16:15:52 +0200 Subject: [PATCH 082/120] revert renamin of cariable chi to chi0 in improper_cossq.cpp --- src/EXTRA-MOLECULE/improper_cossq.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/EXTRA-MOLECULE/improper_cossq.cpp b/src/EXTRA-MOLECULE/improper_cossq.cpp index 75ab4e26fa..263b56f55e 100644 --- a/src/EXTRA-MOLECULE/improper_cossq.cpp +++ b/src/EXTRA-MOLECULE/improper_cossq.cpp @@ -51,7 +51,7 @@ ImproperCossq::~ImproperCossq() if (allocated) { memory->destroy(setflag); memory->destroy(k); - memory->destroy(chi0); + memory->destroy(chi); } } @@ -114,7 +114,7 @@ void ImproperCossq::compute(int eflag, int vflag) /* Calculate the angle: */ double torangle = acos(cosphi); - cosphi = cos(torangle - chi0[type]); + cosphi = cos(torangle - chi[type]); if (eflag) eimproper = 0.5 * k[type] * cosphi * cosphi; @@ -237,7 +237,7 @@ void ImproperCossq::allocate() int n = atom->nimpropertypes; memory->create(k,n+1,"improper:k"); - memory->create(chi0,n+1,"improper:chi0"); + memory->create(chi,n+1,"improper:chi"); memory->create(setflag,n+1,"improper:setflag"); for (int i = 1; i <= n; i++) setflag[i] = 0; @@ -265,7 +265,7 @@ void ImproperCossq::coeff(int narg, char **arg) int count = 0; for (int i = ilo; i <= ihi; i++) { k[i] = k_one; - chi0[i] = ((chi_one * MY_PI)/180.0); + chi[i] = ((chi_one * MY_PI)/180.0); setflag[i] = 1; count++; } @@ -279,7 +279,7 @@ void ImproperCossq::coeff(int narg, char **arg) void ImproperCossq::write_restart(FILE *fp) { fwrite(&k[1],sizeof(double),atom->nimpropertypes,fp); - fwrite(&chi0[1],sizeof(double),atom->nimpropertypes,fp); + fwrite(&chi[1],sizeof(double),atom->nimpropertypes,fp); } /* ---------------------------------------------------------------------- @@ -291,10 +291,10 @@ void ImproperCossq::read_restart(FILE *fp) if (comm->me == 0) { utils::sfread(FLERR,&k[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); - utils::sfread(FLERR,&chi0[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); + utils::sfread(FLERR,&chi[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); } MPI_Bcast(&k[1],atom->nimpropertypes,MPI_DOUBLE,0,world); - MPI_Bcast(&chi0[1],atom->nimpropertypes,MPI_DOUBLE,0,world); + MPI_Bcast(&chi[1],atom->nimpropertypes,MPI_DOUBLE,0,world); for (int i = 1; i <= atom->nimpropertypes; i++) setflag[i] = 1; } @@ -306,7 +306,7 @@ void ImproperCossq::read_restart(FILE *fp) void ImproperCossq::write_data(FILE *fp) { for (int i = 1; i <= atom->nimpropertypes; i++) - fprintf(fp,"%d %g %g\n",i,k[i],chi0[i]/MY_PI*180.0); + fprintf(fp,"%d %g %g\n",i,k[i],chi[i]/MY_PI*180.0); } /* ---------------------------------------------------------------------- @@ -317,6 +317,6 @@ void *ImproperCossq::extract(const char *str, int &dim) { dim = 1; if (strcmp(str, "k") == 0) return (void *) k; - if (strcmp(str, "chi0") == 0) return (void *) chi0; + if (strcmp(str, "chi0") == 0) return (void *) chi; return nullptr; } From 89ceb73ec54c8ff3cccbbcf540f57abd010df082 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 16:21:21 +0200 Subject: [PATCH 083/120] revert renaming in improper_distharm.h --- src/YAFF/improper_distharm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/YAFF/improper_distharm.h b/src/YAFF/improper_distharm.h index f43a13cae9..6896af3e15 100644 --- a/src/YAFF/improper_distharm.h +++ b/src/YAFF/improper_distharm.h @@ -35,7 +35,7 @@ class ImproperDistHarm : public Improper { void *extract(const char *, int &) override; private: - double *k, *d0; + double *k, *chi; void allocate(); }; From 0b47e90008c9bf3b869c9741e6ad87174897a35f Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 16:24:47 +0200 Subject: [PATCH 084/120] revert renaming of variables in improper_distharm.cpp --- src/YAFF/improper_distharm.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/YAFF/improper_distharm.cpp b/src/YAFF/improper_distharm.cpp index ec92ff4c42..0a9239b9b0 100644 --- a/src/YAFF/improper_distharm.cpp +++ b/src/YAFF/improper_distharm.cpp @@ -46,7 +46,7 @@ ImproperDistHarm::~ImproperDistHarm() if (allocated) { memory->destroy(setflag); memory->destroy(k); - memory->destroy(d0); + memory->destroy(chi); } } @@ -137,8 +137,8 @@ void ImproperDistHarm::compute(int eflag, int vflag) da = -(xna*xad + yna*yad + zna*zad); - domega = k[type]*(da - d0[type])*(da - d0[type]); - a = 2.0* k[type]*(da - d0[type]); + domega = k[type]*(da - chi[type])*(da - chi[type]); + a = 2.0* k[type]*(da - chi[type]); if (eflag) eimproper = domega; @@ -204,7 +204,7 @@ void ImproperDistHarm::allocate() int n = atom->nimpropertypes; memory->create(k,n+1,"improper:k"); - memory->create(d0,n+1,"improper:d0"); + memory->create(chi,n+1,"improper:chi"); memory->create(setflag,n+1,"improper:setflag"); for (int i = 1; i <= n; i++) setflag[i] = 0; @@ -224,12 +224,12 @@ void ImproperDistHarm::coeff(int narg, char **arg) utils::bounds(FLERR,arg[0],1,atom->nimpropertypes,ilo,ihi,error); double k_one = utils::numeric(FLERR,arg[1],false,lmp); - double d0_one = utils::numeric(FLERR,arg[2],false,lmp); + double chi_one = utils::numeric(FLERR,arg[2],false,lmp); int count = 0; for (int i = ilo; i <= ihi; i++) { k[i] = k_one; - d0[i] = d0_one; + chi[i] = chi_one; setflag[i] = 1; count++; } @@ -244,7 +244,7 @@ void ImproperDistHarm::coeff(int narg, char **arg) void ImproperDistHarm::write_restart(FILE *fp) { fwrite(&k[1],sizeof(double),atom->nimpropertypes,fp); - fwrite(&d0[1],sizeof(double),atom->nimpropertypes,fp); + fwrite(&chi[1],sizeof(double),atom->nimpropertypes,fp); } /* ---------------------------------------------------------------------- @@ -257,7 +257,7 @@ void ImproperDistHarm::read_restart(FILE *fp) if (comm->me == 0) { utils::sfread(FLERR,&k[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); - utils::sfread(FLERR,&d0[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); + utils::sfread(FLERR,&chi[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); } MPI_Bcast(&k[1],atom->nimpropertypes,MPI_DOUBLE,0,world); MPI_Bcast(&d0[1],atom->nimpropertypes,MPI_DOUBLE,0,world); @@ -273,6 +273,6 @@ void *ImproperDistHarm::extract(const char *str, int &dim) { dim = 1; if (strcmp(str, "k") == 0) return (void *) k; - if (strcmp(str, "d0") == 0) return (void *) d0; + if (strcmp(str, "d0") == 0) return (void *) chi; return nullptr; } From 889b33df4ab013556ef221fa58ffd5ac6305771a Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 16:26:35 +0200 Subject: [PATCH 085/120] missed revert in improper_distharm.cpp --- src/YAFF/improper_distharm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/YAFF/improper_distharm.cpp b/src/YAFF/improper_distharm.cpp index 0a9239b9b0..bd6c29c479 100644 --- a/src/YAFF/improper_distharm.cpp +++ b/src/YAFF/improper_distharm.cpp @@ -260,7 +260,7 @@ void ImproperDistHarm::read_restart(FILE *fp) utils::sfread(FLERR,&chi[1],sizeof(double),atom->nimpropertypes,fp,nullptr,error); } MPI_Bcast(&k[1],atom->nimpropertypes,MPI_DOUBLE,0,world); - MPI_Bcast(&d0[1],atom->nimpropertypes,MPI_DOUBLE,0,world); + MPI_Bcast(&chi[1],atom->nimpropertypes,MPI_DOUBLE,0,world); for (int i = 1; i <= atom->nimpropertypes; i++) setflag[i] = 1; } From ac1221602bc066141bf168ccf357cdfde6f9a199 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 11 Feb 2025 20:23:21 +0000 Subject: [PATCH 086/120] revert unnecessary renaming in improper harmonic and sqdistharm files --- doc/src/fix_adapt.rst | 2 +- src/KOKKOS/improper_harmonic_kokkos.cpp | 6 +++--- src/MOLECULE/improper_harmonic.cpp | 20 ++++++++++---------- src/MOLECULE/improper_harmonic.h | 2 +- src/OPENMP/improper_harmonic_omp.cpp | 2 +- src/YAFF/improper_sqdistharm.cpp | 1 - 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/doc/src/fix_adapt.rst b/doc/src/fix_adapt.rst index 1f3aef976c..3ec64ffd27 100644 --- a/doc/src/fix_adapt.rst +++ b/doc/src/fix_adapt.rst @@ -465,7 +465,7 @@ sub-style name. The improper styles that currently work with fix adapt are: +---------------------------------------------------------+----------------+----------------+ | :doc:`umbrella ` | k,w0 | type impropers | +---------------------------------------------------------+----------------+----------------+ -| :doc:`sqdistharm ` | k,chi | type impropers | +| :doc:`sqdistharm ` | k | type impropers | +---------------------------------------------------------+----------------+----------------+ Note that internally, chi0 and theta0 are stored in radians, so the variable diff --git a/src/KOKKOS/improper_harmonic_kokkos.cpp b/src/KOKKOS/improper_harmonic_kokkos.cpp index 88cb8b66e8..89ca31b9ca 100644 --- a/src/KOKKOS/improper_harmonic_kokkos.cpp +++ b/src/KOKKOS/improper_harmonic_kokkos.cpp @@ -304,7 +304,7 @@ void ImproperHarmonicKokkos::allocate() int n = atom->nimpropertypes; k_k = Kokkos::DualView("ImproperHarmonic::k",n+1); - k_chi = Kokkos::DualView("ImproperHarmonic::chi0",n+1); + k_chi = Kokkos::DualView("ImproperHarmonic::chi",n+1); d_k = k_k.template view(); d_chi = k_chi.template view(); @@ -322,7 +322,7 @@ void ImproperHarmonicKokkos::coeff(int narg, char **arg) int n = atom->nimpropertypes; for (int i = 1; i <= n; i++) { k_k.h_view[i] = k[i]; - k_chi.h_view[i] = chi0[i]; + k_chi.h_view[i] = chi[i]; } k_k.modify_host(); @@ -341,7 +341,7 @@ void ImproperHarmonicKokkos::read_restart(FILE *fp) int n = atom->nimpropertypes; for (int i = 1; i <= n; i++) { k_k.h_view[i] = k[i]; - k_chi.h_view[i] = chi0[i]; + k_chi.h_view[i] = chi[i]; } k_k.modify_host(); diff --git a/src/MOLECULE/improper_harmonic.cpp b/src/MOLECULE/improper_harmonic.cpp index 3e4bb35940..8d1df0d6fd 100644 --- a/src/MOLECULE/improper_harmonic.cpp +++ b/src/MOLECULE/improper_harmonic.cpp @@ -48,7 +48,7 @@ ImproperHarmonic::~ImproperHarmonic() if (allocated && !copymode) { memory->destroy(setflag); memory->destroy(k); - memory->destroy(chi0); + memory->destroy(chi); } } @@ -131,7 +131,7 @@ void ImproperHarmonic::compute(int eflag, int vflag) // force & energy - domega = acos(c) - chi0[type]; + domega = acos(c) - chi[type]; a = k[type] * domega; if (eflag) eimproper = a * domega; @@ -206,7 +206,7 @@ void ImproperHarmonic::allocate() const int np1 = atom->nimpropertypes + 1; memory->create(k, np1, "improper:k"); - memory->create(chi0, np1, "improper:chi0"); + memory->create(chi, np1, "improper:chi"); memory->create(setflag, np1, "improper:setflag"); for (int i = 1; i < np1; i++) setflag[i] = 0; } @@ -226,12 +226,12 @@ void ImproperHarmonic::coeff(int narg, char **arg) double k_one = utils::numeric(FLERR, arg[1], false, lmp); double chi_one = utils::numeric(FLERR, arg[2], false, lmp); - // convert chi0 from degrees to radians + // convert chi from degrees to radians int count = 0; for (int i = ilo; i <= ihi; i++) { k[i] = k_one; - chi0[i] = DEG2RAD * chi_one; + chi[i] = DEG2RAD * chi_one; setflag[i] = 1; count++; } @@ -246,7 +246,7 @@ void ImproperHarmonic::coeff(int narg, char **arg) void ImproperHarmonic::write_restart(FILE *fp) { fwrite(&k[1], sizeof(double), atom->nimpropertypes, fp); - fwrite(&chi0[1], sizeof(double), atom->nimpropertypes, fp); + fwrite(&chi[1], sizeof(double), atom->nimpropertypes, fp); } /* ---------------------------------------------------------------------- @@ -259,10 +259,10 @@ void ImproperHarmonic::read_restart(FILE *fp) if (comm->me == 0) { utils::sfread(FLERR, &k[1], sizeof(double), atom->nimpropertypes, fp, nullptr, error); - utils::sfread(FLERR, &chi0[1], sizeof(double), atom->nimpropertypes, fp, nullptr, error); + utils::sfread(FLERR, &chi[1], sizeof(double), atom->nimpropertypes, fp, nullptr, error); } MPI_Bcast(&k[1], atom->nimpropertypes, MPI_DOUBLE, 0, world); - MPI_Bcast(&chi0[1], atom->nimpropertypes, MPI_DOUBLE, 0, world); + MPI_Bcast(&chi[1], atom->nimpropertypes, MPI_DOUBLE, 0, world); for (int i = 1; i <= atom->nimpropertypes; i++) setflag[i] = 1; } @@ -274,7 +274,7 @@ void ImproperHarmonic::read_restart(FILE *fp) void ImproperHarmonic::write_data(FILE *fp) { for (int i = 1; i <= atom->nimpropertypes; i++) - fprintf(fp, "%d %g %g\n", i, k[i], RAD2DEG * chi0[i]); + fprintf(fp, "%d %g %g\n", i, k[i], RAD2DEG * chi[i]); } /* ---------------------------------------------------------------------- @@ -285,6 +285,6 @@ void *ImproperHarmonic::extract(const char *str, int &dim) { dim = 1; if (strcmp(str, "k") == 0) return (void *) k; - if (strcmp(str, "chi0") == 0) return (void *) chi0; + if (strcmp(str, "chi0") == 0) return (void *) chi; return nullptr; } diff --git a/src/MOLECULE/improper_harmonic.h b/src/MOLECULE/improper_harmonic.h index 05cb992011..a0047c28f2 100644 --- a/src/MOLECULE/improper_harmonic.h +++ b/src/MOLECULE/improper_harmonic.h @@ -36,7 +36,7 @@ class ImproperHarmonic : public Improper { void *extract(const char *, int &) override; protected: - double *k, *chi0; + double *k, *chi; virtual void allocate(); }; diff --git a/src/OPENMP/improper_harmonic_omp.cpp b/src/OPENMP/improper_harmonic_omp.cpp index 15b1af6934..12c2699663 100644 --- a/src/OPENMP/improper_harmonic_omp.cpp +++ b/src/OPENMP/improper_harmonic_omp.cpp @@ -156,7 +156,7 @@ void ImproperHarmonicOMP::eval(int nfrom, int nto, ThrData * const thr) // force & energy - domega = acos(c) - chi0[type]; + domega = acos(c) - chi[type]; a = k[type] * domega; if (EFLAG) eimproper = a*domega; diff --git a/src/YAFF/improper_sqdistharm.cpp b/src/YAFF/improper_sqdistharm.cpp index 038063eae8..71d0827c0c 100644 --- a/src/YAFF/improper_sqdistharm.cpp +++ b/src/YAFF/improper_sqdistharm.cpp @@ -276,6 +276,5 @@ void *ImproperSQDistHarm::extract(const char *str, int &dim) { dim = 1; if (strcmp(str, "k") == 0) return (void *) k; - if (strcmp(str, "chi") == 0) return (void *) chi; return nullptr; } From 52312fcd1d0c9a579a13aaa37c8b24032af82c8b Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Fri, 14 Feb 2025 06:22:29 +0000 Subject: [PATCH 087/120] test for extract() in improper class --- unittest/force-styles/test_improper_style.cpp | 41 +++++++++++++++++++ .../tests/improper-sqdistharm.yaml | 1 - 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index e272033e85..f390850358 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -720,3 +720,44 @@ TEST(ImproperStyle, numdiff) cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); } + +TEST(ImproperStyle, extract) +{ + if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); + + LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-ecoho", "screen", "-ncite"}; + + if (!verbose) ::testing::internal::CaptureStdout(); + LAMMPS *lmp = nullptr; + try { + lmp = init_lammps(args, test_config, true); + } catch (std::exception &e) { + if (!verbose) ::testing::internal::GetCapturedStdout(); + FAIL() << e.what(); + } + if (!verbose) ::testing::internal::GetCapturedStdout(); + + if (!lmp) { + std::cerr << "One or more prerequisite styles are not available " + "in this LAMMPS configuration:\n"; + for (auto prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; + } + GTEST_SKIP(); + } + + auto *improper = lmp->force->improper; + void *ptr = nullptr; + int dim = 0; + for (auto extract : test_config.extract) { + ptr = improper->extract(extract.first.c_str(), dim); + EXPECT_NE(ptr, nullptr); + EXPECT_EQ(dim, extract.second); + } + ptr = improper->extract("does_not_exist", dim); + EXPECT_EQ(ptr, nullptr); + + if (!verbose) ::testing::internal::CaptureStdout(); + cleanup_lammps(lmp, test_config); + if (!verbose) ::testing::internal::GetCapturedStdout(); +} \ No newline at end of file diff --git a/unittest/force-styles/tests/improper-sqdistharm.yaml b/unittest/force-styles/tests/improper-sqdistharm.yaml index 74ff07bb9a..7e08c86fc7 100644 --- a/unittest/force-styles/tests/improper-sqdistharm.yaml +++ b/unittest/force-styles/tests/improper-sqdistharm.yaml @@ -15,7 +15,6 @@ improper_coeff: ! | 2 45.0 6.2 extract: ! | k 1 - chi 1 natoms: 29 init_energy: 3997.62616072489 init_stress: ! |2- From 2a35452c134a87cf5603831286287e9dac508376 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Fri, 14 Feb 2025 06:40:01 +0000 Subject: [PATCH 088/120] fix typo and add new line --- unittest/force-styles/test_improper_style.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index f390850358..096c130235 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -725,7 +725,7 @@ TEST(ImproperStyle, extract) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-ecoho", "screen", "-ncite"}; + LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-ncite"}; if (!verbose) ::testing::internal::CaptureStdout(); LAMMPS *lmp = nullptr; @@ -760,4 +760,4 @@ TEST(ImproperStyle, extract) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); -} \ No newline at end of file +} From c83ae0365e366fe5ae89696490bebc1a440c3626 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Fri, 14 Feb 2025 09:09:10 +0200 Subject: [PATCH 089/120] fix typo ncite in test_improper_style.cpp --- unittest/force-styles/test_improper_style.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index 096c130235..4a8c3d5106 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -725,7 +725,7 @@ TEST(ImproperStyle, extract) { if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); - LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-ncite"}; + LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-echo", "screen", "-nocite"}; if (!verbose) ::testing::internal::CaptureStdout(); LAMMPS *lmp = nullptr; From 1f4b955a34875b1cec7cc0fb1733cfe636c143cb Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 27 Feb 2025 23:35:42 -0700 Subject: [PATCH 090/120] add dihedral multi/harmonic/kk --- doc/src/Commands_bond.rst | 2 +- doc/src/dihedral_multi_harmonic.rst | 2 +- src/KOKKOS/dihedral_multi_harmonic_kokkos.cpp | 541 ++++++++++++++++++ src/KOKKOS/dihedral_multi_harmonic_kokkos.h | 102 ++++ src/MOLECULE/dihedral_multi_harmonic.cpp | 2 +- src/MOLECULE/dihedral_multi_harmonic.h | 2 +- 6 files changed, 647 insertions(+), 4 deletions(-) create mode 100644 src/KOKKOS/dihedral_multi_harmonic_kokkos.cpp create mode 100644 src/KOKKOS/dihedral_multi_harmonic_kokkos.h diff --git a/doc/src/Commands_bond.rst b/doc/src/Commands_bond.rst index 40532bdef7..e091c9d44d 100644 --- a/doc/src/Commands_bond.rst +++ b/doc/src/Commands_bond.rst @@ -127,7 +127,7 @@ OPT. * :doc:`harmonic (iko) ` * :doc:`helix (o) ` * :doc:`lepton (o) ` - * :doc:`multi/harmonic (o) ` + * :doc:`multi/harmonic (ko) ` * :doc:`nharmonic (o) ` * :doc:`opls (iko) ` * :doc:`quadratic (o) ` diff --git a/doc/src/dihedral_multi_harmonic.rst b/doc/src/dihedral_multi_harmonic.rst index 176d3815dc..5f6f840d61 100644 --- a/doc/src/dihedral_multi_harmonic.rst +++ b/doc/src/dihedral_multi_harmonic.rst @@ -4,7 +4,7 @@ dihedral_style multi/harmonic command ===================================== -Accelerator Variants: *multi/harmonic/omp* +Accelerator Variants: *multi/harmonic/kk*, *multi/harmonic/omp* Syntax """""" diff --git a/src/KOKKOS/dihedral_multi_harmonic_kokkos.cpp b/src/KOKKOS/dihedral_multi_harmonic_kokkos.cpp new file mode 100644 index 0000000000..3824c1ea3b --- /dev/null +++ b/src/KOKKOS/dihedral_multi_harmonic_kokkos.cpp @@ -0,0 +1,541 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Richard Berger (LANL) +------------------------------------------------------------------------- */ + +#include "dihedral_multi_harmonic_kokkos.h" + +#include "atom_kokkos.h" +#include "atom_masks.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "memory_kokkos.h" +#include "neighbor_kokkos.h" + +#include + +using namespace LAMMPS_NS; + +static constexpr double TOLERANCE = 0.05; +static constexpr double SMALL = 0.001; + +/* ---------------------------------------------------------------------- */ + +template +DihedralMultiHarmonicKokkos::DihedralMultiHarmonicKokkos(LAMMPS *lmp) : DihedralMultiHarmonic(lmp) +{ + kokkosable = 1; + atomKK = (AtomKokkos *) atom; + neighborKK = (NeighborKokkos *) neighbor; + execution_space = ExecutionSpaceFromDevice::space; + datamask_read = X_MASK | F_MASK | Q_MASK | ENERGY_MASK | VIRIAL_MASK; + datamask_modify = F_MASK | ENERGY_MASK | VIRIAL_MASK; + + k_warning_flag = DAT::tdual_int_scalar("Dihedral:warning_flag"); + d_warning_flag = k_warning_flag.view(); + h_warning_flag = k_warning_flag.h_view; + + centroidstressflag = CENTROID_NOTAVAIL; +} + +/* ---------------------------------------------------------------------- */ + +template +DihedralMultiHarmonicKokkos::~DihedralMultiHarmonicKokkos() +{ + if (!copymode) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->destroy_kokkos(k_vatom,vatom); + } +} + +/* ---------------------------------------------------------------------- */ + +template +void DihedralMultiHarmonicKokkos::compute(int eflag_in, int vflag_in) +{ + eflag = eflag_in; + vflag = vflag_in; + + ev_init(eflag,vflag,0); + + // reallocate per-atom arrays if necessary + + if (eflag_atom) { + if ((int)k_eatom.extent(0) < maxeatom) { + memoryKK->destroy_kokkos(k_eatom,eatom); + memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"dihedral:eatom"); + d_eatom = k_eatom.view(); + } else Kokkos::deep_copy(d_eatom,0.0); + } + if (vflag_atom) { + if ((int)k_vatom.extent(0) < maxvatom) { + memoryKK->destroy_kokkos(k_vatom,vatom); + memoryKK->create_kokkos(k_vatom,vatom,maxvatom,"dihedral:vatom"); + d_vatom = k_vatom.view(); + } else Kokkos::deep_copy(d_vatom,0.0); + } + + k_a1.template sync(); + k_a2.template sync(); + k_a3.template sync(); + k_a4.template sync(); + k_a5.template sync(); + + x = atomKK->k_x.view(); + f = atomKK->k_f.view(); + neighborKK->k_dihedrallist.template sync(); + dihedrallist = neighborKK->k_dihedrallist.view(); + int ndihedrallist = neighborKK->ndihedrallist; + nlocal = atom->nlocal; + newton_bond = force->newton_bond; + + h_warning_flag() = 0; + k_warning_flag.modify_host(); + k_warning_flag.template sync(); + + copymode = 1; + + // loop over neighbors of my atoms + + EV_FLOAT ev; + + if (evflag) { + if (newton_bond) { + Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,ndihedrallist),*this,ev); + } else { + Kokkos::parallel_reduce(Kokkos::RangePolicy >(0,ndihedrallist),*this,ev); + } + } else { + if (newton_bond) { + Kokkos::parallel_for(Kokkos::RangePolicy >(0,ndihedrallist),*this); + } else { + Kokkos::parallel_for(Kokkos::RangePolicy >(0,ndihedrallist),*this); + } + } + + // error check + + k_warning_flag.template modify(); + k_warning_flag.sync_host(); + if (h_warning_flag()) + error->warning(FLERR,"Dihedral problem"); + + if (eflag_global) energy += ev.evdwl; + if (vflag_global) { + virial[0] += ev.v[0]; + virial[1] += ev.v[1]; + virial[2] += ev.v[2]; + virial[3] += ev.v[3]; + virial[4] += ev.v[4]; + virial[5] += ev.v[5]; + } + + if (eflag_atom) { + k_eatom.template modify(); + k_eatom.sync_host(); + } + + if (vflag_atom) { + k_vatom.template modify(); + k_vatom.sync_host(); + } + + copymode = 0; +} + +template +template +KOKKOS_INLINE_FUNCTION +void DihedralMultiHarmonicKokkos::operator()(TagDihedralMultiHarmonicCompute, const int &n, EV_FLOAT& ev) const { + + // The f array is atomic + Kokkos::View::value,Kokkos::MemoryTraits > a_f = f; + + const int i1 = dihedrallist(n,0); + const int i2 = dihedrallist(n,1); + const int i3 = dihedrallist(n,2); + const int i4 = dihedrallist(n,3); + const int type = dihedrallist(n,4); + + // 1st bond + + const F_FLOAT vb1x = x(i1,0) - x(i2,0); + const F_FLOAT vb1y = x(i1,1) - x(i2,1); + const F_FLOAT vb1z = x(i1,2) - x(i2,2); + + // 2nd bond + + const F_FLOAT vb2x = x(i3,0) - x(i2,0); + const F_FLOAT vb2y = x(i3,1) - x(i2,1); + const F_FLOAT vb2z = x(i3,2) - x(i2,2); + + const F_FLOAT vb2xm = -vb2x; + const F_FLOAT vb2ym = -vb2y; + const F_FLOAT vb2zm = -vb2z; + + // 3rd bond + + const F_FLOAT vb3x = x(i4,0) - x(i3,0); + const F_FLOAT vb3y = x(i4,1) - x(i3,1); + const F_FLOAT vb3z = x(i4,2) - x(i3,2); + + // c0 calculation + + const F_FLOAT sb1 = 1.0 / (vb1x * vb1x + vb1y * vb1y + vb1z * vb1z); + const F_FLOAT sb2 = 1.0 / (vb2x * vb2x + vb2y * vb2y + vb2z * vb2z); + const F_FLOAT sb3 = 1.0 / (vb3x * vb3x + vb3y * vb3y + vb3z * vb3z); + + const F_FLOAT rb1 = sqrt(sb1); + const F_FLOAT rb3 = sqrt(sb3); + + F_FLOAT c0 = (vb1x * vb3x + vb1y * vb3y + vb1z * vb3z) * rb1 * rb3; + + // 1st and 2nd angle + + F_FLOAT b1mag2 = vb1x * vb1x + vb1y * vb1y + vb1z * vb1z; + F_FLOAT b1mag = sqrt(b1mag2); + F_FLOAT b2mag2 = vb2x * vb2x + vb2y * vb2y + vb2z * vb2z; + F_FLOAT b2mag = sqrt(b2mag2); + F_FLOAT b3mag2 = vb3x * vb3x + vb3y * vb3y + vb3z * vb3z; + F_FLOAT b3mag = sqrt(b3mag2); + + F_FLOAT ctmp = vb1x * vb2x + vb1y * vb2y + vb1z * vb2z; + F_FLOAT r12c1 = 1.0 / (b1mag * b2mag); + F_FLOAT c1mag = ctmp * r12c1; + + ctmp = vb2xm * vb3x + vb2ym * vb3y + vb2zm * vb3z; + F_FLOAT r12c2 = 1.0 / (b2mag * b3mag); + F_FLOAT c2mag = ctmp * r12c2; + + // cos and sin of 2 angles and final c + + F_FLOAT sin2 = MAX(1.0 - c1mag * c1mag, 0.0); + F_FLOAT sc1 = sqrt(sin2); + if (sc1 < SMALL) sc1 = SMALL; + sc1 = 1.0 / sc1; + + sin2 = MAX(1.0 - c2mag * c2mag, 0.0); + F_FLOAT sc2 = sqrt(sin2); + if (sc2 < SMALL) sc2 = SMALL; + sc2 = 1.0 / sc2; + + F_FLOAT s1 = sc1 * sc1; + F_FLOAT s2 = sc2 * sc2; + F_FLOAT s12 = sc1 * sc2; + F_FLOAT c = (c0 + c1mag * c2mag) * s12; + + // error check + + if ((c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) && !d_warning_flag()) + d_warning_flag() = 1; + + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; + + // force & energy + // p = sum (i=1,5) a_i * c**(i-1) + // pd = dp/dc + + F_FLOAT p = d_a1[type] + c * (d_a2[type] + c * (d_a3[type] + c * (d_a4[type] + c * d_a5[type]))); + F_FLOAT pd = d_a2[type] + c * (2.0 * d_a3[type] + c * (3.0 * d_a4[type] + c * 4.0 * d_a5[type])); + + E_FLOAT edihedral = 0.0; + if (eflag) edihedral = p; + + const F_FLOAT a = pd; + c = c * a; + s12 = s12 * a; + const F_FLOAT a11 = c * sb1 * s1; + const F_FLOAT a22 = -sb2 * (2.0 * c0 * s12 - c * (s1 + s2)); + const F_FLOAT a33 = c * sb3 * s2; + const F_FLOAT a12 = -r12c1 * (c1mag * c * s1 + c2mag * s12); + const F_FLOAT a13 = -rb1 * rb3 * s12; + const F_FLOAT a23 = r12c2 * (c2mag * c * s2 + c1mag * s12); + + const F_FLOAT sx2 = a12 * vb1x + a22 * vb2x + a23 * vb3x; + const F_FLOAT sy2 = a12 * vb1y + a22 * vb2y + a23 * vb3y; + const F_FLOAT sz2 = a12 * vb1z + a22 * vb2z + a23 * vb3z; + + F_FLOAT f1[3],f2[3],f3[3],f4[3]; + f1[0] = a11 * vb1x + a12 * vb2x + a13 * vb3x; + f1[1] = a11 * vb1y + a12 * vb2y + a13 * vb3y; + f1[2] = a11 * vb1z + a12 * vb2z + a13 * vb3z; + + f2[0] = -sx2 - f1[0]; + f2[1] = -sy2 - f1[1]; + f2[2] = -sz2 - f1[2]; + + f4[0] = a13 * vb1x + a23 * vb2x + a33 * vb3x; + f4[1] = a13 * vb1y + a23 * vb2y + a33 * vb3y; + f4[2] = a13 * vb1z + a23 * vb2z + a33 * vb3z; + + f3[0] = sx2 - f4[0]; + f3[1] = sy2 - f4[1]; + f3[2] = sz2 - f4[2]; + + // apply force to each of 4 atoms + + if (NEWTON_BOND || i1 < nlocal) { + a_f(i1,0) += f1[0]; + a_f(i1,1) += f1[1]; + a_f(i1,2) += f1[2]; + } + + if (NEWTON_BOND || i2 < nlocal) { + a_f(i2,0) += f2[0]; + a_f(i2,1) += f2[1]; + a_f(i2,2) += f2[2]; + } + + if (NEWTON_BOND || i3 < nlocal) { + a_f(i3,0) += f3[0]; + a_f(i3,1) += f3[1]; + a_f(i3,2) += f3[2]; + } + + if (NEWTON_BOND || i4 < nlocal) { + a_f(i4,0) += f4[0]; + a_f(i4,1) += f4[1]; + a_f(i4,2) += f4[2]; + } + + if (EVFLAG) + ev_tally(ev,i1,i2,i3,i4,edihedral,f1,f3,f4, + vb1x,vb1y,vb1z,vb2x,vb2y,vb2z,vb3x,vb3y,vb3z); +} + +template +template +KOKKOS_INLINE_FUNCTION +void DihedralMultiHarmonicKokkos::operator()(TagDihedralMultiHarmonicCompute, const int &n) const { + EV_FLOAT ev; + this->template operator()(TagDihedralMultiHarmonicCompute(), n, ev); +} + +/* ---------------------------------------------------------------------- */ + +template +void DihedralMultiHarmonicKokkos::allocate() +{ + DihedralMultiHarmonic::allocate(); + + int n = atom->ndihedraltypes; + k_a1 = DAT::tdual_ffloat_1d("DihedralMultiHarmonic::a1",n+1); + k_a2 = DAT::tdual_ffloat_1d("DihedralMultiHarmonic::a2",n+1); + k_a3 = DAT::tdual_ffloat_1d("DihedralMultiHarmonic::a3",n+1); + k_a4 = DAT::tdual_ffloat_1d("DihedralMultiHarmonic::a4",n+1); + k_a5 = DAT::tdual_ffloat_1d("DihedralMultiHarmonic::a5",n+1); + + d_a1 = k_a1.template view(); + d_a2 = k_a2.template view(); + d_a3 = k_a3.template view(); + d_a4 = k_a4.template view(); + d_a5 = k_a5.template view(); +} + +/* ---------------------------------------------------------------------- + set coeffs for one type +------------------------------------------------------------------------- */ + +template +void DihedralMultiHarmonicKokkos::coeff(int narg, char **arg) +{ + DihedralMultiHarmonic::coeff(narg, arg); + + int n = atom->ndihedraltypes; + for (int i = 1; i <= n; i++) { + k_a1.h_view[i] = a1[i]; + k_a2.h_view[i] = a2[i]; + k_a3.h_view[i] = a3[i]; + k_a4.h_view[i] = a4[i]; + k_a5.h_view[i] = a5[i]; + } + + k_a1.modify_host(); + k_a2.modify_host(); + k_a3.modify_host(); + k_a4.modify_host(); + k_a5.modify_host(); +} + +/* ---------------------------------------------------------------------- + proc 0 reads coeffs from restart file, bcasts them +------------------------------------------------------------------------- */ + +template +void DihedralMultiHarmonicKokkos::read_restart(FILE *fp) +{ + DihedralMultiHarmonic::read_restart(fp); + + int n = atom->ndihedraltypes; + for (int i = 1; i <= n; i++) { + k_a1.h_view[i] = a1[i]; + k_a2.h_view[i] = a2[i]; + k_a3.h_view[i] = a3[i]; + k_a4.h_view[i] = a4[i]; + k_a5.h_view[i] = a5[i]; + } + + k_a1.modify_host(); + k_a2.modify_host(); + k_a3.modify_host(); + k_a4.modify_host(); + k_a5.modify_host(); +} + +/* ---------------------------------------------------------------------- + tally energy and virial into global and per-atom accumulators + virial = r1F1 + r2F2 + r3F3 + r4F4 = (r1-r2) F1 + (r3-r2) F3 + (r4-r2) F4 + = (r1-r2) F1 + (r3-r2) F3 + (r4-r3 + r3-r2) F4 + = vb1*f1 + vb2*f3 + (vb3+vb2)*f4 +------------------------------------------------------------------------- */ + +template +//template +KOKKOS_INLINE_FUNCTION +void DihedralMultiHarmonicKokkos::ev_tally(EV_FLOAT &ev, const int i1, const int i2, const int i3, const int i4, + F_FLOAT &edihedral, F_FLOAT *f1, F_FLOAT *f3, F_FLOAT *f4, + const F_FLOAT &vb1x, const F_FLOAT &vb1y, const F_FLOAT &vb1z, + const F_FLOAT &vb2x, const F_FLOAT &vb2y, const F_FLOAT &vb2z, + const F_FLOAT &vb3x, const F_FLOAT &vb3y, const F_FLOAT &vb3z) const +{ + E_FLOAT edihedralquarter; + F_FLOAT v[6]; + + // The eatom and vatom arrays are atomic + Kokkos::View::value,Kokkos::MemoryTraits > v_eatom = k_eatom.view(); + Kokkos::View::value,Kokkos::MemoryTraits > v_vatom = k_vatom.view(); + + if (eflag_either) { + if (eflag_global) { + if (newton_bond) ev.evdwl += edihedral; + else { + edihedralquarter = 0.25*edihedral; + if (i1 < nlocal) ev.evdwl += edihedralquarter; + if (i2 < nlocal) ev.evdwl += edihedralquarter; + if (i3 < nlocal) ev.evdwl += edihedralquarter; + if (i4 < nlocal) ev.evdwl += edihedralquarter; + } + } + if (eflag_atom) { + edihedralquarter = 0.25*edihedral; + if (newton_bond || i1 < nlocal) v_eatom[i1] += edihedralquarter; + if (newton_bond || i2 < nlocal) v_eatom[i2] += edihedralquarter; + if (newton_bond || i3 < nlocal) v_eatom[i3] += edihedralquarter; + if (newton_bond || i4 < nlocal) v_eatom[i4] += edihedralquarter; + } + } + + if (vflag_either) { + v[0] = vb1x*f1[0] + vb2x*f3[0] + (vb3x+vb2x)*f4[0]; + v[1] = vb1y*f1[1] + vb2y*f3[1] + (vb3y+vb2y)*f4[1]; + v[2] = vb1z*f1[2] + vb2z*f3[2] + (vb3z+vb2z)*f4[2]; + v[3] = vb1x*f1[1] + vb2x*f3[1] + (vb3x+vb2x)*f4[1]; + v[4] = vb1x*f1[2] + vb2x*f3[2] + (vb3x+vb2x)*f4[2]; + v[5] = vb1y*f1[2] + vb2y*f3[2] + (vb3y+vb2y)*f4[2]; + + if (vflag_global) { + if (newton_bond) { + ev.v[0] += v[0]; + ev.v[1] += v[1]; + ev.v[2] += v[2]; + ev.v[3] += v[3]; + ev.v[4] += v[4]; + ev.v[5] += v[5]; + } else { + if (i1 < nlocal) { + ev.v[0] += 0.25*v[0]; + ev.v[1] += 0.25*v[1]; + ev.v[2] += 0.25*v[2]; + ev.v[3] += 0.25*v[3]; + ev.v[4] += 0.25*v[4]; + ev.v[5] += 0.25*v[5]; + } + if (i2 < nlocal) { + ev.v[0] += 0.25*v[0]; + ev.v[1] += 0.25*v[1]; + ev.v[2] += 0.25*v[2]; + ev.v[3] += 0.25*v[3]; + ev.v[4] += 0.25*v[4]; + ev.v[5] += 0.25*v[5]; + } + if (i3 < nlocal) { + ev.v[0] += 0.25*v[0]; + ev.v[1] += 0.25*v[1]; + ev.v[2] += 0.25*v[2]; + ev.v[3] += 0.25*v[3]; + ev.v[4] += 0.25*v[4]; + ev.v[5] += 0.25*v[5]; + } + if (i4 < nlocal) { + ev.v[0] += 0.25*v[0]; + ev.v[1] += 0.25*v[1]; + ev.v[2] += 0.25*v[2]; + ev.v[3] += 0.25*v[3]; + ev.v[4] += 0.25*v[4]; + ev.v[5] += 0.25*v[5]; + } + } + } + + if (vflag_atom) { + if (newton_bond || i1 < nlocal) { + v_vatom(i1,0) += 0.25*v[0]; + v_vatom(i1,1) += 0.25*v[1]; + v_vatom(i1,2) += 0.25*v[2]; + v_vatom(i1,3) += 0.25*v[3]; + v_vatom(i1,4) += 0.25*v[4]; + v_vatom(i1,5) += 0.25*v[5]; + } + if (newton_bond || i2 < nlocal) { + v_vatom(i2,0) += 0.25*v[0]; + v_vatom(i2,1) += 0.25*v[1]; + v_vatom(i2,2) += 0.25*v[2]; + v_vatom(i2,3) += 0.25*v[3]; + v_vatom(i2,4) += 0.25*v[4]; + v_vatom(i2,5) += 0.25*v[5]; + } + if (newton_bond || i3 < nlocal) { + v_vatom(i3,0) += 0.25*v[0]; + v_vatom(i3,1) += 0.25*v[1]; + v_vatom(i3,2) += 0.25*v[2]; + v_vatom(i3,3) += 0.25*v[3]; + v_vatom(i3,4) += 0.25*v[4]; + v_vatom(i3,5) += 0.25*v[5]; + } + if (newton_bond || i4 < nlocal) { + v_vatom(i4,0) += 0.25*v[0]; + v_vatom(i4,1) += 0.25*v[1]; + v_vatom(i4,2) += 0.25*v[2]; + v_vatom(i4,3) += 0.25*v[3]; + v_vatom(i4,4) += 0.25*v[4]; + v_vatom(i4,5) += 0.25*v[5]; + } + } + } +} + +/* ---------------------------------------------------------------------- */ + +namespace LAMMPS_NS { +template class DihedralMultiHarmonicKokkos; +#ifdef LMP_KOKKOS_GPU +template class DihedralMultiHarmonicKokkos; +#endif +} + diff --git a/src/KOKKOS/dihedral_multi_harmonic_kokkos.h b/src/KOKKOS/dihedral_multi_harmonic_kokkos.h new file mode 100644 index 0000000000..68c07ddb54 --- /dev/null +++ b/src/KOKKOS/dihedral_multi_harmonic_kokkos.h @@ -0,0 +1,102 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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. +------------------------------------------------------------------------- */ + +#ifdef DIHEDRAL_CLASS +// clang-format off +DihedralStyle(multi/harmonic/kk,DihedralMultiHarmonicKokkos); +DihedralStyle(multi/harmonic/kk/device,DihedralMultiHarmonicKokkos); +DihedralStyle(multi/harmonic/kk/host,DihedralMultiHarmonicKokkos); +// clang-format on +#else + +// clang-format off +#ifndef LMP_DIHEDRAL_MULTI_HARMONIC_KOKKOS_H +#define LMP_DIHEDRAL_MULTI_HARMONIC_KOKKOS_H + +#include "dihedral_multi_harmonic.h" +#include "kokkos_type.h" + +namespace LAMMPS_NS { + +template +struct TagDihedralMultiHarmonicCompute{}; + +template +class DihedralMultiHarmonicKokkos : public DihedralMultiHarmonic { + public: + typedef DeviceType device_type; + typedef EV_FLOAT value_type; + typedef ArrayTypes AT; + + DihedralMultiHarmonicKokkos(class LAMMPS *); + ~DihedralMultiHarmonicKokkos() override; + void compute(int, int) override; + void coeff(int, char **) override; + void read_restart(FILE *) override; + + template + KOKKOS_INLINE_FUNCTION + void operator()(TagDihedralMultiHarmonicCompute, const int&, EV_FLOAT&) const; + + template + KOKKOS_INLINE_FUNCTION + void operator()(TagDihedralMultiHarmonicCompute, const int&) const; + + //template + KOKKOS_INLINE_FUNCTION + void ev_tally(EV_FLOAT &ev, const int i1, const int i2, const int i3, const int i4, + F_FLOAT &edihedral, F_FLOAT *f1, F_FLOAT *f3, F_FLOAT *f4, + const F_FLOAT &vb1x, const F_FLOAT &vb1y, const F_FLOAT &vb1z, + const F_FLOAT &vb2x, const F_FLOAT &vb2y, const F_FLOAT &vb2z, + const F_FLOAT &vb3x, const F_FLOAT &vb3y, const F_FLOAT &vb3z) const; + + DAT::tdual_efloat_1d k_eatom; + DAT::tdual_virial_array k_vatom; + + protected: + + class NeighborKokkos *neighborKK; + + typename AT::t_x_array_randomread x; + typename AT::t_f_array f; + typename AT::t_int_2d dihedrallist; + typename ArrayTypes::t_efloat_1d d_eatom; + typename ArrayTypes::t_virial_array d_vatom; + + int nlocal,newton_bond; + int eflag,vflag; + + DAT::tdual_int_scalar k_warning_flag; + typename AT::t_int_scalar d_warning_flag; + HAT::t_int_scalar h_warning_flag; + + DAT::tdual_ffloat_1d k_a1; + DAT::tdual_ffloat_1d k_a2; + DAT::tdual_ffloat_1d k_a3; + DAT::tdual_ffloat_1d k_a4; + DAT::tdual_ffloat_1d k_a5; + + typename AT::t_ffloat_1d d_a1; + typename AT::t_ffloat_1d d_a2; + typename AT::t_ffloat_1d d_a3; + typename AT::t_ffloat_1d d_a4; + typename AT::t_ffloat_1d d_a5; + + void allocate() override; +}; + +} + +#endif +#endif + diff --git a/src/MOLECULE/dihedral_multi_harmonic.cpp b/src/MOLECULE/dihedral_multi_harmonic.cpp index 2d1e16b9e4..6836b308fd 100644 --- a/src/MOLECULE/dihedral_multi_harmonic.cpp +++ b/src/MOLECULE/dihedral_multi_harmonic.cpp @@ -43,7 +43,7 @@ DihedralMultiHarmonic::DihedralMultiHarmonic(LAMMPS *_lmp) : Dihedral(_lmp) DihedralMultiHarmonic::~DihedralMultiHarmonic() { - if (allocated) { + if (allocated && !copymode) { memory->destroy(setflag); memory->destroy(a1); memory->destroy(a2); diff --git a/src/MOLECULE/dihedral_multi_harmonic.h b/src/MOLECULE/dihedral_multi_harmonic.h index 45f1112b4f..b1f46bd4bf 100644 --- a/src/MOLECULE/dihedral_multi_harmonic.h +++ b/src/MOLECULE/dihedral_multi_harmonic.h @@ -38,7 +38,7 @@ class DihedralMultiHarmonic : public Dihedral { protected: double *a1, *a2, *a3, *a4, *a5; - void allocate(); + virtual void allocate(); }; } // namespace LAMMPS_NS From 78bfa5b59bec3f1b03d035cee8a45632d8e77f44 Mon Sep 17 00:00:00 2001 From: Navraj Lalli Date: Tue, 18 Mar 2025 17:51:30 +0000 Subject: [PATCH 091/120] Create fix qeqr/reaxff --- src/.gitignore | 2 + src/OPENMP/pair_reaxff_omp.cpp | 1 + src/REAXFF/fix_qeqr_reaxff.cpp | 125 ++++++++++++++++++++++++++++++++ src/REAXFF/fix_qeqr_reaxff.h | 38 ++++++++++ src/REAXFF/fix_qtpie_reaxff.cpp | 10 ++- src/REAXFF/fix_qtpie_reaxff.h | 3 +- src/REAXFF/pair_reaxff.cpp | 3 +- src/fix_efield.h | 1 + 8 files changed, 179 insertions(+), 4 deletions(-) create mode 100644 src/REAXFF/fix_qeqr_reaxff.cpp create mode 100644 src/REAXFF/fix_qeqr_reaxff.h diff --git a/src/.gitignore b/src/.gitignore index a2f7da0400..cdd3c99603 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -996,6 +996,8 @@ /fix_qeq_fire.h /fix_qeq_reaxff.cpp /fix_qeq_reaxff.h +/fix_qeqr_reaxff.cpp +/fix_qeqr_reaxff.h /fix_qmmm.cpp /fix_qmmm.h /fix_qtpie_reaxff.cpp diff --git a/src/OPENMP/pair_reaxff_omp.cpp b/src/OPENMP/pair_reaxff_omp.cpp index 85369cc7bf..df28b64e98 100644 --- a/src/OPENMP/pair_reaxff_omp.cpp +++ b/src/OPENMP/pair_reaxff_omp.cpp @@ -106,6 +106,7 @@ void PairReaxFFOMP::init_style() auto acks2_fixes = modify->get_fix_by_style("^acks2/reax"); int have_qeq = modify->get_fix_by_style("^qeq/reax").size() + + modify->get_fix_by_style("^qeqr/reax").size() + modify->get_fix_by_style("^qeq/shielded").size() + acks2_fixes.size() + modify->get_fix_by_style("^qtpie/reax").size(); diff --git a/src/REAXFF/fix_qeqr_reaxff.cpp b/src/REAXFF/fix_qeqr_reaxff.cpp new file mode 100644 index 0000000000..98f13da2f0 --- /dev/null +++ b/src/REAXFF/fix_qeqr_reaxff.cpp @@ -0,0 +1,125 @@ +// clang-format off +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing authors: + Navraj S Lalli, Imperial College London (navrajsinghlalli@gmail.com) + +------------------------------------------------------------------------- */ + +#include "fix_qeqr_reaxff.h" + +#include "atom.h" +#include "comm.h" +#include "domain.h" +#include "error.h" +#include "fix_efield.h" +#include "force.h" +#include "group.h" +#include "modify.h" +#include "neigh_list.h" +#include "neighbor.h" +#include "pair.h" +#include "region.h" +#include "respa.h" +#include "text_file_reader.h" +#include "update.h" + +#include "pair_reaxff.h" +#include "reaxff_api.h" + +#include +#include + +using namespace LAMMPS_NS; +using namespace FixConst; + +static constexpr double ANGSTROM_TO_BOHRRADIUS = 1.8897261259; + +/* ---------------------------------------------------------------------- */ + +FixQEqrReaxFF::FixQEqrReaxFF(LAMMPS *lmp, int narg, char **arg) : + FixQtpieReaxFF(lmp, narg, arg) +{ +} + +/* ---------------------------------------------------------------------- */ + +void FixQEqrReaxFF::calc_chi_eff() +{ + memset(&chi_eff[0],0,atom->nmax*sizeof(double)); + + const auto x = (const double * const *)atom->x; + const int *type = atom->type; + + double dist,overlap,sum_n,sum_d,expa,expb,chia,phia,phib,p,m; + int i,j; + + // check ghost atoms are stored up to the distance cutoff for overlap integrals + const double comm_cutoff = MAX(neighbor->cutneighmax,comm->cutghostuser); + if(comm_cutoff < dist_cutoff/ANGSTROM_TO_BOHRRADIUS) { + error->all(FLERR,"comm cutoff = {} Angstrom is smaller than distance cutoff = {} Angstrom " + "for overlap integrals in {}. Increase comm cutoff with comm_modify", + comm_cutoff, dist_cutoff/ANGSTROM_TO_BOHRRADIUS, style); + } + + // efield energy is in real units of kcal/mol, factor needed for conversion to eV + const double qe2f = force->qe2f; + const double factor = 1.0/qe2f; + + if (efield) { + if (efield->varflag != FixEfield::CONSTANT) + efield->update_efield_variables(); + + // compute chi_eff for each local atom + for (i = 0; i < nn; i++) { + expa = gauss_exp[type[i]]; + chia = chi[type[i]]; + if (efield->varflag != FixEfield::ATOM) { + phia = -factor*(x[i][0]*efield->ex + x[i][1]*efield->ey + x[i][2]*efield->ez); + } else { // atom-style potential from FixEfield + phia = efield->efield[i][3]; + } + + sum_n = 0.0; + sum_d = 0.0; + + for (j = 0; j < nt; j++) { + dist = distance(x[i],x[j])*ANGSTROM_TO_BOHRRADIUS; // in atomic units + + if (dist < dist_cutoff) { + expb = gauss_exp[type[j]]; + + // overlap integral of two normalised 1s Gaussian type orbitals + p = expa + expb; + m = expa * expb / p; + overlap = pow((4.0*m/p),0.75) * exp(-m*dist*dist); + + if (efield->varflag != FixEfield::ATOM) { + phib = -factor*(x[j][0]*efield->ex + x[j][1]*efield->ey + x[j][2]*efield->ez); + } else { // atom-style potential from FixEfield + phib = efield->efield[j][3]; + } + sum_n += (chia + scale * (phia - phib)) * overlap; + sum_d += overlap; + } + } + chi_eff[i] = sum_n / sum_d; + } + } else { + for (i = 0; i < nn; i++) { + chi_eff[i] = chi[type[i]]; + } + } +} diff --git a/src/REAXFF/fix_qeqr_reaxff.h b/src/REAXFF/fix_qeqr_reaxff.h new file mode 100644 index 0000000000..a48a6ee632 --- /dev/null +++ b/src/REAXFF/fix_qeqr_reaxff.h @@ -0,0 +1,38 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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. +------------------------------------------------------------------------- */ + +#ifdef FIX_CLASS +// clang-format off +FixStyle(qeqr/reaxff,FixQEqrReaxFF); +// clang-format on +#else + +#ifndef LMP_FIX_QEQR_REAXFF_H +#define LMP_FIX_QEQR_REAXFF_H + +#include "fix_qtpie_reaxff.h" + +namespace LAMMPS_NS { + +class FixQEqrReaxFF : public FixQtpieReaxFF { + public: + FixQEqrReaxFF(class LAMMPS *, int, char **); + + protected: + void calc_chi_eff() override; +}; + +} // namespace LAMMPS_NS + +#endif +#endif diff --git a/src/REAXFF/fix_qtpie_reaxff.cpp b/src/REAXFF/fix_qtpie_reaxff.cpp index 3d5289ac6d..86331b2335 100644 --- a/src/REAXFF/fix_qtpie_reaxff.cpp +++ b/src/REAXFF/fix_qtpie_reaxff.cpp @@ -81,8 +81,9 @@ FixQtpieReaxFF::FixQtpieReaxFF(LAMMPS *lmp, int narg, char **arg) : imax = 200; maxwarn = 1; + scale = 1.0; - if ((narg < 9) || (narg > 12)) error->all(FLERR,"Illegal fix {} command", style); + if ((narg < 9) || (narg > 14)) error->all(FLERR,"Illegal fix {} command", style); nevery = utils::inumeric(FLERR,arg[3],false,lmp); if (nevery <= 0) error->all(FLERR,"Illegal fix {} command", style); @@ -101,6 +102,11 @@ FixQtpieReaxFF::FixQtpieReaxFF(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Illegal fix {} command", style); imax = utils::numeric(FLERR,arg[iarg+1],false,lmp); iarg++; + } else if (strcmp(arg[iarg],"scale") == 0) { + if (iarg+1 > narg-1) + error->all(FLERR,"Illegal fix {} command", style); + scale = utils::numeric(FLERR,arg[iarg+1],false,lmp); + iarg++; } else error->all(FLERR,"Illegal fix {} command", style); iarg++; } @@ -1172,7 +1178,7 @@ void FixQtpieReaxFF::calc_chi_eff() } else { // atom-style potential from FixEfield phib = efield->efield[j][3]; } - sum_n += (chia - chib + phia - phib) * overlap; + sum_n += (chia - chib + scale * (phia - phib)) * overlap; } else { sum_n += (chia - chib) * overlap; } diff --git a/src/REAXFF/fix_qtpie_reaxff.h b/src/REAXFF/fix_qtpie_reaxff.h index 2f86e27a7a..a0724912ff 100644 --- a/src/REAXFF/fix_qtpie_reaxff.h +++ b/src/REAXFF/fix_qtpie_reaxff.h @@ -91,6 +91,7 @@ class FixQtpieReaxFF : public Fix { char *gauss_file; // input file for gaussian orbital exponents double *gauss_exp; // array of gaussian orbital exponents for each atom type double dist_cutoff; // separation distance beyond which to neglect overlap integrals + double scale; // scaling factor for electric polarization effects void pertype_parameters(char *); void init_shielding(); @@ -128,7 +129,7 @@ class FixQtpieReaxFF : public Fix { void vector_sum(double *, double, double *, double, double *, int); void vector_add(double *, double, double *, int); - void calc_chi_eff(); + virtual void calc_chi_eff(); double find_min_exp(const double*, const int); double distance(const double*, const double*); diff --git a/src/REAXFF/pair_reaxff.cpp b/src/REAXFF/pair_reaxff.cpp index b36d9e79aa..56a2535108 100644 --- a/src/REAXFF/pair_reaxff.cpp +++ b/src/REAXFF/pair_reaxff.cpp @@ -341,12 +341,13 @@ void PairReaxFF::init_style() auto acks2_fixes = modify->get_fix_by_style("^acks2/reax"); int have_qeq = modify->get_fix_by_style("^qeq/reax").size() + modify->get_fix_by_style("^qeq/shielded").size() + acks2_fixes.size() + + modify->get_fix_by_style("^qeqr/reax").size() + modify->get_fix_by_style("^qtpie/reax").size(); if (qeqflag && (have_qeq != 1)) error->all(FLERR,"Pair style reaxff requires use of exactly one of the " "fix qeq/reaxff or fix qeq/shielded or fix acks2/reaxff or " - "fix qtpie/reaxff commands"); + "fix qtpie/reaxff commands or fix qeqr/reaxff"); api->system->acks2_flag = acks2_fixes.size(); if (api->system->acks2_flag) diff --git a/src/fix_efield.h b/src/fix_efield.h index 108395cc2c..83b5cc8d7e 100644 --- a/src/fix_efield.h +++ b/src/fix_efield.h @@ -26,6 +26,7 @@ namespace LAMMPS_NS { class FixEfield : public Fix { friend class FixQEqReaxFF; + friend class FixQEqrReaxFF; friend class FixQtpieReaxFF; public: From 056733fb1f72bb481be0ebfd2da47b4a6ff212ae Mon Sep 17 00:00:00 2001 From: Navraj Lalli Date: Tue, 18 Mar 2025 18:14:37 +0000 Subject: [PATCH 092/120] Add warning if fix efield is not in use fix qeqr/reaxff leads to the same charges as fix qeq/reaxff when an electric field is not applied, but at a slightly increased computational cost. Therefore, fix qeq/reaxff should be used instead of fix qeqr/reaxff when fix efield is not in use. --- src/REAXFF/fix_qeqr_reaxff.cpp | 62 ++++++++++++++++++++++++++++++++++ src/REAXFF/fix_qeqr_reaxff.h | 1 + 2 files changed, 63 insertions(+) diff --git a/src/REAXFF/fix_qeqr_reaxff.cpp b/src/REAXFF/fix_qeqr_reaxff.cpp index 98f13da2f0..bc84c24b29 100644 --- a/src/REAXFF/fix_qeqr_reaxff.cpp +++ b/src/REAXFF/fix_qeqr_reaxff.cpp @@ -45,6 +45,8 @@ using namespace LAMMPS_NS; using namespace FixConst; +static constexpr double CONV_TO_EV = 14.4; +static constexpr double QSUMSMALL = 0.00001; static constexpr double ANGSTROM_TO_BOHRRADIUS = 1.8897261259; /* ---------------------------------------------------------------------- */ @@ -54,6 +56,66 @@ FixQEqrReaxFF::FixQEqrReaxFF(LAMMPS *lmp, int narg, char **arg) : { } +void FixQEqrReaxFF::init() +{ + if (!atom->q_flag) + error->all(FLERR,"Fix {} requires atom attribute q", style); + + if (group->count(igroup) == 0) + error->all(FLERR,"Fix {} group has no atoms", style); + + // compute net charge and print warning if too large + double qsum_local = 0.0, qsum = 0.0; + for (int i = 0; i < atom->nlocal; i++) { + if (atom->mask[i] & groupbit) + qsum_local += atom->q[i]; + } + MPI_Allreduce(&qsum_local,&qsum,1,MPI_DOUBLE,MPI_SUM,world); + + if ((comm->me == 0) && (fabs(qsum) > QSUMSMALL)) + error->warning(FLERR,"Fix {} group is not charge neutral, net charge = {:.8}" + utils::errorurl(29), style, qsum); + + // get pointer to fix efield if present. there may be at most one instance of fix efield in use. + efield = nullptr; + auto fixes = modify->get_fix_by_style("^efield"); + if (fixes.size() == 1) efield = dynamic_cast(fixes.front()); + else if (fixes.size() > 1) + error->all(FLERR, "There may be only one fix efield instance used with fix {}", style); + + // ensure that fix efield is properly initialized before accessing its data and check some settings + if (efield) { + efield->init(); + if (strcmp(update->unit_style,"real") != 0) + error->all(FLERR,"Must use unit_style real with fix {} and external fields", style); + + if (efield->groupbit != 1){ // if efield is not applied to all atoms + error->all(FLERR,"Must use group id all for fix efield when using fix {}", style); + } + + if (efield->region){ // if efield is not applied to all atoms + error->all(FLERR,"Keyword region not supported for fix efield when using fix {}", style); + } + + if (efield->varflag == FixEfield::ATOM && efield->pstyle != FixEfield::ATOM) + error->all(FLERR,"Atom-style external electric field requires atom-style " + "potential variable when used with fix {}", style); + } else + if (comm->me == 0) + error->warning(FLERR, "Use fix qeq/reaxff instead of fix {} when not using fix efield", + style); + + // we need a half neighbor list w/ Newton off + // built whenever re-neighboring occurs + + neighbor->add_request(this, NeighConst::REQ_NEWTON_OFF); + + init_shielding(); + init_taper(); + + if (utils::strmatch(update->integrate_style,"^respa")) + nlevels_respa = (dynamic_cast(update->integrate))->nlevels; +} + /* ---------------------------------------------------------------------- */ void FixQEqrReaxFF::calc_chi_eff() diff --git a/src/REAXFF/fix_qeqr_reaxff.h b/src/REAXFF/fix_qeqr_reaxff.h index a48a6ee632..e885a34962 100644 --- a/src/REAXFF/fix_qeqr_reaxff.h +++ b/src/REAXFF/fix_qeqr_reaxff.h @@ -27,6 +27,7 @@ namespace LAMMPS_NS { class FixQEqrReaxFF : public FixQtpieReaxFF { public: FixQEqrReaxFF(class LAMMPS *, int, char **); + void init() override; protected: void calc_chi_eff() override; From 5bcfc35cd10c3e75e69bf54bef6950a9c2ffdc9e Mon Sep 17 00:00:00 2001 From: Navraj Lalli Date: Wed, 19 Mar 2025 10:23:22 +0000 Subject: [PATCH 093/120] Reimplement warning through fix qtpie/reaxff --- src/REAXFF/fix_qeqr_reaxff.cpp | 60 --------------------------------- src/REAXFF/fix_qeqr_reaxff.h | 1 - src/REAXFF/fix_qtpie_reaxff.cpp | 5 +++ 3 files changed, 5 insertions(+), 61 deletions(-) diff --git a/src/REAXFF/fix_qeqr_reaxff.cpp b/src/REAXFF/fix_qeqr_reaxff.cpp index bc84c24b29..29c329714d 100644 --- a/src/REAXFF/fix_qeqr_reaxff.cpp +++ b/src/REAXFF/fix_qeqr_reaxff.cpp @@ -56,66 +56,6 @@ FixQEqrReaxFF::FixQEqrReaxFF(LAMMPS *lmp, int narg, char **arg) : { } -void FixQEqrReaxFF::init() -{ - if (!atom->q_flag) - error->all(FLERR,"Fix {} requires atom attribute q", style); - - if (group->count(igroup) == 0) - error->all(FLERR,"Fix {} group has no atoms", style); - - // compute net charge and print warning if too large - double qsum_local = 0.0, qsum = 0.0; - for (int i = 0; i < atom->nlocal; i++) { - if (atom->mask[i] & groupbit) - qsum_local += atom->q[i]; - } - MPI_Allreduce(&qsum_local,&qsum,1,MPI_DOUBLE,MPI_SUM,world); - - if ((comm->me == 0) && (fabs(qsum) > QSUMSMALL)) - error->warning(FLERR,"Fix {} group is not charge neutral, net charge = {:.8}" + utils::errorurl(29), style, qsum); - - // get pointer to fix efield if present. there may be at most one instance of fix efield in use. - efield = nullptr; - auto fixes = modify->get_fix_by_style("^efield"); - if (fixes.size() == 1) efield = dynamic_cast(fixes.front()); - else if (fixes.size() > 1) - error->all(FLERR, "There may be only one fix efield instance used with fix {}", style); - - // ensure that fix efield is properly initialized before accessing its data and check some settings - if (efield) { - efield->init(); - if (strcmp(update->unit_style,"real") != 0) - error->all(FLERR,"Must use unit_style real with fix {} and external fields", style); - - if (efield->groupbit != 1){ // if efield is not applied to all atoms - error->all(FLERR,"Must use group id all for fix efield when using fix {}", style); - } - - if (efield->region){ // if efield is not applied to all atoms - error->all(FLERR,"Keyword region not supported for fix efield when using fix {}", style); - } - - if (efield->varflag == FixEfield::ATOM && efield->pstyle != FixEfield::ATOM) - error->all(FLERR,"Atom-style external electric field requires atom-style " - "potential variable when used with fix {}", style); - } else - if (comm->me == 0) - error->warning(FLERR, "Use fix qeq/reaxff instead of fix {} when not using fix efield", - style); - - // we need a half neighbor list w/ Newton off - // built whenever re-neighboring occurs - - neighbor->add_request(this, NeighConst::REQ_NEWTON_OFF); - - init_shielding(); - init_taper(); - - if (utils::strmatch(update->integrate_style,"^respa")) - nlevels_respa = (dynamic_cast(update->integrate))->nlevels; -} - /* ---------------------------------------------------------------------- */ void FixQEqrReaxFF::calc_chi_eff() diff --git a/src/REAXFF/fix_qeqr_reaxff.h b/src/REAXFF/fix_qeqr_reaxff.h index e885a34962..a48a6ee632 100644 --- a/src/REAXFF/fix_qeqr_reaxff.h +++ b/src/REAXFF/fix_qeqr_reaxff.h @@ -27,7 +27,6 @@ namespace LAMMPS_NS { class FixQEqrReaxFF : public FixQtpieReaxFF { public: FixQEqrReaxFF(class LAMMPS *, int, char **); - void init() override; protected: void calc_chi_eff() override; diff --git a/src/REAXFF/fix_qtpie_reaxff.cpp b/src/REAXFF/fix_qtpie_reaxff.cpp index 86331b2335..c226bb3462 100644 --- a/src/REAXFF/fix_qtpie_reaxff.cpp +++ b/src/REAXFF/fix_qtpie_reaxff.cpp @@ -487,8 +487,13 @@ void FixQtpieReaxFF::init() if (efield->varflag == FixEfield::ATOM && efield->pstyle != FixEfield::ATOM) error->all(FLERR,"Atom-style external electric field requires atom-style " "potential variable when used with fix {}", style); + } else { + if (utils::strmatch(style,"^qeqr/reax") && comm->me == 0) + error->warning(FLERR, "Use fix qeq/reaxff instead of fix {} when not using fix efield\n", + style); } + // we need a half neighbor list w/ Newton off // built whenever re-neighboring occurs From bb8b6590d5c0fb018c7063fe2f5c3b7ab99bf411 Mon Sep 17 00:00:00 2001 From: Navraj Lalli Date: Wed, 19 Mar 2025 11:22:04 +0000 Subject: [PATCH 094/120] Remove unused header files and add affiliation --- src/REAXFF/fix_qeqr_reaxff.cpp | 11 ----------- src/REAXFF/fix_qtpie_reaxff.cpp | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/REAXFF/fix_qeqr_reaxff.cpp b/src/REAXFF/fix_qeqr_reaxff.cpp index 29c329714d..dd546b2c96 100644 --- a/src/REAXFF/fix_qeqr_reaxff.cpp +++ b/src/REAXFF/fix_qeqr_reaxff.cpp @@ -22,19 +22,10 @@ #include "atom.h" #include "comm.h" -#include "domain.h" #include "error.h" #include "fix_efield.h" #include "force.h" -#include "group.h" -#include "modify.h" -#include "neigh_list.h" #include "neighbor.h" -#include "pair.h" -#include "region.h" -#include "respa.h" -#include "text_file_reader.h" -#include "update.h" #include "pair_reaxff.h" #include "reaxff_api.h" @@ -45,8 +36,6 @@ using namespace LAMMPS_NS; using namespace FixConst; -static constexpr double CONV_TO_EV = 14.4; -static constexpr double QSUMSMALL = 0.00001; static constexpr double ANGSTROM_TO_BOHRRADIUS = 1.8897261259; /* ---------------------------------------------------------------------- */ diff --git a/src/REAXFF/fix_qtpie_reaxff.cpp b/src/REAXFF/fix_qtpie_reaxff.cpp index c226bb3462..4ff9e34f7c 100644 --- a/src/REAXFF/fix_qtpie_reaxff.cpp +++ b/src/REAXFF/fix_qtpie_reaxff.cpp @@ -16,7 +16,7 @@ Contributing authors: Efstratios M Kritikos, California Institute of Technology (Implemented original version in LAMMMPS Aug 2019) - Navraj S Lalli, Imperial College London + Navraj S Lalli, Imperial College London (navrajsinghlalli@gmail.com) (Reimplemented QTPIE as a new fix in LAMMPS Aug 2024 and extended functionality) ------------------------------------------------------------------------- */ From e11245d0fda71e39ec42071c005f38b0f9548190 Mon Sep 17 00:00:00 2001 From: Navraj Lalli Date: Thu, 20 Mar 2025 10:42:12 +0000 Subject: [PATCH 095/120] Add examples for fix qeqr/reaxff --- examples/reaxff/water/in.water.qeqr | 29 +++++ examples/reaxff/water/in.water.qeqr.field | 30 +++++ .../log.20Mar25.reaxff.water-qeqr-field.g++.1 | 115 +++++++++++++++++ .../log.20Mar25.reaxff.water-qeqr-field.g++.4 | 115 +++++++++++++++++ .../water/log.20Mar25.reaxff.water-qeqr.g++.1 | 116 ++++++++++++++++++ .../water/log.20Mar25.reaxff.water-qeqr.g++.4 | 116 ++++++++++++++++++ src/REAXFF/fix_qtpie_reaxff.cpp | 3 +- 7 files changed, 523 insertions(+), 1 deletion(-) create mode 100644 examples/reaxff/water/in.water.qeqr create mode 100644 examples/reaxff/water/in.water.qeqr.field create mode 100644 examples/reaxff/water/log.20Mar25.reaxff.water-qeqr-field.g++.1 create mode 100644 examples/reaxff/water/log.20Mar25.reaxff.water-qeqr-field.g++.4 create mode 100644 examples/reaxff/water/log.20Mar25.reaxff.water-qeqr.g++.1 create mode 100644 examples/reaxff/water/log.20Mar25.reaxff.water-qeqr.g++.4 diff --git a/examples/reaxff/water/in.water.qeqr b/examples/reaxff/water/in.water.qeqr new file mode 100644 index 0000000000..6debe0b895 --- /dev/null +++ b/examples/reaxff/water/in.water.qeqr @@ -0,0 +1,29 @@ +# Water with QEqR + +boundary p p p +units real +atom_style charge + +read_data data.water + +variable x index 1 +variable y index 1 +variable z index 1 + +replicate $x $y $z + +pair_style reaxff NULL safezone 3.0 mincap 150 +pair_coeff * * qeq_ff.water O H +neighbor 0.5 bin +neigh_modify every 1 delay 0 check yes + +velocity all create 300.0 4928459 rot yes dist gaussian + +fix 1 all qeqr/reaxff 1 0.0 10.0 1.0e-6 reaxff gauss_exp.txt +fix 2 all nvt temp 300 300 50.0 + +timestep 0.5 +thermo 10 +thermo_style custom step temp press density vol + +run 20 diff --git a/examples/reaxff/water/in.water.qeqr.field b/examples/reaxff/water/in.water.qeqr.field new file mode 100644 index 0000000000..9c61477ff7 --- /dev/null +++ b/examples/reaxff/water/in.water.qeqr.field @@ -0,0 +1,30 @@ +# Water with QEqR + +boundary p p p +units real +atom_style charge + +read_data data.water + +variable x index 1 +variable y index 1 +variable z index 1 + +replicate $x $y $z + +pair_style reaxff NULL safezone 3.0 mincap 150 +pair_coeff * * qeq_ff.water O H +neighbor 0.5 bin +neigh_modify every 1 delay 0 check yes + +velocity all create 300.0 4928459 rot yes dist gaussian + +fix 1 all qeqr/reaxff 1 0.0 10.0 1.0e-6 reaxff gauss_exp.txt +fix 2 all nvt temp 300 300 50.0 +fix 3 all efield 0.0 0.0 0.05 + +timestep 0.5 +thermo 10 +thermo_style custom step temp press density vol + +run 20 diff --git a/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr-field.g++.1 b/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr-field.g++.1 new file mode 100644 index 0000000000..7f4c84d0f0 --- /dev/null +++ b/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr-field.g++.1 @@ -0,0 +1,115 @@ +LAMMPS (4 Feb 2025 - Development - patch_4Feb2025-444-gbb8b6590d5-modified) + using 1 OpenMP thread(s) per MPI task +# Water with QEqR + +boundary p p p +units real +atom_style charge + +read_data data.water +Reading data file ... + orthogonal box = (0 0 0) to (31.043046 31.043046 31.043046) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 3000 atoms + read_data CPU = 0.053 seconds + +variable x index 1 +variable y index 1 +variable z index 1 + +replicate $x $y $z +replicate 1 $y $z +replicate 1 1 $z +replicate 1 1 1 +Replication is creating a 1x1x1 = 1 times larger system... + orthogonal box = (0 0 0) to (31.043046 31.043046 31.043046) + 1 by 1 by 1 MPI processor grid + 3000 atoms + replicate CPU = 0.001 seconds + +pair_style reaxff NULL safezone 3.0 mincap 150 +pair_coeff * * qeq_ff.water O H +WARNING: Changed valency_val to valency_boc for X (src/REAXFF/reaxff_ffield.cpp:300) +neighbor 0.5 bin +neigh_modify every 1 delay 0 check yes + +velocity all create 300.0 4928459 rot yes dist gaussian + +fix 1 all qeqr/reaxff 1 0.0 10.0 1.0e-6 reaxff gauss_exp.txt +fix 2 all nvt temp 300 300 50.0 +fix 3 all efield 0.0 0.0 0.05 + +timestep 0.5 +thermo 10 +thermo_style custom step temp press density vol + +run 20 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- pair reaxff command: doi:10.1016/j.parco.2011.08.005 + +@Article{Aktulga12, + author = {H. M. Aktulga and J. C. Fogarty and S. A. Pandit and A. Y. Grama}, + title = {Parallel Reactive Molecular Dynamics: {N}umerical Methods and Algorithmic Techniques}, + journal = {Parallel Computing}, + year = 2012, + volume = 38, + number = {4--5}, + pages = {245--259} +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 10.5 + ghost atom cutoff = 10.5 + binsize = 5.25, bins = 6 6 6 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair reaxff, perpetual + attributes: half, newton off, ghost + pair build: half/bin/ghost/newtoff + stencil: full/ghost/bin/3d + bin: standard + (2) fix qeqr/reaxff, perpetual, copy from (1) + attributes: half, newton off + pair build: copy + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 539.2 | 539.2 | 539.2 Mbytes + Step Temp Press Density Volume + 0 300 778.75601 1 29915.273 + 10 301.42845 5423.6612 1 29915.273 + 20 298.24707 1549.2257 1 29915.273 +Loop time of 10.6859 on 1 procs for 20 steps with 3000 atoms + +Performance: 0.081 ns/day, 296.830 hours/ns, 1.872 timesteps/s, 5.615 katom-step/s +100.0% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 4.7595 | 4.7595 | 4.7595 | 0.0 | 44.54 +Neigh | 0.17605 | 0.17605 | 0.17605 | 0.0 | 1.65 +Comm | 0.0017511 | 0.0017511 | 0.0017511 | 0.0 | 0.02 +Output | 8.3809e-05 | 8.3809e-05 | 8.3809e-05 | 0.0 | 0.00 +Modify | 5.748 | 5.748 | 5.748 | 0.0 | 53.79 +Other | | 0.0005279 | | | 0.00 + +Nlocal: 3000 ave 3000 max 3000 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 11075 ave 11075 max 11075 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 971785 ave 971785 max 971785 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 971785 +Ave neighs/atom = 323.92833 +Neighbor list builds = 2 +Dangerous builds = 0 +Total wall time: 0:00:12 diff --git a/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr-field.g++.4 b/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr-field.g++.4 new file mode 100644 index 0000000000..722609d9bf --- /dev/null +++ b/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr-field.g++.4 @@ -0,0 +1,115 @@ +LAMMPS (4 Feb 2025 - Development - patch_4Feb2025-444-gbb8b6590d5-modified) + using 1 OpenMP thread(s) per MPI task +# Water with QEqR + +boundary p p p +units real +atom_style charge + +read_data data.water +Reading data file ... + orthogonal box = (0 0 0) to (31.043046 31.043046 31.043046) + 1 by 2 by 2 MPI processor grid + reading atoms ... + 3000 atoms + read_data CPU = 0.053 seconds + +variable x index 1 +variable y index 1 +variable z index 1 + +replicate $x $y $z +replicate 1 $y $z +replicate 1 1 $z +replicate 1 1 1 +Replication is creating a 1x1x1 = 1 times larger system... + orthogonal box = (0 0 0) to (31.043046 31.043046 31.043046) + 1 by 2 by 2 MPI processor grid + 3000 atoms + replicate CPU = 0.002 seconds + +pair_style reaxff NULL safezone 3.0 mincap 150 +pair_coeff * * qeq_ff.water O H +WARNING: Changed valency_val to valency_boc for X (src/REAXFF/reaxff_ffield.cpp:300) +neighbor 0.5 bin +neigh_modify every 1 delay 0 check yes + +velocity all create 300.0 4928459 rot yes dist gaussian + +fix 1 all qeqr/reaxff 1 0.0 10.0 1.0e-6 reaxff gauss_exp.txt +fix 2 all nvt temp 300 300 50.0 +fix 3 all efield 0.0 0.0 0.05 + +timestep 0.5 +thermo 10 +thermo_style custom step temp press density vol + +run 20 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- pair reaxff command: doi:10.1016/j.parco.2011.08.005 + +@Article{Aktulga12, + author = {H. M. Aktulga and J. C. Fogarty and S. A. Pandit and A. Y. Grama}, + title = {Parallel Reactive Molecular Dynamics: {N}umerical Methods and Algorithmic Techniques}, + journal = {Parallel Computing}, + year = 2012, + volume = 38, + number = {4--5}, + pages = {245--259} +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 10.5 + ghost atom cutoff = 10.5 + binsize = 5.25, bins = 6 6 6 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair reaxff, perpetual + attributes: half, newton off, ghost + pair build: half/bin/ghost/newtoff + stencil: full/ghost/bin/3d + bin: standard + (2) fix qeqr/reaxff, perpetual, copy from (1) + attributes: half, newton off + pair build: copy + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 260.5 | 262.2 | 263.6 Mbytes + Step Temp Press Density Volume + 0 300 778.75601 1 29915.273 + 10 301.42845 5423.6623 1 29915.273 + 20 298.24708 1549.2264 1 29915.273 +Loop time of 3.10467 on 4 procs for 20 steps with 3000 atoms + +Performance: 0.278 ns/day, 86.241 hours/ns, 6.442 timesteps/s, 19.326 katom-step/s +99.6% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 1.668 | 1.6843 | 1.7266 | 1.9 | 54.25 +Neigh | 0.08549 | 0.086004 | 0.086638 | 0.2 | 2.77 +Comm | 0.0135 | 0.055821 | 0.072105 | 10.4 | 1.80 +Output | 4.9632e-05 | 5.4515e-05 | 6.8384e-05 | 0.0 | 0.00 +Modify | 1.2774 | 1.2781 | 1.2786 | 0.0 | 41.17 +Other | | 0.000458 | | | 0.01 + +Nlocal: 750 ave 760 max 735 min +Histogram: 1 0 0 0 1 0 0 0 0 2 +Nghost: 6230.75 ave 6255 max 6191 min +Histogram: 1 0 0 0 0 1 0 0 1 1 +Neighs: 276996 ave 280553 max 271385 min +Histogram: 1 0 0 0 0 1 0 0 0 2 + +Total # of neighbors = 1107985 +Ave neighs/atom = 369.32833 +Neighbor list builds = 2 +Dangerous builds = 0 +Total wall time: 0:00:03 diff --git a/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr.g++.1 b/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr.g++.1 new file mode 100644 index 0000000000..9710c81bcb --- /dev/null +++ b/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr.g++.1 @@ -0,0 +1,116 @@ +LAMMPS (4 Feb 2025 - Development - patch_4Feb2025-444-gbb8b6590d5-modified) + using 1 OpenMP thread(s) per MPI task +# Water with QEqR + +boundary p p p +units real +atom_style charge + +read_data data.water +Reading data file ... + orthogonal box = (0 0 0) to (31.043046 31.043046 31.043046) + 1 by 1 by 1 MPI processor grid + reading atoms ... + 3000 atoms + read_data CPU = 0.055 seconds + +variable x index 1 +variable y index 1 +variable z index 1 + +replicate $x $y $z +replicate 1 $y $z +replicate 1 1 $z +replicate 1 1 1 +Replication is creating a 1x1x1 = 1 times larger system... + orthogonal box = (0 0 0) to (31.043046 31.043046 31.043046) + 1 by 1 by 1 MPI processor grid + 3000 atoms + replicate CPU = 0.001 seconds + +pair_style reaxff NULL safezone 3.0 mincap 150 +pair_coeff * * qeq_ff.water O H +WARNING: Changed valency_val to valency_boc for X (src/REAXFF/reaxff_ffield.cpp:300) +neighbor 0.5 bin +neigh_modify every 1 delay 0 check yes + +velocity all create 300.0 4928459 rot yes dist gaussian + +fix 1 all qeqr/reaxff 1 0.0 10.0 1.0e-6 reaxff gauss_exp.txt +fix 2 all nvt temp 300 300 50.0 + +timestep 0.5 +thermo 10 +thermo_style custom step temp press density vol + +run 20 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- pair reaxff command: doi:10.1016/j.parco.2011.08.005 + +@Article{Aktulga12, + author = {H. M. Aktulga and J. C. Fogarty and S. A. Pandit and A. Y. Grama}, + title = {Parallel Reactive Molecular Dynamics: {N}umerical Methods and Algorithmic Techniques}, + journal = {Parallel Computing}, + year = 2012, + volume = 38, + number = {4--5}, + pages = {245--259} +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +WARNING: Use fix qeq/reaxff instead of fix qeqr/reaxff when not using fix efield + (src/REAXFF/fix_qtpie_reaxff.cpp:493) +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 10.5 + ghost atom cutoff = 10.5 + binsize = 5.25, bins = 6 6 6 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair reaxff, perpetual + attributes: half, newton off, ghost + pair build: half/bin/ghost/newtoff + stencil: full/ghost/bin/3d + bin: standard + (2) fix qeqr/reaxff, perpetual, copy from (1) + attributes: half, newton off + pair build: copy + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 539.2 | 539.2 | 539.2 Mbytes + Step Temp Press Density Volume + 0 300 780.33989 1 29915.273 + 10 301.29205 5433.7414 1 29915.273 + 20 297.90652 1572.6111 1 29915.273 +Loop time of 6.87447 on 1 procs for 20 steps with 3000 atoms + +Performance: 0.126 ns/day, 190.957 hours/ns, 2.909 timesteps/s, 8.728 katom-step/s +100.0% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 4.8461 | 4.8461 | 4.8461 | 0.0 | 70.49 +Neigh | 0.17595 | 0.17595 | 0.17595 | 0.0 | 2.56 +Comm | 0.001787 | 0.001787 | 0.001787 | 0.0 | 0.03 +Output | 8.5794e-05 | 8.5794e-05 | 8.5794e-05 | 0.0 | 0.00 +Modify | 1.8501 | 1.8501 | 1.8501 | 0.0 | 26.91 +Other | | 0.0004811 | | | 0.01 + +Nlocal: 3000 ave 3000 max 3000 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 11077 ave 11077 max 11077 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 971826 ave 971826 max 971826 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 971826 +Ave neighs/atom = 323.942 +Neighbor list builds = 2 +Dangerous builds = 0 +Total wall time: 0:00:07 diff --git a/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr.g++.4 b/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr.g++.4 new file mode 100644 index 0000000000..e6182bf53a --- /dev/null +++ b/examples/reaxff/water/log.20Mar25.reaxff.water-qeqr.g++.4 @@ -0,0 +1,116 @@ +LAMMPS (4 Feb 2025 - Development - patch_4Feb2025-444-gbb8b6590d5-modified) + using 1 OpenMP thread(s) per MPI task +# Water with QEqR + +boundary p p p +units real +atom_style charge + +read_data data.water +Reading data file ... + orthogonal box = (0 0 0) to (31.043046 31.043046 31.043046) + 1 by 2 by 2 MPI processor grid + reading atoms ... + 3000 atoms + read_data CPU = 0.082 seconds + +variable x index 1 +variable y index 1 +variable z index 1 + +replicate $x $y $z +replicate 1 $y $z +replicate 1 1 $z +replicate 1 1 1 +Replication is creating a 1x1x1 = 1 times larger system... + orthogonal box = (0 0 0) to (31.043046 31.043046 31.043046) + 1 by 2 by 2 MPI processor grid + 3000 atoms + replicate CPU = 0.002 seconds + +pair_style reaxff NULL safezone 3.0 mincap 150 +pair_coeff * * qeq_ff.water O H +WARNING: Changed valency_val to valency_boc for X (src/REAXFF/reaxff_ffield.cpp:300) +neighbor 0.5 bin +neigh_modify every 1 delay 0 check yes + +velocity all create 300.0 4928459 rot yes dist gaussian + +fix 1 all qeqr/reaxff 1 0.0 10.0 1.0e-6 reaxff gauss_exp.txt +fix 2 all nvt temp 300 300 50.0 + +timestep 0.5 +thermo 10 +thermo_style custom step temp press density vol + +run 20 + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +Your simulation uses code contributions which should be cited: + +- pair reaxff command: doi:10.1016/j.parco.2011.08.005 + +@Article{Aktulga12, + author = {H. M. Aktulga and J. C. Fogarty and S. A. Pandit and A. Y. Grama}, + title = {Parallel Reactive Molecular Dynamics: {N}umerical Methods and Algorithmic Techniques}, + journal = {Parallel Computing}, + year = 2012, + volume = 38, + number = {4--5}, + pages = {245--259} +} + +CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE-CITE + +WARNING: Use fix qeq/reaxff instead of fix qeqr/reaxff when not using fix efield + (src/REAXFF/fix_qtpie_reaxff.cpp:493) +Neighbor list info ... + update: every = 1 steps, delay = 0 steps, check = yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 10.5 + ghost atom cutoff = 10.5 + binsize = 5.25, bins = 6 6 6 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair reaxff, perpetual + attributes: half, newton off, ghost + pair build: half/bin/ghost/newtoff + stencil: full/ghost/bin/3d + bin: standard + (2) fix qeqr/reaxff, perpetual, copy from (1) + attributes: half, newton off + pair build: copy + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 260.5 | 262.2 | 263.6 Mbytes + Step Temp Press Density Volume + 0 300 780.34006 1 29915.273 + 10 301.29205 5433.7414 1 29915.273 + 20 297.90652 1572.6112 1 29915.273 +Loop time of 2.52349 on 4 procs for 20 steps with 3000 atoms + +Performance: 0.342 ns/day, 70.097 hours/ns, 7.926 timesteps/s, 23.777 katom-step/s +99.0% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 1.7081 | 1.7518 | 1.7812 | 2.3 | 69.42 +Neigh | 0.10017 | 0.10116 | 0.10315 | 0.4 | 4.01 +Comm | 0.014848 | 0.044256 | 0.087941 | 14.7 | 1.75 +Output | 5.1199e-05 | 5.663e-05 | 7.1837e-05 | 0.0 | 0.00 +Modify | 0.62379 | 0.62575 | 0.62671 | 0.1 | 24.80 +Other | | 0.000504 | | | 0.02 + +Nlocal: 750 ave 759 max 735 min +Histogram: 1 0 0 0 0 1 0 0 0 2 +Nghost: 6230.5 ave 6256 max 6190 min +Histogram: 1 0 0 0 0 1 0 0 1 1 +Neighs: 277008 ave 280943 max 271394 min +Histogram: 1 0 0 0 0 1 0 0 1 1 + +Total # of neighbors = 1108032 +Ave neighs/atom = 369.344 +Neighbor list builds = 2 +Dangerous builds = 0 +Total wall time: 0:00:02 diff --git a/src/REAXFF/fix_qtpie_reaxff.cpp b/src/REAXFF/fix_qtpie_reaxff.cpp index 4ff9e34f7c..21c66bff9e 100644 --- a/src/REAXFF/fix_qtpie_reaxff.cpp +++ b/src/REAXFF/fix_qtpie_reaxff.cpp @@ -185,7 +185,8 @@ FixQtpieReaxFF::~FixQtpieReaxFF() void FixQtpieReaxFF::post_constructor() { - if (lmp->citeme) lmp->citeme->add(cite_fix_qtpie_reax); + if (utils::strmatch(style,"^qtpie/reax")) + if (lmp->citeme) lmp->citeme->add(cite_fix_qtpie_reax); grow_arrays(atom->nmax); for (int i = 0; i < atom->nmax; i++) From 2e98ae9de95e3ae6f45921021ea770472b2e40a0 Mon Sep 17 00:00:00 2001 From: Navraj Lalli Date: Thu, 20 Mar 2025 13:19:50 +0000 Subject: [PATCH 096/120] Improve qtpie/reaxff docs and add qeqr/reaxff docs --- doc/src/Commands_fix.rst | 1 + doc/src/fix.rst | 1 + doc/src/fix_acks2_reaxff.rst | 2 +- doc/src/fix_qeq_reaxff.rst | 5 +- doc/src/fix_qeqr_reaxff.rst | 198 ++++++++++++++++++++ doc/src/fix_qtpie_reaxff.rst | 42 +++-- doc/utils/sphinx-config/false_positives.txt | 5 + 7 files changed, 238 insertions(+), 16 deletions(-) create mode 100644 doc/src/fix_qeqr_reaxff.rst diff --git a/doc/src/Commands_fix.rst b/doc/src/Commands_fix.rst index ed9bf6429b..2e91d2ad11 100644 --- a/doc/src/Commands_fix.rst +++ b/doc/src/Commands_fix.rst @@ -186,6 +186,7 @@ OPT. * :doc:`qeq/fire ` * :doc:`qeq/point ` * :doc:`qeq/reaxff (ko) ` + * :doc:`qeqr/reaxff ` * :doc:`qeq/shielded ` * :doc:`qeq/slater ` * :doc:`qmmm ` diff --git a/doc/src/fix.rst b/doc/src/fix.rst index f024fc6974..87d58a0dfb 100644 --- a/doc/src/fix.rst +++ b/doc/src/fix.rst @@ -365,6 +365,7 @@ accelerated styles exist. * :doc:`qeq/fire ` - charge equilibration via FIRE minimizer * :doc:`qeq/point ` - charge equilibration via point method * :doc:`qeq/reaxff ` - charge equilibration for ReaxFF potential +* :doc:`qeqr/reaxff ` - charge equilibration for ReaxFF potential with alternate efield implementation * :doc:`qeq/shielded ` - charge equilibration via shielded method * :doc:`qeq/slater ` - charge equilibration via Slater method * :doc:`qmmm ` - functionality to enable a quantum mechanics/molecular mechanics coupling diff --git a/doc/src/fix_acks2_reaxff.rst b/doc/src/fix_acks2_reaxff.rst index 79a9cf8ea6..32a99eca2f 100644 --- a/doc/src/fix_acks2_reaxff.rst +++ b/doc/src/fix_acks2_reaxff.rst @@ -124,7 +124,7 @@ Related commands """""""""""""""" :doc:`pair_style reaxff `, :doc:`fix qeq/reaxff `, -:doc:`fix qtpi/reaxff ` +:doc:`fix qtpie/reaxff `, :doc:`fix qeqr/reaxff ` Default """"""" diff --git a/doc/src/fix_qeq_reaxff.rst b/doc/src/fix_qeq_reaxff.rst index e1a09c4fc3..c85e079e2b 100644 --- a/doc/src/fix_qeq_reaxff.rst +++ b/doc/src/fix_qeq_reaxff.rst @@ -59,7 +59,7 @@ extracted from the :doc:`pair_style reaxff ` command and the ReaxFF force field file it reads in. If a file name is specified for *params*, then the parameters are taken from the specified file and the file must contain one line for each atom type. The latter -form must be used when performing QeQ with a non-ReaxFF potential. +form must be used when performing QEq with a non-ReaxFF potential. Each line should be formatted as follows: .. parsed-literal:: @@ -140,7 +140,8 @@ Related commands """""""""""""""" :doc:`pair_style reaxff `, :doc:`fix qeq/shielded `, -:doc:`fix acks2/reaxff `, :doc:`fix qtpie/reaxff ` +:doc:`fix acks2/reaxff `, :doc:`fix qtpie/reaxff `, +:doc:`fix qeqr/reaxff ` Default """"""" diff --git a/doc/src/fix_qeqr_reaxff.rst b/doc/src/fix_qeqr_reaxff.rst new file mode 100644 index 0000000000..a89da15e3c --- /dev/null +++ b/doc/src/fix_qeqr_reaxff.rst @@ -0,0 +1,198 @@ +.. index:: fix qeqr/reaxff + +fix qeqr/reaxff command +======================== + +Syntax +"""""" + +.. code-block:: LAMMPS + + fix ID group-ID qeqr/reaxff Nevery cutlo cuthi tolerance params gfile args + +* ID, group-ID are documented in :doc:`fix ` command +* qeqr/reaxff = style name of this fix command +* Nevery = perform QEqR every this many steps +* cutlo,cuthi = lo and hi cutoff for Taper radius +* tolerance = precision to which charges will be equilibrated +* params = reaxff or a filename +* gfile = the name of a file containing Gaussian orbital exponents +* one or more keywords or keyword/value pairs may be appended + + .. parsed-literal:: + + keyword = *scale* or *maxiter* or *nowarn* + *scale* beta = set value of scaling factor *beta* (determines strength of electric polarization) + *maxiter* N = limit the number of iterations to *N* + *nowarn* = do not print a warning message if the maximum number of iterations is reached + +Examples +"""""""" + +.. code-block:: LAMMPS + + fix 1 all qeqr/reaxff 1 0.0 10.0 1.0e-6 reaxff exp.qeqr + fix 1 all qeqr/reaxff 1 0.0 10.0 1.0e-6 params.qeqr exp.qeqr scale 1.5 maxiter 500 nowarn + +Description +""""""""""" + +.. versionadded:: 19Nov2024 + +This fix implements QEqR, which only differs from the QEq charge equilibration +method :ref:`(Rappe and Goddard) ` in how external electric fields +are accounted for. This fix therefore raises a warning when used without +:doc:`fix efield ` informing the user to use +:doc:`fix qeq/reaxff ` instead since +:doc:`fix qeq/reaxff ` +leads to the same charges at slightly reduced computational cost. Charges are +computed with QEqR by minimizing the electrostatic energy of the system in the +same way as the QEq method but where the absolute electronegativity, +:math:`\chi_i`, of each atom in the QEq method is replaced with an effective +electronegativity given by + +.. math:: + \chi_{\mathrm{r}i} = \chi_i + \frac{\sum_{j=1}^{N} \beta(\phi_i - \phi_j) S_{ij}} + {\sum_{m=1}^{N}S_{im}}, + +where :math:`N` is the number of atoms in the system, :math:`\beta` is a scaling +factor, :math:`\phi_i` and :math:`\phi_j` are the electric potentials at the +positions of atoms :math:`i` and :math:`j` due to the external electric field +and :math:`S_{ij}` is the overlap integral between atoms :math:`i` and :math:`j`. +This formulation is advantageous over the method used by +:doc:`fix qeq/reaxff ` to account for an external electric +field in that it permits periodic boundaries in the direction of an external +electric field and in that it does not worsen long-range charge transfer seen +with QEq. + +This fix is typically used in conjunction with the ReaxFF force +field model as implemented in the :doc:`pair_style reaxff ` +command, but it can be used with any potential in LAMMPS, so long as it +defines and uses charges on each atom. For more technical details about the +charge equilibration performed by `fix qeqr/reaxff`, which is the same as in +:doc:`fix qeq/reaxff ` except for the use of +:math:`\chi_{\mathrm{r}i}`, please refer to :ref:`(Aktulga) `. +To be explicit, `fix qeqr/reaxff` replaces :math:`\chi_k` of eq. 3 in +:ref:`(Aktulga) ` with :math:`\chi_{\mathrm{r}k}` when an +external electric field is applied. + +This fix requires the absolute electronegativity, :math:`\chi`, in eV, the +self-Coulomb potential, :math:`\eta`, in eV, and the shielded Coulomb +constant, :math:`\gamma`, in :math:`\AA^{-1}`. If the *params* setting above +is the word "reaxff", then these are extracted from the +:doc:`pair_style reaxff ` command and the ReaxFF force field +file it reads in. If a file name is specified for *params*, then the +parameters are taken from the specified file and the file must contain +one line for each atom type. The latter form must be used when using this +fix with a non-ReaxFF potential. Each line should be formatted as follows, +ensuring that the parameters are given in units of eV, eV, and :math:`\AA^{-1}`, +respectively: + +.. parsed-literal:: + + itype chi eta gamma + +where *itype* is the atom type from 1 to Ntypes. Note that eta is +defined here as twice the eta value in the ReaxFF file. + +The overlap integrals :math:`S_{ij}` +are computed by using normalized 1s Gaussian type orbitals. The Gaussian +orbital exponents, :math:`\alpha`, that are needed to compute the overlap +integrals are taken from the file given by *gfile*. +This file must contain one line for each atom type and provide the Gaussian +orbital exponent for each atom type in units of inverse square Bohr radius. +Each line should be formatted as follows: + +.. parsed-literal:: + + itype alpha + +Empty lines or any text following the pound sign (#) are ignored. An example +*gfile* for a system with two atom types is + +.. parsed-literal:: + + # An example gfile. Exponents are taken from Table 2.2 of Chen, J. (2009). + # Theory and applications of fluctuating-charge models. + # The units of the exponents are 1 / (Bohr radius)^2 . + 1 0.2240 # O + 2 0.5434 # H + +The optional *scale* keyword sets the value of :math:`\beta` in the equation for +:math:`\chi_{\mathrm{r}i}`. The default value is 1.0. + +The optional *maxiter* keyword allows changing the max number +of iterations in the linear solver. The default value is 200. + +The optional *nowarn* keyword silences the warning message printed +when the maximum number of iterations is reached. This can be +useful for comparing serial and parallel results where having the +same fixed number of iterations is desired, which can be achieved +by using a very small tolerance and setting *maxiter* to the desired +number of iterations. + +.. note:: + + In order to solve the self-consistent equations for electronegativity + equalization, LAMMPS imposes the additional constraint that all the + charges in the fix group must add up to zero. The initial charge + assignments should also satisfy this constraint. LAMMPS will print a + warning if that is not the case. + +Restart, fix_modify, output, run start/stop, minimize info +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +No information about this fix is written to :doc:`binary restart files +`. This fix computes a global scalar (the number of +iterations) and a per-atom vector (the effective electronegativity), which +can be accessed by various :doc:`output commands `. +No parameter of this fix can be used with the *start/stop* keywords of +the :doc:`run ` command. + +This fix is invoked during :doc:`energy minimization `. + +Restrictions +"""""""""""" + +This fix is part of the REAXFF package. It is only enabled if +LAMMPS was built with that package. See the :doc:`Build package +` page for more info. + +This fix does not correctly handle interactions involving multiple +periodic images of the same atom. Hence, it should not be used for +periodic cell dimensions smaller than the non-bonded cutoff radius, +which is typically :math:`10~\AA` for ReaxFF simulations. + +This fix may be used in combination with :doc:`fix efield ` +and will apply the external electric field during charge equilibration, +but there may be only one fix efield instance used and the electric field +must be applied to all atoms in the system. Consequently, `fix efield` must +be used with *group-ID* all and must not be used with the keyword *region*. +Equal-style variables can be used for electric field vector +components without any further settings. Atom-style variables can be used +for spatially-varying electric field vector components, but the resulting +electric potential must be specified as an atom-style variable using +the *potential* keyword for `fix efield`. + +Related commands +"""""""""""""""" + +:doc:`pair_style reaxff `, :doc:`fix qeq/reaxff `, +:doc:`fix acks2/reaxff `, :doc:`fix qtpie/reaxff ` + +Default +""""""" + +scale = 1.0 and maxiter = 200 + +---------- + +.. _Rappe4: + +**(Rappe)** Rappe and Goddard III, Journal of Physical Chemistry, 95, +3358-3363 (1991). + +.. _qeq-Aktulga3: + +**(Aktulga)** Aktulga, Fogarty, Pandit, Grama, Parallel Computing, 38, +245-259 (2012). diff --git a/doc/src/fix_qtpie_reaxff.rst b/doc/src/fix_qtpie_reaxff.rst index e96cbec459..c3277af32c 100644 --- a/doc/src/fix_qtpie_reaxff.rst +++ b/doc/src/fix_qtpie_reaxff.rst @@ -21,8 +21,10 @@ Syntax .. parsed-literal:: - keyword = *maxiter* + keyword = *scale* or *maxiter* or *nowarn* + *scale* beta = set value of scaling factor *beta* (determines strength of electric polarization) *maxiter* N = limit the number of iterations to *N* + *nowarn* = do not print a warning message if the maximum number of iterations is reached Examples """""""" @@ -30,7 +32,7 @@ Examples .. code-block:: LAMMPS fix 1 all qtpie/reaxff 1 0.0 10.0 1.0e-6 reaxff exp.qtpie - fix 1 all qtpie/reaxff 1 0.0 10.0 1.0e-6 params.qtpie exp.qtpie maxiter 500 + fix 1 all qtpie/reaxff 1 0.0 10.0 1.0e-6 params.qtpie exp.qtpie scale 1.5 maxiter 500 nowarn Description """"""""""" @@ -46,7 +48,7 @@ same way as the QEq method but where the absolute electronegativity, electronegativity given by :ref:`(Chen) ` .. math:: - \chi_{\mathrm{eff},i} = \frac{\sum_{j=1}^{N} (\chi_i - \chi_j) S_{ij}} + \tilde{\chi}_{i} = \frac{\sum_{j=1}^{N} (\chi_i - \chi_j) S_{ij}} {\sum_{m=1}^{N}S_{im}}, which acts to penalize long-range charge transfer seen with the QEq charge @@ -61,11 +63,11 @@ electric field by using the effective electronegativity given in :ref:`(Gergs) `: .. math:: - \chi_{\mathrm{eff},i} = \frac{\sum_{j=1}^{N} (\chi_i - \chi_j + \phi_i - \phi_j) S_{ij}} + \tilde{\chi}_{\mathrm{r}i} = \frac{\sum_{j=1}^{N} (\chi_i - \chi_j + \beta(\phi_i - \phi_j)) S_{ij}} {\sum_{m=1}^{N}S_{im}}, -where :math:`\phi_i` and :math:`\phi_j` are the electric -potentials at the positions of atom :math:`i` and :math:`j` +where :math:`\beta` is a scaling factor and :math:`\phi_i` and :math:`\phi_j` +are the electric potentials at the positions of atoms :math:`i` and :math:`j` due to the external electric field. This fix is typically used in conjunction with the ReaxFF force @@ -74,9 +76,12 @@ command, but it can be used with any potential in LAMMPS, so long as it defines and uses charges on each atom. For more technical details about the charge equilibration performed by `fix qtpie/reaxff`, which is the same as in :doc:`fix qeq/reaxff ` except for the use of -:math:`\chi_{\mathrm{eff},i}`, please refer to :ref:`(Aktulga) `. +:math:`\tilde{\chi}_{i}` or :math:`\tilde{\chi}_{\mathrm{r}i}`, +please refer to :ref:`(Aktulga) `. To be explicit, this fix replaces :math:`\chi_k` of eq. 3 in -:ref:`(Aktulga) ` with :math:`\chi_{\mathrm{eff},k}`. +:ref:`(Aktulga) ` with :math:`\tilde{\chi}_{k}` when no external +electric field is applied and with :math:`\tilde{\chi}_{\mathrm{r}k}` when an +external electric field is applied. This fix requires the absolute electronegativity, :math:`\chi`, in eV, the self-Coulomb potential, :math:`\eta`, in eV, and the shielded Coulomb @@ -97,7 +102,7 @@ respectively: where *itype* is the atom type from 1 to Ntypes. Note that eta is defined here as twice the eta value in the ReaxFF file. -The overlap integrals in the equation for :math:`\chi_{\mathrm{eff},i}` +The overlap integrals :math:`S_{ij}` are computed by using normalized 1s Gaussian type orbitals. The Gaussian orbital exponents, :math:`\alpha`, that are needed to compute the overlap integrals are taken from the file given by *gfile*. @@ -120,15 +125,26 @@ Empty lines or any text following the pound sign (#) are ignored. An example 1 0.2240 # O 2 0.5434 # H +The optional *scale* keyword sets the value of :math:`\beta` in the equation for +:math:`\tilde{\chi}_{\mathrm{r}i}`. This keyword only affects the computed charges +when :doc:`fix efield ` is used. The default value is 1.0. + The optional *maxiter* keyword allows changing the max number of iterations in the linear solver. The default value is 200. +The optional *nowarn* keyword silences the warning message printed +when the maximum number of iterations is reached. This can be +useful for comparing serial and parallel results where having the +same fixed number of iterations is desired, which can be achieved +by using a very small tolerance and setting *maxiter* to the desired +number of iterations. + .. note:: In order to solve the self-consistent equations for electronegativity equalization, LAMMPS imposes the additional constraint that all the - charges in the fix group must add up to zero. The initial charge - assignments should also satisfy this constraint. LAMMPS will print a + charges in the fix group must add up to zero. The initial charge + assignments should also satisfy this constraint. LAMMPS will print a warning if that is not the case. Restart, fix_modify, output, run start/stop, minimize info @@ -170,12 +186,12 @@ Related commands """""""""""""""" :doc:`pair_style reaxff `, :doc:`fix qeq/reaxff `, -:doc:`fix acks2/reaxff ` +:doc:`fix acks2/reaxff `, :doc:`fix qeqr/reaxff ` Default """"""" -maxiter 200 +scale = 1.0 and maxiter = 200 ---------- diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 084f7c0ec1..13f4c3b33d 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -725,6 +725,7 @@ dashpot dat datafile datatype +dataset datums Davidchack Daw @@ -856,6 +857,7 @@ DNi Dobnikar Dobson docenv +docstring Dodds dodgerblue dof @@ -3116,9 +3118,11 @@ qE qeff qelectron qeq +qeqr Qamar QeQ QEq +QEqR qfactor qfile qi @@ -3261,6 +3265,7 @@ resquared REsquared restartfile restartinfo +reStructuredText Restrepo rethrowing Revenga From f5dbf3096549bf41eae18d12da55617a0c757852 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 26 Mar 2025 14:40:39 -0400 Subject: [PATCH 097/120] improve error messages --- src/dump_xyz.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/dump_xyz.cpp b/src/dump_xyz.cpp index 69892888bc..144b234bdf 100644 --- a/src/dump_xyz.cpp +++ b/src/dump_xyz.cpp @@ -16,6 +16,7 @@ #include "atom.h" #include "error.h" +#include "input.h" #include "label_map.h" #include "memory.h" #include "update.h" @@ -32,8 +33,8 @@ static constexpr int DELTA = 1048576; DumpXYZ::DumpXYZ(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg), typenames(nullptr) { - if (narg != 5) error->all(FLERR,"Illegal dump xyz command"); - if (binary || multiproc) error->all(FLERR,"Invalid dump xyz filename"); + if (narg != 5) error->all(FLERR, Error::NOPOINTER, "Illegal dump {} command", style); + if (binary || multiproc) error->all(FLERR, 4, "Invalid dump {} filename", style); size_one = 5; @@ -43,7 +44,6 @@ DumpXYZ::DumpXYZ(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg), sortcol = 0; delete[] format_default; - format_default = utils::strdup("%s %g %g %g"); ntypes = atom->ntypes; @@ -103,9 +103,16 @@ void DumpXYZ::init_style() int DumpXYZ::modify_param(int narg, char **arg) { + // determine argument offset, if possible + int ioffset = 0; + if (input->arg) { + for (int i = 0; i < input->narg; ++i) + if (input->arg[i] == arg[0]) ioffset = i; + } + if (strcmp(arg[0],"element") == 0) { if (narg < ntypes+1) - error->all(FLERR, "Dump modify element names do not match atom types"); + error->all(FLERR, ioffset, "Dump modify element names do not match number of atom types"); if (typenames) { for (int i = 1; i <= ntypes; i++) @@ -120,11 +127,11 @@ int DumpXYZ::modify_param(int narg, char **arg) typenames[itype] = utils::strdup(arg[itype]); } - return ntypes+1; + return ntypes + 1; } if (strcmp(arg[0],"types") == 0) { - if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); + if (narg < 2) utils::missing_cmd_args(FLERR,"dump_modify types", error); if (typenames) { for (int i = 1; i <= ntypes; i++) @@ -138,8 +145,8 @@ int DumpXYZ::modify_param(int narg, char **arg) return 2; } else if (strcmp(arg[1],"labels") == 0) { if (!atom->labelmapflag) - error->all(FLERR, "Label map must be defined when using 'types labels'"); - } else error->all(FLERR, "Illegal option for dump_modify 'types' keyword"); + error->all(FLERR, ioffset + 1, "Label map must be defined when using 'types labels'"); + } else error->all(FLERR, ioffset + 1, "Unknown option {} for dump_modify 'types' keyword", arg[1]); typenames = new char*[ntypes+1]; for (int itype = 1; itype <= ntypes; itype++) { @@ -157,7 +164,7 @@ int DumpXYZ::modify_param(int narg, char **arg) void DumpXYZ::write_header(bigint n) { if (me == 0) { - if (!fp) error->one(FLERR, "Must not use 'run pre no' after creating a new dump"); + if (!fp) error->one(FLERR, Error::NOLASTLINE, "Must not use 'run pre no' after creating a new dump"); auto header = fmt::format("{}\n Atoms. Timestep: {}", n, update->ntimestep); if (time_flag) header += fmt::format(" Time: {:.6f}", compute_time()); From 2ad0cc1820e7da56e587d168e9196fbad5be84d3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 26 Mar 2025 15:29:32 -0400 Subject: [PATCH 098/120] document extxyz dump style --- doc/src/Commands_dump.rst | 1 + doc/src/dump.rst | 53 +++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/doc/src/Commands_dump.rst b/doc/src/Commands_dump.rst index 86dab8b731..c938937755 100644 --- a/doc/src/Commands_dump.rst +++ b/doc/src/Commands_dump.rst @@ -19,6 +19,7 @@ An alphabetic list of all LAMMPS :doc:`dump ` commands. * :doc:`custom/gz ` * :doc:`custom/zstd ` * :doc:`dcd ` + * :doc:`extxyz ` * :doc:`grid ` * :doc:`grid/vtk ` * :doc:`h5md ` diff --git a/doc/src/dump.rst b/doc/src/dump.rst index a8175fa612..8c92884d11 100644 --- a/doc/src/dump.rst +++ b/doc/src/dump.rst @@ -3,6 +3,7 @@ .. index:: dump cfg .. index:: dump custom .. index:: dump dcd +.. index:: dump extxyz .. index:: dump grid .. index:: dump grid/vtk .. index:: dump local @@ -59,7 +60,7 @@ Syntax * ID = user-assigned name for the dump * group-ID = ID of the group of atoms to be dumped -* style = *atom* or *atom/adios* or *atom/gz* or *atom/zstd* or *cfg* or *cfg/gz* or *cfg/zstd* or *cfg/uef* or *custom* or *custom/gz* or *custom/zstd* or *custom/adios* or *dcd* or *grid* or *grid/vtk* or *h5md* or *image* or *local* or *local/gz* or *local/zstd* or *molfile* or *movie* or *netcdf* or *netcdf/mpiio* or *vtk* or *xtc* or *xyz* or *xyz/gz* or *xyz/zstd* or *yaml* +* style = *atom* or *atom/adios* or *atom/gz* or *atom/zstd* or *cfg* or *cfg/gz* or *cfg/zstd* or *cfg/uef* or *custom* or *custom/gz* or *custom/zstd* or *custom/adios* or *dcd* or *extxyz* or *grid* or *grid/vtk* or *h5md* or *image* or *local* or *local/gz* or *local/zstd* or *molfile* or *movie* or *netcdf* or *netcdf/mpiio* or *vtk* or *xtc* or *xyz* or *xyz/gz* or *xyz/zstd* or *yaml* * N = dump on timesteps which are multiples of N * file = name of file to write dump info to * attribute1,attribute2,... = list of attributes for a particular style @@ -77,6 +78,7 @@ Syntax *custom*, *custom/gz*, *custom/zstd* attributes = see below *custom/adios* attributes = same as *custom* attributes, discussed on :doc:`dump custom/adios ` page *dcd* attributes = none + *extxyz* attributes = none *h5md* attributes = discussed on :doc:`dump h5md ` page *grid* attributes = see below *grid/vtk* attributes = see below @@ -242,28 +244,29 @@ all the processors or multiple smaller files. frames consistently to the same atom. This can lead to incorrect visualizations or results. LAMMPS will print a warning in such cases. -For the *atom*, *custom*, *cfg*, *grid*, and *local* styles, sorting -is off by default. For the *dcd*, *grid/vtk*, *xtc*, *xyz*, and +For the *atom*, *custom*, *cfg*, *grid*, and *local* styles, sorting is +off by default. For the *dcd*, *extxyz*, *grid/vtk*, *xtc*, *xyz*, and *molfile* styles, sorting by atom ID or grid ID is on by default. See the :doc:`dump_modify ` page for details. The *style* keyword determines what kind of data is written to the dump file(s) and in what format. -Note that *atom*, *custom*, *dcd*, *xtc*, *xyz*, and *yaml* style dump -files can be read directly by `VMD `_, -a popular tool for visualizing and analyzing trajectories from atomic -and molecular systems. For reading *netcdf* style dump files, the -netcdf plugin needs to be recompiled from source using a NetCDF version -compatible with the one used by LAMMPS. The bundled plugin binary -uses a very old version of NetCDF that is not compatible with LAMMPS. +Note that *atom*, *custom*, *dcd*, *extxyz*, *xtc*, *xyz*, and *yaml* +style dump files can be read directly by `VMD +`_, a popular tool for visualizing +and analyzing trajectories from atomic and molecular systems. For +reading *netcdf* style dump files, the netcdf plugin needs to be +recompiled from source using a NetCDF version compatible with the one +used by LAMMPS. The bundled plugin binary uses a very old version of +NetCDF that is not compatible with LAMMPS. Likewise the `OVITO visualization package `_, -popular for materials modeling, can read the *atom*, *custom*, +popular for materials modeling, can read the *atom*, *custom*, *extxyz*, *local*, *xtc*, *cfg*, *netcdf*, and *xyz* style atom dump files -directly. With version 3.8 and above, OVITO can also read and -visualize *grid* style dump files with grid cell data, including -iso-surface images of the grid cell values. +directly. With version 3.8 and above, OVITO can also read and visualize +*grid* style dump files with grid cell data, including iso-surface +images of the grid cell values. Note that settings made via the :doc:`dump_modify ` command can also alter the format of individual values and content of @@ -475,6 +478,18 @@ label). This option will help many visualization programs to guess bonds and colors. You can use the :doc:`dump_modify types labels ` option to replace numeric atom types with :doc:`type labels `. +.. versionadded:: TBD + +The *extxyz* style writes XYZ files compatible with the Extended XYZ (or +ExtXYZ) format as defined as defined in `the libAtoms specification +`_. Specifically, the following +information will be dumped: + +* timestep +* time, if enabled with :doc:`dump_modify time yes ` +* simulation box lattice and pbc conditions +* atomic velocities and forces + .. versionadded:: 22Dec2022 The *grid/vtk* style writes VTK files for grid data on a regular @@ -607,8 +622,8 @@ with the processor ID from :math:`0` to :math:`P-1`. For example, tmp.dump.% becomes tmp.dump.0, tmp.dump.1, ... tmp.dump.:math:`P-1`, etc. This creates smaller files and can be a fast mode of output on parallel machines that support parallel I/O for output. This option is -**not** available for the *dcd*, *xtc*, *xyz*, *grid/vtk*, and *yaml* -styles. +**not** available for the *dcd*, *extxyz*, *xtc*, *xyz*, *grid/vtk*, and +*yaml* styles. By default, :math:`P` is the the number of processors, meaning one file per processor, but :math:`P` can be set to a smaller value via the *nfile* or @@ -1017,9 +1032,9 @@ the COMPRESS package. They are only enabled if LAMMPS was built with that package. See the :doc:`Build package ` page for more info. -The *xtc*, *dcd*, and *yaml* styles are part of the EXTRA-DUMP package. -They are only enabled if LAMMPS was built with that package. See the -:doc:`Build package ` page for more info. +The *dcd*, *extxyz*, *xtc*, and *yaml* styles are part of the EXTRA-DUMP +package. They are only enabled if LAMMPS was built with that package. +See the :doc:`Build package ` page for more info. Related commands """""""""""""""" From 855737cf04793e75ea0c3810316c680ac509a2fa Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 26 Mar 2025 15:37:42 -0400 Subject: [PATCH 099/120] implement derived extxyz dump style --- doc/src/dump.rst | 4 + src/.gitignore | 2 + src/EXTRA-DUMP/dump_extxyz.cpp | 159 +++++++++++++++++++++++++++++++++ src/EXTRA-DUMP/dump_extxyz.h | 42 +++++++++ src/dump_xyz.h | 2 +- src/label_map.h | 1 + 6 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 src/EXTRA-DUMP/dump_extxyz.cpp create mode 100644 src/EXTRA-DUMP/dump_extxyz.h diff --git a/doc/src/dump.rst b/doc/src/dump.rst index 8c92884d11..47cd2905af 100644 --- a/doc/src/dump.rst +++ b/doc/src/dump.rst @@ -490,6 +490,10 @@ information will be dumped: * simulation box lattice and pbc conditions * atomic velocities and forces +Dump style *extxyz* requires either that a :doc:`type label map for atoms types +` is defined or :doc:`dump_modify element ` is used to +set up an atom type number to atom name mapping. + .. versionadded:: 22Dec2022 The *grid/vtk* style writes VTK files for grid data on a regular diff --git a/src/.gitignore b/src/.gitignore index a2f7da0400..a6540d6611 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -419,6 +419,8 @@ /compute_hexorder_atom.h /dump_dcd.cpp /dump_dcd.h +/dump_extxyz.cpp +/dump_extxyz.h /fix_controller.cpp /fix_controller.h /fix_drag.cpp diff --git a/src/EXTRA-DUMP/dump_extxyz.cpp b/src/EXTRA-DUMP/dump_extxyz.cpp new file mode 100644 index 0000000000..6a32798c1a --- /dev/null +++ b/src/EXTRA-DUMP/dump_extxyz.cpp @@ -0,0 +1,159 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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 "dump_extxyz.h" + +#include "atom.h" +#include "domain.h" +#include "error.h" +#include "label_map.h" +#include "memory.h" +#include "update.h" + +#include + +using namespace LAMMPS_NS; + +static constexpr int ONELINE = 128; +static constexpr int DELTA = 1048576; + +/* ---------------------------------------------------------------------- */ + +DumpExtXYZ::DumpExtXYZ(LAMMPS *lmp, int narg, char **arg) : DumpXYZ(lmp, narg, arg) +{ + + size_one = 11; + delete[] format_default; + format_default = utils::strdup("%s %g %g %g %g %g %g %g %g %g"); + + // use type labels by default if present + if (atom->labelmapflag) { + typenames = new char *[ntypes + 1]; + for (int itype = 1; itype <= ntypes; itype++) { + typenames[itype] = utils::strdup(atom->lmap->typelabel[itype - 1]); + } + } +} + +/* ---------------------------------------------------------------------- */ + +void DumpExtXYZ::init_style() +{ + if (!typenames) + error->all(FLERR, Error::NOLASTLINE, + "Must use either typelables or dump_modify element with dump style extxyz"); + + DumpXYZ::init_style(); +} + +/* ---------------------------------------------------------------------- */ + +int DumpExtXYZ::modify_param(int narg, char **arg) +{ + int rv = DumpXYZ::modify_param(narg, arg); + if (rv > 0) return rv; + return 0; +} + +/* ---------------------------------------------------------------------- */ + +void DumpExtXYZ::write_header(bigint n) +{ + if (me == 0) { + if (!fp) error->one(FLERR, Error::NOLASTLINE, "Must not use 'run pre no' after creating a new dump"); + + std::string header; + + header = fmt::format("{}\nTimestep={}", n, update->ntimestep); + if (time_flag) header += fmt::format(" Time={:.6f}", compute_time()); + header += fmt::format(" pbc=\"{} {} {}\"", domain->xperiodic ? "T" : "F", + domain->yperiodic ? "T" : "F", domain->zperiodic ? "T" : "F"); + header += + fmt::format(" Lattice=\"{:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g}\"", domain->xprd, 0., + 0., domain->xy, domain->yprd, 0., domain->xz, domain->yz, domain->zprd); + header += " Properties=species:S:1:pos:R:3:vel:R:3:forces:R:3"; + utils::print(fp, header + "\n"); + } +} + +/* ---------------------------------------------------------------------- */ + +void DumpExtXYZ::pack(tagint *ids) +{ + int m, n; + + tagint *tag = atom->tag; + int *type = atom->type; + int *mask = atom->mask; + double **x = atom->x; + double **v = atom->v; + double **f = atom->f; + int nlocal = atom->nlocal; + + m = n = 0; + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + buf[m++] = tag[i]; + buf[m++] = type[i]; + buf[m++] = x[i][0]; + buf[m++] = x[i][1]; + buf[m++] = x[i][2]; + buf[m++] = v[i][0]; + buf[m++] = v[i][1]; + buf[m++] = v[i][2]; + buf[m++] = f[i][0]; + buf[m++] = f[i][1]; + buf[m++] = f[i][2]; + + if (ids) ids[n++] = tag[i]; + } +} + +/* ---------------------------------------------------------------------- + convert mybuf of doubles to one big formatted string in sbuf + return -1 if strlen exceeds an int, since used as arg in MPI calls in Dump +------------------------------------------------------------------------- */ + +int DumpExtXYZ::convert_string(int n, double *mybuf) +{ + int offset = 0; + int m = 0; + for (int i = 0; i < n; i++) { + if (offset + ONELINE > maxsbuf) { + if ((bigint) maxsbuf + DELTA > MAXSMALLINT) return -1; + maxsbuf += DELTA; + memory->grow(sbuf, maxsbuf, "dump:sbuf"); + } + + offset += + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], + mybuf[m + 8], mybuf[m + 9], mybuf[m + 10]); + m += size_one; + } + + return offset; +} + +/* ---------------------------------------------------------------------- */ + +void DumpExtXYZ::write_lines(int n, double *mybuf) +{ + int m = 0; + for (int i = 0; i < n; i++) { + fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], mybuf[m + 9], + mybuf[m + 10]); + m += size_one; + } +} diff --git a/src/EXTRA-DUMP/dump_extxyz.h b/src/EXTRA-DUMP/dump_extxyz.h new file mode 100644 index 0000000000..56f6a2670f --- /dev/null +++ b/src/EXTRA-DUMP/dump_extxyz.h @@ -0,0 +1,42 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://www.lammps.org/, Sandia National Laboratories + LAMMPS development team: developers@lammps.org + + 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. +------------------------------------------------------------------------- */ + +#ifdef DUMP_CLASS +// clang-format off +DumpStyle(extxyz,DumpExtXYZ); +// clang-format on +#else + +#ifndef LMP_DUMP_EXTXYZ_H +#define LMP_DUMP_EXTXYZ_H + +#include "dump_xyz.h" + +namespace LAMMPS_NS { + +class DumpExtXYZ : public DumpXYZ { + public: + DumpExtXYZ(class LAMMPS *, int, char **); + + protected: + void init_style() override; + void write_header(bigint) override; + void pack(tagint *) override; + int convert_string(int, double *) override; + int modify_param(int, char **) override; + + void write_lines(int, double *) override; +}; +} // namespace LAMMPS_NS +#endif +#endif diff --git a/src/dump_xyz.h b/src/dump_xyz.h index b5f8105114..a77f51e1fa 100644 --- a/src/dump_xyz.h +++ b/src/dump_xyz.h @@ -43,7 +43,7 @@ class DumpXYZ : public Dump { typedef void (DumpXYZ::*FnPtrWrite)(int, double *); FnPtrWrite write_choice; // ptr to write data functions void write_string(int, double *); - void write_lines(int, double *); + virtual void write_lines(int, double *); }; } // namespace LAMMPS_NS diff --git a/src/label_map.h b/src/label_map.h index eeab3aeae8..a10344cd4b 100644 --- a/src/label_map.h +++ b/src/label_map.h @@ -23,6 +23,7 @@ namespace LAMMPS_NS { class LabelMap : protected Pointers { friend class AtomVec; friend class DumpCustom; + friend class DumpExtXYZ; friend class DumpXYZ; friend class ReadData; From bb6470eb1a94877351fef476fac543dbc7c13b67 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Thu, 27 Mar 2025 15:58:29 +0100 Subject: [PATCH 100/120] More flexibility: forces, vel, mass --- src/EXTRA-DUMP/dump_extxyz.cpp | 78 ++++++++++++++++++++++++++++------ src/EXTRA-DUMP/dump_extxyz.h | 9 ++++ 2 files changed, 75 insertions(+), 12 deletions(-) diff --git a/src/EXTRA-DUMP/dump_extxyz.cpp b/src/EXTRA-DUMP/dump_extxyz.cpp index 6a32798c1a..2e3410c059 100644 --- a/src/EXTRA-DUMP/dump_extxyz.cpp +++ b/src/EXTRA-DUMP/dump_extxyz.cpp @@ -29,12 +29,35 @@ static constexpr int DELTA = 1048576; /* ---------------------------------------------------------------------- */ +void DumpExtXYZ::update_properties() +{ + // How many per-atom elements we buffer + size_one = 5 + (with_vel ? 3 : 0) + (with_forces ? 3 : 0) + (with_mass ? 1 : 0); + + // The properties string + delete[] properties_string; + properties_string = utils::strdup(fmt::format("species:S:1:pos:R:3{}{}{}", + (with_vel ? ":vel:R:3" : ""), (with_forces ? ":forces:R:3" : ""), (with_mass ? ":mass:R:1" : ""))); + + + // The output printf-style format + delete [] format; + if (format_line_user) + format = utils::strdup(fmt::format("{}\n", format_line_user)); + else { + format = utils::strdup(fmt::format("%s %g %g %g{}{}{}\n", + (with_vel ? " %g %g %g" : ""), (with_forces ? " %g %g %g" : ""), (with_mass ? " %g" : ""))); + } +} + +/* ---------------------------------------------------------------------- */ + DumpExtXYZ::DumpExtXYZ(LAMMPS *lmp, int narg, char **arg) : DumpXYZ(lmp, narg, arg) { + update_properties(); - size_one = 11; - delete[] format_default; - format_default = utils::strdup("%s %g %g %g %g %g %g %g %g %g"); + // We want time by default + time_flag = 1; // use type labels by default if present if (atom->labelmapflag) { @@ -54,6 +77,7 @@ void DumpExtXYZ::init_style() "Must use either typelables or dump_modify element with dump style extxyz"); DumpXYZ::init_style(); + update_properties(); } /* ---------------------------------------------------------------------- */ @@ -62,6 +86,28 @@ int DumpExtXYZ::modify_param(int narg, char **arg) { int rv = DumpXYZ::modify_param(narg, arg); if (rv > 0) return rv; + + if (strcmp(arg[0],"vel") == 0) { + if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); + with_vel = utils::logical(FLERR,arg[1],false,lmp); + update_properties(); + return 2; + } + + if (strcmp(arg[0],"forces") == 0) { + if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); + with_forces = utils::logical(FLERR,arg[1],false,lmp); + update_properties(); + return 2; + } + + if (strcmp(arg[0],"mass") == 0) { + if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); + with_mass = utils::logical(FLERR,arg[1],false,lmp); + update_properties(); + return 2; + } + return 0; } @@ -81,7 +127,7 @@ void DumpExtXYZ::write_header(bigint n) header += fmt::format(" Lattice=\"{:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g}\"", domain->xprd, 0., 0., domain->xy, domain->yprd, 0., domain->xz, domain->yz, domain->zprd); - header += " Properties=species:S:1:pos:R:3:vel:R:3:forces:R:3"; + header += fmt::format(" Properties={}", properties_string); utils::print(fp, header + "\n"); } } @@ -98,6 +144,7 @@ void DumpExtXYZ::pack(tagint *ids) double **x = atom->x; double **v = atom->v; double **f = atom->f; + double *mass = atom->mass; int nlocal = atom->nlocal; m = n = 0; @@ -108,12 +155,19 @@ void DumpExtXYZ::pack(tagint *ids) buf[m++] = x[i][0]; buf[m++] = x[i][1]; buf[m++] = x[i][2]; - buf[m++] = v[i][0]; - buf[m++] = v[i][1]; - buf[m++] = v[i][2]; - buf[m++] = f[i][0]; - buf[m++] = f[i][1]; - buf[m++] = f[i][2]; + if (with_vel) { + buf[m++] = v[i][0]; + buf[m++] = v[i][1]; + buf[m++] = v[i][2]; + } + if (with_forces) { + buf[m++] = f[i][0]; + buf[m++] = f[i][1]; + buf[m++] = f[i][2]; + } + if (with_mass) { + buf[m++] = mass[type[i]]; + } if (ids) ids[n++] = tag[i]; } @@ -138,7 +192,7 @@ int DumpExtXYZ::convert_string(int n, double *mybuf) offset += snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], - mybuf[m + 8], mybuf[m + 9], mybuf[m + 10]); + mybuf[m + 8], mybuf[m + 9], mybuf[m + 10], mybuf[m + 11]); m += size_one; } @@ -153,7 +207,7 @@ void DumpExtXYZ::write_lines(int n, double *mybuf) for (int i = 0; i < n; i++) { fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], mybuf[m + 9], - mybuf[m + 10]); + mybuf[m + 10], mybuf[m + 11]); m += size_one; } } diff --git a/src/EXTRA-DUMP/dump_extxyz.h b/src/EXTRA-DUMP/dump_extxyz.h index 56f6a2670f..a40d958b5b 100644 --- a/src/EXTRA-DUMP/dump_extxyz.h +++ b/src/EXTRA-DUMP/dump_extxyz.h @@ -29,6 +29,15 @@ class DumpExtXYZ : public DumpXYZ { DumpExtXYZ(class LAMMPS *, int, char **); protected: + int with_vel = 1; + int with_forces = 1; + int with_mass = 0; + int with_pe = 1; + int with_temp = 1; + int with_press = 0; + char *properties_string; + + void update_properties(); void init_style() override; void write_header(bigint) override; void pack(tagint *) override; From b0a83914138facc2baaa97ecf8a14f27e85c818f Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Thu, 27 Mar 2025 16:23:58 +0100 Subject: [PATCH 101/120] Update CODEOWNERS --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 5016d9a644..d286a6fa15 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -71,6 +71,7 @@ src/EXTRA-COMMAND/group_ndx.* @akohlmey src/EXTRA-COMMAND/ndx_group.* @akohlmey src/EXTRA-COMPUTE/compute_stress_mop*.* @RomainVermorel src/EXTRA-COMPUTE/compute_born_matrix.* @Bibobu @athomps +src/EXTRA-DUMP/dump_extxyz @fxcoudert src/EXTRA-FIX/fix_deform_pressure.* @jtclemm src/EXTRA-PAIR/pair_dispersion_d3.* @soniasolomoni @arthurfl src/EXTRA-PAIR/d3_parameters.h @soniasolomoni @arthurfl From 0c7c21925f0f8bb5ab54e1471a569525bd940d04 Mon Sep 17 00:00:00 2001 From: FX Coudert Date: Thu, 27 Mar 2025 16:55:35 +0100 Subject: [PATCH 102/120] Update .github/CODEOWNERS Co-authored-by: Axel Kohlmeyer --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index d286a6fa15..6d1bcee2db 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -71,7 +71,7 @@ src/EXTRA-COMMAND/group_ndx.* @akohlmey src/EXTRA-COMMAND/ndx_group.* @akohlmey src/EXTRA-COMPUTE/compute_stress_mop*.* @RomainVermorel src/EXTRA-COMPUTE/compute_born_matrix.* @Bibobu @athomps -src/EXTRA-DUMP/dump_extxyz @fxcoudert +src/EXTRA-DUMP/dump_extxyz.* @fxcoudert src/EXTRA-FIX/fix_deform_pressure.* @jtclemm src/EXTRA-PAIR/pair_dispersion_d3.* @soniasolomoni @arthurfl src/EXTRA-PAIR/d3_parameters.h @soniasolomoni @arthurfl From dcb844b01b608015543f56cf0d2940e135da1e83 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Thu, 27 Mar 2025 17:27:08 +0100 Subject: [PATCH 103/120] Safer printf --- src/EXTRA-DUMP/dump_extxyz.cpp | 62 +++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/src/EXTRA-DUMP/dump_extxyz.cpp b/src/EXTRA-DUMP/dump_extxyz.cpp index 2e3410c059..6e6dcca6c8 100644 --- a/src/EXTRA-DUMP/dump_extxyz.cpp +++ b/src/EXTRA-DUMP/dump_extxyz.cpp @@ -24,7 +24,7 @@ using namespace LAMMPS_NS; -static constexpr int ONELINE = 128; +static constexpr int ONELINE = 512; static constexpr int DELTA = 1048576; /* ---------------------------------------------------------------------- */ @@ -189,10 +189,36 @@ int DumpExtXYZ::convert_string(int n, double *mybuf) memory->grow(sbuf, maxsbuf, "dump:sbuf"); } - offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], - mybuf[m + 8], mybuf[m + 9], mybuf[m + 10], mybuf[m + 11]); + if (size_one == 5) { + offset += + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4]); + } else if (size_one == 6) { + offset += + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5]); + } else if (size_one == 8) { + offset += + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7]); + } else if (size_one == 9) { + offset += + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], + mybuf[m + 8]); + } else if (size_one == 11) { + offset += + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], + mybuf[m + 8], mybuf[m + 9], mybuf[m + 10]); + } else if (size_one == 12) { + offset += + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], + mybuf[m + 8], mybuf[m + 9], mybuf[m + 10], mybuf[m + 11]); + } else { + error->all(FLERR,"Invalid value of size_one for dump extxyz format."); + } m += size_one; } @@ -205,9 +231,29 @@ void DumpExtXYZ::write_lines(int n, double *mybuf) { int m = 0; for (int i = 0; i < n; i++) { - fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], - mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], mybuf[m + 9], - mybuf[m + 10], mybuf[m + 11]); + if (size_one == 5) { + fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4]); + } else if (size_one == 6) { + fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4], mybuf[m + 5]); + } else if (size_one == 8) { + fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7]); + } else if (size_one == 9) { + fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8]); + } else if (size_one == 11) { + fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], mybuf[m + 9], + mybuf[m + 10]); + } else if (size_one == 12) { + fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], mybuf[m + 9], + mybuf[m + 10], mybuf[m + 11]); + } else { + error->all(FLERR,"Invalid value of size_one for dump extxyz format."); + } m += size_one; } } From 032c1c39b0194c41ce0a95384dd8ec583ebd6e8b Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Thu, 27 Mar 2025 20:14:29 +0100 Subject: [PATCH 104/120] Handle mass better --- src/EXTRA-DUMP/dump_extxyz.cpp | 53 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/EXTRA-DUMP/dump_extxyz.cpp b/src/EXTRA-DUMP/dump_extxyz.cpp index 6e6dcca6c8..1381725260 100644 --- a/src/EXTRA-DUMP/dump_extxyz.cpp +++ b/src/EXTRA-DUMP/dump_extxyz.cpp @@ -145,6 +145,7 @@ void DumpExtXYZ::pack(tagint *ids) double **v = atom->v; double **f = atom->f; double *mass = atom->mass; + double *rmass = atom->rmass; int nlocal = atom->nlocal; m = n = 0; @@ -166,7 +167,11 @@ void DumpExtXYZ::pack(tagint *ids) buf[m++] = f[i][2]; } if (with_mass) { - buf[m++] = mass[type[i]]; + if (rmass) { + buf[m++] = rmass[i]; + } else { + buf[m++] = mass[type[i]]; + } } if (ids) ids[n++] = tag[i]; @@ -191,31 +196,31 @@ int DumpExtXYZ::convert_string(int n, double *mybuf) if (size_one == 5) { offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4]); + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4]); } else if (size_one == 6) { offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5]); + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5]); } else if (size_one == 8) { offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7]); + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7]); } else if (size_one == 9) { offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], - mybuf[m + 8]); + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], + mybuf[m + 8]); } else if (size_one == 11) { offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], - mybuf[m + 8], mybuf[m + 9], mybuf[m + 10]); + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], + mybuf[m + 8], mybuf[m + 9], mybuf[m + 10]); } else if (size_one == 12) { offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], - mybuf[m + 8], mybuf[m + 9], mybuf[m + 10], mybuf[m + 11]); + snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], + mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], + mybuf[m + 8], mybuf[m + 9], mybuf[m + 10], mybuf[m + 11]); } else { error->all(FLERR,"Invalid value of size_one for dump extxyz format."); } @@ -233,24 +238,24 @@ void DumpExtXYZ::write_lines(int n, double *mybuf) for (int i = 0; i < n; i++) { if (size_one == 5) { fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], - mybuf[m + 4]); + mybuf[m + 4]); } else if (size_one == 6) { fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], - mybuf[m + 4], mybuf[m + 5]); + mybuf[m + 4], mybuf[m + 5]); } else if (size_one == 8) { fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], - mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7]); + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7]); } else if (size_one == 9) { fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], - mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8]); + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8]); } else if (size_one == 11) { fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], - mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], mybuf[m + 9], - mybuf[m + 10]); + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], mybuf[m + 9], + mybuf[m + 10]); } else if (size_one == 12) { fprintf(fp, format, typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], - mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], mybuf[m + 9], - mybuf[m + 10], mybuf[m + 11]); + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], mybuf[m + 9], + mybuf[m + 10], mybuf[m + 11]); } else { error->all(FLERR,"Invalid value of size_one for dump extxyz format."); } From d12f4b076bb6ede76d988666bc5c03284d7da6d4 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Thu, 27 Mar 2025 21:05:38 +0100 Subject: [PATCH 105/120] Dump pe, temp, press --- src/EXTRA-DUMP/dump_extxyz.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/EXTRA-DUMP/dump_extxyz.cpp b/src/EXTRA-DUMP/dump_extxyz.cpp index 1381725260..e05de0e1a2 100644 --- a/src/EXTRA-DUMP/dump_extxyz.cpp +++ b/src/EXTRA-DUMP/dump_extxyz.cpp @@ -14,10 +14,12 @@ #include "dump_extxyz.h" #include "atom.h" +#include "compute.h" #include "domain.h" #include "error.h" #include "label_map.h" #include "memory.h" +#include "modify.h" #include "update.h" #include @@ -118,15 +120,36 @@ void DumpExtXYZ::write_header(bigint n) if (me == 0) { if (!fp) error->one(FLERR, Error::NOLASTLINE, "Must not use 'run pre no' after creating a new dump"); - std::string header; - - header = fmt::format("{}\nTimestep={}", n, update->ntimestep); + std::string header = fmt::format("{}\nTimestep={}", n, update->ntimestep); if (time_flag) header += fmt::format(" Time={:.6f}", compute_time()); header += fmt::format(" pbc=\"{} {} {}\"", domain->xperiodic ? "T" : "F", domain->yperiodic ? "T" : "F", domain->zperiodic ? "T" : "F"); header += fmt::format(" Lattice=\"{:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g}\"", domain->xprd, 0., 0., domain->xy, domain->yprd, 0., domain->xz, domain->yz, domain->zprd); + + Compute *pe_compute = modify->get_compute_by_id("thermo_pe"); + if (pe_compute->invoked_flag) { + double pe = pe_compute->compute_scalar(); + header += fmt::format(" Potential_energy={}", pe); + } + + Compute *temp_compute = modify->get_compute_by_id("thermo_temp"); + if (temp_compute->invoked_flag) { + double temp = temp_compute->compute_scalar(); + header += fmt::format(" Temperature={}", temp); + } + + Compute *press_compute = modify->get_compute_by_id("thermo_press"); + if (press_compute->invoked_flag) { + press_compute->compute_vector(); + double *press = press_compute->vector; + header += fmt::format(" Stress=\"{} {} {} {} {} {} {} {} {}\"", + press[0], press[3], press[4], + press[3], press[1], press[5], + press[4], press[5], press[2]); + } + header += fmt::format(" Properties={}", properties_string); utils::print(fp, header + "\n"); } From f652687a3a2af8e818b68902487478e934c5abae Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Mar 2025 17:14:06 -0400 Subject: [PATCH 106/120] add support for outputting the same temperature, pressure, and potential energy as the thermo output --- src/EXTRA-DUMP/dump_extxyz.cpp | 88 +++++++++++++++++++--------------- src/EXTRA-DUMP/dump_extxyz.h | 13 +++-- src/thermo.cpp | 4 +- src/thermo.h | 8 ++-- 4 files changed, 62 insertions(+), 51 deletions(-) diff --git a/src/EXTRA-DUMP/dump_extxyz.cpp b/src/EXTRA-DUMP/dump_extxyz.cpp index e05de0e1a2..0936d96abf 100644 --- a/src/EXTRA-DUMP/dump_extxyz.cpp +++ b/src/EXTRA-DUMP/dump_extxyz.cpp @@ -20,6 +20,8 @@ #include "label_map.h" #include "memory.h" #include "modify.h" +#include "output.h" +#include "thermo.h" #include "update.h" #include @@ -31,6 +33,36 @@ static constexpr int DELTA = 1048576; /* ---------------------------------------------------------------------- */ +DumpExtXYZ::DumpExtXYZ(LAMMPS *lmp, int narg, char **arg) : + DumpXYZ(lmp, narg, arg), properties_string(nullptr) +{ + // style specific customizable settings + with_vel = 1; + with_forces = 1; + with_mass = 0; + with_pe = 1; + with_temp = 1; + with_press = 0; + + update_properties(); + + // We want simulation time by default + time_flag = 1; + + // dump may invoke computes + clearstep = 1; + + // use type labels by default if present + if (atom->labelmapflag) { + typenames = new char *[ntypes + 1]; + for (int itype = 1; itype <= ntypes; itype++) { + typenames[itype] = utils::strdup(atom->lmap->typelabel[itype - 1]); + } + } +} + +/* ---------------------------------------------------------------------- */ + void DumpExtXYZ::update_properties() { // How many per-atom elements we buffer @@ -54,29 +86,11 @@ void DumpExtXYZ::update_properties() /* ---------------------------------------------------------------------- */ -DumpExtXYZ::DumpExtXYZ(LAMMPS *lmp, int narg, char **arg) : DumpXYZ(lmp, narg, arg) -{ - update_properties(); - - // We want time by default - time_flag = 1; - - // use type labels by default if present - if (atom->labelmapflag) { - typenames = new char *[ntypes + 1]; - for (int itype = 1; itype <= ntypes; itype++) { - typenames[itype] = utils::strdup(atom->lmap->typelabel[itype - 1]); - } - } -} - -/* ---------------------------------------------------------------------- */ - void DumpExtXYZ::init_style() { if (!typenames) error->all(FLERR, Error::NOLASTLINE, - "Must use either typelables or dump_modify element with dump style extxyz"); + "Must use either type lables or dump_modify element with dump style extxyz"); DumpXYZ::init_style(); update_properties(); @@ -118,7 +132,8 @@ int DumpExtXYZ::modify_param(int narg, char **arg) void DumpExtXYZ::write_header(bigint n) { if (me == 0) { - if (!fp) error->one(FLERR, Error::NOLASTLINE, "Must not use 'run pre no' after creating a new dump"); + if (!fp) + error->one(FLERR, Error::NOLASTLINE, "Must not use 'run pre no' after creating a new dump"); std::string header = fmt::format("{}\nTimestep={}", n, update->ntimestep); if (time_flag) header += fmt::format(" Time={:.6f}", compute_time()); @@ -128,28 +143,23 @@ void DumpExtXYZ::write_header(bigint n) fmt::format(" Lattice=\"{:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g}\"", domain->xprd, 0., 0., domain->xy, domain->yprd, 0., domain->xz, domain->yz, domain->zprd); - Compute *pe_compute = modify->get_compute_by_id("thermo_pe"); - if (pe_compute->invoked_flag) { - double pe = pe_compute->compute_scalar(); - header += fmt::format(" Potential_energy={}", pe); - } + if (output && output->thermo) { + auto *pe = output->thermo->pe; + if (pe) header += fmt::format(" Potential_energy={}", pe->compute_scalar()); - Compute *temp_compute = modify->get_compute_by_id("thermo_temp"); - if (temp_compute->invoked_flag) { - double temp = temp_compute->compute_scalar(); - header += fmt::format(" Temperature={}", temp); - } + auto *temp = output->thermo->temperature; + if (temp) header += fmt::format(" Temperature={}", temp->compute_scalar()); - Compute *press_compute = modify->get_compute_by_id("thermo_press"); - if (press_compute->invoked_flag) { - press_compute->compute_vector(); - double *press = press_compute->vector; - header += fmt::format(" Stress=\"{} {} {} {} {} {} {} {} {}\"", - press[0], press[3], press[4], - press[3], press[1], press[5], - press[4], press[5], press[2]); + auto *press = output->thermo->pressure; + if (press) { + press->compute_vector(); + header += fmt::format(" Stress=\"{} {} {} {} {} {} {} {} {}\"", + press->vector[0], press->vector[3], press->vector[4], + press->vector[3], press->vector[1], press->vector[5], + press->vector[4], press->vector[5], press->vector[2]); + } } - + header += fmt::format(" Properties={}", properties_string); utils::print(fp, header + "\n"); } diff --git a/src/EXTRA-DUMP/dump_extxyz.h b/src/EXTRA-DUMP/dump_extxyz.h index a40d958b5b..b32deb0a23 100644 --- a/src/EXTRA-DUMP/dump_extxyz.h +++ b/src/EXTRA-DUMP/dump_extxyz.h @@ -23,18 +23,17 @@ DumpStyle(extxyz,DumpExtXYZ); #include "dump_xyz.h" namespace LAMMPS_NS { - class DumpExtXYZ : public DumpXYZ { public: DumpExtXYZ(class LAMMPS *, int, char **); protected: - int with_vel = 1; - int with_forces = 1; - int with_mass = 0; - int with_pe = 1; - int with_temp = 1; - int with_press = 0; + int with_vel; + int with_forces; + int with_mass; + int with_pe; + int with_temp; + int with_press; char *properties_string; void update_properties(); diff --git a/src/thermo.cpp b/src/thermo.cpp index caf5206b4a..b07cfe539d 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -101,8 +101,8 @@ static char fmtbuf[512]; /* ---------------------------------------------------------------------- */ Thermo::Thermo(LAMMPS *_lmp, int narg, char **arg) : - Pointers(_lmp), style(nullptr), vtype(nullptr), cache_mutex(nullptr), field2index(nullptr), - argindex1(nullptr), argindex2(nullptr), temperature(nullptr), pressure(nullptr), pe(nullptr) + Pointers(_lmp), style(nullptr), temperature(nullptr), pressure(nullptr), pe(nullptr), + vtype(nullptr), cache_mutex(nullptr), field2index(nullptr), argindex1(nullptr), argindex2(nullptr) { style = utils::strdup(arg[0]); diff --git a/src/thermo.h b/src/thermo.h index f5466e70cd..109d838dc5 100644 --- a/src/thermo.h +++ b/src/thermo.h @@ -21,8 +21,8 @@ namespace LAMMPS_NS { class Thermo : protected Pointers { - friend class MinCG; // accesses compute_pe - + friend class MinCG; // accesses compute_pe + friend class DumpExtXYZ; // accesses compute_temp, compute_press, compute_pe public: char *style; int normflag; // 0 if do not normalize by atoms, 1 if normalize @@ -57,6 +57,9 @@ class Thermo : protected Pointers { void set_line(int _nline) { nline = _nline; } void set_image_fname(const std::string &fname) { image_fname = fname; } + protected: + class Compute *temperature, *pressure, *pe; + private: int nfield, nfield_initial; int *vtype; @@ -104,7 +107,6 @@ class Thermo : protected Pointers { // Compute * = ptrs to the Compute objects int index_temp, index_press_scalar, index_press_vector, index_pe; - class Compute *temperature, *pressure, *pe; double press_tensor[3][3]; int ncompute; // # of Compute objects called by thermo From fc78806bc7b3bdfee6dbf3f654e7a64f11f214ca Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Mar 2025 17:14:35 -0400 Subject: [PATCH 107/120] apply clang-format --- src/EXTRA-DUMP/dump_extxyz.cpp | 89 +++++++++++++++++----------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/src/EXTRA-DUMP/dump_extxyz.cpp b/src/EXTRA-DUMP/dump_extxyz.cpp index 0936d96abf..80a6ee2bdd 100644 --- a/src/EXTRA-DUMP/dump_extxyz.cpp +++ b/src/EXTRA-DUMP/dump_extxyz.cpp @@ -34,7 +34,7 @@ static constexpr int DELTA = 1048576; /* ---------------------------------------------------------------------- */ DumpExtXYZ::DumpExtXYZ(LAMMPS *lmp, int narg, char **arg) : - DumpXYZ(lmp, narg, arg), properties_string(nullptr) + DumpXYZ(lmp, narg, arg), properties_string(nullptr) { // style specific customizable settings with_vel = 1; @@ -70,17 +70,17 @@ void DumpExtXYZ::update_properties() // The properties string delete[] properties_string; - properties_string = utils::strdup(fmt::format("species:S:1:pos:R:3{}{}{}", - (with_vel ? ":vel:R:3" : ""), (with_forces ? ":forces:R:3" : ""), (with_mass ? ":mass:R:1" : ""))); - + properties_string = utils::strdup( + fmt::format("species:S:1:pos:R:3{}{}{}", (with_vel ? ":vel:R:3" : ""), + (with_forces ? ":forces:R:3" : ""), (with_mass ? ":mass:R:1" : ""))); // The output printf-style format - delete [] format; + delete[] format; if (format_line_user) format = utils::strdup(fmt::format("{}\n", format_line_user)); else { - format = utils::strdup(fmt::format("%s %g %g %g{}{}{}\n", - (with_vel ? " %g %g %g" : ""), (with_forces ? " %g %g %g" : ""), (with_mass ? " %g" : ""))); + format = utils::strdup(fmt::format("%s %g %g %g{}{}{}\n", (with_vel ? " %g %g %g" : ""), + (with_forces ? " %g %g %g" : ""), (with_mass ? " %g" : ""))); } } @@ -103,23 +103,23 @@ int DumpExtXYZ::modify_param(int narg, char **arg) int rv = DumpXYZ::modify_param(narg, arg); if (rv > 0) return rv; - if (strcmp(arg[0],"vel") == 0) { - if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); - with_vel = utils::logical(FLERR,arg[1],false,lmp); + if (strcmp(arg[0], "vel") == 0) { + if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); + with_vel = utils::logical(FLERR, arg[1], false, lmp); update_properties(); return 2; } - if (strcmp(arg[0],"forces") == 0) { - if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); - with_forces = utils::logical(FLERR,arg[1],false,lmp); + if (strcmp(arg[0], "forces") == 0) { + if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); + with_forces = utils::logical(FLERR, arg[1], false, lmp); update_properties(); return 2; } - if (strcmp(arg[0],"mass") == 0) { - if (narg < 2) error->all(FLERR,"Illegal dump_modify command"); - with_mass = utils::logical(FLERR,arg[1],false,lmp); + if (strcmp(arg[0], "mass") == 0) { + if (narg < 2) error->all(FLERR, "Illegal dump_modify command"); + with_mass = utils::logical(FLERR, arg[1], false, lmp); update_properties(); return 2; } @@ -143,7 +143,7 @@ void DumpExtXYZ::write_header(bigint n) fmt::format(" Lattice=\"{:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g}\"", domain->xprd, 0., 0., domain->xy, domain->yprd, 0., domain->xz, domain->yz, domain->zprd); - if (output && output->thermo) { + if (output && output->thermo) { auto *pe = output->thermo->pe; if (pe) header += fmt::format(" Potential_energy={}", pe->compute_scalar()); @@ -153,13 +153,13 @@ void DumpExtXYZ::write_header(bigint n) auto *press = output->thermo->pressure; if (press) { press->compute_vector(); - header += fmt::format(" Stress=\"{} {} {} {} {} {} {} {} {}\"", - press->vector[0], press->vector[3], press->vector[4], - press->vector[3], press->vector[1], press->vector[5], - press->vector[4], press->vector[5], press->vector[2]); + header += + fmt::format(" Stress=\"{} {} {} {} {} {} {} {} {}\"", press->vector[0], + press->vector[3], press->vector[4], press->vector[3], press->vector[1], + press->vector[5], press->vector[4], press->vector[5], press->vector[2]); } } - + header += fmt::format(" Properties={}", properties_string); utils::print(fp, header + "\n"); } @@ -228,34 +228,33 @@ int DumpExtXYZ::convert_string(int n, double *mybuf) } if (size_one == 5) { - offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4]); + offset += snprintf(&sbuf[offset], maxsbuf - offset, format, + typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4]); } else if (size_one == 6) { - offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5]); + offset += snprintf(&sbuf[offset], maxsbuf - offset, format, + typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4], mybuf[m + 5]); } else if (size_one == 8) { - offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7]); + offset += snprintf(&sbuf[offset], maxsbuf - offset, format, + typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7]); } else if (size_one == 9) { - offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], - mybuf[m + 8]); + offset += snprintf(&sbuf[offset], maxsbuf - offset, format, + typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8]); } else if (size_one == 11) { - offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], - mybuf[m + 8], mybuf[m + 9], mybuf[m + 10]); + offset += snprintf(&sbuf[offset], maxsbuf - offset, format, + typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], + mybuf[m + 9], mybuf[m + 10]); } else if (size_one == 12) { - offset += - snprintf(&sbuf[offset], maxsbuf - offset, format, typenames[static_cast(mybuf[m + 1])], - mybuf[m + 2], mybuf[m + 3], mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], - mybuf[m + 8], mybuf[m + 9], mybuf[m + 10], mybuf[m + 11]); + offset += snprintf(&sbuf[offset], maxsbuf - offset, format, + typenames[static_cast(mybuf[m + 1])], mybuf[m + 2], mybuf[m + 3], + mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], + mybuf[m + 9], mybuf[m + 10], mybuf[m + 11]); } else { - error->all(FLERR,"Invalid value of size_one for dump extxyz format."); + error->all(FLERR, "Invalid value of size_one for dump extxyz format."); } m += size_one; } @@ -290,7 +289,7 @@ void DumpExtXYZ::write_lines(int n, double *mybuf) mybuf[m + 4], mybuf[m + 5], mybuf[m + 6], mybuf[m + 7], mybuf[m + 8], mybuf[m + 9], mybuf[m + 10], mybuf[m + 11]); } else { - error->all(FLERR,"Invalid value of size_one for dump extxyz format."); + error->all(FLERR, "Invalid value of size_one for dump extxyz format."); } m += size_one; } From c9be07df9cfb04e33086acd30dc792c68b9966ce Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Mar 2025 18:28:06 -0400 Subject: [PATCH 108/120] fix bug with addstep_compute skipping on first step --- src/modify.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modify.cpp b/src/modify.cpp index e571440ddd..b42772f931 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -1431,7 +1431,7 @@ void Modify::addstep_compute(bigint newstep) } for (int icompute = 0; icompute < n_timeflag; icompute++) - if (compute[list_timeflag[icompute]]->invoked_flag) + if (compute[list_timeflag[icompute]]->invoked_flag >=0) compute[list_timeflag[icompute]]->addstep(newstep); } From 963083b2d5956bfaa063368279b93f85e6aab982 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Mar 2025 23:50:37 -0400 Subject: [PATCH 109/120] must use addstep_compute() on next variable dump output --- src/output.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/output.cpp b/src/output.cpp index 0602c4f52d..07d0ba26a5 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -402,6 +402,7 @@ void Output::write(bigint ntimestep) next_dump_any = MIN(next_dump_any,next_dump[idump]); } } + modify->addstep_compute(next_dump_any); // next_restart does not force output on last step of run // for toggle = 0, replace "*" with current timestep in restart filename From 9ac09e839f361a4eb049787736aee5d23ad8a3be Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 28 Mar 2025 00:05:14 -0400 Subject: [PATCH 110/120] trigger computes only if next variable step or time based dump present --- src/output.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index 07d0ba26a5..19082161e2 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -373,6 +373,7 @@ void Output::write(bigint ntimestep) // can't remove an uneeded addstep from a compute, b/c don't know // what other command may have added it + int mode_dump_any = 0; // any variable time or clearstep dump if (next_dump_any == ntimestep) { next_dump_any = next_time_dump_any = MAXBIGINT; @@ -397,12 +398,15 @@ void Output::write(bigint ntimestep) modify->addstep_compute(next_dump[idump]); } - if (mode_dump[idump] && (dump[idump]->clearstep || var_dump[idump])) + if (mode_dump[idump] && (dump[idump]->clearstep || var_dump[idump])) { + mode_dump_any = 1; next_time_dump_any = MIN(next_time_dump_any,next_dump[idump]); + } next_dump_any = MIN(next_dump_any,next_dump[idump]); } } - modify->addstep_compute(next_dump_any); + // trigger computes for any time based or variable step dumps + if (mode_dump_any) modify->addstep_compute(next_time_dump_any); // next_restart does not force output on last step of run // for toggle = 0, replace "*" with current timestep in restart filename From 09242c0b129f283c3289a50e5d7606d35a796c8e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 28 Mar 2025 00:31:01 -0400 Subject: [PATCH 111/120] forgot handling addstep_compute in setup() --- src/output.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/output.cpp b/src/output.cpp index 19082161e2..ab27e92759 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -222,7 +222,7 @@ void Output::setup(int memflag) if (ndump && update->restrict_output == 0) { next_dump_any = next_time_dump_any = MAXBIGINT; - + int mode_dump_any = 0; for (int idump = 0; idump < ndump; idump++) { // wrap step dumps that invoke computes or do variable eval with clear/add @@ -279,10 +279,13 @@ void Output::setup(int memflag) else modify->addstep_compute_all(next_dump[idump]); } - if (mode_dump[idump] && (dump[idump]->clearstep || var_dump[idump])) + if (mode_dump[idump] && (dump[idump]->clearstep || var_dump[idump])) { next_time_dump_any = MIN(next_time_dump_any,next_dump[idump]); + mode_dump_any = 1; + } next_dump_any = MIN(next_dump_any,next_dump[idump]); } + if (mode_dump_any) modify->addstep_compute(next_time_dump_any); // if no dumps, set next_dump_any to last+1 so will not influence next @@ -378,7 +381,6 @@ void Output::write(bigint ntimestep) next_dump_any = next_time_dump_any = MAXBIGINT; for (int idump = 0; idump < ndump; idump++) { - if (next_dump[idump] == ntimestep) { if (last_dump[idump] == ntimestep) continue; From c0321b5f0035af21ef195d7b952c79b1e038e2e0 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Fri, 28 Mar 2025 10:58:54 +0100 Subject: [PATCH 112/120] More doc --- doc/src/dump.rst | 6 ++++-- doc/src/dump_modify.rst | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/src/dump.rst b/doc/src/dump.rst index 47cd2905af..557d7b11bb 100644 --- a/doc/src/dump.rst +++ b/doc/src/dump.rst @@ -486,9 +486,11 @@ ExtXYZ) format as defined as defined in `the libAtoms specification information will be dumped: * timestep -* time, if enabled with :doc:`dump_modify time yes ` +* time, which can be disabled with :doc:`dump_modify time no ` * simulation box lattice and pbc conditions -* atomic velocities and forces +* atomic forces, which can be disabled with :doc:`dump_modify forces no ` +* atomic velocities, which can be disabled with :doc:`dump_modify vel no ` +* atomic masses, if enabled with :doc:`dump_modify mass yes ` Dump style *extxyz* requires either that a :doc:`type label map for atoms types ` is defined or :doc:`dump_modify element ` is used to diff --git a/doc/src/dump_modify.rst b/doc/src/dump_modify.rst index 1f2b1c8e0e..4786ea3c8f 100644 --- a/doc/src/dump_modify.rst +++ b/doc/src/dump_modify.rst @@ -92,6 +92,15 @@ Syntax see the :doc:`dump image ` doc page for details +* these keywords apply only to the extxyz dump style +* keyword = *forces* or *mass* or *vel* + + .. parsed-literal:: + + *forces* arg = *yes* or *no* + *mass* arg = *yes* or *no* + *vel* arg = *yes* or *no* + * these keywords apply only to the */gz* and */zstd* dump styles * keyword = *compression_level* @@ -972,9 +981,11 @@ The option defaults are * fileper = # of processors * first = no * flush = yes +* forces = yes * format = %d and %g for each integer or floating point value * image = no * label = ENTRIES +* mass = no * maxfiles = -1 * nfile = 1 * pad = 0 @@ -990,6 +1001,7 @@ The option defaults are * types = numeric * units = no * unwrap = no +* vel = yes * compression_level = 9 (gz variants) * compression_level = 0 (zstd variants) From b7b9a4a599dfa200e79b3f85c7da0b35e81c6330 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Fri, 28 Mar 2025 15:29:14 -0600 Subject: [PATCH 113/120] Update Kokkos library in LAMMPS to v4.6.0 --- lib/kokkos/CHANGELOG.md | 67 + lib/kokkos/CMakeLists.txt | 4 +- lib/kokkos/CTestConfig.cmake | 4 + lib/kokkos/Makefile.kokkos | 44 +- lib/kokkos/README.md | 12 +- lib/kokkos/algorithms/CMakeLists.txt | 4 + .../algorithms/perf_test/CMakeLists.txt | 63 + .../perf_test/test_inclusive_scan.cpp | 191 + lib/kokkos/algorithms/src/Kokkos_Random.hpp | 7 + .../src/sorting/Kokkos_BinOpsPublicAPI.hpp | 2 +- .../src/sorting/Kokkos_SortPublicAPI.hpp | 20 +- .../src/sorting/impl/Kokkos_SortByKeyImpl.hpp | 64 +- .../src/sorting/impl/Kokkos_SortImpl.hpp | 64 +- .../impl/Kokkos_Constraints.hpp | 13 +- .../src/std_algorithms/impl/Kokkos_CopyIf.hpp | 5 +- .../impl/Kokkos_ExclusiveScan.hpp | 4 +- .../Kokkos_IdentityReferenceUnaryFunctor.hpp | 7 +- .../impl/Kokkos_InclusiveScan.hpp | 160 +- .../impl/Kokkos_RandomAccessIterator.hpp | 137 +- .../src/std_algorithms/impl/Kokkos_Unique.hpp | 8 +- .../std_algorithms/impl/Kokkos_UniqueCopy.hpp | 5 +- lib/kokkos/algorithms/unit_tests/Makefile | 2 + .../algorithms/unit_tests/TestRandom.hpp | 10 +- .../unit_tests/TestRandomAccessIterator.cpp | 18 +- lib/kokkos/algorithms/unit_tests/TestSort.hpp | 1 + .../unit_tests/TestStdAlgorithmsCommon.hpp | 5 +- .../TestStdAlgorithmsCompileOnly.cpp | 14 + .../TestStdAlgorithmsConstraints.cpp | 1 + .../TestStdAlgorithmsExclusiveScan.cpp | 2 +- .../TestStdAlgorithmsInclusiveScan.cpp | 2 +- .../TestStdAlgorithmsIsSortedUntil.cpp | 11 +- .../unit_tests/TestStdAlgorithmsModOps.cpp | 6 +- .../unit_tests/TestStdAlgorithmsNumerics.cpp | 55 +- .../unit_tests/TestStdAlgorithmsRotate.cpp | 2 +- ...estStdAlgorithmsTeamAdjacentDifference.cpp | 1 + .../TestStdAlgorithmsTeamAdjacentFind.cpp | 1 + .../unit_tests/TestStdAlgorithmsTeamEqual.cpp | 1 + .../TestStdAlgorithmsTeamExclusiveScan.cpp | 1 + .../TestStdAlgorithmsTeamFindEnd.cpp | 1 + .../TestStdAlgorithmsTeamFindFirstOf.cpp | 1 + .../TestStdAlgorithmsTeamFindIf.cpp | 12 - .../TestStdAlgorithmsTeamFindIfNot.cpp | 12 - .../TestStdAlgorithmsTeamInclusiveScan.cpp | 1 + ...tdAlgorithmsTeamLexicographicalCompare.cpp | 1 + .../TestStdAlgorithmsTeamMismatch.cpp | 1 + .../TestStdAlgorithmsTeamReduce.cpp | 1 + .../TestStdAlgorithmsTeamSearch.cpp | 1 + .../TestStdAlgorithmsTeamSearchN.cpp | 1 + ...tdAlgorithmsTeamTransformExclusiveScan.cpp | 1 + ...tdAlgorithmsTeamTransformInclusiveScan.cpp | 1 + .../TestStdAlgorithmsTeamTransformReduce.cpp | 1 + ...estStdAlgorithmsTransformExclusiveScan.cpp | 3 +- ...estStdAlgorithmsTransformInclusiveScan.cpp | 3 +- lib/kokkos/benchmarks/atomic/Makefile | 1 + .../benchmarks/bytes_and_flops/Makefile | 1 + lib/kokkos/benchmarks/gather/Makefile | 1 + .../launch_latency/launch_latency.cpp | 7 +- .../benchmarks/policy_performance/Makefile | 1 + .../benchmarks/policy_performance/main.cpp | 7 +- .../policy_performance/policy_perf_test.hpp | 7 +- lib/kokkos/benchmarks/stream/Makefile | 1 + .../benchmarks/view_copy_constructor/Makefile | 1 + lib/kokkos/bin/nvcc_wrapper | 40 +- lib/kokkos/cmake/KokkosConfig.cmake.in | 90 +- lib/kokkos/cmake/KokkosConfigCommon.cmake.in | 384 +- lib/kokkos/cmake/KokkosCore_config.h.in | 5 +- lib/kokkos/cmake/Modules/FindTPLCUDA.cmake | 13 +- lib/kokkos/cmake/intel.cmake | 15 - lib/kokkos/cmake/kokkos_arch.cmake | 74 +- lib/kokkos/cmake/kokkos_compiler_id.cmake | 8 +- lib/kokkos/cmake/kokkos_enable_options.cmake | 2 +- lib/kokkos/cmake/kokkos_functions.cmake | 1 - lib/kokkos/cmake/kokkos_test_cxx_std.cmake | 3 - lib/kokkos/cmake/kokkos_tribits.cmake | 1 - .../containers/performance_tests/Makefile | 2 + lib/kokkos/containers/src/Kokkos_Bitset.hpp | 51 +- lib/kokkos/containers/src/Kokkos_DualView.hpp | 38 +- .../containers/src/Kokkos_DynRankView.hpp | 77 +- .../containers/src/Kokkos_DynamicView.hpp | 39 +- .../containers/src/Kokkos_ErrorReporter.hpp | 21 +- .../containers/src/Kokkos_OffsetView.hpp | 14 +- .../containers/src/Kokkos_ScatterView.hpp | 18 +- .../containers/src/Kokkos_StaticCrsGraph.hpp | 17 + .../containers/src/Kokkos_UnorderedMap.hpp | 44 +- lib/kokkos/containers/src/Kokkos_Vector.hpp | 55 +- .../src/impl/Kokkos_Functional_impl.hpp | 3 + .../containers/unit_tests/CMakeLists.txt | 4 +- lib/kokkos/containers/unit_tests/Makefile | 9 +- .../containers/unit_tests/TestDualView.hpp | 164 +- .../TestDynRankView_TeamScratch.hpp | 8 +- .../containers/unit_tests/TestDynViewAPI.hpp | 26 +- .../containers/unit_tests/TestOffsetView.hpp | 63 +- .../containers/unit_tests/TestScatterView.hpp | 6 +- .../unit_tests/TestStaticCrsGraph.hpp | 2 + lib/kokkos/core/perf_test/BenchmarkMain.cpp | 1 + lib/kokkos/core/perf_test/CMakeLists.txt | 1 + lib/kokkos/core/perf_test/Makefile | 2 + .../perf_test/PerfTest_CustomReduction.cpp | 4 +- .../core/perf_test/PerfTest_ViewCopy.hpp | 32 +- .../core/perf_test/PerfTest_ViewCopy_a123.cpp | 31 + .../core/perf_test/PerfTest_ViewFill.hpp | 20 + .../core/perf_test/PerfTest_ViewFill_123.cpp | 2 + lib/kokkos/core/perf_test/test_atomic.cpp | 3 + lib/kokkos/core/perf_test/test_reduction.cpp | 121 + lib/kokkos/core/src/CMakeLists.txt | 4 + lib/kokkos/core/src/Cuda/Kokkos_CudaSpace.hpp | 6 +- .../src/Cuda/Kokkos_Cuda_GraphNodeKernel.hpp | 10 +- .../core/src/Cuda/Kokkos_Cuda_Graph_Impl.hpp | 52 +- .../src/Cuda/Kokkos_Cuda_Half_Conversion.hpp | 144 +- .../core/src/Cuda/Kokkos_Cuda_Instance.cpp | 56 +- .../core/src/Cuda/Kokkos_Cuda_Instance.hpp | 24 +- .../src/Cuda/Kokkos_Cuda_KernelLaunch.hpp | 23 +- .../src/Cuda/Kokkos_Cuda_Parallel_MDRange.hpp | 15 +- .../src/Cuda/Kokkos_Cuda_Parallel_Range.hpp | 57 +- .../src/Cuda/Kokkos_Cuda_Parallel_Team.hpp | 52 +- .../core/src/Cuda/Kokkos_Cuda_ReduceScan.hpp | 8 +- lib/kokkos/core/src/Cuda/Kokkos_Cuda_Team.hpp | 28 +- lib/kokkos/core/src/Cuda/Kokkos_Cuda_View.hpp | 29 +- .../src/Cuda/Kokkos_Cuda_WorkGraphPolicy.hpp | 4 +- .../core/src/Cuda/Kokkos_Cuda_abort.hpp | 1 + lib/kokkos/core/src/HIP/Kokkos_HIP.cpp | 51 +- .../HIP/Kokkos_HIP_BlockSize_Deduction.hpp | 82 +- .../core/src/HIP/Kokkos_HIP_DeepCopy.cpp | 4 +- .../core/src/HIP/Kokkos_HIP_DeepCopy.hpp | 6 +- .../src/HIP/Kokkos_HIP_GraphNodeKernel.hpp | 10 +- .../core/src/HIP/Kokkos_HIP_Graph_Impl.hpp | 92 +- .../src/HIP/Kokkos_HIP_Half_Conversion.hpp | 28 +- .../core/src/HIP/Kokkos_HIP_Instance.cpp | 113 +- .../core/src/HIP/Kokkos_HIP_Instance.hpp | 153 +- .../core/src/HIP/Kokkos_HIP_IsXnack.cpp | 92 + .../core/src/HIP/Kokkos_HIP_IsXnack.hpp | 63 + .../core/src/HIP/Kokkos_HIP_KernelLaunch.hpp | 136 +- .../src/HIP/Kokkos_HIP_ParallelFor_Range.hpp | 30 +- .../src/HIP/Kokkos_HIP_ParallelFor_Team.hpp | 12 +- .../HIP/Kokkos_HIP_ParallelReduce_Range.hpp | 23 +- .../HIP/Kokkos_HIP_ParallelReduce_Team.hpp | 4 +- .../src/HIP/Kokkos_HIP_ParallelScan_Range.hpp | 4 +- .../core/src/HIP/Kokkos_HIP_ReduceScan.hpp | 6 +- lib/kokkos/core/src/HIP/Kokkos_HIP_Space.cpp | 71 +- lib/kokkos/core/src/HIP/Kokkos_HIP_Space.hpp | 44 +- lib/kokkos/core/src/HIP/Kokkos_HIP_Team.hpp | 2 +- .../src/HIP/Kokkos_HIP_TeamPolicyInternal.hpp | 41 +- .../src/HIP/Kokkos_HIP_WorkGraphPolicy.hpp | 4 +- .../core/src/HIP/Kokkos_HIP_ZeroMemset.cpp | 3 +- .../core/src/HIP/Kokkos_HIP_ZeroMemset.hpp | 12 +- lib/kokkos/core/src/HPX/Kokkos_HPX.hpp | 2 +- lib/kokkos/core/src/HPX/Kokkos_HPX_Task.hpp | 4 +- lib/kokkos/core/src/Kokkos_Array.hpp | 42 +- .../core/src/Kokkos_BitManipulation.hpp | 2 +- lib/kokkos/core/src/Kokkos_Complex.hpp | 20 +- lib/kokkos/core/src/Kokkos_CopyViews.hpp | 872 +--- lib/kokkos/core/src/Kokkos_Core_fwd.hpp | 8 - lib/kokkos/core/src/Kokkos_ExecPolicy.hpp | 26 +- lib/kokkos/core/src/Kokkos_Future.hpp | 89 +- lib/kokkos/core/src/Kokkos_Graph.hpp | 11 + lib/kokkos/core/src/Kokkos_GraphNode.hpp | 61 +- lib/kokkos/core/src/Kokkos_Macros.hpp | 27 +- lib/kokkos/core/src/Kokkos_MemoryPool.hpp | 19 +- .../core/src/Kokkos_Parallel_Reduce.hpp | 34 +- lib/kokkos/core/src/Kokkos_TaskScheduler.hpp | 5 +- lib/kokkos/core/src/Kokkos_Tuners.hpp | 4 + lib/kokkos/core/src/Kokkos_TypeInfo.hpp | 11 +- lib/kokkos/core/src/Kokkos_View.hpp | 2 +- .../src/OpenMP/Kokkos_OpenMP_Instance.cpp | 31 +- .../src/OpenMP/Kokkos_OpenMP_Instance.hpp | 6 +- .../src/OpenMP/Kokkos_OpenMP_Parallel_For.hpp | 42 +- .../OpenMP/Kokkos_OpenMP_Parallel_Reduce.hpp | 20 +- .../OpenMP/Kokkos_OpenMP_Parallel_Scan.hpp | 8 +- .../core/src/OpenMP/Kokkos_OpenMP_Task.hpp | 33 +- .../OpenMP/Kokkos_OpenMP_WorkGraphPolicy.hpp | 4 +- lib/kokkos/core/src/SYCL/Kokkos_SYCL.cpp | 16 +- lib/kokkos/core/src/SYCL/Kokkos_SYCL.hpp | 9 +- .../core/src/SYCL/Kokkos_SYCL_DeepCopy.hpp | 6 +- .../src/SYCL/Kokkos_SYCL_GraphNodeKernel.hpp | 10 +- .../core/src/SYCL/Kokkos_SYCL_Graph_Impl.hpp | 48 +- .../src/SYCL/Kokkos_SYCL_Half_Conversion.hpp | 108 +- .../core/src/SYCL/Kokkos_SYCL_Instance.cpp | 3 + .../core/src/SYCL/Kokkos_SYCL_Instance.hpp | 18 +- .../src/SYCL/Kokkos_SYCL_ParallelFor_Team.hpp | 5 +- .../Kokkos_SYCL_ParallelReduce_MDRange.hpp | 6 +- .../SYCL/Kokkos_SYCL_ParallelReduce_Range.hpp | 5 +- .../SYCL/Kokkos_SYCL_ParallelReduce_Team.hpp | 5 +- .../SYCL/Kokkos_SYCL_ParallelScan_Range.hpp | 7 +- .../core/src/SYCL/Kokkos_SYCL_Space.cpp | 26 +- lib/kokkos/core/src/SYCL/Kokkos_SYCL_Team.hpp | 2 +- .../core/src/SYCL/Kokkos_SYCL_TeamPolicy.hpp | 27 +- .../SYCL/Kokkos_SYCL_WorkgroupReduction.hpp | 6 +- .../core/src/SYCL/Kokkos_SYCL_ZeroMemset.hpp | 7 +- lib/kokkos/core/src/Serial/Kokkos_Serial.hpp | 58 +- .../core/src/Threads/Kokkos_Threads_Team.hpp | 9 +- lib/kokkos/core/src/View/Kokkos_BasicView.hpp | 197 +- .../Kokkos_ViewAccessPreconditionsCheck.hpp | 160 + .../core/src/View/Kokkos_ViewCommonType.hpp | 128 + lib/kokkos/core/src/View/Kokkos_ViewCtor.hpp | 21 +- .../core/src/View/Kokkos_ViewLegacy.hpp | 129 +- .../core/src/View/Kokkos_ViewMapping.hpp | 12 +- .../View/MDSpan/Kokkos_MDSpan_Accessor.hpp | 27 +- .../src/View/MDSpan/Kokkos_MDSpan_Layout.hpp | 134 +- .../src/impl/KokkosExp_Host_IterateTile.hpp | 6 +- .../src/impl/KokkosExp_IterateTileGPU.hpp | 215 +- lib/kokkos/core/src/impl/Kokkos_BitOps.hpp | 34 +- lib/kokkos/core/src/impl/Kokkos_Core.cpp | 32 +- .../impl/Kokkos_Default_GraphNodeKernel.hpp | 8 +- .../impl/Kokkos_Default_GraphNode_Impl.hpp | 6 +- .../src/impl/Kokkos_Default_Graph_Impl.hpp | 12 +- .../src/impl/Kokkos_Default_Graph_fwd.hpp | 2 +- lib/kokkos/core/src/impl/Kokkos_EBO.hpp | 2 + .../core/src/impl/Kokkos_FunctorAnalysis.hpp | 37 - lib/kokkos/core/src/impl/Kokkos_GraphImpl.hpp | 11 + .../core/src/impl/Kokkos_GraphImpl_fwd.hpp | 3 + .../src/impl/Kokkos_GraphNodeThenImpl.hpp | 58 + .../impl/Kokkos_Half_FloatingPointWrapper.hpp | 96 +- lib/kokkos/core/src/impl/Kokkos_HostSpace.cpp | 4 - .../impl/Kokkos_InitializationSettings.hpp | 32 +- lib/kokkos/core/src/impl/Kokkos_LIFO.hpp | 2 +- lib/kokkos/core/src/impl/Kokkos_Profiling.cpp | 61 +- .../core/src/impl/Kokkos_SharedAlloc.hpp | 77 +- .../src/impl/Kokkos_SharedAlloc_timpl.hpp | 44 +- .../src/impl/Kokkos_SimpleTaskScheduler.hpp | 22 +- .../core/src/impl/Kokkos_Stacktrace.cpp | 1 + .../src/impl/Kokkos_StringManipulation.hpp | 4 +- .../core/src/impl/Kokkos_TaskQueueCommon.hpp | 8 +- .../impl/Kokkos_TaskQueueMemoryManager.hpp | 4 +- .../core/src/impl/Kokkos_TeamMDPolicy.hpp | 3 + lib/kokkos/core/src/impl/Kokkos_Traits.hpp | 114 - lib/kokkos/core/src/impl/Kokkos_Utilities.hpp | 4 + .../core/src/impl/Kokkos_VLAEmulation.hpp | 7 +- .../core/src/setup/Kokkos_Setup_HIP.hpp | 6 + .../src/traits/Kokkos_PolicyTraitAdaptor.hpp | 4 + lib/kokkos/core/unit_test/CMakeLists.txt | 67 +- .../core/unit_test/IncrementalTest.cpp.in | 7 - ...ionEnvironmentNeverInitializedFixture.hpp} | 30 +- lib/kokkos/core/unit_test/Makefile | 11 +- lib/kokkos/core/unit_test/TestAbort.hpp | 2 +- lib/kokkos/core/unit_test/TestArray.cpp | 6 +- .../core/unit_test/TestAtomicOperations.hpp | 3 + .../unit_test/TestAtomicOperations_double.hpp | 2 +- .../unit_test/TestAtomicOperations_float.hpp | 2 +- lib/kokkos/core/unit_test/TestAtomics.hpp | 5 + lib/kokkos/core/unit_test/TestCXX11.hpp | 2 + .../core/unit_test/TestCompilerMacros.cpp | 3 +- lib/kokkos/core/unit_test/TestComplex.hpp | 41 +- .../core/unit_test/TestDetectionIdiom.cpp | 2 + .../unit_test/TestExecSpacePartitioning.hpp | 3 +- .../unit_test/TestExecSpaceThreadSafety.hpp | 6 - ...onEnvironmentNonInitializedOrFinalized.cpp | 143 + lib/kokkos/core/unit_test/TestGraph.hpp | 187 +- .../core/unit_test/TestGraphAtomicLocks.hpp | 79 + .../core/unit_test/TestHalfConversion.hpp | 18 +- .../core/unit_test/TestHalfOperators.hpp | 52 +- .../core/unit_test/TestHostSharedPtr.hpp | 6 +- .../TestHostSharedPtrAccessOnDevice.hpp | 6 +- .../core/unit_test/TestInitializeFinalize.cpp | 115 + .../core/unit_test/TestIrregularLayout.hpp | 1 + .../unit_test/TestLegionInitialization.cpp | 69 +- lib/kokkos/core/unit_test/TestMDRange.hpp | 313 +- lib/kokkos/core/unit_test/TestMDRange_a.hpp | 8 + lib/kokkos/core/unit_test/TestMDRange_b.hpp | 11 +- lib/kokkos/core/unit_test/TestMDRange_e.hpp | 7 + .../unit_test/TestMathematicalFunctions.hpp | 33 +- .../TestMathematicalSpecialFunctions.hpp | 25 +- lib/kokkos/core/unit_test/TestMultiGPU.hpp | 13 + .../unit_test/TestNonTrivialScalarTypes.hpp | 5 + .../core/unit_test/TestNumericTraits.hpp | 2 + .../core/unit_test/TestPushFinalizeHook.cpp | 114 + lib/kokkos/core/unit_test/TestRange.hpp | 71 +- ...Test_ScopeGuard.cpp => TestScopeGuard.cpp} | 41 +- lib/kokkos/core/unit_test/TestSharedSpace.cpp | 6 +- .../TestSpaceAwareAccessorAccessViolation.hpp | 2 +- .../core/unit_test/TestStringManipulation.cpp | 6 +- .../unit_test/TestTaskScheduler_single.hpp | 4 +- lib/kokkos/core/unit_test/TestTeam.hpp | 4 +- lib/kokkos/core/unit_test/TestTeamBasic.hpp | 8 +- lib/kokkos/core/unit_test/TestTeamScan.hpp | 6 +- lib/kokkos/core/unit_test/TestTeamVector.hpp | 11 +- lib/kokkos/core/unit_test/TestViewAPI.hpp | 24 +- lib/kokkos/core/unit_test/TestViewAPI_e.hpp | 18 +- .../core/unit_test/TestViewBadAlloc.hpp | 6 +- lib/kokkos/core/unit_test/TestViewCopy_a.hpp | 12 + lib/kokkos/core/unit_test/TestViewCopy_b.hpp | 12 + .../core/unit_test/TestViewCtorProp.hpp | 14 +- .../TestViewEmptyRuntimeUnmanaged.hpp | 6 - .../core/unit_test/TestViewMapping_a.hpp | 133 +- .../TestViewMemoryAccessViolation.hpp | 8 +- .../unit_test/TestViewOutOfBoundsAccess.hpp | 4 +- lib/kokkos/core/unit_test/TestViewSubview.hpp | 28 +- lib/kokkos/core/unit_test/TestView_64bit.hpp | 2 +- .../unit_test/TestWithoutInitializing.hpp | 6 +- lib/kokkos/core/unit_test/UnitTestMain.cpp | 1 - .../core/unit_test/UnitTestMainInit.cpp | 1 - .../unit_test/UnitTest_PushFinalizeHook.cpp | 102 - .../UnitTest_PushFinalizeHook_terminate.cpp | 57 - .../configuration/test-code/Makefile | 1 + .../unit_test/cuda/TestCuda_InterOp_Graph.cpp | 30 +- .../cuda/TestCuda_InterOp_StreamsMultiGPU.cpp | 69 +- .../core/unit_test/cuda/TestCuda_Spaces.cpp | 42 +- .../default/TestDefaultDeviceTypeViewAPI.cpp | 84 +- .../headers_self_contained/CMakeLists.txt | 5 +- .../hip/TestHIP_BlocksizeDeduction.cpp | 8 +- .../unit_test/hip/TestHIP_InterOp_Graph.cpp | 35 + .../hip/TestHIP_InterOp_StreamsMultiGPU.cpp | 153 + .../core/unit_test/hip/TestHIP_ScanUnit.cpp | 4 +- .../core/unit_test/hip/TestHIP_Spaces.cpp | 24 +- .../hip/TestHIP_UnifiedMemory_ZeroMemset.cpp | 27 +- .../core/unit_test/hpx/TestHPX_InParallel.cpp | 8 + .../incremental/Test01_execspace.hpp | 12 +- lib/kokkos/core/unit_test/standalone/Makefile | 2 + .../unit_test/sycl/TestSYCL_InterOp_Graph.cpp | 40 +- .../core/unit_test/sycl/TestSYCL_Spaces.cpp | 26 +- .../tools/TestWithoutInitializing.cpp | 4 +- .../tools/include/ToolTestingUtilities.hpp | 30 +- .../core/unit_test/view/TestBasicView.hpp | 16 +- .../view/TestBasicViewMDSpanConversion.cpp | 36 +- .../build_cmake_installed/CMakeLists.txt | 4 +- .../CMakeLists.txt | 15 +- lib/kokkos/example/make_buildlink/Makefile | 1 + lib/kokkos/example/query_device/Makefile | 3 + .../example/relocatable_function/Makefile | 2 + .../example/tutorial/01_hello_world/Makefile | 2 + .../tutorial/01_hello_world_lambda/Makefile | 2 + .../tutorial/02_simple_reduce/Makefile | 2 + .../tutorial/02_simple_reduce_lambda/Makefile | 1 + .../example/tutorial/03_simple_view/Makefile | 1 + .../tutorial/03_simple_view_lambda/Makefile | 1 + .../tutorial/04_simple_memoryspaces/Makefile | 1 + .../tutorial/05_simple_atomics/Makefile | 1 + .../tutorial/06_simple_mdrangepolicy/Makefile | 1 + .../Advanced_Views/01_data_layouts/Makefile | 1 + .../Advanced_Views/02_memory_traits/Makefile | 1 + .../Advanced_Views/03_subviews/Makefile | 1 + .../Advanced_Views/04_dualviews/Makefile | 1 + .../Advanced_Views/04_dualviews/dual_view.cpp | 4 +- .../Advanced_Views/05_NVIDIA_UVM/Makefile | 2 + .../Advanced_Views/06_AtomicViews/Makefile | 1 + .../07_Overlapping_DeepCopy/Makefile | 2 + .../Algorithms/01_random_numbers/Makefile | 1 + .../01_random_numbers/random_numbers.cpp | 10 +- .../01_thread_teams/Makefile | 1 + .../01_thread_teams_lambda/Makefile | 1 + .../02_nested_parallel_for/Makefile | 1 + .../03_vectorization/Makefile | 1 + .../04_team_scan/Makefile | 1 + .../example/tutorial/launch_bounds/Makefile | 1 + lib/kokkos/example/virtual_functions/Makefile | 2 + lib/kokkos/generate_makefile.bash | 1 + lib/kokkos/gnu_generate_makefile.bash | 1 + lib/kokkos/master_history.txt | 1 + lib/kokkos/simd/src/Kokkos_SIMD.hpp | 87 +- lib/kokkos/simd/src/Kokkos_SIMD_AVX2.hpp | 2708 ++++++------ lib/kokkos/simd/src/Kokkos_SIMD_AVX512.hpp | 3614 ++++++++++------- lib/kokkos/simd/src/Kokkos_SIMD_Common.hpp | 234 +- .../simd/src/Kokkos_SIMD_Common_Math.hpp | 222 +- lib/kokkos/simd/src/Kokkos_SIMD_NEON.hpp | 2788 +++++++------ lib/kokkos/simd/src/Kokkos_SIMD_Scalar.hpp | 581 ++- .../unit_tests/include/SIMDTesting_Ops.hpp | 385 +- .../include/SIMDTesting_Utilities.hpp | 84 +- .../unit_tests/include/TestSIMD_Condition.hpp | 8 +- .../include/TestSIMD_Construction.hpp | 51 +- .../include/TestSIMD_Conversions.hpp | 78 +- .../include/TestSIMD_GeneratorCtors.hpp | 36 +- .../unit_tests/include/TestSIMD_MaskOps.hpp | 8 +- .../unit_tests/include/TestSIMD_MathOps.hpp | 106 +- .../include/TestSIMD_Reductions.hpp | 93 +- .../unit_tests/include/TestSIMD_ShiftOps.hpp | 90 +- .../include/TestSIMD_WhereExpressions.hpp | 146 +- .../include/desul/atomics/Fetch_Op_HIP.hpp | 6 + .../__p0009_bits/compressed_pair.hpp | 50 +- .../experimental/__p0009_bits/config.hpp | 189 +- .../__p0009_bits/default_accessor.hpp | 2 +- .../__p0009_bits/dynamic_extent.hpp | 2 +- .../experimental/__p0009_bits/extents.hpp | 41 +- .../__p0009_bits/full_extent_t.hpp | 2 +- .../experimental/__p0009_bits/layout_left.hpp | 30 +- .../__p0009_bits/layout_right.hpp | 32 +- .../__p0009_bits/layout_stride.hpp | 82 +- .../experimental/__p0009_bits/macros.hpp | 344 +- .../experimental/__p0009_bits/mdspan.hpp | 92 +- .../__p0009_bits/no_unique_address.hpp | 14 +- .../__p0009_bits/trait_backports.hpp | 14 +- .../experimental/__p0009_bits/type_list.hpp | 3 +- .../experimental/__p0009_bits/utility.hpp | 2 +- .../experimental/__p1684_bits/mdarray.hpp | 64 +- .../__p2630_bits/strided_slice.hpp | 6 +- .../__p2630_bits/submdspan_mapping.hpp | 16 +- 384 files changed, 13243 insertions(+), 9477 deletions(-) create mode 100644 lib/kokkos/CTestConfig.cmake create mode 100644 lib/kokkos/algorithms/perf_test/CMakeLists.txt create mode 100644 lib/kokkos/algorithms/perf_test/test_inclusive_scan.cpp delete mode 100644 lib/kokkos/cmake/intel.cmake create mode 100644 lib/kokkos/core/perf_test/test_reduction.cpp create mode 100644 lib/kokkos/core/src/HIP/Kokkos_HIP_IsXnack.cpp create mode 100644 lib/kokkos/core/src/HIP/Kokkos_HIP_IsXnack.hpp create mode 100644 lib/kokkos/core/src/View/Kokkos_ViewAccessPreconditionsCheck.hpp create mode 100644 lib/kokkos/core/src/View/Kokkos_ViewCommonType.hpp create mode 100644 lib/kokkos/core/src/impl/Kokkos_GraphNodeThenImpl.hpp rename lib/kokkos/core/unit_test/{TestInit.hpp => KokkosExecutionEnvironmentNeverInitializedFixture.hpp} (55%) create mode 100644 lib/kokkos/core/unit_test/TestExecutionEnvironmentNonInitializedOrFinalized.cpp create mode 100644 lib/kokkos/core/unit_test/TestGraphAtomicLocks.hpp create mode 100644 lib/kokkos/core/unit_test/TestInitializeFinalize.cpp create mode 100644 lib/kokkos/core/unit_test/TestPushFinalizeHook.cpp rename lib/kokkos/core/unit_test/{UnitTest_ScopeGuard.cpp => TestScopeGuard.cpp} (76%) delete mode 100644 lib/kokkos/core/unit_test/UnitTest_PushFinalizeHook.cpp delete mode 100644 lib/kokkos/core/unit_test/UnitTest_PushFinalizeHook_terminate.cpp create mode 100644 lib/kokkos/core/unit_test/hip/TestHIP_InterOp_StreamsMultiGPU.cpp diff --git a/lib/kokkos/CHANGELOG.md b/lib/kokkos/CHANGELOG.md index 84bbd03585..7d39bd36ae 100644 --- a/lib/kokkos/CHANGELOG.md +++ b/lib/kokkos/CHANGELOG.md @@ -1,5 +1,72 @@ # CHANGELOG +## 4.6.00 + +[Full Changelog](https://github.com/kokkos/kokkos/compare/4.5.01...4.6.00) + +### Features: + +* Kokkos::Graph: Allow adding tasks to the graph via a `then`-node [\#7629](https://github.com/kokkos/kokkos/pull/7629) +* Kokkos::Graph: Allow construction from CUDA/HIP graph [\#7664](https://github.com/kokkos/kokkos/pull/7664) +* HIP: Add experimental support for using multiple GPUs from one process [\#7130](https://github.com/kokkos/kokkos/pull/7130) + +### Backend and Architecture Enhancements: + +#### CUDA: +* Improved reduction performance, in particular on H100 and newer [\#7823](https://github.com/kokkos/kokkos/pull/7823) + +#### HIP: +* Change block size deduction to prefer smaller blocks/teams [\#7509](https://github.com/kokkos/kokkos/pull/7509) +* Allocate memory with stream ordered semantics (i.e. use `hipMallocAsync`) [\#7659](https://github.com/kokkos/kokkos/pull/7659) +* Fix a segfault when a virtual function called inside a kernel requires too many registers[\#7660](https://github.com/kokkos/kokkos/pull/7660) + +#### SYCL: +* Improve sorting performance for non-contiguous views [\#7502](https://github.com/kokkos/kokkos/pull/7502) + +#### Serial: +* Reduce fences overhead when using `Kokkos_ENABLE_ATOMICS_BYPASS` [\#7821](https://github.com/kokkos/kokkos/pull/7821) + +### General Enhancements +* Allow use of `kokkos_check` in `Config.cmake` without warnings [\#7669](https://github.com/kokkos/kokkos/pull/7669) +* Add simd compound assignments and update simd reductions [\#7486](https://github.com/kokkos/kokkos/pull/7486) +* Improve performance of the `inclusive_scan` algorithm with Cuda and HIP [\#7542](https://github.com/kokkos/kokkos/pull/7542) +* Reduce tooling interface overhead (don't pay for what you don't use) [\#7817](https://github.com/kokkos/kokkos/pull/7817) +* Avoid storing the view in `RandomAccessIterator` to increase performance [\#7304](https://github.com/kokkos/kokkos/pull/7304) +* Make `RandomAccessIterator` fulfill `std::random_access_iterator concept` [\#7451](https://github.com/kokkos/kokkos/pull/7451) +* Include information about support for system allocated memory in `print_configuration` (Cuda and HIP) [\#7673](https://github.com/kokkos/kokkos/pull/7673) + +### Build System Changes +* Add support for Zen 4 AMD microarchitecture [\#7550](https://github.com/kokkos/kokkos/pull/7550) +* Enable NVIDIA Grace architecture with NVHPC [\#7858](https://github.com/kokkos/kokkos/pull/7858) +* Support static library builds when using CUDA as CMake language [\#7830](https://github.com/kokkos/kokkos/pull/7830) + +### Incompatibilities (i.e. breaking changes) +* Change SIMD comparison operator to return `simd_mask` instead of `bool` [\#7781](https://github.com/kokkos/kokkos/pull/7781) +* Remove classic Intel compiler (icpc) support [\#7737](https://github.com/kokkos/kokkos/pull/7737) +* Remove `operator[]` overloads of Kokkos `basic_simd` and `basic_simd_mask` that return a reference [\#7630](https://github.com/kokkos/kokkos/pull/7630) + +### Deprecations +* Deprecate `StaticCrsGraph` and move it to Kokkos Kernels into `KokkosSparse::` [\#7516](https://github.com/kokkos/kokkos/pull/7516) +* Deprecate `native_simd` and hide `simd_abi` [\#7472](https://github.com/kokkos/kokkos/pull/7472) +* Deprecate Makefile support [\#7613](https://github.com/kokkos/kokkos/pull/7613) +* DualView: Deprecate direct access to d_view and h_view [\#7716](https://github.com/kokkos/kokkos/pull/7716) + +### Bug Fixes +* Fix performance bug affecting `atomic_fetch_{add,sub,min,max,and,or,xor}` on integral types `long` and `unsigned long` with HIP [\#7816](https://github.com/kokkos/kokkos/pull/7816) +* Fix execution of ranges with more than 2B elements [\#7797](https://github.com/kokkos/kokkos/pull/7797) +* Fix clean target when embedding Kokkos in another project [\#7557](https://github.com/kokkos/kokkos/pull/7557) +* Fix Zen3 flag for NVHPC [\#7558](https://github.com/kokkos/kokkos/pull/7558) +* graph: nodes must be stored by the graph [\#7619](https://github.com/kokkos/kokkos/pull/7619) +* Make sure lock arrays are on device before launching a graph [\#7685](https://github.com/kokkos/kokkos/pull/7685) +* Performance bug in `RangePolicy`: construct error message if and only if the precondition is violated [\#7809](https://github.com/kokkos/kokkos/pull/7809) +* simd: fix a bug in scalar min/max [\#7813](https://github.com/kokkos/kokkos/pull/7813) +* simd: fix a bug in non-masked reductions [\#7845](https://github.com/kokkos/kokkos/pull/7845) +* Cuda: fix incorrect iteration in `MDRangePolicy` of rank > 4 for high iteration counts [\#7724](https://github.com/kokkos/kokkos/pull/7724) +* Cuda: ignore gcc assembler options in `nvcc-wrapper` [\#7492](https://github.com/kokkos/kokkos/pull/7492) +* Build system: hint to `ARCH_NATIVE` if ARMv9 Grace arch is not explicitly supported by the compiler [\#7862](https://github.com/kokkos/kokkos/pull/7862) +* Use right arch for MI300A in makefiles [\#7786](https://github.com/kokkos/kokkos/pull/7786) +* Fix compiling BasicView on MSVC [\#7751](https://github.com/kokkos/kokkos/pull/7751) + ## 4.5.01 [Full Changelog](https://github.com/kokkos/kokkos/compare/4.5.00...4.5.01) diff --git a/lib/kokkos/CMakeLists.txt b/lib/kokkos/CMakeLists.txt index 6a70bea149..7a4dc73444 100644 --- a/lib/kokkos/CMakeLists.txt +++ b/lib/kokkos/CMakeLists.txt @@ -148,8 +148,8 @@ elseif(NOT CMAKE_SIZEOF_VOID_P EQUAL 8) endif() set(Kokkos_VERSION_MAJOR 4) -set(Kokkos_VERSION_MINOR 5) -set(Kokkos_VERSION_PATCH 1) +set(Kokkos_VERSION_MINOR 6) +set(Kokkos_VERSION_PATCH 0) set(Kokkos_VERSION "${Kokkos_VERSION_MAJOR}.${Kokkos_VERSION_MINOR}.${Kokkos_VERSION_PATCH}") message(STATUS "Kokkos version: ${Kokkos_VERSION}") math(EXPR KOKKOS_VERSION "${Kokkos_VERSION_MAJOR} * 10000 + ${Kokkos_VERSION_MINOR} * 100 + ${Kokkos_VERSION_PATCH}") diff --git a/lib/kokkos/CTestConfig.cmake b/lib/kokkos/CTestConfig.cmake new file mode 100644 index 0000000000..deb80ab76a --- /dev/null +++ b/lib/kokkos/CTestConfig.cmake @@ -0,0 +1,4 @@ +set(CTEST_PROJECT_NAME Kokkos) +set(CTEST_NIGHTLY_START_TIME 01:00:00 UTC) +set(CTEST_SUBMIT_URL https://my.cdash.org/submit.php?project=Kokkos) +set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/lib/kokkos/Makefile.kokkos b/lib/kokkos/Makefile.kokkos index abdfb7a316..65c576bb8d 100644 --- a/lib/kokkos/Makefile.kokkos +++ b/lib/kokkos/Makefile.kokkos @@ -1,18 +1,26 @@ # Default settings common options. -#SPARTA specific settings: +#LAMMPS specific settings: + +KOKKOS_USE_DEPRECATED_MAKEFILES=1 + ifndef KOKKOS_PATH KOKKOS_PATH=../../lib/kokkos endif CXXFLAGS=$(CCFLAGS) ifeq ($(mode),shared) -CXXFLAGS += $(SHFLAGS) + CXXFLAGS += $(SHFLAGS) +endif + + +ifneq ($(KOKKOS_USE_DEPRECATED_MAKEFILES), 1) + $(error Makefile support is deprecated. Only CMake builds will be supported from Kokkos 5 on. Set KOKKOS_USE_DEPRECATED_MAKEFILES=1 to silence this error.) endif KOKKOS_VERSION_MAJOR = 4 -KOKKOS_VERSION_MINOR = 5 -KOKKOS_VERSION_PATCH = 1 +KOKKOS_VERSION_MINOR = 6 +KOKKOS_VERSION_PATCH = 0 KOKKOS_VERSION = $(shell echo $(KOKKOS_VERSION_MAJOR)*10000+$(KOKKOS_VERSION_MINOR)*100+$(KOKKOS_VERSION_PATCH) | bc) # Options: Cuda,HIP,SYCL,OpenMPTarget,OpenMP,Threads,Serial @@ -24,7 +32,7 @@ KOKKOS_DEVICES ?= "OpenMP" # ARM: ARMv80,ARMv81,ARMv8-ThunderX,ARMv8-TX2,A64FX,ARMv9-Grace # IBM: Power8,Power9 # AMD-GPUS: AMD_GFX906,AMD_GFX908,AMD_GFX90A,AMD_GFX940,AMD_GFX942,AMD_GFX942_APU,AMD_GFX1030,AMD_GFX1100,AMD_GFX1103 -# AMD-CPUS: AMDAVX,Zen,Zen2,Zen3 +# AMD-CPUS: AMDAVX,Zen,Zen2,Zen3,Zen4 # Intel-GPUs: Intel_Gen,Intel_Gen9,Intel_Gen11,Intel_Gen12LP,Intel_DG1,Intel_XeHP,Intel_PVC KOKKOS_ARCH ?= "" # Options: yes,no @@ -442,11 +450,14 @@ KOKKOS_INTERNAL_USE_ARCH_IBM := $(strip $(shell echo $(KOKKOS_INTERNAL_USE_ARCH_ # AMD based. KOKKOS_INTERNAL_USE_ARCH_AMDAVX := $(call kokkos_has_string,$(KOKKOS_ARCH),AMDAVX) +KOKKOS_INTERNAL_USE_ARCH_ZEN4 := $(call kokkos_has_string,$(KOKKOS_ARCH),Zen4) KOKKOS_INTERNAL_USE_ARCH_ZEN3 := $(call kokkos_has_string,$(KOKKOS_ARCH),Zen3) KOKKOS_INTERNAL_USE_ARCH_ZEN2 := $(call kokkos_has_string,$(KOKKOS_ARCH),Zen2) -ifeq ($(KOKKOS_INTERNAL_USE_ARCH_ZEN3), 0) - ifeq ($(KOKKOS_INTERNAL_USE_ARCH_ZEN2), 0) - KOKKOS_INTERNAL_USE_ARCH_ZEN := $(call kokkos_has_string,$(KOKKOS_ARCH),Zen) +ifeq ($(KOKKOS_INTERNAL_USE_ARCH_ZEN4), 0) + ifeq ($(KOKKOS_INTERNAL_USE_ARCH_ZEN3), 0) + ifeq ($(KOKKOS_INTERNAL_USE_ARCH_ZEN2), 0) + KOKKOS_INTERNAL_USE_ARCH_ZEN := $(call kokkos_has_string,$(KOKKOS_ARCH),Zen) + endif endif endif @@ -463,8 +474,10 @@ ifeq ($(KOKKOS_INTERNAL_USE_ARCH_AMD_GFX90A), 0) KOKKOS_INTERNAL_USE_ARCH_AMD_GFX90A := $(call kokkos_has_string,$(KOKKOS_ARCH),VEGA90A) endif KOKKOS_INTERNAL_USE_ARCH_AMD_GFX940 := $(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX940) -KOKKOS_INTERNAL_USE_ARCH_AMD_GFX942 := $(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX942) KOKKOS_INTERNAL_USE_ARCH_AMD_GFX942_APU := $(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX942_APU) +ifeq ($(KOKKOS_INTERNAL_USE_ARCH_AMD_GFX942_APU), 0) + KOKKOS_INTERNAL_USE_ARCH_AMD_GFX942 := $(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX942) +endif KOKKOS_INTERNAL_USE_ARCH_AMD_GFX1030 := $(call kokkos_has_string,$(KOKKOS_ARCH),AMD_GFX1030) ifeq ($(KOKKOS_INTERNAL_USE_ARCH_AMD_GFX1030), 0) KOKKOS_INTERNAL_USE_ARCH_AMD_GFX1030 := $(call kokkos_has_string,$(KOKKOS_ARCH),NAVI1030) @@ -857,6 +870,19 @@ ifeq ($(KOKKOS_INTERNAL_USE_ARCH_ZEN3), 1) endif endif +ifeq ($(KOKKOS_INTERNAL_USE_ARCH_ZEN4), 1) + tmp := $(call kokkos_append_header,"$H""define KOKKOS_ARCH_AMD_ZEN4") + tmp := $(call kokkos_append_header,"$H""define KOKKOS_ARCH_AVX512XEON") + + ifeq ($(KOKKOS_INTERNAL_COMPILER_INTEL), 1) + KOKKOS_CXXFLAGS += -xCORE-AVX512 + KOKKOS_LDFLAGS += -xCORE-AVX512 + else + KOKKOS_CXXFLAGS += -march=znver4 -mtune=znver4 + KOKKOS_LDFLAGS += -march=znver4 -mtune=znver4 + endif +endif + ifeq ($(KOKKOS_INTERNAL_USE_ARCH_ARMV8_THUNDERX), 1) tmp := $(call kokkos_append_header,"$H""define KOKKOS_ARCH_ARMV80") tmp := $(call kokkos_append_header,"$H""define KOKKOS_ARCH_ARMV8_THUNDERX") diff --git a/lib/kokkos/README.md b/lib/kokkos/README.md index 56159b35c2..13d99c0bad 100644 --- a/lib/kokkos/README.md +++ b/lib/kokkos/README.md @@ -18,24 +18,24 @@ Kokkos is a [Linux Foundation](https://linuxfoundation.org) project. To start learning about Kokkos: -- [Kokkos Lectures](https://kokkos.org/kokkos-core-wiki/videolectures.html): they contain a mix of lecture videos and hands-on exercises covering all the important capabilities. +- [Kokkos Lectures](https://kokkos.org/kokkos-core-wiki/tutorials-and-examples/video-lectures.html): they contain a mix of lecture videos and hands-on exercises covering all the important capabilities. - [Programming guide](https://kokkos.org/kokkos-core-wiki/programmingguide.html): contains in "narrative" form a technical description of the programming model, machine model, and the main building blocks like the Views and parallel dispatch. - [API reference](https://kokkos.org/kokkos-core-wiki/): organized by category, i.e., [core](https://kokkos.org/kokkos-core-wiki/API/core-index.html), [algorithms](https://kokkos.org/kokkos-core-wiki/API/algorithms-index.html) and [containers](https://kokkos.org/kokkos-core-wiki/API/containers-index.html) or, if you prefer, in [alphabetical order](https://kokkos.org/kokkos-core-wiki/API/alphabetical.html). -- [Use cases and Examples](https://kokkos.org/kokkos-core-wiki/usecases.html): a serie of examples ranging from how to use Kokkos with MPI to Fortran interoperability. +- [Use cases and Examples](https://kokkos.org/kokkos-core-wiki/tutorials-and-examples/use-cases-and-examples.html): a serie of examples ranging from how to use Kokkos with MPI to Fortran interoperability. ## Obtaining Kokkos The latest release of Kokkos can be obtained from the [GitHub releases page](https://github.com/kokkos/kokkos/releases/latest). -The current release is [4.5.01](https://github.com/kokkos/kokkos/releases/tag/4.5.01). +The current release is [4.6.00](https://github.com/kokkos/kokkos/releases/tag/4.6.00). ```bash -curl -OJ -L https://github.com/kokkos/kokkos/releases/download/4.5.01/kokkos-4.5.01.tar.gz +curl -OJ -L https://github.com/kokkos/kokkos/releases/download/4.6.00/kokkos-4.6.00.tar.gz # Or with wget -wget https://github.com/kokkos/kokkos/releases/download/4.5.01/kokkos-4.5.01.tar.gz +wget https://github.com/kokkos/kokkos/releases/download/4.6.00/kokkos-4.6.00.tar.gz ``` To clone the latest development version of Kokkos from GitHub: @@ -47,7 +47,7 @@ git clone -b develop https://github.com/kokkos/kokkos.git ### Building Kokkos To build Kokkos, you will need to have a C++ compiler that supports C++17 or later. -All requirements including minimum and primary tested compiler versions can be found [here](https://kokkos.org/kokkos-core-wiki/requirements.html). +All requirements including minimum and primary tested compiler versions can be found [here](https://kokkos.org/kokkos-core-wiki/get-started/requirements.html). Building and installation instructions are described [here](https://kokkos.org/kokkos-core-wiki/building.html). diff --git a/lib/kokkos/algorithms/CMakeLists.txt b/lib/kokkos/algorithms/CMakeLists.txt index 73ce9f7ec5..e257e4ccce 100644 --- a/lib/kokkos/algorithms/CMakeLists.txt +++ b/lib/kokkos/algorithms/CMakeLists.txt @@ -5,3 +5,7 @@ endif() if(NOT ((KOKKOS_ENABLE_OPENMPTARGET AND KOKKOS_CXX_COMPILER_ID STREQUAL NVHPC) OR KOKKOS_ENABLE_OPENACC)) kokkos_add_test_directories(unit_tests) endif() + +if(Kokkos_ENABLE_BENCHMARKS) + add_subdirectory(perf_test) +endif() diff --git a/lib/kokkos/algorithms/perf_test/CMakeLists.txt b/lib/kokkos/algorithms/perf_test/CMakeLists.txt new file mode 100644 index 0000000000..a41d3f891b --- /dev/null +++ b/lib/kokkos/algorithms/perf_test/CMakeLists.txt @@ -0,0 +1,63 @@ +# FIXME: The following logic should be moved from here and also from `core/perf_test/CMakeLists.txt` to +# the root `CMakeLists.txt` in the form of a macro +# Find or download google/benchmark library +find_package(benchmark QUIET 1.5.6) +if(benchmark_FOUND) + message(STATUS "Using google benchmark found in ${benchmark_DIR}") +else() + message(STATUS "No installed google benchmark found, fetching from GitHub") + include(FetchContent) + set(BENCHMARK_ENABLE_TESTING OFF) + + list(APPEND CMAKE_MESSAGE_INDENT "[benchmark] ") + FetchContent_Declare( + googlebenchmark + DOWNLOAD_EXTRACT_TIMESTAMP FALSE + URL https://github.com/google/benchmark/archive/refs/tags/v1.7.1.tar.gz + URL_HASH MD5=0459a6c530df9851bee6504c3e37c2e7 + ) + FetchContent_MakeAvailable(googlebenchmark) + list(POP_BACK CMAKE_MESSAGE_INDENT) + + # Suppress clang-tidy diagnostics on code that we do not have control over + if(CMAKE_CXX_CLANG_TIDY) + set_target_properties(benchmark PROPERTIES CXX_CLANG_TIDY "") + endif() + + # FIXME: Check whether the following target_compile_options are needed. + # If so, clarify why. + target_compile_options(benchmark PRIVATE -w) + target_compile_options(benchmark_main PRIVATE -w) +endif() + +# FIXME: This function should be moved from here and also from `core/perf_test/CMakeLists.txt` to +# the root `CMakeLists.txt` +# FIXME: Could NAME be a one_value_keyword specified in cmake_parse_arguments? +function(KOKKOS_ADD_BENCHMARK NAME) + cmake_parse_arguments(BENCHMARK "" "" "SOURCES" ${ARGN}) + if(DEFINED BENCHMARK_UNPARSED_ARGUMENTS) + message(WARNING "Unexpected arguments when adding a benchmark: " ${BENCHMARK_UNPARSED_ARGUMENTS}) + endif() + + set(BENCHMARK_NAME Kokkos_${NAME}) + # FIXME: BenchmarkMain.cpp and Benchmark_Context.cpp should be moved to a common location from which + # they can be used by all performance tests. + list(APPEND BENCHMARK_SOURCES ../../core/perf_test/BenchmarkMain.cpp ../../core/perf_test/Benchmark_Context.cpp) + + add_executable(${BENCHMARK_NAME} ${BENCHMARK_SOURCES}) + target_link_libraries(${BENCHMARK_NAME} PRIVATE benchmark::benchmark Kokkos::kokkos impl_git_version) + target_include_directories(${BENCHMARK_NAME} SYSTEM PRIVATE ${benchmark_SOURCE_DIR}/include) + + # FIXME: This alone will not work. It might need an architecture and standard which need to be defined on target level. + # It will potentially go away with #7582. + foreach(SOURCE_FILE ${BENCHMARK_SOURCES}) + set_source_files_properties(${SOURCE_FILE} PROPERTIES LANGUAGE ${KOKKOS_COMPILE_LANGUAGE}) + endforeach() + + string(TIMESTAMP BENCHMARK_TIME "%Y-%m-%d_T%H-%M-%S" UTC) + set(BENCHMARK_ARGS --benchmark_counters_tabular=true --benchmark_out=${BENCHMARK_NAME}_${BENCHMARK_TIME}.json) + + add_test(NAME ${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} ${BENCHMARK_ARGS}) +endfunction() + +kokkos_add_benchmark(PerformanceTest_InclusiveScan SOURCES test_inclusive_scan.cpp) diff --git a/lib/kokkos/algorithms/perf_test/test_inclusive_scan.cpp b/lib/kokkos/algorithms/perf_test/test_inclusive_scan.cpp new file mode 100644 index 0000000000..a0a5de6b07 --- /dev/null +++ b/lib/kokkos/algorithms/perf_test/test_inclusive_scan.cpp @@ -0,0 +1,191 @@ +//@HEADER +// ************************************************************************ +// +// Kokkos v. 4.0 +// Copyright (2022) National Technology & Engineering +// Solutions of Sandia, LLC (NTESS). +// +// Under the terms of Contract DE-NA0003525 with NTESS, +// the U.S. Government retains certain rights in this software. +// +// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. +// See https://kokkos.org/LICENSE for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//@HEADER + +#include +#include +#include +#include + +#include + +#include +#include +#include +// FIXME: Benchmark_Context.hpp should be moved to a common location +#include "../../core/perf_test/Benchmark_Context.hpp" + +namespace { + +namespace KE = Kokkos::Experimental; + +using ExecSpace = Kokkos::DefaultExecutionSpace; +using HostExecSpace = Kokkos::DefaultHostExecutionSpace; + +// A tag struct to identify when inclusive scan with the implicit sum +// based binary operation needs to be called. +template +struct ImpSumBinOp; + +template +struct SumFunctor { + KOKKOS_FUNCTION + ValueType operator()(const ValueType& a, const ValueType& b) const { + return (a + b); + } +}; + +template +struct MaxFunctor { + KOKKOS_FUNCTION + ValueType operator()(const ValueType& a, const ValueType& b) const { + if (a > b) + return a; + else + return b; + } +}; + +// Helper to obtain last element of a view +template +T obtain_last_elem(const Kokkos::View& v) { + T last_element; + Kokkos::deep_copy(last_element, Kokkos::subview(v, v.extent(0) - 1)); + return last_element; +} + +// Helper to allocate input and output views +template +auto prepare_views(const std::size_t kProbSize) { + Kokkos::View in{"input", kProbSize}; + Kokkos::View out{"output", kProbSize}; + + auto h_in = Kokkos::create_mirror_view(in); + + for (std::size_t i = 0; i < kProbSize; ++i) { + h_in(i) = i; + } + + Kokkos::deep_copy(in, h_in); + + return std::make_tuple(in, out, h_in); +} + +// Perform scan with a reference implementation +template > +T ref_scan(const ViewType& h_in, ScanFunctor scan_functor = ScanFunctor()) { + std::size_t view_size = h_in.extent(0); + + Kokkos::View h_out("output", view_size); + + // FIXME: We have GCC 8.4.0 based check in our ORNL Jenkins CI. + // std::inclusive_scan is available only from GCC 9.3. Since, GCC 9.1 + // std::inclusive_scan that takes execution policy is available. However, + // there is error with header before GCC 10.1. + h_out(0) = h_in(0); + + for (std::size_t i = 1; i < view_size; ++i) { + h_out(i) = scan_functor(h_in(i), h_out(i - 1)); + } + + return h_out(view_size - 1); +} + +// Inclusive Scan with default binary operation (sum) or user provided functor +// Note: The nature of the functor must be compatible with the +// elements in the input and output views +template class ScanFunctor = ImpSumBinOp> +auto inclusive_scan(const Kokkos::View& in, + const Kokkos::View& out, T res_check) { + ExecSpace().fence(); + Kokkos::Timer timer; + + if constexpr (std::is_same_v, ImpSumBinOp>) { + KE::inclusive_scan("Default scan", ExecSpace(), KE::cbegin(in), + KE::cend(in), KE::begin(out)); + } else { + KE::inclusive_scan("Scan using a functor", ExecSpace(), KE::cbegin(in), + KE::cend(in), KE::begin(out), ScanFunctor()); + } + + ExecSpace().fence(); + double time_scan = timer.seconds(); + + T res_scan = obtain_last_elem(out); + bool passed = (res_check == res_scan); + + return std::make_tuple(time_scan, passed); +} + +// Benchmark: Inclusive Scan with default binary operation (sum) +// or user provided functor +template class ScanFunctor = ImpSumBinOp> +void BM_inclusive_scan(benchmark::State& state) { + const std::size_t kProbSize = state.range(0); + + auto [in, out, h_in] = prepare_views(kProbSize); + + T res_check; + + if constexpr (std::is_same_v, ImpSumBinOp>) { + res_check = ref_scan(h_in); + } else { + res_check = ref_scan(h_in, ScanFunctor()); + } + + double time_scan = 0.; + bool passed = false; + + for (auto _ : state) { + if constexpr (std::is_same_v, ImpSumBinOp>) { + std::tie(time_scan, passed) = inclusive_scan(in, out, res_check); + } else { + std::tie(time_scan, passed) = + inclusive_scan(in, out, res_check); + } + + KokkosBenchmark::report_results(state, in, 2, time_scan); + state.counters["Passed"] = passed; + } +} + +constexpr std::size_t PROB_SIZE = 100'000'000; + +} // anonymous namespace + +// FIXME: Add logic to pass min. warm-up time. Also, the value should be set +// by the user. Say, via the environment variable BENCHMARK_MIN_WARMUP_TIME. + +BENCHMARK(BM_inclusive_scan)->Arg(PROB_SIZE)->UseManualTime(); +BENCHMARK(BM_inclusive_scan)->Arg(PROB_SIZE)->UseManualTime(); +BENCHMARK(BM_inclusive_scan)->Arg(PROB_SIZE)->UseManualTime(); +BENCHMARK(BM_inclusive_scan) + ->Arg(PROB_SIZE) + ->UseManualTime(); +BENCHMARK(BM_inclusive_scan) + ->Arg(PROB_SIZE) + ->UseManualTime(); +BENCHMARK(BM_inclusive_scan) + ->Arg(PROB_SIZE) + ->UseManualTime(); +BENCHMARK(BM_inclusive_scan) + ->Arg(PROB_SIZE) + ->UseManualTime(); +BENCHMARK(BM_inclusive_scan) + ->Arg(PROB_SIZE) + ->UseManualTime(); +BENCHMARK(BM_inclusive_scan) + ->Arg(PROB_SIZE) + ->UseManualTime(); diff --git a/lib/kokkos/algorithms/src/Kokkos_Random.hpp b/lib/kokkos/algorithms/src/Kokkos_Random.hpp index b28ea4c2ca..54a853fa55 100644 --- a/lib/kokkos/algorithms/src/Kokkos_Random.hpp +++ b/lib/kokkos/algorithms/src/Kokkos_Random.hpp @@ -587,11 +587,13 @@ struct Random_XorShift1024_State { int state_idx) : state_(&v(state_idx, 0)), stride_(v.stride_1()) {} + // NOLINTBEGIN(bugprone-implicit-widening-of-multiplication-result) KOKKOS_FUNCTION uint64_t operator[](const int i) const { return state_[i * stride_]; } KOKKOS_FUNCTION uint64_t& operator[](const int i) { return state_[i * stride_]; } + // NOLINTEND(bugprone-implicit-widening-of-multiplication-result) }; template @@ -670,7 +672,12 @@ struct Random_UniqueIndex> { View>; KOKKOS_FUNCTION static int get_state_idx(const locks_view_type& locks_) { +#if defined(KOKKOS_COMPILER_INTEL_LLVM) && \ + KOKKOS_COMPILER_INTEL_LLVM >= 20250000 + auto item = sycl::ext::oneapi::this_work_item::get_nd_item<3>(); +#else auto item = sycl::ext::oneapi::experimental::this_nd_item<3>(); +#endif std::size_t threadIdx[3] = {item.get_local_id(2), item.get_local_id(1), item.get_local_id(0)}; std::size_t blockIdx[3] = {item.get_group(2), item.get_group(1), diff --git a/lib/kokkos/algorithms/src/sorting/Kokkos_BinOpsPublicAPI.hpp b/lib/kokkos/algorithms/src/sorting/Kokkos_BinOpsPublicAPI.hpp index 8e7de32a07..b093b72ad6 100644 --- a/lib/kokkos/algorithms/src/sorting/Kokkos_BinOpsPublicAPI.hpp +++ b/lib/kokkos/algorithms/src/sorting/Kokkos_BinOpsPublicAPI.hpp @@ -45,7 +45,7 @@ struct BinOp1D { // For integral types the number of bins may be larger than the range // in which case we can exactly have one unique value per bin // and then don't need to sort bins. - if (std::is_integral::value && + if (std::is_integral_v && (static_cast(max) - static_cast(min)) <= static_cast(max_bins)) { mul_ = 1.; diff --git a/lib/kokkos/algorithms/src/sorting/Kokkos_SortPublicAPI.hpp b/lib/kokkos/algorithms/src/sorting/Kokkos_SortPublicAPI.hpp index 20026c77e4..308e9e3a00 100644 --- a/lib/kokkos/algorithms/src/sorting/Kokkos_SortPublicAPI.hpp +++ b/lib/kokkos/algorithms/src/sorting/Kokkos_SortPublicAPI.hpp @@ -53,13 +53,9 @@ void sort(const ExecutionSpace& exec, if constexpr (Impl::better_off_calling_std_sort_v) { exec.fence("Kokkos::sort without comparator use std::sort"); - if (view.span_is_contiguous()) { - std::sort(view.data(), view.data() + view.size()); - } else { - auto first = ::Kokkos::Experimental::begin(view); - auto last = ::Kokkos::Experimental::end(view); - std::sort(first, last); - } + auto first = ::Kokkos::Experimental::begin(view); + auto last = ::Kokkos::Experimental::end(view); + std::sort(first, last); } else { Impl::sort_device_view_without_comparator(exec, view); } @@ -111,13 +107,9 @@ void sort(const ExecutionSpace& exec, if constexpr (Impl::better_off_calling_std_sort_v) { exec.fence("Kokkos::sort with comparator use std::sort"); - if (view.span_is_contiguous()) { - std::sort(view.data(), view.data() + view.size(), comparator); - } else { - auto first = ::Kokkos::Experimental::begin(view); - auto last = ::Kokkos::Experimental::end(view); - std::sort(first, last, comparator); - } + auto first = ::Kokkos::Experimental::begin(view); + auto last = ::Kokkos::Experimental::end(view); + std::sort(first, last, comparator); } else { Impl::sort_device_view_with_comparator(exec, view, comparator); } diff --git a/lib/kokkos/algorithms/src/sorting/impl/Kokkos_SortByKeyImpl.hpp b/lib/kokkos/algorithms/src/sorting/impl/Kokkos_SortByKeyImpl.hpp index 2a8f761d9b..f17d254b0b 100644 --- a/lib/kokkos/algorithms/src/sorting/impl/Kokkos_SortByKeyImpl.hpp +++ b/lib/kokkos/algorithms/src/sorting/impl/Kokkos_SortByKeyImpl.hpp @@ -47,6 +47,7 @@ #ifdef _CubLog #undef _CubLog #endif +// NOLINTNEXTLINE(bugprone-reserved-identifier) #define _CubLog #include #include @@ -65,12 +66,24 @@ #include #endif -#if defined(KOKKOS_ENABLE_ONEDPL) && \ - (ONEDPL_VERSION_MAJOR > 2022 || \ - (ONEDPL_VERSION_MAJOR == 2022 && ONEDPL_VERSION_MINOR >= 2)) -#define KOKKOS_ONEDPL_HAS_SORT_BY_KEY +#ifdef KOKKOS_ENABLE_ONEDPL +#define KOKKOS_IMPL_ONEDPL_VERSION \ + ONEDPL_VERSION_MAJOR * 10000 + ONEDPL_VERSION_MINOR * 100 + \ + ONEDPL_VERSION_PATCH +#define KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL(MAJOR, MINOR, PATCH) \ + (KOKKOS_IMPL_ONEDPL_VERSION >= ((MAJOR)*10000 + (MINOR)*100 + (PATCH))) + +#if KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL(2022, 2, 0) +#define KOKKOS_IMPL_ONEDPL_HAS_SORT_BY_KEY +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#pragma GCC diagnostic ignored "-Wunused-local-typedef" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wunused-variable" #include #include +#pragma GCC diagnostic pop +#endif #endif namespace Kokkos::Impl { @@ -141,12 +154,18 @@ void sort_by_key_rocthrust( #endif #if defined(KOKKOS_ENABLE_ONEDPL) + +#if KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL(2022, 7, 1) +template +inline constexpr bool sort_on_device_v = true; +#else template inline constexpr bool sort_on_device_v = std::is_same_v || std::is_same_v; +#endif -#ifdef KOKKOS_ONEDPL_HAS_SORT_BY_KEY +#ifdef KOKKOS_IMPL_ONEDPL_HAS_SORT_BY_KEY template void sort_by_key_onedpl( @@ -154,6 +173,14 @@ void sort_by_key_onedpl( const Kokkos::View& keys, const Kokkos::View& values, MaybeComparator&&... maybeComparator) { + auto queue = exec.sycl_queue(); + auto policy = oneapi::dpl::execution::make_device_policy(queue); +#if KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL(2022, 7, 1) + oneapi::dpl::sort_by_key(policy, ::Kokkos::Experimental::begin(keys), + ::Kokkos::Experimental::end(keys), + ::Kokkos::Experimental::begin(values), + std::forward(maybeComparator)...); +#else if (keys.stride(0) != 1 && values.stride(0) != 1) { Kokkos::abort( "SYCL sort_by_key only supports rank-1 Views with stride(0) = 1."); @@ -161,11 +188,10 @@ void sort_by_key_onedpl( // Can't use Experimental::begin/end here since the oneDPL then assumes that // the data is on the host. - auto queue = exec.sycl_queue(); - auto policy = oneapi::dpl::execution::make_device_policy(queue); const int n = keys.extent(0); oneapi::dpl::sort_by_key(policy, keys.data(), keys.data() + n, values.data(), std::forward(maybeComparator)...); +#endif } #endif #endif @@ -336,12 +362,18 @@ void sort_by_key_device_view_without_comparator( const Kokkos::SYCL& exec, const Kokkos::View& keys, const Kokkos::View& values) { -#ifdef KOKKOS_ONEDPL_HAS_SORT_BY_KEY +#ifdef KOKKOS_IMPL_ONEDPL_HAS_SORT_BY_KEY +#if KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL(2022, 7, 1) + sort_by_key_onedpl(exec, keys, values); +#else if (keys.stride(0) == 1 && values.stride(0) == 1) sort_by_key_onedpl(exec, keys, values); else -#endif sort_by_key_via_sort(exec, keys, values); +#endif +#else + sort_by_key_via_sort(exec, keys, values); +#endif } #endif @@ -394,12 +426,18 @@ void sort_by_key_device_view_with_comparator( const Kokkos::View& keys, const Kokkos::View& values, const ComparatorType& comparator) { -#ifdef KOKKOS_ONEDPL_HAS_SORT_BY_KEY +#ifdef KOKKOS_IMPL_ONEDPL_HAS_SORT_BY_KEY +#if KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL(2022, 7, 1) + sort_by_key_onedpl(exec, keys, values, comparator); +#else if (keys.stride(0) == 1 && values.stride(0) == 1) sort_by_key_onedpl(exec, keys, values, comparator); else -#endif sort_by_key_via_sort(exec, keys, values, comparator); +#endif +#else + sort_by_key_via_sort(exec, keys, values, comparator); +#endif } #endif @@ -416,7 +454,9 @@ sort_by_key_device_view_with_comparator( sort_by_key_via_sort(exec, keys, values, comparator); } -#undef KOKKOS_ONEDPL_HAS_SORT_BY_KEY +#undef KOKKOS_IMPL_ONEDPL_HAS_SORT_BY_KEY } // namespace Kokkos::Impl +#undef KOKKOS_IMPL_ONEDPL_VERSION +#undef KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL #endif diff --git a/lib/kokkos/algorithms/src/sorting/impl/Kokkos_SortImpl.hpp b/lib/kokkos/algorithms/src/sorting/impl/Kokkos_SortImpl.hpp index 734ce450f6..fa7c28b4d0 100644 --- a/lib/kokkos/algorithms/src/sorting/impl/Kokkos_SortImpl.hpp +++ b/lib/kokkos/algorithms/src/sorting/impl/Kokkos_SortImpl.hpp @@ -51,6 +51,7 @@ #ifdef _CubLog #undef _CubLog #endif +// NOLINTNEXTLINE(bugprone-reserved-identifier) #define _CubLog #include #include @@ -70,8 +71,20 @@ #endif #if defined(KOKKOS_ENABLE_ONEDPL) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#pragma GCC diagnostic ignored "-Wunused-local-typedef" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wunused-variable" #include #include +#pragma GCC diagnostic pop + +#define KOKKOS_IMPL_ONEDPL_VERSION \ + ONEDPL_VERSION_MAJOR * 10000 + ONEDPL_VERSION_MINOR * 100 + \ + ONEDPL_VERSION_PATCH +#define KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL(MAJOR, MINOR, PATCH) \ + (KOKKOS_IMPL_ONEDPL_VERSION >= ((MAJOR)*10000 + (MINOR)*100 + (PATCH))) #endif namespace Kokkos { @@ -221,6 +234,10 @@ void sort_onedpl(const Kokkos::SYCL& space, "SYCL execution space is not able to access the memory space " "of the View argument!"); +#if KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL(2022, 7, 1) + static_assert(ViewType::rank == 1, + "Kokkos::sort currently only supports rank-1 Views."); +#else static_assert( (ViewType::rank == 1) && (std::is_same_v || @@ -234,18 +251,26 @@ void sort_onedpl(const Kokkos::SYCL& space, if (view.stride(0) != 1) { Kokkos::abort("SYCL sort only supports rank-1 Views with stride(0) = 1."); } +#endif if (view.extent(0) <= 1) { return; } - // Can't use Experimental::begin/end here since the oneDPL then assumes that - // the data is on the host. auto queue = space.sycl_queue(); auto policy = oneapi::dpl::execution::make_device_policy(queue); + +#if KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL(2022, 7, 1) + oneapi::dpl::sort(policy, ::Kokkos::Experimental::begin(view), + ::Kokkos::Experimental::end(view), + std::forward(maybeComparator)...); +#else + // Can't use Experimental::begin/end here since the oneDPL then assumes that + // the data is on the host. const int n = view.extent(0); oneapi::dpl::sort(policy, view.data(), view.data() + n, std::forward(maybeComparator)...); +#endif } #endif @@ -269,29 +294,19 @@ void copy_to_host_run_stdsort_copy_back( KE::copy(exec, view, view_dc); // run sort on the mirror of view_dc - auto mv_h = create_mirror_view_and_copy(Kokkos::HostSpace(), view_dc); - if (view.span_is_contiguous()) { - std::sort(mv_h.data(), mv_h.data() + mv_h.size(), - std::forward(maybeComparator)...); - } else { - auto first = KE::begin(mv_h); - auto last = KE::end(mv_h); - std::sort(first, last, std::forward(maybeComparator)...); - } + auto mv_h = create_mirror_view_and_copy(Kokkos::HostSpace(), view_dc); + auto first = KE::begin(mv_h); + auto last = KE::end(mv_h); + std::sort(first, last, std::forward(maybeComparator)...); Kokkos::deep_copy(exec, view_dc, mv_h); // copy back to argument view KE::copy(exec, KE::cbegin(view_dc), KE::cend(view_dc), KE::begin(view)); } else { auto view_h = create_mirror_view_and_copy(Kokkos::HostSpace(), view); - if (view.span_is_contiguous()) { - std::sort(view_h.data(), view_h.data() + view_h.size(), - std::forward(maybeComparator)...); - } else { - auto first = KE::begin(view_h); - auto last = KE::end(view_h); - std::sort(first, last, std::forward(maybeComparator)...); - } + auto first = KE::begin(view_h); + auto last = KE::end(view_h); + std::sort(first, last, std::forward(maybeComparator)...); Kokkos::deep_copy(exec, view, view_h); } } @@ -332,11 +347,15 @@ void sort_device_view_without_comparator( "sort_device_view_without_comparator: supports rank-1 Views " "with LayoutLeft, LayoutRight or LayoutStride"); +#if KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL(2022, 7, 1) + sort_onedpl(exec, view); +#else if (view.stride(0) == 1) { sort_onedpl(exec, view); } else { copy_to_host_run_stdsort_copy_back(exec, view); } +#endif } #endif @@ -387,11 +406,15 @@ void sort_device_view_with_comparator( "sort_device_view_with_comparator: supports rank-1 Views " "with LayoutLeft, LayoutRight or LayoutStride"); +#if KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL(2022, 7, 1) + sort_onedpl(exec, view, comparator); +#else if (view.stride(0) == 1) { sort_onedpl(exec, view, comparator); } else { copy_to_host_run_stdsort_copy_back(exec, view, comparator); } +#endif } #endif @@ -423,4 +446,7 @@ sort_device_view_with_comparator( } // namespace Impl } // namespace Kokkos + +#undef KOKKOS_IMPL_ONEDPL_VERSION +#undef KOKKOS_IMPL_ONEDPL_VERSION_GREATER_EQUAL #endif diff --git a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Constraints.hpp b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Constraints.hpp index da16141f5a..2e73ace8d5 100644 --- a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Constraints.hpp +++ b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Constraints.hpp @@ -238,12 +238,9 @@ KOKKOS_INLINE_FUNCTION void expect_no_overlap( [[maybe_unused]] IteratorType2 s_first) { if constexpr (is_kokkos_iterator_v && is_kokkos_iterator_v) { - auto const view1 = first.view(); - auto const view2 = s_first.view(); - - std::size_t stride1 = view1.stride(0); - std::size_t stride2 = view2.stride(0); - ptrdiff_t first_diff = view1.data() - view2.data(); + std::size_t stride1 = first.stride(); + std::size_t stride2 = s_first.stride(); + ptrdiff_t first_diff = first.data() - s_first.data(); // FIXME If strides are not identical, checks may not be made // with the cost of O(1) @@ -251,8 +248,8 @@ KOKKOS_INLINE_FUNCTION void expect_no_overlap( // If first_diff == 0, there is already an overlap if (stride1 == stride2 || first_diff == 0) { [[maybe_unused]] bool is_no_overlap = (first_diff % stride1); - auto* first_pointer1 = view1.data(); - auto* first_pointer2 = view2.data(); + auto* first_pointer1 = first.data(); + auto* first_pointer2 = s_first.data(); [[maybe_unused]] auto* last_pointer1 = first_pointer1 + (last - first); [[maybe_unused]] auto* last_pointer2 = first_pointer2 + (last - first); KOKKOS_EXPECTS(first_pointer1 >= last_pointer2 || diff --git a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_CopyIf.hpp b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_CopyIf.hpp index ad7b8bb8ca..ef39be6366 100644 --- a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_CopyIf.hpp +++ b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_CopyIf.hpp @@ -150,9 +150,8 @@ KOKKOS_FUNCTION OutputIterator copy_if_team_impl( return d_first + count; } -#if defined KOKKOS_COMPILER_INTEL || \ - (defined(KOKKOS_COMPILER_NVCC) && KOKKOS_COMPILER_NVCC >= 1130 && \ - !defined(KOKKOS_COMPILER_MSVC)) +#if defined(KOKKOS_COMPILER_NVCC) && KOKKOS_COMPILER_NVCC >= 1130 && \ + !defined(KOKKOS_COMPILER_MSVC) __builtin_unreachable(); #endif } diff --git a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_ExclusiveScan.hpp b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_ExclusiveScan.hpp index 6da992b4bb..08e04810f6 100644 --- a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_ExclusiveScan.hpp +++ b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_ExclusiveScan.hpp @@ -103,7 +103,7 @@ OutputIteratorType exclusive_scan_custom_op_exespace_impl( // aliases using index_type = typename InputIteratorType::difference_type; - using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; + using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; using func_type = TransformExclusiveScanFunctorWithValueWrapper< ExecutionSpace, index_type, ValueType, InputIteratorType, OutputIteratorType, BinaryOpType, unary_op_type>; @@ -177,7 +177,7 @@ KOKKOS_FUNCTION OutputIteratorType exclusive_scan_custom_op_team_impl( // aliases using exe_space = typename TeamHandleType::execution_space; - using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; + using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; using index_type = typename InputIteratorType::difference_type; using func_type = TransformExclusiveScanFunctorWithoutValueWrapper< exe_space, index_type, ValueType, InputIteratorType, OutputIteratorType, diff --git a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_IdentityReferenceUnaryFunctor.hpp b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_IdentityReferenceUnaryFunctor.hpp index 252511c5d0..928508fdfb 100644 --- a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_IdentityReferenceUnaryFunctor.hpp +++ b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_IdentityReferenceUnaryFunctor.hpp @@ -23,10 +23,11 @@ namespace Kokkos { namespace Experimental { namespace Impl { -template struct StdNumericScanIdentityReferenceUnaryFunctor { - KOKKOS_FUNCTION - constexpr const ValueType& operator()(const ValueType& a) const { return a; } + template + KOKKOS_FUNCTION constexpr T&& operator()(T&& t) const { + return static_cast(t); + } }; } // namespace Impl diff --git a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_InclusiveScan.hpp b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_InclusiveScan.hpp index 0b4acec0fe..867d0b0266 100644 --- a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_InclusiveScan.hpp +++ b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_InclusiveScan.hpp @@ -18,12 +18,60 @@ #define KOKKOS_STD_ALGORITHMS_INCLUSIVE_SCAN_IMPL_HPP #include +#include #include "Kokkos_Constraints.hpp" #include "Kokkos_HelperPredicates.hpp" #include #include #include +#if defined(KOKKOS_ENABLE_CUDA) + +// Workaround for `Instruction 'shfl' without '.sync' is not supported on +// .target sm_70 and higher from PTX ISA version 6.4`. +// Also see https://github.com/NVIDIA/cub/pull/170. +#if !defined(CUB_USE_COOPERATIVE_GROUPS) +#define CUB_USE_COOPERATIVE_GROUPS +#endif + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#pragma GCC diagnostic ignored "-Wsuggest-override" + +#if defined(KOKKOS_COMPILER_CLANG) +// Some versions of Clang fail to compile Thrust, failing with errors like +// this: +// /thrust/system/cuda/detail/core/agent_launcher.h:557:11: +// error: use of undeclared identifier 'va_printf' +// The exact combination of versions for Clang and Thrust (or CUDA) for this +// failure was not investigated, however even very recent version combination +// (Clang 10.0.0 and Cuda 10.0) demonstrated failure. +// +// Defining _CubLog here locally allows us to avoid that code path, however +// disabling some debugging diagnostics +#pragma push_macro("_CubLog") +#ifdef _CubLog +#undef _CubLog +#endif +// NOLINTNEXTLINE(bugprone-reserved-identifier) +#define _CubLog +#include +#include +#pragma pop_macro("_CubLog") +#else +#include +#include +#endif + +#pragma GCC diagnostic pop + +#endif + +#if defined(KOKKOS_ENABLE_ROCTHRUST) +#include +#include +#endif + namespace Kokkos { namespace Experimental { namespace Impl { @@ -101,9 +149,48 @@ struct InclusiveScanDefaultFunctor { } }; -// -// exespace impl -// +// ------------------------------------------------------------- +// inclusive_scan_default_op_exespace_impl +// ------------------------------------------------------------- + +#if defined(KOKKOS_ENABLE_CUDA) +template +OutputIteratorType inclusive_scan_default_op_exespace_impl( + const std::string& label, const Cuda& ex, InputIteratorType first_from, + InputIteratorType last_from, OutputIteratorType first_dest) { + const auto thrust_ex = thrust::cuda::par.on(ex.cuda_stream()); + + Kokkos::Profiling::pushRegion(label + " via thrust::inclusive_scan"); + + thrust::inclusive_scan(thrust_ex, first_from, last_from, first_dest); + + Kokkos::Profiling::popRegion(); + + const auto num_elements = thrust::distance(first_from, last_from); + + return first_dest + num_elements; +} +#endif + +#if defined(KOKKOS_ENABLE_ROCTHRUST) +template +OutputIteratorType inclusive_scan_default_op_exespace_impl( + const std::string& label, const HIP& ex, InputIteratorType first_from, + InputIteratorType last_from, OutputIteratorType first_dest) { + const auto thrust_ex = thrust::hip::par.on(ex.hip_stream()); + + Kokkos::Profiling::pushRegion(label + " via thrust::inclusive_scan"); + + thrust::inclusive_scan(thrust_ex, first_from, last_from, first_dest); + + Kokkos::Profiling::popRegion(); + + const auto num_elements = thrust::distance(first_from, last_from); + + return first_dest + num_elements; +} +#endif + template OutputIteratorType inclusive_scan_default_op_exespace_impl( @@ -132,11 +219,16 @@ OutputIteratorType inclusive_scan_default_op_exespace_impl( // run const auto num_elements = Kokkos::Experimental::distance(first_from, last_from); + + Kokkos::Profiling::pushRegion(label + " via Kokkos::parallel_scan"); + ::Kokkos::parallel_scan(label, RangePolicy(ex, 0, num_elements), func_type(first_from, first_dest)); ex.fence("Kokkos::inclusive_scan_default_op: fence after operation"); + Kokkos::Profiling::popRegion(); + // return return first_dest + num_elements; } @@ -144,6 +236,49 @@ OutputIteratorType inclusive_scan_default_op_exespace_impl( // ------------------------------------------------------------- // inclusive_scan_custom_binary_op_impl // ------------------------------------------------------------- + +#if defined(KOKKOS_ENABLE_CUDA) +template +OutputIteratorType inclusive_scan_custom_binary_op_exespace_impl( + const std::string& label, const Cuda& ex, InputIteratorType first_from, + InputIteratorType last_from, OutputIteratorType first_dest, + BinaryOpType binary_op) { + const auto thrust_ex = thrust::cuda::par.on(ex.cuda_stream()); + + Kokkos::Profiling::pushRegion(label + " via thrust::inclusive_scan"); + + thrust::inclusive_scan(thrust_ex, first_from, last_from, first_dest, + binary_op); + + Kokkos::Profiling::popRegion(); + + const auto num_elements = thrust::distance(first_from, last_from); + + return first_dest + num_elements; +} +#endif + +#if defined(KOKKOS_ENABLE_ROCTHRUST) +template +OutputIteratorType inclusive_scan_custom_binary_op_exespace_impl( + const std::string& label, const HIP& ex, InputIteratorType first_from, + InputIteratorType last_from, OutputIteratorType first_dest, + BinaryOpType binary_op) { + const auto thrust_ex = thrust::hip::par.on(ex.hip_stream()); + + Kokkos::Profiling::pushRegion(label + " via thrust::inclusive_scan"); + + thrust::inclusive_scan(thrust_ex, first_from, last_from, first_dest, + binary_op); + + Kokkos::Profiling::popRegion(); + + const auto num_elements = thrust::distance(first_from, last_from); + + return first_dest + num_elements; +} +#endif + template OutputIteratorType inclusive_scan_custom_binary_op_exespace_impl( @@ -160,7 +295,7 @@ OutputIteratorType inclusive_scan_custom_binary_op_exespace_impl( using index_type = typename InputIteratorType::difference_type; using value_type = std::remove_const_t; - using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; + using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; using func_type = ExeSpaceTransformInclusiveScanNoInitValueFunctor< ExecutionSpace, index_type, value_type, InputIteratorType, OutputIteratorType, BinaryOpType, unary_op_type>; @@ -168,11 +303,16 @@ OutputIteratorType inclusive_scan_custom_binary_op_exespace_impl( // run const auto num_elements = Kokkos::Experimental::distance(first_from, last_from); + + Kokkos::Profiling::pushRegion(label + " via Kokkos::parallel_scan"); + ::Kokkos::parallel_scan( label, RangePolicy(ex, 0, num_elements), func_type(first_from, first_dest, binary_op, unary_op_type())); ex.fence("Kokkos::inclusive_scan_custom_binary_op: fence after operation"); + Kokkos::Profiling::popRegion(); + // return return first_dest + num_elements; } @@ -195,7 +335,7 @@ OutputIteratorType inclusive_scan_custom_binary_op_exespace_impl( // aliases using index_type = typename InputIteratorType::difference_type; - using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; + using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; using func_type = ExeSpaceTransformInclusiveScanWithInitValueFunctor< ExecutionSpace, index_type, ValueType, InputIteratorType, OutputIteratorType, BinaryOpType, unary_op_type>; @@ -203,12 +343,17 @@ OutputIteratorType inclusive_scan_custom_binary_op_exespace_impl( // run const auto num_elements = Kokkos::Experimental::distance(first_from, last_from); + + Kokkos::Profiling::pushRegion(label + " via Kokkos::parallel_scan"); + ::Kokkos::parallel_scan(label, RangePolicy(ex, 0, num_elements), func_type(first_from, first_dest, binary_op, unary_op_type(), std::move(init_value))); ex.fence("Kokkos::inclusive_scan_custom_binary_op: fence after operation"); + Kokkos::Profiling::popRegion(); + // return return first_dest + num_elements; } @@ -283,7 +428,7 @@ KOKKOS_FUNCTION OutputIteratorType inclusive_scan_custom_binary_op_team_impl( // aliases using exe_space = typename TeamHandleType::execution_space; - using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; + using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; using func_type = TeamTransformInclusiveScanNoInitValueFunctor< exe_space, value_type, InputIteratorType, OutputIteratorType, BinaryOpType, unary_op_type>; @@ -291,7 +436,6 @@ KOKKOS_FUNCTION OutputIteratorType inclusive_scan_custom_binary_op_team_impl( // run const auto num_elements = Kokkos::Experimental::distance(first_from, last_from); - ::Kokkos::parallel_scan( TeamThreadRange(teamHandle, 0, num_elements), func_type(first_from, first_dest, binary_op, unary_op_type())); @@ -325,7 +469,7 @@ KOKKOS_FUNCTION OutputIteratorType inclusive_scan_custom_binary_op_team_impl( // aliases using exe_space = typename TeamHandleType::execution_space; - using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; + using unary_op_type = StdNumericScanIdentityReferenceUnaryFunctor; using func_type = TeamTransformInclusiveScanWithInitValueFunctor< exe_space, ValueType, InputIteratorType, OutputIteratorType, BinaryOpType, unary_op_type>; diff --git a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_RandomAccessIterator.hpp b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_RandomAccessIterator.hpp index e8c638c94c..c504673c3d 100644 --- a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_RandomAccessIterator.hpp +++ b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_RandomAccessIterator.hpp @@ -18,6 +18,7 @@ #define KOKKOS_RANDOM_ACCESS_ITERATOR_IMPL_HPP #include +#include // declval #include #include #include "Kokkos_Constraints.hpp" @@ -29,8 +30,29 @@ namespace Impl { template class RandomAccessIterator; +namespace { + +template +struct is_always_strided { + static_assert(is_view_v); + + constexpr static bool value = +#ifdef KOKKOS_ENABLE_IMPL_MDSPAN + decltype(std::declval().to_mdspan())::is_always_strided(); +#else + (std::is_same_v || + std::is_same_v || + std::is_same_v); +#endif +}; + +} // namespace + template -class RandomAccessIterator< ::Kokkos::View > { +class RandomAccessIterator<::Kokkos::View> { public: using view_type = ::Kokkos::View; using iterator_type = RandomAccessIterator; @@ -41,30 +63,31 @@ class RandomAccessIterator< ::Kokkos::View > { using pointer = typename view_type::pointer_type; using reference = typename view_type::reference_type; +// oneDPL needs this alias in order not to assume the data is on the host but on +// the device, see +// https://github.com/uxlfoundation/oneDPL/blob/a045eac689f9107f50ba7b42235e9e927118e483/include/oneapi/dpl/pstl/hetero/dpcpp/utils_ranges_sycl.h#L210-L214 +#ifdef KOKKOS_ENABLE_ONEDPL + using is_passed_directly = std::true_type; +#endif + static_assert(view_type::rank == 1 && - (std::is_same_v || - std::is_same_v || - std::is_same_v), - "RandomAccessIterator only supports 1D Views with LayoutLeft, " - "LayoutRight, LayoutStride."); + is_always_strided<::Kokkos::View>::value); KOKKOS_DEFAULTED_FUNCTION RandomAccessIterator() = default; explicit KOKKOS_FUNCTION RandomAccessIterator(const view_type view) - : m_view(view) {} + : m_data(view.data()), m_stride(view.stride_0()) {} explicit KOKKOS_FUNCTION RandomAccessIterator(const view_type view, ptrdiff_t current_index) - : m_view(view), m_current_index(current_index) {} + : m_data(view.data() + current_index * view.stride_0()), + m_stride(view.stride_0()) {} #ifndef KOKKOS_ENABLE_CXX17 // C++20 and beyond template requires(std::is_constructible_v) KOKKOS_FUNCTION explicit(!std::is_convertible_v) RandomAccessIterator(const RandomAccessIterator& other) - : m_view(other.m_view), m_current_index(other.m_current_index) {} + : m_data(other.m_data), m_stride(other.m_stride) {} #else template < class OtherViewType, @@ -73,19 +96,22 @@ class RandomAccessIterator< ::Kokkos::View > { int> = 0> KOKKOS_FUNCTION explicit RandomAccessIterator( const RandomAccessIterator& other) - : m_view(other.m_view), m_current_index(other.m_current_index) {} + : m_data(other.m_data), m_stride(other.m_stride) {} template , int> = 0> KOKKOS_FUNCTION RandomAccessIterator( const RandomAccessIterator& other) - : m_view(other.m_view), m_current_index(other.m_current_index) {} + : m_data(other.m_data), m_stride(other.m_stride) {} #endif KOKKOS_FUNCTION iterator_type& operator++() { - ++m_current_index; + if constexpr (is_always_contiguous) + m_data++; + else + m_data += m_stride; return *this; } @@ -98,7 +124,10 @@ class RandomAccessIterator< ::Kokkos::View > { KOKKOS_FUNCTION iterator_type& operator--() { - --m_current_index; + if constexpr (is_always_contiguous) + m_data--; + else + m_data -= m_stride; return *this; } @@ -111,77 +140,95 @@ class RandomAccessIterator< ::Kokkos::View > { KOKKOS_FUNCTION reference operator[](difference_type n) const { - return m_view(m_current_index + n); + if constexpr (is_always_contiguous) + return *(m_data + n); + else + return *(m_data + n * m_stride); } KOKKOS_FUNCTION iterator_type& operator+=(difference_type n) { - m_current_index += n; + if constexpr (is_always_contiguous) + m_data += n; + else + m_data += n * m_stride; return *this; } KOKKOS_FUNCTION iterator_type& operator-=(difference_type n) { - m_current_index -= n; + if constexpr (is_always_contiguous) + m_data -= n; + else + m_data -= n * m_stride; return *this; } KOKKOS_FUNCTION iterator_type operator+(difference_type n) const { - return iterator_type(m_view, m_current_index + n); + auto it = *this; + it += n; + return it; + } + + friend iterator_type operator+(difference_type n, iterator_type other) { + return other + n; } KOKKOS_FUNCTION iterator_type operator-(difference_type n) const { - return iterator_type(m_view, m_current_index - n); + auto it = *this; + it -= n; + return it; } KOKKOS_FUNCTION difference_type operator-(iterator_type it) const { - return m_current_index - it.m_current_index; + if constexpr (is_always_contiguous) + return m_data - it.m_data; + else + return (m_data - it.m_data) / m_stride; } KOKKOS_FUNCTION bool operator==(iterator_type other) const { - return m_current_index == other.m_current_index && - m_view.data() == other.m_view.data(); + return m_data == other.m_data && m_stride == other.m_stride; } KOKKOS_FUNCTION bool operator!=(iterator_type other) const { - return m_current_index != other.m_current_index || - m_view.data() != other.m_view.data(); + return m_data != other.m_data || m_stride != other.m_stride; } KOKKOS_FUNCTION - bool operator<(iterator_type other) const { - return m_current_index < other.m_current_index; - } + bool operator<(iterator_type other) const { return m_data < other.m_data; } KOKKOS_FUNCTION - bool operator<=(iterator_type other) const { - return m_current_index <= other.m_current_index; - } + bool operator<=(iterator_type other) const { return m_data <= other.m_data; } KOKKOS_FUNCTION - bool operator>(iterator_type other) const { - return m_current_index > other.m_current_index; - } + bool operator>(iterator_type other) const { return m_data > other.m_data; } KOKKOS_FUNCTION - bool operator>=(iterator_type other) const { - return m_current_index >= other.m_current_index; - } + bool operator>=(iterator_type other) const { return m_data >= other.m_data; } KOKKOS_FUNCTION - reference operator*() const { return m_view(m_current_index); } + reference operator*() const { return *m_data; } KOKKOS_FUNCTION - view_type view() const { return m_view; } + pointer data() const { return m_data; } + + KOKKOS_FUNCTION + int stride() const { return m_stride; } private: - view_type m_view; - ptrdiff_t m_current_index = 0; + pointer m_data; + int m_stride; + static constexpr bool is_always_contiguous = + (std::is_same_v || + std::is_same_v); // Needed for the converting constructor accepting another iterator template @@ -192,4 +239,10 @@ class RandomAccessIterator< ::Kokkos::View > { } // namespace Experimental } // namespace Kokkos +#ifdef KOKKOS_ENABLE_SYCL +template +struct sycl::is_device_copyable< + Kokkos::Experimental::Impl::RandomAccessIterator> : std::true_type {}; +#endif + #endif diff --git a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Unique.hpp b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Unique.hpp index 2863582458..75f3315473 100644 --- a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Unique.hpp +++ b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_Unique.hpp @@ -52,13 +52,10 @@ struct StdUniqueFunctor { auto& val_i = m_first_from[i]; const auto& val_ip1 = m_first_from[i + 1]; - if (final_pass) { - if (!m_pred(val_i, val_ip1)) { + if (!m_pred(val_i, val_ip1)) { + if (final_pass) { m_first_dest[update] = std::move(val_i); } - } - - if (!m_pred(val_i, val_ip1)) { update += 1; } } @@ -188,6 +185,7 @@ KOKKOS_FUNCTION IteratorType unique_team_impl(const TeamHandleType& teamHandle, IteratorType result = first; IteratorType lfirst = first; while (++lfirst != last) { + // NOLINTNEXTLINE(bugprone-inc-dec-in-conditions) if (!pred(*result, *lfirst) && ++result != lfirst) { *result = std::move(*lfirst); } diff --git a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_UniqueCopy.hpp b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_UniqueCopy.hpp index 710d04805d..226fd49d16 100644 --- a/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_UniqueCopy.hpp +++ b/lib/kokkos/algorithms/src/std_algorithms/impl/Kokkos_UniqueCopy.hpp @@ -175,9 +175,8 @@ KOKKOS_FUNCTION OutputIterator unique_copy_team_impl( d_first + count); } -#if defined KOKKOS_COMPILER_INTEL || \ - (defined(KOKKOS_COMPILER_NVCC) && KOKKOS_COMPILER_NVCC >= 1130 && \ - !defined(KOKKOS_COMPILER_MSVC)) +#if defined(KOKKOS_COMPILER_NVCC) && KOKKOS_COMPILER_NVCC >= 1130 && \ + !defined(KOKKOS_COMPILER_MSVC) __builtin_unreachable(); #endif } diff --git a/lib/kokkos/algorithms/unit_tests/Makefile b/lib/kokkos/algorithms/unit_tests/Makefile index d3946c149b..eaf616c5d6 100644 --- a/lib/kokkos/algorithms/unit_tests/Makefile +++ b/lib/kokkos/algorithms/unit_tests/Makefile @@ -18,6 +18,8 @@ LINK ?= $(CXX) LDFLAGS ?= override LDFLAGS += -lpthread +KOKKOS_USE_DEPRECATED_MAKEFILES=1 + include $(KOKKOS_PATH)/Makefile.kokkos KOKKOS_CXXFLAGS += -I$(GTEST_PATH) -I${KOKKOS_PATH}/algorithms/unit_tests -I${KOKKOS_PATH}/core/unit_test/category_files diff --git a/lib/kokkos/algorithms/unit_tests/TestRandom.hpp b/lib/kokkos/algorithms/unit_tests/TestRandom.hpp index 6960b912d0..ed9c2610b6 100644 --- a/lib/kokkos/algorithms/unit_tests/TestRandom.hpp +++ b/lib/kokkos/algorithms/unit_tests/TestRandom.hpp @@ -281,7 +281,7 @@ struct test_random_scalar { double covariance_eps = result.covariance / num_draws / 2 / variance_expect; #if defined(KOKKOS_BHALF_T_IS_FLOAT) && !KOKKOS_BHALF_T_IS_FLOAT - if (!std::is_same::value) { + if (!std::is_same_v) { #endif EXPECT_LT(std::abs(mean_eps), tolerance); EXPECT_LT(std::abs(variance_eps), 1.5 * tolerance); @@ -312,7 +312,7 @@ struct test_random_scalar { (result.covariance / HIST_DIM1D - covariance_expect) / mean_expect; #if defined(KOKKOS_HALF_T_IS_FLOAT) && !KOKKOS_HALF_T_IS_FLOAT - if (std::is_same::value) { + if (std::is_same_v) { mean_eps_expect = 0.0003; variance_eps_expect = 1.0; covariance_eps_expect = 5.0e4; @@ -320,7 +320,7 @@ struct test_random_scalar { #endif #if defined(KOKKOS_BHALF_T_IS_FLOAT) && !KOKKOS_BHALF_T_IS_FLOAT - if (!std::is_same::value) { + if (!std::is_same_v) { #endif EXPECT_LT(std::abs(mean_eps), mean_eps_expect); EXPECT_LT(std::abs(variance_eps), variance_eps_expect); @@ -358,13 +358,13 @@ struct test_random_scalar { (result.covariance / HIST_DIM1D - covariance_expect) / mean_expect; #if defined(KOKKOS_HALF_T_IS_FLOAT) && !KOKKOS_HALF_T_IS_FLOAT - if (std::is_same::value) { + if (std::is_same_v) { variance_factor = 7; } #endif #if defined(KOKKOS_BHALF_T_IS_FLOAT) && !KOKKOS_BHALF_T_IS_FLOAT - if (!std::is_same::value) { + if (!std::is_same_v) { #endif EXPECT_LT(std::abs(mean_eps), tolerance); EXPECT_LT(std::abs(variance_eps), variance_factor); diff --git a/lib/kokkos/algorithms/unit_tests/TestRandomAccessIterator.cpp b/lib/kokkos/algorithms/unit_tests/TestRandomAccessIterator.cpp index 5ab348cb19..65e45ebb96 100644 --- a/lib/kokkos/algorithms/unit_tests/TestRandomAccessIterator.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestRandomAccessIterator.cpp @@ -37,12 +37,18 @@ struct random_access_iterator_test : std_algorithms_test { TEST_F(random_access_iterator_test, constructor) { // just tests that constructor works - auto it1 = KE::Impl::RandomAccessIterator(m_static_view); - auto it2 = KE::Impl::RandomAccessIterator(m_dynamic_view); - auto it3 = KE::Impl::RandomAccessIterator(m_strided_view); - auto it4 = KE::Impl::RandomAccessIterator(m_static_view, 3); - auto it5 = KE::Impl::RandomAccessIterator(m_dynamic_view, 3); - auto it6 = KE::Impl::RandomAccessIterator(m_strided_view, 3); + [[maybe_unused]] auto it1 = + KE::Impl::RandomAccessIterator(m_static_view); + [[maybe_unused]] auto it2 = + KE::Impl::RandomAccessIterator(m_dynamic_view); + [[maybe_unused]] auto it3 = + KE::Impl::RandomAccessIterator(m_strided_view); + [[maybe_unused]] auto it4 = + KE::Impl::RandomAccessIterator(m_static_view, 3); + [[maybe_unused]] auto it5 = + KE::Impl::RandomAccessIterator(m_dynamic_view, 3); + [[maybe_unused]] auto it6 = + KE::Impl::RandomAccessIterator(m_strided_view, 3); EXPECT_TRUE(true); } diff --git a/lib/kokkos/algorithms/unit_tests/TestSort.hpp b/lib/kokkos/algorithms/unit_tests/TestSort.hpp index 5ea88ae5d6..562ff97e42 100644 --- a/lib/kokkos/algorithms/unit_tests/TestSort.hpp +++ b/lib/kokkos/algorithms/unit_tests/TestSort.hpp @@ -99,6 +99,7 @@ void test_dynamic_view_sort_impl(unsigned int n) { Kokkos::Experimental::DynamicView; using KeyViewType = Kokkos::View; + // NOLINTNEXTLINE(bugprone-implicit-widening-of-multiplication-result) const size_t upper_bound = 2 * n; const size_t min_chunk_size = 1024; diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCommon.hpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCommon.hpp index dadce2d474..d8a68f768a 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCommon.hpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCommon.hpp @@ -198,9 +198,8 @@ auto create_deep_copyable_compatible_view_with_same_extent(ViewType view) { // this is needed for intel to avoid // error #1011: missing return statement at end of non-void function -#if defined KOKKOS_COMPILER_INTEL || \ - (defined(KOKKOS_COMPILER_NVCC) && KOKKOS_COMPILER_NVCC >= 1130 && \ - !defined(KOKKOS_COMPILER_MSVC)) +#if defined(KOKKOS_COMPILER_NVCC) && KOKKOS_COMPILER_NVCC >= 1130 && \ + !defined(KOKKOS_COMPILER_MSVC) __builtin_unreachable(); #endif } diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCompileOnly.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCompileOnly.cpp index 9324db12f2..ddb7dc2a68 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCompileOnly.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsCompileOnly.cpp @@ -507,6 +507,20 @@ struct TestStruct { } }; +#ifndef KOKKOS_ENABLE_CXX17 +template +constexpr bool +test_kokkos_iterator_satify_std_random_access_iterator_concept() { + return std::random_access_iterator< + Kokkos::Experimental::Impl::RandomAccessIterator>; +} + +static_assert(test_kokkos_iterator_satify_std_random_access_iterator_concept< + Kokkos::View>()); +static_assert(test_kokkos_iterator_satify_std_random_access_iterator_concept< + Kokkos::View>()); +#endif + } // namespace compileonly } // namespace stdalgos } // namespace Test diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsConstraints.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsConstraints.cpp index 923ea970f9..67d21dd740 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsConstraints.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsConstraints.cpp @@ -173,6 +173,7 @@ TEST(std_algorithms_DeathTest, expect_no_overlap) { KE::Impl::expect_no_overlap(sub_first_d0, sub_last_d0, sub_first_d1); + // NOLINTNEXTLINE(bugprone-implicit-widening-of-multiplication-result) Kokkos::LayoutStride layout2d{2, 3, extent0, 2 * 3}; Kokkos::View strided_view_2d{ "std-algo-test-2d-contiguous-view-strided", layout2d}; diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsExclusiveScan.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsExclusiveScan.cpp index a85e63fe34..1a81991c35 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsExclusiveScan.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsExclusiveScan.cpp @@ -171,7 +171,7 @@ struct VerifyData { create_mirror_view_and_copy(Kokkos::HostSpace(), test_view_dc); if (test_view_h.extent(0) > 0) { for (std::size_t i = 0; i < test_view_h.extent(0); ++i) { - if (std::is_same::value) { + if (std::is_same_v) { ASSERT_EQ(gold_h(i), test_view_h(i)); } else { const auto error = diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsInclusiveScan.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsInclusiveScan.cpp index b4f40b4651..c8ecc137e2 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsInclusiveScan.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsInclusiveScan.cpp @@ -184,7 +184,7 @@ struct VerifyData { const auto ext = test_view_h.extent(0); if (ext > 0) { for (std::size_t i = 0; i < ext; ++i) { - if (std::is_same::value) { + if (std::is_same_v) { ASSERT_EQ(gold_h(i), test_view_h(i)); } else { const auto error = diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsIsSortedUntil.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsIsSortedUntil.cpp index 8327bfe13c..9e30630f07 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsIsSortedUntil.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsIsSortedUntil.cpp @@ -153,12 +153,13 @@ void run_single_scenario(const InfoType& scenario_info) { #if !defined KOKKOS_ENABLE_OPENMPTARGET CustomLessThanComparator comp; - auto r5 = + [[maybe_unused]] auto r5 = KE::is_sorted_until(exespace(), KE::cbegin(view), KE::cend(view), comp); - auto r6 = KE::is_sorted_until("label", exespace(), KE::cbegin(view), - KE::cend(view), comp); - auto r7 = KE::is_sorted_until(exespace(), view, comp); - auto r8 = KE::is_sorted_until("label", exespace(), view, comp); + [[maybe_unused]] auto r6 = KE::is_sorted_until( + "label", exespace(), KE::cbegin(view), KE::cend(view), comp); + [[maybe_unused]] auto r7 = KE::is_sorted_until(exespace(), view, comp); + [[maybe_unused]] auto r8 = + KE::is_sorted_until("label", exespace(), view, comp); #endif ASSERT_EQ(r1, gold) << name << ", " << view_tag_to_string(Tag{}); diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsModOps.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsModOps.cpp index 6918185bc0..1fbeab3d9d 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsModOps.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsModOps.cpp @@ -53,13 +53,13 @@ TEST(std_algorithms_mod_ops_test, move) { // move constr MyMovableType b(std::move(a)); ASSERT_EQ(b.m_value, 11); - ASSERT_EQ(a.m_value, -2); + ASSERT_EQ(a.m_value, -2); // NOLINT(bugprone-use-after-move) // move assign MyMovableType c; c = std::move(b); ASSERT_EQ(c.m_value, 11); - ASSERT_EQ(b.m_value, -4); + ASSERT_EQ(b.m_value, -4); // NOLINT(bugprone-use-after-move) } template @@ -70,7 +70,7 @@ struct StdAlgoModSeqOpsTestMove { void operator()(const int index) const { typename ViewType::value_type a{11}; using move_t = decltype(std::move(a)); - static_assert(std::is_rvalue_reference::value); + static_assert(std::is_rvalue_reference_v); m_view(index) = std::move(a); } diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsNumerics.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsNumerics.cpp index 0933c4e135..a3d7df533b 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsNumerics.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsNumerics.cpp @@ -243,16 +243,15 @@ void run_and_check_transform_reduce_overloadA(ViewType1 first_view, ViewType2 second_view, ValueType init_value, ValueType result_value, - Args&&... args) { + Args const&... args) { // trivial cases const auto r1 = KE::transform_reduce( ExecutionSpace(), KE::cbegin(first_view), KE::cbegin(first_view), - KE::cbegin(second_view), init_value, std::forward(args)...); + KE::cbegin(second_view), init_value, args...); - const auto r2 = - KE::transform_reduce("MYLABEL", ExecutionSpace(), KE::cbegin(first_view), - KE::cbegin(first_view), KE::cbegin(second_view), - init_value, std::forward(args)...); + const auto r2 = KE::transform_reduce( + "MYLABEL", ExecutionSpace(), KE::cbegin(first_view), + KE::cbegin(first_view), KE::cbegin(second_view), init_value, args...); ASSERT_EQ(r1, init_value); ASSERT_EQ(r2, init_value); @@ -260,18 +259,16 @@ void run_and_check_transform_reduce_overloadA(ViewType1 first_view, // non trivial cases const auto r3 = KE::transform_reduce( ExecutionSpace(), KE::cbegin(first_view), KE::cend(first_view), - KE::cbegin(second_view), init_value, std::forward(args)...); + KE::cbegin(second_view), init_value, args...); const auto r4 = KE::transform_reduce( "MYLABEL", ExecutionSpace(), KE::cbegin(first_view), KE::cend(first_view), - KE::cbegin(second_view), init_value, std::forward(args)...); + KE::cbegin(second_view), init_value, args...); - const auto r5 = - KE::transform_reduce(ExecutionSpace(), first_view, second_view, - init_value, std::forward(args)...); - const auto r6 = - KE::transform_reduce("MYLABEL", ExecutionSpace(), first_view, second_view, - init_value, std::forward(args)...); + const auto r5 = KE::transform_reduce(ExecutionSpace(), first_view, + second_view, init_value, args...); + const auto r6 = KE::transform_reduce("MYLABEL", ExecutionSpace(), first_view, + second_view, init_value, args...); ASSERT_EQ(r3, result_value); ASSERT_EQ(r4, result_value); @@ -363,32 +360,30 @@ template void run_and_check_transform_reduce_overloadB(ViewType view, ValueType init_value, ValueType result_value, - Args&&... args) { + Args const&... args) { // trivial - const auto r1 = - KE::transform_reduce(ExecutionSpace(), KE::cbegin(view), KE::cbegin(view), - init_value, std::forward(args)...); + const auto r1 = KE::transform_reduce(ExecutionSpace(), KE::cbegin(view), + KE::cbegin(view), init_value, args...); - const auto r2 = KE::transform_reduce("MYLABEL", ExecutionSpace(), - KE::cbegin(view), KE::cbegin(view), - init_value, std::forward(args)...); + const auto r2 = + KE::transform_reduce("MYLABEL", ExecutionSpace(), KE::cbegin(view), + KE::cbegin(view), init_value, args...); ASSERT_EQ(r1, init_value); ASSERT_EQ(r2, init_value); // non trivial - const auto r3 = - KE::transform_reduce(ExecutionSpace(), KE::cbegin(view), KE::cend(view), - init_value, std::forward(args)...); + const auto r3 = KE::transform_reduce(ExecutionSpace(), KE::cbegin(view), + KE::cend(view), init_value, args...); - const auto r4 = KE::transform_reduce("MYLABEL", ExecutionSpace(), - KE::cbegin(view), KE::cend(view), - init_value, std::forward(args)...); - const auto r5 = KE::transform_reduce(ExecutionSpace(), view, init_value, - std::forward(args)...); + const auto r4 = + KE::transform_reduce("MYLABEL", ExecutionSpace(), KE::cbegin(view), + KE::cend(view), init_value, args...); + const auto r5 = + KE::transform_reduce(ExecutionSpace(), view, init_value, args...); const auto r6 = KE::transform_reduce("MYLABEL", ExecutionSpace(), view, - init_value, std::forward(args)...); + init_value, args...); ASSERT_EQ(r3, result_value); ASSERT_EQ(r4, result_value); diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsRotate.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsRotate.cpp index bf5c2ee782..b9545e8b2e 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsRotate.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsRotate.cpp @@ -196,7 +196,7 @@ void run_single_scenario(const InfoType& scenario_info, // create host copy BEFORE rotate or view will be modified auto view_h = create_host_space_copy(view); auto rit = KE::rotate(exespace(), view, rotation_point); - // verify_data(rit, view, view_h, rotation_point); + verify_data(rit, view, view_h, rotation_point); } { diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamAdjacentDifference.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamAdjacentDifference.cpp index 5a2c046939..1dfdcfd568 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamAdjacentDifference.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamAdjacentDifference.cpp @@ -191,6 +191,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { ASSERT_EQ(stdDistance, distancesView_h(i)); break; } + default: Kokkos::abort("unreachable"); } } diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamAdjacentFind.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamAdjacentFind.cpp index 95f2934e01..88fc649a9b 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamAdjacentFind.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamAdjacentFind.cpp @@ -217,6 +217,7 @@ void test_A(const bool ensureAdjacentFindCanFind, std::size_t numTeams, break; } + default: Kokkos::abort("unreachable"); } } } diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamEqual.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamEqual.cpp index 82cce0b384..592bb4c864 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamEqual.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamEqual.cpp @@ -244,6 +244,7 @@ void test_A(const bool viewsAreEqual, std::size_t numTeams, std::size_t numCols, break; } + default: Kokkos::abort("unreachable"); } } } diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamExclusiveScan.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamExclusiveScan.cpp index 0c35c5e599..0c9f1e1bd2 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamExclusiveScan.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamExclusiveScan.cpp @@ -224,6 +224,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { break; } #endif + default: Kokkos::abort("unreachable"); } #undef exclusive_scan diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindEnd.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindEnd.cpp index d350bc62cd..21a905be56 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindEnd.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindEnd.cpp @@ -227,6 +227,7 @@ void test_A(const bool sequencesExist, std::size_t numTeams, break; } + default: Kokkos::abort("unreachable"); } if (sequencesExist) { diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindFirstOf.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindFirstOf.cpp index e992882e91..ad1043362e 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindFirstOf.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindFirstOf.cpp @@ -244,6 +244,7 @@ void test_A(const bool sequencesExist, std::size_t numTeams, break; } + default: Kokkos::abort("unreachable"); } } } diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindIf.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindIf.cpp index 70f2be77f6..f21f947e97 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindIf.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindIf.cpp @@ -57,14 +57,7 @@ struct TestFunctorA { const auto myRowIndex = member.league_rank(); auto myRowViewFrom = Kokkos::subview(m_dataView, myRowIndex, Kokkos::ALL()); const auto val = m_greaterThanValuesView(myRowIndex); - // FIXME_INTEL -#if defined(KOKKOS_COMPILER_INTEL) && (1900 == KOKKOS_COMPILER_INTEL) - GreaterEqualFunctor< - typename GreaterThanValuesViewType::non_const_value_type> - unaryPred{val}; -#else GreaterEqualFunctor unaryPred{val}; -#endif ptrdiff_t resultDist = 0; switch (m_apiPick) { @@ -185,12 +178,7 @@ void test_A(const bool predicatesReturnTrue, std::size_t numTeams, const auto rowFromBegin = KE::cbegin(rowFrom); const auto rowFromEnd = KE::cend(rowFrom); const auto val = greaterEqualValuesView_h(i); - // FIXME_INTEL -#if defined(KOKKOS_COMPILER_INTEL) && (1900 == KOKKOS_COMPILER_INTEL) - const GreaterEqualFunctor unaryPred{val}; -#else const GreaterEqualFunctor unaryPred{val}; -#endif auto it = std::find_if(rowFromBegin, rowFromEnd, unaryPred); diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindIfNot.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindIfNot.cpp index 873e8faf4c..0794dc0a79 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindIfNot.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamFindIfNot.cpp @@ -57,14 +57,7 @@ struct TestFunctorA { const auto myRowIndex = member.league_rank(); auto myRowViewFrom = Kokkos::subview(m_dataView, myRowIndex, Kokkos::ALL()); const auto val = m_greaterThanValuesView(myRowIndex); - // FIXME_INTEL -#if defined(KOKKOS_COMPILER_INTEL) && (1900 == KOKKOS_COMPILER_INTEL) - GreaterEqualFunctor< - typename GreaterThanValuesViewType::non_const_value_type> - unaryPred{val}; -#else GreaterEqualFunctor unaryPred{val}; -#endif ptrdiff_t resultDist = 0; switch (m_apiPick) { @@ -180,12 +173,7 @@ void test_A(const bool predicatesReturnTrue, std::size_t numTeams, const auto rowFromBegin = KE::cbegin(rowFrom); const auto rowFromEnd = KE::cend(rowFrom); const auto val = greaterEqualValuesView_h(i); - // FIXME_INTEL -#if defined(KOKKOS_COMPILER_INTEL) && (1900 == KOKKOS_COMPILER_INTEL) - const GreaterEqualFunctor unaryPred{val}; -#else const GreaterEqualFunctor unaryPred{val}; -#endif auto it = std::find_if_not(rowFromBegin, rowFromEnd, unaryPred); diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamInclusiveScan.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamInclusiveScan.cpp index b5f4cdd612..4c77eff9c4 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamInclusiveScan.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamInclusiveScan.cpp @@ -253,6 +253,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { break; } + default: Kokkos::abort("unreachable"); } #undef inclusive_scan diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamLexicographicalCompare.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamLexicographicalCompare.cpp index c377b9fec8..9d2d2721c6 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamLexicographicalCompare.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamLexicographicalCompare.cpp @@ -245,6 +245,7 @@ void test_A(const TestCaseType testCase, std::size_t numTeams, break; } + default: Kokkos::abort("unreachable"); } } } diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamMismatch.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamMismatch.cpp index 84269511d8..9b245508e3 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamMismatch.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamMismatch.cpp @@ -249,6 +249,7 @@ void test_A(const bool viewsAreEqual, std::size_t numTeams, std::size_t numCols, break; } + default: Kokkos::abort("unreachable"); } } } diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReduce.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReduce.cpp index eb00d9e083..88264b45c0 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReduce.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamReduce.cpp @@ -242,6 +242,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { break; } + default: Kokkos::abort("unreachable"); } #undef reduce diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamSearch.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamSearch.cpp index 039db4095d..1f0f4b6c1b 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamSearch.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamSearch.cpp @@ -243,6 +243,7 @@ void test_A(const bool sequencesExist, std::size_t numTeams, break; } + default: Kokkos::abort("unreachable"); } } } diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamSearchN.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamSearchN.cpp index 25cd1471e0..6d8a34e842 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamSearchN.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamSearchN.cpp @@ -258,6 +258,7 @@ void test_A(const bool sequencesExist, std::size_t numTeams, break; } + default: Kokkos::abort("unreachable"); } } } diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformExclusiveScan.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformExclusiveScan.cpp index 1c43854381..60e199a350 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformExclusiveScan.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformExclusiveScan.cpp @@ -203,6 +203,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { ASSERT_EQ(stdDistance, distancesView_h(i)); break; } + default: Kokkos::abort("unreachable"); } #undef transform_exclusive_scan diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformInclusiveScan.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformInclusiveScan.cpp index 78a21c4430..0dc3e68b1d 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformInclusiveScan.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformInclusiveScan.cpp @@ -240,6 +240,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { break; } + default: Kokkos::abort("unreachable"); } } #undef transform_inclusive_scan diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformReduce.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformReduce.cpp index 17ded226aa..3ad0b5b354 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformReduce.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTeamTransformReduce.cpp @@ -293,6 +293,7 @@ void test_A(std::size_t numTeams, std::size_t numCols, int apiId) { break; } + default: Kokkos::abort("unreachable"); } #undef transform_reduce diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTransformExclusiveScan.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTransformExclusiveScan.cpp index 365ca21688..e3114daeae 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTransformExclusiveScan.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTransformExclusiveScan.cpp @@ -344,8 +344,7 @@ TEST(std_algorithms_numeric_ops_test, transform_exclusive_scan_functor) { using view_type = Kokkos::View; view_type dummy_view("dummy_view", 0); using unary_op_type = - Kokkos::Experimental::Impl::StdNumericScanIdentityReferenceUnaryFunctor< - int>; + Kokkos::Experimental::Impl::StdNumericScanIdentityReferenceUnaryFunctor; using functor_type = Kokkos::Experimental::Impl::TransformExclusiveScanFunctorWithValueWrapper< exespace, int, int, view_type, view_type, MultiplyFunctor, diff --git a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTransformInclusiveScan.cpp b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTransformInclusiveScan.cpp index cc87262147..2dda12e22d 100644 --- a/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTransformInclusiveScan.cpp +++ b/lib/kokkos/algorithms/unit_tests/TestStdAlgorithmsTransformInclusiveScan.cpp @@ -390,8 +390,7 @@ TEST(std_algorithms_numeric_ops_test, transform_inclusive_scan_functor) { int dummy = 0; using view_type = Kokkos::View; view_type dummy_view("dummy_view", 0); - using unary_op_type = - KE::Impl::StdNumericScanIdentityReferenceUnaryFunctor; + using unary_op_type = KE::Impl::StdNumericScanIdentityReferenceUnaryFunctor; { using functor_type = KE::Impl::ExeSpaceTransformInclusiveScanNoInitValueFunctor< diff --git a/lib/kokkos/benchmarks/atomic/Makefile b/lib/kokkos/benchmarks/atomic/Makefile index 636c0ad4ab..c59de75ce8 100644 --- a/lib/kokkos/benchmarks/atomic/Makefile +++ b/lib/kokkos/benchmarks/atomic/Makefile @@ -2,6 +2,7 @@ KOKKOS_DEVICES=Cuda KOKKOS_CUDA_OPTIONS=enable_lambda KOKKOS_ARCH = "SNB,Volta70" +KOKKOS_USE_DEPRECATED_MAKEFILES=1 MAKEFILE_PATH := $(subst Makefile,,$(abspath $(lastword $(MAKEFILE_LIST)))) diff --git a/lib/kokkos/benchmarks/bytes_and_flops/Makefile b/lib/kokkos/benchmarks/bytes_and_flops/Makefile index 1aa4edddcd..4b6f084d20 100644 --- a/lib/kokkos/benchmarks/bytes_and_flops/Makefile +++ b/lib/kokkos/benchmarks/bytes_and_flops/Makefile @@ -2,6 +2,7 @@ KOKKOS_DEVICES=Cuda KOKKOS_CUDA_OPTIONS=enable_lambda KOKKOS_ARCH = "SNB,Volta70" +KOKKOS_USE_DEPRECATED_MAKEFILES=1 MAKEFILE_PATH := $(subst Makefile,,$(abspath $(lastword $(MAKEFILE_LIST)))) diff --git a/lib/kokkos/benchmarks/gather/Makefile b/lib/kokkos/benchmarks/gather/Makefile index 6827995bed..e1bfce21a6 100644 --- a/lib/kokkos/benchmarks/gather/Makefile +++ b/lib/kokkos/benchmarks/gather/Makefile @@ -2,6 +2,7 @@ KOKKOS_DEVICES=Cuda KOKKOS_CUDA_OPTIONS=enable_lambda KOKKOS_ARCH = "SNB,Volta70" +KOKKOS_USE_DEPRECATED_MAKEFILES=1 MAKEFILE_PATH := $(subst Makefile,,$(abspath $(lastword $(MAKEFILE_LIST)))) diff --git a/lib/kokkos/benchmarks/launch_latency/launch_latency.cpp b/lib/kokkos/benchmarks/launch_latency/launch_latency.cpp index 156c29af09..0935706ee8 100644 --- a/lib/kokkos/benchmarks/launch_latency/launch_latency.cpp +++ b/lib/kokkos/benchmarks/launch_latency/launch_latency.cpp @@ -37,7 +37,7 @@ template struct TestFunctor { - double values[V]; + double values[V] = {}; Kokkos::View a; int K; TestFunctor(Kokkos::View a_, int K_) : a(a_), K(K_) {} @@ -50,7 +50,7 @@ struct TestFunctor { template struct TestRFunctor { - double values[V]; + double values[V] = {}; Kokkos::View a; int K; TestRFunctor(Kokkos::View a_, int K_) : a(a_), K(K_) {} @@ -247,12 +247,15 @@ int main(int argc, char* argv[]) { // anything that doesn't start with -- if (arg.size() < 2 || (arg.size() >= 2 && arg[0] != '-' && arg[1] != '-')) { + // signing off that arg.data() is null terminated + // NOLINTBEGIN(bugprone-suspicious-stringview-data-usage) if (i == 1) N = atoi(arg.data()); else if (i == 2) M = atoi(arg.data()); else if (i == 3) K = atoi(arg.data()); + // NOLINTEND(bugprone-suspicious-stringview-data-usage) else { Kokkos::abort("unexpected argument!"); } diff --git a/lib/kokkos/benchmarks/policy_performance/Makefile b/lib/kokkos/benchmarks/policy_performance/Makefile index f50aea720e..21365f36c6 100644 --- a/lib/kokkos/benchmarks/policy_performance/Makefile +++ b/lib/kokkos/benchmarks/policy_performance/Makefile @@ -2,6 +2,7 @@ KOKKOS_DEVICES=Cuda KOKKOS_CUDA_OPTIONS=enable_lambda KOKKOS_ARCH = "SNB,Volta70" +KOKKOS_USE_DEPRECATED_MAKEFILES=1 MAKEFILE_PATH := $(subst Makefile,,$(abspath $(lastword $(MAKEFILE_LIST)))) diff --git a/lib/kokkos/benchmarks/policy_performance/main.cpp b/lib/kokkos/benchmarks/policy_performance/main.cpp index 0983a3d535..dd61ba6502 100644 --- a/lib/kokkos/benchmarks/policy_performance/main.cpp +++ b/lib/kokkos/benchmarks/policy_performance/main.cpp @@ -120,11 +120,12 @@ int main(int argc, char* argv[]) { // view appropriately for test and should obey first-touch etc Second call to // test is the one we actually care about and time view_type_1d v_1(Kokkos::view_alloc(Kokkos::WithoutInitializing, "v_1"), - team_range * team_size); + static_cast(team_range) * team_size); view_type_2d v_2(Kokkos::view_alloc(Kokkos::WithoutInitializing, "v_2"), - team_range * team_size, thread_range); + static_cast(team_range) * team_size, thread_range); view_type_3d v_3(Kokkos::view_alloc(Kokkos::WithoutInitializing, "v_3"), - team_range * team_size, thread_range, vector_range); + static_cast(team_range) * team_size, thread_range, + vector_range); double result_computed = 0.0; double result_expect = 0.0; diff --git a/lib/kokkos/benchmarks/policy_performance/policy_perf_test.hpp b/lib/kokkos/benchmarks/policy_performance/policy_perf_test.hpp index 0e23d221f6..8a874e0139 100644 --- a/lib/kokkos/benchmarks/policy_performance/policy_perf_test.hpp +++ b/lib/kokkos/benchmarks/policy_performance/policy_perf_test.hpp @@ -367,7 +367,7 @@ void test_policy(int team_range, int thread_range, int vector_range, // parallel_for RangePolicy: range = team_size*team_range if (test_type == 300) { Kokkos::parallel_for( - "300 outer for", team_size * team_range, + "300 outer for", static_cast(team_size) * team_range, KOKKOS_LAMBDA(const int idx) { v1(idx) = idx; // prevent compiler from optimizing away the loop @@ -376,14 +376,15 @@ void test_policy(int team_range, int thread_range, int vector_range, // parallel_reduce RangePolicy: range = team_size*team_range if (test_type == 400) { Kokkos::parallel_reduce( - "400 outer reduce", team_size * team_range, + "400 outer reduce", static_cast(team_size) * team_range, KOKKOS_LAMBDA(const int idx, double& val) { val += idx; }, result); result_expect = 0.5 * (team_size * team_range) * (team_size * team_range - 1); } // parallel_scan RangePolicy: range = team_size*team_range if (test_type == 500) { - Kokkos::parallel_scan("500 outer scan", team_size * team_range, + Kokkos::parallel_scan("500 outer scan", + static_cast(team_size) * team_range, ParallelScanFunctor(v1) #if 0 // This does not compile with pre Cuda 8.0 - see Github Issue #913 for explanation diff --git a/lib/kokkos/benchmarks/stream/Makefile b/lib/kokkos/benchmarks/stream/Makefile index 47a13838a4..529e789247 100644 --- a/lib/kokkos/benchmarks/stream/Makefile +++ b/lib/kokkos/benchmarks/stream/Makefile @@ -2,6 +2,7 @@ KOKKOS_DEVICES=Cuda KOKKOS_CUDA_OPTIONS=enable_lambda KOKKOS_ARCH = "SNB,Volta70" +KOKKOS_USE_DEPRECATED_MAKEFILES=1 MAKEFILE_PATH := $(subst Makefile,,$(abspath $(lastword $(MAKEFILE_LIST)))) diff --git a/lib/kokkos/benchmarks/view_copy_constructor/Makefile b/lib/kokkos/benchmarks/view_copy_constructor/Makefile index 70c6d517e0..77845a22b1 100644 --- a/lib/kokkos/benchmarks/view_copy_constructor/Makefile +++ b/lib/kokkos/benchmarks/view_copy_constructor/Makefile @@ -1,6 +1,7 @@ KOKKOS_DEVICES=Serial KOKKOS_ARCH = "" +KOKKOS_USE_DEPRECATED_MAKEFILES=1 MAKEFILE_PATH := $(subst Makefile,,$(abspath $(lastword $(MAKEFILE_LIST)))) diff --git a/lib/kokkos/bin/nvcc_wrapper b/lib/kokkos/bin/nvcc_wrapper index d58645f98a..8d3dbf1c75 100755 --- a/lib/kokkos/bin/nvcc_wrapper +++ b/lib/kokkos/bin/nvcc_wrapper @@ -317,7 +317,7 @@ do # End of Werror handling #Handle unsupported standard flags --std=c++1y|-std=c++1y|--std=gnu++1y|-std=gnu++1y|--std=c++1z|-std=c++1z|--std=gnu++1z|-std=gnu++1z|--std=c++2a|-std=c++2a) - fallback_std_flag="-std=c++14" + fallback_std_flag="-std=c++17" # this is hopefully just occurring in a downstream project during CMake feature tests # we really have no choice here but to accept the flag and change to an accepted C++ standard echo "nvcc_wrapper does not accept standard flags $1 since partial standard flags and standards after C++17 are not supported. nvcc_wrapper will use $fallback_std_flag instead. It is undefined behavior to use this flag. This should only be occurring during CMake configuration." @@ -346,35 +346,17 @@ do # NVCC only has C++20 from version 12 on cuda_main_version=$([[ $(${nvcc_compiler} --version) =~ V([0-9]+) ]] && echo ${BASH_REMATCH[1]}) if [ ${cuda_main_version} -lt 12 ]; then - fallback_std_flag="-std=c++14" + fallback_std_flag="-std=c++17" # this is hopefully just occurring in a downstream project during CMake feature tests # we really have no choice here but to accept the flag and change to an accepted C++ standard - echo "nvcc_wrapper does not accept standard flags $1 since partial standard flags and standards after C++14 are not supported. nvcc_wrapper will use $fallback_std_flag instead. It is undefined behavior to use this flag. This should only be occurring during CMake configuration." + echo "nvcc_wrapper does not accept standard flags $1 since partial standard flags and standards after C++17 are not supported. nvcc_wrapper will use $fallback_std_flag instead. It is undefined behavior to use this flag. This should only be occurring during CMake configuration." std_flag=$fallback_std_flag else std_flag=$1 fi shared_args="$shared_args $std_flag" ;; - --std=c++17|-std=c++17) - if [ -n "$std_flag" ]; then - warn_std_flag - shared_args=${shared_args/ $std_flag/} - fi - # NVCC only has C++17 from version 11 on - cuda_main_version=$([[ $(${nvcc_compiler} --version) =~ V([0-9]+) ]] && echo ${BASH_REMATCH[1]}) - if [ ${cuda_main_version} -lt 11 ]; then - fallback_std_flag="-std=c++14" - # this is hopefully just occurring in a downstream project during CMake feature tests - # we really have no choice here but to accept the flag and change to an accepted C++ standard - echo "nvcc_wrapper does not accept standard flags $1 since partial standard flags and standards after C++14 are not supported. nvcc_wrapper will use $fallback_std_flag instead. It is undefined behavior to use this flag. This should only be occurring during CMake configuration." - std_flag=$fallback_std_flag - else - std_flag=$1 - fi - shared_args="$shared_args $std_flag" - ;; - --std=c++11|-std=c++11|--std=c++14|-std=c++14) + --std=c++11|-std=c++11|--std=c++14|-std=c++14|--std=c++17|-std=c++17) if [ -n "$std_flag" ]; then warn_std_flag shared_args=${shared_args/ $std_flag/} @@ -500,6 +482,20 @@ do xlinker_args="$xlinker_args -Xlinker ${1:4:${#1}}" host_linker_args="$host_linker_args ${1:4:${#1}}" ;; + #Handle host assembler options + -Wa,*) + #To pass the -Wa options to the host compiler via -Xcompiler it is necessary + #to use '\\,' for each comma in the options. As users might already add escapes + #to the comma by themselves, the escapes are first removed and then only the + #required number of \ are added back. + xcompiler_args_wa=$(echo -e "$1" | sed -E 's/\\\+,/,/g' | sed -E 's/,/\\\\\\\,/g') + if [ $first_xcompiler_arg -eq 1 ]; then + xcompiler_args="$xcompiler_args_wa" + first_xcompiler_arg=0 + else + xcompiler_args="$xcompiler_args,$xcompiler_args_wa" + fi + ;; #Handle object files: -x cu applies to all input files, so give them to linker, except if only linking *.a|*.so|*.o|*.obj) object_files="$object_files $1" diff --git a/lib/kokkos/cmake/KokkosConfig.cmake.in b/lib/kokkos/cmake/KokkosConfig.cmake.in index 1b6d1b66ff..aed9f1060c 100644 --- a/lib/kokkos/cmake/KokkosConfig.cmake.in +++ b/lib/kokkos/cmake/KokkosConfig.cmake.in @@ -2,65 +2,71 @@ # loaded by include() and find_package() commands except when invoked with # the NO_POLICY_SCOPE option # CMP0057 + NEW -> IN_LIST operator in IF(...) -CMAKE_POLICY(SET CMP0057 NEW) +cmake_policy(SET CMP0057 NEW) # Compute paths @PACKAGE_INIT@ #Find dependencies -INCLUDE(CMakeFindDependencyMacro) +include(CMakeFindDependencyMacro) #This needs to go above the KokkosTargets in case #the Kokkos targets depend in some way on the TPL imports @KOKKOS_TPL_EXPORTS@ -GET_FILENAME_COMPONENT(Kokkos_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -INCLUDE("${Kokkos_CMAKE_DIR}/KokkosTargets.cmake") -INCLUDE("${Kokkos_CMAKE_DIR}/KokkosConfigCommon.cmake") -UNSET(Kokkos_CMAKE_DIR) +get_filename_component(Kokkos_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +include("${Kokkos_CMAKE_DIR}/KokkosTargets.cmake") +include("${Kokkos_CMAKE_DIR}/KokkosConfigCommon.cmake") +unset(Kokkos_CMAKE_DIR) # check for conflicts -IF("launch_compiler" IN_LIST Kokkos_FIND_COMPONENTS AND - "separable_compilation" IN_LIST Kokkos_FIND_COMPONENTS) - MESSAGE(STATUS "'launch_compiler' implies global redirection of targets depending on Kokkos to appropriate compiler.") - MESSAGE(STATUS "'separable_compilation' implies explicitly defining where redirection occurs via 'kokkos_compilation(PROJECT|TARGET|SOURCE|DIRECTORY ...)'") - MESSAGE(FATAL_ERROR "Conflicting COMPONENTS: 'launch_compiler' and 'separable_compilation'") -ENDIF() +if("launch_compiler" IN_LIST Kokkos_FIND_COMPONENTS AND "separable_compilation" IN_LIST Kokkos_FIND_COMPONENTS) + message(STATUS "'launch_compiler' implies global redirection of targets depending on Kokkos to appropriate compiler.") + message( + STATUS + "'separable_compilation' implies explicitly defining where redirection occurs via 'kokkos_compilation(PROJECT|TARGET|SOURCE|DIRECTORY ...)'" + ) + message(FATAL_ERROR "Conflicting COMPONENTS: 'launch_compiler' and 'separable_compilation'") +endif() -IF("launch_compiler" IN_LIST Kokkos_FIND_COMPONENTS) - # - # if find_package(Kokkos COMPONENTS launch_compiler) then rely on the - # RULE_LAUNCH_COMPILE and RULE_LAUNCH_LINK to always redirect to the - # appropriate compiler for Kokkos - # +if("launch_compiler" IN_LIST Kokkos_FIND_COMPONENTS) + # + # if find_package(Kokkos COMPONENTS launch_compiler) then rely on the + # RULE_LAUNCH_COMPILE and RULE_LAUNCH_LINK to always redirect to the + # appropriate compiler for Kokkos + # - MESSAGE(STATUS "kokkos_launch_compiler is enabled globally. C++ compiler commands with -DKOKKOS_DEPENDENCE will be redirected to the appropriate compiler for Kokkos") - kokkos_compilation( - GLOBAL - CHECK_CUDA_COMPILES) + message( + STATUS + "kokkos_launch_compiler is enabled globally. C++ compiler commands with -DKOKKOS_DEPENDENCE will be redirected to the appropriate compiler for Kokkos" + ) + kokkos_compilation(GLOBAL CHECK_CUDA_COMPILES) -ELSEIF(@Kokkos_ENABLE_CUDA@ - AND NOT @KOKKOS_COMPILE_LANGUAGE@ STREQUAL CUDA - AND NOT "separable_compilation" IN_LIST Kokkos_FIND_COMPONENTS) - # - # if CUDA was enabled, the compilation language was not set to CUDA, and separable compilation was not - # specified, then set the RULE_LAUNCH_COMPILE and RULE_LAUNCH_LINK globally and - # kokkos_launch_compiler will re-direct to the compiler used to compile CUDA code during installation. - # kokkos_launch_compiler will re-direct if ${CMAKE_CXX_COMPILER} and -DKOKKOS_DEPENDENCE is present, - # otherwise, the original command will be executed - # +elseif(@Kokkos_ENABLE_CUDA@ AND NOT @KOKKOS_COMPILE_LANGUAGE@ STREQUAL CUDA AND NOT "separable_compilation" IN_LIST + Kokkos_FIND_COMPONENTS +) + # + # if CUDA was enabled, the compilation language was not set to CUDA, and separable compilation was not + # specified, then set the RULE_LAUNCH_COMPILE and RULE_LAUNCH_LINK globally and + # kokkos_launch_compiler will re-direct to the compiler used to compile CUDA code during installation. + # kokkos_launch_compiler will re-direct if ${CMAKE_CXX_COMPILER} and -DKOKKOS_DEPENDENCE is present, + # otherwise, the original command will be executed + # - # run test to see if CMAKE_CXX_COMPILER=nvcc_wrapper - kokkos_compiler_is_nvcc(IS_NVCC ${CMAKE_CXX_COMPILER}) + # run test to see if CMAKE_CXX_COMPILER=nvcc_wrapper + kokkos_compiler_is_nvcc(IS_NVCC ${CMAKE_CXX_COMPILER}) - # if not nvcc_wrapper and Kokkos_LAUNCH_COMPILER was not set to OFF - IF(NOT IS_NVCC AND (NOT DEFINED Kokkos_LAUNCH_COMPILER OR Kokkos_LAUNCH_COMPILER)) - MESSAGE(STATUS "kokkos_launch_compiler is enabled globally. C++ compiler commands with -DKOKKOS_DEPENDENCE will be redirected to the appropriate compiler for Kokkos") - kokkos_compilation(GLOBAL) - ENDIF() + # if not nvcc_wrapper and Kokkos_LAUNCH_COMPILER was not set to OFF + if(NOT IS_NVCC AND (NOT DEFINED Kokkos_LAUNCH_COMPILER OR Kokkos_LAUNCH_COMPILER)) + message( + STATUS + "kokkos_launch_compiler is enabled globally. C++ compiler commands with -DKOKKOS_DEPENDENCE will be redirected to the appropriate compiler for Kokkos" + ) + kokkos_compilation(GLOBAL) + endif() - # be mindful of the environment, pollution is bad - UNSET(IS_NVCC) -ENDIF() + # be mindful of the environment, pollution is bad + unset(IS_NVCC) +endif() set(Kokkos_COMPILE_LANGUAGE @KOKKOS_COMPILE_LANGUAGE@) diff --git a/lib/kokkos/cmake/KokkosConfigCommon.cmake.in b/lib/kokkos/cmake/KokkosConfigCommon.cmake.in index d3ac39ffa3..769dff6b10 100644 --- a/lib/kokkos/cmake/KokkosConfigCommon.cmake.in +++ b/lib/kokkos/cmake/KokkosConfigCommon.cmake.in @@ -1,67 +1,67 @@ -SET(Kokkos_DEVICES @KOKKOS_ENABLED_DEVICES@) -SET(Kokkos_OPTIONS @KOKKOS_ENABLED_OPTIONS@) -SET(Kokkos_TPLS @KOKKOS_ENABLED_TPLS@) -SET(Kokkos_ARCH @KOKKOS_ENABLED_ARCH_LIST@) -SET(Kokkos_CXX_COMPILER "@CMAKE_CXX_COMPILER@") -SET(Kokkos_CXX_COMPILER_ID "@KOKKOS_CXX_COMPILER_ID@") -SET(Kokkos_CXX_COMPILER_VERSION "@KOKKOS_CXX_COMPILER_VERSION@") -SET(Kokkos_CXX_STANDARD @KOKKOS_CXX_STANDARD@) +set(Kokkos_DEVICES @KOKKOS_ENABLED_DEVICES@) +set(Kokkos_OPTIONS @KOKKOS_ENABLED_OPTIONS@) +set(Kokkos_TPLS @KOKKOS_ENABLED_TPLS@) +set(Kokkos_ARCH @KOKKOS_ENABLED_ARCH_LIST@) +set(Kokkos_CXX_COMPILER "@CMAKE_CXX_COMPILER@") +set(Kokkos_CXX_COMPILER_ID "@KOKKOS_CXX_COMPILER_ID@") +set(Kokkos_CXX_COMPILER_VERSION "@KOKKOS_CXX_COMPILER_VERSION@") +set(Kokkos_CXX_STANDARD @KOKKOS_CXX_STANDARD@) # Required to be a TriBITS-compliant external package -IF(NOT TARGET Kokkos::all_libs) +if(NOT TARGET Kokkos::all_libs) # CMake Error at /lib/cmake/Kokkos/KokkosConfigCommon.cmake:10 (ADD_LIBRARY): # ADD_LIBRARY cannot create ALIAS target "Kokkos::all_libs" because target # "Kokkos::kokkos" is imported but not globally visible. - IF(CMAKE_VERSION VERSION_LESS "3.18") - SET_TARGET_PROPERTIES(Kokkos::kokkos PROPERTIES IMPORTED_GLOBAL ON) - ENDIF() - ADD_LIBRARY(Kokkos::all_libs ALIAS Kokkos::kokkos) -ENDIF() + if(CMAKE_VERSION VERSION_LESS "3.18") + set_target_properties(Kokkos::kokkos PROPERTIES IMPORTED_GLOBAL ON) + endif() + add_library(Kokkos::all_libs ALIAS Kokkos::kokkos) +endif() # Export Kokkos_ENABLE_ for each backend that was enabled. # NOTE: "Devices" is a little bit of a misnomer here. These are really # backends, e.g. Kokkos_ENABLE_OPENMP, Kokkos_ENABLE_CUDA, Kokkos_ENABLE_HIP, # or Kokkos_ENABLE_SYCL. -FOREACH(DEV ${Kokkos_DEVICES}) - SET(Kokkos_ENABLE_${DEV} ON) -ENDFOREACH() +foreach(DEV ${Kokkos_DEVICES}) + set(Kokkos_ENABLE_${DEV} ON) +endforeach() # Export relevant Kokkos_ENABLE