Skip to content

Fix Jp + multigrid#5189

Draft
pbrubeck wants to merge 1 commit into
mainfrom
pbrubeck/fix/pmat
Draft

Fix Jp + multigrid#5189
pbrubeck wants to merge 1 commit into
mainfrom
pbrubeck/fix/pmat

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

@pbrubeck pbrubeck requested a review from stefanozampini June 18, 2026 08:52
@pbrubeck pbrubeck force-pushed the pbrubeck/fix/pmat branch from 15ec603 to 9098532 Compare June 23, 2026 16:39
dm = ksp.getDM()
ctx = dmhooks.get_appctx(dm)
A = ctx._jac.petscmat
P = A if ctx.Jp is None else ctx._pjac.petscmat

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe passing None is cleaner code

Suggested change
P = A if ctx.Jp is None else ctx._pjac.petscmat
P = None if ctx.Jp is None else ctx._pjac.petscmat

Is this creating new matrices or just passing the ones stored inside?
Ideally, callbacks to create operators should create new ones, rather than passing references to stored matrices. Ideally, one can do

DMCreateMatrix(dm,&A1);
// ...populate A1
DMCreateMatrix(dm,&A2);
// ...populate A2

// use A1 and A2 independently

I believe it is conceptually wrong to pass matrices already stored in the context. One should duplicate the internal matrices instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants