<commit_before>/**
 * \file generateQuadratureGaussKronrod.cpp
 * This file will generate a replacement for the file GaussKronrodNodesWeights.h 
 * at the level of precision specified by the user.
 */

#include <NumericalIntegration.h>

#include <iostream>
#include <fstream>
#include <iomanip>

int test_values()
{
    /** 
     * \details The level of precision in the calculations requires greater precision
     *          than the number of the digits written to file to avoid roundoff errors.
     */

    // Set the number of output digits
    int outputDigits = 50;
    
    // Set this flag to 0 for LaurieGautschi Polity, 1 for PiessensPolicy, or 2 for Monegato Policy;
    int solverPolicy = 2;

    typedef mpfr::mpreal Scalar;
    // IMPORTANT - 4X of the output digits must be used for calculations to calculate nodes/weights accurately.
    Scalar::set_default_prec(outputDigits*4);
    
    typedef Eigen::QuadratureKronrod<Scalar> QuadratureKronrodValuesType;

    QuadratureKronrodValuesType::computeNodesAndWeights();

    std::ofstream fout;
    std::string fileNameAndLocation = "test/testOutput/GaussKronrodNodesWeights.h";
    fout.open(fileNameAndLocation);
    fout<<std::fixed<<std::setprecision(outputDigits);

    int gaussRule[12] = {7, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 100};
    int kronrodRule[12] = {15, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 201};

    std::string gaussKronrodAbscissaeNames[12];
    std::string gaussKronrodWeightsNames[12];
    std::string gaussAbscissaeNames[12];
    std::string gaussWeightsNames[12];

    for (size_t i=0; i<12; ++i)
    {
        char ruleStr[5];
        sprintf(ruleStr, "%d", kronrodRule[i]);
        gaussKronrodAbscissaeNames[i] = "abscissaeGaussKronrod";
        gaussKronrodAbscissaeNames[i] += ruleStr;
        
        gaussKronrodWeightsNames[i] = "weightsGaussKronrod";
        gaussKronrodWeightsNames[i] +=ruleStr;
        
        gaussAbscissaeNames[i] = "abscissaeGauss";
        gaussAbscissaeNames[i] += ruleStr;

        gaussWeightsNames[i] = "weightsGauss";
        gaussWeightsNames[i] += ruleStr;
    }

//----------------------------------Begin File Header Information--------------------------------//

    fout << "/**\n * \\file QuadratureKronrod.h\n"
         << " * \\sa <NAME>, <NAME>, <NAME>, <NAME>, QUADPACK, A Subroutine Package\n"
         << " *     for Automatic Integration, Springer Verlag, 1983.\n"
         << " */\n\n#ifndef EIGEN_QUADRATURE_KRONROD_H\n#define EIGEN_QUADRATURE_KRONROD_H\n\n"
         << "namespace Eigen\n{\n\n/**\n * \\brief The abscissae and weights are given for the interval (-1,1).\n"
         << " *        Because of symmetry, only the positive abscissae and their\n"
         << " *        corresponding weights are given.\n *\n";

    for (size_t i=0; i<12; ++i)
    {
        // " * \\param abscissaeGaussKronrodXX  The abscissae of the X point kronrod rule."
        fout << " * \\param abscissaeGaussKronrod" << kronrodRule[i] << "  The abscissae of the " << kronrodRule[i] << " point kronrod rule.\n";
    }
    fout << " *\n";

    for (size_t i=0; i<12; ++i)
    {
        // " * \\param weightsGaussKronrodXX  The weights of the X point kronrod rule."
        fout << " * \\param weightsGaussKronrod" << kronrodRule[i] << "  The weights of the " << kronrodRule[i] << " point kronrod rule.\n";
    }
    fout << " *\n";

    for (size_t i=0; i<12; ++i)
    {
        // " * \\param abscissaeGaussXX  The abscissae of the X point gauss rule."
        fout << " * \\param abscissaeGauss" << kronrodRule[i] << "  The abscissae of the " << gaussRule[i] << " point gauss rule.\n";
    }
    fout << " *\n";

    for (size_t i=0; i<12; ++i)
    {
        // " * \\param weightsGaussXX  The weights of the X point gauss rule."
        fout << " * \\param weightsGauss" << kronrodRule[i] << "  The weights of the " << gaussRule[i] << " point gauss rule.\n";
    }

    fout << " */\n\ntemplate <typename Scalar>\nclass QuadratureKronrod\n{\npublic:\n";
    
    for (size_t i=0; i<12; ++i)
    {
        fout << "\tstatic Array<Scalar, " << kronrodRule[i]/2 + 1 << ", 1> " << gaussKronrodAbscissaeNames[i] << ";\n"
             << "\tstatic Array<Scalar, " << kronrodRule[i]/2 + 1 << ", 1> " << gaussKronrodWeightsNames[i] << ";\n"
             << "\tstatic Array<Scalar, " << (gaussRule[i]+1)/2 << ", 1> " << gaussAbscissaeNames[i] << ";\n"
             << "\tstatic Array<Scalar, " << (gaussRule[i]+1)/2 << ", 1> " << gaussWeightsNames[i] << ";\n\n";
    }

    fout << "\ttypedef Kronrod::LaurieGautschi<Scalar> LaurieGautschiPolicy;\n"
         << "\ttypedef typename LaurieGautschiPolicy::VectorType VectorType;\n"
         << "\ttypedef typename MonegatoPolicy::VectorType VectorType;\n"
         << "\ttypedef Kronrod::Piessens<Scalar> PiessensPolicy;\n\n"
         << "\tstatic bool compute;\n\n";


    fout << "\tstatic void computeNodesAndWeights()\n\t{\n\t\tif(compute)\n\t\t{\n";
    for (size_t i=0; i<12; ++i)
    {
        fout << "\t\t\tQuadratureKronrod::computeForRule<" << gaussRule[i] << ">(" 
             << gaussKronrodAbscissaeNames[i] << ", " << gaussKronrodWeightsNames[i] << ", "<commit_msg>Correct a copy/paste error.  All policies are functioning well.<commit_after>/**
 * \file generateQuadratureGaussKronrod.cpp
 * This file will generate a replacement for the file GaussKronrodNodesWeights.h 
 * at the level of precision specified by the user.
 */

#include <NumericalIntegration.h>

#include <iostream>
#include <fstream>
#include <iomanip>

int test_values()
{
    /** 
     * \details The level of precision in the calculations requires greater precision
     *          than the number of the digits written to file to avoid roundoff errors.
     */

    // Set the number of output digits
    int outputDigits = 50;
    
    // Set this flag to 0 for LaurieGautschi Polity, 1 for PiessensPolicy, or 2 for Monegato Policy;
    int solverPolicy = 2;

    typedef mpfr::mpreal Scalar;
    // IMPORTANT - 4X of the output digits must be used for calculations to calculate nodes/weights accurately.
    Scalar::set_default_prec(outputDigits*4);
    
    typedef Eigen::QuadratureKronrod<Scalar> QuadratureKronrodValuesType;

    QuadratureKronrodValuesType::computeNodesAndWeights();

    std::ofstream fout;
    std::string fileNameAndLocation = "test/testOutput/GaussKronrodNodesWeights.h";
    fout.open(fileNameAndLocation);
    fout<<std::fixed<<std::setprecision(outputDigits);

    int gaussRule[12] = {7, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 100};
    int kronrodRule[12] = {15, 21, 31, 41, 51, 61, 71, 81, 91, 101, 121, 201};

    std::string gaussKronrodAbscissaeNames[12];
    std::string gaussKronrodWeightsNames[12];
    std::string gaussAbscissaeNames[12];
    std::string gaussWeightsNames[12];

    for (size_t i=0; i<12; ++i)
    {
        char ruleStr[5];
        sprintf(ruleStr, "%d", kronrodRule[i]);
        gaussKronrodAbscissaeNames[i] = "abscissaeGaussKronrod";
        gaussKronrodAbscissaeNames[i] += ruleStr;
        
        gaussKronrodWeightsNames[i] = "weightsGaussKronrod";
        gaussKronrodWeightsNames[i] +=ruleStr;
        
        gaussAbscissaeNames[i] = "abscissaeGauss";
        gaussAbscissaeNames[i] += ruleStr;

        gaussWeightsNames[i] = "weightsGauss";
        gaussWeightsNames[i] += ruleStr;
    }

//----------------------------------Begin File Header Information--------------------------------//

    fout << "/**\n * \\file QuadratureKronrod.h\n"
         << " * \\sa <NAME>, <NAME>, <NAME>, <NAME>, QUADPACK, A Subroutine Package\n"
         << " *     for Automatic Integration, <NAME>, 1983.\n"
         << " */\n\n#ifndef EIGEN_QUADRATURE_KRONROD_H\n#define EIGEN_QUADRATURE_KRONROD_H\n\n"
         << "namespace Eigen\n{\n\n/**\n * \\brief The abscissae and weights are given for the interval (-1,1).\n"
         << " *        Because of symmetry, only the positive abscissae and their\n"
         << " *        corresponding weights are given.\n *\n";

    for (size_t i=0; i<12; ++i)
    {
        // " * \\param abscissaeGaussKronrodXX  The abscissae of the X point kronrod rule."
        fout << " * \\param abscissaeGaussKronrod" << kronrodRule[i] << "  The abscissae of the " << kronrodRule[i] << " point kronrod rule.\n";
    }
    fout << " *\n";

    for (size_t i=0; i<12; ++i)
    {
        // " * \\param weightsGaussKronrodXX  The weights of the X point kronrod rule."
        fout << " * \\param weightsGaussKronrod" << kronrodRule[i] << "  The weights of the " << kronrodRule[i] << " point kronrod rule.\n";
    }
    fout << " *\n";

    for (size_t i=0; i<12; ++i)
    {
        // " * \\param abscissaeGaussXX  The abscissae of the X point gauss rule."
        fout << " * \\param abscissaeGauss" << kronrodRule[i] << "  The abscissae of the " << gaussRule[i] << " point gauss rule.\n";
    }
    fout << " *\n";

    for (size_t i=0; i<12; ++i)
    {
        // " * \\param weightsGaussXX  The weights of the X point gauss rule."
        fout << " * \\param weightsGauss" << kronrodRule[i] << "  The weights of the " << gaussRule[i] << " point gauss rule.\n";
    }

    fout << " */\n\ntemplate <typename Scalar>\nclass QuadratureKronrod\n{\npublic:\n";
    
    for (size_t i=0; i<12; ++i)
    {
        fout << "\tstatic Array<Scalar, " << kronrodRule[i]/2 + 1 << ", 1> " << gaussKronrodAbscissaeNames[i] << ";\n"
             << "\tstatic Array<Scalar, " << kronrodRule[i]/2 + 1 << ", 1> " << gaussKronrodWeightsNames[i] << ";\n"
             << "\tstatic Array<Scalar, " << (gaussRule[i]+1)/2 << ", 1> " << gaussAbscissaeNames[i] << ";\n"
             << "\tstatic Array<Scalar, " << (gaussRule[i]+1)/2 << ", 1> " << gaussWeightsNames[i] << ";\n\n";
    }

    fout << "\ttypedef Kronrod::LaurieGautschi<Scalar> LaurieGautschiPolicy;\n"
         << "\ttypedef Kronrod::Monegato<Scalar> MonegatoPolicy;\n"
         << "\ttypedef Kronrod::Piessens<Scalar> PiessensPolicy;\n\n"
         << "\ttypedef typename LaurieGautschiPolicy::VectorType VectorType;\n\n"
         << "\tstatic bool compute;\n\n";

    fout << "\tstatic void computeNodesAndWeights()\n\t{\n\t\tif(compute)\n\t\t{\n";
    for (size_t i=0; i<12; ++i)
    {
        fout << "\t\t\tQuadratureKronrod::computeForRule<" << gaussRule[i] << ">(" 
             << gaussKronrodAbscissaeNames[i] << ", " << gaussKronrodWeightsNames[i] << ", "
{'fraction_non_alphanumeric': 0.16486694947936753, 'fraction_numerical': 0.021403779406093327, 'mean_word_length': 2.7192542129795627, 'pattern_counts': {'":': 0, '<': 317, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5700991', 'n_tokens_mistral': 3909, 'n_tokens_neox': 3649, 'n_words': 830}