Commit cc09a633 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

small code refactor for FixNHUef class

- use forward declaration for UEFBox to avoid having to include custom header
- remove uef_arg_kludge() thanks to changes in 0c7879e9
parent 81be9b37
Loading
Loading
Loading
Loading
+71 −115
Original line number Diff line number Diff line
@@ -34,69 +34,15 @@
#include "neighbor.h"
#include "compute_pressure_uef.h"
#include "compute_temp_uef.h"
#include "uef_utils.h"

using namespace LAMMPS_NS;
using namespace FixConst;

enum{ISO,ANISO,TRICLINIC};
/* ---------------------------------------------------------------------- 
 Put all of the uef-only keywords at the back of arg and make narg smaller
 so FixNH::FixNH() only sees the keywords it knows. Save the numer of 
 remaining keywords in rem.
 ---------------------------------------------------------------------- */
char ** LAMMPS_NS::uef_arg_kludge(int &narg, char **arg, int &rem)
{
  int iarg = 3;
  bool flags[3]= {false,false,false};
  rem=0;
  char *tmp[3];
  while (iarg < narg)
  {
    if (strcmp(arg[iarg],"erate" ) == 0 && !flags[0])
    {
      tmp[0] = arg[iarg];
      tmp[1] = arg[iarg+1];
      tmp[2] = arg[iarg+2];
      for (int k=iarg+3; k<narg; k++)
        arg[k-3] = arg[k];
      arg[narg-1] = tmp[2];
      arg[narg-2] = tmp[1];
      arg[narg-3] = tmp[0];
      rem += 3;
      flags[0] = true;
    }
    else if (strcmp(arg[iarg],"strain" ) == 0 && !flags[1])
    {
      tmp[0] = arg[iarg];
      tmp[1] = arg[iarg+1];
      tmp[2] = arg[iarg+2];
      for (int k=iarg+3; k<narg; k++)
        arg[k-3] = arg[k];
      arg[narg-1] = tmp[2];
      arg[narg-2] = tmp[1];
      arg[narg-3] = tmp[0];
      rem += 3;
      flags[1] = true;
    }
    else if(strcmp(arg[iarg],"ext") == 0 && !flags[2])
    {
      tmp[0] = arg[iarg];
      tmp[1] = arg[iarg+1];
      for (int k=iarg+2; k<narg; k++)
        arg[k-2] = arg[k];
      arg[narg-1] = tmp[1];
      arg[narg-2] = tmp[0];
      rem += 2;
      flags[2] = true;
    }
    else
      iarg++;
  }
  narg -= rem;
  return arg;
}

// citation info

static const char cite_user_uef_package[] =
  "USER-UEF package:\n\n"
  "@Article{NicholsonRutledge16,\n"
@@ -110,43 +56,45 @@ static const char cite_user_uef_package[] =
  "}\n\n";

/* ----------------------------------------------------------------------
 * Parse the remaing keywords, do some error checking, and initalize 
 * Parse fix specific keywords, do some error checking, and initalize
 * temp/pressure fixes
 ---------------------------------------------------------------------- */
FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) :
  FixNH(lmp, narg, uef_arg_kludge(narg,arg,rem))
  FixNH(lmp, narg, arg), uefbox(NULL)
{
  if (lmp->citeme) lmp->citeme->add(cite_user_uef_package);

  //initialization

  erate[0] = erate[1] = 0;

  // default values

  strain[0]=strain[1]= 0;
  ext_flags[0]=ext_flags[1]=ext_flags[2] = true;

  // need to initialize these

  omega_dot[0]=omega_dot[1]=omega_dot[2]=0;

  // parse remaining input
  // parse fix nh/uef specific options

  bool erate_flag = false;
  int iarg = narg;
  narg += rem;
  while (iarg <narg)
  {
  int iarg = 3;

  while (iarg <narg) {
    if (strcmp(arg[iarg],"erate")==0) {
      if (iarg+3 > narg) error->all(FLERR,"Illegal fix nvt/npt/uef command");
      erate[0] = force->numeric(FLERR,arg[iarg+1]);
      erate[1] = force->numeric(FLERR,arg[iarg+2]);
      erate_flag = true;
      iarg += 3;
    }
    else if (strcmp(arg[iarg],"strain")==0) {
    } else if (strcmp(arg[iarg],"strain")==0) {
      if (iarg+3 > narg) error->all(FLERR,"Illegal fix nvt/npt/uef command");
      strain[0] = force->numeric(FLERR,arg[iarg+1]);
      strain[1] = force->numeric(FLERR,arg[iarg+2]);
      iarg += 3;
    }
    else if (strcmp(arg[iarg],"ext")==0) {
    } else if (strcmp(arg[iarg],"ext")==0) {
      if (iarg+2 > narg) error->all(FLERR,"Illegal fix nvt/npt/uef command");
      if (strcmp(arg[iarg+1],"x")==0)
        ext_flags[1] = ext_flags[2] =  false;
@@ -165,9 +113,10 @@ FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) :

      iarg += 2;
    }
    else
      error->all(FLERR,"Illegal fix nvt/npt/uef command");
    // skip to next argument; argument check for unknown keywords is done in FixNH
    ++iarg;
  }

  if (!erate_flag)
    error->all(FLERR,"Keyword erate must be set for fix npt/npt/uef command");

@@ -177,6 +126,7 @@ FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) :
    error->all(FLERR,"Simulation box must be triclinic for fix/nvt/npt/uef");

  // check for conditions that impose a deviatoric stress

  if (pstyle == TRICLINIC)
    error->all(FLERR,"Only normal stresses can be controlled with fix/nvt/npt/uef");
  double erate_tmp[3];
@@ -184,43 +134,51 @@ FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) :
  erate_tmp[1]=erate[1];
  erate_tmp[2]=-erate[0]-erate[1];

  if (pstyle == ANISO)
  {
  if (pstyle == ANISO) {
    if (!(ext_flags[0] & ext_flags[1] & ext_flags[2]))
      error->all(FLERR,"The ext keyword may only be used with iso pressure control");
    for (int k=0;k<3;k++)
      for (int j=0;j<3;j++)
        if (p_flag[k] && p_flag[j])
        {
        if (p_flag[k] && p_flag[j]) {
          double tol = 1e-6;
          if ( !nearly_equal(p_start[k],p_start[j],tol) || !nearly_equal(p_stop[k],p_stop[j],tol))
            error->all(FLERR,"All controlled stresses must have the same value in fix/nvt/npt/uef");
          if ( !nearly_equal(erate_tmp[k],erate_tmp[j],tol) || !nearly_equal(erate_tmp[k],erate_tmp[j],tol))
            error->all(FLERR,"Dimensions with controlled stresses must have same strain rate in fix/nvt/npt/uef");
          if ( !nearly_equal(p_start[k],p_start[j],tol)
               || !nearly_equal(p_stop[k],p_stop[j],tol))
            error->all(FLERR,"All controlled stresses must have the same "
                       "value in fix/nvt/npt/uef");
          if ( !nearly_equal(erate_tmp[k],erate_tmp[j],tol)
               || !nearly_equal(erate_tmp[k],erate_tmp[j],tol))
            error->all(FLERR,"Dimensions with controlled stresses must have"\
                       " same strain rate in fix/nvt/npt/uef");
        }
  }
  // conditions that produce a deviatoric stress have already
  // been eliminated.

  // conditions that produce a deviatoric stress have already been eliminated.

  deviatoric_flag=0;

  // need pre_exchange and irregular migration

  pre_exchange_flag = 1;
  irregular = new Irregular(lmp);

  // flag that I change the box here (in case of nvt)

  box_change_shape = 1;

  // initialize the UEFBox class which computes the box at each step

  uefbox = new UEF_utils::UEFBox();
  uefbox->set_strain(strain[0],strain[1]);

  // reset fixedpoint to the stagnation point. I don't allow fixedpoint
  // to be set by the user.

  fixedpoint[0] = domain->boxlo[0];
  fixedpoint[1] = domain->boxlo[1];
  fixedpoint[2] = domain->boxlo[2];

  // Create temp and pressure computes for uef
  // Create temp and pressure computes for nh/uef

  int n = strlen(id) + 6;
  id_temp = new char[n];
  strcpy(id_temp,id);
@@ -232,6 +190,7 @@ FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) :
  modify->add_compute(3,newarg);
  delete [] newarg;
  tcomputeflag = 1;

  n = strlen(id) + 7;
  id_press = new char[n];
  strcpy(id_press,id);
@@ -246,8 +205,6 @@ FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) :
  pcomputeflag = 1;

  nevery = 1;


}

/* ----------------------------------------------------------------------
@@ -294,19 +251,18 @@ void FixNHUef::init()

  // this will make the pressure compute for nvt
  if (!pstat_flag)
    if (pcomputeflag)
    {
    if (pcomputeflag) {
      int icomp = modify->find_compute(id_press);
      if (icomp<0)
        error->all(FLERR,"Pressure ID for fix/nvt/uef doesn't exist");
      pressure = modify->compute[icomp];

    }
      if (strcmp(pressure->style,"pressure/uef") != 0)
        error->all(FLERR,"Using fix nvt/npt/uef without a compute pressure/uef");
    }

  if (strcmp(temperature->style,"temp/uef") != 0)
    error->all(FLERR,"Using fix nvt/npt/uef without a compute temp/uef");
  
}

/* ----------------------------------------------------------------------
+6 −4
Original line number Diff line number Diff line
/* ----------------------------------------------------------------------
/* -*- c++ -*- ----------------------------------------------------------
   LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
   www.cs.sandia.gov/~sjplimp/lammps.html
   Steve Plimpton, sjplimp@sandia.gov, Sandia National Laboratories
@@ -17,12 +17,14 @@
#ifndef LMP_FIX_NH_UEF_H
#define LMP_FIX_NH_UEF_H

#include "uef_utils.h"
#include "fix_nh.h"

namespace LAMMPS_NS {
  // forward declaration
  namespace UEF_utils {
    class UEFBox;
  };

char **uef_arg_kludge(int&, char**, int&);
class FixNHUef : public FixNH {
 public:
  FixNHUef(class LAMMPS *, int, char **);