From d5428be4736c552d990c71f3638817e36650b9b1 Mon Sep 17 00:00:00 2001 From: Jan Breuer Date: Thu, 16 Jan 2025 11:27:58 +0100 Subject: [PATCH] Add binding model submodule tests to CI 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 --- .github/workflows/ci.yml | 2 +- test/BindingModelTests.cpp | 6 +++--- test/BindingModelTests.hpp | 3 ++- test/BindingModels.cpp | 19 ++++++++++--------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92658b6c8..f5b785d40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/test/BindingModelTests.cpp b/test/BindingModelTests.cpp index 69c0c6f80..b96c0818c 100644 --- a/test/BindingModelTests.cpp +++ b/test/BindingModelTests.cpp @@ -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); @@ -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 diff --git a/test/BindingModelTests.hpp b/test/BindingModelTests.hpp index 8b46e097d..e242183c2 100644 --- a/test/BindingModelTests.hpp +++ b/test/BindingModelTests.hpp @@ -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::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::epsilon() * 100.0); /** * @brief Checks residual and analytic Jacobian of normal model variant against externally dependent ones diff --git a/test/BindingModels.cpp b/test/BindingModels.cpp index de55e9f57..a90e497e6 100644 --- a/test/BindingModels.cpp +++ b/test/BindingModels.cpp @@ -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], @@ -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) @@ -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], @@ -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) @@ -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], @@ -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) @@ -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], @@ -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) @@ -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, @@ -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); } } }