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);


--
jeremy theler
www.seamplex.com


Reply via email to