Skip to content

Commit 3a3ed1d

Browse files
committed
clean up MAL
1 parent 56bb490 commit 3a3ed1d

File tree

7 files changed

+225
-292
lines changed

7 files changed

+225
-292
lines changed

src/libcadet/model/StirredTankModel.cpp

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ void CSTRModel::consistentInitialState(const SimulationTime& simTime, double* co
709709
continue;
710710
double dotProduct = 0.0;
711711
for (unsigned int j = 0; j < _MconvMoityBulk2.cols(); ++j)
712-
dotProduct += _MconvMoityBulk2(i, j) * c[j];
712+
dotProduct += static_cast<double>(_MconvMoityBulk2(i, j)) * c[j];
713713

714714
conservedQuants[mIdx] = dotProduct;
715715
mIdx++;
@@ -772,14 +772,19 @@ void CSTRModel::consistentInitialState(const SimulationTime& simTime, double* co
772772
int mIdx = 0;
773773
for (unsigned int i = 0; i < _nComp; ++i)
774774
{
775-
if (_QsCompBulk[i]== 0)
775+
if (_QsCompBulk[i] == 0)
776776
continue;
777777
if (mIdx >= _nConservedQuants)
778778
continue;
779-
for (unsigned int j = 0; j < _MconvMoityBulk2.cols(); ++i)
779+
780+
int jIdx = 0;
781+
for (unsigned int j = 0; j < _MconvMoityBulk2.cols(); ++j)
780782
{
781-
mat.native(mIdx, j) = _MconvMoityBulk2(i, j);
782-
j++;
783+
if (_QsCompBulk[j] == 0)
784+
continue;
785+
786+
mat.native(mIdx, jIdx) = static_cast<double>(_MconvMoityBulk2(i, j));
787+
jIdx++;
783788
}
784789
mIdx++;
785790
}
@@ -817,7 +822,7 @@ void CSTRModel::consistentInitialState(const SimulationTime& simTime, double* co
817822
if(_QsCompBulk[j] == 0)
818823
continue;
819824

820-
mat.native(mIdx, jIdx) = _MconvMoityBulk2(i, j);
825+
mat.native(mIdx, jIdx) = static_cast<double>(_MconvMoityBulk2(i, j));
821826
jIdx++;
822827
}
823828
mIdx++;
@@ -854,7 +859,7 @@ void CSTRModel::consistentInitialState(const SimulationTime& simTime, double* co
854859
{
855860
if (_QsCompBulk[j] == 0)
856861
continue;
857-
dotProduct += _MconvMoityBulk2(i, j) * x[jIdx];
862+
dotProduct += static_cast<double>(_MconvMoityBulk2(i, j)) * x[jIdx];
858863
jIdx++;
859864
}
860865
r[mIdx] = dotProduct - conservedQuants[mIdx];
@@ -1719,9 +1724,10 @@ void CSTRModel::applyConservedMoitiesBulk2(double t, unsigned int secIdx, const
17191724
Eigen::Map<Eigen::Vector<ResidualType, Eigen::Dynamic>> resCWithMoities(static_cast<ResidualType*>(temp), _nComp);
17201725
resCWithMoities.setZero();
17211726

1727+
Eigen::Matrix<ResidualType, Eigen::Dynamic, Eigen::Dynamic> MconvMoityBulk2Cast = _MconvMoityBulk2.template cast<ResidualType>();
17221728

17231729
// multiply conserved moities matrix with residual
1724-
resCWithMoities = M * mapResC;
1730+
resCWithMoities = MconvMoityBulk2Cast * mapResC;
17251731

17261732
// add quasi stationary reaction to residium
17271733
const int nQsReac = _dynReactionBulk->numReactionQuasiStationary();
@@ -1745,7 +1751,7 @@ void CSTRModel::applyConservedMoitiesBulk2(double t, unsigned int secIdx, const
17451751

17461752
if (wantJac)
17471753
{
1748-
EigenMatrixTimesDemseMatrix(M, _jac);
1754+
EigenMatrixTimesDemseMatrix(MconvMoityBulk2Cast, _jac);
17491755
int mIdx = 0;
17501756
int rIdx = 0;
17511757
for (int i = 0; i < _nComp; i++)
@@ -1764,52 +1770,9 @@ void CSTRModel::applyConservedMoitiesBulk2(double t, unsigned int secIdx, const
17641770

17651771
}
17661772

1767-
//std::cout << "Jacobian with conserved moities" << std::endl;
1768-
//std::cout << "Jacobian before" << std::endl;
1769-
//for (int i = 0; i < _nComp + 1; i++)
1770-
//{
1771-
// for (int j = 0; j < _nComp+ 1; j++)
1772-
// {
1773-
// std::cout << _jac.native(i, j) << " ";
1774-
// }
1775-
// std::cout << std::endl;
1776-
//}
1777-
// multiply conserved moities matrix with jacobian
1778-
//if (wantJac)
1779-
//{
1780-
// EigenMatrixTimesDemseMatrix(M, _jac);
1781-
1782-
// int state = _nComp - _dynReactionBulk->numReactionQuasiStationary();
1783-
// for (int qsReac = 0; qsReac < nQsReac; ++qsReac) // todo this in a function
1784-
// {
1785-
// if (state < _nComp)
1786-
// {
1787-
// _dynReactionBulk->analyticJacobianQuasiStationaryReaction(t, secIdx, colPos, reinterpret_cast<double const*>(c), state, qsReac, _jac.row(state), subAlloc);
1788-
// _jac.native(state, _nComp + _totalBound) = 0.0; // dF_{ci}/dvliquid = 0
1789-
// state++;
1790-
// }
1791-
// else
1792-
// throw InvalidParameterException(
1793-
// "Jacobian implementation with conserved moities: Too many quasi stationary reactions detected. "
1794-
// "Please check the implementation of the model."
1795-
// );
1796-
// }
1797-
1798-
//std::cout << "Jacobian with conserved moities" << std::endl;
1799-
//std::cout << "Jacobian after" << std::endl;
1800-
//for (int i = 0; i < _nComp+ 1; i++)
1801-
//{
1802-
// for (int j = 0; j < _nComp+1; j++)
1803-
//{
1804-
// std::cout << _jac.native(i, j) << " ";
1805-
// }
1806-
//std::cout << std::endl;
1807-
//}
1808-
18091773
}
18101774

18111775

1812-
18131776
template <typename StateType, typename ResidualType, typename ParamType, bool wantJac>
18141777
int CSTRModel::residualImpl(double t, unsigned int secIdx, StateType const* const y, double const* const yDot, ResidualType* const res, LinearBufferAllocator tlmAlloc)
18151778
{

src/libcadet/model/StirredTankModel.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
namespace cadet
3333
{
34-
struct ColumnPosition;
34+
struct ColumnPosition;
3535

3636
namespace model
3737
{
@@ -183,7 +183,7 @@ class CSTRModel : public UnitOperationBase
183183
IDynamicReactionModel* _dynReactionBulk; //!< Dynamic reactions in the bulk volume
184184

185185
Eigen::MatrixXd _MconvMoityBulk; //!< Matrix with conservation of moieties in the bulk volume
186-
Eigen::MatrixXd _MconvMoityBulk2; //!< Matrix with conservation of moieties in the bulk volume
186+
Eigen::Matrix<active, Eigen::Dynamic, Eigen::Dynamic> _MconvMoityBulk2; //!< Matrix with conservation of moieties in the bulk volume
187187
int const* _qsReactionBulk; //!< Indices of reactions that are not conserved in the bulk volume
188188
bool _hasQuasiStationaryReactionBulk; //!< Flag that determines whether there are quasi-stationary reactions in the bulk volume
189189
std::vector<int> _QsCompBulk; //!< Indices of components that are conserved in the bulk volume

src/libcadet/model/reaction/CrystallizationReaction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ namespace cadet
198198
virtual bool requiresConfiguration() const CADET_NOEXCEPT { return true; }
199199
virtual bool usesParamProviderInDiscretizationConfig() const CADET_NOEXCEPT { return false; }
200200
template <typename RowIterator>
201-
void jacobianQuasiSteadyLiquidImpl(double t, unsigned int secIdx, const ColumnPosition& colPos, double const* y, int state, int reaction, const RowIterator& jac, LinearBufferAllocator workSpace) const { }
201+
void jacobianQuasiStationaryBulkImpl(double t, unsigned int secIdx, const ColumnPosition& colPos, double const* y, int state, int reaction, const RowIterator& jac, LinearBufferAllocator workSpace) const { }
202202

203203
template <typename RowIterator>
204204
void jacobianSingleFluxImpl(double t, unsigned int secIdx, const ColumnPosition& colPos, double const* y, int state, int reaction, const RowIterator& jac, LinearBufferAllocator workSpace) const { }
205205

206206
template<typename StateType, typename ResidualType>
207207
int quasiStationaryFlux(double t, unsigned int secIdx, const ColumnPosition& colPos, StateType const* y,
208-
Eigen::Map<Eigen::Vector<ResidualType, Eigen::Dynamic>> fluxes, int const* mapQSReac, LinearBufferAllocator workSpace){return 0;}
208+
Eigen::Map<Eigen::Vector<ResidualType, Eigen::Dynamic>> fluxes, LinearBufferAllocator workSpace){return 0;}
209209

210210
virtual int const* reactionQuasiStationarity() const CADET_NOEXCEPT { return nullptr; }
211211
virtual void timeDerivativeQuasiStationaryReaction(double t, unsigned int secIdx, const ColumnPosition& colPos, double const* y, double* dReacDt, LinearBufferAllocator workSpace){ }
@@ -348,7 +348,7 @@ namespace cadet
348348
virtual unsigned int numReactionsCombined() const CADET_NOEXCEPT { return 1; }
349349
virtual unsigned int numReactionQuasiStationary() const CADET_NOEXCEPT { return 0; }
350350
template<typename ResidualType>
351-
void fillConservedMoietiesBulk21(Eigen::Matrix<ResidualType, Eigen::Dynamic, Eigen::Dynamic>& M, int& conservedState, std::vector<int>& QsCompBulk) {}
351+
void fillConservedMoietiesBulk(Eigen::Matrix<ResidualType, Eigen::Dynamic, Eigen::Dynamic>& M, int& conservedState, std::vector<int>& QsCompBulk) {}
352352

353353
CADET_DYNAMICREACTIONMODEL_BOILERPLATE
354354

src/libcadet/model/reaction/DummyReaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class DummyDynamicReaction : public IDynamicReactionModel
130130
virtual unsigned int numReactionsCombined() const CADET_NOEXCEPT { return 0; }
131131
virtual unsigned int numReactionQuasiStationary() const CADET_NOEXCEPT { return 0; }
132132
template<typename ResidualType>
133-
void fillConservedMoietiesBulk21(Eigen::Matrix<ResidualType, Eigen::Dynamic, Eigen::Dynamic>& M, int& conservedState, std::vector<int>& QsCompBulk) {}
133+
void fillConservedMoietiesBulk(Eigen::Matrix<ResidualType, Eigen::Dynamic, Eigen::Dynamic>& M, int& conservedState, std::vector<int>& QsCompBulk) {}
134134
protected:
135135
};
136136

0 commit comments

Comments
 (0)