示例#1
0
Vector<double> BoundingLayer::calculate_second_derivative(const Vector<double>& inputs) const
{
   std::ostringstream buffer;

   const size_t bounding_neurons_number = get_bounding_neurons_number();

   const Vector<double> outputs = calculate_outputs(inputs);

   for(size_t i = 0; i < bounding_neurons_number; i++)
   {
      if(outputs[i] == lower_bounds[i])
      {
         buffer << "OpenNN Exception: BoundingLayer class.\n"
                << "Vector<double> calculate_outputs(const Vector<double>&) const method.\n"
                << "Output is equal to lower bound. The bounding function is not differentiable at this point.\n";

	     throw std::logic_error(buffer.str());
      }
      else if(outputs[i] == upper_bounds[i])
      {
         buffer << "OpenNN Exception: BoundingLayer class.\n"
                << "Vector<double> calculate_outputs(const Vector<double>&) const method.\n"
                << "Output is equal to upper bound. The bounding function is not differentiable at this point.\n";

	     throw std::logic_error(buffer.str());
      }
   }

   Vector<double> second_derivative(bounding_neurons_number, 0.0);

   return(second_derivative);
}
示例#2
0
/*!
 * Off-site contribution to the force constant matrix, i.e. the
 * 3*n_atoms x 3*n_atoms matrix D_ij for i != j.
 */
void FCLJCut::offsite(const CrystalSurface *surf,
                      const CrystalSurface::lattice_neighbor_t *pair,
                      int ab, double *_D, Error *error)
{
    int itype = surf->get_type(pair->indexi);
    int jtype = surf->get_type(pair->indexj);

    vec<double, 3> e(pair->r);
    e /= e.nrm2();

    mat<double> D(3, _D);
    outer(e, e, D);

    mat<double> perp = identity<double>(3) - D;

    double k = second_derivative(itype, jtype, pair->rnorm);
    double kappa = first_derivative(itype, jtype, pair->rnorm)/pair->rnorm;

    D *= -k;
    perp *= kappa;

    D -= perp;
}
示例#3
0
/*!
 * Dump generic text info to file
 */
void FCLJCut::dump_info(FILE *f, CrystalSurface *surf, Error *error)
{
    ForceConstants::dump_info(f, surf, error);

    int nat = surf->get_number_of_atoms();

    fprintf(f, "Force constants for each neighbor shell:\n");
    for (int i = 0; i < nat; i++) {
        int itype = surf->get_type(i);
        fprintf(f, "Atom %i, k (kappa) = ", i);
        for (int j = 0; j < 10; j++) {
            const CrystalSurface::lattice_neighbor_t *neigh = 
                surf->get_neighbors(i);
            int nneigh = surf->get_number_of_neighbors(i);
            int n = 0;
            while (n < nneigh && neigh->neighbor_shell != j) {
                n++;
                neigh++;
            }
            if (n < nneigh) {
                int jtype = surf->get_type(neigh->indexj);
                fprintf(f, "%f (%f) ",
                        second_derivative(itype, jtype, neigh->rnorm),
                        first_derivative(itype, jtype, neigh->rnorm)/
                        neigh->rnorm);
            }
        }
        fprintf(f, "\n");
    }

    double linf[nat];
    linear(surf, linf, error);

    fprintf(f, "Linear forces on each atom = ");
    for (int i = 0; i < nat; i++)  fprintf(f, "%f ", linf[i]);
    fprintf(f, "\n");
}