Пример #1
0
int tester()
{
  std::vector<Scalar> bin_ref_x,bin_ref_y;

  make_reference(bin_ref_x,bin_ref_y);

  Antioch::SigmaBinConverter<std::vector<Scalar> > bin;

  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 10;

  int return_flag = 0;

  // 4 cases:
  //   - custom inside ref
  //   - ref inside custom
  //   - custom beyond only min ref
  //   - custom beyond only max ref
  for(unsigned int i = 0; i < 4; i++)
  {
    std::vector<Scalar> bin_custom_x, exact_sol_y;
    make_custom(i,bin_custom_x,exact_sol_y);
    std::vector<Scalar> bin_custom_y(bin_custom_x.size());

    bin.y_on_custom_grid(bin_ref_x,bin_ref_y,
                         bin_custom_x,bin_custom_y);


    for(unsigned int il = 0; il < bin_custom_x.size() - 1; il++)
    {
      const Scalar dist = (exact_sol_y[il] < tol)?std::abs(bin_custom_y[il] - exact_sol_y[il]):std::abs(bin_custom_y[il] - exact_sol_y[il])/exact_sol_y[il];
      if( dist > tol )
      {
        std::cout << std::scientific << std::setprecision(16)
                  << "Error: Mismatch in bin values."                                                  << std::endl
                  << "case ("            << bin_custom_x[il]   << ";"   << bin_custom_x[il+1]   << ")" << std::endl 
                  << "bin = "            << bin_custom_y[il]                                           << std::endl
                  << "bin_exact = "      << exact_sol_y[il]                                            << std::endl
                  << "relative error = " << dist                                                       << std::endl
                  << "tolerance = "      << tol                                                        << std::endl;

        return_flag = 1;
      }
    }
  }

  return return_flag;
}
int vectester(const PairScalars& example, const std::string& testname)
{
  typedef typename Antioch::value_type<PairScalars>::type Scalar;

  std::vector<Scalar> bin_ref_x,bin_ref_y;

  make_reference(bin_ref_x,bin_ref_y);

  Antioch::SigmaBinConverter<std::vector<Scalar> > bin;

  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 10;

  int return_flag = 0;

#ifdef ANTIOCH_HAVE_GRVY
  gt.BeginTimer(testname);
#endif

  // 2 * 2  cases:
  //   - custom inside ref, ref inside custom
  //   - custom beyond only min ref, custom beyond only max ref
  for(unsigned int i = 0; i < 2; i++)
  {
    std::vector<PairScalars> bin_custom_x, exact_sol_y;
    make_custom(i,example,bin_custom_x,exact_sol_y);
    std::vector<PairScalars> bin_custom_y(bin_custom_x.size(),Antioch::zero_clone(bin_custom_x[0]));

    bin.y_on_custom_grid(bin_ref_x,bin_ref_y,
                         bin_custom_x,bin_custom_y);


    for(unsigned int il = 0; il < bin_custom_x.size() - 1; il++)
    {
      for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
      {
//tuple

        Scalar dist = Antioch::if_else(exact_sol_y[il][2*tuple] < tol,
                                                std::abs(bin_custom_y[il][2*tuple] - exact_sol_y[il][2*tuple]),
                                                std::abs(bin_custom_y[il][2*tuple] - exact_sol_y[il][2*tuple])/exact_sol_y[il][2*tuple]);
        if( dist > tol )
        {
         std::cout << std::scientific << std::setprecision(16)
                   << "Error: Mismatch in bin values for " << testname                                                      << std::endl
                   << "case ("            << bin_custom_x[il][2*tuple]   << ";"   << bin_custom_x[il + 1][2*tuple]   << ")" << std::endl 
                   << "bin = "            << bin_custom_y[il][2*tuple]                                                      << std::endl
                   << "bin_exact = "      << exact_sol_y[il][2*tuple]                                                       << std::endl
                   << "relative error = " << dist                                                                           << std::endl
                   << "tolerance = "      << tol                                                                            << std::endl;

         return_flag = 1;
        }

//tuple + 1
        dist = Antioch::if_else(exact_sol_y[il][2*tuple + 1] < tol,
                                                std::abs(bin_custom_y[il][2*tuple + 1] - exact_sol_y[il][2*tuple + 1]),
                                                std::abs(bin_custom_y[il][2*tuple + 1] - exact_sol_y[il][2*tuple + 1])/exact_sol_y[il][2*tuple + 1]);
        if( dist > tol )
        {
         std::cout << std::scientific << std::setprecision(16)
                   << "Error: Mismatch in bin values for " << testname                                                      << std::endl
                   << "case ("            << bin_custom_x[il][2*tuple + 1]   << ";"   << bin_custom_x[il+1][2*tuple + 1]   << ")" << std::endl 
                   << "bin = "            << bin_custom_y[il][2*tuple + 1]                                                        << std::endl
                   << "bin_exact = "      << exact_sol_y[il][2*tuple + 1]                                                         << std::endl
                   << "relative error = " << dist                                                                                 << std::endl
                   << "tolerance = "      << tol                                                                                  << std::endl;

         return_flag = 1;
        }


      }
    }
  }

#ifdef ANTIOCH_HAVE_GRVY
  gt.EndTimer(testname);
#endif

  return return_flag;
}