[petsc-users] Internal product through a matrix norm

Jed Brown jed at jedbrown.org
Wed Jan 22 12:30:20 CST 2020


Jeremy Theler <jeremy at seamplex.com> writes:

> Sorry for the basic question, but here it goes.
> Say I have a vector u and a matrix K and I want to compute the scalar
>
>     e = u^T K u
>
> (for example the strain energy if u are displacements a K is the
> stiffness matrix).
>
> Is there anything better (both in elegance and efficiency) than doing
> this?
>
>     PetscScalar e;
>     Vec Kx;
>   
>     VecDuplicate(x, &Kx);
>     MatMult(K, x, Kx);
>     VecDot(x, Kx, &e);

Nope; this is standard.


More information about the petsc-users mailing list