Skip to content

Commit

Permalink
Merge pull request #77 from njoy/feature/legendre-normalisation
Browse files Browse the repository at this point in the history
Feature/legendre normalisation
  • Loading branch information
whaeck authored Sep 9, 2024
2 parents 003ae3b + c52a805 commit 5b724ee
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/scion/math/LegendreSeries/test/LegendreSeries.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ SCENARIO( "LegendreSeries" ) {
CHECK( false == chunk.isSameDomain( OpenDomain< double >() ) );
} // THEN

THEN( "a PolynomialSeries can be linearised" ) {
THEN( "a LegendreSeries can be linearised" ) {

ToleranceConvergence< double > convergence( 0.01 );
InterpolationTable< double > linear = chunk.linearise( convergence );
Expand Down
4 changes: 2 additions & 2 deletions src/scion/math/SeriesBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ namespace math {
/* methods */

/**
* @brief Return the Legendre coefficients
* @brief Return the series coefficients
*/
const std::vector< Y >& coefficients() const noexcept {

return this->coefficients_;
}

/**
* @brief Return the Legendre order
* @brief Return the series order
*/
unsigned int order() const noexcept {

Expand Down
4 changes: 4 additions & 0 deletions src/scion/math/SeriesBase/src/ctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ SeriesBase() = default;
/**
* @brief Constructor
*
* There must be at least 1 coefficient. Trailing zeros in the coefficients are
* removed (if all are zero, a single zero coefficient will remain).
*
* @param coefficients the coefficients of the series (from lowest to highest
* order coefficient)
* @param domain the domain of the series
Expand All @@ -15,4 +18,5 @@ SeriesBase( DomainVariant domain, std::vector< Y > coefficients ) :
coefficients_( std::move( coefficients ) ) {

verifyCoefficients( this->coefficients() );
this->trimCoefficients();
}
10 changes: 8 additions & 2 deletions src/scion/math/SeriesBase/src/trimCoefficients.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
void trimCoefficients() {

// this removes trailing zeros in the coefficients
// if all coefficients are zero, it leaves a single order 0 coefficient
// equal to zero

if ( 0.0 == this->coefficients().back() ) {
if ( Y( 0. ) == this->coefficients().back() ) {

const auto iter =
std::find_if( this->coefficients().rbegin(), this->coefficients().rend(),
[] ( auto&& coefficient ) { return coefficient != 0.; } );
[] ( auto&& coefficient ) { return coefficient != Y( 0. ); } );
this->coefficients_.erase( iter.base(), this->coefficients_.end() );
if ( this->coefficients_.size() == 0 ) {

this->coefficients_.push_back( Y( 0. ) );
}
}
}

0 comments on commit 5b724ee

Please sign in to comment.