From 0c1dcfb617e9b0f4aeb3a38919d14b20ab09b357 Mon Sep 17 00:00:00 2001
From: Stan Moore <stamoor@sandia.gov>
Date: Fri, 6 Jul 2018 17:06:37 -0600
Subject: [PATCH] Favor copymode instead of cleanup_copy

---
 src/KOKKOS/fix_enforce2d_kokkos.cpp | 11 ++---------
 src/KOKKOS/fix_enforce2d_kokkos.h   |  3 +--
 src/fix_enforce2d.cpp               |  2 ++
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/src/KOKKOS/fix_enforce2d_kokkos.cpp b/src/KOKKOS/fix_enforce2d_kokkos.cpp
index f2c313b2fe..33aa39e2f6 100644
--- a/src/KOKKOS/fix_enforce2d_kokkos.cpp
+++ b/src/KOKKOS/fix_enforce2d_kokkos.cpp
@@ -77,6 +77,7 @@ void FixEnforce2DKokkos<DeviceType>::post_force(int vflag)
   if( atomKK->angmom_flag ) flag_mask |= 2;
   if( atomKK->torque_flag ) flag_mask |= 4;
 
+  copymode = 1;
   switch( flag_mask ){
     case 0:{
       FixEnforce2DKokkosPostForceFunctor<DeviceType,0,0,0> functor(this);
@@ -121,7 +122,7 @@ void FixEnforce2DKokkos<DeviceType>::post_force(int vflag)
     default:
       error->all(FLERR, "flag_mask outside of what it should be");
   }
-
+  copymode = 0;
 
   // Probably sync here again?
   atomKK->sync(execution_space,datamask_read);
@@ -159,14 +160,6 @@ void FixEnforce2DKokkos<DeviceType>::post_force_item( int i ) const
 }
 
 
-template<class DeviceType>
-void FixEnforce2DKokkos<DeviceType>::cleanup_copy()
-{
-  id = style = NULL;
-  vatom = NULL;
-}
-
-
 namespace LAMMPS_NS {
 template class FixEnforce2DKokkos<LMPDeviceType>;
 #ifdef KOKKOS_HAVE_CUDA
diff --git a/src/KOKKOS/fix_enforce2d_kokkos.h b/src/KOKKOS/fix_enforce2d_kokkos.h
index ae8183acf1..1ed3cf3ef8 100644
--- a/src/KOKKOS/fix_enforce2d_kokkos.h
+++ b/src/KOKKOS/fix_enforce2d_kokkos.h
@@ -33,7 +33,6 @@ class FixEnforce2DKokkos : public FixEnforce2D {
   FixEnforce2DKokkos(class LAMMPS *, int, char **);
   // ~FixEnforce2DKokkos() {}
   // void init();
-  void cleanup_copy();
   void setup(int);
   void post_force(int);
 
@@ -63,7 +62,7 @@ struct FixEnforce2DKokkosPostForceFunctor {
   FixEnforce2DKokkos<DeviceType> c;
 
   FixEnforce2DKokkosPostForceFunctor(FixEnforce2DKokkos<DeviceType>* c_ptr):
-    c(*c_ptr) {c.cleanup_copy();};
+    c(*c_ptr) {};
 
   KOKKOS_INLINE_FUNCTION
   void operator()(const int i) const {
diff --git a/src/fix_enforce2d.cpp b/src/fix_enforce2d.cpp
index 4ffd2ca7ac..791a52c50c 100644
--- a/src/fix_enforce2d.cpp
+++ b/src/fix_enforce2d.cpp
@@ -38,6 +38,8 @@ FixEnforce2D::FixEnforce2D(LAMMPS *lmp, int narg, char **arg) :
 
 FixEnforce2D::~FixEnforce2D()
 {
+  if (copymode) return;
+
   delete [] flist;
 }
 
-- 
GitLab