Пример #1
0
int main()
{
#include "ellint_e_data.ipp"

   add_data(data2);
   add_data(ellint_e_data);

   unsigned data_total = data.size();

   screen_data([](const std::vector<double>& v){  return boost::math::ellint_2(v[0]);  }, [](const std::vector<double>& v){ return v[1];  });


#if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
   screen_data([](const std::vector<double>& v){  return std::tr1::comp_ellint_2(v[0]);  }, [](const std::vector<double>& v){ return v[1];  });
#endif
#if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
   screen_data([](const std::vector<double>& v){  return gsl_sf_ellint_Ecomp(v[0], GSL_PREC_DOUBLE);  }, [](const std::vector<double>& v){ return v[1];  });
#endif

   unsigned data_used = data.size();
   std::string function = "ellint_2 (complete)[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)";
   std::string function_short = "ellint_2 (complete)";

   double time;

   time = exec_timed_test([](const std::vector<double>& v){  return boost::math::ellint_2(v[0]);  });
   std::cout << time << std::endl;
#if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
   report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
#endif
   report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
   //
   // Boost again, but with promotion to long double turned off:
   //
#if !defined(COMPILER_COMPARISON_TABLES)
   if(sizeof(long double) != sizeof(double))
   {
      time = exec_timed_test([](const std::vector<double>& v){  return boost::math::ellint_2(v[0], boost::math::policies::make_policy(boost::math::policies::promote_double<false>()));  });
      std::cout << time << std::endl;
#if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
      report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name() + "[br]promote_double<false>");
#endif
      report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>");
   }
#endif


#if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
   time = exec_timed_test([](const std::vector<double>& v){  return std::tr1::comp_ellint_2(v[0]);  });
   std::cout << time << std::endl;
   report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath");
#endif
#if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
   time = exec_timed_test([](const std::vector<double>& v){  return gsl_sf_ellint_Ecomp(v[0], GSL_PREC_DOUBLE);  });
   std::cout << time << std::endl;
   report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION);
#endif

   return 0;
}
Пример #2
0
cnoidalFirst::cnoidalFirst
(
    const word & subDictName,
	const fvMesh & mesh_
)
:
    waveTheory(subDictName, mesh_),
    H_(readScalar(coeffDict_.lookup("height"))),
    h_(readScalar(coeffDict_.lookup("depth"))),
    omega_(readScalar(coeffDict_.lookup("omega"))),

    propagationDirection_(vector(coeffDict_.lookup("direction"))),
    m_(readScalar(coeffDict_.lookup("m"))),
    length_(readScalar(coeffDict_.lookup("length"))),
    celerity_(readScalar(coeffDict_.lookup("celerity")))
{   
    scalar Eelliptic = gsl_sf_ellint_Ecomp( Foam::sqrt(m_), GSL_PREC_DOUBLE);

    period_    = 2.0 * PI_ / omega_;

    Kelliptic_ = gsl_sf_ellint_Kcomp( Foam::sqrt(m_), GSL_PREC_DOUBLE);
    etaMin_    = ((1.0 - Eelliptic / Kelliptic_) / m_ - 1.0) * H_;

    propagationDirection_ /= Foam::mag(propagationDirection_);
    
    Tsoft_ = coeffDict_.lookupOrDefault<scalar>("Tsoft",period_);
}
void cnoidalFirstProperties::set( Ostream& os)
{
    scalar m = solve();

    // Write the beginning of the sub-dictionary
    writeBeginning( os );

    // Write the already given parameters
    writeGiven( os, "waveType" );

    if (dict_.found( "Tsoft" ))
    {
        writeGiven( os, "Tsoft");
    }

    writeGiven( os, "depth");
    writeGiven( os, "period");
    writeGiven( os, "height");

    if (m < 0.0)
    {
        Info << "\nPARAMETERS NOT SET\nNo cnoidal wave solution"
             << " exists for given input\n" << endl;
    }
    else
    {
        double K = gsl_sf_ellint_Kcomp( Foam::sqrt(m), GSL_PREC_DOUBLE );
        double E = gsl_sf_ellint_Ecomp( Foam::sqrt(m), GSL_PREC_DOUBLE );

        double A = 2.0/m - 1.0 - 3.0/m*E/K;

        double L =
            Foam::sqrt(16.0*m * Foam::pow(K, 2.0)*Foam::pow(d_, 3.0)/(3.0*H_));
        double c = Foam::sqrt( G_*d_*(1 + A*H_/d_));
        double omega = 2*PI_/T_;

        if (write_)
        {
            writeDerived(os, "omega", omega);
            writeDerived(os, "length", L);
            writeDerived(os, "celerity", c);

            // Locally change the write precision for m to avoid it being
            // written as 1 instead of 0.9999999999 which makes elliptic
            // integrals to infinity.
            unsigned int pre = os.precision( 14 );
            writeDerived(os, "m", m);
            os.precision( pre );
        }
    }

    writeGiven( os, "direction" );

    // Write the relaxation zone
    writeRelaxationZone( os );

    // Write the closing bracket
    writeEnding( os );
}
Пример #4
0
double
  ell (double x)
{

  double k = x;
  gsl_mode_t mode = GSL_PREC_DOUBLE;
  double var = (gsl_sf_ellint_Kcomp(k, mode) - gsl_sf_ellint_Ecomp(k, mode));

  return var;
}
double lowerMBound_f ( double m, void *params )
{
    // Solves to find the value of m at which Foam::sqrt(1.0 + H/d*A) == 0.0
    struct cnoidalFirstParams *p = (struct cnoidalFirstParams * ) params;

    double d = p->depth_;
    double H = p->height_;

    double K = gsl_sf_ellint_Kcomp( Foam::sqrt(m), GSL_PREC_DOUBLE );
    double E = gsl_sf_ellint_Ecomp( Foam::sqrt(m), GSL_PREC_DOUBLE );

    double A = 2.0/m - 1.0 - 3.0/m*E/K;

    // The value of 1.0e-8 is added to ensure strictly larger than 0!
    return 1.0 - 1.0e-8 + H/d*A;
}
double cnoidalFirst_f ( double m, void *params)
{
    struct cnoidalFirstParams *p = (struct cnoidalFirstParams * ) params;

    double T = p->period_;
    double d = p->depth_;
    double G = p->g_;
    double H = p->height_;

    double K = gsl_sf_ellint_Kcomp( Foam::sqrt(m), GSL_PREC_DOUBLE );
    double E = gsl_sf_ellint_Ecomp( Foam::sqrt(m), GSL_PREC_DOUBLE );

    double A = 2.0/m - 1.0 - 3.0/m*E/K;

    return T*Foam::sqrt(G/d)*Foam::sqrt(1.0 + H/d*A)
        - Foam::sqrt( 16.0*d/(3.0*H)*m * Foam::pow(K, 2.0) );
}
Пример #7
0
      /**
       * C++ version of gsl_sf_ellint_Ecomp().
       * Legendre form of complete elliptic integrals
       *
       * E(k) = Integral[  Sqrt[1 - k^2 Sin[t]^2], {t, 0, Pi/2}]
       *
       * @param k A real number
       * @param mode The mode
       * @return The function value
       */
      inline double Ecomp( double k, mode_t mode ){
	return gsl_sf_ellint_Ecomp( k, mode ); }