<commit_before>/*!   \file unitTestCoefficientGenerator.cpp
 *    This file contains the unit test of the hypersonic local inclination
 *    analysis.
 *
 *    Path              : /Astrodynamics/ForceModels/Aerothermodynamics/
 *    Version           : 1
 *    Check status      : Checked
 *
 *    Author            : <NAME>
 *    Affiliation       : Delft University of Technology
 *    E-mail address    : <EMAIL>
 *
 *    Checker           : <NAME>
 *    Affiliation       : Delft University of Technology
 *    E-mail address    : <EMAIL>
 *
 *    Date created      : 25 November, 2010
 *    Last modified     : 9 February,  2011
 *
 *    References
 *      <NAME>., <NAME>., and <NAME>. . The Mark IV Supersonic-Hypersonic
 *        Arbitrary Body Program, Volume II - Program Formulation, Douglas Aircraft
 *        Aircraft Company, 1973.
 *
 *    Notes
 *
 *    Copyright (c) 2010 Delft University of Technology.
 *
 *    This software is protected by national and international copyright.
 *    Any unauthorized use, reproduction or modification is unlawful and
 *    will be prosecuted. Commercial and non-private application of the
 *    software in any form is strictly prohibited unless otherwise granted
 *    by the authors.
 *
 *    The code is provided without any warranty; without even the implied
 *    warranty of merchantibility or fitness for a particular purpose.
 *
 *    Changelog
 *      YYMMDD    Author            Comment
 *      102511    <NAME>          First version of file.
 */

// Include statements.
#include "unitTestCoefficientGenerator.h"
#include "writingOutputToFile.h"

bool unit_tests::testCoefficientGenerator( )
{

    // Declare test variable.
    bool isCoefficientGeneratorBad_ = 0;

    // Create test sphere.
    SphereSegment sphere = SphereSegment( );
    sphere.setRadius( 1.0 );
    sphere.setMinimumAzimuthAngle(  0.0 );
    sphere.setMaximumAzimuthAngle( 2.0 * M_PI);
    sphere.setMinimumZenithAngle( 0.0 );
    sphere.setMaximumZenithAngle( M_PI );
    VehicleExternalModel externalModel = VehicleExternalModel();
    externalModel.setVehicleGeometry( sphere );
    Vehicle vehicle = Vehicle();
    vehicle.setExternalModel( externalModel );

    // Create analysis object.
    HypersonicLocalInclinationAnalysis analysis =
            HypersonicLocalInclinationAnalysis( );

    // Set vehicle in analysis with 10,000 panels.
    int* numberOfLines = new int[ 1 ];
    int* numberOfPoints = new int[ 1 ];
    bool* invertOrder = new bool[ 1 ];
    numberOfLines[ 0 ] = 101;
    numberOfPoints[ 0 ] = 101;
    invertOrder[ 0 ] = 0;
    analysis.setVehicle( vehicle, numberOfLines, numberOfPoints, invertOrder );

    // Set reference quantities.
    analysis.setReferenceArea( M_PI );
    analysis.setReferenceLength( 1.0 );
    analysis.setMomentReferencePoint( Vector3d( 0, 0, 0) );

    // Set pure Newtonian compression method for test purposes.
    analysis.setSelectedMethod( 0, 0, 0 );

    // Generate sphere database.
    analysis.generateDatabase( );

    // Allocate memory for independent variables
    // to pass to analysis for retrieval.
    int* independentVariables = new int[ 3 ];
    independentVariables[ 0 ] = 0;
    independentVariables[ 1 ] = 0;
    independentVariables[ 2 ] = 0;

    // Declare local test variables.
    VectorXd aerodynamicCoefficients_;
    double forceCoefficient_;

    // Iterate over all angles of attack to verify sphere coefficients.
    for( int i = 0; i < analysis.getNumberOfMachPoints(); i++ )
    {
        independentVariables[ 0 ] = i;

        for( int j = 0; j < analysis.getNumberOfAngleOfAttackPoints( ); j++ )
        {
            independentVariables[ 1 ] = j;

            for( int k = 0; k < analysis.getNumberOfAngleOfSideslipPoints( ); k++ )
            {
                independentVariables[ 2 ] = k;

                // Retrieve aerodynamic coefficients.
                aerodynamicCoefficients_ = analysis.getAerodynamicCoefficients(
                        independentVariables );
                forceCoefficient_ = sqrt( aerodynamicCoefficients_.x( )
                                        * aerodynamicCoefficients_.x( )
                                        + aerodynamicCoefficients_.y( )
                                        * aerodynamicCoefficients_.y( )
                                        + aerodynamicCoefficients_.z( )
                                        * aerodynamicCoefficients_.z( ) );

                // Check if 'total' aerodynamic coefficient is always
                // sufficiently close to zero.
                if( fabs( forceCoefficient_ - 1.0 ) > 1.0E-3 )
                {
                    std::cout<<"Total magnitude of aerodynamic force wrong in "
                            <<"sphere."<<std::endl;
                    isCoefficientGeneratorBad_ = true;
                }

                // Check if moment coefficients are approximately zero. Deviations
                // for pitch moment are greater due to greater range of angles of
                // attack than sideslip.
                if( fabs( aerodynamicCoefficients_[ 3 ] ) > 1.0E-5 )
                {
                    std::cerr<<" Error, sphere roll moment coefficient not zero. "
                            <<std::endl;
                    isCoefficientGeneratorBad_ = true;
                }
                if( fabs( aerodynamicCoefficients_[ 4 ] ) > 1.0E-3 )
                {
                    std::cerr<<" Error, sphere pitch moment coefficient not zero. "
                            <<std::endl;
                    isCoefficientGeneratorBad_ = true;
                }
                if( fabs( aerodynamicCoefficients_[ 5 ] ) > 1.0E-5 )
                {
                    std::cerr<<" Error, sphere yaw moment coefficient not zero. "
                            <<std::endl;
                    isCoefficientGeneratorBad_ = true;
                }
            }
        }
    }


    // Set Apollo capsule for validation.
    Capsule capsule = Capsule( );
    capsule.setNoseRadius( 4.694 );
    capsule.setMiddleRadius( 1.956 );
    capsule.setRearAngle( -1*33.0 * M_PI / 180.0 );
    capsule.setRearLength( 2.662 );
    capsule.setSideRadius( 0.196 );
    capsule.setCapsule( );
    externalModel.setVehicleGeometry( capsule );
    vehicle.setExternalModel( externalModel );

    // Declare new analysis object
    HypersonicLocalInclinationAnalysis analysis2 =
            HypersonicLocalInclinationAnalysis( );

    int * numberOfLines2 = new int[ 4 ];
    int * numberOfPoints2 = new int[ 4 ];
    bool * invertOrders2 = new bool[ 4 ];

    // Set number of analysis points
    numberOfLines2[ 0 ] = 51;
    numberOfPoints2[ 0 ] = 51;
    numberOfLines2[ 1 ] = 51;
    numberOfPoints2[ 1 ] = 51;
    numberOfLines2[ 2 ] = 51;
    numberOfPoints2[ 2 ] = 2;
    numberOfLines2[ 3 ] = 51;
    numberOfPoints2[ 3 ] = 51;
    invertOrders2[ 0 ] = 1;
    invertOrders2[ 1 ] = 1;
    invertOrders2[ 2 ] = 1;
    invertOrders2[ 3 ] = 1;

    // Set capsule for analysis.
    analysis2.setVehicle( vehicle, numberOfLines2, numberOfPoints2, invertOrders2 );

    // Set reference quantities.
    analysis2.setReferenceArea( M_PI * pow( capsule.getMiddleRadius( ), 2.0 ) );
    analysis2.setReferenceLength( 3.9116 );
    VectorXd momentReference = VectorXd( 3 );
    momentReference( 0 ) = 0.6624;//27.334;
    momentReference( 1 ) = 0;
    momentReference( 2 ) = 0.1369;//9.398;
    analysis2.setMomentReferencePoint( momentReference );

    // Set angle of attack analysis points.
    analysis2.setNumberOfAngleOfAttackPoints( 7 );
    int i;
    for( i = 0; i < 7; i++ )
    {
        analysis2.setAngleOfAttackPoint( i,
                                         static_cast< double >( i - 6 )
                                         * 5.0 * M_PI / 180.0 );
    }

    // Generate database.
    analysis2.generateDatabase( );
<commit_msg>Commit of update to unit test of aerodynamics coefficient generator.<commit_after>/*!   \file unitTestCoefficientGenerator.cpp
 *    This file contains the unit test of the hypersonic local inclination
 *    analysis.
 *
 *    Path              : /Astrodynamics/ForceModels/Aerothermodynamics/
 *    Version           : 1
 *    Check status      : Checked
 *
 *    Author            : <NAME>
 *    Affiliation       : Delft University of Technology
 *    E-mail address    : <EMAIL>
 *
 *    Checker           : <NAME>
 *    Affiliation       : Delft University of Technology
 *    E-mail address    : <EMAIL>
 *
 *    Date created      : 25 November, 2010
 *    Last modified     : 9 February,  2011
 *
 *    References
 *      <NAME>., <NAME>., and <NAME>. . The Mark IV Supersonic-Hypersonic
 *        Arbitrary Body Program, Volume II - Program Formulation, Douglas Aircraft
 *        Aircraft Company, 1973.
 *
 *    Notes
 *
 *    Copyright (c) 2010 Delft University of Technology.
 *
 *    This software is protected by national and international copyright.
 *    Any unauthorized use, reproduction or modification is unlawful and
 *    will be prosecuted. Commercial and non-private application of the
 *    software in any form is strictly prohibited unless otherwise granted
 *    by the authors.
 *
 *    The code is provided without any warranty; without even the implied
 *    warranty of merchantibility or fitness for a particular purpose.
 *
 *    Changelog
 *      YYMMDD    Author            Comment
 *      102511    <NAME>          First version of file.
 */

// Include statements.
#include "unitTestCoefficientGenerator.h"
#include "writingOutputToFile.h"

bool unit_tests::testCoefficientGenerator( )
{

    // Declare test variable.
    bool isCoefficientGeneratorBad_ = 0;

    // Create test sphere.
    SphereSegment sphere = SphereSegment( );
    sphere.setRadius( 1.0 );
    sphere.setMinimumAzimuthAngle(  0.0 );
    sphere.setMaximumAzimuthAngle( 2.0 * M_PI);
    sphere.setMinimumZenithAngle( 0.0 );
    sphere.setMaximumZenithAngle( M_PI );
    VehicleExternalModel externalModel = VehicleExternalModel();
    externalModel.setVehicleGeometry( sphere );
    Vehicle vehicle = Vehicle();
    vehicle.setExternalModel( externalModel );

    // Create analysis object.
    HypersonicLocalInclinationAnalysis analysis =
            HypersonicLocalInclinationAnalysis( );

    // Set vehicle in analysis with 10,000 panels.
    int* numberOfLines = new int[ 1 ];
    int* numberOfPoints = new int[ 1 ];
    bool* invertOrder = new bool[ 1 ];
    numberOfLines[ 0 ] = 31;
    numberOfPoints[ 0 ] = 31;
    invertOrder[ 0 ] = 0;
    analysis.setVehicle( vehicle, numberOfLines, numberOfPoints, invertOrder );

    // Set reference quantities.
    analysis.setReferenceArea( M_PI );
    analysis.setReferenceLength( 1.0 );
    analysis.setMomentReferencePoint( Vector3d( 0, 0, 0) );

    // Set pure Newtonian compression method for test purposes.
    analysis.setSelectedMethod( 0, 0, 0 );

    // Generate sphere database.
    analysis.generateDatabase( );

    // Allocate memory for independent variables
    // to pass to analysis for retrieval.
    int* independentVariables = new int[ 3 ];
    independentVariables[ 0 ] = 0;
    independentVariables[ 1 ] = 0;
    independentVariables[ 2 ] = 0;

    // Declare local test variables.
    VectorXd aerodynamicCoefficients_;
    double forceCoefficient_;

    // Iterate over all angles of attack to verify sphere coefficients.
    for( int i = 0; i < analysis.getNumberOfMachPoints(); i++ )
    {
        independentVariables[ 0 ] = i;

        for( int j = 0; j < analysis.getNumberOfAngleOfAttackPoints( ); j++ )
        {
            independentVariables[ 1 ] = j;

            for( int k = 0; k < analysis.getNumberOfAngleOfSideslipPoints( ); k++ )
            {
                independentVariables[ 2 ] = k;

                // Retrieve aerodynamic coefficients.
                aerodynamicCoefficients_ = analysis.getAerodynamicCoefficients(
                        independentVariables );
                forceCoefficient_ = sqrt( aerodynamicCoefficients_.x( )
                                        * aerodynamicCoefficients_.x( )
                                        + aerodynamicCoefficients_.y( )
                                        * aerodynamicCoefficients_.y( )
                                        + aerodynamicCoefficients_.z( )
                                        * aerodynamicCoefficients_.z( ) );

                // Check if 'total' aerodynamic coefficient is always
                // sufficiently close to zero.
                if( fabs( forceCoefficient_ - 1.0 ) > 1.0E-2 )
                {
                    std::cout<<"Total magnitude of aerodynamic force wrong in "
                            <<"sphere."<<std::endl;
                    isCoefficientGeneratorBad_ = true;
                }

                // Check if moment coefficients are approximately zero. Deviations
                // for pitch moment are greater due to greater range of angles of
                // attack than sideslip.
                if( fabs( aerodynamicCoefficients_[ 3 ] ) > 1.0E-4 )
                {
                    std::cerr<<" Error, sphere roll moment coefficient not zero. "
                            <<std::endl;
                    isCoefficientGeneratorBad_ = true;
                }
                if( fabs( aerodynamicCoefficients_[ 4 ] ) > 1.0E-2 )
                {
                    std::cerr<<" Error, sphere pitch moment coefficient not zero. "
                            <<std::endl;
                    isCoefficientGeneratorBad_ = true;
                }
                if( fabs( aerodynamicCoefficients_[ 5 ] ) > 1.0E-2 )
                {
                    std::cerr<<" Error, sphere yaw moment coefficient not zero. "
                            <<std::endl;
                    isCoefficientGeneratorBad_ = true;
                }
            }
        }
    }


    // Set Apollo capsule for validation.
    Capsule capsule = Capsule( );
    capsule.setNoseRadius( 4.694 );
    capsule.setMiddleRadius( 1.956 );
    capsule.setRearAngle( -1*33.0 * M_PI / 180.0 );
    capsule.setRearLength( 2.662 );
    capsule.setSideRadius( 0.196 );
    capsule.setCapsule( );
    externalModel.setVehicleGeometry( capsule );
    vehicle.setExternalModel( externalModel );

    // Declare new analysis object
    HypersonicLocalInclinationAnalysis analysis2 =
            HypersonicLocalInclinationAnalysis( );

    int * numberOfLines2 = new int[ 4 ];
    int * numberOfPoints2 = new int[ 4 ];
    bool * invertOrders2 = new bool[ 4 ];

    // Set number of analysis points
    numberOfLines2[ 0 ] = 31;
    numberOfPoints2[ 0 ] = 31;
    numberOfLines2[ 1 ] = 31;
    numberOfPoints2[ 1 ] = 31;
    numberOfLines2[ 2 ] = 31;
    numberOfPoints2[ 2 ] = 2;
    numberOfLines2[ 3 ] = 11;
    numberOfPoints2[ 3 ] = 11;
    invertOrders2[ 0 ] = 1;
    invertOrders2[ 1 ] = 1;
    invertOrders2[ 2 ] = 1;
    invertOrders2[ 3 ] = 1;

    // Set capsule for analysis.
    analysis2.setVehicle( vehicle, numberOfLines2, numberOfPoints2, invertOrders2 );

    // Set reference quantities.
    analysis2.setReferenceArea( M_PI * pow( capsule.getMiddleRadius( ), 2.0 ) );
    analysis2.setReferenceLength( 3.9116 );
    VectorXd momentReference = VectorXd( 3 );
    momentReference( 0 ) = 0.6624;//27.334;
    momentReference( 1 ) = 0;
    momentReference( 2 ) = 0.1369;//9.398;
    analysis2.setMomentReferencePoint( momentReference );

    // Set angle of attack analysis points.
    analysis2.setNumberOfAngleOfAttackPoints( 7 );
    int i;
    for( i = 0; i < 7; i++ )
    {
        analysis2.setAngleOfAttackPoint( i,
                                         static_cast< double >( i - 6 )
                                         * 5.0 * M_PI / 180.0 );
    }

    // Generate database.
    analysis2.generateDatabase( );

{'fraction_non_alphanumeric': 0.09041579910404442, 'fraction_numerical': 0.027257240204429302, 'mean_word_length': 1.9313852413538006, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5014807', 'n_tokens_mistral': 4828, 'n_tokens_neox': 4267, 'n_words': 1201}