-
Notifications
You must be signed in to change notification settings - Fork 26
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
Use a piecewise cubic polynomial for charateristic charge in GIEX adsorption model #97
Open
sleweke
wants to merge
8
commits into
master
Choose a base branch
from
feature/giex_spline
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eb9fde1
Add vector valued parameters
sleweke 5fc9b89
Convert nu to piecewise cubic poly in GIEX model
sleweke 3558279
Decouple validation and config in binding base
sleweke 4b69dc0
Decouple validation and config in reaction base
sleweke 25c2ea7
Fix bugs in GIEX parameter configuration
sleweke c4b2a98
Fix more bugs in GIEX adsorption model
sleweke b834e8c
Fix bug in computing number of GIEX spline pieces
sleweke d804b30
Remove debug logging
sleweke 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
// ============================================================================= | ||
// CADET | ||
// | ||
// Copyright © 2008-2021: The CADET Authors | ||
// Please see the AUTHORS and CONTRIBUTORS file. | ||
// | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the GNU Public License v3.0 (or, at | ||
// your option, any later version) which accompanies this distribution, and | ||
// is available at http://www.gnu.org/licenses/gpl.html | ||
// ============================================================================= | ||
|
||
#ifndef LIBCADET_SPLINE_HPP_ | ||
#define LIBCADET_SPLINE_HPP_ | ||
|
||
#include <algorithm> | ||
#include <tuple> | ||
|
||
#include "cadet/cadetCompilerInfo.hpp" | ||
#include "AutoDiff.hpp" | ||
|
||
namespace cadet | ||
{ | ||
|
||
/** | ||
* @brief Evaluates a piecewise cubic polynomial | ||
* @details If the evaluation point @p x is outside the domain of the piecewise polynomial, | ||
* constant extrapolation from the first and last value of the polynomial on its | ||
* domain is applied. | ||
* @param[in] x Evaluation position | ||
* @param[in] breaks Array with @c nPieces+1 elements (strictly increasing) that defines the domain pieces | ||
* @param[in] constCoeff Array with constant coefficients of size @p nPieces | ||
* @param[in] linCoeff Array with linear coefficients of size @p nPieces | ||
* @param[in] quadCoeff Array with quadratic coefficients of size @p nPieces | ||
* @param[in] cubeCoeff Array with cubic coefficients of size @p nPieces | ||
* @param[in] nPieces Number of pieces (at least 1) | ||
* @tparam value_t Type of the evaluation point | ||
* @tparam result_t Type of the result | ||
* @return Value of the piecewise cubic polynomial at the given point @p x | ||
*/ | ||
template <typename value_t, typename result_t> | ||
result_t evaluateCubicPiecewisePolynomial(const value_t& x, active const* breaks, active const* constCoeff, | ||
active const* linCoeff, active const* quadCoeff, active const* cubeCoeff, int nPieces) CADET_NOEXCEPT | ||
{ | ||
// Test if outside of domain, apply constant extrapolation | ||
if (x < breaks[0]) | ||
{ | ||
return constCoeff[0]; | ||
} | ||
|
||
if (x >= breaks[nPieces]) | ||
{ | ||
// Return the value at the right of the domain | ||
const result_t y = static_cast<result_t>(breaks[nPieces]) - static_cast<result_t>(breaks[nPieces - 1]); | ||
const int idx = nPieces - 1; | ||
return static_cast<result_t>(constCoeff[idx]) + y * ( | ||
static_cast<result_t>(linCoeff[idx]) + y * ( | ||
static_cast<result_t>(quadCoeff[idx]) + y * static_cast<result_t>(cubeCoeff[idx]) | ||
) | ||
); | ||
} | ||
|
||
// Find correct piece | ||
int idx = 0; | ||
for (; idx < nPieces; ++idx) | ||
{ | ||
if (breaks[idx] >= x) | ||
break; | ||
} | ||
|
||
// Evaluate polynomial | ||
const typename DoubleActivePromoter<value_t, result_t>::type y = x - static_cast<result_t>(breaks[idx]); | ||
return static_cast<result_t>(constCoeff[idx]) + y * ( | ||
static_cast<result_t>(linCoeff[idx]) + y * ( | ||
static_cast<result_t>(quadCoeff[idx]) + y * static_cast<result_t>(cubeCoeff[idx]) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @brief Evaluates a piecewise cubic polynomial and returns base and dependent values | ||
* @details If the evaluation point @p x is outside the domain of the piecewise polynomial, | ||
* constant extrapolation from the first and last value of the polynomial on its | ||
* domain is applied. | ||
* | ||
* The function returns the constant base value and the variable part depending on @p x. | ||
* @param[in] x Evaluation position | ||
* @param[in] breaks Array with @c nPieces+1 elements (strictly increasing) that defines the domain pieces | ||
* @param[in] constCoeff Array with constant coefficients of size @p nPieces | ||
* @param[in] linCoeff Array with linear coefficients of size @p nPieces | ||
* @param[in] quadCoeff Array with quadratic coefficients of size @p nPieces | ||
* @param[in] cubeCoeff Array with cubic coefficients of size @p nPieces | ||
* @param[in] nPieces Number of pieces (at least 1) | ||
* @tparam value_t Type of the evaluation point | ||
* @tparam result_t Type of the result | ||
* @return Constant and dynamic value of the piecewise cubic polynomial at the given point @p x | ||
*/ | ||
template <typename value_t, typename result_t> | ||
std::tuple<result_t, result_t> evaluateCubicPiecewisePolynomialSplit(const value_t& x, active const* breaks, active const* constCoeff, | ||
active const* linCoeff, active const* quadCoeff, active const* cubeCoeff, int nPieces) CADET_NOEXCEPT | ||
{ | ||
// Test if outside of domain, apply constant extrapolation | ||
if (x < breaks[0]) | ||
{ | ||
return {static_cast<result_t>(constCoeff[0]), result_t(0.0)}; | ||
} | ||
|
||
if (x >= breaks[nPieces]) | ||
{ | ||
// Return the value at the right of the domain | ||
const result_t y = static_cast<result_t>(breaks[nPieces]) - static_cast<result_t>(breaks[nPieces - 1]); | ||
const int idx = nPieces - 1; | ||
return {static_cast<result_t>(constCoeff[idx]) + y * ( | ||
static_cast<result_t>(linCoeff[idx]) + y * ( | ||
static_cast<result_t>(quadCoeff[idx]) + y * static_cast<result_t>(cubeCoeff[idx]) | ||
) | ||
), result_t(0.0)}; | ||
} | ||
|
||
// Find correct piece | ||
int idx = 0; | ||
for (; idx < nPieces; ++idx) | ||
{ | ||
if (breaks[idx] >= x) | ||
break; | ||
} | ||
|
||
// Evaluate polynomial | ||
const typename DoubleActivePromoter<value_t, result_t>::type y = x - static_cast<result_t>(breaks[idx]); | ||
return {static_cast<result_t>(constCoeff[idx]), y * ( | ||
static_cast<result_t>(linCoeff[idx]) + y * ( | ||
static_cast<result_t>(quadCoeff[idx]) + y * static_cast<result_t>(cubeCoeff[idx]) | ||
) | ||
)}; | ||
} | ||
|
||
/** | ||
* @brief Evaluates the derivative of a piecewise cubic polynomial | ||
* @details If the evaluation point @p x is outside the domain of the piecewise polynomial, | ||
* constant extrapolation from the first and last value of the polynomial on its | ||
* domain is applied. | ||
* @param[in] x Evaluation position | ||
* @param[in] breaks Array with @c nPieces+1 elements (strictly increasing) that defines the domain pieces | ||
* @param[in] linCoeff Array with linear coefficients of size @p nPieces | ||
* @param[in] quadCoeff Array with quadratic coefficients of size @p nPieces | ||
* @param[in] cubeCoeff Array with cubic coefficients of size @p nPieces | ||
* @param[in] nPieces Number of pieces (at least 1) | ||
* @return Derivative of the piecewise cubic polynomial at the given point @p x | ||
*/ | ||
inline double evaluateCubicPiecewisePolynomialDerivative(double x, active const* breaks, active const* linCoeff, | ||
active const* quadCoeff, active const* cubeCoeff, int nPieces) CADET_NOEXCEPT | ||
{ | ||
// Test if outside of domain, apply constant extrapolation | ||
if (x < breaks[0]) | ||
return 0.0; | ||
|
||
if (x >= breaks[nPieces]) | ||
return 0.0; | ||
|
||
// Find correct piece | ||
int idx = 0; | ||
for (; idx < nPieces; ++idx) | ||
{ | ||
if (breaks[idx] >= x) | ||
break; | ||
} | ||
|
||
// Evaluate polynomial | ||
const double y = x - static_cast<double>(breaks[idx]); | ||
return static_cast<double>(linCoeff[idx]) + y * (2.0 * static_cast<double>(quadCoeff[idx]) + 3.0 * y * static_cast<double>(cubeCoeff[idx])); | ||
} | ||
|
||
} // namespace cadet | ||
|
||
#endif // LIBCADET_SPLINE_HPP_ |
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.
Is this really NCOMP or rather NBOUND?
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.
It's
NCOMP
. Each component has at most 1 bound state. Entries of non-binding components are ignored (but must be present just in the other adsorption models).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.
Ok, good! Otherwise setting up the config would be a nightmare! ^^