Skip to content

Feature/integration part6 #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding the first moment analytical integration of a lin-lin panel
  • Loading branch information
whaeck committed Oct 1, 2024
commit 2026d27038f2f6f113b66afa78812b069dcca333
58 changes: 58 additions & 0 deletions src/scion/integration/FirstMomentLinearLinear.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef NJOY_SCION_INTEGRATION_LINEARLINEAR
#define NJOY_SCION_INTEGRATION_LINEARLINEAR

// system includes

// other includes
#include "scion/integration/IntegratorBase.hpp"

namespace njoy {
namespace scion {
namespace integration {

/**
* @class
* @brief First raw moment of a Linear-linear panel (y is linear in x)
*
* The first raw moment or mean is defined as the integral of x * f(x)
*/
class FirstMomentLinearLinear : public IntegratorBase< FirstMomentLinearLinear > {

/* friend declarations */
friend class IntegratorBase< FirstMomentLinearLinear >;

/* interface implementation functions */

/**
* @brief Perform first raw moment integration of a linear-linear panel (y is linear in x)
*
* @param[in] xLeft the left value on the x interval
* @param[in] xRight the right value on the x interval
* @param[in] yLeft the left value on the y interval
* @param[in] yRight the right value on the y interval
*/
template < typename X, typename Y,
typename I = decltype( std::declval< X >() * std::declval< X >() * std::declval< Y >() ) >
I integrate( const X& xLeft, const X& xRight,
const Y& yLeft, const Y& yRight ) const noexcept {

auto delta = ( xRight - xLeft );
auto slope = ( yRight - yLeft ) / delta / 3.;
auto constant = 0.5 * ( xRight * yLeft - xLeft * yRight ) / delta;
return xRight * xRight * ( slope * xRight + constant )
- xLeft * xLeft * ( slope * yLeft + constant );
}

public:

using IntegratorBase::operator();
};

// integration function
static constexpr FirstMomentLinearLinear firstMomentLinLin;

} // integration namespace
} // scion namespace
} // njoy namespace

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_cpp_test( integration.FirstMomentLinearLinear FirstMomentLinearLinear.test.cpp )
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// include Catch2
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
using Catch::Matchers::WithinRel;

// what we are testing
#include "scion/integration/FirstMomentLinearLinear.hpp"

// other includes

// convenience typedefs
using namespace njoy::scion;

SCENARIO( "MeanLinearLinear" ) {

GIVEN( "MeanLinearLinear integration object" ) {

WHEN( "integrating an interval" ) {

integration::FirstMomentLinearLinear integrator{};

THEN( "the integration is performed correctly" ) {

double xLeft = 1.0;
double xRight = 2.0;
double yLeft = 1.0;
double yRight = 4.0;

// both y values are the same
CHECK_THAT( 1.5, WithinRel( integrator( xLeft, xRight, yLeft, yLeft ) ) );

// the y values are different
CHECK_THAT( 4.0, WithinRel( integrator( xLeft, xRight, yLeft, yRight ) ) );
} // THEN
} // WHEN
} // GIVEN

GIVEN( "linlin integration function" ) {

WHEN( "integrating an interval" ) {

THEN( "the integration is performed correctly" ) {

double xLeft = 1.0;
double xRight = 2.0;
double yLeft = 1.0;
double yRight = 4.0;

// both y values are the same
CHECK_THAT( 1.5, WithinRel( integration::firstMomentLinLin( xLeft, xRight, yLeft, yLeft ) ) );

// the y values are different
CHECK_THAT( 4.0, WithinRel( integration::firstMomentLinLin( xLeft, xRight, yLeft, yRight ) ) );
} // THEN
} // WHEN
} // GIVEN
} // SCENARIO