From ccb546ab2498f7551cb7c5bbc138bd738683bdc2 Mon Sep 17 00:00:00 2001 From: nataliaero Date: Thu, 7 May 2015 14:35:14 +0100 Subject: [PATCH 01/10] Drag model and test has been added to the library --- include/Astro/dragAccelerationModel.hpp | 64 ++++++++++++++++++++ test/testDragAccelerationModel.cpp | 79 +++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100755 include/Astro/dragAccelerationModel.hpp create mode 100755 test/testDragAccelerationModel.cpp diff --git a/include/Astro/dragAccelerationModel.hpp b/include/Astro/dragAccelerationModel.hpp new file mode 100755 index 0000000..e066792 --- /dev/null +++ b/include/Astro/dragAccelerationModel.hpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2014-2015 Kartik Kumar (me@kartikkumar.com) + * Distributed under the MIT License. + * See accompanying file LICENSE.md or copy at http://opensource.org/licenses/MIT + */ + +#include + +namespace astro +{ + +//! Compute drag acceleration on a cannonball. +/*! + * Computes drag acceleration using a cannonball model. The model for the acceleration is given by + * + * \f[ + * a_{drag} = \frac{1}{2} \frac{C_{d}}{m} \rho V S \vec{V} + * \f] + * + * where \f$a_{drag}\f$ is the drag acceleration, \f$C_{d}\f$ is the drag coefficient, \f$m\f$ is + * the mass, \f$\rho\f$ is the atmospheric density, \$f\vec{V}$f is the relative velocity with + * respect to the body-fixed frame and \f$S\f$ is the drag area, that is, the projected area + * of the object perpendicular to \$f\vec{V}$f. + * + * @param dragCoefficient Drag coefficient [adim] + * @param atmosphericDensity Atmospheric Density [kg * m^-3] + * @param velocity Velocity vector 3x3 [m s^-1] + * @param dragArea Drag area [m^2] + * @param mass Mass [kg] + * @return + */ + template< typename Real, typename Vector3 > + Vector3 computeDragAcceleration( Real dragCoefficient, + Real atmosphericDensity, + Vector3 velocity, + Real dragArea, + Real mass ); + + + //! Compute drag acceleration on a cannonball. + template< typename Real, typename Vector3 > + Vector3 computeDragAcceleration( Real dragCoefficient, + Real atmosphericDensity, + Vector3 velocity, + Real dragArea, + Real mass ) + { + Vector3 dragAcceleration( 3 ); + + // Compute the squared norm of the velocity + Real normVelocity = sml::norm< Real >( velocity ); + + // Compute a premultiplier so that it does not have to be written several times + Real preMultiplier = 0.5 * dragCoefficient * atmosphericDensity * dragArea * normVelocity/mass; + + // Compute the drag acceleration vector + dragAcceleration[ 0 ] = preMultiplier * velocity[ 0 ]; + dragAcceleration[ 1 ] = preMultiplier * velocity[ 1 ]; + dragAcceleration[ 2 ] = preMultiplier * velocity[ 2 ]; + + return dragAcceleration; + } + +} // namespace astro \ No newline at end of file diff --git a/test/testDragAccelerationModel.cpp b/test/testDragAccelerationModel.cpp new file mode 100755 index 0000000..3a13489 --- /dev/null +++ b/test/testDragAccelerationModel.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2014-2015 Kartik Kumar (me@kartikkumar.com) + * Distributed under the MIT License. + * See accompanying file LICENSE.md or copy at http://opensource.org/licenses/MIT + */ + +#include + +using namespace std; + +#include + +#include + +#include + +namespace astro +{ + +namespace tests +{ + +typedef double Real; +typedef std::vector< Real > Vector; + +TEST_CASE( "Obtain drag acceleration", "[obtain-drag-acceleration]" ) +{ + // Set expected drag acceleration vector [m/s]. + Vector expectedDragAcceleration( 3 ); + expectedDragAcceleration[ 0 ] = 0.107800109999944e-4; + expectedDragAcceleration[ 1 ] = 0.0; + expectedDragAcceleration[ 2 ] = 0.000154000157143e-4; + + // Set epsilon = error between expected value and computed value. + const Real epsilon = 1e-10; + + // Set drag coefficient. + const Real dragCoefficient = 2.2; + + // Set atmospheric density [kg/m3]. + const Real atmosphericDensity = 2.0e-11; + + // Velocity vector in [m/s]. + Vector velocity( 3 ); + velocity[ 0 ] = 7000.0; + velocity[ 1 ] = 0.0; + velocity[ 2 ] = 10.0; + + // Set drag area [m^2] + const Real dragArea = 5.0; + + // Set mass [kg] + const Real mass = 500.0; + + //! Compute drag acceleration. + const Vector dragAcceleration = computeDragAcceleration( dragCoefficient, + atmosphericDensity, + velocity, + dragArea, + mass ); + // Outputs of the test + cout << endl; + cout << "Comp Drag: <" << dragAcceleration[ 0 ] << ", " + << dragAcceleration[ 1 ] << ", " + << dragAcceleration[ 2 ] << ">" << endl; + + cout << "Ref Drag: <" << expectedDragAcceleration[ 0 ] << ", " + << expectedDragAcceleration[ 1 ] << ", " + << expectedDragAcceleration[ 2 ] << ">" << endl; + + + // Check if computed mean motion matches expected value. + REQUIRE( abs(dragAcceleration[ 0 ] - expectedDragAcceleration[ 0 ]) <= epsilon ); + REQUIRE( abs(dragAcceleration[ 1 ] - expectedDragAcceleration[ 1 ]) <= epsilon ); + REQUIRE( abs(dragAcceleration[ 2 ] - expectedDragAcceleration[ 2 ]) <= epsilon ); +} + +} // namespace tests +} // namespace astro From 2b67bcdf4165d331c0c392c479efd2bf7a6581c2 Mon Sep 17 00:00:00 2001 From: nataliaero Date: Thu, 7 May 2015 16:35:35 +0100 Subject: [PATCH 02/10] minor change to Air Drag test --- test/testDragAccelerationModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testDragAccelerationModel.cpp b/test/testDragAccelerationModel.cpp index 3a13489..e8f0016 100755 --- a/test/testDragAccelerationModel.cpp +++ b/test/testDragAccelerationModel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2015 Kartik Kumar (me@kartikkumar.com) + * Copyright (c) 2015 Kartik Kumar (me@kartikkumar.com) * Distributed under the MIT License. * See accompanying file LICENSE.md or copy at http://opensource.org/licenses/MIT */ From 730f4bf05bf0dc22b9ced0be84b99137517a3421 Mon Sep 17 00:00:00 2001 From: nataliaero Date: Thu, 7 May 2015 16:36:19 +0100 Subject: [PATCH 03/10] air drag model in make list --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d86bae1..96f8d5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ CMAKE_DEPENDENT_OPTION(BUILD_COVERAGE_ANALYSIS "Build code coverage analysis" set(TEST_SRC "${TEST_SRC_PATH}/testAstro.cpp" "${TEST_SRC_PATH}/testConstants.cpp" + "${TEST_SRC_PATH}/testDragAccelerationModel.cpp" "${TEST_SRC_PATH}/testOrbitalElementConversions.cpp" "${TEST_SRC_PATH}/testTwoBodyMethods.cpp" ) From 442c001ad91023632708f51f8eb24f297d07f957 Mon Sep 17 00:00:00 2001 From: nataliaero Date: Thu, 7 May 2015 16:43:00 +0100 Subject: [PATCH 04/10] remove comments tests so that test is clean --- test/testDragAccelerationModel.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test/testDragAccelerationModel.cpp b/test/testDragAccelerationModel.cpp index e8f0016..66ae42c 100755 --- a/test/testDragAccelerationModel.cpp +++ b/test/testDragAccelerationModel.cpp @@ -4,10 +4,6 @@ * See accompanying file LICENSE.md or copy at http://opensource.org/licenses/MIT */ -#include - -using namespace std; - #include #include @@ -58,16 +54,6 @@ TEST_CASE( "Obtain drag acceleration", "[obtain-drag-acceleration]" ) velocity, dragArea, mass ); - // Outputs of the test - cout << endl; - cout << "Comp Drag: <" << dragAcceleration[ 0 ] << ", " - << dragAcceleration[ 1 ] << ", " - << dragAcceleration[ 2 ] << ">" << endl; - - cout << "Ref Drag: <" << expectedDragAcceleration[ 0 ] << ", " - << expectedDragAcceleration[ 1 ] << ", " - << expectedDragAcceleration[ 2 ] << ">" << endl; - // Check if computed mean motion matches expected value. REQUIRE( abs(dragAcceleration[ 0 ] - expectedDragAcceleration[ 0 ]) <= epsilon ); From b2e9c32a44892f0550e65ccbd6c183ef3e7eb3ca Mon Sep 17 00:00:00 2001 From: nataliaero Date: Fri, 8 May 2015 13:42:20 +0100 Subject: [PATCH 05/10] Drag Acceleration Model and Tests --- CMakeLists.txt | 1 + include/Astro/dragAccelerationModel.hpp | 71 +++++++++++++------------ test/testDragAccelerationModel.cpp | 66 +++++++++++++++++++---- 3 files changed, 94 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96f8d5f..8eb16d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ set(TEST_SRC "${TEST_SRC_PATH}/testAstro.cpp" "${TEST_SRC_PATH}/testConstants.cpp" "${TEST_SRC_PATH}/testDragAccelerationModel.cpp" + "${TEST_SRC_PATH}/testEddyTorqueModel.cpp" "${TEST_SRC_PATH}/testOrbitalElementConversions.cpp" "${TEST_SRC_PATH}/testTwoBodyMethods.cpp" ) diff --git a/include/Astro/dragAccelerationModel.hpp b/include/Astro/dragAccelerationModel.hpp index e066792..4f783f8 100755 --- a/include/Astro/dragAccelerationModel.hpp +++ b/include/Astro/dragAccelerationModel.hpp @@ -4,6 +4,9 @@ * See accompanying file LICENSE.md or copy at http://opensource.org/licenses/MIT */ +#ifndef ASTRO_DRAG_ACCELERATION_MODEL_HPP +#define ASTRO_DRAG_ACCELERATION_MODEL_HPP + #include namespace astro @@ -14,51 +17,53 @@ namespace astro * Computes drag acceleration using a cannonball model. The model for the acceleration is given by * * \f[ - * a_{drag} = \frac{1}{2} \frac{C_{d}}{m} \rho V S \vec{V} + * a_{drag} = \frac{1}{2} \frac{C_{d}}{m} \rho S V \vec{V} * \f] * * where \f$a_{drag}\f$ is the drag acceleration, \f$C_{d}\f$ is the drag coefficient, \f$m\f$ is - * the mass, \f$\rho\f$ is the atmospheric density, \$f\vec{V}$f is the relative velocity with - * respect to the body-fixed frame and \f$S\f$ is the drag area, that is, the projected area - * of the object perpendicular to \$f\vec{V}$f. + * the mass, \f$\rho\f$ is the atmospheric density, \f$\vec{V}\f$ is the relative velocity with + * respect to the body-fixed frame and \f$S\f$ is the drag area, that is, the projected area + * of the object perpendicular to \f$\vec{V}\f$. * - * @param dragCoefficient Drag coefficient [adim] - * @param atmosphericDensity Atmospheric Density [kg * m^-3] - * @param velocity Velocity vector 3x3 [m s^-1] - * @param dragArea Drag area [m^2] - * @param mass Mass [kg] - * @return + * @param[in] dragCoefficient Drag coefficient [adim] + * @param[in] atmosphericDensity Atmospheric density [kg m^-3] + * @param[in] velocity Velocity vector (3x1) [m s^-1] + * @param[in] dragArea Drag area [m^2] + * @param[in] mass Mass [kg] + * @return Drag acceleration vector (3x1) [m s^-2] */ - template< typename Real, typename Vector3 > - Vector3 computeDragAcceleration( Real dragCoefficient, - Real atmosphericDensity, - Vector3 velocity, - Real dragArea, - Real mass ); - +template< typename Real, typename Vector3 > +Vector3 computeDragAcceleration( const Real dragCoefficient, + const Real atmosphericDensity, + const Vector3& velocity, + const Real dragArea, + const Real mass ); - //! Compute drag acceleration on a cannonball. - template< typename Real, typename Vector3 > - Vector3 computeDragAcceleration( Real dragCoefficient, - Real atmosphericDensity, - Vector3 velocity, - Real dragArea, - Real mass ) - { - Vector3 dragAcceleration( 3 ); +//! Compute drag acceleration on a cannonball. +template< typename Real, typename Vector3 > +Vector3 computeDragAcceleration( const Real dragCoefficient, + const Real atmosphericDensity, + const Vector3& velocity, + const Real dragArea, + const Real mass ) +{ + Vector3 dragAcceleration = velocity; - // Compute the squared norm of the velocity - Real normVelocity = sml::norm< Real >( velocity ); + // Compute the squared norm of the velocity. + const Real normVelocity = sml::norm< Real >( velocity ); - // Compute a premultiplier so that it does not have to be written several times - Real preMultiplier = 0.5 * dragCoefficient * atmosphericDensity * dragArea * normVelocity/mass; + // Compute a premultiplier so that it does not have to be written several times. + const Real preMultiplier = 0.5 * dragCoefficient * atmosphericDensity + * dragArea * normVelocity / mass; - // Compute the drag acceleration vector + // Compute the drag acceleration vector. dragAcceleration[ 0 ] = preMultiplier * velocity[ 0 ]; dragAcceleration[ 1 ] = preMultiplier * velocity[ 1 ]; dragAcceleration[ 2 ] = preMultiplier * velocity[ 2 ]; return dragAcceleration; - } +} + +} // namespace astro -} // namespace astro \ No newline at end of file +#endif // ASTRO_DRAG_ACCELERATION_MODEL_HPP diff --git a/test/testDragAccelerationModel.cpp b/test/testDragAccelerationModel.cpp index 66ae42c..e5f5d5d 100755 --- a/test/testDragAccelerationModel.cpp +++ b/test/testDragAccelerationModel.cpp @@ -4,22 +4,22 @@ * See accompanying file LICENSE.md or copy at http://opensource.org/licenses/MIT */ +#include #include #include -#include +#include "Astro/dragAccelerationModel.hpp" namespace astro { - namespace tests { typedef double Real; typedef std::vector< Real > Vector; -TEST_CASE( "Obtain drag acceleration", "[obtain-drag-acceleration]" ) +TEST_CASE( "Obtain drag acceleration: test 1", "[drag, acceleration, models]" ) { // Set expected drag acceleration vector [m/s]. Vector expectedDragAcceleration( 3 ); @@ -28,12 +28,12 @@ TEST_CASE( "Obtain drag acceleration", "[obtain-drag-acceleration]" ) expectedDragAcceleration[ 2 ] = 0.000154000157143e-4; // Set epsilon = error between expected value and computed value. - const Real epsilon = 1e-10; + const Real epsilon = 1.0e-10; // Set drag coefficient. const Real dragCoefficient = 2.2; - // Set atmospheric density [kg/m3]. + // Set atmospheric density [kg/m^3]. const Real atmosphericDensity = 2.0e-11; // Velocity vector in [m/s]. @@ -42,18 +42,62 @@ TEST_CASE( "Obtain drag acceleration", "[obtain-drag-acceleration]" ) velocity[ 1 ] = 0.0; velocity[ 2 ] = 10.0; - // Set drag area [m^2] + // Set drag area [m^2]. const Real dragArea = 5.0; - // Set mass [kg] + // Set mass [kg]. const Real mass = 500.0; //! Compute drag acceleration. const Vector dragAcceleration = computeDragAcceleration( dragCoefficient, - atmosphericDensity, - velocity, - dragArea, - mass ); + atmosphericDensity, + velocity, + dragArea, + mass ); + + // Check if computed mean motion matches expected value. + REQUIRE( std::fabs( dragAcceleration[ 0 ] - expectedDragAcceleration[ 0 ] ) <= epsilon ); + REQUIRE( std::fabs( dragAcceleration[ 1 ] - expectedDragAcceleration[ 1 ] ) <= epsilon ); + REQUIRE( std::fabs( dragAcceleration[ 2 ] - expectedDragAcceleration[ 2 ] ) <= epsilon ); +} + +TEST_CASE( "Obtain drag acceleration: test 2", "[obtain-drag-acceleration-2]" ) +{ + // Reference: http://tudat.tudelft.nl/ + + // Set expected drag acceleration vector [m/s]. + Vector expectedDragAcceleration( 3 ); + expectedDragAcceleration[ 0 ] = 0.0; + expectedDragAcceleration[ 1 ] = 0.0; + expectedDragAcceleration[ 2 ] = 267.4212; + + // Set epsilon = error between expected value and computed value. + const Real epsilon = 1.0e-10; + + // Set drag coefficient. + const Real dragCoefficient = 1.1; + + // Set atmospheric density [kg/m3]. + const Real atmosphericDensity = 3.5e-5; + + // Velocity vector in [m/s]. + Vector velocity( 3 ); + velocity[ 0 ] = 0.0; + velocity[ 1 ] = 0.0; + velocity[ 2 ] = 3491.0; + + // Set drag area [m^2] + const Real dragArea = 2.2; + + // Set mass [kg] + const Real mass = 1.93; + + //! Compute drag acceleration. + const Vector dragAcceleration = computeDragAcceleration( dragCoefficient, + atmosphericDensity, + velocity, + dragArea, + mass ); // Check if computed mean motion matches expected value. REQUIRE( abs(dragAcceleration[ 0 ] - expectedDragAcceleration[ 0 ]) <= epsilon ); From f36943b1af03715aca88ea5a1ad1257d47dfed6c Mon Sep 17 00:00:00 2001 From: nataliaero Date: Fri, 8 May 2015 14:14:41 +0100 Subject: [PATCH 06/10] eddy current torque model --- CMakeLists.txt | 1 + include/Astro/eddyCurrentModel.hpp | 45 +++++++++++++++ test/testEddyTorqueModel.cpp | 91 ++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100755 include/Astro/eddyCurrentModel.hpp create mode 100755 test/testEddyTorqueModel.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 96f8d5f..8eb16d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ set(TEST_SRC "${TEST_SRC_PATH}/testAstro.cpp" "${TEST_SRC_PATH}/testConstants.cpp" "${TEST_SRC_PATH}/testDragAccelerationModel.cpp" + "${TEST_SRC_PATH}/testEddyTorqueModel.cpp" "${TEST_SRC_PATH}/testOrbitalElementConversions.cpp" "${TEST_SRC_PATH}/testTwoBodyMethods.cpp" ) diff --git a/include/Astro/eddyCurrentModel.hpp b/include/Astro/eddyCurrentModel.hpp new file mode 100755 index 0000000..e43445e --- /dev/null +++ b/include/Astro/eddyCurrentModel.hpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) + */ + +#ifndef ASTRO_EDDY_CURRENT_HPP +#define ASTRO_EDDY_CURRENT_HPP + +#include + +namespace astro +{ + +//! Compute eddy current torque. +/*! + * Computes the eddy current torque on a certain object generated by an external source. The model + * for the torque is given by + * + * \f[ + * \vec{T}_{eddy} = \vec{m} \times \vec{B} + * \f] + * + * where \f$\vec{m}\f$ is the magnetic moment of the object and \f$\vec{B}\f$ is the magnetic field + * generated by an external source. + * + * @param magneticMoment Magnetic Moment [A * m^2] + * @param magneticField Magnetic Field [T] + * @return Eddy Current Torque [N * m] + */ + template< typename Vector3 > + Vector3 computeEddyTorque( const Vector3& magneticMoment, + const Vector3& magneticField ); + + //! Compute eddy current torque. + template< typename Vector3 > + Vector3 computeEddyTorque( const Vector3& magneticMoment, + const Vector3& magneticField ) + + { + // Compute the eddy current torque. + return sml::cross< Vector3 >( magneticMoment, magneticField); + } + + } // namespace astro + + #endif // ASTRO_EDDY_CURRENT_HPP \ No newline at end of file diff --git a/test/testEddyTorqueModel.cpp b/test/testEddyTorqueModel.cpp new file mode 100755 index 0000000..a1f3954 --- /dev/null +++ b/test/testEddyTorqueModel.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) + */ +#include + +#include + +#include + +#include + +using namespace std; + +namespace astro +{ + +namespace tests +{ + +typedef double Real; +typedef std::vector< Real > Vector3; + +TEST_CASE( "Obtain eddy current torque: test 1", "[obtain-eddy-torque-1]" ) +{ + // Set expected eddy current torque vector [N * m]. + Vector3 expectedEddyTorque( 3 ); + expectedEddyTorque[ 0 ] = 0.095000000000000; + expectedEddyTorque[ 1 ] = 0.065000000000000; + expectedEddyTorque[ 2 ] = -0.149000000000000; + + // Set magnetic moment vector [A * m^2]. + Vector3 magneticMoment( 3 ); + magneticMoment[ 0 ] = 100.0; + magneticMoment[ 1 ] = 1000.0; + magneticMoment[ 2 ] = 500.0; + + // Set magnetic field vector [T]. + Vector3 magneticField( 3 ); + magneticField[ 0 ] = 150e-6; + magneticField[ 1 ] = 10e-6; + magneticField[ 2 ] = 100e-6; + + // Set epsilon = error between expected value and computed value. + const Real epsilon = 1.0e-10; + + //! Compute eddy current torque. + const Vector3 eddyTorque = computeEddyTorque( magneticMoment, + magneticField ); + + // Check if computed torque matches expected value. + REQUIRE( std::fabs(eddyTorque[ 0 ] - expectedEddyTorque[ 0 ]) <= epsilon ); + REQUIRE( std::fabs(eddyTorque[ 1 ] - expectedEddyTorque[ 1 ]) <= epsilon ); + REQUIRE( std::fabs(eddyTorque[ 2 ] - expectedEddyTorque[ 2 ]) <= epsilon ); +} + +TEST_CASE( "Obtain eddy current torque: test 2", "[obtain-eddy-torque-2]" ) +{ + // Set expected eddy current torque vector [N * m]. + Vector3 expectedEddyTorque( 3 ); + expectedEddyTorque[ 0 ] = 0.0; + expectedEddyTorque[ 1 ] = 0.0; + expectedEddyTorque[ 2 ] = 0.0; + + // Set magnetic moment vector [A * m^2]. + Vector3 magneticMoment( 3 ); + magneticMoment[ 0 ] = 0.0; + magneticMoment[ 1 ] = 0.0; + magneticMoment[ 2 ] = 1150.0; + + // Set magnetic field vector [T]. + Vector3 magneticField( 3 ); + magneticField[ 0 ] = 0.0; + magneticField[ 1 ] = 0.0; + magneticField[ 2 ] = 127e-6; + + // Set epsilon = error between expected value and computed value. + const Real epsilon = 1.0e-10; + + //! Compute eddy current torque. + const Vector3 eddyTorque = computeEddyTorque( magneticMoment, + magneticField ); + + // Check if computed torque matches expected value. + REQUIRE( std::fabs(eddyTorque[ 0 ] - expectedEddyTorque[ 0 ]) <= epsilon ); + REQUIRE( std::fabs(eddyTorque[ 1 ] - expectedEddyTorque[ 1 ]) <= epsilon ); + REQUIRE( std::fabs(eddyTorque[ 2 ] - expectedEddyTorque[ 2 ]) <= epsilon ); +} + + +} // namespace tests +} // namespace astro From b5156075e6fd32d6f81374bf2ecc6069ca1753d1 Mon Sep 17 00:00:00 2001 From: nataliaero Date: Fri, 8 May 2015 15:13:30 +0100 Subject: [PATCH 07/10] Remove erroneous eddy torque test from CMakeLists.txt --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8eb16d1..96f8d5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,6 @@ set(TEST_SRC "${TEST_SRC_PATH}/testAstro.cpp" "${TEST_SRC_PATH}/testConstants.cpp" "${TEST_SRC_PATH}/testDragAccelerationModel.cpp" - "${TEST_SRC_PATH}/testEddyTorqueModel.cpp" "${TEST_SRC_PATH}/testOrbitalElementConversions.cpp" "${TEST_SRC_PATH}/testTwoBodyMethods.cpp" ) From 6cc466195947fb2c5bd2c9ea703e58e326cd1ac2 Mon Sep 17 00:00:00 2001 From: nataliaero Date: Fri, 8 May 2015 14:03:06 +0100 Subject: [PATCH 08/10] change abs for std::fabs --- test/testDragAccelerationModel.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/testDragAccelerationModel.cpp b/test/testDragAccelerationModel.cpp index e5f5d5d..a96eca7 100755 --- a/test/testDragAccelerationModel.cpp +++ b/test/testDragAccelerationModel.cpp @@ -100,9 +100,9 @@ TEST_CASE( "Obtain drag acceleration: test 2", "[obtain-drag-acceleration-2]" ) mass ); // Check if computed mean motion matches expected value. - REQUIRE( abs(dragAcceleration[ 0 ] - expectedDragAcceleration[ 0 ]) <= epsilon ); - REQUIRE( abs(dragAcceleration[ 1 ] - expectedDragAcceleration[ 1 ]) <= epsilon ); - REQUIRE( abs(dragAcceleration[ 2 ] - expectedDragAcceleration[ 2 ]) <= epsilon ); + REQUIRE( std::fabs(dragAcceleration[ 0 ] - expectedDragAcceleration[ 0 ]) <= epsilon ); + REQUIRE( std::fabs(dragAcceleration[ 1 ] - expectedDragAcceleration[ 1 ]) <= epsilon ); + REQUIRE( std::fabs(dragAcceleration[ 2 ] - expectedDragAcceleration[ 2 ]) <= epsilon ); } } // namespace tests From 7dafa5d23211d86f95c3cb921b1733d2e015aa65 Mon Sep 17 00:00:00 2001 From: nataliaero Date: Fri, 8 May 2015 14:14:41 +0100 Subject: [PATCH 09/10] eddy current torque model --- CMakeLists.txt | 1 + include/Astro/eddyCurrentModel.hpp | 45 +++++++++++++++ test/testEddyTorqueModel.cpp | 91 ++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100755 include/Astro/eddyCurrentModel.hpp create mode 100755 test/testEddyTorqueModel.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 96f8d5f..8eb16d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ set(TEST_SRC "${TEST_SRC_PATH}/testAstro.cpp" "${TEST_SRC_PATH}/testConstants.cpp" "${TEST_SRC_PATH}/testDragAccelerationModel.cpp" + "${TEST_SRC_PATH}/testEddyTorqueModel.cpp" "${TEST_SRC_PATH}/testOrbitalElementConversions.cpp" "${TEST_SRC_PATH}/testTwoBodyMethods.cpp" ) diff --git a/include/Astro/eddyCurrentModel.hpp b/include/Astro/eddyCurrentModel.hpp new file mode 100755 index 0000000..e43445e --- /dev/null +++ b/include/Astro/eddyCurrentModel.hpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) + */ + +#ifndef ASTRO_EDDY_CURRENT_HPP +#define ASTRO_EDDY_CURRENT_HPP + +#include + +namespace astro +{ + +//! Compute eddy current torque. +/*! + * Computes the eddy current torque on a certain object generated by an external source. The model + * for the torque is given by + * + * \f[ + * \vec{T}_{eddy} = \vec{m} \times \vec{B} + * \f] + * + * where \f$\vec{m}\f$ is the magnetic moment of the object and \f$\vec{B}\f$ is the magnetic field + * generated by an external source. + * + * @param magneticMoment Magnetic Moment [A * m^2] + * @param magneticField Magnetic Field [T] + * @return Eddy Current Torque [N * m] + */ + template< typename Vector3 > + Vector3 computeEddyTorque( const Vector3& magneticMoment, + const Vector3& magneticField ); + + //! Compute eddy current torque. + template< typename Vector3 > + Vector3 computeEddyTorque( const Vector3& magneticMoment, + const Vector3& magneticField ) + + { + // Compute the eddy current torque. + return sml::cross< Vector3 >( magneticMoment, magneticField); + } + + } // namespace astro + + #endif // ASTRO_EDDY_CURRENT_HPP \ No newline at end of file diff --git a/test/testEddyTorqueModel.cpp b/test/testEddyTorqueModel.cpp new file mode 100755 index 0000000..a1f3954 --- /dev/null +++ b/test/testEddyTorqueModel.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) + */ +#include + +#include + +#include + +#include + +using namespace std; + +namespace astro +{ + +namespace tests +{ + +typedef double Real; +typedef std::vector< Real > Vector3; + +TEST_CASE( "Obtain eddy current torque: test 1", "[obtain-eddy-torque-1]" ) +{ + // Set expected eddy current torque vector [N * m]. + Vector3 expectedEddyTorque( 3 ); + expectedEddyTorque[ 0 ] = 0.095000000000000; + expectedEddyTorque[ 1 ] = 0.065000000000000; + expectedEddyTorque[ 2 ] = -0.149000000000000; + + // Set magnetic moment vector [A * m^2]. + Vector3 magneticMoment( 3 ); + magneticMoment[ 0 ] = 100.0; + magneticMoment[ 1 ] = 1000.0; + magneticMoment[ 2 ] = 500.0; + + // Set magnetic field vector [T]. + Vector3 magneticField( 3 ); + magneticField[ 0 ] = 150e-6; + magneticField[ 1 ] = 10e-6; + magneticField[ 2 ] = 100e-6; + + // Set epsilon = error between expected value and computed value. + const Real epsilon = 1.0e-10; + + //! Compute eddy current torque. + const Vector3 eddyTorque = computeEddyTorque( magneticMoment, + magneticField ); + + // Check if computed torque matches expected value. + REQUIRE( std::fabs(eddyTorque[ 0 ] - expectedEddyTorque[ 0 ]) <= epsilon ); + REQUIRE( std::fabs(eddyTorque[ 1 ] - expectedEddyTorque[ 1 ]) <= epsilon ); + REQUIRE( std::fabs(eddyTorque[ 2 ] - expectedEddyTorque[ 2 ]) <= epsilon ); +} + +TEST_CASE( "Obtain eddy current torque: test 2", "[obtain-eddy-torque-2]" ) +{ + // Set expected eddy current torque vector [N * m]. + Vector3 expectedEddyTorque( 3 ); + expectedEddyTorque[ 0 ] = 0.0; + expectedEddyTorque[ 1 ] = 0.0; + expectedEddyTorque[ 2 ] = 0.0; + + // Set magnetic moment vector [A * m^2]. + Vector3 magneticMoment( 3 ); + magneticMoment[ 0 ] = 0.0; + magneticMoment[ 1 ] = 0.0; + magneticMoment[ 2 ] = 1150.0; + + // Set magnetic field vector [T]. + Vector3 magneticField( 3 ); + magneticField[ 0 ] = 0.0; + magneticField[ 1 ] = 0.0; + magneticField[ 2 ] = 127e-6; + + // Set epsilon = error between expected value and computed value. + const Real epsilon = 1.0e-10; + + //! Compute eddy current torque. + const Vector3 eddyTorque = computeEddyTorque( magneticMoment, + magneticField ); + + // Check if computed torque matches expected value. + REQUIRE( std::fabs(eddyTorque[ 0 ] - expectedEddyTorque[ 0 ]) <= epsilon ); + REQUIRE( std::fabs(eddyTorque[ 1 ] - expectedEddyTorque[ 1 ]) <= epsilon ); + REQUIRE( std::fabs(eddyTorque[ 2 ] - expectedEddyTorque[ 2 ]) <= epsilon ); +} + + +} // namespace tests +} // namespace astro From 3acf35a7c15f443bb51e601f6c7726aac9bad3b1 Mon Sep 17 00:00:00 2001 From: nataliaero Date: Fri, 8 May 2015 16:44:50 +0100 Subject: [PATCH 10/10] replace abs function with fabs --- test/testDragAccelerationModel.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/testDragAccelerationModel.cpp b/test/testDragAccelerationModel.cpp index 66ae42c..c326048 100755 --- a/test/testDragAccelerationModel.cpp +++ b/test/testDragAccelerationModel.cpp @@ -28,7 +28,7 @@ TEST_CASE( "Obtain drag acceleration", "[obtain-drag-acceleration]" ) expectedDragAcceleration[ 2 ] = 0.000154000157143e-4; // Set epsilon = error between expected value and computed value. - const Real epsilon = 1e-10; + const Real epsilon = 1.0e-10; // Set drag coefficient. const Real dragCoefficient = 2.2; @@ -50,15 +50,15 @@ TEST_CASE( "Obtain drag acceleration", "[obtain-drag-acceleration]" ) //! Compute drag acceleration. const Vector dragAcceleration = computeDragAcceleration( dragCoefficient, - atmosphericDensity, - velocity, - dragArea, - mass ); + atmosphericDensity, + velocity, + dragArea, + mass ); // Check if computed mean motion matches expected value. - REQUIRE( abs(dragAcceleration[ 0 ] - expectedDragAcceleration[ 0 ]) <= epsilon ); - REQUIRE( abs(dragAcceleration[ 1 ] - expectedDragAcceleration[ 1 ]) <= epsilon ); - REQUIRE( abs(dragAcceleration[ 2 ] - expectedDragAcceleration[ 2 ]) <= epsilon ); + REQUIRE( std::fabs(dragAcceleration[ 0 ] - expectedDragAcceleration[ 0 ]) <= epsilon ); + REQUIRE( std::fabs(dragAcceleration[ 1 ] - expectedDragAcceleration[ 1 ]) <= epsilon ); + REQUIRE( std::fabs(dragAcceleration[ 2 ] - expectedDragAcceleration[ 2 ]) <= epsilon ); } } // namespace tests