-
Notifications
You must be signed in to change notification settings - Fork 2
Table Integration #10
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
Open
HunterBelanger
wants to merge
31
commits into
njoy:master
Choose a base branch
from
HunterBelanger:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
ec0ae64
adds integration to Histogram
HunterBelanger 36bab58
adds integration to LinearLinear
HunterBelanger 9ec3289
adds integration to LinearLogarithmic
HunterBelanger abc97df
move LinearLogarithmic tests to their own file
HunterBelanger 9d668e9
adds LogarithmicLinear integragion. Must modify to reduce error
HunterBelanger cb99e3a
added build directory to .gitignore
HunterBelanger b81bdf2
remove currently unneeded <iostream> header
HunterBelanger a07f4fa
adds integration to LogarithmicLogarithmic
HunterBelanger 6b5cd65
adds basic integration for basic table (Ex1)
HunterBelanger 9e6b127
fixes bug in integration over more than one interval
HunterBelanger fa58f1f
adjusted formatting
HunterBelanger a72bce0
Adds integration to Variant tables
HunterBelanger 6917281
changes name of do_integrate to integrate. Necessary for template mag…
HunterBelanger 8239671
Adds integration for domain Min and Max decorators
HunterBelanger e7c8bca
Add integration compatability to left and right intervals
HunterBelanger 6c1f8d4
Changes for agreement with style guide
HunterBelanger 0b49b1a
throw logic_error when trying to integrating a table with transformat…
HunterBelanger 2aa6e3c
Adds integration to Vector table
HunterBelanger 39059d2
Adds unit tests for integration of Type
HunterBelanger 815d075
Adds unit tests for integration of Type
HunterBelanger 135f27e
Adds to unit test for Variant
HunterBelanger 61b5bae
Adds to unit test for Vector
HunterBelanger f78afb6
Adds to unit test for domain.max
HunterBelanger 342e9f1
Adds to unit test for domain.min
HunterBelanger d10d124
Adds to unit tests for left
HunterBelanger f3a5805
Adds to unit tests for right
HunterBelanger 8f0f212
Adds to unit test for transform
HunterBelanger 20cdaff
Adds some integration to a few of the examples
HunterBelanger dc4d839
Adds one integration example to readme
HunterBelanger 9710c07
Fixes unit tests for LogarithmicLinear
HunterBelanger a0e728b
Removes unused F1 and F2 lambdas from LinearLogarithmic interpolate t…
HunterBelanger 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| bin | ||
| build |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
91 changes: 91 additions & 0 deletions
91
src/interpolation/Interpolant/LinearLogarithmic/test/integration.test.cpp
This file contains hidden or 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,91 @@ | ||
| #include "catch.hpp" | ||
| #include "interpolation.hpp" | ||
|
|
||
| #include "dimwits.hpp" | ||
|
|
||
| #include "range/v3/view/take.hpp" | ||
|
|
||
| using namespace njoy::interpolation; | ||
| using namespace dimwits; | ||
|
|
||
| SCENARIO("The LinearLogarithmic interpolant computes the correct integral", | ||
| "[interpolant], [LinearLogarithmic]"){ | ||
| std::vector<double> xValues{ 1E-2, 1, 10 }; | ||
| auto f1 = []( double x ){ return 13.2 * std::log(3.2*x); }; | ||
| auto f2 = []( double x ){ return -5.6 * std::log(2.4*x); }; | ||
| auto F1 = [](double x){return 13.2*x*(std::log(3.2*x)-1.);}; | ||
| auto F2 = [](double x){return -5.6*x*(std::log(2.4*x)-1.);}; | ||
|
|
||
| auto avg = | ||
| []( double xLeft, double xRight ){ return 0.5 * ( xLeft + xRight ); }; | ||
|
|
||
| auto excessiveError = | ||
| []( double reference, double trial ){ | ||
| auto error = std::abs( (trial - reference) | ||
| / ( ( reference != 0 ) ? reference : 1.0 ) ); | ||
| return error > 1E-15; }; | ||
|
|
||
| auto iterator = xValues.begin(); | ||
| auto last = std::prev( xValues.end() ); | ||
| do { | ||
| double xLeft = *iterator, xRight = *( ++iterator ); | ||
| double y1Left = f1( xLeft ), y1Right = f1( xRight ); | ||
| double y2Left = f2( xLeft ), y2Right = f2( xRight ); | ||
| double xBar = avg( xLeft, xRight ); | ||
| double xLow = xLeft, xHi = xRight; | ||
|
|
||
| REQUIRE( not excessiveError( F1(xBar) - F1(xLow), | ||
| LinearLogarithmic::integrate | ||
| ( xLow, xBar, xLeft, xRight, y1Left, y1Right ) ) ); | ||
| REQUIRE( not excessiveError( F2(xBar) - F2(xLow), | ||
| LinearLogarithmic::integrate | ||
| ( xLow, xBar, xLeft, xRight, y2Left, y2Right ) ) ); | ||
|
|
||
| REQUIRE( not excessiveError( F1(xHi) - F1(xBar), | ||
| LinearLogarithmic::integrate | ||
| ( xBar, xHi, xLeft, xRight, y1Left, y1Right ) ) ); | ||
| REQUIRE( not excessiveError( F2(xHi) - F2(xBar), | ||
| LinearLogarithmic::integrate | ||
| ( xBar, xHi, xLeft, xRight, y2Left, y2Right ) ) ); | ||
| } while( iterator != last ); | ||
| } | ||
|
|
||
| SCENARIO("The LinearLogarithmic interpolant integration is compatible with units", | ||
| "[interpolant], [LinearLogarithmic]"){ | ||
| std::vector< double > xValues{ 1E-2, 1, 10 }; | ||
| auto f1 = []( auto x ){ return 13.2 * std::log(3.2 * x.value) * barn; }; | ||
| auto f2 = []( auto x ){ return -5.6 * std::log(2.4 * x.value) * barn; }; | ||
| auto F1 = []( auto x ){return 13.2*x.value*(std::log(3.2*x.value)-1.) * barn * electronVolts;}; | ||
| auto F2 = []( auto x ){return -5.6*x.value*(std::log(2.4*x.value)-1.) * barn * electronVolts;}; | ||
|
|
||
| auto avg = []( auto xLeft, auto xRight ) { return 0.5 * ( xLeft + xRight ); }; | ||
|
|
||
| auto excessiveError = | ||
| []( auto reference, auto trial ){ | ||
| auto error = std::abs( (trial - reference).value | ||
| / ( ( reference.value != 0 ) ? | ||
| reference.value : 1.0 ) ); | ||
| return error > 1E-15; }; | ||
|
|
||
| auto units = xValues | | ||
| ranges::view::take( xValues.size() - 1 ) | | ||
| ranges::view::transform( []( auto arg ){ return arg * electronVolts; } ); | ||
|
|
||
| auto iterator = units.begin(); | ||
| auto last = units.end(); | ||
| do { | ||
| auto xLeft = *iterator, xRight = *( ++iterator ); | ||
| auto y1Left = f1( xLeft ), y1Right = f1( xRight ); | ||
| auto y2Left = f2( xLeft ), y2Right = f2( xRight ); | ||
| auto xBar = avg( xLeft, xRight ); | ||
| auto xLow = xLeft, xHi = xRight; | ||
|
|
||
| REQUIRE( not excessiveError( F2(xBar) - F2(xLow), | ||
| LinearLogarithmic::integrate | ||
| ( xLow, xBar, xLeft, xRight, y2Left, y2Right ) ) ); | ||
|
|
||
| REQUIRE( not excessiveError( F1(xHi) - F1(xBar), | ||
| LinearLogarithmic::integrate | ||
| ( xBar, xHi, xLeft, xRight, y1Left, y1Right ) ) ); | ||
| } while( iterator != last ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
91 changes: 91 additions & 0 deletions
91
src/interpolation/Interpolant/LogarithmicLinear/test/integration.test.cpp
This file contains hidden or 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,91 @@ | ||
| #include "catch.hpp" | ||
| #include "interpolation.hpp" | ||
|
|
||
| #include "dimwits.hpp" | ||
|
|
||
| #include "range/v3/view/take.hpp" | ||
|
|
||
| using namespace njoy::interpolation; | ||
|
|
||
| SCENARIO("The LogarithmicLinear interpolant computes the correct integral", | ||
| "[interpolant], [LogarithmicLinear]"){ | ||
| std::vector<double> xValues {10, 1, 1E-1}; | ||
| auto f1 = []( double x ){ return 13.2 * pow(3.14, 0.002*x); }; | ||
| auto f2 = []( double x ){ return -13.2 * pow(3.14, 0.002*x); }; | ||
| auto F1 = []( double xl, double xh ){ return (13.2/(0.002*std::log(3.14)))*(pow(3.14, 0.002*xh) - pow(3.14, 0.002*xl));}; | ||
| auto F2 = []( double xl, double xh ){ return (-13.2/(0.002*std::log(3.14)))*(pow(3.14, 0.002*xh) - pow(3.14, 0.002*xl));}; | ||
| //auto F2 = []( double x ){ return (-13.2*pow(3.14, 0.002*x))/(0.002*std::log(3.14));}; | ||
| auto avg = []( double xLeft, double xRight ){ return 0.5 * ( xLeft + xRight ); }; | ||
|
|
||
| auto excessiveError = | ||
| []( double reference, double trial ){ | ||
| auto error = std::abs( (trial - reference) | ||
| / ( ( reference != 0 ) ? reference : 1.0 ) ); | ||
| return error > 1E-13; }; | ||
|
|
||
| auto iterator = xValues.begin(); | ||
| auto last = std::prev( xValues.end() ); | ||
| do { | ||
| double xLeft = *iterator, xRight = *( ++iterator ); | ||
| double y1Left = f1( xLeft ), y1Right = f1( xRight ); | ||
| double y2Left = f2( xLeft ), y2Right = f2( xRight ); | ||
| double xBar = avg( xLeft, xRight ); | ||
| double xLow = xLeft, xHi = xRight; | ||
|
|
||
| REQUIRE( not excessiveError( F1(xLow, xBar), | ||
| LogarithmicLinear::integrate | ||
| ( xLow, xBar, xLeft, xRight, y1Left, y1Right ) ) ); | ||
| REQUIRE( not excessiveError( F2(xLow, xBar), | ||
| LogarithmicLinear::integrate | ||
| ( xLow, xBar, xLeft, xRight, y2Left, y2Right ) ) ); | ||
|
|
||
| REQUIRE( not excessiveError( F1(xBar, xHi), | ||
| LogarithmicLinear::integrate | ||
| ( xBar, xHi, xLeft, xRight, y1Left, y1Right ) ) ); | ||
| REQUIRE( not excessiveError( F2(xBar, xHi), | ||
| LogarithmicLinear::integrate | ||
| ( xBar, xHi, xLeft, xRight, y2Left, y2Right ) ) ); | ||
| } while( iterator != last ); | ||
| } | ||
|
|
||
| using namespace dimwits; | ||
|
|
||
| SCENARIO("The LogarithmicLinear integration is compatible with units", | ||
| "[interpolant], [LinearLogarithmic]"){ | ||
| std::vector< double > xValues{ 1E-2, 1, 10 }; | ||
| auto f1 = []( auto x ){ return 13.2 * pow(3.14, 0.002*x.value) * barn; }; | ||
| auto f2 = []( auto x ){ return -13.2 * pow(3.14, 0.002*x.value) * barn; }; | ||
| auto F1 = []( auto x ){ return (13.2*pow(3.14, 0.002*x.value))/(0.002*std::log(3.14))*barn*electronVolts;}; | ||
| auto F2 = []( auto x ){ return (-13.2*pow(3.14, 0.002*x.value))/(0.002*std::log(3.14))*barn*electronVolts;}; | ||
| auto avg = []( auto xLeft, auto xRight ) { return 0.5 * ( xLeft + xRight ); }; | ||
|
|
||
| auto excessiveError = | ||
| []( auto reference, auto trial ){ | ||
| auto error = std::abs( (reference - trial).value | ||
| / ( ( reference.value != 0 ) ? | ||
| reference.value : 1.0 ) ); | ||
| return error > 1E-13; }; | ||
|
|
||
| auto units = xValues | | ||
| ranges::view::take( xValues.size() - 1 ) | | ||
| ranges::view::transform( []( auto arg ){ return arg * electronVolts; } ); | ||
|
|
||
| auto iterator = units.begin(); | ||
| auto last = units.end(); | ||
| do { | ||
| auto xLeft = *iterator, xRight = *( ++iterator ); | ||
| auto y1Left = f1( xLeft ), y1Right = f1( xRight ); | ||
| auto y2Left = f2( xLeft ), y2Right = f2( xRight ); | ||
| auto xBar = avg( xLeft, xRight ); | ||
| auto xLow = xLeft, xHi = xRight; | ||
|
|
||
| REQUIRE( not excessiveError( F2(xBar) - F2(xLow), | ||
| LogarithmicLinear::integrate | ||
| ( xLow, xBar, xLeft, xRight, y2Left, y2Right ) ) ); | ||
|
|
||
| REQUIRE( not excessiveError( F1(xHi) - F1(xBar), | ||
| LogarithmicLinear::integrate | ||
| ( xBar, xHi, xLeft, xRight, y1Left, y1Right ) ) ); | ||
|
|
||
| } while( iterator != last ); | ||
| } |
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
src/interpolation/Interpolant/LogarithmicLogarithmic/test/CMakeLists.txt
This file contains hidden or 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
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.
You create
F1andF2here, but do you use them anywhere?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.
No, those should be removed from there. Initially, I had put the integration tests in the
interpolate.test.cppfile, but later moved them to theintegration.test.cppfile to keep things somewhat separated. I must have forgotten to remove these two lines. I will add a commit to remove them.