예제 #1
0
void init_calc_table0()
{
  const int size = g_pot.apot_table.number;

  pot_table_t* calc = &g_pot.calc_pot;
  pot_table_t* opt = &g_pot.opt_pot;

  calc->len =
      size * APOT_STEPS + 2 * opt->ncols + g_param.ntypes + g_param.compnodes;
  calc->idxlen = APOT_STEPS;
  calc->ncols = opt->ncols;
  calc->begin = opt->begin;
  calc->end = opt->end;
  calc->first = (int*)Malloc(size * sizeof(int));
  calc->last = (int*)Malloc(size * sizeof(int));
  calc->step = (double*)Malloc(size * sizeof(double));
  calc->invstep = (double*)Malloc(size * sizeof(double));
  calc->xcoord = (double*)Malloc(calc->len * sizeof(double));
  calc->table = (double*)Malloc(calc->len * sizeof(double));
  calc->d2tab = (double*)Malloc(calc->len * sizeof(double));
  calc->idx = (int*)Malloc(calc->len * sizeof(int));

  double f = 0;
  int x = 0;

  /* initialize the g_pot.calc_pot table */
  for (int i = 0; i < size; i++) {
    double* val = g_pot.apot_table.values[i];
    double h = g_pot.apot_table.values[i][g_pot.apot_table.n_par[i] - 1];
    calc->table[i * APOT_STEPS + i * 2] = 10e30;
    calc->table[i * APOT_STEPS + i * 2 + 1] = 0;
    calc->first[i] = (x += 2);
    calc->last[i] = (x += APOT_STEPS - 1);
    x++;
    calc->step[i] = (calc->end[i] - calc->begin[i]) / (APOT_STEPS - 1);
    calc->invstep[i] = 1.0 / calc->step[i];

    for (int j = 0; j < APOT_STEPS; j++) {
      int index = i * APOT_STEPS + (i + 1) * 2 + j;
      calc->xcoord[index] = calc->begin[i] + j * calc->step[i];

      g_pot.apot_table.fvalue[i](calc->xcoord[index], val, &f);
      calc->table[index] =
          g_pot.smooth_pot[i]
              ? f * apot_cutoff(calc->xcoord[index], calc->begin[i], h)
              : f;
      calc->idx[i * APOT_STEPS + j] = index;
    }
  }
}
예제 #2
0
void write_plotpot_pair(pot_table_t* pt, const char* filename)
{
  double r = 0.0;
  double r_step = 0.0;

  // open file
  FILE* outfile = fopen(filename, "w");
  if (outfile == NULL)
    error(1, "Could not open file %s for writing\n", filename);

#if !defined(APOT)
  int k = 0;

  // write pair data
  for (int i = 0; i < g_param.ntypes; i++) {
    for (int j = i; j < g_param.ntypes; j++) {
      r = pt->begin[k];
      r_step = (pt->end[k] - r) / (NPLOT - 1);
      for (int l = 0; l < NPLOT - 1; l++) {
        fprintf(outfile, "%e %e\n", r, splint_ne(pt, pt->table, k, r));
        r += r_step;
      }
      fprintf(outfile, "%e %e\n\n\n", r, 0.0);
      k++;
    }
  }

#if defined(EAM) || defined(ADP) || defined(MEAM)
  for (int i = g_calc.paircol; i < g_calc.paircol + g_param.ntypes; i++) {
    r = pt->begin[i];
    r_step = (pt->end[i] - pt->begin[i]) / (NPLOT - 1);
    for (int l = 0; l < NPLOT - 1; l++) {
      fprintf(outfile, "%e %e\n", r, splint_ne(pt, pt->table, i, r));
      r += r_step;
    }
    fprintf(outfile, "%e %e\n\n\n", r, 0.0);
  }
  for (int i = g_calc.paircol + g_param.ntypes;
       i < g_calc.paircol + 2 * g_param.ntypes; i++) {
    r = pt->begin[i];
    r_step = (pt->end[i] - pt->begin[i]) / (NPLOT - 1);
    for (int l = 0; l < NPLOT; l++) {
      fprintf(outfile, "%e %e\n", r, splint_ne(pt, pt->table, i, r));
      r += r_step;
    }
    fprintf(outfile, "\n\n\n");
  }
#endif  // EAM || ADP || MEAM

#if defined(MEAM)
  for (int i = g_calc.paircol; i < g_calc.paircol + g_param.ntypes; i++) {
    r = pt->begin[i];
    r_step = (pt->end[i] - pt->begin[i]) / (NPLOT - 1);
    for (int l = 0; l < NPLOT - 1; l++) {
      fprintf(outfile, "%e %e\n", r, splint_ne(pt, pt->table, i, r));
      r += r_step;
    }
    fprintf(outfile, "%e %e\n\n\n", r, 0.0);
  }
  for (int i = g_calc.paircol + g_param.ntypes;
       i < g_calc.paircol + 2 * g_param.ntypes; i++) {
    r = pt->begin[i];
    r_step = (pt->end[i] - pt->begin[i]) / (NPLOT - 1);
    for (int l = 0; l < NPLOT; l++) {
      fprintf(outfile, "%e %e\n", r, splint_ne(pt, pt->table, i, r));
      r += r_step;
    }
    fprintf(outfile, "\n\n\n");
  }
  for (int i = g_calc.paircol + 2 * g_param.ntypes;
       i < 2 * g_calc.paircol + 2 * g_param.ntypes; i++) {
    r = pt->begin[i];
    r_step = (pt->end[i] - pt->begin[i]) / (NPLOT - 1);
    for (int l = 0; l < NPLOT - 1; l++) {
      fprintf(outfile, "%e %e\n", r, splint_ne(pt, pt->table, i, r));
      r += r_step;
    }
    fprintf(outfile, "%e %e\n\n\n", r, 0.0);
  }
  for (int i = 2 * g_calc.paircol + 2 * g_param.ntypes;
       i < 2 * g_calc.paircol + 3 * g_param.ntypes; i++) {
    r = pt->begin[i];
    r_step = (pt->end[i] - pt->begin[i]) / (NPLOT - 1);
    for (int l = 0; l < NPLOT - 1; l++) {
      fprintf(outfile, "%e %e\n", r, splint_ne(pt, pt->table, i, r));
      r += r_step;
    }
    fprintf(outfile, "%e %e\n\n\n", r, 0.0);
  }
#endif  // MEAM

#if defined(ADP)
  for (int i = g_calc.paircol + 2 * g_param.ntypes;
       i < 2 * (g_calc.paircol + g_param.ntypes); i++) {
    r = pt->begin[i];
    r_step = (pt->end[i] - r) / (NPLOT - 1);
    for (int l = 0; l < NPLOT - 1; l++) {
      fprintf(outfile, "%e %e\n", r, splint_ne(pt, pt->table, i, r));
      r += r_step;
    }
    fprintf(outfile, "%e %e\n\n\n", r, 0.0);
  }
  for (int i = 2 * (g_calc.paircol + g_param.ntypes);
       i < 3 * g_calc.paircol + 2 * g_param.ntypes; i++) {
    r = pt->begin[i];
    r_step = (pt->end[i] - r) / (NPLOT - 1);
    for (int l = 0; l < NPLOT - 1; l++) {
      fprintf(outfile, "%e %e\n", r, splint_ne(pt, pt->table, i, r));
      r += r_step;
    }
    fprintf(outfile, "%e %e\n\n\n", r, 0.0);
  }
#endif  // ADP

#else   // APOT

  for (int i = 0; i < g_pot.apot_table.number; i++) {
    r = (g_param.plotmin == 0 ? 0.1 : g_param.plotmin);
    r_step = (g_pot.apot_table.end[i] - r) / (NPLOT - 1);
    double h = g_pot.apot_table.values[i][g_pot.apot_table.n_par[i] - 1];
    for (int j = 0; j < NPLOT; j++) {
      double temp = 0.0;

      (*g_pot.apot_table.fvalue[i])(r, g_pot.apot_table.values[i], &temp);

      if (g_pot.smooth_pot[i])
        temp *= apot_cutoff(r, g_pot.apot_table.end[i], h);

      if (isnan(temp))
        temp = 10e30;

      fprintf(outfile, "%e %e\n", r, temp);
      r += r_step;
    }
    if (i != (g_pot.apot_table.number - 1))
      fprintf(outfile, "\n\n");
  }
#endif  // APOT

  fclose(outfile);
  printf("Potential plotting data written to \t%s\n", filename);
}