scalar cnoidalFirst::ddxPd ( const point & x, const scalar & time, const vector & unitVector ) const { scalar Z(returnZ(x)); scalar arg(argument(x,time)); scalar snn(0.0), cnn(0.0), dnn(0.0); gsl_sf_elljac_e( arg, m_, &snn, &cnn, &dnn); scalar ddxPd(0); ddxPd = rhoWater_ * Foam::mag(g_) * ( eta_x(snn, cnn, dnn) + 1.0 / 2.0 * Foam::pow(h_, 2.0) * (1 - Foam::pow((Z + h_) / h_, 2.0)) * eta_xxx(snn, cnn, dnn) ); ddxPd *= factor(time); // Info << "ddxPd still isn't implemented. Need to think about the gradient on arbitrary directed mesh with arbitrary wave number vector! and arbitrary g-direction!!!" << endl; return ddxPd; }
static VALUE rb_gsl_sf_elljac_e(VALUE obj, VALUE n, VALUE m) { double sn, cn, dn; // local variable "status" declared and set, but never used //int status; Need_Float(n); Need_Float(m); /*status =*/ gsl_sf_elljac_e(NUM2DBL(n), NUM2DBL(m), &sn, &cn, &dn); return rb_ary_new3(3, rb_float_new(sn), rb_float_new(cn), rb_float_new(dn)); }
/// Jacobian elliptic integrals dn. double jacobi_dn(double k, double u) { double m = k * k; double sn, cn, dn; int stat = gsl_sf_elljac_e(u, m, &sn, &cn, &dn); if (stat != GSL_SUCCESS) { std::ostringstream msg("Error in jacobi_dn:"); msg << " u=" << u << " k=" << k; throw std::runtime_error(msg.str()); } else return dn; }
scalar cnoidalFirst::eta ( const point & x, const scalar & time ) const { scalar arg(argument(x,time)); scalar snn(0.0), cnn(0.0), dnn(0.0); gsl_sf_elljac_e( arg, m_, &snn, &cnn, &dnn); scalar eta = ( etaMin_ + H_ * Foam::pow(cnn,2.0) ) * factor(time) + seaLevel_; return eta; }
const vector<double> getOmega(int Ns,double lambda_min,double lambda_max){ double u, m; double sn, cn, dn; double kprime = sqrt(1.0-(lambda_min/lambda_max)*(lambda_min/lambda_max)); vector<double> omegas(Ns); for(int ii=0; ii<Ns; ++ii){ int is = 2*ii + 1; m = kprime*kprime; double vs = set_vs( is, Ns*2, kprime ); gsl_sf_elljac_e( vs, m, &sn, &cn, &dn ); double sn2 = sn * sn; double kappaprime2 = kprime * kprime; omegas[ii] = (1.0/lambda_min)* sqrt(1.0-kappaprime2*sn2); } #if VERBOSITY>2 for( int ii=0; ii<Ns; ++ii) printf("%24.16E\n", omegas[ii] ); #endif return omegas; }
vector cnoidalFirst::U ( const point & x, const scalar & time ) const { scalar Z(returnZ(x)); scalar arg(argument(x, time)); scalar snn(0.0), cnn(0.0), dnn(0.0); gsl_sf_elljac_e( arg, m_, &snn, &cnn, &dnn); scalar etaVal = eta(x,time); scalar Uhorz = celerity_ * ( etaVal / h_ - Foam::pow(etaVal / h_, 2.0) + 1.0 / 2.0 * ( 1.0 / 3.0 - Foam::pow((Z + h_) / h_, 2.0) ) * h_ * eta_xx(snn, cnn, dnn) ); Uhorz *= factor(time); scalar Uvert = - celerity_ * (Z + h_) * ( eta_x(snn, cnn, dnn) / h_ * (1 - 2.0 * etaVal / h_) + 1.0 / 6.0 * h_ * eta_xxx(snn, cnn, dnn) * (1 - Foam::pow((Z + h_) / h_, 2.0)) ); Uvert *= factor(time); return Uhorz * propagationDirection_ - Uvert * direction_; // Note "-" because of "g" working in the opposite direction }
int main() { #include "jacobi_elliptic.ipp" #include "jacobi_elliptic_small.ipp" #include "jacobi_near_1.ipp" #include "jacobi_large_phi.ipp" add_data(data1); add_data(jacobi_elliptic); add_data(jacobi_elliptic_small); add_data(jacobi_near_1); add_data(jacobi_large_phi); unsigned data_total = data.size(); std::cout << "Screening Boost data:\n"; screen_data([](const std::vector<double>& v) { return boost::math::jacobi_dn(v[1], v[0]); }, [](const std::vector<double>& v) { return v[4]; }); #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) std::cout << "Screening GSL data:\n"; screen_data([](const std::vector<double>& v) { double s, c, d; gsl_sf_elljac_e(v[0], v[1] * v[1], &s, &c, &d); return d; }, [](const std::vector<double>& v) { return v[4]; }); #endif unsigned data_used = data.size(); std::string function = "jacobi_dn[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)"; std::string function_short = "jacobi_dn"; double time; time = exec_timed_test([](const std::vector<double>& v) { return boost::math::jacobi_dn(v[1], v[2]); }); std::cout << time << std::endl; #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH)) 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::jacobi_dn(v[1], 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)) 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_GSL) && !defined(COMPILER_COMPARISON_TABLES) time = exec_timed_test([](const std::vector<double>& v) { double s, c, d; gsl_sf_elljac_e(v[0], v[1] * v[1], &s, &c, &d); return d; }); 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; }