ls
README.md demo_nonlinear-poisson.py.rst Untitled.ipynb demo_poisson.ipynb __pycache__/ demo_poisson.py.rst aneurysm.xml.gz demo_singular-poisson-rst.ipynb box_with_dent.xml.gz demo_singular-poisson-rst.py.rst convert.py dolfin-1.6.0/ demo_auto-adaptive-poisson.ipynb dolfin-1.6.0.tar.gz demo_auto-adaptive-poisson.py.rst dolfin_fine.xml.gz demo_biharmonic.ipynb dolfin_fine_subdomains.xml.gz demo_biharmonic.py.rst environment.yml demo_built-in-meshes.ipynb generate-notebooks.py demo_built-in-meshes.py.rst jupyter_converter.py demo_cahn-hilliard.ipynb lshape.xml.gz demo_cahn-hilliard.py.rst rst-to-ipynb-demos.py demo_eigenvalue.ipynb split-cell-example.ipynb demo_eigenvalue.py.rst splitcell.py demo_hyperelasticity.ipynb test.py demo_hyperelasticity.py.rst unitsquare_32_32.xml.gz demo_maxwell-eigenvalues.ipynb unitsquare_32_32_c00.xml.gz demo_maxwell-eigenvalues.py.rst unitsquare_32_32_c01.xml.gz demo_nonlinear-poisson.ipynb unitsquare_32_32_c11.xml.gz
import nbformat
nb = nbformat.read('demo_maxwell-eigenvalues.ipynb', as_version=4)
for cell in nb.cells:
print(cell.cell_type)
print(' %s...' % cell.source.splitlines()[0])
markdown Stable and unstable finite elements for the Maxwell eigenvalue problem... code diagonal mesh... markdown Note that the eigenvalues calculated using the Nédélec elements are all... code crossed mesh... markdown Again the Nédélec elements are accurate. The Lagrange elements also... code from dolfin import *... markdown Specifying matplotlib as backend:... code %matplotlib inline... markdown **Function eigenvalues.** The function `eigenvalues` takes the finite... code def eigenvalues(V, bcs):... markdown We start by defining the bilinear forms on the right- and left-hand... code #... markdown Next we assemble the bilinear forms `a` and `b` into PETSc matrices `A`... code #... markdown We zero out the rows of $B$ corresponding to constrained boundary... code #... markdown Now we solve the generalized matrix eigenvalue problem using the SLEPc... code #... markdown We specify that we want 12 eigenvalues nearest in magnitude to a target... code #... markdown Finally we collect the computed eigenvalues in list which we convert to... code #... markdown **Function print\_eigenvalues.** Given just a mesh, the function... code def print_eigenvalues(mesh):... markdown First we define the Nédélec edge element space and the essential... code #... markdown Then we do the same for the vector Lagrange elements. Since the Lagrange... code #... markdown The true eigenvalues are just the 12 smallest numbers of the form... code #... markdown Finally we print the results:... code #... markdown **Calling the functions.** To complete the program, we call... code mesh = RectangleMesh(Point(0, 0), Point(pi, pi), 40, 40)...
cell3 = nb.cells[3]
cell3
{'cell_type': 'code', 'execution_count': None, 'metadata': {'attributes': {'classes': ['sourceCode', 'none'], 'id': ''}}, 'outputs': [], 'source': 'crossed mesh\nNédélec: [ 1.00 1.00 2.00 4.00 4.00 5.00 5.00 7.99 9.00 9.00 10.00 10.00]\nLagrange: [ 1.00 1.00 2.00 4.00 4.00 5.00 5.00 6.00 8.01 9.01 9.01 10.02]\nExact: [ 1.00 1.00 2.00 4.00 4.00 5.00 5.00 8.00 9.00 9.00 10.00 10.00]'}
cell3.metadata.attributes.classes
['sourceCode', 'none']
cell1 = nb.cells[1]
new_source = '\n'.join(['```', cell1.source, '````'])
new_cell = nbformat.v4.new_markdown_cell(new_source)
nb.cells[1] = new_cell
new_cell
{'cell_type': 'markdown', 'metadata': {}, 'source': '```\ndiagonal mesh\nNédélec: [ 1.00 1.00 2.00 4.00 4.00 5.00 5.00 8.01 8.98 8.99 9.99 9.99]\nLagrange: [ 5.16 5.26 5.26 5.30 5.39 5.45 5.53 5.61 5.61 5.62 5.71 5.73]\nExact: [ 1.00 1.00 2.00 4.00 4.00 5.00 5.00 8.00 9.00 9.00 10.00 10.00]\n````'}
nbformat.write(nb, 'demo_maxwell-eigenvalues.ipynb')
md =
nbformat.v4.new_markdown_cell('some markdown')
{'cell_type': 'markdown', 'metadata': {}, 'source': 'some markdown'}