-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature/integration part6 #83
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5718244
Updating the IntegratorBase function to include checkking for equal x
whaeck 2026d27
Adding the first moment analytical integration of a lin-lin panel
whaeck 62f0c1a
adding test
whaeck 5808c54
Adding zero and first moment integration to the AnalyticalIntegrator
whaeck f7f29d6
preventing eigen from populating .cmake/packages
whaeck 7e71f1d
Adding the first moment of a histogram panel
whaeck b9ec1ed
Adding first raw moment for a lin-log panel
whaeck 6699496
Adding unit test
whaeck 743d08c
Adding a missing include file
whaeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,54 @@ | ||
#ifndef NJOY_SCION_INTEGRATION_FIRSTMOMENTHISTOGRAM | ||
#define NJOY_SCION_INTEGRATION_FIRSTMOMENTHISTOGRAM | ||
|
||
// system includes | ||
|
||
// other includes | ||
#include "scion/integration/IntegratorBase.hpp" | ||
|
||
namespace njoy { | ||
namespace scion { | ||
namespace integration { | ||
|
||
/** | ||
* @class | ||
* @brief First raw moment of a histogram panel (y is constant in x) | ||
* | ||
* The first raw moment or mean is defined as the integral of x * f(x) | ||
*/ | ||
class FirstMomentHistogram : public IntegratorBase< FirstMomentHistogram > { | ||
|
||
/* friend declarations */ | ||
friend class IntegratorBase< FirstMomentHistogram >; | ||
|
||
/* interface implementation functions */ | ||
|
||
/** | ||
* @brief Perform first raw moment integration of a histogram panel (y is constant 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& ) const noexcept { | ||
|
||
return 0.5 * yLeft * ( xRight - xLeft ) * ( xRight + xLeft ); | ||
} | ||
|
||
public: | ||
|
||
using IntegratorBase::operator(); | ||
}; | ||
|
||
// integration function | ||
static constexpr FirstMomentHistogram firstMomentHistogram; | ||
|
||
} // integration namespace | ||
} // scion namespace | ||
} // njoy namespace | ||
|
||
#endif |
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.FirstMomentHistogram FirstMomentHistogram.test.cpp ) |
57 changes: 57 additions & 0 deletions
57
src/scion/integration/FirstMomentHistogram/test/FirstMomentHistogram.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/FirstMomentHistogram.hpp" | ||
|
||
// other includes | ||
|
||
// convenience typedefs | ||
using namespace njoy::scion; | ||
|
||
SCENARIO( "FirstMomentHistogram" ) { | ||
|
||
GIVEN( "FirstMomentHistogram integration object" ) { | ||
|
||
WHEN( "integrating an interval" ) { | ||
|
||
integration::FirstMomentHistogram 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( 1.5, 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::firstMomentHistogram( xLeft, xRight, yLeft, yLeft ) ) ); | ||
|
||
// the y values are different | ||
CHECK_THAT( 1.5, WithinRel( integration::firstMomentHistogram( xLeft, xRight, yLeft, yRight ) ) ); | ||
} // THEN | ||
} // WHEN | ||
} // GIVEN | ||
} // SCENARIO |
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_FIRSTMOMENTLINEARLINEAR | ||
#define NJOY_SCION_INTEGRATION_FIRSTMOMENTLINEARLINEAR | ||
|
||
// 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 * xLeft + 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( "FirstMomentLinearLinear" ) { | ||
|
||
GIVEN( "FirstMomentLinearLinear 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 |
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,72 @@ | ||
#ifndef NJOY_SCION_INTEGRATION_FIRSTMOMENTLINEARLOGARITHMIC | ||
#define NJOY_SCION_INTEGRATION_FIRSTMOMENTLINEARLOGARITHMIC | ||
|
||
// system includes | ||
#include <cmath> | ||
|
||
// other includes | ||
#include "scion/integration/IntegratorBase.hpp" | ||
|
||
namespace njoy { | ||
namespace scion { | ||
namespace integration { | ||
|
||
/** | ||
* @class | ||
* @brief First raw moment of a linear-logarithmic panel (y is linear in ln(x)) | ||
* | ||
* The first raw moment or mean is defined as the integral of x * f(x) | ||
* | ||
* The first raw moment of a panel is calculated analytically using the following | ||
* primitive function: | ||
* int x ln(x) = x**2 / 2 ( ln(x) - 1 / 2 ) | ||
* | ||
* Since y is linear in ln(x), the function to be integrated is: | ||
* y = a x ln(x/x1) + y1 x with a = (y2 - y1) / ln(x2/x1) | ||
* | ||
* The integral over the panel is then given by: | ||
* int[x1,x2] y dx = int[x1,x2] a x ln(x/x1) dx + y1 (x2**2 - x1**2) / 2 | ||
* | ||
* By substituting z = x/x1 in the first term, we obtain: | ||
* int[x1,x2] y dx = int[1,x2/x1] a x1**2 z ln(z) dz + y1 (x2**2 - x1**2) / 2 | ||
* which simplifies to (using the primitive): | ||
* int[x1,x2] y dx = a / 2 (x2**2 (ln(x2/x1) - 1 / 2) + x1**2 / 2) + y1 (x2**2 - x1**2) / 2 | ||
*/ | ||
class FirstMomentLinearLogarithmic : public IntegratorBase< FirstMomentLinearLogarithmic > { | ||
|
||
/* friend declarations */ | ||
friend class IntegratorBase< FirstMomentLinearLogarithmic >; | ||
|
||
/* interface implementation functions */ | ||
|
||
/** | ||
* @brief Perform first raw moment integration of a linear-logarithmic panel (y is linear in ln(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 { | ||
|
||
return 0.5 * ( ( yRight - yLeft ) / std::log( xRight / xLeft ) | ||
* ( xRight * xRight * ( std::log( xRight / xLeft ) - 0.5 ) + 0.5 * xLeft * xLeft ) | ||
+ yLeft * ( xRight * xRight - xLeft * xLeft ) ); | ||
} | ||
|
||
public: | ||
|
||
using IntegratorBase::operator(); | ||
}; | ||
|
||
// integration function | ||
static constexpr FirstMomentLinearLogarithmic firstMomentLinLog; | ||
|
||
} // integration namespace | ||
} // scion namespace | ||
} // njoy namespace | ||
|
||
#endif |
1 change: 1 addition & 0 deletions
1
src/scion/integration/FirstMomentLinearLogarithmic/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.FirstMomentLinearLogarithmic FirstMomentLinearLogarithmic.test.cpp ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct me if I'm wrong, but I think this shoul prevent population of ~/.cmake/packages, yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. .cmake is in your user directory.