Skip to content

Commit 1765bfd

Browse files
committed
change jacobian impl
1 parent e21fb9a commit 1765bfd

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/libcadet/model/StirredTankModel.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,31 +1329,45 @@ int CSTRModel::residualImpl(double t, unsigned int secIdx, StateType const* cons
13291329
{
13301330
resCMoities[comp] = _MconvMoityBulk.row(MoityIdx) * resC[comp];
13311331
MoityIdx++;
1332+
1333+
if (wantJac)
1334+
_jac.native(comp, _nComp + _totalBound) = 0; // dF_{Vliquid}/dci = 0
1335+
13321336
}
13331337
else if (comp < _nComp - nmoities)
13341338
{
13351339
resCMoities[comp] += v * flux[comp];
1340+
1341+
if (wantJac)
1342+
_jac.native(comp, _nComp + _totalBound) = static_cast<double>(flux[comp]); // dF/dci = v_liquid
1343+
13361344
}
1345+
13371346
else if(comp > _nComp - nmoities)
13381347
{
13391348
resCMoities[comp] = v * flux[comp];
1349+
1350+
if (wantJac)
1351+
_dynReactionBulk->analyticJacobianLiquidAdd(t, secIdx, colPos, reinterpret_cast<double const*>(c), -static_cast<double>(v), _jac.row(0), subAlloc);
13401352
}
13411353
}
1354+
13421355
Eigen::Map<Vector<ResidualType, Dynamic>> mapResC(resC, _nComp);
13431356
mapResC = resCMoities;
1357+
13441358
}
13451359
else
13461360
{
13471361
for (unsigned int comp = 0; comp < _nComp; ++comp)
13481362
resC[comp] += v * flux[comp];
1349-
}
1350-
1351-
if (wantJac)
1352-
{
1353-
for (unsigned int comp = 0; comp < _nComp; ++comp)
1354-
_jac.native(comp, _nComp + _totalBound) += static_cast<double>(flux[comp]); // dF/dvliquid = flux
1363+
1364+
if (wantJac)
1365+
{
1366+
for (unsigned int comp = 0; comp < _nComp; ++comp)
1367+
_jac.native(comp, _nComp + _totalBound) += static_cast<double>(flux[comp]); // dF/dvliquid = flux
13551368

1356-
_dynReactionBulk->analyticJacobianLiquidAdd(t, secIdx, colPos, reinterpret_cast<double const*>(c), -static_cast<double>(v), _jac.row(0), subAlloc);
1369+
_dynReactionBulk->analyticJacobianLiquidAdd(t, secIdx, colPos, reinterpret_cast<double const*>(c), -static_cast<double>(v), _jac.row(0), subAlloc);
1370+
}
13571371
}
13581372
}
13591373

0 commit comments

Comments
 (0)