Skip to content

Commit

Permalink
wip fix memory issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jbreue16 committed Oct 19, 2024
1 parent 7fcdf23 commit 280170f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/libcadet/model/GeneralRateModelDG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ constexpr double SurfVolRatioSlab = 1.0;


GeneralRateModelDG::GeneralRateModelDG(UnitOpIdx unitOpIdx) : UnitOperationBase(unitOpIdx),
_hasSurfaceDiffusion(0, false), _dynReactionBulk(nullptr),
_hasSurfaceDiffusion(0, false), _singleParDepSurfDiffusion(false), _dynReactionBulk(nullptr),
_globalJac(), _globalJacDisc(), _jacInlet(), _hasParDepSurfDiffusion(false),
_analyticJac(true), _jacobianAdDirs(0), _factorizeJacobian(false), _tempState(nullptr),
_initC(0), _initCp(0), _initQ(0), _initState(0), _initStateDot(0)
Expand Down
21 changes: 14 additions & 7 deletions src/libcadet/model/GeneralRateModelDG.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,13 @@ class GeneralRateModelDG : public UnitOperationBase
delete[] parNodes;
delete[] parPolyDerM;
delete[] minus_InvMM_ST;
delete[] minus_parInvMM_Ar;
delete[] parInvWeights;
delete[] parInvMM;
delete[] parInvMM_Leg;
delete[] Ir;
delete[] Dr;
delete[] secondOrderStiffnessM;

delete[] DGjacParDispBlocks;

Expand Down Expand Up @@ -2547,32 +2549,37 @@ class GeneralRateModelDG : public UnitOperationBase
return 1;
}

int calcStaticAnaJacobian_GRM(unsigned int secIdx) {

int calcStaticAnaJacobian_GRM(unsigned int secIdx)
{
Indexer idxr(_disc);
// inlet and bulk jacobian
_convDispOp.calcStaticAnaJacobian(_globalJac, _jacInlet, idxr.offsetC());

// particle jacobian (without isotherm, which is handled in residualKernel)
for (int colNode = 0; colNode < _disc.nPoints; colNode++) {
for (int type = 0; type < _disc.nParType; type++) {
double* invBetaP = new double[_disc.nComp];

// particle jacobian (without isotherm, which is handled in residualKernel)
for (int colNode = 0; colNode < _disc.nPoints; colNode++)
{
for (int type = 0; type < _disc.nParType; type++)
{
// Prepare parameters
const active* const parDiff = getSectionDependentSlice(_parDiffusion, _disc.nComp * _disc.nParType, secIdx) + type * _disc.nComp;

// Ordering of particle surface diffusion:
// bnd0comp0, bnd0comp1, bnd0comp2, bnd1comp0, bnd1comp1, bnd1comp2
const active* const parSurfDiff = getSectionDependentSlice(_parSurfDiffusion, _disc.strideBound[_disc.nParType], secIdx) + _disc.nBoundBeforeType[type];

double* invBetaP = new double[_disc.nComp];
for (int comp = 0; comp < _disc.nComp; comp++) {
for (int comp = 0; comp < _disc.nComp; comp++)
{
invBetaP[comp] = (1.0 - static_cast<double>(_parPorosity[type])) / (static_cast<double>(_poreAccessFactor[_disc.nComp * type + comp]) * static_cast<double>(_parPorosity[type]));
}

calcStaticAnaParticleDispJacobian(type, colNode, parDiff, parSurfDiff, invBetaP);
}
}

delete[] invBetaP;

calcFluxJacobians(secIdx);

return _globalJac.isCompressed(); // check if the jacobian estimation fits the pattern
Expand Down

0 comments on commit 280170f

Please sign in to comment.