Skip to content

Conversation

jrmaddison
Copy link
Contributor

Fixes based on reading the code.

  1. Handle boundary conditions in the Riesz map inverse. This seems to be the consistent way to apply this, but should be reviewed.
  2. Zero guess the Riesz map linear solver. Required for consistent behaviour, e.g. if changing the order of mappings.

Minor fixes

  1. Remove an unnecessary allocation.
  2. Catch the case where boundary conditions are supplied with an $l_2$ Riesz map.

@jrmaddison jrmaddison marked this pull request as ready for review September 23, 2025 18:40
@jrmaddison jrmaddison force-pushed the jrmaddison/riesz_map_fixes branch from ed5213a to c04f182 Compare September 23, 2025 18:45
else:
solve, rhs, soln = self._solver
rhs.assign(value)
soln.zero()
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't PETSc always use a zero initial guess unless you pass -ksp_initial_guess_nonzero?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might be ignored due to #4142. I'd need to check for this use case, but I think it's still safer to zero here.

Copy link
Contributor

@pbrubeck pbrubeck Sep 26, 2025

Choose a reason for hiding this comment

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

LinearSolver inherits from NonlinearVariationalSolver, which means that we are running a SNES, which gives a different behaivor from the plain KSP. Currently -ksp_initial_guess_nonzero False zeros the update to whatever is prescribed as the initial guess.

Copy link
Contributor

Choose a reason for hiding this comment

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

Setting the initial guess explicitly outside PETSc is the only way with SNES.

@JHopeCollins
Copy link
Member

@pbrubeck I think this looks fine but could you cast a quick eye over it please?

else:
bcs = tuple(bcs)
if len(bcs) > 0 and inner_product == "l2":
raise ValueError("Cannot supply boundary conditions with an l2 Riesz map")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious here. Does this lead to the wrong results in optimization?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does "l2" here means that we are imposing the wrong inner-product between two primal objects, or does it mean that we are pairing a primal with a dual?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm curious here. Does this lead to the wrong results in optimization?

For $l_2$ the bcs are ignored. They could probably be applied, but I'm not sure it would be that useful.

Does "l2" here means that we are imposing the wrong inner-product between two primal objects, or does it mean that we are pairing a primal with a dual?

Yes, it's the basis dependent map defined by dof assignment. I'm not sure if there's a case to remove this now (Firedrake code at least doesn't seem to use it much?) but maybe not for this PR?

Copy link
Member

@JHopeCollins JHopeCollins Sep 26, 2025

Choose a reason for hiding this comment

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

I'm not sure if there's a case to remove this now (Firedrake code at least doesn't seem to use it much?) but maybe not for this PR?

This close to a major release I'd say lets keep this PR to fixes, then we can think about API changes after.

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.

3 participants