-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an exchange module for the MCT (#257)
Key changes : * Add PhaseTransitionModel.hpp and first changes for Linear Exchange * Add comments for possible changes * Add comments where to add exchange modul * Add linear flux residual to MCT * Add jacobian to MCT modul --------- Co-authored-by: Jan Breuer <[email protected]>
- Loading branch information
1 parent
020834d
commit f9e963a
Showing
21 changed files
with
593 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// ============================================================================= | ||
// CADET | ||
// | ||
// Copyright © 2008-present: The CADET-Core Authors | ||
// Please see the AUTHORS.md 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 "ExchangeModelFactory.hpp" | ||
#include "cadet/Exceptions.hpp" | ||
|
||
|
||
namespace cadet | ||
{ | ||
namespace model | ||
{ | ||
namespace exchange | ||
{ | ||
void registerLinearExModel(std::unordered_map<std::string, std::function<model::IExchangeModel* ()>>& exchange); | ||
} | ||
} | ||
|
||
ExchangeModelFactory::ExchangeModelFactory() | ||
{ | ||
// Register all ExchangeModels here | ||
model::exchange::registerLinearExModel(_exchangeModels); | ||
|
||
} | ||
|
||
ExchangeModelFactory::~ExchangeModelFactory() { } | ||
|
||
template <class ExchangeModel_t> | ||
void ExchangeModelFactory::registerModel(const std::string& name) | ||
{ | ||
_exchangeModels[name] = []() { return new ExchangeModel_t(); }; | ||
} | ||
|
||
template <class ExchangeModel_t> | ||
void ExchangeModelFactory::registerModel() | ||
{ | ||
registerModel<ExchangeModel_t>(ExchangeModel_t::identifier()); | ||
} | ||
|
||
model::IExchangeModel* ExchangeModelFactory::create(const std::string& name) const | ||
{ | ||
const auto it = _exchangeModels.find(name); | ||
if (it == _exchangeModels.end()) | ||
{ | ||
// ExchangeModel was not found | ||
return nullptr; | ||
} | ||
|
||
// Call factory function (thanks to type erasure of std::function we can store | ||
// all factory functions in one container) | ||
return it->second(); | ||
} | ||
|
||
void ExchangeModelFactory::registerModel(const std::string& name, std::function<model::IExchangeModel*()> factory) | ||
{ | ||
if (_exchangeModels.find(name) == _exchangeModels.end()) | ||
_exchangeModels[name] = factory; | ||
else | ||
throw InvalidParameterException("IExchange implementation with the name " + name + " is already registered and cannot be overwritten"); | ||
} | ||
|
||
bool ExchangeModelFactory::exists(const std::string& name) const | ||
{ | ||
return _exchangeModels.find(name) != _exchangeModels.end(); | ||
} | ||
} // namespace cadet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// ============================================================================= | ||
// CADET | ||
// | ||
// Copyright © 2008-present: The CADET-Core Authors | ||
// Please see the AUTHORS.md 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 | ||
// ============================================================================= | ||
|
||
/** | ||
* @file | ||
* Defines the ExchangeModelFactory | ||
*/ | ||
|
||
#ifndef LIBCADET_EXCHANGEMODELFACTORY_HPP_ | ||
#define LIBCADET_EXCHANGEMODELFACTORY_HPP_ | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
#include <functional> | ||
|
||
namespace cadet | ||
{ | ||
|
||
namespace model | ||
{ | ||
class IExchangeModel; | ||
} | ||
|
||
/** | ||
* @brief Creates Exchange models | ||
*/ | ||
class ExchangeModelFactory | ||
{ | ||
public: | ||
/** | ||
* @brief Construct the ExchangeModelFactory | ||
* @details All internal exchange models are registered here. | ||
*/ | ||
ExchangeModelFactory(); | ||
|
||
~ExchangeModelFactory(); | ||
|
||
/** | ||
* @brief Creates exchange models with the given @p name | ||
* @param [in] name Name of the exchange model | ||
* @return The exchange model or @c NULL if a exchange model with this name does not exist | ||
*/ | ||
model::IExchangeModel* create(const std::string& name) const; | ||
|
||
/** | ||
* @brief Registers the given exchange model implementation | ||
* @param [in] name Name of the IExchangeModel implementation | ||
* @param [in] factory Function that creates an object of the IExchangeModel class | ||
*/ | ||
void registerModel(const std::string& name, std::function<model::IExchangeModel*()> factory); | ||
|
||
/** | ||
* @brief Returns whether a exchange model of the given name @p name exists | ||
* @param [in] name Name of the exchange model | ||
* @return @c true if a exchange model of this name exists, otherwise @c false | ||
*/ | ||
bool exists(const std::string& name) const; | ||
protected: | ||
|
||
/** | ||
* @brief Registers an IExchangeModel | ||
* @param [in] name Name of the exchange model | ||
* @tparam ExchangeModel_t Type of the exchange model | ||
*/ | ||
template <class ExchangeModel_t> | ||
void registerModel(const std::string& name); | ||
|
||
/** | ||
* @brief Registers an IExchangeModel | ||
* @details The name of the exchange model is inferred from the static function IExchangeModel::identifier(). | ||
* @tparam ExchangeModel_t Type of the exchange model | ||
*/ | ||
template <class ExchangeModel_t> | ||
void registerModel(); | ||
|
||
std::unordered_map<std::string, std::function<model::IExchangeModel* ()>> _exchangeModels; //!< Map with factory functions | ||
}; | ||
|
||
} // namespace cadet | ||
|
||
#endif // LIBCADET_EXCHANGEMODELFACTORY_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// ============================================================================= | ||
// CADET | ||
// | ||
// Copyright © 2008-present: The CADET-Core Authors | ||
// Please see the AUTHORS.md 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 | ||
// ============================================================================= | ||
|
||
/** | ||
* @file | ||
* Defines the ExchangeModel interface. | ||
*/ | ||
|
||
#ifndef LIBCADET_EXCHANGEMODELINTERFACE_HPP_ | ||
#define LIBCADET_EXCHANGEMODELINTERFACE_HPP_ | ||
|
||
#include <unordered_map> | ||
|
||
#include "CompileTimeConfig.hpp" | ||
#include "cadet/ParameterProvider.hpp" | ||
#include "cadet/ParameterId.hpp" | ||
#include "linalg/DenseMatrix.hpp" | ||
#include "linalg/BandMatrix.hpp" | ||
|
||
#ifdef ENABLE_DG | ||
#include "linalg/BandedEigenSparseRowIterator.hpp" | ||
#endif | ||
|
||
#include "AutoDiff.hpp" | ||
#include "SimulationTypes.hpp" | ||
#include "Memory.hpp" | ||
|
||
namespace cadet | ||
{ | ||
|
||
class IParameterProvider; | ||
class IExternalFunction; | ||
|
||
struct ColumnPosition; | ||
|
||
namespace model | ||
{ | ||
|
||
class IExchangeModel | ||
{ | ||
public: | ||
|
||
virtual ~IExchangeModel() CADET_NOEXCEPT { } | ||
|
||
virtual const char* name() const CADET_NOEXCEPT = 0; | ||
|
||
//virtual bool requiresConfiguration() const CADET_NOEXCEPT = 0; | ||
|
||
virtual bool configureModelDiscretization(IParameterProvider& paramProvider, unsigned int nComp, unsigned int nChannel, unsigned int nCol) = 0; | ||
|
||
virtual bool configure(IParameterProvider& paramProvider, UnitOpIdx unitOpIdx) = 0; | ||
|
||
virtual int residual(active const* y, active* res, WithParamSensitivity, bool wantJac, linalg::BandedSparseRowIterator jacBegin) const = 0; | ||
virtual int residual(active const* y, active* res, WithoutParamSensitivity, bool wantJac, linalg::BandedSparseRowIterator jacBegin) const = 0; | ||
virtual int residual(double const* y, active* res, WithParamSensitivity, bool wantJac, linalg::BandedSparseRowIterator jacBegin) const = 0; | ||
virtual int residual(double const* y, double* res, WithoutParamSensitivity, bool wantJac, linalg::BandedSparseRowIterator jacBegin) const = 0; | ||
|
||
protected: | ||
}; | ||
|
||
} // namespace model | ||
} // namespace cadet | ||
|
||
#endif // LIBCADET_EXCHANGEMODELINTERFACE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.