<a name="Intro"></a>
<h1>Introduction</h1>

This program grew out of a student project by Xing Jin at Texas A&amp;M
University. Most of the work for this program is by her. Some of the work on
this tutorial program has been funded by NSF under grant DMS-0604778.

The program is part of a project that aims to simulate thermoacoustic
tomography imaging. In thermoacoustic tomography, pulsed electromagnetic
energy is delivered into biological issues. Tissues absorb some of this energy
and those parts of the tissue that absorb the most energy generate
thermoacoustic waves through thermoelastic expansion. For imaging, one uses
that different kinds of tissue, most importantly healthy and diseased tissue,
absorb different amounts of energy and therefore expand at different
rates. The experimental setup is to measure the amplitude of the pressure
waves generated by these sources on the surface of the tissue and try to
reconstruct the source distributions, which is indicative for the distribution
of absorbers and therefore of different kinds of tissue. Part of this project
is to compare simulated data with actual measurements, so one has to solve the
"forward problem", i.e. the wave equation that describes the propagation of
pressure waves in tissue. This program is therefore a continuation of @ref
step_23 "step-23", where the wave equation was first introduced.


<h3>The problem</h3>

The temperature at a given location, neglecting thermal diffusion, can be
stated as 

@f[
\rho C_p \frac{\partial}{\partial t}T(t,\mathbf r) = H(t,\mathbf r)
@f]

Here $\rho (\mathbf r) $ is the density; $C_p (\mathbf r) $ is the specific
heat; $\frac{\partial T}{\partial t}(t,\mathbf r)$ is the temperature rise due
to the delivered microwave energy; and $H(t,\mathbf r)$ is the heating
function defined as the thermal energy per time and volume transformed from
deposited microwave energy.

Let us assume that tissues have heterogeneous dielectric properties but
homogeneous acoustic properties. The basic acoustic generation equation in an
acoustically homogeneous medium can be described as follows: if $u$ is the
vector-valued displacement, then tissue certainly reacts to changes in
pressure by acceleration:
@f[
\rho \frac{\partial^2}{\partial t^2}u(t,\mathbf r) = 
-\nabla p(t,\mathbf r).
@f]
Furthermore, it contracts due to excess pressure and expands based on changes in temperature:
@f[
\nabla \cdot u(t,\mathbf r) = -\frac{p(t,\mathbf r)}{\rho c_0^2}+\beta T(t,\mathbf r) .
@f]
Here, $\beta$ is a thermoexpansion coefficient.

Let us now make the assumption that heating only happens on a time
scale much shorter than wave propagation through tissue (i.e. the temporal
length of the microwave pulse that heats the tissue is much shorter than the
time it takes a wave to cross the domain). In that case, the heating
rate $H(t,\mathbf r)$ can be written as $H(t,\mathbf r) = a(\mathbf
r)\delta(t)$ (where $a(\mathbf r)$ is a map of absorption strengths for
microwave energy and $\delta(t)$ is the Dirac delta function), which together
with the first equation above will yield 
an instantaneous jump in the temperature $T(\mathbf r)$ at time $t=0$.
Using this assumption, and taking all equations together, we can
rewrite and combine the above as follows:
@f[
\Delta p-\frac{1}{c_0^2} \frac{\partial^2 p}{\partial t^2} = \lambda
a(\mathbf r)\frac{d\delta(t)}{dt}
@f]
where $\lambda = - \frac{\beta}{C_p}$. 

This somewhat strange equation with the derivative of a Dirac delta function
on the right hand side can be rewritten as an initial value problem as follows:
@f{eqnarray*} 
\Delta \bar{p}- \frac{1}{c_0^2} \frac{\partial^2 \bar{p}}{\partial t^2} & = &
0 \\ 
\bar{p}(0,\mathbf r) &=& c_0^2 \lambda a(\mathbf r) = b(\mathbf r)  \\ 
\frac{\partial\bar{p}(0,\mathbf r)}{\partial t} &=& 0.
@f}
(A derivation of this transformation into an initial value problem is given at
the end of this introduction as an appendix.)

In the inverse problem, it is the initial condition $b(\mathbf r) = c_0^2 \lambda a(\mathbf r)$ that
one would like to recover, since it is a map of absorption strengths for
microwave energy, and therefore presumably an indicator to discern healthy
from diseased tissue.

In real application, the thermoacoustic source is very small as compared to
the medium.  The propagation path of the thermoacoustic waves can then be
approximated as from the source to the infinity. Furthermore, detectors are
only a limited distance from the source. One only needs to evaluate the values
when the thermoacoustic waves pass through the detectors, although they do
continue beyond. This is therefore a problem where we are only interested in a
small part of an infinite medium, and we do not want waves generated somewhere
to be reflected at the boundary of the domain which we consider
interesting. Rather, we would like to simulate only that part of the wave
field that is contained inside the domain of interest, and waves that hit the
boundary of that domain to simply pass undisturbed through the boundary. In
other words, we would like the boundary to absorb any waves that hit it.

In general, this is a hard problem: Good absorbing boundary conditions are
nonlinear and/or numerically very expensive. We therefore opt for a simple
first order approximation to absorbing boundary conditions that reads
@f[
\frac{\partial\bar{p}}{\partial\mathbf n} = 
-\frac{1}{c_0} \frac{\partial\bar{p}}{\partial t}
@f]
Here, $\frac{\partial\bar{p}}{\partial\mathbf n}$ is the normal derivative at
the boundary. It should be noted that this is not a particularly good boundary
condition, but it is one of the very few that are reasonably simple to implement.


<h3>Weak form and discretization</h3>

As in step-23, one first introduces a second variable, which is
defined as the derivative of the pressure potential:
@f[ 
v = \frac{\partial\bar{p}}{\partial t} 
@f]

With the second variable, one then transforms the forward problem into
two separate equations:
@f{eqnarray*}
\bar{p}_{t} - v & = & 0 \\
\Delta\bar{p} - \frac{1}{c_0^2}\,v_{t} & = & f 
@f}
with initial conditions:
@f{eqnarray*}
\bar{p}(0,\mathbf r) & = & b(r) \\
v(0,\mathbf r)=\bar{p}_t(0,\mathbf r) & = & 0.
@f}
Note that we have introduced a right hand side $f(t,\mathbf r)$ here to show
how to derive these formulas in the general case, although in the application
to the thermoacoustic problem $f=0$.

The semi-discretized, weak version of this model, using the general $\theta$ scheme
introduced in step-23 is then:
@f{eqnarray*}
\left(\frac{\bar{p}^n-\bar{p}^{n-1}}{k},\phi\right)_\Omega-
\left(\theta v^{n}+(1-\theta)v^{n-1},\phi\right)_\Omega & = & 0   \\
-\left(\nabla((\theta\bar{p}^n+(1-\theta)\bar{p}^{n-1})),\nabla\phi\right)_\Omega-
\frac{1}{c_0}\left(\frac{\bar{p}^n-\bar{p}^{n-1}}{k},\phi\right)_{\partial\Omega} - 
\frac{1}{c_0^2}\left(\frac{v^n-v^{n-1}}{k},\phi\right)_\Omega & = 
& \left(\theta f^{n}+(1-\theta)f^{n-1}, \phi\right)_\Omega,
@f}
where $\phi$ is an arbitrary test function, and where we have used the
absorbing boundary condition to integrate by parts:
absorbing boundary conditions are incorporated into the weak form by using 
@f[ 
\int_\Omega\varphi \, \Delta p\; dx =
-\int_\Omega\nabla \varphi \cdot \nabla p dx + 
\int_{\partial\Omega}\varphi \frac{\partial p}{\partial {\mathbf n}}ds.
@f]

From this we obtain the discrete model by introducing a finite number of shape
functions, and get
@f{eqnarray*}
M\bar{p}^{n}-k \theta M v^n & = & M\bar{p}^{n-1}+k (1-\theta)Mv^{n-1},\\

(-c_0^2k \theta A-c_0 B)\bar{p}^n-Mv^{n} & = & 
(c_0^2k(1-\theta)A-c_0B)\bar{p}^{n-1}-Mv^{n-1}+c_0^2k(\theta F^{n}+(1-\theta)F^{n-1}).
@f}
The matrices $M$ and $A$ are here as in step-23, and the
boundary mass matrix
@f[
	B_{ij} = \left(\varphi_i,\varphi_j\right)_{\partial\Omega}
@f]
results from the use of absorbing boundary conditions.

Above two equations can be rewritten in a matrix form with the pressure and its derivative as
an unknown vector:
@f[
\left(\begin{array}{cc}
 M         &       -k\theta M \\
c_0^2\,k\,\theta\,A+c_0\,B  &  M   \\
               \end{array} \right)\\
\left(\begin{array}{c}
 \bar{p}^{n}    \\
 \bar{v}^{n}
              \end{array}\right)=\\
\left(\begin{array}{l}
 G_1  \\
 G_2 -(\theta F^{n}+(1-\theta)F ^{n-1})c_{0}^{2}k \\        
                \end{array}\right)
@f]

where
@f[
\left(\begin{array}{c}
G_1 \\
G_2 \\
   \end{array} \right)=\\
\left(\begin{array}{l}
 M\bar{p}^{n-1}+k(1-\theta)Mv^{n-1}\\               
 (-c_{0}^{2}k (1-\theta)A+c_0 B)\bar{p}^{n-1} +Mv^{n-1}
                \end{array}\right)
@f]

By simple transformations, one then obtains two equations for
the pressure potential and its derivative, just as in the previous tutorial program:
@f{eqnarray*}
(M+(k\,\theta\,c_{0})^{2}A+c_0k\theta B)\bar{p}^{n} & = & 
G_{1}+(k\, \theta)G_{2}-(c_0k)^2\theta (\theta F^{n}+(1-\theta)F^{n-1}) \\
Mv^n & = & -(c_0^2\,k\, \theta\, A+c_0B)\bar{p}^{n}+ G_2 - 
c_0^2k(\theta F^{n}+(1-\theta)F^{n-1}) 
@f}


<h3>What the program does</h3>

Compared to step-23, this programs adds the treatment of a
simple absorbing boundary conditions. In addition, it deals with data obtained
from actual experimental measurements. To this end, we need to evaluate the
solution at points at which the experiment also evaluates a real pressure
field. We will see how to do that using the VectorTools::point_value function
further down below.



<h3>Appendix: PDEs with Dirac delta functions as right hand side and their transformation to an initial value problem</h3>

In the derivation of the initial value problem for the wave equation, we
initially found that the equation had the derivative of a Dirac delta function
as a right hand side:
@f[
\Delta p-\frac{1}{c_0^2} \frac{\partial^2 p}{\partial t^2} = \lambda
a(\mathbf r)\frac{d\delta(t)}{dt}.
@f]
In order to see how to transform this single equation into the usual statement
of a PDE with initial conditions, let us make the assumption that the
physically quite reasonable medium is at rest initially, i.e. $p(t,\mathbf
r)=\frac{\partial p(t,\mathbf r)}{\partial t}=0$ for $t<0$. Next, let us form
the indefinite integral with respect to time of both sides:
@f[
\int^t \Delta p\; dt -\int^t \frac{1}{c_0^2} \frac{\partial^2 p}{\partial t^2}
\; dt
= 
\int^t \lambda a(\mathbf r)\frac{d\delta(t)}{dt} \;dt.
@f]
This immediately leads to the statement
@f[
P(t,\mathbf r) - \frac{1}{c_0^2} \frac{\partial p}{\partial t}
= 
\lambda a(\mathbf r) \delta(t),
@f]
where $P(t,\mathbf r)$ is such that $\frac{dP(t,\mathbf r)}{dt}=\Delta
p$. Next, we form the (definite) integral over time from $t=-\epsilon$ to
$t=+\epsilon$ to find 
@f[
\int_{-\epsilon}^{\epsilon} P(t,\mathbf r)\; dt 
- \frac{1}{c_0^2} \left[ p(\epsilon,\mathbf r) - p(-\epsilon,\mathbf r) \right]
= 
\int_{-\epsilon}^{\epsilon} \lambda a(\mathbf r) \delta(t) \; dt.
@f]
If we use the property of the delta function that $\int_{-\epsilon}^{\epsilon}
\delta(t)\; dt = 1$, and assume that $P$ is a continuous function in time, we find
as we let $\epsilon$ go to zero that
@f[
- \lim_{\epsilon\rightarrow 0}\frac{1}{c_0^2} \left[ p(\epsilon,\mathbf r) - p(-\epsilon,\mathbf r) \right]
= 
\lambda a(\mathbf r).
@f]
In other words, using that $p(-\epsilon,\mathbf r)=0$, we retrieve the initial
condition 
@f[
  \frac{1}{c_0^2} p(0,\mathbf r)  
  =
  \lambda a(\mathbf r).
@f]
At the same time, we know that for every $t>0$ the delta function is zero, so
for $0<t<T$ we get the equation
@f[
\Delta p-\frac{1}{c_0^2} \frac{\partial^2 p}{\partial t^2} = 0.
@f]
Consequently, we have obtained a representation of the wave equation and one
initial condition from the original somewhat strange equation.

Finally, because we here have an equation with two time derivatives, we still
need a second initial condition. To this end, let us go back to the equation
@f[
\Delta p-\frac{1}{c_0^2} \frac{\partial^2 p}{\partial t^2} = \lambda
a(\mathbf r)\frac{d\delta(t)}{dt}.
@f]
and integrate it in time from $t=-\epsilon$ to $t=+\epsilon$. This leads to
@f[
P(\epsilon)-P(-\epsilon)
-\frac{1}{c_0^2} \left[\frac{\partial p(\epsilon)}{\partial t} -
                       \frac{\partial p(-\epsilon)}{\partial t}\right]
 = \lambda a(\mathbf r) \int_{-\epsilon}^{\epsilon}\frac{d\delta(t)}{dt} \; dt.
@f]
Using integration by parts of the form
@f[
  \int_{-\epsilon}^{\epsilon}\varphi(t)\frac{d\delta(t)}{dt} \; dt
  =
  -\int_{-\epsilon}^{\epsilon}\frac{d\varphi(t)}{dt} \delta(t)\; dt
@f]
where we use that $\delta(\pm \epsilon)=0$ and inserting $\varphi(t)=1$, we
see that in fact
@f[
  \int_{-\epsilon}^{\epsilon}\frac{d\delta(t)}{dt} \; dt
  =
  0.
@f]

Now, let $\epsilon\rightarrow 0$. Assuming that $P$ is a continuous function in
time, we see that 
@f[
  P(\epsilon)-P(-\epsilon) \rightarrow 0,
@f]
and consequently
@f[
  \frac{\partial p(\epsilon)}{\partial t} -
                       \frac{\partial p(-\epsilon)}{\partial t}
		       \rightarrow 0.
@f]
However, we have assumed that $\frac{\partial p(-\epsilon)}{\partial t}=0$.
Consequently, we obtain as the second initial condition that
@f[
  \frac{\partial p(0)}{\partial t} = 0,
@f]
completing the system of equations.

