-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the first moment analytical integration of a lin-lin panel
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
1 change: 1 addition & 0 deletions
1
src/scion/integration/FirstMomentLinearLinear/test/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_cpp_test( integration.FirstMomentLinearLinear FirstMomentLinearLinear.test.cpp ) |
57 changes: 57 additions & 0 deletions
57
src/scion/integration/FirstMomentLinearLinear/test/FirstMomentLinearLinear.test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |