+
Skip to content

Added overload for derivative and dderivative #116

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
wants to merge 5 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ecl_geometry/include/ecl/geometry/cubic_spline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class ECL_PUBLIC CubicSpline : public BluePrintFactory< CubicSpline > {
* @exception : StandardException : throws if input x value is outside the spline range [debug mode only].
*/
double operator()(const double &x) const;
std::map<int, double> operator()(int last_index, const double &x);
/**
* @brief Spline derivative.
*
Expand All @@ -186,6 +187,7 @@ class ECL_PUBLIC CubicSpline : public BluePrintFactory< CubicSpline > {
* @exception : StandardException : throws if input x value is outside the spline range [debug mode only].
*/
double derivative(double x) const;
std::map<int, double> derivative(const int &last_index, const double &x) const;
/**
* @brief Spline second derivative.
*
Expand All @@ -195,7 +197,7 @@ class ECL_PUBLIC CubicSpline : public BluePrintFactory< CubicSpline > {
* @exception : StandardException : throws if input x value is outside the spline range [debug mode only].
*/
double dderivative(double x) const;

std::map<int, double> dderivative(const int &last_index, const double &x) const;
/**
* @brief The discretised domain for this spline.
*
Expand Down
7 changes: 6 additions & 1 deletion ecl_geometry/include/ecl/geometry/smooth_linear_spline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class ecl_geometry_PUBLIC SmoothLinearSpline {
* @exception : StandardException : throws if x is outside the spline range [debug mode only].
*/
double operator()(const double &x) const;
std::map<int, double> operator()(const int &last_index,const double &x) const;

/**
* @brief Spline derivative.
*
Expand All @@ -99,6 +101,8 @@ class ecl_geometry_PUBLIC SmoothLinearSpline {
* @exception : StandardException : throws if x is outside the spline range [debug mode only].
*/
double derivative(const double &x) const;
std::map<int, double> derivative(const int &last_index, const double &x) const;

/**
* @brief Spline second derivative.
*
Expand All @@ -108,6 +112,7 @@ class ecl_geometry_PUBLIC SmoothLinearSpline {
* @exception : StandardException : throws if x is outside the spline range [debug mode only].
*/
double dderivative(const double &x) const;
std::map<int, double> dderivative(const int &last_index, const double &x) const;

/**
* @brief The discretised domain for this spline.
Expand Down Expand Up @@ -150,7 +155,7 @@ class ecl_geometry_PUBLIC SmoothLinearSpline {
* @brief Streaming output insertion operator for smoothed linear splines.
*
* Streaming output insertion operator for smoothed linear splines. This
* simply lists the spline segments and corners (linear functions and
* simply lists the spline segments and corners (linear functions andTensionSpline
* quintic polynomials) in algebraic form.
*
* @tparam OutputStream : the type of stream being used.
Expand Down
7 changes: 7 additions & 0 deletions ecl_geometry/include/ecl/geometry/tension_spline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <ecl/exceptions/standard_exception.hpp>
#include <ecl/utilities/blueprints.hpp>
#include "macros.hpp"
#include <map>

/*****************************************************************************
** Namespaces
Expand Down Expand Up @@ -156,6 +157,8 @@ class ecl_geometry_PUBLIC TensionSpline : public BluePrintFactory< TensionSpline
* @exception : StandardException : throws if x is outside the spline range [debug mode only].
*/
double operator()(const double &x) const;

std::map<int, double> operator()(const int &last_index, const double &x) const;
/**
* @brief Spline derivative.
*
Expand All @@ -167,6 +170,8 @@ class ecl_geometry_PUBLIC TensionSpline : public BluePrintFactory< TensionSpline
* @exception : StandardException : throws if x is outside the spline range [debug mode only].
*/
double derivative(const double &x) const;

std::map<int, double> derivative(const int &last_index, const double &x) const;
/**
* @brief Spline second derivative.
*
Expand All @@ -177,6 +182,8 @@ class ecl_geometry_PUBLIC TensionSpline : public BluePrintFactory< TensionSpline
*/
double dderivative(const double &x) const;

std::map<int, double> dderivative(const int &last_index, const double &x) const;

/**
* @brief The discretised domain for this spline.
*
Expand Down
31 changes: 31 additions & 0 deletions ecl_geometry/src/lib/cubic_spline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ double CubicSpline::operator()(const double &x) const {
return cubic_polynomials[index](x);
}

std::map<int, double> CubicSpline::operator()(int last_index, const double &x) {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = last_index;
while ( x > discretised_domain[index+1] ) {
++index;
}
std::map<int, double> m = {{index, cubic_polynomials[index](x)}};
return m;
}

double CubicSpline::derivative(double x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = 0;
Expand All @@ -44,6 +54,16 @@ double CubicSpline::derivative(double x) const {
return cubic_polynomials[index].derivative()(x);
}

std::map<int, double> CubicSpline::derivative(const int &last_index, const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = last_index;
while ( x > discretised_domain[index+1] ) {
++index;
}
std::map<int, double> m = {{index, cubic_polynomials[index].derivative()(x)}};
return m;
}

double CubicSpline::dderivative(double x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = 0;
Expand All @@ -53,4 +73,15 @@ double CubicSpline::dderivative(double x) const {
return cubic_polynomials[index].derivative().derivative()(x);
}

std::map<int, double> CubicSpline::dderivative(const int &last_index, const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = last_index;
while ( x > discretised_domain[index+1] ) {
++index;
}
std::map<int, double> m = {{index, cubic_polynomials[index].derivative().derivative()(x)}};
return m;
}


} // namespace ecl
49 changes: 49 additions & 0 deletions ecl_geometry/src/lib/smooth_linear_spline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ double SmoothLinearSpline::operator()(const double &x) const {
}
}

std::map<int, double> SmoothLinearSpline::operator()(const int &last_index, const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = last_index;
while ( x > discretised_domain[index+1] ) {
++index;
}
if ( index % 2 == 0 ) { // linear
std::map<int,double> m = {{index,segments[index/2](x)}};
return m;
} else { // quintic
std::map<int,double> m = {{index, corners[(index-1)/2](x)}};
return m;
}
}

double SmoothLinearSpline::derivative(const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = 0;
Expand All @@ -135,6 +150,23 @@ double SmoothLinearSpline::derivative(const double &x) const {
}
}

std::map<int, double> SmoothLinearSpline::derivative(const int &last_index, const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = last_index;
while ( x > discretised_domain[index+1] ) {
++index;
}
std::map<int, double> m;
if ( index % 2 == 0 )
{ // linear
std::map<int,double> m = {{index,segments[index/2].derivative(x)}};
return m;
} else { // quintic
std::map<int,double> m = {{index,corners[(index-1)/2].derivative(x)}};
return m;
}
}

double SmoothLinearSpline::dderivative(const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = 0;
Expand All @@ -148,6 +180,23 @@ double SmoothLinearSpline::dderivative(const double &x) const {
}
}

std::map<int, double> SmoothLinearSpline::dderivative(const int &last_index, const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = last_index;
while ( x > discretised_domain[index+1] ) {
++index;
}
std::map<int, double> m;
if ( index % 2 == 0 )
{ // linear
std::map<int,double> m = {{index,segments[index/2].dderivative(x)}};
return m;
} else { // quintic
std::map<int,double> m = {{index,corners[(index-1)/2].dderivative(x)}};
return m;
}
}

} // namespace ecl


Expand Down
30 changes: 30 additions & 0 deletions ecl_geometry/src/lib/tension_spline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ double TensionSpline::operator()(const double &x) const {
return functions[index](tension,x);
}

std::map<int, double> TensionSpline::operator()(const int &last_index, const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = last_index;
while ( x > discretised_domain[index+1] ) {
++index;
}
std::map<int, double> m = {{index, functions[index](tension,x)}};
return m;
}

double TensionSpline::derivative(const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = 0;
Expand All @@ -44,6 +54,16 @@ double TensionSpline::derivative(const double &x) const {
return functions[index].derivative(tension,x);
}

std::map<int, double> TensionSpline::derivative(const int &last_index, const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = last_index;
while ( x > discretised_domain[index+1] ) {
++index;
}
std::map<int, double> m = {{index, functions[index].derivative(tension,x)}};
return m;
}

double TensionSpline::dderivative(const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = 0;
Expand All @@ -53,4 +73,14 @@ double TensionSpline::dderivative(const double &x) const {
return functions[index].dderivative(tension,x);
}

std::map<int, double> TensionSpline::dderivative(const int &last_index, const double &x) const {
ecl_assert_throw( ( ( x >= discretised_domain.front() ) && ( x <= discretised_domain.back() ) ), StandardException(LOC,OutOfRangeError) );
int index = last_index;
while ( x > discretised_domain[index+1] ) {
++index;
}
std::map<int, double> m = {{index, functions[index].dderivative(tension, x)}};
return m;
}

} // namespace ecl
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载