Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element view on PETSC vector breaks const-ness invariant #2180

Open
metivett opened this issue Nov 10, 2023 · 0 comments
Open

Element view on PETSC vector breaks const-ness invariant #2180

metivett opened this issue Nov 10, 2023 · 0 comments

Comments

@metivett
Copy link
Member

Functionspace::Element view onto a PETSC vector, as provided by the

element_type FunctionSpace::element( Vector<value_type> const& vec, int blockIdStart = 0 );
element_ptrtype FunctionSpace::elementPtr( Vector<value_type> const& vec, int blockIdStart = 0 );

functions (functionspace.hpp:5285 and functionspace.hpp:5315 resp.), explicitly break const-ness invariance by const_casting the input Vector<value_type> const& vec to VectorPetsc<value_type> *.
This can notably trigger PETSC crash (Incorrect object state) if such view is accessed within a PETSC::VecLockReadPush context, which is for example the case when assembling SNES residuals in the TOOLBOXES, which eventually ends-up calling the provided Feel ModelAlgebraicFactory::updateResidual function through PETSC::SNESComputeFunction (via __feel_petsc_snes_residual), which enforces read-only access to the "X" (input) vector (at least from PETSC v3.18 on).
Note that the element view on the "X" (currentSolution) vector is actually often hidden in the ModelContext used, for example when retrieving auto const& u = mctx.field( FieldTag::velocity(this), "velocity" ); in the FluidMechanics toolbox, which actually retrieves the current velocity vector through the modelFields as a view auto field_u = this->fieldVelocity().functionSpace()->elementPtr( *sol, rowStartInVector+this->startSubBlockSpaceIndex("velocity") ); (c.f. fluidmechanics.hpp:2050).

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

No branches or pull requests

1 participant