Skip to content

Commit

Permalink
Add identity parameter-parameter dependence
Browse files Browse the repository at this point in the history
Adds a parameter dependence that simply outputs the given parameter
value.
  • Loading branch information
sleweke-bayer authored and jbreue16 committed May 3, 2024
1 parent c3586c1 commit 82a0f84
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/libcadet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ set(LIBCADET_SOURCES
${CMAKE_SOURCE_DIR}/src/libcadet/model/StirredTankModel.cpp
${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithoutPores.cpp
${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithPores.cpp
# ${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithPores-LinearSolver.cpp
# ${CMAKE_SOURCE_DIR}/src/libcadet/model/LumpedRateModelWithPores-InitialConditions.cpp
${CMAKE_SOURCE_DIR}/src/libcadet/model/GeneralRateModel.cpp
# ${CMAKE_SOURCE_DIR}/src/libcadet/model/GeneralRateModel-LinearSolver.cpp
# ${CMAKE_SOURCE_DIR}/src/libcadet/model/GeneralRateModel-InitialConditions.cpp
${CMAKE_SOURCE_DIR}/src/libcadet/model/ParameterMultiplexing.cpp
${CMAKE_SOURCE_DIR}/src/libcadet/model/parts/ConvectionDispersionOperator.cpp
${CMAKE_SOURCE_DIR}/src/libcadet/model/parts/AxialConvectionDispersionKernel.cpp
Expand All @@ -150,6 +146,7 @@ set(LIBCADET_SOURCES
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/ParameterDependenceBase.cpp
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/LiquidSaltSolidParameterDependence.cpp
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/DummyParameterDependence.cpp
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/IdentityParameterDependence.cpp
${CMAKE_SOURCE_DIR}/src/libcadet/model/paramdep/PowerLawParameterDependence.cpp
)

Expand Down
4 changes: 4 additions & 0 deletions src/libcadet/ParameterDependenceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace cadet
void registerLiquidSaltSolidParamDependence(std::unordered_map<std::string, std::function<model::IParameterStateDependence*()>>& paramDeps);
void registerDummyParamDependence(std::unordered_map<std::string, std::function<model::IParameterStateDependence*()>>& paramDeps);
void registerDummyParamDependence(std::unordered_map<std::string, std::function<model::IParameterParameterDependence*()>>& paramDeps);
void registerIdentityParamDependence(std::unordered_map<std::string, std::function<model::IParameterStateDependence*()>>& paramDeps);
void registerIdentityParamDependence(std::unordered_map<std::string, std::function<model::IParameterParameterDependence*()>>& paramDeps);
void registerPowerLawParamDependence(std::unordered_map<std::string, std::function<model::IParameterParameterDependence*()>>& paramDeps);
}
}
Expand All @@ -31,9 +33,11 @@ namespace cadet
// Register all ParamState dependencies
model::paramdep::registerLiquidSaltSolidParamDependence(_paramStateDeps);
model::paramdep::registerDummyParamDependence(_paramStateDeps);
model::paramdep::registerIdentityParamDependence(_paramStateDeps);

// Register all ParamParam dependencies
model::paramdep::registerDummyParamDependence(_paramParamDeps);
model::paramdep::registerIdentityParamDependence(_paramParamDeps);
model::paramdep::registerPowerLawParamDependence(_paramParamDeps);
}

Expand Down
141 changes: 141 additions & 0 deletions src/libcadet/model/paramdep/IdentityParameterDependence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// =============================================================================
// CADET
//
// Copyright ┬® 2008-2022: The CADET Authors
// Please see the AUTHORS and CONTRIBUTORS file.
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the GNU Public License v3.0 (or, at
// your option, any later version) which accompanies this distribution, and
// is available at http://www.gnu.org/licenses/gpl.html
// =============================================================================

#include "model/paramdep/ParameterDependenceBase.hpp"
#include "ParamReaderHelper.hpp"
#include "cadet/Exceptions.hpp"
#include "SimulationTypes.hpp"
#include "cadet/ParameterId.hpp"

#include <sstream>
#include <vector>
#include <iomanip>

namespace cadet
{

namespace model
{

/**
* @brief Defines an identity parameter dependence
*/
class IdentityParameterStateDependence : public ParameterStateDependenceBase
{
public:

IdentityParameterStateDependence() { }
virtual ~IdentityParameterStateDependence() CADET_NOEXCEPT { }

static const char* identifier() { return "IDENTITY"; }
virtual const char* name() const CADET_NOEXCEPT { return IdentityParameterStateDependence::identifier(); }

virtual int jacobianElementsPerRowLiquid() const CADET_NOEXCEPT { return 0; }
virtual int jacobianElementsPerRowCombined() const CADET_NOEXCEPT { return 0; }

virtual void analyticJacobianLiquidAdd(const ColumnPosition& colPos, double param, double const* y, int comp, double factor, int offset, int row, linalg::DoubleSparseMatrix& jac) const { }
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 { }
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 { }

CADET_PARAMETERSTATEDEPENDENCE_BOILERPLATE

protected:

virtual bool configureImpl(IParameterProvider& paramProvider, UnitOpIdx unitOpIdx, ParticleTypeIdx parTypeIdx, const std::string& name)
{
return true;
}

template <typename StateType, typename ParamType>
typename DoubleActivePromoter<StateType, ParamType>::type liquidParameterImpl(const ColumnPosition& colPos, const ParamType& param, StateType const* y, int comp) const
{
return param;
}

template <typename RowIterator>
void analyticJacobianLiquidAddImpl(const ColumnPosition& colPos, double param, double const* y, int comp, double factor, int offset, RowIterator jac) const { }

template <typename StateType, typename ParamType>
typename DoubleActivePromoter<StateType, ParamType>::type combinedParameterLiquidImpl(const ColumnPosition& colPos, const ParamType& param, StateType const* yLiquid, StateType const* ySolid, int comp) const
{
return param;
}

template <typename RowIterator>
void analyticJacobianCombinedAddLiquidImpl(const ColumnPosition& colPos, double param, double const* yLiquid, double const* ySolid, int comp, double factor, int offset, RowIterator jac) const { }

template <typename StateType, typename ParamType>
typename DoubleActivePromoter<StateType, ParamType>::type combinedParameterSolidImpl(const ColumnPosition& colPos, const ParamType& param, StateType const* yLiquid, StateType const* ySolid, int bnd) const
{
return param;
}

template <typename RowIterator>
void analyticJacobianCombinedAddSolidImpl(const ColumnPosition& colPos, double param, double const* yLiquid, double const* ySolid, int bnd, double factor, int offset, RowIterator jac) const { }
};


/**
* @brief Defines an identity parameter dependence
*/
class IdentityParameterParameterDependence : public ParameterParameterDependenceBase
{
public:

IdentityParameterParameterDependence() { }
virtual ~IdentityParameterParameterDependence() CADET_NOEXCEPT { }

static const char* identifier() { return "IDENTITY"; }
virtual const char* name() const CADET_NOEXCEPT { return IdentityParameterParameterDependence::identifier(); }

CADET_PARAMETERPARAMETERDEPENDENCE_BOILERPLATE

protected:

virtual bool configureImpl(IParameterProvider& paramProvider, UnitOpIdx unitOpIdx, ParticleTypeIdx parTypeIdx, BoundStateIdx bndIdx, const std::string& name)
{
return true;
}

template <typename ParamType>
ParamType getValueImpl(const IModel& model, const ColumnPosition& colPos, int comp, int parType, int bnd) const
{
return 0.0;
}

template <typename ParamType>
ParamType getValueImpl(const IModel& model, const ColumnPosition& colPos, int comp, int parType, int bnd, const ParamType& val) const
{
return val;
}

};


namespace paramdep
{
void registerIdentityParamDependence(std::unordered_map<std::string, std::function<model::IParameterStateDependence*()>>& paramDeps)
{
paramDeps[IdentityParameterStateDependence::identifier()] = []() { return new IdentityParameterStateDependence(); };
paramDeps["NONE"] = []() { return new IdentityParameterStateDependence(); };
}

void registerIdentityParamDependence(std::unordered_map<std::string, std::function<model::IParameterParameterDependence*()>>& paramDeps)
{
paramDeps[IdentityParameterParameterDependence::identifier()] = []() { return new IdentityParameterParameterDependence(); };
paramDeps["NONE"] = []() { return new IdentityParameterParameterDependence(); };
}
} // namespace paramdep

} // namespace model

} // namespace cadet

0 comments on commit 82a0f84

Please sign in to comment.