Skip to content

Commit 27f263c

Browse files
committed
wip fix reaction tests
1 parent 72bcad9 commit 27f263c

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

src/libcadet/model/ColumnModel1D.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ class ColumnModel1D : public UnitOperationBase
501501
}
502502
}
503503

504-
// particle jacobian (including film diffusion, isotherm and time derivative)
504+
// particle jacobian (including film diffusion, isotherm, reaction and time derivative)
505505
for (int colNode = 0; colNode < _disc.nPoints; colNode++)
506506
{
507507
for (int type = 0; type < _disc.nParType; type++)
@@ -519,7 +519,7 @@ class ColumnModel1D : public UnitOperationBase
519519
// inlet and bulk jacobian
520520
_convDispOp.calcTransportJacobian(_globalJac, _jacInlet, idxr.offsetC());
521521

522-
// particle jacobian (without isotherm, which is handled in residualKernel)
522+
// particle transport jacobian
523523
for (int colNode = 0; colNode < _disc.nPoints; colNode++)
524524
{
525525
for (int parType = 0; parType < _disc.nParType; parType++)

src/libcadet/model/particle/GeneralRateParticle.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ namespace model
162162
paramProvider.popScope();
163163
}
164164

165+
MultiplexedScopeSelector scopeGuard(paramProvider, "reaction", _dynReaction->usesParamProviderInDiscretizationConfig());
165166
reactionConfSuccess = _dynReaction->configureModelDiscretization(paramProvider, _nComp, _nBound.get(), _parDiffOp->offsetBoundComp()) && reactionConfSuccess;
166167
}
167168

src/libcadet/model/particle/HomogeneousParticle.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ namespace model
176176
paramProvider.popScope();
177177
}
178178

179+
MultiplexedScopeSelector scopeGuard(paramProvider, "reaction", _dynReaction->usesParamProviderInDiscretizationConfig());
179180
reactionConfSuccess = _dynReaction->configureModelDiscretization(paramProvider, _nComp, _nBound.get(), _boundOffset) && reactionConfSuccess;
180181
}
181182

@@ -404,24 +405,22 @@ namespace model
404405

405406
void HomogeneousParticle::setParJacPattern(std::vector<Eigen::Triplet<double>>& tripletList, const unsigned int offsetPar, const unsigned int offsetBulk, unsigned int colNode, unsigned int secIdx) const
406407
{
407-
// binding Jacobian pattern
408-
// add dense nComp * nBound blocks, since all solid and liquid entries can be coupled through binding.
408+
// binding and reaction Jacobian pattern
409+
// add dense nComp * nBound blocks, since all solid and liquid entries can be coupled through reaction and or binding.
409410
for (unsigned int parState = 0; parState < _nComp + _strideBound; parState++) {
410411
for (unsigned int toParState = 0; toParState < _nComp + _strideBound; toParState++) {
411412
tripletList.push_back(Eigen::Triplet<double>(offsetPar + parState, offsetPar + toParState, 0.0));
412413
}
413414
}
414415

415416
// flux Jacobian pattern
416-
417417
for (unsigned int comp = 0; comp < _nComp; comp++)
418418
{
419419
tripletList.push_back(Eigen::Triplet<double>(offsetPar + comp, offsetBulk + comp, 0.0));
420420
tripletList.push_back(Eigen::Triplet<double>(offsetBulk + comp, offsetPar + comp, 0.0));
421421
}
422422
}
423423

424-
425424
unsigned int HomogeneousParticle::jacobianNNZperParticle() const
426425
{
427426
return (_nComp + _strideBound) * (_nComp + _strideBound) + _nComp * 4; // reaction, binding patter + film diffusion pattern for one particle

src/libcadet/model/parts/ParticleDiffusionOperatorDG.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,12 +912,13 @@ namespace parts
912912
// ======================================== DG particle Jacobian ============================================= //
913913
// ========================================================================================================================================================== //
914914

915-
void ParticleDiffusionOperatorDG::parBindingPattern(std::vector<Eigen::Triplet<double>>& tripletList, const int offset, const unsigned int colNode)
915+
void ParticleDiffusionOperatorDG::parBindingAndReactionPattern(std::vector<Eigen::Triplet<double>>& tripletList, const int offset, const unsigned int colNode)
916916
{
917-
// every bound state might depend on every bound and liquid state
918917
for (int parNode = 0; parNode < _nParPoints; parNode++)
919918
{
920-
for (int state = 0; state < strideParPoint(); state++)
919+
// binding: every bound state might depend on every bound and liquid state
920+
// reaction: every liquid and bound state might depend on every liquid and bound state
921+
for (int state = 0; state < _strideBound; state++)
921922
{
922923
for (int stateDep = 0; stateDep < strideParPoint(); stateDep++) {
923924
// row: jump over previous nodes and liquid states and add current bound state offset
@@ -928,14 +929,14 @@ namespace parts
928929
}
929930
}
930931
}
932+
931933
/**
932934
* @brief calculates the particle dispersion jacobian Pattern, including entries for the dependence of particle entries on bulk entries through film diffusion boundary condition
933935
* @detail Does NOT add film diffusion entries for the dependence of bulk conc. on particle conc.
934936
*/
935937
void ParticleDiffusionOperatorDG::setParticleJacobianPattern(std::vector<ParticleDiffusionOperatorDG::T>& tripletList, unsigned int offsetPar, unsigned int offsetBulk, unsigned int colNode, unsigned int secIdx)
936938
{
937-
938-
parBindingPattern(tripletList, offsetPar, colNode);
939+
parBindingAndReactionPattern(tripletList, offsetPar, colNode);
939940

940941
// Ordering of particle surface diffusion:
941942
// bnd0comp0, bnd1comp0, bnd0comp1, bnd1comp1, bnd0comp2, bnd1comp2

src/libcadet/model/parts/ParticleDiffusionOperatorDG.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ namespace parts
143143

144144
protected:
145145

146-
void parBindingPattern(std::vector<Eigen::Triplet<double>>& tripletList, const int offset, const unsigned int colNode);
146+
void parBindingAndReactionPattern(std::vector<Eigen::Triplet<double>>& tripletList, const int offset, const unsigned int colNode);
147147

148148
template <typename StateType, typename ResidualType, typename ParamType, bool wantJac, bool wantRes>
149149
int residualImpl(double t, unsigned int secIdx, StateType const* yPar, StateType const* yBulk, double const* yDotPar, ResidualType* resPar, linalg::BandedEigenSparseRowIterator& jacBase);

test/ReactionModelTests.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,18 @@ namespace reaction
221221

222222
std::vector<int> nBound = jpp.getIntArray("NBOUND");
223223
const int nTotalBound = std::accumulate(nBound.begin(), nBound.end(), 0);
224-
jpp.set("REACTION_MODEL", "MASS_ACTION_LAW");
225224

226225
std::string scope;
227226
if (!isCSTR)
227+
{
228+
jpp.set("REACTION_MODEL", "MASS_ACTION_LAW");
228229
scope = "reaction";
230+
}
229231
else
232+
{
233+
jpp.set("REACTION_MODEL_PARTICLE", "MASS_ACTION_LAW");
230234
scope = "reaction_particle";
235+
}
231236

232237
jpp.addScope(scope);
233238
auto gs2 = util::makeGroupScope(jpp, scope);

0 commit comments

Comments
 (0)