Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
With the default DirichletBC apprach, the BCs are applied on the initial guess before linearising. This could be problematic, as the intial state with BCs could cause NaNs for some nonlinear problems containing functions that blow up like logarithms.
This PR adds a kwarg to
solve(F == 0, u, bcs, pre_apply_bcs=False)
to delay the imposition of bcs, so that the problem is linearised around the initial guess before imposing the boundary conditions. Internally, we assemble the residual of the bcs:bc_resid = u - bc_data
on the rows of the residualCofunction
, and the rows and columns of the Jacobian remain as those of the identity, to preserve symmetry. This means that the interior rows of residual need an extra termF -= action(J, bc_resid)
coming from the lifted BC values on each nonlinear update, in a similar way we already do for the BC lifting in the linear case.A cool implication of this approach for nonlinear problems where the forcing is driven by inhomogeneous boundary conditions (inflow or traction BCs) is that a linesearch method automatically enables some sort of parameter continuation.