Skip to content

Commit

Permalink
Aded Firedrake, some pictures and a video
Browse files Browse the repository at this point in the history
  • Loading branch information
Umberto Zerbinati committed Jun 15, 2024
1 parent 4ac866d commit 175c106
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ sphinxcontrib-jsmath
sphinxcontrib-qthelp
sphinxcontrib-serializinghtml
sphinx-autoapi
sphinxcontrib-video
stack-data==0.6.2
tbb==2021.9.0
tinycss2==1.2.1
Expand Down
7 changes: 6 additions & 1 deletion docs/src/PETScSNES/hyperelasticity.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,9 @@ We compare the performance of the `PETSc SNES` solvers and the one of `NGSolve`
* - PETSc SNES
- 10

This suggests that while NGS non-linear solver when finely tuned performs as well as PETSc SNES, it is more sensitive to the choice of the damping factor. In this case, a damping factor of 0.3 was found to be the best choice.
This suggests that while NGSolve's non-linear solver when finely tuned performs as well as PETSc SNES, it is more sensitive to the choice of the damping factor. In this case, a damping factor of 0.3 was found to be the best choice.

.. video:: ./twistedBeam.mp4
:width: 600
:height: 400
:loop:
Binary file added docs/src/PETScSNES/twistedBeam.mp4
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ['sphinx.ext.autodoc', 'sphinx_autodoc_typehints',"sphinx.ext.mathjax","sphinx.ext.todo",
extensions = ['sphinx.ext.autodoc', 'sphinxcontrib.video', 'sphinx_autodoc_typehints',"sphinx.ext.mathjax","sphinx.ext.todo",
"IPython.sphinxext.ipython_console_highlighting", "IPython.sphinxext.ipython_directive",
"nbsphinx", 'sphinx.ext.autodoc', "autoapi.extension"]
autosummary_generate = True # Turn on sphinx.ext.autosummary]
Expand Down
7 changes: 7 additions & 0 deletions docs/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ Welcome to ngsPETSc's documentation!

SLEPcEPS/poisson.py

.. toctree::
:maxdepth: 1
:caption: Firedrake

utils/firedrake/lomesh.py
utils/firedrake/homesh.py

Indices and tables
==================

Expand Down
2 changes: 1 addition & 1 deletion docs/src/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ We are now fianlly ready to install ngsPETSc:
Authors
----------

Stefano Zampini, Umberto Zerbinati
Patrick E. Farrell, Stefano Zampini, Umberto Zerbinati

License
---------------
Expand Down
Binary file added docs/src/utils/firedrake/Adaptive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/utils/firedrake/Bottle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/utils/firedrake/Example1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/utils/firedrake/Example2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/utils/firedrake/Example5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/utils/firedrake/Example6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/utils/firedrake/Example7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions docs/src/utils/firedrake/homesh.py.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
High-order meshes
==================

This tutorial is an improved version of the Netgen tutorial available in the Firedrake documentation, which can be found `here <https://www.firedrakeproject.org/demos/netgen_mesh.py.html>`__.
It is possible to construct high-order meshes for a geometry constructed in Netgen.
In order to do so we need to use the `curve_field` method of a Firedrake `Mesh` object generated from a Netgen mesh.
In particular, we need to pass the degree of the polynomial field we want to use to parametrise the coordinates of the domain to the `curve_field` method, which will return a `Function` constructed on a DG space for this purpose. ::

from firedrake import *
from netgen.occ import WorkPlane, OCCGeometry
import netgen
from mpi4py import MPI

wp = WorkPlane()
if COMM_WORLD.rank == 0:
for i in range(6):
wp.Line(0.6).Arc(0.4, 60)
shape = wp.Face()
ngmesh = OCCGeometry(shape,dim=2).GenerateMesh(maxh=1.)
else:
ngmesh = netgen.libngpy._meshing.Mesh(2)
mesh = Mesh(Mesh(ngmesh, comm=COMM_WORLD).curve_field(4))
VTKFile("output/MeshExample5.pvd").write(mesh)

.. figure:: Example5.png
:align: center
:alt: Example of a curved mesh of order 4 generated from a geometry described using Open Cascade WorkPlane.

High-order meshes are also supported in three dimensions; we just need to specify the correct dimension when constructing the OCCGeometry object.
We will now show how to solve the Poisson problem on a high-order mesh, of order 3, for the unit sphere. ::

from netgen.occ import Sphere, Pnt
import netgen
from mpi4py import MPI

if COMM_WORLD.rank == 0:
shape = Sphere(Pnt(0,0,0), 1)
ngmesh = OCCGeometry(shape,dim=3).GenerateMesh(maxh=1.)
else:
ngmesh = netgen.libngpy._meshing.Mesh(3)
mesh = Mesh(Mesh(ngmesh).curve_field(3))
# Solving the Poisson problem
VTKFile("output/MeshExample6.pvd").write(mesh)
x, y, z = SpatialCoordinate(mesh)
V = FunctionSpace(mesh, "CG", 3)
f = Function(V).interpolate(1+0*x)
u = TrialFunction(V)
v = TestFunction(V)
a = inner(grad(u), grad(v)) * dx
l = inner(f, v) * dx

sol = Function(V)

bc = DirichletBC(V, 0.0, [1])
A = assemble(a, bcs=bc)
b = assemble(l)
bc.apply(b)
solve(A, sol, b, solver_parameters={"ksp_type": "cg", "pc_type": "lu"})

VTKFile("output/Sphere.pvd").write(sol)

.. figure:: Example6.png
:align: center
:alt: The solution of the Poisson problem solved on a mesh of order 3 for the unit sphere.

It is also possible to construct high-order meshes using the `SplineGeometry`, `CSG2d` and `CSG` classes. ::

from netgen.geom2d import CSG2d, Circle, Rectangle
import netgen
from mpi4py import MPI

if COMM_WORLD.rank == 0:
geo = CSG2d()
circle = Circle(center=(1,1), radius=0.1, bc="curve").Maxh(0.01)
rect = Rectangle(pmin=(0,1), pmax=(1,2),
bottom="b", left="l", top="t", right="r")
geo.Add(rect-circle)
ngmesh = geo.GenerateMesh(maxh=0.2)
else:
ngmesh = netgen.libngpy._meshing.Mesh(2)
mesh = Mesh(Mesh(ngmesh,comm=COMM_WORLD).curve_field(2))
VTKFile("output/MeshExample7.pvd").write(mesh)

.. figure:: Example7.png
:align: center
:alt: Example of a curved mesh of order 2 generated from a geometry described using Netgen CSG2d.
Loading

0 comments on commit 175c106

Please sign in to comment.