Skip to content

Commit

Permalink
added eddy current model and test
Browse files Browse the repository at this point in the history
 enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
  • Loading branch information
nataliaero committed May 8, 2015
2 parents c7832f0 + f36943b commit db318c4
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
45 changes: 45 additions & 0 deletions include/Astro/eddyCurrentModel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c)
*/

#ifndef ASTRO_EDDY_CURRENT_HPP
#define ASTRO_EDDY_CURRENT_HPP

#include <SML/linearAlgebra.hpp>

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
91 changes: 91 additions & 0 deletions test/testEddyTorqueModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c)
*/
#include <cmath>

#include <vector>

#include <catch.hpp>

#include <Astro/eddyCurrentModel.hpp>

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

0 comments on commit db318c4

Please sign in to comment.