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
Feature/ldf isotherms #104
Conversation
Work update: Implementation:
Documentation:
|
515cfb7
to
6f3e457
Compare
I did run some tests to check the plausibility of the Langmuir and Bi-Langmuir LDF models by comparing them to the native approach and so far it looks all good! 🥳 |
Great. I hope the next results also come fine |
173a1f0
to
989ea52
Compare
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.
Please add tests for the Freundlich isotherm.
For binding model implementation, tests are really helpful. For example, they check your analytic Jacobian. If you had done this for the Freundlich model, you would've noticed that they fail.
const double n_param = (double)static_cast<ParamType>(p->n[i]); | ||
const double kF = (double)static_cast<ParamType>(p->kF[i]); | ||
const double kkin = (double)static_cast<ParamType>(p->kkin[i]); | ||
double const alpha_1 = ((2 * n_param - 1) / n_param) * kF * std::pow(threshold, (1 - n_param) / n_param); | ||
double const alpha_2 = ((1 - n_param) / n_param) * kF * std::pow(threshold, (1 - 2 * n_param) / n_param); |
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.
Please do not convert the active
types to double
! This will disable parameter sensitivities.
If you need to copy these to local variables, please do
const ParamType& n_param = static_cast<ParamType>(p->n[i]);
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.
Done
double const alpha_1 = ((2 * n_param - 1) / n_param) * kF * std::pow(threshold, (1 - n_param) / n_param); | ||
double const alpha_2 = ((1 - n_param) / n_param) * kF * std::pow(threshold, (1 - 2 * n_param) / n_param); |
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.
Use plain pow
instead of std::pow
. The latter will fail for active
types.
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.
Done
double const alpha_1 = ((2 * n_param - 1) / n_param) * kF * std::pow(threshold, (1 - n_param) / n_param); | ||
double const alpha_2 = ((1 - n_param) / n_param) * kF * std::pow(threshold, (1 - 2 * n_param) / n_param); |
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.
Use plain pow
instead of std::pow
. The latter will fail for active
types.
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.
Done
if (std::abs((double)yCp[i]) < threshold) | ||
res[bndIdx] = kkin * y[bndIdx] - alpha_1 * yCp[i] - alpha_2 * std::pow((double)yCp[i], 2); | ||
else | ||
res[bndIdx] = kkin * y[bndIdx] - kkin * kF * std::pow(std::abs((double)yCp[i]), 1.0 / n_param); | ||
} | ||
else | ||
{ | ||
res[bndIdx] = kkin * y[bndIdx] - kkin * kF * std::pow(std::abs((double)yCp[i]), 1.0 / n_param); |
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.
Same here: No std::pow
or std::abs
, use plain pow
and abs
.
Also: Do not convert to double
.
Sidenote: Why not collect kkin
into a common factor?
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.
Done and put kkin into a common factor.
if (std::abs((double)yCp[i]) < threshold) | ||
res[bndIdx] = kkin * y[bndIdx] - alpha_1 * yCp[i] - alpha_2 * std::pow((double)yCp[i], 2); | ||
else | ||
res[bndIdx] = kkin * y[bndIdx] - kkin * kF * std::pow(std::abs((double)yCp[i]), 1.0 / n_param); | ||
} | ||
else | ||
{ | ||
res[bndIdx] = kkin * y[bndIdx] - kkin * kF * std::pow(std::abs((double)yCp[i]), 1.0 / n_param); |
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.
Same here: No std::pow
or std::abs
, use plain pow
and abs
.
Also: Do not convert to double
.
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.
Done
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.
If I use pow and don't convert it to (double) then I get type error.
add_library(libcadet_object OBJECT ${LIBCADET_SOURCES}) | ||
add_library(libcadet_object OBJECT ${LIBCADET_SOURCES} "model/binding/LangmuirLDFCBinding.cpp") |
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.
Please revert
src/libcadet/CMakeLists.txt
Outdated
add_library(libcadet_nonlinalg_mex STATIC ${LIBCADET_NONLINALG_SOURCES} ${LIBCADET_NONLINALG_MEX_SOURCES}) | ||
add_library(libcadet_nonlinalg_mex STATIC ${LIBCADET_NONLINALG_SOURCES} ${LIBCADET_NONLINALG_MEX_SOURCES} "model/binding/LangmuirLDFCBinding.cpp") |
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.
Please revert
src/libcadet/CMakeLists.txt
Outdated
add_library(libcadet_nonlinalg_mex STATIC ${LIBCADET_NONLINALG_SOURCES} ${LIBCADET_NONLINALG_MEX_SOURCES}) | ||
add_library(libcadet_nonlinalg_mex STATIC ${LIBCADET_NONLINALG_SOURCES} ${LIBCADET_NONLINALG_MEX_SOURCES} "model/binding/LangmuirLDFCBinding.cpp") |
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.
Please revert
src/libcadet/CMakeLists.txt
Outdated
add_library(libcadet_mex STATIC ${LIBCADET_SOURCES}) | ||
add_library(libcadet_mex STATIC ${LIBCADET_SOURCES} "model/binding/LangmuirLDFCBinding.cpp") |
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.
Please revert
src/libcadet/CMakeLists.txt
Outdated
add_library(libcadet_mex STATIC ${LIBCADET_SOURCES}) | ||
add_library(libcadet_mex STATIC ${LIBCADET_SOURCES} "model/binding/LangmuirLDFCBinding.cpp") |
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.
Please revert
6cc103a
to
342fcbe
Compare
Do not merge yet! Because this branch was not properly rebased on master in the past, there are some unwanted changes, especially in the documentation. |
I've fixed the tests, the Jacobians, and (in some cases) the model equations. The tests now pass, the Jacobians should be correct. |
I have tested the implememtation on some known cases and its working and I will discuss the documentation with @schmoelder and try to finalize it in next one or two days. |
This reverts commit efba48e.
…ate major ordering and correcting the required size of the parameters
…nd states for each component in Bi-Langmuir models
Fixes several problems with the model equations and Jacobians of the LDF binding models. Also fixes the tests, which all pass now.
f6b81d4
to
160b4f2
Compare
This branch contains LDF based implementations of Freundlich, Langmuir and Bi-Langmuir isotherms.