.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_tutorials_foundations_plot_advection_diffusion_model.py: Numerical Approximations of Governing Equations =============================================== This tutorial discusses the effect of numerically solving governing equations on model uncertainty. The following focuses on models based upon partial differential equations, but the points raised below apply to a much broader class of numerical models. Partial Differential Equations ------------------------------ We seek to quantify uncertainty in a broad class of stochastic partial differential equations (PDE). Let :math:`D\subset\mathbb{R}^\ell`, for :math:`\ell=1,2,` or :math:`3` and :math:`\text{dim}(D)=\ell`, be a physical domain; :math:`T>0` be a real number; and :math:`\rvdom\subseteq \mathbb{R}^{d}`, for :math:`d\geq 1` and :math:`\text{dim}(\rvdom)=d`, be the stochastic space. The PDE is defined as .. math:: \left\{ \begin{array} {ll} u_t(x,t,\rv) = \mathcal{L}(u), &\\ \mathcal{B}(u(x, t, \rv)) = 0, & \\ u(x, 0, \rv) = u_0(x, \rv), & %% D\times\{t=0\}\times \rvdom \end{array} \right. where :math:`t` is the time, :math:`x=(x_1,\dots,x_\ell)` is the physical coordinate, :math:`\mathcal{L}` is a (nonlinear) differential operator, :math:`\mathcal{B}` is the boundary condition operator, :math:`u_0` is the initial condition, and :math:`\rv=(\rv_1,\dots,\rv_{d})\in \rvdom` are a set of random variables characterizing the random inputs to the governing equation. The solution :math:`u \in V` is a vector-valued stochastic quantity .. math:: u:\bar{D}\times[0,T]\times \rvdom\to\mathbb{R}^{n}, for some suitable function space :math:`V` and where :math:`\bar{D} = D \times \partial D` is the closure of the interior domain. As an example, :math:`u(x,t, \rv)` can be a vector of temperatures, pressures, and velocities for a specific location in the domain :math:`x`, specific time :math:`t`, and for a specific realization :math:`\rv` of the stochastic variable :math:`\rv`. In this tutorial we will consider the following model of advection-diffusion .. math:: \frac{\partial u}{\partial t}(x,t,\rv) + \nabla u(x,t,\rv)-\nabla\cdot\left[k(x,\rv) \nabla u(x,t,\rv)\right] &=g(x,t) \qquad\qquad (x,t,\rv)\in D\times [0,1]\times\rvdom\\ u(x,t,\rv)&=0 \qquad\qquad\qquad (x,t,\rv)\in \partial D\times[0,1]\times\rvdom with forcing :math:`g(x,t)=(1.5+\cos(2\pi t))\cos(x_1)`, and subject to the initial condition :math:`u(x,0,\rv)=0`. Following [NTWSIAMNA2008]_, we model the diffusivity :math:`k` as a random field represented by the Karhunen-Loeve (like) expansion (KLE) .. math:: \log(k(x,\rv)-0.5)=1+\rv_1\left(\frac{\sqrt{\pi L}}{2}\right)^{1/2}+\sum_{k=2}^d \lambda_k\phi(x)\rv_k, with .. math:: \lambda_k=\left(\sqrt{\pi L}\right)^{1/2}\exp\left(-\frac{(\lfloor\frac{k}{2}\rfloor\pi L)^2}{4}\right) k>1, \qquad\qquad \phi(x)= \begin{cases} \sin\left(\frac{(\lfloor\frac{k}{2}\rfloor\pi x_1)}{L_p}\right) & k \text{ even}\,,\\ \cos\left(\frac{(\lfloor\frac{k}{2}\rfloor\pi x_1)}{L_p}\right) & k \text{ odd}\,. \end{cases} where :math:`L_p=\max(1,2L_c)`, :math:`L=\frac{L_c}{L_p}` and :math:`L_c=0.5`. We choose a random field which is effectively one-dimensional so that the error in the finite element solution is more sensitive to refinement of the mesh in the :math:`x_1`-direction than to refinement in the :math:`x_2`-direction. Quantities of Interest ---------------------- Often, one is more interested in quantifying uncertainty in a particular functional of the solution, called the quantity of interest (QoI), rather than the full solution. Let .. math:: F\left[u\right]: V \rightarrow \mathbb{R}^{q}, \qquad q>0 be such a function, where :math:`F` is typically a continuous and bounded functional. Then, we are interested in estimating statistics of the function .. math:: f(\rv)=F[u(\cdot,\rv)] : \Gamma \to \mathbb{R}^{q}. which assigns the value of the quantity of interest :math:`F[u]` to each realization of the random variables :math:`\rv`. The above expression allows us to express the QoI as a function of the random variables without needed to explicitly state the dependence of the QoI on the PDE solution. For the advection-diffusion model we consider the quantity of interest .. math:: f(\rv)=\int_D u(\rv)\frac{1}{2\pi\sigma^2}\exp\left(-\frac{\lVert x-x^\star \rVert_2^2}{\sigma^2}\right)\,dx, where :math:`x^\star=(0.3,0.5)` and :math:`\sigma=0.16`. Numerical Approximations ------------------------ For most, if not all, practical applications, the solutions of the governing equations and statistics of the resulting QoI cannot be computed analytically and numerical approximations must be employed. In the following we will consider finite element approximations, but other approaches such as finite volume and finite difference can also be used. Given a set of governing equations, we assume access to a PDE solver that approximates the solution :math:`u` of these equations for a given *fixed* :math:`\rv`. We also assume this solver has a set of hyper-parameters --- mesh size, time step, maximum number of iterations, convergence tolerance, etc. --- which can be used to estimate the QoI :math:`f` at varying accuracy and cost. Differing settings for these hyper-parameters produces simulations of *varying fidelities (resolution)*. We refer to approaches that leverage only one model or solver setting as *single-fidelity* methods and approaches that leverage multiple models and settings as *multi-fidelity* methods. The accuracy and cost of a model is often determined by a set of solver parameters, such as mesh size, time step, tolerances of numerical solvers. Let :math:`{n_\ai}` denote the number of such parameters for a given model. Furthermore let :math:`l_{\ai_i} \in \mathbb{N}` denote the number of values that each solver parameter can assume, such that the multi-index :math:`\ai=(\ai_1,\ldots,\ai_{n_\ai})\in\mathbb{N}^{n_\ai}`, :math:`\ai_i\in \mathcal{M}_{\ai_i}=\{1,\ldots,l_{\ai_i}\}` can be used to index specific values of the solver parameters. Finally let :math:`f_\ai(\rv)` to denote a single-fidelity physical approximation of the QoI :math:`f(\rv)` using the solver parameters indexed by :math:`\ai`. The advection-diffusion equation is solved with `Fenics `_ using the Galerkin finite element method with linear finite elements and the implicit backward-Euler time-stepping scheme. Let :math:`h_1` and :math:`h_2` denote the mesh-size in the spatial directions :math:`x_1` and :math:`x_2`. Then given some base coarse discretization :math:`h_{j,0}`, we create a sequence of :math:`l_{\ai_j}` uniform triangular meshes of increasing fidelity by setting \(h_{\ai_j}=h_{j,0}\cdot 2^{-\ai_j}`, :math:`0\le\ai_j`_ .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 3 minutes 7.723 seconds) .. _sphx_glr_download_auto_tutorials_foundations_plot_advection_diffusion_model.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_advection_diffusion_model.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_advection_diffusion_model.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_