# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Computational Astrophysics
# ## Partial Differential Equations. 01 Generalities
#
# ---
# ## <NAME>
#
# Observatorio Astronómico Nacional\
# Facultad de Ciencias\
# Universidad Nacional de Colombia
#
# ---

# ### About this notebook
#
# In this notebook we present some of the generalities about systems of Partial Differential Equations.
#
# `<NAME>. Numerical Methods for Physics. (1999). Chapter 6 - 7 `
#
# ---

# ## Partial Differential Equations (PDEs)
#
# A PDE is a relation between the partial derivatives of an unknown
# function and the independent variables. The order of the highest derivative sets the *order* of the PDE.
#
# A PDE is *linear* if it is of the first degree in the dependent 
# variable (i.e. the unknown function) and in its partial derivatives.
#
# If each term of a PDE contains either the dependent variable
# or one of its partial derivatives, the PDE is called *homogeneous*.
# Otherwise it is *non-homogeneous*.
#
#
#
#
#
#
# ---
# ### Types of Partial Differential Equations
#
# There are three general types of PDEs
#
# 1. hyperbolic
# 2. parabolic
# 3. elliptic
#
# Not all PDEs fall into one of these three types, but many
# PDEs used in practice do.
#
# These classes of PDEs model different sorts
# of phenomena, display different behavior, and require different numerical
# techniques for their solution.
#
# It is not always straighforward to see (to show and proof) what type
# of PDE is a given PDE!!. 
#

# ### Linear Second Order Differential Equation
#
# Consider a function $u=u(x,y)$ satisfying the linear second order differential equation
#
# \begin{equation}
# a \partial^2_{xx} u + b \partial^2_{xy} u + c \partial^2_{yy} u + d \partial_x u + e \partial_y u + f u = g\,\,,
# \end{equation}
#
# This equation is straightforwardly categorized based on the discriminant,
#
# \begin{equation}
# b^2 - 4ac \left\{ \begin{array}{lcr}
# < 0 & \rightarrow & \text{elliptic},\\
# = 0 & \rightarrow & \text{parabolic},\\
# > 0 & \rightarrow & \text{hyperbolic}.
# \end{array}\right.
# \end{equation}
#
# The names come from analogy with conic sections in the theory of
# ellipses.

# ---
# ## Hyperbolic PDEs
#
# Hyperbolic equations in physics and astrophysics
# describe **dynamical** processes and systems that generally start
# at some initial time $t_0=0$ with some initial conditions. Hence, the equations are then integrated in time.
#
#
# The prototypical linear second-order hyperbolic equation is the
# homogeneous wave equation,
#
# \begin{equation}
# c^2 \partial^2_{xx} u - \partial^2_{tt} u = 0\,\,,
# \end{equation}
#
# where $c$ is the wave speed.

# ---
# Another  class of hyperbolic equations are the **first-order
# hyperbolic systems**. In one space dimension and assuming a linear
# problem, this is
#
# \begin{equation}
# \partial_t u + A \partial_x u = 0\,\,,
# \end{equation}
#
# where $u(x,t)$ is a state vector with $s$ components and $A$
# is a $s \times s$ matrix.
#
# The problem is called *hyperbolic* if
# $A$ has only real eigenvalues and is diagonizable, i.e., has a complet set
# of linearly independent eigenvectors so that one can construct a 
# matrix
#
# \begin{equation}
# \Lambda = Q^{-1} A Q\,\,,
# \end{equation}
#
# where $\Lambda$ is diagonal and has real numbers on its diagonal. 
#
# **Example** 
#
# An example of these equations is the linear **advection equation**, in which the function $u=u(t,x)$ satisfies
#
# \begin{equation}
# \partial_t u + v \partial_x u = 0\,\,,
# \end{equation}
#
# which is first order, linear, and homogeneous.

# --- 
#
# Other example is given by the non-linear first-order systems. Consider the equation
#
# \begin{equation}
# \partial_t u + \partial_x F(u) = 0\,\,,
# \end{equation}
#
# where $F(u)$ is the **flux** and may or may not be non-linear in $u(t,x)$.
# We can re-write this PDE in **quasi-linear** form, by introducing
# the Jacobian
#
# \begin{equation}
# \bar{A} = \frac{\partial F}{\partial u}\,\,,
# \end{equation}
#
# and writing
#
# \begin{equation}
# \partial_t u + \bar{A}\partial_x u = 0\,\,.
# \label{eq:pde_quasilin1}
# \end{equation}
#
# This PDE is hyperbolic if $\bar{A}$ has real eigenvalues and is
# diagonizable. 
#
# The **equations of hydrodynamics** are a key example
# of a non-linear, first-order hyperbolic PDE system.

# ### Initial Conditions for Hyperbolic Problems
#
# One must specify either von Neumann, Dirichlet, or Robin boundary
# conditions:
#
# 1. **Dirichlet Boundary Conditions**
#
# \begin{equation}
# \begin{aligned}
# u(x=0,t) &= \Phi_1(t)\,\,,\\
# u(x=L,t) &= \Phi_2(t)\,\,.
# \end{aligned}
# \end{equation}
#
# 2. **von Neumann Boundary Conditions** 
# \begin{equation}
# \begin{aligned}
# \partial_x u(x=0,t) &= \Psi_1(t)\,\,,\\
# \partial_x u(x=L,t) &= \Psi_2(t)\,\,.
# \end{aligned}
# \end{equation}
#
# Note that in a multi-dimensional problem $\partial_x$ turns into the derivative in the direction of the normal to the boundary.
#
# 3. **Robin Boundary Conditions**
#
# $a_1, b_1, a_2, b_2$ be real numbers with $a_i \neq 0$ and $ b_i \neq 0$.
#
# \begin{equation}
# \begin{aligned}
# a_1 u(x=0,t) + b_1 \partial_x u(x=0,t) &= \Psi_1(t)\,\,,\\
# a_2 u(x=L,t) + b_2 \partial_x u(x=L,t) &= \Psi_2(t)\,\,.
# \end{aligned}
# \end{equation}
#
# Dirichlet and von Neuman boundary conditions are recovered if either
# both $a_i$ or both $b_i$ vanish.
# Note that in a multi-D problem $\partial_x$ turns into
# the derivative in the direction of the normal to the boundary.
#
#

# ---
# ## Parabolic PDEs
#
# Parabolic PDEs describe processes that are slowly changing, such as
# the slow diffusion of heat in a medium, sediments in ground water, and
# radiation in an opaque medium. Parabolic PDEs are second order and
# have generally the shape
#
# \begin{equation}
# \partial_t u - k \partial^2_{xx} u = f\,\,.
# \end{equation}
#
# ### Initial Conditions for Parabolic Problems
#
# One must specify $u(x,t=0)$ at all $x$.
#
#
# ### Boundary Conditions for Parabolic Problems
#
# Dirichlet, von Neumann or Robin boundary conditions.
# If the boundary conditions are independent of time, the system will
# evolve towards a steady state ($\partial_t u = 0$). In this case, 
# one may set $\partial_t u = 0$ for all times and treat the differential equation as an elliptic equation.

# ---
# ## Ellpitic PDEs
#
# Elliptic equations describe systems that are static, in steady state
# and/or in equilibrium. There is no time dependence. A typical elliptic
# equation is the Poisson equation,
#
# \begin{equation}
# \nabla^2 u = f\,\,,
# \end{equation}
#
# which one encounters in Newtonian gravity and in electrodynamics.
# $\nabla^2$ is the Laplace operator, and $f$ is a given scalar function
# of position. Elliptic problems may be linear ($f$ does not depend on
# $u$ or its derivatives) or non-linear ($f$ depends on $u$ or its
# derivatives).
#
#
# ### Initial Conditions for Elliptic Problems
#
# Do not apply, since there is no time dependence.
#
# ### Boundary Conditions for Elliptic Problems
#
# Dirichlet, von Neumann or Robin boundary conditions.

# ---
#
# ---
#
# ## Numerical Methods for PDEs
#
# There is no such thing as a general robust method for the solution of 
# generic PDEs. Each type (and each sub-type) of PDE requires a different
# approach. Real-life PDEs may be of mixed type or may have special 
# properties that require knowledge about the underlying physics for their
# successful solution.
#
# There are three general classes of approaches to solving PDEs

# ### 1. Finite Difference Methods.
#       
# The differential operators are approximated using their finite-difference
#       representation on a given grid. A sub-class of finite-difference methods,
#       so-called finite-volume methods, can be used for PDEs arising from
#       conservation laws (e.g., the hydrodynamics equations).
#
# Finite difference/volume methods have polynomial convergence for
#       smooth functions.
#       
# ### 2. Finite Element Methods.
#
# The domain is divided into cells (**elements**). The solution
#       is represented as a single function (e.g., a polynomial) on each
#       cell and the PDE is transformed to an algebraic problem for the matching
#       conditions of the simple functions at cell interfaces.
#
# Finite element methods can have polynomial or exponential convergence
#       for smooth functions.
#
# ### 3. Spectral Methods.
# The solution is represented by a linear combination of known
#       functions (e.g. trigonometric functions or special
#       polynomials). The PDE is transformed to a set of algebraic
#       equations (or ODEs) for the amplitudes of the component
#       functions. A sub-class of these methods are the collocation
#       methods. In them, the solution is represented on a grid and the
#       spectral decomposition of the solution in known functions is
#       used to estimate to a high degree of accuracy the partial
#       derivatives of the solution on the grid points.



StarcoderdataJupyterScriptsDedupFiltered