示例#1
0
void FixAdapt::init()
{
  int i,j;

  // allow a dynamic group only if ATOM attribute not used

  if (group->dynamic[igroup])
    for (int i = 0; i < nadapt; i++)
      if (adapt[i].which == ATOM)
        error->all(FLERR,"Cannot use dynamic group with fix adapt atom");

  // setup and error checks

  anypair = 0;

  for (int m = 0; m < nadapt; m++) {
    Adapt *ad = &adapt[m];

    ad->ivar = input->variable->find(ad->var);
    if (ad->ivar < 0)
      error->all(FLERR,"Variable name for fix adapt does not exist");
    if (!input->variable->equalstyle(ad->ivar))
      error->all(FLERR,"Variable for fix adapt is invalid style");

    if (ad->which == PAIR) {
      anypair = 1;
      ad->pair = NULL;

      // if ad->pstyle has trailing sub-style annotation ":N",
      //   strip it for pstyle arg to pair_match() and set nsub = N
      // this should work for appended suffixes as well

      int n = strlen(ad->pstyle) + 1;
      char *pstyle = new char[n];
      strcpy(pstyle,ad->pstyle);

      char *cptr;
      int nsub = 0;
      if ((cptr = strchr(pstyle,':'))) {
        *cptr = '\0';
        nsub = force->inumeric(FLERR,cptr+1);
      }

      if (lmp->suffix_enable) {
        int len = 2 + strlen(pstyle) + strlen(lmp->suffix);
        char *psuffix = new char[len];
        strcpy(psuffix,pstyle);
        strcat(psuffix,"/");
        strcat(psuffix,lmp->suffix);
        ad->pair = force->pair_match(psuffix,1,nsub);
        delete[] psuffix;
      }
      if (ad->pair == NULL) ad->pair = force->pair_match(pstyle,1,nsub);
      if (ad->pair == NULL) error->all(FLERR,"Fix adapt pair style does not exist");

      void *ptr = ad->pair->extract(ad->pparam,ad->pdim);
      if (ptr == NULL)
        error->all(FLERR,"Fix adapt pair style param not supported");

      // for pair styles only parameters that are 2-d arrays in atom types or
      // scalars are supported
      if (ad->pdim != 2 && ad->pdim != 0)
        error->all(FLERR,"Fix adapt pair style param is not compatible");

      if(ad->pdim == 2) ad->array = (double **) ptr;
      if(ad->pdim == 0) ad->scalar = (double *) ptr;

      // if pair hybrid, test that ilo,ihi,jlo,jhi are valid for sub-style

      if (strcmp(force->pair_style,"hybrid") == 0 ||
          strcmp(force->pair_style,"hybrid/overlay") == 0) {
        PairHybrid *pair = (PairHybrid *) force->pair;
        for (i = ad->ilo; i <= ad->ihi; i++)
          for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
            if (!pair->check_ijtype(i,j,pstyle))
              error->all(FLERR,"Fix adapt type pair range is not valid for "
                         "pair hybrid sub-style");
      }

      delete [] pstyle;

    } else if (ad->which == KSPACE) {
      if (force->kspace == NULL)
        error->all(FLERR,"Fix adapt kspace style does not exist");
      kspace_scale = (double *) force->kspace->extract("scale");

    } else if (ad->which == ATOM) {
      if (ad->aparam == DIAMETER) {
        if (!atom->radius_flag)
          error->all(FLERR,"Fix adapt requires atom attribute diameter");
      }
      if (ad->aparam == CHARGE) {
	if (!atom->q_flag)
	  error->all(FLERR,"Fix adapt requires atom attribute charge");
      }
    }
  }

  // make copy of original pair array values
  for (int m = 0; m < nadapt; m++) {
    Adapt *ad = &adapt[m];
    if (ad->which == PAIR && ad->pdim == 2) {
      for (i = ad->ilo; i <= ad->ihi; i++)
        for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
          ad->array_orig[i][j] = ad->array[i][j];
    }else if (ad->which == PAIR && ad->pdim == 0){
      ad->scalar_orig = *ad->scalar;
    }
  }

  // fixes that store initial per-atom values

  if (id_fix_diam) {
    int ifix = modify->find_fix(id_fix_diam);
    if (ifix < 0) error->all(FLERR,"Could not find fix adapt storage fix ID");
    fix_diam = (FixStore *) modify->fix[ifix];
  }
  if (id_fix_chg) {
    int ifix = modify->find_fix(id_fix_chg);
    if (ifix < 0) error->all(FLERR,"Could not find fix adapt storage fix ID");
    fix_chg = (FixStore *) modify->fix[ifix];
  }

  if (strstr(update->integrate_style,"respa"))
    nlevels_respa = ((Respa *) update->integrate)->nlevels;
}
示例#2
0
void FixAdapt::init()
{
    int i,j;

    // setup and error checks

    anypair = 0;

    for (int m = 0; m < nadapt; m++) {
        Adapt *ad = &adapt[m];

        ad->ivar = input->variable->find(ad->var);
        if (ad->ivar < 0)
            error->all("Variable name for fix adapt does not exist");
        if (!input->variable->equalstyle(ad->ivar))
            error->all("Variable for fix adapt is invalid style");

        if (ad->which == PAIR) {
            anypair = 1;

            Pair *pair = force->pair_match(ad->pstyle,1);
            if (pair == NULL) error->all("Fix adapt pair style does not exist");
            void *ptr = pair->extract(ad->pparam,ad->pdim);
            if (ptr == NULL) error->all("Fix adapt pair style param not supported");

            ad->pdim = 2;
            if (ad->pdim == 0) ad->scalar = (double *) ptr;
            if (ad->pdim == 2) ad->array = (double **) ptr;

            // if pair hybrid, test that ilo,ihi,jlo,jhi are valid for sub-style

            if (ad->pdim == 2 && (strcmp(force->pair_style,"hybrid") == 0 ||
                                  strcmp(force->pair_style,"hybrid/overlay") == 0)) {
                PairHybrid *pair = (PairHybrid *) force->pair;
                for (i = ad->ilo; i <= ad->ihi; i++)
                    for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
                        if (!pair->check_ijtype(i,j,ad->pstyle))
                            error->all("Fix adapt type pair range is not valid for "
                                       "pair hybrid sub-style");
            }

        } else if (ad->which == KSPACE) {
            if (force->kspace == NULL)
                error->all("Fix adapt is incompatible with KSpace style");
            kspace_scale = (double *) force->kspace->extract("scale");

        } else if (ad->which == ATOM) {
            if (ad->aparam == DIAMETER) {
                if (!atom->radius_flag)
                    error->all("Fix adapt requires atom attribute diameter");
            }
        }
    }

    // make copy of original pair array values

    for (int m = 0; m < nadapt; m++) {
        Adapt *ad = &adapt[m];
        if (ad->which == PAIR && ad->pdim == 2) {
            for (i = ad->ilo; i <= ad->ihi; i++)
                for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
                    ad->array_orig[i][j] = ad->array[i][j];
        }
    }
}
示例#3
0
void ComputeFEP::init()
{
  int i,j;

  if (!fepinitflag)    // avoid init to run entirely when called by write_data
      fepinitflag = 1;
  else return;

  // setup and error checks

  pairflag = 0;

  for (int m = 0; m < npert; m++) {
    Perturb *pert = &perturb[m];

    pert->ivar = input->variable->find(pert->var);
    if (pert->ivar < 0)
      error->all(FLERR,"Variable name for compute fep does not exist");
    if (!input->variable->equalstyle(pert->ivar))
      error->all(FLERR,"Variable for compute fep is of invalid style");

    if (force->pair == NULL)
      error->all(FLERR,"compute fep pair requires pair interactions");

    if (pert->which == PAIR) {
      pairflag = 1;

      Pair *pair = force->pair_match(pert->pstyle,1);
      if (pair == NULL) error->all(FLERR,"compute fep pair style "
                                   "does not exist");
      void *ptr = pair->extract(pert->pparam,pert->pdim);
      if (ptr == NULL) 
        error->all(FLERR,"compute fep pair style param not supported");

      pert->array = (double **) ptr;

      // if pair hybrid, test that ilo,ihi,jlo,jhi are valid for sub-style

      if ((strcmp(force->pair_style,"hybrid") == 0 ||
           strcmp(force->pair_style,"hybrid/overlay") == 0)) {
        PairHybrid *pair = (PairHybrid *) force->pair;
        for (i = pert->ilo; i <= pert->ihi; i++)
          for (j = MAX(pert->jlo,i); j <= pert->jhi; j++)
            if (!pair->check_ijtype(i,j,pert->pstyle))
              error->all(FLERR,"compute fep type pair range is not valid for "
                         "pair hybrid sub-style");
      }

    } else if (pert->which == ATOM) {
      if (pert->aparam == CHARGE) {
        if (!atom->q_flag)
          error->all(FLERR,"compute fep requires atom attribute charge");
      }
    }
  }

  if (tailflag) {
    if (force->pair->tail_flag == 0)
      error->all(FLERR,"Compute fep tail when pair style does not "
                 "compute tail corrections");
  }

  // detect if package gpu is present

  int ifixgpu = modify->find_fix("package_gpu");
  if (ifixgpu >= 0) fixgpu = modify->fix[ifixgpu];

  if (comm->me == 0) {
    if (screen) {
      fprintf(screen, "FEP settings ...\n");
      fprintf(screen, "  temperature = %f\n", temp_fep);
      fprintf(screen, "  tail %s\n", (tailflag ? "yes":"no"));
      for (int m = 0; m < npert; m++) {
        Perturb *pert = &perturb[m];
        if (pert->which == PAIR)
          fprintf(screen, "  %s %s %d-%d %d-%d\n", pert->pstyle, pert->pparam,
                  pert->ilo, pert->ihi, pert->jlo, pert->jhi);
        else if (pert->which == ATOM)
          fprintf(screen, "  %d-%d charge\n", pert->ilo, pert->ihi);
      }
    }
    if (logfile) {
      fprintf(logfile, "FEP settings ...\n");
      fprintf(logfile, "  temperature = %f\n", temp_fep);
      fprintf(logfile, "  tail %s\n", (tailflag ? "yes":"no"));
      for (int m = 0; m < npert; m++) {
        Perturb *pert = &perturb[m];
        if (pert->which == PAIR)
          fprintf(logfile, "  %s %s %d-%d %d-%d\n", pert->pstyle, pert->pparam,
                  pert->ilo, pert->ihi, pert->jlo, pert->jhi);
        else if (pert->which == ATOM)
          fprintf(logfile, "  %d-%d charge\n", pert->ilo, pert->ihi);
      }
    }
  }

}
示例#4
0
void FixAdaptFEP::init()
{
  int i,j;

  // setup and error checks

  anypair = 0;

  for (int m = 0; m < nadapt; m++) {
    Adapt *ad = &adapt[m];

    ad->ivar = input->variable->find(ad->var);
    if (ad->ivar < 0)
      error->all(FLERR,"Variable name for fix adapt/fep does not exist");
    if (!input->variable->equalstyle(ad->ivar))
      error->all(FLERR,"Variable for fix adapt/fep is invalid style");

    if (ad->which == PAIR) {
      anypair = 1;

      Pair *pair = force->pair_match(ad->pstyle,1);
      if (pair == NULL) error->all(FLERR,"Fix adapt/fep pair style does not exist");
      void *ptr = pair->extract(ad->pparam,ad->pdim);
      if (ptr == NULL) 
        error->all(FLERR,"Fix adapt/fep pair style param not supported");

      ad->pdim = 2;
      if (ad->pdim == 0) ad->scalar = (double *) ptr;
      if (ad->pdim == 2) ad->array = (double **) ptr;

      // if pair hybrid, test that ilo,ihi,jlo,jhi are valid for sub-style

      if (ad->pdim == 2 && (strcmp(force->pair_style,"hybrid") == 0 ||
                            strcmp(force->pair_style,"hybrid/overlay") == 0)) {
        PairHybrid *pair = (PairHybrid *) force->pair;
        for (i = ad->ilo; i <= ad->ihi; i++)
          for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
            if (!pair->check_ijtype(i,j,ad->pstyle))
              error->all(FLERR,"Fix adapt/fep type pair range is not valid for "
                         "pair hybrid sub-style");
      }

    } else if (ad->which == KSPACE) {
      if (force->kspace == NULL)
        error->all(FLERR,"Fix adapt/fep kspace style does not exist");
      kspace_scale = (double *) force->kspace->extract("scale");

    } else if (ad->which == ATOM) {
      if (ad->aparam == DIAMETER) {
        if (!atom->radius_flag)
          error->all(FLERR,"Fix adapt/fep requires atom attribute diameter");
      }
      if (ad->aparam == CHARGE) {
        if (!atom->q_flag)
          error->all(FLERR,"Fix adapt/fep requires atom attribute charge");
      }
    }
  }

  // make copy of original pair array values

  for (int m = 0; m < nadapt; m++) {
    Adapt *ad = &adapt[m];
    if (ad->which == PAIR && ad->pdim == 2) {
      for (i = ad->ilo; i <= ad->ihi; i++)
        for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
          ad->array_orig[i][j] = ad->array[i][j];
    }
  }

#ifdef ADAPT_DEBUG
  if (comm->me == 0 && screen) {
    for (int m = 0; m < nadapt; m++) {
      Adapt *ad = &adapt[m];
      if (ad->which == PAIR && ad->pdim == 2) {
        fprintf(screen, "###ADAPT original %s %s\n", ad->pstyle, ad->pparam);
        fprintf(screen, "###ADAPT  I  J   old_param\n");
        for (i = ad->ilo; i <= ad->ihi; i++)
          for (j = MAX(ad->jlo,i); j <= ad->jhi; j++)
            fprintf(screen, "###ADAPT %2d %2d %9.5f\n", i, j,
                    ad->array_orig[i][j]);
      }
    }
  }
#endif

}