### How to change the mesh of a dolphin::Function in C++?

207
views
0
9 months ago by
Hi all,

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?

Community: FEniCS Project
For non-matching meshes, you def want the LagrangeInterpolator. A little MWE with Python is handy.
written 9 months ago by pf4d