535 *
static const std::array<Source, 5> sources{
542 *
for (
const auto &source : sources)
543 *
if (p.distance(source.location) < source.radius)
558 *
const double radius;
566 * <a name=
"ImplementationofthecodeTATForwardProblemcodeclass"></a>
567 * <h3>Implementation of the <code>TATForwardProblem</code>
class</h3>
571 * Let
's start again with the constructor. Setting the member variables is
572 * straightforward. We use the acoustic wave speed of mineral oil (in
573 * millimeters per microsecond, a common unit in experimental biomedical
574 * imaging) since this is where many of the experiments we want to compare
575 * the output with are made in. The Crank-Nicolson scheme is used again,
576 * i.e. theta is set to 0.5. The time step is later selected to satisfy @f$k =
577 * \frac hc@f$: here we initialize it to an invalid number.
581 * TATForwardProblem<dim>::TATForwardProblem()
583 * , dof_handler(triangulation)
584 * , time_step(std::numeric_limits<double>::quiet_NaN())
586 * , timestep_number(1)
588 * , wave_speed(1.437)
592 * The second task in the constructor is to initialize the array that
593 * holds the detector locations. The results of this program were compared
594 * with experiments in which the step size of the detector spacing is 2.25
595 * degree, corresponding to 160 detector locations. The radius of the
596 * scanning circle is selected to be half way between the center and the
597 * boundary to avoid that the remaining reflections from the imperfect
598 * boundary condition spoils our numerical results.
602 * The locations of the detectors are then calculated in clockwise
603 * order. Note that the following of course only works if we are computing
604 * in 2d, a condition that we guard with an assertion. If we later wanted
605 * to run the same program in 3d, we would have to add code here for the
606 * initialization of detector locations in 3d. Due to the assertion, there
607 * is no way we can forget to do this.
610 * Assert(dim == 2, ExcNotImplemented());
612 * const double detector_step_angle = 2.25;
613 * const double detector_radius = 0.5;
615 * for (double detector_angle = 2 * numbers::PI; detector_angle >= 0;
616 * detector_angle -= detector_step_angle / 360 * 2 * numbers::PI)
617 * detector_locations.push_back(
618 * Point<dim>(std::cos(detector_angle), std::sin(detector_angle)) *
627 * <a name="TATForwardProblemsetup_system"></a>
628 * <h4>TATForwardProblem::setup_system</h4>
632 * The following system is pretty much what we've already done in @ref step_23
"step-23",
633 * but with two important differences. First, we have to create a circular
634 * (or spherical) mesh around the origin, with a radius of 1. This nothing
635 *
new: we
've done so before in @ref step_6 "step-6" and @ref step_10 "step-10", where we also explain
636 * how the PolarManifold or SphericalManifold object places new points on
637 * concentric circles when a cell is refined, which we will use here as
642 * One thing we had to make sure is that the time step satisfies the CFL
643 * condition discussed in the introduction of @ref step_23 "step-23". Back in that program,
644 * we ensured this by hand by setting a timestep that matches the mesh
645 * width, but that was error prone because if we refined the mesh once more
646 * we would also have to make sure the time step is changed. Here, we do
647 * that automatically: we ask a library function for the minimal diameter of
648 * any cell. Then we set @f$k=\frac h{c_0}@f$. The only problem is: what exactly
649 * is @f$h@f$? The point is that there is really no good theory on this question
650 * for the wave equation. It is known that for uniformly refined meshes
651 * consisting of rectangles, @f$h@f$ is the minimal edge length. But for meshes
652 * on general quadrilaterals, the exact relationship appears to be unknown,
653 * i.e. it is unknown what properties of cells are relevant for the CFL
654 * condition. The problem is that the CFL condition follows from knowledge
655 * of the smallest eigenvalue of the Laplace matrix, and that can only be
656 * computed analytically for simply structured meshes.
660 * The upshot of all this is that we're not quite sure what exactly we
662 * computes the minimal
diameter of all cells. If the cells were all squares
663 * or cubes, then the minimal edge length would be the minimal
diameter
664 * divided by <code>std::sqrt(dim)</code>. We simply generalize
this,
665 * without theoretical justification, to the
case of non-uniform meshes.
669 * The only other significant change is that we need to build the boundary
670 * mass
matrix. We will comment on
this further down below.
674 *
void TATForwardProblem<dim>::setup_system()
683 * std::cout <<
"Number of active cells: " <<
triangulation.n_active_cells()
686 * dof_handler.distribute_dofs(fe);
688 * std::cout <<
"Number of degrees of freedom: " << dof_handler.n_dofs()
694 * sparsity_pattern.copy_from(dsp);
696 * system_matrix.reinit(sparsity_pattern);
698 * laplace_matrix.reinit(sparsity_pattern);
709 * The
second difference, as mentioned, to @ref step_23
"step-23" is that we need to
710 * build the boundary mass
matrix that grew out of the absorbing boundary
715 *
A first observation would be that
this matrix is much sparser than the
717 * interior support contribute to
this matrix. We could therefore
718 * optimize the storage pattern to
this situation and build up a
second
719 * sparsity pattern that only contains the
nonzero entries that we
720 * need. There is a trade-off to make here:
first, we would have to have a
721 *
second sparsity pattern object, so that costs memory. Secondly, the
722 *
matrix attached to
this sparsity pattern is going to be smaller and
723 * therefore requires less memory; it would also be faster to perform
724 *
matrix-vector multiplications with it. The
final argument, however, is
725 * the
one that tips the
scale: we are not primarily interested in
726 * performing
matrix-vector with the boundary
matrix alone (though we need
727 * to
do that
for the right hand side vector once per time step), but
728 * mostly wish to add it up to the other matrices used in the
first of the
729 * two equations since
this is the
one that is going to be multiplied with
730 * once per iteration of the CG method, i.e. significantly more often. It
732 *
matrix to another, but only
if they use the same sparsity pattern (the
733 * reason being that we can
't add nonzero entries to a matrix after the
734 * sparsity pattern has been created, so we simply require that the two
735 * matrices have the same sparsity pattern).
739 * So let's go with that:
742 * boundary_matrix.reinit(sparsity_pattern);
746 * The
second thing to
do is to actually build the
matrix. Here, we need
747 * to integrate over faces of cells, so
first we need a quadrature
object
748 * that works on <code>dim-1</code> dimensional objects. Secondly, the
750 * suggest. And
finally, the other variables that are part of the assembly
751 * machinery. All of
this we put between curly braces to limit the scope
752 * of these variables to where we actually need them.
756 * The actual act of assembling the
matrix is then fairly straightforward:
757 * we
loop over all cells, over all faces of each of these cells, and then
758 *
do something only
if that particular face is at the boundary of the
763 * const QGauss<dim - 1> quadrature_formula(fe.degree + 1);
764 * FEFaceValues<dim> fe_values(fe,
765 * quadrature_formula,
766 * update_values | update_JxW_values);
768 * const unsigned int dofs_per_cell = fe.dofs_per_cell;
769 * const unsigned int n_q_points = quadrature_formula.size();
771 * FullMatrix<double> cell_matrix(dofs_per_cell, dofs_per_cell);
773 * std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
775 * for (const auto &cell : dof_handler.active_cell_iterators())
776 * for (const auto &face : cell->face_iterators())
777 * if (face->at_boundary())
781 * fe_values.reinit(cell, face);
783 * for (unsigned int q_point = 0; q_point < n_q_points; ++q_point)
784 * for (unsigned int i = 0; i < dofs_per_cell; ++i)
785 * for (unsigned int j = 0; j < dofs_per_cell; ++j)
786 * cell_matrix(i, j) += (fe_values.shape_value(i, q_point) *
787 * fe_values.shape_value(j, q_point) *
788 * fe_values.JxW(q_point));
790 * cell->get_dof_indices(local_dof_indices);
791 * for (unsigned int i = 0; i < dofs_per_cell; ++i)
792 * for (unsigned int j = 0; j < dofs_per_cell; ++j)
793 * boundary_matrix.add(local_dof_indices[i],
794 * local_dof_indices[j],
795 * cell_matrix(i, j));
800 * system_matrix.add(time_step * time_step * theta * theta * wave_speed *
803 * system_matrix.add(wave_speed * theta * time_step, boundary_matrix);
806 * solution_p.reinit(dof_handler.n_dofs());
807 * old_solution_p.reinit(dof_handler.n_dofs());
808 * system_rhs_p.reinit(dof_handler.n_dofs());
810 * solution_v.reinit(dof_handler.n_dofs());
811 * old_solution_v.reinit(dof_handler.n_dofs());
812 * system_rhs_v.reinit(dof_handler.n_dofs());
814 * constraints.close();
821 * <a name=
"TATForwardProblemsolve_pandTATForwardProblemsolve_v"></a>
822 * <h4>TATForwardProblem::solve_p and TATForwardProblem::solve_v</h4>
826 * The following two
functions, solving the linear systems
for the pressure
827 * and the velocity variable, are taken pretty much verbatim (with the
828 * exception of the change of name from @f$u@f$ to @f$p@f$ of the primary variable)
829 * from @ref step_23
"step-23":
833 *
void TATForwardProblem<dim>::solve_p()
835 *
SolverControl solver_control(1000, 1
e-8 * system_rhs_p.l2_norm());
840 * std::cout <<
" p-equation: " << solver_control.last_step()
841 * <<
" CG iterations." << std::endl;
847 *
void TATForwardProblem<dim>::solve_v()
849 *
SolverControl solver_control(1000, 1
e-8 * system_rhs_v.l2_norm());
854 * std::cout <<
" v-equation: " << solver_control.last_step()
855 * <<
" CG iterations." << std::endl;
863 * <a name=
"TATForwardProblemoutput_results"></a>
864 * <h4>TATForwardProblem::output_results</h4>
868 * The same holds here: the
function is from @ref step_23
"step-23".
872 *
void TATForwardProblem<dim>::output_results() const
882 *
const std::string filename =
886 * DataOutBase::VtkFlags::ZlibCompressionLevel::best_speed;
887 * std::ofstream output(filename);
896 * <a name=
"TATForwardProblemrun"></a>
901 * This
function that does most of the work is pretty much again like in
902 * @ref step_23
"step-23", though we make things a bit clearer by
using the vectors G1 and
903 * G2 mentioned in the introduction. Compared to the overall memory
904 * consumption of the program, the introduction of a few temporary vectors
905 * isn
't doing much harm.
909 * The only changes to this function are: first, that we do not have to
910 * project initial values for the velocity @f$v@f$, since we know that it is
911 * zero. And second that we evaluate the solution at the detector locations
912 * computed in the constructor. This is done using the
913 * VectorTools::point_value function. These values are then written to a
914 * file that we open at the beginning of the function.
918 * void TATForwardProblem<dim>::run()
922 * VectorTools::project(dof_handler,
924 * QGauss<dim>(fe.degree + 1),
925 * InitialValuesP<dim>(),
927 * old_solution_v = 0;
930 * std::ofstream detector_data("detectors.dat");
932 * Vector<double> tmp(solution_p.size());
933 * Vector<double> G1(solution_p.size());
934 * Vector<double> G2(solution_v.size());
936 * const double end_time = 0.7;
937 * for (time = time_step; time <= end_time;
938 * time += time_step, ++timestep_number)
940 * std::cout << std::endl;
941 * std::cout << "time_step " << timestep_number << " @ t=" << time
944 * mass_matrix.vmult(G1, old_solution_p);
945 * mass_matrix.vmult(tmp, old_solution_v);
946 * G1.add(time_step * (1 - theta), tmp);
948 * mass_matrix.vmult(G2, old_solution_v);
949 * laplace_matrix.vmult(tmp, old_solution_p);
950 * G2.add(-wave_speed * wave_speed * time_step * (1 - theta), tmp);
952 * boundary_matrix.vmult(tmp, old_solution_p);
953 * G2.add(wave_speed, tmp);
956 * system_rhs_p.add(time_step * theta, G2);
961 * laplace_matrix.vmult(tmp, solution_p);
962 * system_rhs_v.add(-time_step * theta * wave_speed * wave_speed, tmp);
964 * boundary_matrix.vmult(tmp, solution_p);
965 * system_rhs_v.add(-wave_speed, tmp);
971 * detector_data << time;
972 * for (unsigned int i = 0; i < detector_locations.size(); ++i)
973 * detector_data << " "
974 * << VectorTools::point_value(dof_handler,
976 * detector_locations[i])
978 * detector_data << std::endl;
980 * old_solution_p = solution_p;
981 * old_solution_v = solution_v;
984 * } // namespace Step24
991 * <a name="Thecodemaincodefunction"></a>
992 * <h3>The <code>main</code> function</h3>
996 * What remains is the main function of the program. There is nothing here
997 * that hasn't been shown in several of the previous programs:
1004 *
using namespace Step24;
1006 * TATForwardProblem<2> forward_problem_solver;
1007 * forward_problem_solver.run();
1009 *
catch (std::exception &exc)
1011 * std::cerr << std::endl
1013 * <<
"----------------------------------------------------"
1015 * std::cerr <<
"Exception on processing: " << std::endl
1016 * << exc.what() << std::endl
1017 * <<
"Aborting!" << std::endl
1018 * <<
"----------------------------------------------------"
1025 * std::cerr << std::endl
1027 * <<
"----------------------------------------------------"
1029 * std::cerr <<
"Unknown exception!" << std::endl
1030 * <<
"Aborting!" << std::endl
1031 * <<
"----------------------------------------------------"
1039 <a name=
"Results"></a><h1>Results</h1>
1042 The program writes both graphical data
for each time step as well as the
1043 values evaluated at each detector location to disk. We then
1044 draw them in plots. Experimental data were also collected
for comparison.
1045 Currently our experiments have only been done in two dimensions by
1046 circularly scanning a single detector. The tissue sample here is a thin slice
1047 in the @f$X-Y@f$ plane (@f$Z=0@f$), and we assume that signals from other @f$Z@f$
1048 directions won
't contribute to the data. Consequently, we only have to compare
1049 our experimental data with two dimensional simulated data.
1051 <a name="Oneabsorber"></a><h3> One absorber </h3>
1054 This movie shows the thermoacoustic waves generated by a single small absorber
1055 propagating in the medium (in our simulation, we assume the medium is mineral
1056 oil, which has a acoustic speed of 1.437 @f$\frac{mm}{\mu s}@f$):
1058 <img src="https://www.dealii.org/images/steps/developer/step-24.one_movie.gif" alt="">
1060 For a single absorber, we of course have to change the
1061 <code>InitialValuesP</code> class accordingly.
1063 Next, let us compare experimental and computational results. The visualization
1064 uses a technique long used in seismology, where the data of each detector is
1065 plotted all in one graph. The way this is done is by offsetting each
1066 detector's signal a bit compared to the previous
one. For example, here is a
1067 plot of the
first four detectors (from bottom to top, with time in
1068 microseconds running from left to right)
using the source setup used in the
1069 program, to make things a bit more interesting compared to the present
case of
1070 only a single source:
1072 <img src=
"https://www.dealii.org/images/steps/developer/step-24.traces.png" alt=
"">
1074 One thing that can be seen,
for example, is that the arrival of the
second and
1075 fourth signals shifts to earlier times
for greater detector
numbers (i.e. the
1076 topmost ones), but not the
first and the third;
this can be interpreted to
1077 mean that the origin of these signals must be closer to the latter detectors
1078 than to the former ones.
1080 If we stack not only 4, but all 160 detectors in
one graph, the individual
1081 lines blur, but where they
run together they create a pattern of darker or
1082 lighter grayscales. The following two figures show the results obtained at
1083 the detector locations stacked in that way. The left figure is obtained from
1084 experiments, and the right is the simulated data.
1085 In the experiment, a single small strong absorber was embedded in
1086 weaker absorbing tissue:
1088 <table width=
"100%">
1091 <img src=
"https://www.dealii.org/images/steps/developer/step-24.one.png" alt=
"">
1094 <img src=
"https://www.dealii.org/images/steps/developer/step-24.one_s.png" alt=
"">
1099 It is obvious that the source location is closer to the detectors at
angle
1100 @f$180^\circ@f$. All the other signals that can be seen in the experimental data
1101 result from the fact that there are weak absorbers also in the rest of the
1102 tissue, which surrounds the signals generated by the small strong absorber in
1103 the
center. On the other hand, in the simulated data, we only simulate the
1104 small strong absorber.
1106 In reality, detectors have limited bandwidth. The thermoacoustic waves passing
1107 through the detector will therefore be filtered. By
using a high-pass filter
1108 (implemented in MATLAB and
run against the data file produced by
this program),
1109 the simulated results can be made to look closer to the experimental
1112 <img src=
"https://www.dealii.org/images/steps/developer/step-24.one_sf.png" alt=
"">
1114 In our simulations, we see spurious signals behind the main wave that
1115 result from numerical artifacts. This problem can be alleviated by
using finer
1116 mesh, resulting in the following plot:
1118 <img src=
"https://www.dealii.org/images/steps/developer/step-24.one_s2.png" alt=
"">
1122 <a name=
"Multipleabsorbers"></a><h3>Multiple absorbers</h3>
1125 To further verify the program, we will also show simulation results
for
1126 multiple absorbers. This corresponds to the
case that is actually implemented
1127 in the program. The following movie shows the propagation of the generated
1128 thermoacoustic waves in the medium by multiple absorbers:
1130 <img src=
"https://www.dealii.org/images/steps/developer/step-24.multi_movie.gif" alt=
"">
1132 Experimental data and our simulated data are compared in the following two
1134 <table width=
"100%">
1137 <img src=
"https://www.dealii.org/images/steps/developer/step-24.multi.png" alt=
"">
1140 <img src=
"https://www.dealii.org/images/steps/developer/step-24.multi_s.png" alt=
"">
1145 Note that in the experimental data, the
first signal (i.e. the left-most dark
1146 line) results from absorption at the tissue boundary, and therefore reaches
1147 the detectors
first and before any of the signals from the interior. This
1148 signal is also faintly visible at the
end of the traces, around 30 @f$\mu s@f$,
1149 which indicates that the signal traveled through the entire tissue to reach
1150 detectors at the other side, after all the signals originating from the
1151 interior have reached them.
1153 As before, the numerical result better matches experimental ones by applying a
1154 bandwidth filter that matches the actual behavior of detectors (left) and by
1155 choosing a finer mesh (right):
1157 <table width=
"100%">
1160 <img src=
"https://www.dealii.org/images/steps/developer/step-24.multi_sf.png" alt=
"">
1163 <img src=
"https://www.dealii.org/images/steps/developer/step-24.multi_s2.png" alt=
"">
1168 One of the important differences between the left and the right figure is that
1169 the curves look much less
"angular" at the right. The angularity comes from
1170 the fact that while waves in the continuous equation travel equally fast in
1171 all directions, this isn
't the case after discretization: there, waves that
1172 travel diagonal to cells move at slightly different speeds to those that move
1173 parallel to mesh lines. This anisotropy leads to wave fronts that aren't
1174 perfectly circular (and would produce sinusoidal signals in the stacked
1175 plots), but are bulged out in certain directions. To make things worse, the
1176 circular mesh we use (see for example @ref step_6
"step-6" for a view of the
1177 coarse mesh) is not isotropic either. The net result is that the signal fronts
1178 are not sinusoidal unless the mesh is sufficiently fine. The right image is a
1179 lot better in this respect, though artifacts in the form of trailing spurious
1180 waves can still be seen.
1183 <a name=
"PlainProg"></a>
1184 <h1> The plain program</h1>
1185 @include
"step-24.cc"