Exporting results for visualisation

We now turn to the exporter facility of Feel++ which allows to provide the results of Feel++ solves in a format readable by ParaView or EnSight.

In this 2D and 3D example, we

  • initiate the Feel++ environment

  • download a mesh description from github.com/feelpp/feelpp/

  • build the mesh and partition it

  • build a function space \(X_h\)

  • create an element \(u\) of \(X_h\) which interpolate an expression givn by the end-user

  • export to the Ensight Gold format (the default Feel++ format) of Feel++

Example to build a mesh and function space, create an element and visualize them in ParaView
import feelpp
import sys,os
import spdlog as spd
from feelpp.timing import tic, toc

logger = spd.ConsoleLogger('Logger', False, True, True)
logger.set_level(spd.LogLevel.TRACE)

tic()
app = feelpp.Environment(["myapp"],config=feelpp.localRepository("")) (1)
toc("init Feel++")

logger.info(f"Feel++ version: {feelpp.Info.version()}")
Results

1 The Feel++ environment is initiated with the name of the application and the path to the local repository where the results will be stored.
app.setLogVerbosityLevel(0) (1)
geofilename=feelpp.download( "github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}", worldComm=app.worldCommPtr() )[0]

tic()
mesh = feelpp.load(feelpp.mesh(dim=2,realdim=2), name=geofilename, h=0.1, verbose=1) (2)
toc("load mesh")
logger.info(f"mesh loaded")

Xh=feelpp.functionSpace(mesh=mesh,space="Pch",order=1) (3)
P0h=feelpp.functionSpace(mesh=mesh,space="Pdh",order=0) (4)
u=Xh.element() (5)
u.on(range=feelpp.elements(mesh), expr=feelpp.expr("sin(2*pi*x)*cos(pi*y):x:y")) (6)
logger.info(f"functionspace built and u created")

e = feelpp.exporter(mesh=mesh)  (7)
e.add("a_scalar", 1.) (8)
e.add("u",u) (9)
e.add("pid",feelpp.pid( P0h )) (10)
e.save() (11)
logger.info(f"export done")
Results

1 The verbosity level is set to 0 (only VLOG(level) with level ⇐ 0 are displayed)
2 The mesh is loaded from the github.com/feelpp/feelpp/ repository
3 The function space \(X_h\) is built from the mesh mesh and the space Pch and order 1
4 The function space \(P0_h\) is built from the mesh mesh and the space Pdh and order 0
5 The element u is built from the function space Xh
6 The element u is interpolated with the expression {sin(2*pi*x)*cos(pi*y)}:x:y
7 The exporter is built from the mesh mesh
8 The scalar a_scalar is added to the exporter e
9 The element u is added to the exporter e
10 The element pid is added to the exporter e
11 The exporter e is saved to the disk

The results are stored in the directory feelppdb and can be visualized with ParaView or EnSight.

INFO: The file exports/ensightgold/myapp/myapp.case can be opened directly in ParaView or EnSight to visualize the mesh and the fields.

from xvfbwrapper import Xvfb
vdisplay = Xvfb()
vdisplay.start()
import pyvista as pv
import os
pv.set_jupyter_backend('pythreejs')

def pv_get_mesh(mesh_path):
    reader = pv.get_reader(mesh_path)
    mesh = reader.read()
    return mesh

plotter = pv.Plotter()
plotter.show_axes()
mesh = pv_get_mesh(f"exports/ensightgold/Exporter/Exporter.case")
plotter.add_mesh(mesh, scalars="u", clim=None, cmap="viridis", show_scalar_bar=True, show_edges=True)
plotter.camera_position = 'xy'
axes = pv.create_axes_marker(
                                line_width=4,
                                ambient=0.0,
                                x_color="#378df0",
                                y_color="#ab2e5d",
                                z_color="#f7fb9a",
                                xlabel="X Axis",
                                ylabel="Y Axis",
                                zlabel="Z Axis",
                                label_size=(0.1, 0.1), label_color="#aaaaaa",
                            )
plotter.add_actor(axes)

plotter.show()
Results