Advertisement
Guest User

fix_set.cpp

a guest
Apr 3rd, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include "fix_set.h"
  2. #include "mpi.h"
  3. #include "math.h"
  4. #include "stdio.h"
  5. #include "string.h"
  6. #include "stdlib.h"
  7. #include "atom.h"
  8. #include "domain.h"
  9. #include "region.h"
  10. #include "update.h"
  11. #include "respa.h"
  12. #include "modify.h"
  13. #include "force.h"
  14. #include "output.h"
  15. #include "group.h"
  16. #include "comm.h"
  17. #include "memory.h"
  18. #include "error.h"
  19. #include "variable.h"
  20. #include "input.h"
  21.  
  22. using namespace LAMMPS_NS;
  23. using namespace FixConst; //needed for L2.x
  24.  
  25. #define MIN(A,B) ((A) < (B)) ? (A) : (B)
  26. #define MAX(A,B) ((A) > (B)) ? (A) : (B)
  27.  
  28. FixSet::FixSet(LAMMPS *lmp, int narg, char **arg) :
  29.   Fix(lmp, narg, arg)
  30. {
  31.  
  32.    vector_flag = 1;
  33.    global_freq = 1;
  34.    extvector = 1;
  35.  
  36.    int i=0;
  37.  
  38.    //parse command-line args  
  39.    if (narg < 9) error->all(FLERR,"Illegal fix SET command, usage: fix ID GRP set {EVERY} vx vy vz region {ID}"); //FLERR,
  40.    nevery = atoi(arg[3]); //every n-th TS
  41.    fprintf(screen,"FixSet %d : %s %s %s %s\n",narg, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],arg[7],arg[8]);
  42.  
  43.    
  44.     char *id;
  45.     vx=atof(arg[4]);
  46.     vy=atof(arg[5]);
  47.     vz=atof(arg[6]);
  48.  
  49.     int n = strlen(arg[8]) + 1;
  50.     id = new char[n];
  51.     strcpy(id,arg[8]);
  52.     iregion = domain->find_region(id);
  53.     if (iregion == -1) error->all(FLERR,"Set region ID does not exist");
  54.     delete [] id;
  55.  
  56. }
  57.  
  58. FixSet::~FixSet()
  59. {
  60.   if (atom) atom->delete_callback(id,0);
  61. }
  62.  
  63. //tell the pipeline which functions should be invoked during run
  64. int FixSet::setmask()
  65. {
  66.   int mask=0;
  67.    mask |= END_OF_STEP; //needed for "nevery"
  68.   return mask;
  69. }
  70.  
  71. //runs every nevery steps
  72. void FixSet::end_of_step()
  73. {
  74.  modify->addstep_compute(update->ntimestep + nevery);
  75.  //do something
  76.     int n=atom->nlocal;
  77.     int cc=0;
  78.     double **x = atom->x;
  79.  
  80.     for (int i = 0; i < n; i++)
  81.       if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2])) {
  82.     atom->v[i][0] = vx; //todo use v_ID here
  83.     atom->v[i][1] = vy; //todo use v_ID here
  84.     atom->v[i][2] = vz; //todo use v_ID here
  85.     cc++;
  86.       }
  87.  //if (cc>0) printf("Hallo @step %d, seting %d/%d to %f atoms\n",update->ntimestep,cc,n,vz);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement