Skip to content

Commit

Permalink
Add binding model submodule tests to CI
Browse files Browse the repository at this point in the history
Fix FD pattern sign tolerance in Fruendlich LDF test

In the test settings, remove EXT_ prefix from constant binding
parameters, fixing the configuration of external binding parameter
handler
  • Loading branch information
jbreue16 committed Jan 16, 2025
1 parent e054d22 commit d5428be
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ jobs:
${INSTALL_PREFIX}/bin/cadet-cli LWE.h5 || true
- name: Run tests
run: |
${BUILD_DIR}/test/testRunner [CI]
${BUILD_DIR}/test/testRunner [CI],[BindingModel]
MacOS:
runs-on: macos-latest
strategy:
Expand Down
6 changes: 3 additions & 3 deletions test/BindingModelTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ int ConfiguredBindingModel::requiredBufferSize() CADET_NOEXCEPT
return 0;
}

void testJacobianAD(const char* modelName, unsigned int nComp, unsigned int const* nBound, bool isKinetic, const char* config, double const* point, bool skipStructureTest, double absTol, double relTol)
void testJacobianAD(const char* modelName, unsigned int nComp, unsigned int const* nBound, bool isKinetic, const char* config, double const* point, bool skipStructureTest, double FDsignAbsTol, double absTol, double relTol)
{
ConfiguredBindingModel cbm = ConfiguredBindingModel::create(modelName, nComp, nBound, isKinetic, config);

Expand Down Expand Up @@ -229,12 +229,12 @@ void testJacobianAD(const char* modelName, unsigned int nComp, unsigned int cons
cadet::test::checkJacobianPatternFD(
[&](double const* lDir, double* res) -> void { cbm.model().flux(1.0, 0u, ColumnPosition{0.0, 0.0, 0.0}, lDir + cbm.nComp(), lDir, res, cbm.buffer()); },
[&](double const* lDir, double* res) -> void { jacAna.submatrixMultiplyVector(lDir, cbm.nComp(), 0, numEq, numDofs, res); },
yState.data(), dir.data(), colA.data(), colB.data(), numDofs, numEq);
yState.data(), dir.data(), colA.data(), colB.data(), numDofs, numEq, FDsignAbsTol);

cadet::test::checkJacobianPatternFD(
[&](double const* lDir, double* res) -> void { cbm.model().flux(1.0, 0u, ColumnPosition{0.0, 0.0, 0.0}, lDir + cbm.nComp(), lDir, res, cbm.buffer()); },
[&](double const* lDir, double* res) -> void { jacAD.multiplyVector(lDir, res); },
yState.data(), dir.data(), colA.data(), colB.data(), numDofs, numEq);
yState.data(), dir.data(), colA.data(), colB.data(), numDofs, numEq, FDsignAbsTol);
}

// Check Jacobians against each other
Expand Down
3 changes: 2 additions & 1 deletion test/BindingModelTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ namespace binding
* @param [in] config JSON string with binding model parameters
* @param [in] point Liquid phase and solid phase values to check Jacobian at
* @param [in] skipStructureTest Determines whether the structural test using finite differences is skipped
* @param [in] FDsignAbsTol Absolute tolerance in FD pattern sign check
* @param [in] absTol Absolute error tolerance
* @param [in] relTol Relative error tolerance
*/
void testJacobianAD(const char* modelName, unsigned int nComp, unsigned int const* nBound, bool isKinetic, const char* config, double const* point, bool skipStructureTest = false, double absTol = 0.0, double relTol = std::numeric_limits<float>::epsilon() * 100.0);
void testJacobianAD(const char* modelName, unsigned int nComp, unsigned int const* nBound, bool isKinetic, const char* config, double const* point, bool skipStructureTest = false, double FDsignAbsTol = 0.0, double absTol = 0.0, double relTol = std::numeric_limits<float>::epsilon() * 100.0);

/**
* @brief Checks residual and analytic Jacobian of normal model variant against externally dependent ones
Expand Down
19 changes: 10 additions & 9 deletions test/BindingModels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ CADET_BINDINGTEST("MOBILE_PHASE_MODULATOR", "EXT_MOBILE_PHASE_MODULATOR", (1,1,1
"EXT_MPM_BETA_T": [0.0, 1.5, 2.0],
"EXT_MPM_BETA_TT": [0.0, 0.0, 0.0],
"EXT_MPM_BETA_TTT": [0.0, 0.0, 0.0],
"EXT_MPM_LINEAR_THRESHOLD": 1e-10
"MPM_LINEAR_THRESHOLD": 1e-10
)json", \
R"json( "EXT_MPM_KA": [0.0, 0.0, 0.0, 0.0],
"EXT_MPM_KA_T": [0.0, 1.14, 1.0, 2.0],
Expand All @@ -295,7 +295,7 @@ CADET_BINDINGTEST("MOBILE_PHASE_MODULATOR", "EXT_MOBILE_PHASE_MODULATOR", (1,1,1
"EXT_MPM_BETA_T": [0.0, 1.5, 0.0, 2.0],
"EXT_MPM_BETA_TT": [0.0, 0.0, 0.0, 0.0],
"EXT_MPM_BETA_TTT": [0.0, 0.0, 0.0, 0.0],
"EXT_MPM_LINEAR_THRESHOLD": 1e-10
"MPM_LINEAR_THRESHOLD": 1e-10
)json", \
1e-10, 1e-10, CADET_NONBINDING_LIQUIDPHASE_COMP_UNUSED, CADET_COMPARE_BINDING_VS_NONBINDING)

Expand Down Expand Up @@ -334,7 +334,7 @@ CADET_BINDINGTEST("MOBILE_PHASE_MODULATOR", "EXT_MOBILE_PHASE_MODULATOR", (1,1,1
"EXT_MPM_BETA_T": [0.0, 1.5, 2.0],
"EXT_MPM_BETA_TT": [0.0, 0.0, 0.0],
"EXT_MPM_BETA_TTT": [0.0, 0.0, 0.0],
"EXT_MPM_LINEAR_THRESHOLD": 1e-10
"MPM_LINEAR_THRESHOLD": 1e-10
)json", \
R"json( "EXT_MPM_KA": [0.0, 0.0, 0.0, 0.0],
"EXT_MPM_KA_T": [0.0, 1.14, 1.0, 2.0],
Expand All @@ -356,7 +356,7 @@ CADET_BINDINGTEST("MOBILE_PHASE_MODULATOR", "EXT_MOBILE_PHASE_MODULATOR", (1,1,1
"EXT_MPM_BETA_T": [0.0, 1.5, 0.0, 2.0],
"EXT_MPM_BETA_TT": [0.0, 0.0, 0.0, 0.0],
"EXT_MPM_BETA_TTT": [0.0, 0.0, 0.0, 0.0],
"EXT_MPM_LINEAR_THRESHOLD": 1e-10
"MPM_LINEAR_THRESHOLD": 1e-10
)json", \
1e-10, 1e-10, CADET_NONBINDING_LIQUIDPHASE_COMP_UNUSED, CADET_COMPARE_BINDING_VS_NONBINDING)

Expand Down Expand Up @@ -1002,7 +1002,7 @@ CADET_BINDINGTEST("MULTI_COMPONENT_LDF_FREUNDLICH", "EXT_MULTI_COMPONENT_LDF_FRE
"EXT_MCLDFFRL_A_T": [3.0, 2.2, 1.5, 0.5],
"EXT_MCLDFFRL_A_TT": [0.0, 0.0, 0.0, 0.0],
"EXT_MCLDFFRL_A_TTT": [0.0, 0.0, 0.0, 0.0],
"EXT_MCLDFFRL_TAU": 0.1
"MCLDFFRL_TAU": 0.1
)json", \
R"json( "EXT_MCLDFFRL_KLDF": [0.0, 0.0, 0.0],
"EXT_MCLDFFRL_KLDF_T": [1.14, 1.0, 2.0],
Expand All @@ -1020,7 +1020,7 @@ CADET_BINDINGTEST("MULTI_COMPONENT_LDF_FREUNDLICH", "EXT_MULTI_COMPONENT_LDF_FRE
"EXT_MCLDFFRL_A_T": [2.2, 1.1, 0.4, 0.1, 0.94, 2.8, 0.5, 1.2, 2.4],
"EXT_MCLDFFRL_A_TT": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
"EXT_MCLDFFRL_A_TTT": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
"EXT_MCLDFFRL_TAU": 0.1
"MCLDFFRL_TAU": 0.1
)json", \
1e-10, 1e-10, CADET_NONBINDING_LIQUIDPHASE_COMP_USED, CADET_DONT_COMPARE_BINDING_VS_NONBINDING)

Expand Down Expand Up @@ -1059,7 +1059,7 @@ CADET_BINDINGTEST("MULTI_COMPONENT_SIPS", "EXT_MULTI_COMPONENT_SIPS", (1, 1, 1,
"EXT_SIPS_EXP_TTT": [0.0, 0.0, 0.0, 0.0],
"EXT_SIPS_REFC0": 2.0,
"EXT_SIPS_REFQ": 1.1,
"EXT_SIPS_LINEAR_THRESHOLD": 1e-10
"SIPS_LINEAR_THRESHOLD": 1e-10
)json", \
R"json( "EXT_SIPS_KA": [0.0, 0.0, 0.0, 0.0, 0.0],
"EXT_SIPS_KA_T": [1.14, 1.0, 2.0, 1.14, 2.0],
Expand All @@ -1079,7 +1079,7 @@ CADET_BINDINGTEST("MULTI_COMPONENT_SIPS", "EXT_MULTI_COMPONENT_SIPS", (1, 1, 1,
"EXT_SIPS_EXP_TTT": [0.0, 0.0, 0.0, 0.0, 0.0],
"EXT_SIPS_REFC0": 2.0,
"EXT_SIPS_REFQ": 1.1,
"EXT_SIPS_LINEAR_THRESHOLD": 1e-10
"SIPS_LINEAR_THRESHOLD": 1e-10
)json", \
1e-10, 1e-10, CADET_NONBINDING_LIQUIDPHASE_COMP_UNUSED, CADET_COMPARE_BINDING_VS_NONBINDING)

Expand Down Expand Up @@ -1461,6 +1461,7 @@ CADET_BINDINGTEST("GENERALIZED_ION_EXCHANGE", "EXT_GENERALIZED_ION_EXCHANGE", (1
{
const unsigned int nBound[] = { 0, 0, 1, 1, 1};
const double state[] = { 0.9, 1.1, 1.5e-2, 3.2e-3, 1.5e-5, 3.2e-5, 1.5e-5, 3.2e-5 };
double FDsignAbsTol = 1e-10; // specific tolerance for this test, non-default value
char const* const config = R"json({
"COL_PHI": 49232983.6522396,
"COL_KAPPA_EXP": 1.8,
Expand All @@ -1487,7 +1488,7 @@ CADET_BINDINGTEST("GENERALIZED_ION_EXCHANGE", "EXT_GENERALIZED_ION_EXCHANGE", (1
const bool isKinetic = bindMode;
SECTION(std::string("Binding mode ") + (isKinetic ? "dynamic" : "quasi-stationary"))
{
cadet::test::binding::testJacobianAD("MULTI_COMPONENT_COLLOIDAL", sizeof(nBound) / sizeof(unsigned int), nBound, isKinetic, config, state);
cadet::test::binding::testJacobianAD("MULTI_COMPONENT_COLLOIDAL", sizeof(nBound) / sizeof(unsigned int), nBound, isKinetic, config, state, FDsignAbsTol);
}
}
}
Expand Down

0 comments on commit d5428be

Please sign in to comment.