Course PrePost Processing Notebook

This is a Jupyter notebook for the Course PrePost Processing project.

1. Introduction

You write your notebook in AsciiDoc including LaTeX math and thanks to the :page-jupyter: true attribute, the notebook is converted to a Jupyter notebook when the book is built.

For the doc contributors, to run the notebook in VScode:

  • select the kernel to use: use the previously created virtual env

For the others, you need to download the notebook and run it in a separate way. To test the notebook, you can either use:

  • a local jupyter installation:

    • create a python virtual environment

    • install the requested packages

    • start the the notebook

  • or a container (eg. docker image)

    • get the container

    • run the container with mounting …​

2. Code cells

You can include code cells in your notebook using the [source,python] block macro. To run and view the result use [%dynamic%open,python] block macro.

import sys, os
print("Hello, world!")
Results
Hello, world!

3. Feel++ Code cells

You can include Feel++ code cells in your notebook using the [source,python] block macro.

import feelpp.core as fppc
app = fppc.Environment(["myapp"],config=fppc.globalRepository("myapp"))

import os
print(f'pwd: {os.getcwd()}')

geo=fppc.download( "github:{repo:feelpp,path:feelpp/quickstart/laplacian/cases/feelpp2d/feelpp2d.geo}", worldComm=app.worldCommPtr() )[0]
print("geo file: {}".format(geo))
mesh = fppc.load(fppc.mesh(dim=2,realdim=2), geo, 0.1)

Xh=fppc.functionSpace(mesh=mesh, space="Pchv")
f = Xh.element()
f.on(range=fppc.elements(mesh),expr=fppc.expr("{sin(pi*x)*sin(pi*y),cos(pi*x)*cos(pi*y)}:x:y",row=2,col=1))
e= fppc.exporter(mesh=mesh)
e.add("f",f)
e.save()

You can then visualize the result using the pyvista package as follows:

import pyvista as pv
pv.start_xvfb()
pv.set_jupyter_backend('client')

# hack for vtk 9.3
filename = "/home/feelpp/feelppdb/myapp/np_1/exports/ensightgold/Exporter/Exporter.case"
new_filename = f"{filename}.tmp"

with open(new_filename, "w") as out:
    with open(filename, "r") as input:
        Lines = input.readlines()
        for line in Lines:
            out.write(line.replace('change_coords_only',''))

os.rename(filename, f'{filename}.orig')
os.rename(new_filename, filename)

# load "corrected" case
reader = pv.get_reader(filename)
mesh = reader.read()
mesh.plot(scalars="f",show_edges=True, cpos='xy', interactive=False)

# restore initial case file
# os.rename(f'{filename}.orig', filename)

You may need to change the path to the ensight gold output file depending on your setup.