Skip to content

Commit

Permalink
Simplifying SingleTableBase
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Jul 24, 2024
1 parent f9cb5ec commit 233f29c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 27 deletions.
1 change: 0 additions & 1 deletion cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ add_subdirectory( src/scion/interpolation/LinearLinear/test )
add_subdirectory( src/scion/interpolation/LinearLogarithmic/test )
add_subdirectory( src/scion/interpolation/LogarithmicLinear/test )
add_subdirectory( src/scion/interpolation/LogarithmicLogarithmic/test )
add_subdirectory( src/scion/interpolation/Table/test )

add_subdirectory( src/scion/linearisation/ToleranceConvergence/test )
add_subdirectory( src/scion/linearisation/MidpointSplit/test )
Expand Down
2 changes: 1 addition & 1 deletion src/scion/interpolation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
#include "scion/interpolation/LinearLogarithmic.hpp"
#include "scion/interpolation/LogarithmicLinear.hpp"
#include "scion/interpolation/LogarithmicLogarithmic.hpp"
#include "scion/interpolation/Table.hpp"

30 changes: 14 additions & 16 deletions src/scion/math/SingleTableBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// other includes
#include "tools/Log.hpp"
#include "scion/interpolation/InterpolationType.hpp"
#include "scion/interpolation/Table.hpp"
#include "scion/linearisation/ToleranceConvergence.hpp"
#include "scion/linearisation/MidpointSplit.hpp"
#include "scion/linearisation/Lineariser.hpp"
Expand All @@ -32,8 +31,6 @@ namespace math {

/* type aliases */
using Parent = FunctionBase< Derived, X, Y >;
using Table = interpolation::Table< Interpolator,
XContainer, YContainer >;

public:

Expand All @@ -43,11 +40,21 @@ namespace math {
private:

/* fields */
Table table_;
Interpolator interpolator_;
XContainer x_;
YContainer y_;

/* auxiliary function */
#include "scion/math/SingleTableBase/src/verifyTable.hpp"

/**
* @brief Return the panel interpolator
*/
const Interpolator& interpolator() const noexcept {

return this->interpolator_;
}

protected:

/* constructor */
Expand All @@ -70,15 +77,15 @@ namespace math {
*/
const XContainer& x() const noexcept {

return this->table_.x();
return this->x_;
}

/**
* @brief Return the y values of the table
*/
const YContainer& y() const noexcept {

return this->table_.y();
return this->y_;
}

/**
Expand All @@ -89,16 +96,7 @@ namespace math {
return this->x().size();
}

/**
* @brief Evaluate the function for a value of x
*
* @param x the value to be evaluated
*/
Y evaluate( const X& x ) const {

return this->table_.evaluate( x );
}

#include "scion/math/SingleTableBase/src/evaluate.hpp"
#include "scion/math/SingleTableBase/src/linearise.hpp"

using Parent::domain;
Expand Down
15 changes: 7 additions & 8 deletions src/scion/math/SingleTableBase/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
private:

/**
* @brief Private intermediate constructor
* @brief Private constructor
*/
SingleTableBase( Table&& table ) :
Parent( IntervalDomain( table.x().front(), table.x().back() ) ),
table_( std::move( table ) ) {

verifyTable( this->table_.x(), this->table_.y() );
}
SingleTableBase( IntervalDomain< X >&& domain, XContainer&& x, YContainer&& y ) :
Parent( std::move( domain ) ), interpolator_(),
x_( std::move( x ) ), y_( std::move( y ) ) {}

protected:

Expand All @@ -19,4 +16,6 @@ SingleTableBase( Table&& table ) :
* @param y the y values of the tabulated data
*/
SingleTableBase( XContainer x, YContainer y ) :
SingleTableBase( Table( std::move( x ), std::move( y ) ) ) {}
SingleTableBase( verifyTableAndRetrieveDomain( x, y ),
std::move( x ), std::move( y ) ) {}

32 changes: 31 additions & 1 deletion src/scion/math/SingleTableBase/src/verifyTable.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
static void verifyTable( const XContainer& x, const YContainer& y ) {
static IntervalDomain< X >
verifyTableAndRetrieveDomain( const XContainer& x, const YContainer& y ) {

if ( ( ! verification::isAtLeastOfSize( x, 2 ) ) ||
( ! verification::isAtLeastOfSize( y, 2 ) ) ) {

Log::error( "Insufficient x or y values defined for tabulated data "
"with a single interpolation type (at least 2 points are "
"required)" );
Log::info( "x.size(): {}", x.size() );
Log::info( "y.size(): {}", y.size() );
throw std::exception();
}

if ( ! verification::isSameSize( x, y ) ) {

Log::error( "Inconsistent number of x and y values for tabulated data "
"with a single interpolation type" );
Log::info( "x.size(): {}", x.size() );
Log::info( "y.size(): {}", y.size() );
throw std::exception();
}

if ( ! verification::isSorted( x ) ) {

Log::error( "The x values do not appear to be in ascending order for "
"tabulated data with a single interpolation type" );
throw std::exception();
}

if ( ! verification::isUnique( x ) ) {

Expand All @@ -13,4 +41,6 @@ static void verifyTable( const XContainer& x, const YContainer& y ) {
}
throw std::exception();
}

return IntervalDomain( x.front(), x.back() );
}

0 comments on commit 233f29c

Please sign in to comment.