This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

C++: How to subtract one GenericVector object from another.

0 votes

Hi,
Assume that I have two GenericVector objects, one that represents the solution found by FEniCS's solve(), and the other a solution interpolated to a similar space from an expression representing the closed-form solution. I'd like to find the norm of their difference in a C++ code. For example, I have u, and u0, both of type GenericVector, and would like to obtain the norm of u-u0. What should be the C++ syntax for achieving this?

asked May 26, 2017 by hbinzubair FEniCS Novice (250 points)

1 Answer

0 votes
 
Best answer

The elastodynamics example shows what you want for its updates:

https://bitbucket.org/fenics-project/dolfin/src/0aa8af18ff46ddcaec22db1cc927c4f5fc88813c/demo/undocumented/elastodynamics/cpp/main.cpp?at=master&fileviewer=file-view-default

so you could create a new zero function a and set its vector values with

*a.vector() = *u.vector() - *u0.vector()

or maybe there is something equivalent to the 'errornorm' command in c++.

answered May 27, 2017 by nabarnaf FEniCS User (2,940 points)
selected Jun 8, 2017 by johannr

Yes, it works, many thanks.
Cheers,

...