Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion demos/benney_luke/benney_luke.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Finally, before implementing the problem in Firedrake, we calculate the total en
The implementation of this problem in Firedrake requires solving two nonlinear variational problems and one linear problem. The Benney-Luke equations are solved in a rectangular domain :math:`\Omega=[0,10]\times[0,1]`, with :math:`\mu=\epsilon=0.01`, time step :math:`dt=0.005` and up to the final time :math:`T=2.0`. Additionally, the domain is split into 50 cells in the x-direction using a quadrilateral mesh. In the y-direction only 1 cell is enough since there are no variations in y::

from firedrake import *
from firedrake.output import VTKFile

Now we move on to defining parameters::

Expand Down Expand Up @@ -190,7 +191,7 @@ For visualisation, we save the computed and exact solutions to
an output file. Note that the visualised data will be interpolated
from piecewise quadratic functions to piecewise linears::

output = File('output.pvd')
output = VTKFile('output.pvd')
output.write(phi0, eta0, ex_phi, ex_eta, time=t)

We are now ready to enter the main time iteration loop::
Expand Down
19 changes: 10 additions & 9 deletions demos/burgers/burgers.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ the viscosity term by parts:

.. math::

\int_\Omega\frac{\partial u}{\partial t}\cdot v +
\int_\Omega\frac{\partial u}{\partial t}\cdot v +
((u\cdot\nabla) u)\cdot v + \nu\nabla u\cdot\nabla v \ \mathrm d x = 0.

The boundary condition has been used to discard the surface
Expand All @@ -28,12 +28,13 @@ stability we elect to use a backward Euler discretisation:

.. math::

\int_\Omega\frac{u^{n+1}-u^n}{dt}\cdot v +
\int_\Omega\frac{u^{n+1}-u^n}{dt}\cdot v +
((u^{n+1}\cdot\nabla) u^{n+1})\cdot v + \nu\nabla u^{n+1}\cdot\nabla v \ \mathrm d x = 0.

We can now proceed to set up the problem. We choose a resolution and set up a square mesh::

from firedrake import *
from firedrake.output import VTKFile
n = 30
mesh = UnitSquareMesh(n, n)

Expand Down Expand Up @@ -76,7 +77,7 @@ system's evolution::
timestep = 1.0/n

Here we finally get to define the residual of the equation. In the advection
term we need to contract the test function :math:`v` with
term we need to contract the test function :math:`v` with
:math:`(u\cdot\nabla)u`, which is the derivative of the velocity in the
direction :math:`u`. This directional derivative can be written as
``dot(u,nabla_grad(u))`` since ``nabla_grad(u)[i,j]``:math:`=\partial_i u_j`.
Expand All @@ -89,15 +90,15 @@ is differentiated by the nonlinear solver::

We now create an object for output visualisation::

outfile = File("burgers.pvd")
outfile = VTKFile("burgers.pvd")

Output only supports visualisation of linear fields (either P1, or
P1DG). In this example we project to a linear space by hand. Another
option is to let the :class:`~.File` object manage the decimation. It
option is to let the :class:`~.VTKFile` object manage the decimation. It
supports both interpolation to linears (the default) or projection (by
passing ``project_output=True`` when creating the :class:`~.File`).
Outputting data is carried out using the :meth:`~.File.write` method
of :class:`~.File` objects::
passing ``project_output=True`` when creating the :class:`~.VTKFile`).
Outputting data is carried out using the :meth:`~.VTKFile.write` method
of :class:`~.VTKFile` objects::

outfile.write(project(u, V_out, name="Velocity"))

Expand All @@ -112,5 +113,5 @@ which amount to applying a full LU decomposition as a preconditioner. ::
u_.assign(u)
t += timestep
outfile.write(project(u, V_out, name="Velocity"))

A python script version of this demo can be found :demo:`here <burgers.py>`.
5 changes: 3 additions & 2 deletions demos/camassa-holm/camassaholm.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ As usual, to implement this problem, we start by importing the
Firedrake namespace. ::

from firedrake import *
from firedrake.output import VTKFile

To visualise the output, we also need to import matplotlib.pyplot to display
the visual output ::
Expand Down Expand Up @@ -168,11 +169,11 @@ e.g. for output. ::
m0, u0 = w0.subfunctions
m1, u1 = w1.subfunctions

We choose a final time, and initialise a :class:`~.File` object for
We choose a final time, and initialise a :class:`~.VTKFile` object for
storing ``u``. as well as an array for storing the function to be visualised::

T = 100.0
ufile = File('u.pvd')
ufile = VTKFile('u.pvd')
t = 0.0
ufile.write(u1, time=t)
all_us = []
Expand Down
3 changes: 2 additions & 1 deletion demos/extruded_shallow_water/test_extrusion_lsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
a sin(x)*sin(y) solution that doesn't care about the silly BCs"""

from firedrake import *
from firedrake.output import VTKFile


power = 5
Expand Down Expand Up @@ -37,7 +38,7 @@
t = 0
dt = 0.0025

file = File("lsw3d.pvd")
file = VTKFile("lsw3d.pvd")
p_trial = TrialFunction(Xplot)
p_test = TestFunction(Xplot)
solve(p_trial * p_test * dx == p_0 * p_test * dx, p_plot)
Expand Down
3 changes: 2 additions & 1 deletion demos/helmholtz/helmholtz.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ method, so lets go ahead and produce a numerical solution.
First, we always need a mesh. Let's have a :math:`10\times10` element unit square::

from firedrake import *
from firedrake.output import VTKFile
mesh = UnitSquareMesh(10, 10)

We need to decide on the function space in which we'd like to solve the
Expand Down Expand Up @@ -93,7 +94,7 @@ of the manual on :doc:`solving PDEs <../solving-interface>`.
Next, we might want to look at the result, so we output our solution
to a file::

File("helmholtz.pvd").write(u)
VTKFile("helmholtz.pvd").write(u)

This file can be visualised using `paraview <http://www.paraview.org/>`__.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ In the work of :cite:`Chin:1999` and later :cite:`Geevers:2018`, several triangu
In addition to importing firedrake as usual, we will need to construct the correct quadrature rules for the mass-lumping by hand. FInAT is responsible for providing these quadrature rules, so we import it here too.::

from firedrake import *
from firedrake.output import VTKFile
import finat

import math
Expand All @@ -73,7 +74,7 @@ We choose a degree 2 `KMV` continuous function space, set it up and then create

We create an output file to hold the simulation results::

outfile = File("out.pvd")
outfile = VTKFile("out.pvd")

Now we set the time-stepping variables performing a simulation for 1 second with a timestep of 0.001 seconds::

Expand Down
5 changes: 3 additions & 2 deletions demos/linear-wave-equation/linear_wave_equation.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ This time we created the mesh with `Gmsh <http://gmsh.info/>`_:
We can then start our Python script and load this mesh::

from firedrake import *
from firedrake.output import VTKFile
mesh = Mesh("wave_tank.msh")

We choose a degree 1 continuous function space, and set up the
Expand All @@ -66,7 +67,7 @@ output file::

Output the initial conditions::

outfile = File("out.pvd")
outfile = VTKFile("out.pvd")
outfile.write(phi)

We next establish a boundary condition object. Since we have time-dependent
Expand Down Expand Up @@ -128,7 +129,7 @@ Step forward :math:`\phi` by the second half timestep::
phi -= dt / 2 * p

Advance time and output as appropriate, note how we pass the current
timestep value into the :meth:`~.File.write` method, so that when
timestep value into the :meth:`~.VTKFile.write` method, so that when
visualising the results Paraview will use it::

t += dt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The underlined terms are the coupling terms. Note that the first equation for :m
Now we present the code used to solve the system of equations above. We start with appropriate imports::

from firedrake import *
from firedrake.output import VTKFile
import math
import numpy as np

Expand Down Expand Up @@ -278,7 +279,7 @@ Let us set the initial condition. We choose no motion at the beginning in both f

A file to store data for visualization::

outfile_phi = File("results_pvd/phi.pvd")
outfile_phi = VTKFile("results_pvd/phi.pvd")

To save data for visualization, we change the position of the nodes in the mesh, so that they represent the computed dynamic position of the free surface and the structure::

Expand Down
3 changes: 2 additions & 1 deletion demos/ma-demo/ma-demo.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ We now proceed to set up the problem in Firedrake using a square
mesh of quadrilaterals. ::

from firedrake import *
from firedrake.output import VTKFile
n = 100
mesh = UnitSquareMesh(n, n, quadrilateral=True)

Expand Down Expand Up @@ -188,7 +189,7 @@ and output the solution to a file. ::

u, sigma = w.subfunctions
u_solv.solve()
File("u.pvd").write(u)
VTKFile("u.pvd").write(u)

An image of the solution is shown below.

Expand Down
3 changes: 2 additions & 1 deletion demos/matrix_free/navier_stokes.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ We solve the Navier-Stokes equations using Taylor-Hood elements. The
example is that of a lid-driven cavity. ::

from firedrake import *
from firedrake.output import VTKFile

N = 64

Expand Down Expand Up @@ -134,7 +135,7 @@ And finally we write the results to a file for visualisation. ::
u.rename("Velocity")
p.rename("Pressure")

File("cavity.pvd").write(u, p)
VTKFile("cavity.pvd").write(u, p)

A runnable python script implementing this demo file is available
:demo:`here <navier_stokes.py>`.
3 changes: 2 additions & 1 deletion demos/matrix_free/rayleigh-benard.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ the Navier-Stokes part, and piecewise linear elements for the
temperature. ::

from firedrake import *
from firedrake.output import VTKFile

N = 128

Expand Down Expand Up @@ -241,7 +242,7 @@ Finally, we'll output the results for visualisation. ::
p.rename("Pressure")
T.rename("Temperature")

File("benard.pvd").write(u, p, T)
VTKFile("benard.pvd").write(u, p, T)

A runnable python script implementing this demo file is available
:demo:`here <rayleigh-benard.py>`.
5 changes: 3 additions & 2 deletions demos/matrix_free/stokes.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cavity.
As ever, we import firedrake and define a mesh.::

from firedrake import *
from firedrake.output import VTKFile

N = 64

Expand Down Expand Up @@ -47,7 +48,7 @@ wrapped in a ``try/except`` block so that an error is not raised in
the case that it is not, to do this we must import ``PETSc``::

from firedrake.petsc import PETSc

To factor the matrix from this mixed system, we must specify
a ``mat_type`` of ``aij`` to the solve call.::

Expand Down Expand Up @@ -130,7 +131,7 @@ file.::
u.rename("Velocity")
p.rename("Pressure")

File("stokes.pvd").write(u, p)
VTKFile("stokes.pvd").write(u, p)

By default, the mass matrix is assembled in the :class:`~.MassInvPC`
preconditioner, however, this can be controlled using a ``mat_type``
Expand Down
5 changes: 3 additions & 2 deletions demos/multigrid/geometric_multigrid.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ hierarchies are constructed using regular bisection refinement, so we
must create a coarse mesh. ::

from firedrake import *
from firedrake.output import VTKFile

mesh = UnitSquareMesh(8, 8)

Expand Down Expand Up @@ -114,7 +115,7 @@ appropriate settings using solver parameters. ::

u = run_solve(parameters)
print('MG F-cycle error', error(u))

A saddle-point system: The Stokes equations
-------------------------------------------

Expand Down Expand Up @@ -259,7 +260,7 @@ Finally, we'll write the solution for visualisation with Paraview. ::
u.rename("Velocity")
p.rename("Pressure")

File("stokes.pvd").write(u, p)
VTKFile("stokes.pvd").write(u, p)

A runnable python version of this demo can be found :demo:`here
<geometric_multigrid.py>`.
Loading