Skip to content

Commit c18b15f

Browse files
committed
WIP: Add PowerLawParameterParameterDependence
1 parent d424c21 commit c18b15f

9 files changed

+123
-28
lines changed

src/libcadet/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ set(LIBCADET_SOURCES
148148
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/ParameterDependenceBase.cpp
149149
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/LiquidSaltSolidParameterDependence.cpp
150150
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/DummyParameterDependence.cpp
151+
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/PowerLawParameterDependence.cpp
151152
)
152153

153154
# LIBCADET_NONLINALG_SOURCES holds all source files for LIBCADET_NONLINALG target

src/libcadet/ParameterDependenceFactory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace cadet
2222
void registerLiquidSaltSolidParamDependence(std::unordered_map<std::string, std::function<model::IParameterStateDependence*()>>& paramDeps);
2323
void registerDummyParamDependence(std::unordered_map<std::string, std::function<model::IParameterStateDependence*()>>& paramDeps);
2424
void registerDummyParamDependence(std::unordered_map<std::string, std::function<model::IParameterParameterDependence*()>>& paramDeps);
25+
void registerPowerLawParamDependence(std::unordered_map<std::string, std::function<model::IParameterParameterDependence*()>>& paramDeps);
2526
}
2627
}
2728

@@ -33,6 +34,7 @@ namespace cadet
3334

3435
// Register all ParamParam dependencies
3536
model::paramdep::registerDummyParamDependence(_paramParamDeps);
37+
model::paramdep::registerPowerLawParamDependence(_paramParamDeps);
3638
}
3739

3840
ParameterDependenceFactory::~ParameterDependenceFactory() { }

src/libcadet/model/paramdep/DummyParameterDependence.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ class DummyParameterParameterDependence : public ParameterParameterDependenceBas
107107
}
108108

109109
template <typename ParamType>
110-
ParamType getValue(UnitOpIdx unitOpIdx, const std::unordered_map<ParameterId, active*>& params, const ColumnPosition& colPos, int comp, int parType, int bnd) const
110+
ParamType getValueImpl(UnitOpIdx unitOpIdx, const std::unordered_map<ParameterId, active*>& params, const ColumnPosition& colPos, int comp, int parType, int bnd) const
111111
{
112112
return 0.0;
113113
}
114114

115115
template <typename ParamType>
116-
ParamType getValue(UnitOpIdx unitOpIdx, const std::unordered_map<ParameterId, active*>& params, const ColumnPosition& colPos, int comp, int parType, int bnd, const ParamType& val) const
116+
ParamType getValueImpl(UnitOpIdx unitOpIdx, const std::unordered_map<ParameterId, active*>& params, const ColumnPosition& colPos, int comp, int parType, int bnd, const ParamType& val) const
117117
{
118118
return 0.0;
119119
}

src/libcadet/model/paramdep/LiquidSaltSolidParameterDependence.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ namespace paramdep
307307
paramDeps[PowerLiquidSaltSolidParameterStateDependence::identifier()] = []() { return new PowerLiquidSaltSolidParameterStateDependence(); };
308308
paramDeps[ColloidalAffinityLiquidSaltSolidParameterStateDependence::identifier()] = []() { return new ColloidalAffinityLiquidSaltSolidParameterStateDependence(); };
309309
}
310-
} // namespace reaction
310+
} // namespace paramdep
311311

312312
} // namespace model
313313

src/libcadet/model/paramdep/ParameterDependenceBase.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,25 +241,25 @@ class ParameterParameterDependenceBase : public IParameterParameterDependence
241241
*
242242
* The implementation is inserted inline in the class declaration.
243243
*/
244-
#define CADET_PARAMETERPARAMETERDEPENDENCE_BOILERPLATE \
244+
#define CADET_PARAMETERPARAMETERDEPENDENCE_BOILERPLATE \
245245
virtual double getValue(UnitOpIdx unitOpIdx, const std::unordered_map<ParameterId, active*>& params, const ColumnPosition& colPos, int comp, int parType, int bnd, double val) const \
246246
{ \
247-
return getValue<double>(unitOpIdx, params, colPos, comp, parType, bnd, val); \
247+
return getValueImpl<double>(unitOpIdx, params, colPos, comp, parType, bnd, val); \
248248
} \
249249
\
250250
virtual active getValue(UnitOpIdx unitOpIdx, const std::unordered_map<ParameterId, active*>& params, const ColumnPosition& colPos, int comp, int parType, int bnd, const active& val) const \
251251
{ \
252-
return getValue<active>(unitOpIdx, params, colPos, comp, parType, bnd, val); \
252+
return getValueImpl<active>(unitOpIdx, params, colPos, comp, parType, bnd, val); \
253253
} \
254254
\
255255
virtual double getValue(UnitOpIdx unitOpIdx, const std::unordered_map<ParameterId, active*>& params, const ColumnPosition& colPos, int comp, int parType, int bnd) const \
256256
{ \
257-
return getValue<double>(unitOpIdx, params, colPos, comp, parType, bnd); \
257+
return getValueImpl<double>(unitOpIdx, params, colPos, comp, parType, bnd); \
258258
} \
259259
\
260260
virtual active getValueActive(UnitOpIdx unitOpIdx, const std::unordered_map<ParameterId, active*>& params, const ColumnPosition& colPos, int comp, int parType, int bnd) const \
261261
{ \
262-
return getValue<active>(unitOpIdx, params, colPos, comp, parType, bnd); \
262+
return getValueImpl<active>(unitOpIdx, params, colPos, comp, parType, bnd); \
263263
}
264264

265265

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// =============================================================================
2+
// CADET
3+
//
4+
// Copyright © 2008-2022: The CADET Authors
5+
// Please see the AUTHORS and CONTRIBUTORS file.
6+
//
7+
// All rights reserved. This program and the accompanying materials
8+
// are made available under the terms of the GNU Public License v3.0 (or, at
9+
// your option, any later version) which accompanies this distribution, and
10+
// is available at http://www.gnu.org/licenses/gpl.html
11+
// =============================================================================
12+
13+
#include "model/paramdep/ParameterDependenceBase.hpp"
14+
#include "SimulationTypes.hpp"
15+
#include "cadet/ParameterId.hpp"
16+
17+
#include <cmath>
18+
19+
namespace cadet
20+
{
21+
namespace model
22+
{
23+
24+
/**
25+
* @brief Defines a power law parameter parameter dependence
26+
* @details The parameter dependence is defined as
27+
* @f[\begin{align}
28+
p_{new}(p) = \alpha p^k,
29+
\end{align} @f]
30+
where @f$ \alpha @f$ and @f$ k @f$ are (meta-)parameters.
31+
*/
32+
class PowerLawParameterParameterDependence : public ParameterParameterDependenceBase
33+
{
34+
public:
35+
36+
PowerLawParameterParameterDependence() { }
37+
virtual ~PowerLawParameterParameterDependence() CADET_NOEXCEPT { }
38+
39+
static const char* identifier() { return "POWER_LAW"; }
40+
virtual const char* name() const CADET_NOEXCEPT { return PowerLawParameterParameterDependence::identifier(); }
41+
42+
CADET_PARAMETERPARAMETERDEPENDENCE_BOILERPLATE
43+
44+
protected:
45+
active _base;
46+
active _exponent;
47+
48+
virtual bool configureImpl(IParameterProvider& paramProvider, UnitOpIdx unitOpIdx, ParticleTypeIdx parTypeIdx, BoundStateIdx bndIdx, const std::string& name)
49+
{
50+
const std::string baseName = name + "_BASE";
51+
const std::string expName = name + "_EXPONENT";
52+
_base = paramProvider.getDouble(baseName);
53+
_exponent = paramProvider.getDouble(expName);
54+
55+
_parameters[makeParamId(hashStringRuntime(baseName), unitOpIdx, CompIndep, parTypeIdx, bndIdx, ReactionIndep, SectionIndep)] = &_base;
56+
_parameters[makeParamId(hashStringRuntime(expName), unitOpIdx, CompIndep, parTypeIdx, bndIdx, ReactionIndep, SectionIndep)] = &_exponent;
57+
58+
return true;
59+
}
60+
61+
template <typename ParamType>
62+
ParamType getValueImpl(UnitOpIdx unitOpIdx, const std::unordered_map<ParameterId, active*>& params, const ColumnPosition& colPos, int comp, int parType, int bnd) const
63+
{
64+
return 0.0;
65+
}
66+
67+
template <typename ParamType>
68+
ParamType getValueImpl(UnitOpIdx unitOpIdx, const std::unordered_map<ParameterId, active*>& params, const ColumnPosition& colPos, int comp, int parType, int bnd, ParamType val) const
69+
{
70+
using std::pow;
71+
return static_cast<ParamType>(_base) * pow(val, static_cast<ParamType>(_exponent));
72+
}
73+
74+
};
75+
76+
77+
namespace paramdep
78+
{
79+
void registerPowerLawParamDependence(std::unordered_map<std::string, std::function<model::IParameterParameterDependence*()>>& paramDeps)
80+
{
81+
paramDeps[PowerLawParameterParameterDependence::identifier()] = []() { return new PowerLawParameterParameterDependence(); };
82+
}
83+
} // namespace paramdep
84+
85+
} // namespace model
86+
87+
} // namespace cadet

src/libcadet/model/parts/ConvectionDispersionOperator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,11 @@ bool RadialConvectionDispersionOperatorBase::notifyDiscontinuousSectionTransitio
676676
*/
677677
void RadialConvectionDispersionOperatorBase::setFlowRates(const active& in, const active& out, const active& colPorosity) CADET_NOEXCEPT
678678
{
679+
const double pi = 3.1415926535897932384626434;
680+
679681
// If we have cross section area, interstitial velocity is given by network flow rates
680682
if (_colLength > 0.0)
681-
_curVelocity = _dir * in / (2.0 * M_PI * _colLength * colPorosity);
683+
_curVelocity = _dir * in / (2.0 * pi * _colLength * colPorosity);
682684
}
683685

684686
/**

test/CMakeLists.txt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,24 @@ endif()
3131
add_executable(testLogging testLogging.cpp)
3232
target_link_libraries(testLogging PRIVATE CADET::CompileOptions)
3333

34-
add_executable(testRadialKernel testRadialKernel.cpp TimeIntegrator.cpp ${CMAKE_SOURCE_DIR}/src/libcadet/Logging.cpp ${CMAKE_SOURCE_DIR}/src/libcadet/AutoDiff.cpp)
35-
target_link_libraries(testRadialKernel PRIVATE CADET::CompileOptions CADET::AD SUNDIALS::sundials_idas ${SUNDIALS_NVEC_TARGET} )
36-
target_include_directories(testRadialKernel PRIVATE ${CMAKE_SOURCE_DIR}/test)
37-
38-
if (ENABLE_GRM_2D)
39-
target_include_directories(testRadialKernel PRIVATE ${CMAKE_BINARY_DIR}/src/libcadet)
40-
if (SUPERLU_FOUND)
41-
target_link_libraries(testRadialKernel PRIVATE SuperLU::SuperLU)
42-
endif()
43-
if (UMFPACK_FOUND)
44-
target_link_libraries(testRadialKernel PRIVATE UMFPACK::UMFPACK)
34+
if (NOT WIN32)
35+
add_executable(testRadialKernel testRadialKernel.cpp TimeIntegrator.cpp ${CMAKE_SOURCE_DIR}/src/libcadet/Logging.cpp ${CMAKE_SOURCE_DIR}/src/libcadet/AutoDiff.cpp)
36+
target_link_libraries(testRadialKernel PRIVATE CADET::CompileOptions CADET::AD SUNDIALS::sundials_idas ${SUNDIALS_NVEC_TARGET} )
37+
target_include_directories(testRadialKernel PRIVATE ${CMAKE_SOURCE_DIR}/test ${CMAKE_BINARY_DIR}/src/libcadet)
38+
39+
if (ENABLE_GRM_2D)
40+
target_include_directories(testRadialKernel PRIVATE ${CMAKE_BINARY_DIR}/src/libcadet)
41+
if (SUPERLU_FOUND)
42+
target_link_libraries(testRadialKernel PRIVATE SuperLU::SuperLU)
43+
endif()
44+
if (UMFPACK_FOUND)
45+
target_link_libraries(testRadialKernel PRIVATE UMFPACK::UMFPACK)
46+
endif()
4547
endif()
46-
endif()
4748

48-
list(APPEND TEST_NONLINALG_TARGETS testRadialKernel)
49-
list(APPEND TEST_HDF5_TARGETS testRadialKernel)
49+
list(APPEND TEST_NONLINALG_TARGETS testRadialKernel)
50+
list(APPEND TEST_HDF5_TARGETS testRadialKernel)
51+
endif()
5052

5153

5254
# CATCH unit tests
@@ -74,8 +76,8 @@ add_executable(testRunner testRunner.cpp JsonTestModels.cpp ColumnTests.cpp Unit
7476
$<TARGET_OBJECTS:libcadet_object>)
7577

7678
target_link_libraries(testRunner PRIVATE CADET::CompileOptions CADET::AD SUNDIALS::sundials_idas ${SUNDIALS_NVEC_TARGET} ${TBB_TARGET})
79+
target_include_directories(testRunner PRIVATE ${CMAKE_BINARY_DIR}/src/libcadet)
7780
if (ENABLE_GRM_2D)
78-
target_include_directories(testRunner PRIVATE ${CMAKE_BINARY_DIR}/src/libcadet)
7981
if (SUPERLU_FOUND)
8082
target_link_libraries(testRunner PRIVATE SuperLU::SuperLU)
8183
endif()
@@ -112,9 +114,10 @@ endforeach()
112114

113115
# ---------------------------------------------------
114116

115-
116-
add_executable(testCAPIv1 "${CMAKE_CURRENT_BINARY_DIR}/Paths_$<CONFIG>.cpp" testCAPIv1.cpp)
117-
target_include_directories(testCAPIv1 PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/ThirdParty/json)
117+
if (WIN32)
118+
add_executable(testCAPIv1 "${CMAKE_CURRENT_BINARY_DIR}/Paths_$<CONFIG>.cpp" testCAPIv1.cpp)
119+
target_include_directories(testCAPIv1 PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/ThirdParty/json)
120+
endif()
118121

119122
# ---------------------------------------------------
120123

test/testRadialKernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define TEST_MANUFACTURED_TEXPT 1
3131

3232
// Uncomment the next line to enable logging output of CADET in unit tests
33-
#define CADETTEST_ENABLE_LOG
33+
//#define CADETTEST_ENABLE_LOG
3434

3535
#ifdef CADETTEST_ENABLE_LOG
3636
#include "cadet/Logging.hpp"

0 commit comments

Comments
 (0)