Commit ed9f1366 authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@15602 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent 4f941abd
Loading
Loading
Loading
Loading

src/USER-MISC/fix_ti_rs.cpp

deleted100755 → 0
+0 −199
Original line number Diff line number Diff line
/* -------------------------------------------------------------------------
   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
   http://lammps.sandia.gov, Sandia National Laboratories
   Steve Plimpton, sjplimp@sandia.gov

   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:
             Rodrigo Freitas   (Unicamp/Brazil) - rodrigohb@gmail.com
             Maurice de Koning (Unicamp/Brazil) - dekoning@ifi.unicamp.br
------------------------------------------------------------------------- */

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "fix_ti_rs.h"
#include "atom.h"
#include "update.h"
#include "respa.h"
#include "error.h"
#include "force.h"

using namespace LAMMPS_NS;
using namespace FixConst;

/* ---------------------------------------------------------------------- */

// Class constructor initialize all variables.

FixTIRS::FixTIRS(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
{
  // Checking the input information.
  if (narg < 7 || narg > 9) error->all(FLERR,"Illegal fix ti/rs command");

  // Fix flags.
  vector_flag = 1;
  size_vector = 2;
  global_freq = 1;
  extvector   = 1;

  // Time variables.
  t_switch  = force->bnumeric(FLERR,arg[5]);
  t_equil   = force->bnumeric(FLERR,arg[6]);
  t0 = update->ntimestep;
  if (t_switch <= 0) error->all(FLERR,"Illegal fix ti/rs command");
  if (t_equil  <= 0) error->all(FLERR,"Illegal fix ti/rs command");

  // Coupling parameter limits and initialization.
  l_initial = force->numeric(FLERR,arg[3]);
  l_final   = force->numeric(FLERR,arg[4]);
  sf = 1;
  if (narg > 7) {
    if (strcmp(arg[7], "function") == 0) sf = force->inumeric(FLERR,arg[8]);
    else error->all(FLERR,"Illegal fix ti/rs switching function");
    if ((sf<1) || (sf>3))
      error->all(FLERR,"Illegal fix ti/rs switching function");
  }
  lambda  =  switch_func(0);
  dlambda = dswitch_func(0);
}

/* ---------------------------------------------------------------------- */

FixTIRS::~FixTIRS()
{
  // unregister callbacks to this fix from Atom class
  atom->delete_callback(id,0);
  atom->delete_callback(id,1);
}

/* ---------------------------------------------------------------------- */

int FixTIRS::setmask()
{
  int mask = 0;
  mask |= INITIAL_INTEGRATE;
  mask |= POST_FORCE;
  return mask;
}

/* ---------------------------------------------------------------------- */

void FixTIRS::init()
{
  if (strstr(update->integrate_style,"respa"))
    nlevels_respa = ((Respa *) update->integrate)->nlevels;
}

/* ---------------------------------------------------------------------- */

void FixTIRS::setup(int vflag)
{
  if (strstr(update->integrate_style,"verlet"))
    post_force(vflag);
  else {
    ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1);
    post_force_respa(vflag,nlevels_respa-1,0);
    ((Respa *) update->integrate)->copy_f_flevel(nlevels_respa-1);
  }
}

/* ---------------------------------------------------------------------- */

void FixTIRS::min_setup(int vflag)
{
  post_force(vflag);
}


/* ---------------------------------------------------------------------- */

void FixTIRS::post_force(int vflag)
{

  int *mask  = atom->mask;
  int nlocal = atom->nlocal;
  double **f = atom->f;

  // Scaling forces.
  for (int i = 0; i < nlocal; i++) {
    if (mask[i] & groupbit) {
      f[i][0] = lambda * f[i][0];
      f[i][1] = lambda * f[i][1];
      f[i][2] = lambda * f[i][2];
    }
  }
}

/* ---------------------------------------------------------------------- */

void FixTIRS::post_force_respa(int vflag, int ilevel, int iloop)
{
  if (ilevel == nlevels_respa-1) post_force(vflag);
}

/* ---------------------------------------------------------------------- */

void FixTIRS::min_post_force(int vflag)
{
  post_force(vflag);
}

/* ---------------------------------------------------------------------- */

void FixTIRS::initial_integrate(int vflag)
{
  // Update the coupling parameter value.
  const bigint t = update->ntimestep - (t0+t_equil);
  const double r_switch = 1.0/t_switch;

  if( (t >= 0) && (t <= t_switch) ) {
    lambda  =  switch_func(t*r_switch);
    dlambda = dswitch_func(t*r_switch);
  }

  if( (t >= t_equil+t_switch) && (t <= (t_equil+2*t_switch)) ) {
    lambda  =    switch_func(1.0 - (t - t_switch - t_equil)*r_switch);
    dlambda = - dswitch_func(1.0 - (t - t_switch - t_equil)*r_switch);
  }
}

/* ---------------------------------------------------------------------- */

double FixTIRS::compute_vector(int n)
{
  linfo[0] = lambda;
  linfo[1] = dlambda;
  return linfo[n];
}

/* ---------------------------------------------------------------------- */

double FixTIRS::switch_func(double t)
{
  if (sf == 2) return l_initial / (1 + t * (l_initial/l_final - 1));
  if (sf == 3) return l_initial / (1 + log2(1+t) * (l_initial/l_final - 1));

  // Default option is sf = 1.
  return l_initial + (l_final - l_initial) * t;
}

/* ---------------------------------------------------------------------- */

double FixTIRS::dswitch_func(double t)
{
  double aux = (1.0/l_initial - 1.0/l_final);
  if (sf == 2) return lambda * lambda * aux / t_switch;
  if (sf == 3) return lambda * lambda * aux / (t_switch * log(2) * (1 + t));

  // Default option is sf = 1.
  return (l_final-l_initial)/t_switch;
}

src/USER-MISC/fix_ti_rs.h

deleted100755 → 0
+0 −66
Original line number Diff line number Diff line
/* -*- c++ -*- ----------------------------------------------------------
   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
   http://lammps.sandia.gov, Sandia National Laboratories
   Steve Plimpton, sjplimp@sandia.gov

   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:
             Rodrigo Freitas   (Unicamp/Brazil) - rodrigohb@gmail.com
             Maurice de Koning (Unicamp/Brazil) - dekoning@ifi.unicamp.br
------------------------------------------------------------------------- */

#ifdef FIX_CLASS

FixStyle(ti/rs,FixTIRS)

#else

#ifndef LMP_FIX_TI_RS_H
#define LMP_FIX_TI_RS_H

#include "fix.h"

namespace LAMMPS_NS {

class FixTIRS : public Fix {
 public:
  FixTIRS(class LAMMPS *, int, char **);
  ~FixTIRS();
  int setmask();
  void init();
  void setup(int);
  void min_setup(int);
  void post_force(int);
  void post_force_respa(int, int, int);
  void min_post_force(int);
  virtual void initial_integrate(int);
  double compute_vector(int);

 private:
  double switch_func(double);
  double dswitch_func(double);

  double lambda;       // Coupling parameter.
  double dlambda;      // Lambda variation with t.
  double l_initial;    // Lambda initial value.
  double l_final;      // Lambda final value.
  double linfo[2];     // Current lambda status.
  bigint t_switch;     // Total switching steps.
  bigint t_equil;      // Equilibration time.
  bigint t0;           // Initial time.
  int    sf;           // Switching function option.
  int    nlevels_respa;
};

}

#endif
#endif
+44 −32
Original line number Diff line number Diff line
@@ -13,12 +13,13 @@

/* -------------------------------------------------------------------------
    Contributing authors: 
             Rodrigo Freitas   (Unicamp/Brazil) - rodrigohb@gmail.com
             Rodrigo Freitas (UC Berkeley) - rodrigof@berkeley.edu
             Mark Asta (UC Berkeley) - mdasta@berkeley.edu
             Maurice de Koning (Unicamp/Brazil) - dekoning@ifi.unicamp.br
------------------------------------------------------------------------- */

#include <stdlib.h>
#include <string.h>
#include "stdlib.h"
#include "string.h"
#include "fix_ti_spring.h"
#include "atom.h"
#include "update.h"
@@ -31,6 +32,18 @@
using namespace LAMMPS_NS; 
using namespace FixConst;  

static const char cite_ti_spring[] =
  "ti/spring command:\n\n"
  "@article{freitas2016,\n"
  "  author={Freitas, Rodrigo and Asta, Mark and de Koning, Maurice},\n"
  "  title={Nonequilibrium free-energy calculation of solids using LAMMPS},\n"
  "  journal={Computational Materials Science},\n"
  "  volume={112},\n"
  "  pages={333--341},\n"
  "  year={2016},\n"
  "  publisher={Elsevier}\n"
  "}\n\n";

/* ---------------------------------------------------------------------- */

FixTISpring::FixTISpring(LAMMPS *lmp, int narg, char **arg) : 
@@ -64,7 +77,7 @@ FixTISpring::FixTISpring(LAMMPS *lmp, int narg, char **arg) :

  double **x = atom->x;
  int *mask = atom->mask;
  imageint *image = atom->image;
  tagint *image = atom->image;
  int nlocal = atom->nlocal;

  for (int i = 0; i < nlocal; i++) {
@@ -73,16 +86,16 @@ FixTISpring::FixTISpring(LAMMPS *lmp, int narg, char **arg) :
  }

  // Time variables.
  t_switch = force->bnumeric(FLERR,arg[4]); // Number of steps for switching.
  t_equil =  force->bnumeric(FLERR,arg[5]); // Number of steps for equilibration.
  t_switch = atoi(arg[4]); // Switching time.
  t_equil = atoi(arg[5]);  // Equilibration time.
  t0 = update->ntimestep;  // Initial time.
  if (t_switch <= 0) error->all(FLERR,"Illegal fix ti/spring command");
  if (t_equil  <= 0) error->all(FLERR,"Illegal fix ti/spring command");
  if (t_switch < 0.0) error->all(FLERR,"Illegal fix ti/spring command");
  if (t_equil  < 0.0) error->all(FLERR,"Illegal fix ti/spring command");

  // Coupling parameter initialization.
  sf = 1;
  if (narg > 6) {
    if (strcmp(arg[6], "function") == 0) sf = force->inumeric(FLERR,arg[7]);
    if (strcmp(arg[6], "function") == 0) sf = atoi(arg[7]);
    else error->all(FLERR,"Illegal fix ti/spring switching function");
    if ((sf!=1) && (sf!=2)) 
      error->all(FLERR,"Illegal fix ti/spring switching function");
@@ -151,13 +164,13 @@ void FixTISpring::min_setup(int vflag)
void FixTISpring::post_force(int vflag)
{
  // If on the first equilibration do not calculate forces.
  bigint t = update->ntimestep - t0;
  int t = update->ntimestep - t0;
  if(t < t_equil) return;

  double **x = atom->x;
  double **f = atom->f;
  int *mask = atom->mask;
  imageint *image = atom->image;
  tagint *image = atom->image;
  int nlocal = atom->nlocal;

  double dx, dy, dz;
@@ -199,17 +212,16 @@ void FixTISpring::min_post_force(int vflag)
void FixTISpring::initial_integrate(int vflag) 
{ 
  // Update the coupling parameter value.
  const bigint t = update->ntimestep - (t0+t_equil);
  const double r_switch = 1.0/t_switch;
  double t = update->ntimestep - (t0+t_equil); 

  if( (t >= 0) && (t <= t_switch) ) {
    lambda  =  switch_func(t*r_switch);
    dlambda = dswitch_func(t*r_switch);
    lambda  =  switch_func(t/t_switch); 
    dlambda = dswitch_func(t/t_switch); 
  }

  if( (t >= t_equil+t_switch) && (t <= (t_equil+2*t_switch)) ) {
    lambda  =    switch_func(1.0 - (t - t_switch - t_equil)*r_switch);
    dlambda = - dswitch_func(1.0 - (t - t_switch - t_equil)*r_switch);
    lambda  =    switch_func(1.0 - (t - t_switch - t_equil)/t_switch ); 
    dlambda = - dswitch_func(1.0 - (t - t_switch - t_equil)/t_switch ); 
  }
} 

+8 −7
Original line number Diff line number Diff line
/* -*- c++ -*- ----------------------------------------------------------
/* ----------------------------------------------------------------------
   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
   http://lammps.sandia.gov, Sandia National Laboratories
   Steve Plimpton, sjplimp@sandia.gov
@@ -13,7 +13,8 @@

/* ----------------------------------------------------------------------
    Contributing authors: 
             Rodrigo Freitas   (Unicamp/Brazil) - rodrigohb@gmail.com
             Rodrigo Freitas (UC Berkeley) - rodrigof@berkeley.edu
             Mark Asta (UC Berkeley) - mdasta@berkeley.edu
             Maurice de Koning (Unicamp/Brazil) - dekoning@ifi.unicamp.br
------------------------------------------------------------------------- */

@@ -65,9 +66,9 @@ class FixTISpring : public Fix {
  double lambda;      // Coupling parameter.
  double dlambda;     // Lambda variation with t.
  double linfo[2];    // Current lambda status.
  bigint t_switch;    // Total switching steps.
  bigint t_equil;     // Equilibration time.
  bigint t0;          // Initial time.
  int    t_switch;    // Total switching steps.
  int    t_equil;     // Equilibration time.
  int    t0;          // Initial time.
  int    sf;          // Switching function option.
  int    nlevels_respa;
};