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

Best practice for consuming fenics output (mesh and functions) in other software?

+1 vote

My plan is to use FEniCS to generate a mesh and solution as input to another visualization system. Specifically, I'm solving an electrostatics problem and visualizing charged particles moving through it. My visualization system uses Java, as it is targeting Android.

Below are a number of specfic questions, but I'm also looking for guidance on some best practices for consuming FEniCS output in other systems. I've done some searching, but mostly find folks wanting to visualize the field values at, say, mesh points. However, I need to evaluate the function at any arbitrary point within the domain.

I've already written a simple java consumer of the FEniCS mesh XML file. I'm now tackling how to get the solution values into the visualization, with enough info to evaluate it at arbitrary points within the domain.

I'm beginning to realize that I need not only the "dof values" emitted by writing the function to an XML file, but also the dofmap and the function space's base finite element.

When I write the function to an XML file, e.g.

<dolfin xmlns:dolfin="http://fenicsproject.org">   
  <function_data size="4">
    <dof index="0" value="1" cell_index="1" cell_dof_index="2" />
    <dof index="1" value="2" cell_index="0" cell_dof_index="1" />
    <dof index="2" value="3" cell_index="0" cell_dof_index="2" />
    <dof index="3" value="4" cell_index="0" cell_dof_index="0" />   
  </function_data> 
</dolfin>

I can certainly see the dof values, but I don't see any indication of what is the function space. Is there a standard way to dump that information, e.g. dofmap and finite element?

If not, I can certainly write out the dofmap myself and consume it, since it is pretty simple. But it's less clear how to pass along the base finite element; i.e. the dof points of the standard cell and the basis functions. Right now I'm just using a simple Linear Lagrange element and since that maps dofs onto vertices, I could certainly just hard-code this element and replicate the evaluation machinery for it. But if there is already a way to emit the element info, I'd rather use that.

At the other end of the spectrum, I suppose I could look into generating swig wrapping for java, but since (a) I don't need all of fenics and (b) I'm targeting lower-powered machines, i'd really rather not embed so much code.

Thanks for reading this far! Any experiences or advice would be appreciated.

asked Apr 16, 2017 by steve FEniCS Novice (340 points)

1 Answer

+1 vote

If you are sure you will only ever use P1 elements, then it should be easy, as you say. Evaluation is just linear interpolation. From your description, this sounds the simplest option. If you are just solving the Poisson equation, you can always refine the mesh around areas that need it. I guess you won't use MPI, so you can also turn off dof reordering, which makes the mapping to points easier.

I'm currently looking at higher order output with XDMF, which will need to also use the dofmap, as you correctly state. Probably, some of this code will be merged this summer.

answered Apr 17, 2017 by chris_richardson FEniCS Expert (31,740 points)

By the way, I recommend XDMF over dolfin XML.

...