← Back to team overview

dolfin team mailing list archive

Re: Plotting MeshFunction

 

On Mon, May 05, 2008 at 04:20:04PM +0100, Nuno David Lopes wrote:
> On Monday 05 May 2008, Anders Logg wrote:
> > On Mon, May 05, 2008 at 03:38:49PM +0200, Ola Skavhaug wrote:
> > > Ola Skavhaug skrev den 05/05-2008 følgende:
> > > > >
> > > > > I think the problem may be that it's not possible to plot a mesh
> > > > > function defined on the facets of a mesh. Viper can't handle that as
> > > > > far as I remember. It would be very good if this could be added since
> > > > > it's a simple way to debug boundary conditions.
> > >
> > > Should be:
> > >
> > > bmesh = BoundaryMesh(mesh)
> > > bmf = MeshFunction("uint", bmesh, bmesh.topology().dim())
> > > #                                 ^^^^^
> > > # use mesh-bmesh mapping to remap indicators and insert into bmf
> > > plot(bmf)
> >
> > I think that's a good solution (to just add a few lines that extracts
> > the boundary and then plots the cells of the boundary).
> 
> Thanks, I've got it!
> After some copy paste and other extra lines for the markers, it's done. 
> 
> 
> My c++ code for a boundary test.
> 
> int main()
> {
> 
>   // Sub domain for heat inflow DirichletBC  
>   class DirichletBC : public SubDomain
>   {
>     bool inside(const real* x, bool on_boundary) const
>     {
>       real h3=0.035;
>       return ((x[0] > h3 - DOLFIN_EPS)&&(x[2]>DOLFIN_EPS)) && on_boundary;
>     }
>   };
> 
>   // {{{For boundary conditions debug
>   class B_DirichletBC : public SubDomain
>   {
>     bool inside(const real* x,bool on_boundary) const
>     {
>       real h3=0.035;
>       return ((x[0] > h3 - DOLFIN_EPS)&&(x[2]>DOLFIN_EPS));
>     }
>   };
>   // }}}
>  
>   // Read mesh
>   Mesh mesh("../barra4.xml");
>   BoundaryMesh bmesh(mesh);
> 
>   MeshFunction<unsigned int> sub_domains(mesh, mesh.topology().dim() - 1);//
>   MeshFunction<unsigned int> b_sub_domains(bmesh,    
>             bmesh.topology().dim());//For boundary conditions debug
>   
>   // {{{ Mark all facets as sub domain 0 (*)
>   sub_domains = 0; //interior and boundary facets
>   b_sub_domains = 0; //facets of boundary mesh
>   // }}}
> 
>   // {{{ Mark Dirichlet boundary as sub domain 1
>   DirichletBC dirichletbc;
>   B_DirichletBC b_dirichletbc;
> 
>   dirichletbc.mark(sub_domains, 1); //boundary facets of 3D mesh
>   b_dirichletbc.mark(b_sub_domains, 1);//facets of boundary mesh
>   // }}}
> 
>   // {{{ Save sub domains to file
>   // The information we need to the main code
>   File file("bc_subdomains.xml");
>   file << sub_domains;
>   // }}}
>   
>   // {{{ Plotting for boundary conditions debug 
>   File b_file("bmf.xml");
>   b_file << b_sub_domains;
>   File bmfvtk("bmf.pvd"); 
>   bmfvtk<<b_sub_domains; 
>   plot(b_sub_domains);
>   // }}}
> }

Nice. Note that there is a tool called MeshBuilder which lets you mark
all the boundaries graphically using the mouse. It's available here:

  http://www.fenics.org/dev/meshbuilder

(It currently doesn't work with the latest Ubuntu.)

-- 
Anders


Follow ups

References