|
| 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