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

Error "updating" objects with childs relations

0 votes

Hi,
when i try to update objects (meshes and meshfunctions) after being adapted an errors occurs. What i understand by update is something like this:

// Refine mesh
adapt(mesh, cell_markers);

// Adapt cell function to refined mesh
adapt(subdomain, mesh.child_shared_ptr());

// Eliminate child relations and update mesh and meshfunction
mesh       = *mesh.child_shared_ptr();
subdomain  = *subdomain.child_shared_ptr();

Running the above code, i'm getting this error when i attempt to plot the meshfunction (subdomain):

 *** Process received signal ***
Signal: Segmentation fault (11)
Signal code: Address not mapped (1)
Failing at address: 0xfffffffffffffff0
[ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x36d40) [0x7f6ee96acd40]
[ 1] /usr/lib/x86_64-linux-gnu/libstdc++.so.6(__dynamic_cast+0x16) [0x7f6ee9cae156]
[ 2] /usr/lib/x86_64-linux-gnu/libdolfin.so.1.6(_ZN6dolfin16VTKPlottableMesh6updateESt10shared_ptrIKNS_8VariableEERKNS_10ParametersEi+0x34) [0x7f6eeb77d744]
[ 3] /usr/lib/x86_64-linux-gnu/libdolfin.so.1.6(_ZN6dolfin24VTKPlottableMeshFunctionImE6updateESt10shared_ptrIKNS_8VariableEERKNS_10ParametersEi+0x10c) [0x7f6eeb77c13c]
[ 4] /usr/lib/x86_64-linux-gnu/libdolfin.so.1.6(_ZN6dolfin10VTKPlotter15update_pipelineESt10shared_ptrIKNS_8VariableEE+0x287) [0x7f6eeb772847]
[ 5] /usr/lib/x86_64-linux-gnu/libdolfin.so.1.6(_ZN6dolfin10VTKPlotter4plotESt10shared_ptrIKNS_8VariableEE+0xc0) [0x7f6eeb773eb0]
[ 6] /usr/lib/x86_64-linux-gnu/libdolfin.so.1.6(_Z11plot_objectSt10shared_ptrIKN6dolfin8VariableEES_IKNS0_10ParametersEESs+0x152) [0x7f6eeb767bc2]
[ 7] /usr/lib/x86_64-linux-gnu/libdolfin.so.1.6(_ZN6dolfin4plotESt10shared_ptrIKNS_8VariableEES0_IKNS_10ParametersEE+0x93) [0x7f6eeb767f03]
[ 8] /usr/lib/x86_64-linux-gnu/libdolfin.so.1.6(_ZN6dolfin4plotESt10shared_ptrIKNS_8VariableEESsSs+0xa7) [0x7f6eeb768167]
[ 9] /usr/lib/x86_64-linux-gnu/libdolfin.so.1.6(_ZN6dolfin4plotERKNS_8VariableESsSs+0x90) [0x7f6eeb768ed0]
[10] ./demo_meshfunction-refinement(main+0x646) [0x4052e6]
[11] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f6ee9697ec5]
[12] ./demo_meshfunction-refinement() [0x405626]
*** End of error message ***
Segmentation fault (core dumped)

Running the same code, but now without the line mesh = *mesh.child_shared_ptr(), the plot of the subdomain meshfunction works correctly.

Any ideas about what i'm doing wrong?

A minimal non-working example is this:

#include <dolfin.h>
using namespace dolfin; 

// Circular subdomain
class Circle : public SubDomain
{
  bool inside(const Array<double>& x, bool on_boundary) const
  {
    return pow(x[1] - 0.5, 2) + pow(x[0] - 0.5, 2) <= pow(0.2, 2);
  }
};

int main()
{
parameters["refinement_algorithm"] = "plaza_with_parent_facets";

// Square mesh
UnitSquareMesh mesh(40, 40, "crossed");

// Create object of Circle class
Circle Circle;

// Create MeshFunction over cells facets and mark subdomain
MeshFunction<std::size_t> subdomain(mesh, mesh.topology().dim(), 0);
Circle.mark(subdomain, 1);

// Create MeshFunction over cells and mark cells for refinement
MeshFunction<bool> cell_markers(mesh, mesh.topology().dim(), false);
Circle.mark(cell_markers, true);

// Mesh refinement
adapt(mesh, cell_markers);

// Adapt cell function to refined mesh
adapt(subdomain, mesh.child_shared_ptr());

// Eliminate child relations and update mesh and meshfunction
mesh       = *mesh.child_shared_ptr();
subdomain  = *subdomain.child_shared_ptr();

// Plot
plot(mesh);
interactive();
plot(subdomain);
interactive();

return 0;
}
asked Oct 14, 2015 by hernan_mella FEniCS Expert (19,460 points)
edited Oct 16, 2015 by hernan_mella

It is a bit complicated, but I think probably the problem comes from overwriting the existing Mesh. If you are not using the full adaptivity framework (see demos), you can probably do most things by just using the refine() method, and not adapt().
In your example above, you are also setting a MeshFunction on Cells, not Facets. Is that intentional? Maybe you can explain exactly what you want to do.

What i'm trying to do is to define some subdomains on my physical domain and refine them according its physical parameters i.e, wavelengths or velocities of propagation. Maybe you are right, i'm being a little stubborn trying to solve everything using the adapt() method.

The idea of use a MeshFunction on cells is to use a SubsetIterator to refine each subdomain in function to their properties, but now that i think, this MeshFunction on cells can be perfectly a "FacetFunction".

...