Mfem: Subtracting two gridfunctions?

Created on 18 Dec 2020  路  4Comments  路  Source: mfem/mfem

Hi there,

How can I subtract one gridfunction from another?
The following code to calculate c=a-b does not produce errors when running, but it does not return a plot and gives an error in glvis.

Please help.

Sai

MFEM abort: input stream is not a FiniteElementSpace!
 ... in function: mfem::FiniteElementCollection* mfem::FiniteElementSpace::Load(mfem::Mesh*, std::istream&)
 ... in file: fem/fespace.cpp:2216
   GridFunction a(&fes_h1);
   GridFunction b(&fes_h1);
   //values calculated for a and b
   GridFunction c(&fes_h1);
   c=a-b;
   socketstream c_sock(vishost, visport);
   c_sock.precision(8);
   c_sock << "solution\n" << *mesh << c << "window_title 'GridFunction c'" <<flush;
fem usage

Most helpful comment

All 4 comments

Try:

c = a;
c -= b;

That was unexpected. Thank you!

I didn't find -= or += operator in http://mfem.github.io/doxygen/html/classmfem_1_1GridFunction.html. How did you know that it would work? Please share.

I'll close this now, feel free to reopen if you have further questions.

Was this page helpful?
0 / 5 - 0 ratings