Skip to content

Commit bb857cd

Browse files
committed
Refactor particle operator to be particle type specific (#423)
1 parent f462933 commit bb857cd

8 files changed

+1752
-903
lines changed

src/libcadet/model/GeneralRateModelDG-InitialConditions.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ void GeneralRateModelDG::consistentInitialState(const SimulationTime& simTime, d
386386
active* const localAdY = adJac.adY ? adJac.adY + localOffsetToParticle + localOffsetInParticle : nullptr;
387387

388388
// r (particle) coordinate of current node
389-
const double r = _parDiffOp.relativeCoordinate(type, node);
389+
const double r = _parDiffOp[type].relativeCoordinate(node);
390390
const ColumnPosition colPos{ z, 0.0, r };
391391

392392
// Determine whether nonlinear solver is required
@@ -397,8 +397,8 @@ void GeneralRateModelDG::consistentInitialState(const SimulationTime& simTime, d
397397
linalg::selectVectorSubset(qShell - _disc.nComp, mask, solution);
398398

399399
// Save values of conserved moieties
400-
const double epsQ = 1.0 - static_cast<double>(_parDiffOp._parPorosity[type]);
401-
linalg::conservedMoietiesFromPartitionedMask(mask, _disc.nBound + type * _disc.nComp, _disc.nComp, qShell - _disc.nComp, conservedQuants, static_cast<double>(_parDiffOp._parPorosity[type]), epsQ);
400+
const double epsQ = 1.0 - static_cast<double>(_parDiffOp[type]._parPorosity);
401+
linalg::conservedMoietiesFromPartitionedMask(mask, _disc.nBound + type * _disc.nComp, _disc.nComp, qShell - _disc.nComp, conservedQuants, static_cast<double>(_parDiffOp[type]._parPorosity), epsQ);
402402

403403
std::function<bool(double const* const, linalg::detail::DenseMatrixBase&)> jacFunc;
404404

@@ -477,7 +477,7 @@ void GeneralRateModelDG::consistentInitialState(const SimulationTime& simTime, d
477477
continue;
478478
}
479479

480-
mat.native(rIdx, rIdx) = static_cast<double>(_parDiffOp._parPorosity[type]);
480+
mat.native(rIdx, rIdx) = static_cast<double>(_parDiffOp[type]._parPorosity);
481481

482482
for (unsigned int bnd = 0; bnd < _disc.nBound[_disc.nComp * type + comp]; ++bnd, ++bndIdx)
483483
{
@@ -525,7 +525,7 @@ void GeneralRateModelDG::consistentInitialState(const SimulationTime& simTime, d
525525
continue;
526526
}
527527

528-
mat.native(rIdx, rIdx) = static_cast<double>(_parDiffOp._parPorosity[type]);
528+
mat.native(rIdx, rIdx) = static_cast<double>(_parDiffOp[type]._parPorosity);
529529

530530
for (unsigned int bnd = 0; bnd < _disc.nBound[_disc.nComp * type + comp]; ++bnd, ++bndIdx)
531531
{
@@ -572,7 +572,7 @@ void GeneralRateModelDG::consistentInitialState(const SimulationTime& simTime, d
572572
continue;
573573
}
574574

575-
r[rIdx] = static_cast<double>(_parDiffOp._parPorosity[type]) * x[rIdx] - conservedQuants[rIdx];
575+
r[rIdx] = static_cast<double>(_parDiffOp[type]._parPorosity) * x[rIdx] - conservedQuants[rIdx];
576576

577577
for (unsigned int bnd = 0; bnd < _disc.nBound[_disc.nComp * type + comp]; ++bnd, ++bndIdx)
578578
{
@@ -713,7 +713,7 @@ void GeneralRateModelDG::consistentInitialTimeDerivative(const SimulationTime& s
713713
if (_binding[type]->dependsOnTime())
714714
{
715715
// r (particle) coordinate of current node (particle radius normed to 1) - needed in externally dependent adsorption kinetic
716-
const double r = _parDiffOp.relativeCoordinate(type, j);
716+
const double r = _parDiffOp[type].relativeCoordinate(j);
717717

718718
_binding[type]->timeDerivativeQuasiStationaryFluxes(simTime.t, simTime.secIdx,
719719
ColumnPosition{ z, 0.0, r },
@@ -797,10 +797,13 @@ void GeneralRateModelDG::consistentInitialTimeDerivative(const SimulationTime& s
797797
*/
798798
void GeneralRateModelDG::leanConsistentInitialState(const SimulationTime& simTime, double* const vecStateY, const AdJacobianParams& adJac, double errorTol, util::ThreadLocalStorage& threadLocalMem)
799799
{
800-
if (isSectionDependent(_parDiffOp._parDiffusionMode) || isSectionDependent(_parDiffOp._parSurfDiffusionMode))
801-
LOG(Warning) << "Lean consistent initialization is not appropriate for section-dependent pore and surface diffusion";
800+
for (int parType = 0; parType < _disc.nParType; parType++)
801+
{
802+
if (isSectionDependent(_parDiffOp[parType]._parDiffusionMode) || isSectionDependent(_parDiffOp[parType]._parSurfDiffusionMode))
803+
LOG(Warning) << "Lean consistent initialization is not appropriate for section-dependent pore and surface diffusion";
802804

803-
BENCH_SCOPE(_timerConsistentInit);
805+
BENCH_SCOPE(_timerConsistentInit);
806+
}
804807

805808
Indexer idxr(_disc);
806809

@@ -830,7 +833,7 @@ void GeneralRateModelDG::leanConsistentInitialState(const SimulationTime& simTim
830833
const int localOffsetInParticle = static_cast<int>(shell) * idxr.strideParNode(type) + idxr.strideParLiquid();
831834
double* const qShell = vecStateY + localOffsetToParticle + localOffsetInParticle;
832835
// r (particle) coordinate of current node
833-
const double r = _parDiffOp.relativeCoordinate(type, shell);
836+
const double r = _parDiffOp[type].relativeCoordinate(shell);
834837
const ColumnPosition colPos{ z, 0.0, r};
835838

836839
// Perform consistent initialization that does not require a full fledged nonlinear solver (that may fail or damage the current state vector)
@@ -885,8 +888,13 @@ void GeneralRateModelDG::leanConsistentInitialState(const SimulationTime& simTim
885888
*/
886889
void GeneralRateModelDG::leanConsistentInitialTimeDerivative(double t, double const* const vecStateY, double* const vecStateYdot, double* const res, util::ThreadLocalStorage& threadLocalMem)
887890
{
888-
if (isSectionDependent(_parDiffOp._parDiffusionMode) || isSectionDependent(_parDiffOp._parSurfDiffusionMode))
889-
LOG(Warning) << "Lean consistent initialization is not appropriate for section-dependent pore and surface diffusion";
891+
for (int parType = 0; parType < _disc.nParType; parType++)
892+
{
893+
if (isSectionDependent(_parDiffOp[parType]._parDiffusionMode) || isSectionDependent(_parDiffOp[parType]._parSurfDiffusionMode))
894+
LOG(Warning) << "Lean consistent initialization is not appropriate for section-dependent pore and surface diffusion";
895+
896+
BENCH_SCOPE(_timerConsistentInit);
897+
}
890898

891899
BENCH_SCOPE(_timerConsistentInit);
892900

@@ -1268,8 +1276,13 @@ void GeneralRateModelDG::solveBulkTimeDerivativeSystem(const SimulationTime& sim
12681276
void GeneralRateModelDG::leanConsistentInitialSensitivity(const SimulationTime& simTime, const ConstSimulationState& simState,
12691277
std::vector<double*>& vecSensY, std::vector<double*>& vecSensYdot, active const* const adRes, util::ThreadLocalStorage& threadLocalMem)
12701278
{
1271-
if (isSectionDependent(_parDiffOp._parDiffusionMode) || isSectionDependent(_parDiffOp._parSurfDiffusionMode))
1272-
LOG(Warning) << "Lean consistent initialization is not appropriate for section-dependent pore and surface diffusion";
1279+
for (int parType = 0; parType < _disc.nParType; parType++)
1280+
{
1281+
if (isSectionDependent(_parDiffOp[parType]._parDiffusionMode) || isSectionDependent(_parDiffOp[parType]._parSurfDiffusionMode))
1282+
LOG(Warning) << "Lean consistent initialization is not appropriate for section-dependent pore and surface diffusion";
1283+
1284+
BENCH_SCOPE(_timerConsistentInit);
1285+
}
12731286

12741287
BENCH_SCOPE(_timerConsistentInit);
12751288

src/libcadet/model/GeneralRateModelDG-LinearSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void GeneralRateModelDG::assembleDiscretizedGlobalJacobian(double alpha, Indexer
220220
*/
221221
void GeneralRateModelDG::addTimeDerivativeToJacobianParticleShell(linalg::BandedEigenSparseRowIterator& jac, const Indexer& idxr, double alpha, unsigned int parType)
222222
{
223-
parts::cell::addTimeDerivativeToJacobianParticleShell<linalg::BandedEigenSparseRowIterator, true>(jac, alpha, static_cast<double>(_parDiffOp._parPorosity[parType]), _disc.nComp, _disc.nBound + _disc.nComp * parType,
223+
parts::cell::addTimeDerivativeToJacobianParticleShell<linalg::BandedEigenSparseRowIterator, true>(jac, alpha, static_cast<double>(_parDiffOp[parType]._parPorosity), _disc.nComp, _disc.nBound + _disc.nComp * parType,
224224
_poreAccessFactor.data() + _disc.nComp * parType, _disc.strideBound[parType], _disc.boundOffset + _disc.nComp * parType, _binding[parType]->reactionQuasiStationarity());
225225
}
226226

0 commit comments

Comments
 (0)