Skip to content

Commit 82a0f84

Browse files
sleweke-bayerjbreue16
authored andcommitted
Add identity parameter-parameter dependence
Adds a parameter dependence that simply outputs the given parameter value.
1 parent c3586c1 commit 82a0f84

File tree

3 files changed

+146
-4
lines changed

3 files changed

+146
-4
lines changed

src/libcadet/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@ set(LIBCADET_SOURCES
133133
${CMAKE_SOURCE_DIR}/src/libcadet/model/StirredTankModel.cpp
134134
${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithoutPores.cpp
135135
${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithPores.cpp
136-
# ${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithPores-LinearSolver.cpp
137-
# ${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithPores-InitialConditions.cpp
138136
${CMAKE_SOURCE_DIR}/src/libcadet/model/GeneralRateModel.cpp
139-
# ${CMAKE_SOURCE_DIR}/src/libcadet/model/GeneralRateModel-LinearSolver.cpp
140-
# ${CMAKE_SOURCE_DIR}/src/libcadet/model/GeneralRateModel-InitialConditions.cpp
141137
${CMAKE_SOURCE_DIR}/src/libcadet/model/ParameterMultiplexing.cpp
142138
${CMAKE_SOURCE_DIR}/src/libcadet/model/parts/ConvectionDispersionOperator.cpp
143139
${CMAKE_SOURCE_DIR}/src/libcadet/model/parts/AxialConvectionDispersionKernel.cpp
@@ -150,6 +146,7 @@ set(LIBCADET_SOURCES
150146
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/ParameterDependenceBase.cpp
151147
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/LiquidSaltSolidParameterDependence.cpp
152148
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/DummyParameterDependence.cpp
149+
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/IdentityParameterDependence.cpp
153150
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/PowerLawParameterDependence.cpp
154151
)
155152

src/libcadet/ParameterDependenceFactory.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ 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 registerIdentityParamDependence(std::unordered_map<std::string, std::function<model::IParameterStateDependence*()>>& paramDeps);
26+
void registerIdentityParamDependence(std::unordered_map<std::string, std::function<model::IParameterParameterDependence*()>>& paramDeps);
2527
void registerPowerLawParamDependence(std::unordered_map<std::string, std::function<model::IParameterParameterDependence*()>>& paramDeps);
2628
}
2729
}
@@ -31,9 +33,11 @@ namespace cadet
3133
// Register all ParamState dependencies
3234
model::paramdep::registerLiquidSaltSolidParamDependence(_paramStateDeps);
3335
model::paramdep::registerDummyParamDependence(_paramStateDeps);
36+
model::paramdep::registerIdentityParamDependence(_paramStateDeps);
3437

3538
// Register all ParamParam dependencies
3639
model::paramdep::registerDummyParamDependence(_paramParamDeps);
40+
model::paramdep::registerIdentityParamDependence(_paramParamDeps);
3741
model::paramdep::registerPowerLawParamDependence(_paramParamDeps);
3842
}
3943

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 "ParamReaderHelper.hpp"
15+
#include "cadet/Exceptions.hpp"
16+
#include "SimulationTypes.hpp"
17+
#include "cadet/ParameterId.hpp"
18+
19+
#include <sstream>
20+
#include <vector>
21+
#include <iomanip>
22+
23+
namespace cadet
24+
{
25+
26+
namespace model
27+
{
28+
29+
/**
30+
* @brief Defines an identity parameter dependence
31+
*/
32+
class IdentityParameterStateDependence : public ParameterStateDependenceBase
33+
{
34+
public:
35+
36+
IdentityParameterStateDependence() { }
37+
virtual ~IdentityParameterStateDependence() CADET_NOEXCEPT { }
38+
39+
static const char* identifier() { return "IDENTITY"; }
40+
virtual const char* name() const CADET_NOEXCEPT { return IdentityParameterStateDependence::identifier(); }
41+
42+
virtual int jacobianElementsPerRowLiquid() const CADET_NOEXCEPT { return 0; }
43+
virtual int jacobianElementsPerRowCombined() const CADET_NOEXCEPT { return 0; }
44+
45+
virtual void analyticJacobianLiquidAdd(const ColumnPosition& colPos, double param, double const* y, int comp, double factor, int offset, int row, linalg::DoubleSparseMatrix& jac) const { }
46+
virtual void analyticJacobianCombinedAddLiquid(const ColumnPosition& colPos, double param, double const* yLiquid, double const* ySolid, int comp, double factor, int offset, int row, linalg::DoubleSparseMatrix& jac) const { }
47+
virtual void analyticJacobianCombinedAddSolid(const ColumnPosition& colPos, double param, double const* yLiquid, double const* ySolid, int bnd, double factor, int offset, int row, linalg::DoubleSparseMatrix& jac) const { }
48+
49+
CADET_PARAMETERSTATEDEPENDENCE_BOILERPLATE
50+
51+
protected:
52+
53+
virtual bool configureImpl(IParameterProvider& paramProvider, UnitOpIdx unitOpIdx, ParticleTypeIdx parTypeIdx, const std::string& name)
54+
{
55+
return true;
56+
}
57+
58+
template <typename StateType, typename ParamType>
59+
typename DoubleActivePromoter<StateType, ParamType>::type liquidParameterImpl(const ColumnPosition& colPos, const ParamType& param, StateType const* y, int comp) const
60+
{
61+
return param;
62+
}
63+
64+
template <typename RowIterator>
65+
void analyticJacobianLiquidAddImpl(const ColumnPosition& colPos, double param, double const* y, int comp, double factor, int offset, RowIterator jac) const { }
66+
67+
template <typename StateType, typename ParamType>
68+
typename DoubleActivePromoter<StateType, ParamType>::type combinedParameterLiquidImpl(const ColumnPosition& colPos, const ParamType& param, StateType const* yLiquid, StateType const* ySolid, int comp) const
69+
{
70+
return param;
71+
}
72+
73+
template <typename RowIterator>
74+
void analyticJacobianCombinedAddLiquidImpl(const ColumnPosition& colPos, double param, double const* yLiquid, double const* ySolid, int comp, double factor, int offset, RowIterator jac) const { }
75+
76+
template <typename StateType, typename ParamType>
77+
typename DoubleActivePromoter<StateType, ParamType>::type combinedParameterSolidImpl(const ColumnPosition& colPos, const ParamType& param, StateType const* yLiquid, StateType const* ySolid, int bnd) const
78+
{
79+
return param;
80+
}
81+
82+
template <typename RowIterator>
83+
void analyticJacobianCombinedAddSolidImpl(const ColumnPosition& colPos, double param, double const* yLiquid, double const* ySolid, int bnd, double factor, int offset, RowIterator jac) const { }
84+
};
85+
86+
87+
/**
88+
* @brief Defines an identity parameter dependence
89+
*/
90+
class IdentityParameterParameterDependence : public ParameterParameterDependenceBase
91+
{
92+
public:
93+
94+
IdentityParameterParameterDependence() { }
95+
virtual ~IdentityParameterParameterDependence() CADET_NOEXCEPT { }
96+
97+
static const char* identifier() { return "IDENTITY"; }
98+
virtual const char* name() const CADET_NOEXCEPT { return IdentityParameterParameterDependence::identifier(); }
99+
100+
CADET_PARAMETERPARAMETERDEPENDENCE_BOILERPLATE
101+
102+
protected:
103+
104+
virtual bool configureImpl(IParameterProvider& paramProvider, UnitOpIdx unitOpIdx, ParticleTypeIdx parTypeIdx, BoundStateIdx bndIdx, const std::string& name)
105+
{
106+
return true;
107+
}
108+
109+
template <typename ParamType>
110+
ParamType getValueImpl(const IModel& model, const ColumnPosition& colPos, int comp, int parType, int bnd) const
111+
{
112+
return 0.0;
113+
}
114+
115+
template <typename ParamType>
116+
ParamType getValueImpl(const IModel& model, const ColumnPosition& colPos, int comp, int parType, int bnd, const ParamType& val) const
117+
{
118+
return val;
119+
}
120+
121+
};
122+
123+
124+
namespace paramdep
125+
{
126+
void registerIdentityParamDependence(std::unordered_map<std::string, std::function<model::IParameterStateDependence*()>>& paramDeps)
127+
{
128+
paramDeps[IdentityParameterStateDependence::identifier()] = []() { return new IdentityParameterStateDependence(); };
129+
paramDeps["NONE"] = []() { return new IdentityParameterStateDependence(); };
130+
}
131+
132+
void registerIdentityParamDependence(std::unordered_map<std::string, std::function<model::IParameterParameterDependence*()>>& paramDeps)
133+
{
134+
paramDeps[IdentityParameterParameterDependence::identifier()] = []() { return new IdentityParameterParameterDependence(); };
135+
paramDeps["NONE"] = []() { return new IdentityParameterParameterDependence(); };
136+
}
137+
} // namespace paramdep
138+
139+
} // namespace model
140+
141+
} // namespace cadet

0 commit comments

Comments
 (0)