How to change the mesh of a dolphin::Function in C++?
12 months ago by
this issue maybe is simple, but I am dealing with a lot of problems.
I have a dolfin::Function, say rho, on a dolfin::Mesh Th. I want to interpolate, or to "change" the mesh of rho with another mesh, say Th1 (the result of an adaption, same geometry). Consider that this new mesh is "good" or "usable", because I can correctly solve linear problems on it (redefining everything).
Firstly I tried to use dolfin::Function::interpolate in the following way:
Th=Th1; // substitute the old mesh with the new one Vh =std::make_shared<varfs::CoefficientSpace_rho>(Th); // recompute the fespace auto temp=rho; // create a temporary function rho=std::make_shared<Function>(Vh); // clear the old function temp->interpolate(*rho); // interpolate
but this gives the following run-time error:
*** Error: Unable to successfully call PETSc function 'VecSetValuesLocal'.
*** Reason: PETSc error code is: 63 (Argument out of range).
when the dolphin::Function::interpolate function is called (last line).
Then, I tried to use LagrangeInterpolator in the following way:
Th=Th1; Vh =std::make_shared<varfs::CoefficientSpace_rho>(Th); auto temp=rho; rho=std::make_shared<Function>(Vh); LagrangeInterpolator funInterpolator; funInterpolator.interpolate(*rho,*temp);
but this gives a segmentation fault when dolfin::LagrangeInterpolator::interpolate is called.
Do you have any suggestion in order to solve this problem?
Thank you in advance.
Community: FEniCS Project
12 months ago by
I included APIs to copy dolfin::Function objects to and from Omega_h so that Omega_h can do the interpolation. The idea is to use from_dolfin(dolfin::Function) before adaptation and to_dolfin(dolfin::Function) after the adaptation. I think you should still create a new dolfin::Function using the new dolfin::Mesh. Note that I have not yet tested to_dolfin(dolfin::Function). Feel free to discuss this via email with me.
Edit: I don't know how to format inline code on this site.
Please login to add an answer/comment or follow this question.