Reference documentation for deal.II version GIT relicensing-437-g81ec864850 2024-04-19 07:30:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
step-32.h
Go to the documentation of this file.
1
1510 *   constexpr double kappa = 1e-6; /* m^2 / s */
1511 *   constexpr double reference_density = 3300; /* kg / m^3 */
1512 *   constexpr double reference_temperature = 293; /* K */
1513 *   constexpr double expansion_coefficient = 2e-5; /* 1/K */
1514 *   constexpr double specific_heat = 1250; /* J / K / kg */
1515 *   constexpr double radiogenic_heating = 7.4e-12; /* W / kg */
1516 *  
1517 *  
1518 *   constexpr double R0 = 6371000. - 2890000.; /* m */
1519 *   constexpr double R1 = 6371000. - 35000.; /* m */
1520 *  
1521 *   constexpr double T0 = 4000 + 273; /* K */
1522 *   constexpr double T1 = 700 + 273; /* K */
1523 *  
1524 *  
1525 * @endcode
1526 *
1527 * The next set of definitions are for functions that encode the density
1528 * as a function of temperature, the gravity vector, and the initial
1529 * values for the temperature. Again, all of these (along with the values
1530 * they compute) are discussed in the introduction:
1531 *
1532 * @code
1533 *   double density(const double temperature)
1534 *   {
1535 *   return (
1536 *   reference_density *
1537 *   (1 - expansion_coefficient * (temperature - reference_temperature)));
1538 *   }
1539 *  
1540 *  
1541 *   template <int dim>
1542 *   Tensor<1, dim> gravity_vector(const Point<dim> &p)
1543 *   {
1544 *   const double r = p.norm();
1545 *   return -(1.245e-6 * r + 7.714e13 / r / r) * p / r;
1546 *   }
1547 *  
1548 *  
1549 *  
1550 *   template <int dim>
1551 *   class TemperatureInitialValues : public Function<dim>
1552 *   {
1553 *   public:
1554 *   TemperatureInitialValues()
1555 *   : Function<dim>(1)
1556 *   {}
1557 *  
1558 *   virtual double value(const Point<dim> &p,
1559 *   const unsigned int component = 0) const override;
1560 *  
1561 *   virtual void vector_value(const Point<dim> &p,
1562 *   Vector<double> &value) const override;
1563 *   };
1564 *  
1565 *  
1566 *  
1567 *   template <int dim>
1568 *   double TemperatureInitialValues<dim>::value(const Point<dim> &p,
1569 *   const unsigned int) const
1570 *   {
1571 *   const double r = p.norm();
1572 *   const double h = R1 - R0;
1573 *  
1574 *   const double s = (r - R0) / h;
1575 *   const double q =
1576 *   (dim == 3) ? std::max(0.0, cos(numbers::PI * abs(p[2] / R1))) : 1.0;
1577 *   const double phi = std::atan2(p[0], p[1]);
1578 *   const double tau = s + 0.2 * s * (1 - s) * std::sin(6 * phi) * q;
1579 *  
1580 *   return T0 * (1.0 - tau) + T1 * tau;
1581 *   }
1582 *  
1583 *  
1584 *   template <int dim>
1585 *   void
1586 *   TemperatureInitialValues<dim>::vector_value(const Point<dim> &p,
1587 *   Vector<double> &values) const
1588 *   {
1589 *   for (unsigned int c = 0; c < this->n_components; ++c)
1590 *   values(c) = TemperatureInitialValues<dim>::value(p, c);
1591 *   }
1592 *  
1593 *  
1594 * @endcode
1595 *
1596 * As mentioned in the introduction we need to rescale the pressure to
1597 * avoid the relative ill-conditioning of the momentum and mass
1598 * conservation equations. The scaling factor is @f$\frac{\eta}{L}@f$ where
1599 * @f$L@f$ was a typical length scale. By experimenting it turns out that a
1600 * good length scale is the diameter of plumes, which is around 10 km:
1601 *
1602 * @code
1603 *   constexpr double pressure_scaling = eta / 10000;
1604 *  
1605 * @endcode
1606 *
1607 * The final number in this namespace is a constant that denotes the
1608 * number of seconds per (average, tropical) year. We use this only when
1609 * generating screen output: internally, all computations of this program
1610 * happen in SI units (kilogram, meter, seconds) but writing geological
1611 * times in seconds yields numbers that one can't relate to reality, and
1612 * so we convert to years using the factor defined here:
1613 *
1614 * @code
1615 *   const double year_in_seconds = 60 * 60 * 24 * 365.2425;
1616 *  
1617 *   } // namespace EquationData
1618 *  
1619 *  
1620 *  
1621 * @endcode
1622 *
1623 *
1624 * <a name="step_32-PreconditioningtheStokessystem"></a>
1625 * <h3>Preconditioning the Stokes system</h3>
1626 *
1627
1628 *
1629 * This namespace implements the preconditioner. As discussed in the
1630 * introduction, this preconditioner differs in a number of key portions
1631 * from the one used in @ref step_31 "step-31". Specifically, it is a right preconditioner,
1632 * implementing the matrix
1633 * @f{align*}{
1634 * \left(\begin{array}{cc}A^{-1} & -A^{-1}B^TS^{-1}
1635 * \\0 & S^{-1}
1636 * \end{array}\right)
1637 * @f}
1638 * where the two inverse matrix operations
1639 * are approximated by linear solvers or, if the right flag is given to the
1640 * constructor of this class, by a single AMG V-cycle for the velocity
1641 * block. The three code blocks of the <code>vmult</code> function implement
1642 * the multiplications with the three blocks of this preconditioner matrix
1643 * and should be self explanatory if you have read through @ref step_31 "step-31" or the
1644 * discussion of composing solvers in @ref step_20 "step-20".
1645 *
1646 * @code
1647 *   namespace LinearSolvers
1648 *   {
1649 *   template <class PreconditionerTypeA, class PreconditionerTypeMp>
1650 *   class BlockSchurPreconditioner : public Subscriptor
1651 *   {
1652 *   public:
1653 *   BlockSchurPreconditioner(const TrilinosWrappers::BlockSparseMatrix &S,
1654 *   const TrilinosWrappers::BlockSparseMatrix &Spre,
1655 *   const PreconditionerTypeMp &Mppreconditioner,
1656 *   const PreconditionerTypeA &Apreconditioner,
1657 *   const bool do_solve_A)
1658 *   : stokes_matrix(&S)
1659 *   , stokes_preconditioner_matrix(&Spre)
1660 *   , mp_preconditioner(Mppreconditioner)
1661 *   , a_preconditioner(Apreconditioner)
1662 *   , do_solve_A(do_solve_A)
1663 *   {}
1664 *  
1665 *   void vmult(TrilinosWrappers::MPI::BlockVector &dst,
1666 *   const TrilinosWrappers::MPI::BlockVector &src) const
1667 *   {
1668 *   TrilinosWrappers::MPI::Vector utmp(src.block(0));
1669 *  
1670 *   {
1671 *   SolverControl solver_control(5000, 1e-6 * src.block(1).l2_norm());
1672 *  
1673 *   SolverCG<TrilinosWrappers::MPI::Vector> solver(solver_control);
1674 *  
1675 *   solver.solve(stokes_preconditioner_matrix->block(1, 1),
1676 *   dst.block(1),
1677 *   src.block(1),
1678 *   mp_preconditioner);
1679 *  
1680 *   dst.block(1) *= -1.0;
1681 *   }
1682 *  
1683 *   {
1684 *   stokes_matrix->block(0, 1).vmult(utmp, dst.block(1));
1685 *   utmp *= -1.0;
1686 *   utmp.add(src.block(0));
1687 *   }
1688 *  
1689 *   if (do_solve_A == true)
1690 *   {
1691 *   SolverControl solver_control(5000, utmp.l2_norm() * 1e-2);
1692 *   TrilinosWrappers::SolverCG solver(solver_control);
1693 *   solver.solve(stokes_matrix->block(0, 0),
1694 *   dst.block(0),
1695 *   utmp,
1696 *   a_preconditioner);
1697 *   }
1698 *   else
1699 *   a_preconditioner.vmult(dst.block(0), utmp);
1700 *   }
1701 *  
1702 *   private:
1703 *   const SmartPointer<const TrilinosWrappers::BlockSparseMatrix>
1704 *   stokes_matrix;
1705 *   const SmartPointer<const TrilinosWrappers::BlockSparseMatrix>
1706 *   stokes_preconditioner_matrix;
1707 *   const PreconditionerTypeMp &mp_preconditioner;
1708 *   const PreconditionerTypeA &a_preconditioner;
1709 *   const bool do_solve_A;
1710 *   };
1711 *   } // namespace LinearSolvers
1712 *  
1713 *  
1714 *  
1715 * @endcode
1716 *
1717 *
1718 * <a name="step_32-Definitionofassemblydatastructures"></a>
1719 * <h3>Definition of assembly data structures</h3>
1720 *
1721
1722 *
1723 * As described in the introduction, we will use the WorkStream mechanism
1724 * discussed in the @ref threads module to parallelize operations among the
1725 * processors of a single machine. The WorkStream class requires that data
1726 * is passed around in two kinds of data structures, one for scratch data
1727 * and one to pass data from the assembly function to the function that
1728 * copies local contributions into global objects.
1729 *
1730
1731 *
1732 * The following namespace (and the two sub-namespaces) contains a
1733 * collection of data structures that serve this purpose, one pair for each
1734 * of the four operations discussed in the introduction that we will want to
1735 * parallelize. Each assembly routine gets two sets of data: a Scratch array
1736 * that collects all the classes and arrays that are used for the
1737 * calculation of the cell contribution, and a CopyData array that keeps
1738 * local matrices and vectors which will be written into the global
1739 * matrix. Whereas CopyData is a container for the final data that is
1740 * written into the global matrices and vector (and, thus, absolutely
1741 * necessary), the Scratch arrays are merely there for performance reasons
1742 * &mdash; it would be much more expensive to set up a FEValues object on
1743 * each cell, than creating it only once and updating some derivative data.
1744 *
1745
1746 *
1747 * @ref step_31 "step-31" had four assembly routines: One for the preconditioner matrix of
1748 * the Stokes system, one for the Stokes matrix and right hand side, one for
1749 * the temperature matrices and one for the right hand side of the
1750 * temperature equation. We here organize the scratch arrays and CopyData
1751 * objects for each of those four assembly components using a
1752 * <code>struct</code> environment (since we consider these as temporary
1753 * objects we pass around, rather than classes that implement functionality
1754 * of their own, though this is a more subjective point of view to
1755 * distinguish between <code>struct</code>s and <code>class</code>es).
1756 *
1757
1758 *
1759 * Regarding the Scratch objects, each struct is equipped with a constructor
1760 * that creates an @ref FEValues object using the @ref FiniteElement,
1761 * Quadrature, @ref Mapping (which describes the interpolation of curved
1762 * boundaries), and @ref UpdateFlags instances. Moreover, we manually
1763 * implement a copy constructor (since the FEValues class is not copyable by
1764 * itself), and provide some additional vector fields that are used to hold
1765 * intermediate data during the computation of local contributions.
1766 *
1767
1768 *
1769 * Let us start with the scratch arrays and, specifically, the one used for
1770 * assembly of the Stokes preconditioner:
1771 *
1772 * @code
1773 *   namespace Assembly
1774 *   {
1775 *   namespace Scratch
1776 *   {
1777 *   template <int dim>
1778 *   struct StokesPreconditioner
1779 *   {
1780 *   StokesPreconditioner(const FiniteElement<dim> &stokes_fe,
1781 *   const Quadrature<dim> &stokes_quadrature,
1782 *   const Mapping<dim> &mapping,
1783 *   const UpdateFlags update_flags);
1784 *  
1785 *   StokesPreconditioner(const StokesPreconditioner &data);
1786 *  
1787 *  
1788 *   FEValues<dim> stokes_fe_values;
1789 *  
1790 *   std::vector<Tensor<2, dim>> grad_phi_u;
1791 *   std::vector<double> phi_p;
1792 *   };
1793 *  
1794 *   template <int dim>
1795 *   StokesPreconditioner<dim>::StokesPreconditioner(
1796 *   const FiniteElement<dim> &stokes_fe,
1797 *   const Quadrature<dim> &stokes_quadrature,
1798 *   const Mapping<dim> &mapping,
1799 *   const UpdateFlags update_flags)
1800 *   : stokes_fe_values(mapping, stokes_fe, stokes_quadrature, update_flags)
1801 *   , grad_phi_u(stokes_fe.n_dofs_per_cell())
1802 *   , phi_p(stokes_fe.n_dofs_per_cell())
1803 *   {}
1804 *  
1805 *  
1806 *  
1807 *   template <int dim>
1808 *   StokesPreconditioner<dim>::StokesPreconditioner(
1809 *   const StokesPreconditioner &scratch)
1810 *   : stokes_fe_values(scratch.stokes_fe_values.get_mapping(),
1811 *   scratch.stokes_fe_values.get_fe(),
1812 *   scratch.stokes_fe_values.get_quadrature(),
1813 *   scratch.stokes_fe_values.get_update_flags())
1814 *   , grad_phi_u(scratch.grad_phi_u)
1815 *   , phi_p(scratch.phi_p)
1816 *   {}
1817 *  
1818 *  
1819 *  
1820 * @endcode
1821 *
1822 * The next one is the scratch object used for the assembly of the full
1823 * Stokes system. Observe that we derive the StokesSystem scratch class
1824 * from the StokesPreconditioner class above. We do this because all the
1825 * objects that are necessary for the assembly of the preconditioner are
1826 * also needed for the actual matrix system and right hand side, plus
1827 * some extra data. This makes the program more compact. Note also that
1828 * the assembly of the Stokes system and the temperature right hand side
1829 * further down requires data from temperature and velocity,
1830 * respectively, so we actually need two FEValues objects for those two
1831 * cases.
1832 *
1833 * @code
1834 *   template <int dim>
1835 *   struct StokesSystem : public StokesPreconditioner<dim>
1836 *   {
1837 *   StokesSystem(const FiniteElement<dim> &stokes_fe,
1838 *   const Mapping<dim> &mapping,
1839 *   const Quadrature<dim> &stokes_quadrature,
1840 *   const UpdateFlags stokes_update_flags,
1841 *   const FiniteElement<dim> &temperature_fe,
1842 *   const UpdateFlags temperature_update_flags);
1843 *  
1844 *   StokesSystem(const StokesSystem<dim> &data);
1845 *  
1846 *  
1847 *   FEValues<dim> temperature_fe_values;
1848 *  
1849 *   std::vector<Tensor<1, dim>> phi_u;
1850 *   std::vector<SymmetricTensor<2, dim>> grads_phi_u;
1851 *   std::vector<double> div_phi_u;
1852 *  
1853 *   std::vector<double> old_temperature_values;
1854 *   };
1855 *  
1856 *  
1857 *   template <int dim>
1858 *   StokesSystem<dim>::StokesSystem(
1859 *   const FiniteElement<dim> &stokes_fe,
1860 *   const Mapping<dim> &mapping,
1861 *   const Quadrature<dim> &stokes_quadrature,
1862 *   const UpdateFlags stokes_update_flags,
1863 *   const FiniteElement<dim> &temperature_fe,
1864 *   const UpdateFlags temperature_update_flags)
1865 *   : StokesPreconditioner<dim>(stokes_fe,
1866 *   stokes_quadrature,
1867 *   mapping,
1868 *   stokes_update_flags)
1869 *   , temperature_fe_values(mapping,
1870 *   temperature_fe,
1871 *   stokes_quadrature,
1872 *   temperature_update_flags)
1873 *   , phi_u(stokes_fe.n_dofs_per_cell())
1874 *   , grads_phi_u(stokes_fe.n_dofs_per_cell())
1875 *   , div_phi_u(stokes_fe.n_dofs_per_cell())
1876 *   , old_temperature_values(stokes_quadrature.size())
1877 *   {}
1878 *  
1879 *  
1880 *   template <int dim>
1881 *   StokesSystem<dim>::StokesSystem(const StokesSystem<dim> &scratch)
1882 *   : StokesPreconditioner<dim>(scratch)
1883 *   , temperature_fe_values(
1884 *   scratch.temperature_fe_values.get_mapping(),
1885 *   scratch.temperature_fe_values.get_fe(),
1886 *   scratch.temperature_fe_values.get_quadrature(),
1887 *   scratch.temperature_fe_values.get_update_flags())
1888 *   , phi_u(scratch.phi_u)
1889 *   , grads_phi_u(scratch.grads_phi_u)
1890 *   , div_phi_u(scratch.div_phi_u)
1891 *   , old_temperature_values(scratch.old_temperature_values)
1892 *   {}
1893 *  
1894 *  
1895 * @endcode
1896 *
1897 * After defining the objects used in the assembly of the Stokes system,
1898 * we do the same for the assembly of the matrices necessary for the
1899 * temperature system. The general structure is very similar:
1900 *
1901 * @code
1902 *   template <int dim>
1903 *   struct TemperatureMatrix
1904 *   {
1905 *   TemperatureMatrix(const FiniteElement<dim> &temperature_fe,
1906 *   const Mapping<dim> &mapping,
1907 *   const Quadrature<dim> &temperature_quadrature);
1908 *  
1909 *   TemperatureMatrix(const TemperatureMatrix &data);
1910 *  
1911 *  
1912 *   FEValues<dim> temperature_fe_values;
1913 *  
1914 *   std::vector<double> phi_T;
1915 *   std::vector<Tensor<1, dim>> grad_phi_T;
1916 *   };
1917 *  
1918 *  
1919 *   template <int dim>
1920 *   TemperatureMatrix<dim>::TemperatureMatrix(
1921 *   const FiniteElement<dim> &temperature_fe,
1922 *   const Mapping<dim> &mapping,
1923 *   const Quadrature<dim> &temperature_quadrature)
1924 *   : temperature_fe_values(mapping,
1925 *   temperature_fe,
1926 *   temperature_quadrature,
1927 *   update_values | update_gradients |
1928 *   update_JxW_values)
1929 *   , phi_T(temperature_fe.n_dofs_per_cell())
1930 *   , grad_phi_T(temperature_fe.n_dofs_per_cell())
1931 *   {}
1932 *  
1933 *  
1934 *   template <int dim>
1935 *   TemperatureMatrix<dim>::TemperatureMatrix(
1936 *   const TemperatureMatrix &scratch)
1937 *   : temperature_fe_values(
1938 *   scratch.temperature_fe_values.get_mapping(),
1939 *   scratch.temperature_fe_values.get_fe(),
1940 *   scratch.temperature_fe_values.get_quadrature(),
1941 *   scratch.temperature_fe_values.get_update_flags())
1942 *   , phi_T(scratch.phi_T)
1943 *   , grad_phi_T(scratch.grad_phi_T)
1944 *   {}
1945 *  
1946 *  
1947 * @endcode
1948 *
1949 * The final scratch object is used in the assembly of the right hand
1950 * side of the temperature system. This object is significantly larger
1951 * than the ones above because a lot more quantities enter the
1952 * computation of the right hand side of the temperature equation. In
1953 * particular, the temperature values and gradients of the previous two
1954 * time steps need to be evaluated at the quadrature points, as well as
1955 * the velocities and the strain rates (i.e. the symmetric gradients of
1956 * the velocity) that enter the right hand side as friction heating
1957 * terms. Despite the number of terms, the following should be rather
1958 * self explanatory:
1959 *
1960 * @code
1961 *   template <int dim>
1962 *   struct TemperatureRHS
1963 *   {
1964 *   TemperatureRHS(const FiniteElement<dim> &temperature_fe,
1965 *   const FiniteElement<dim> &stokes_fe,
1966 *   const Mapping<dim> &mapping,
1967 *   const Quadrature<dim> &quadrature);
1968 *  
1969 *   TemperatureRHS(const TemperatureRHS &data);
1970 *  
1971 *  
1972 *   FEValues<dim> temperature_fe_values;
1973 *   FEValues<dim> stokes_fe_values;
1974 *  
1975 *   std::vector<double> phi_T;
1976 *   std::vector<Tensor<1, dim>> grad_phi_T;
1977 *  
1978 *   std::vector<Tensor<1, dim>> old_velocity_values;
1979 *   std::vector<Tensor<1, dim>> old_old_velocity_values;
1980 *  
1981 *   std::vector<SymmetricTensor<2, dim>> old_strain_rates;
1982 *   std::vector<SymmetricTensor<2, dim>> old_old_strain_rates;
1983 *  
1984 *   std::vector<double> old_temperature_values;
1985 *   std::vector<double> old_old_temperature_values;
1986 *   std::vector<Tensor<1, dim>> old_temperature_grads;
1987 *   std::vector<Tensor<1, dim>> old_old_temperature_grads;
1988 *   std::vector<double> old_temperature_laplacians;
1989 *   std::vector<double> old_old_temperature_laplacians;
1990 *   };
1991 *  
1992 *  
1993 *   template <int dim>
1994 *   TemperatureRHS<dim>::TemperatureRHS(
1995 *   const FiniteElement<dim> &temperature_fe,
1996 *   const FiniteElement<dim> &stokes_fe,
1997 *   const Mapping<dim> &mapping,
1998 *   const Quadrature<dim> &quadrature)
1999 *   : temperature_fe_values(mapping,
2000 *   temperature_fe,
2001 *   quadrature,
2002 *   update_values | update_gradients |
2003 *   update_hessians | update_quadrature_points |
2004 *   update_JxW_values)
2005 *   , stokes_fe_values(mapping,
2006 *   stokes_fe,
2007 *   quadrature,
2008 *   update_values | update_gradients)
2009 *   , phi_T(temperature_fe.n_dofs_per_cell())
2010 *   , grad_phi_T(temperature_fe.n_dofs_per_cell())
2011 *   ,
2012 *  
2013 *   old_velocity_values(quadrature.size())
2014 *   , old_old_velocity_values(quadrature.size())
2015 *   , old_strain_rates(quadrature.size())
2016 *   , old_old_strain_rates(quadrature.size())
2017 *   ,
2018 *  
2019 *   old_temperature_values(quadrature.size())
2020 *   , old_old_temperature_values(quadrature.size())
2021 *   , old_temperature_grads(quadrature.size())
2022 *   , old_old_temperature_grads(quadrature.size())
2023 *   , old_temperature_laplacians(quadrature.size())
2024 *   , old_old_temperature_laplacians(quadrature.size())
2025 *   {}
2026 *  
2027 *  
2028 *   template <int dim>
2029 *   TemperatureRHS<dim>::TemperatureRHS(const TemperatureRHS &scratch)
2030 *   : temperature_fe_values(
2031 *   scratch.temperature_fe_values.get_mapping(),
2032 *   scratch.temperature_fe_values.get_fe(),
2033 *   scratch.temperature_fe_values.get_quadrature(),
2034 *   scratch.temperature_fe_values.get_update_flags())
2035 *   , stokes_fe_values(scratch.stokes_fe_values.get_mapping(),
2036 *   scratch.stokes_fe_values.get_fe(),
2037 *   scratch.stokes_fe_values.get_quadrature(),
2038 *   scratch.stokes_fe_values.get_update_flags())
2039 *   , phi_T(scratch.phi_T)
2040 *   , grad_phi_T(scratch.grad_phi_T)
2041 *   ,
2042 *  
2043 *   old_velocity_values(scratch.old_velocity_values)
2044 *   , old_old_velocity_values(scratch.old_old_velocity_values)
2045 *   , old_strain_rates(scratch.old_strain_rates)
2046 *   , old_old_strain_rates(scratch.old_old_strain_rates)
2047 *   ,
2048 *  
2049 *   old_temperature_values(scratch.old_temperature_values)
2050 *   , old_old_temperature_values(scratch.old_old_temperature_values)
2051 *   , old_temperature_grads(scratch.old_temperature_grads)
2052 *   , old_old_temperature_grads(scratch.old_old_temperature_grads)
2053 *   , old_temperature_laplacians(scratch.old_temperature_laplacians)
2054 *   , old_old_temperature_laplacians(scratch.old_old_temperature_laplacians)
2055 *   {}
2056 *   } // namespace Scratch
2057 *  
2058 *  
2059 * @endcode
2060 *
2061 * The CopyData objects are even simpler than the Scratch objects as all
2062 * they have to do is to store the results of local computations until
2063 * they can be copied into the global matrix or vector objects. These
2064 * structures therefore only need to provide a constructor, a copy
2065 * operation, and some arrays for local matrix, local vectors and the
2066 * relation between local and global degrees of freedom (a.k.a.
2067 * <code>local_dof_indices</code>). Again, we have one such structure for
2068 * each of the four operations we will parallelize using the WorkStream
2069 * class:
2070 *
2071 * @code
2072 *   namespace CopyData
2073 *   {
2074 *   template <int dim>
2075 *   struct StokesPreconditioner
2076 *   {
2077 *   StokesPreconditioner(const FiniteElement<dim> &stokes_fe);
2078 *   StokesPreconditioner(const StokesPreconditioner &data);
2079 *   StokesPreconditioner &operator=(const StokesPreconditioner &) = default;
2080 *  
2081 *   FullMatrix<double> local_matrix;
2082 *   std::vector<types::global_dof_index> local_dof_indices;
2083 *   };
2084 *  
2085 *   template <int dim>
2086 *   StokesPreconditioner<dim>::StokesPreconditioner(
2087 *   const FiniteElement<dim> &stokes_fe)
2088 *   : local_matrix(stokes_fe.n_dofs_per_cell(), stokes_fe.n_dofs_per_cell())
2089 *   , local_dof_indices(stokes_fe.n_dofs_per_cell())
2090 *   {}
2091 *  
2092 *   template <int dim>
2093 *   StokesPreconditioner<dim>::StokesPreconditioner(
2094 *   const StokesPreconditioner &data)
2095 *   : local_matrix(data.local_matrix)
2096 *   , local_dof_indices(data.local_dof_indices)
2097 *   {}
2098 *  
2099 *  
2100 *  
2101 *   template <int dim>
2102 *   struct StokesSystem : public StokesPreconditioner<dim>
2103 *   {
2104 *   StokesSystem(const FiniteElement<dim> &stokes_fe);
2105 *  
2106 *   Vector<double> local_rhs;
2107 *   };
2108 *  
2109 *   template <int dim>
2110 *   StokesSystem<dim>::StokesSystem(const FiniteElement<dim> &stokes_fe)
2111 *   : StokesPreconditioner<dim>(stokes_fe)
2112 *   , local_rhs(stokes_fe.n_dofs_per_cell())
2113 *   {}
2114 *  
2115 *  
2116 *  
2117 *   template <int dim>
2118 *   struct TemperatureMatrix
2119 *   {
2120 *   TemperatureMatrix(const FiniteElement<dim> &temperature_fe);
2121 *  
2122 *   FullMatrix<double> local_mass_matrix;
2123 *   FullMatrix<double> local_stiffness_matrix;
2124 *   std::vector<types::global_dof_index> local_dof_indices;
2125 *   };
2126 *  
2127 *   template <int dim>
2128 *   TemperatureMatrix<dim>::TemperatureMatrix(
2129 *   const FiniteElement<dim> &temperature_fe)
2130 *   : local_mass_matrix(temperature_fe.n_dofs_per_cell(),
2131 *   temperature_fe.n_dofs_per_cell())
2132 *   , local_stiffness_matrix(temperature_fe.n_dofs_per_cell(),
2133 *   temperature_fe.n_dofs_per_cell())
2134 *   , local_dof_indices(temperature_fe.n_dofs_per_cell())
2135 *   {}
2136 *  
2137 *  
2138 *  
2139 *   template <int dim>
2140 *   struct TemperatureRHS
2141 *   {
2142 *   TemperatureRHS(const FiniteElement<dim> &temperature_fe);
2143 *  
2144 *   Vector<double> local_rhs;
2145 *   std::vector<types::global_dof_index> local_dof_indices;
2146 *   FullMatrix<double> matrix_for_bc;
2147 *   };
2148 *  
2149 *   template <int dim>
2150 *   TemperatureRHS<dim>::TemperatureRHS(
2151 *   const FiniteElement<dim> &temperature_fe)
2152 *   : local_rhs(temperature_fe.n_dofs_per_cell())
2153 *   , local_dof_indices(temperature_fe.n_dofs_per_cell())
2154 *   , matrix_for_bc(temperature_fe.n_dofs_per_cell(),
2155 *   temperature_fe.n_dofs_per_cell())
2156 *   {}
2157 *   } // namespace CopyData
2158 *   } // namespace Assembly
2159 *  
2160 *  
2161 *  
2162 * @endcode
2163 *
2164 *
2165 * <a name="step_32-ThecodeBoussinesqFlowProblemcodeclasstemplate"></a>
2166 * <h3>The <code>BoussinesqFlowProblem</code> class template</h3>
2167 *
2168
2169 *
2170 * This is the declaration of the main class. It is very similar to @ref step_31 "step-31"
2171 * but there are a number differences we will comment on below.
2172 *
2173
2174 *
2175 * The top of the class is essentially the same as in @ref step_31 "step-31", listing the
2176 * public methods and a set of private functions that do the heavy
2177 * lifting. Compared to @ref step_31 "step-31" there are only two additions to this
2178 * section: the function <code>get_cfl_number()</code> that computes the
2179 * maximum CFL number over all cells which we then compute the global time
2180 * step from, and the function <code>get_entropy_variation()</code> that is
2181 * used in the computation of the entropy stabilization. It is akin to the
2182 * <code>get_extrapolated_temperature_range()</code> we have used in @ref step_31 "step-31"
2183 * for this purpose, but works on the entropy instead of the temperature
2184 * instead.
2185 *
2186 * @code
2187 *   template <int dim>
2188 *   class BoussinesqFlowProblem
2189 *   {
2190 *   public:
2191 *   struct Parameters;
2192 *   BoussinesqFlowProblem(Parameters &parameters);
2193 *   void run();
2194 *  
2195 *   private:
2196 *   void setup_dofs();
2197 *   void assemble_stokes_preconditioner();
2198 *   void build_stokes_preconditioner();
2199 *   void assemble_stokes_system();
2200 *   void assemble_temperature_matrix();
2201 *   void assemble_temperature_system(const double maximal_velocity);
2202 *   double get_maximal_velocity() const;
2203 *   double get_cfl_number() const;
2204 *   double get_entropy_variation(const double average_temperature) const;
2205 *   std::pair<double, double> get_extrapolated_temperature_range() const;
2206 *   void solve();
2207 *   void output_results();
2208 *   void refine_mesh(const unsigned int max_grid_level);
2209 *  
2210 *   double compute_viscosity(
2211 *   const std::vector<double> &old_temperature,
2212 *   const std::vector<double> &old_old_temperature,
2213 *   const std::vector<Tensor<1, dim>> &old_temperature_grads,
2214 *   const std::vector<Tensor<1, dim>> &old_old_temperature_grads,
2215 *   const std::vector<double> &old_temperature_laplacians,
2216 *   const std::vector<double> &old_old_temperature_laplacians,
2217 *   const std::vector<Tensor<1, dim>> &old_velocity_values,
2218 *   const std::vector<Tensor<1, dim>> &old_old_velocity_values,
2219 *   const std::vector<SymmetricTensor<2, dim>> &old_strain_rates,
2220 *   const std::vector<SymmetricTensor<2, dim>> &old_old_strain_rates,
2221 *   const double global_u_infty,
2222 *   const double global_T_variation,
2223 *   const double average_temperature,
2224 *   const double global_entropy_variation,
2225 *   const double cell_diameter) const;
2226 *  
2227 *   public:
2228 * @endcode
2229 *
2230 * The first significant new component is the definition of a struct for
2231 * the parameters according to the discussion in the introduction. This
2232 * structure is initialized by reading from a parameter file during
2233 * construction of this object.
2234 *
2235 * @code
2236 *   struct Parameters
2237 *   {
2238 *   Parameters(const std::string &parameter_filename);
2239 *  
2240 *   static void declare_parameters(ParameterHandler &prm);
2241 *   void parse_parameters(ParameterHandler &prm);
2242 *  
2243 *   double end_time;
2244 *  
2245 *   unsigned int initial_global_refinement;
2246 *   unsigned int initial_adaptive_refinement;
2247 *  
2248 *   bool generate_graphical_output;
2249 *   unsigned int graphical_output_interval;
2250 *  
2251 *   unsigned int adaptive_refinement_interval;
2252 *  
2253 *   double stabilization_alpha;
2254 *   double stabilization_c_R;
2255 *   double stabilization_beta;
2256 *  
2257 *   unsigned int stokes_velocity_degree;
2258 *   bool use_locally_conservative_discretization;
2259 *  
2260 *   unsigned int temperature_degree;
2261 *   };
2262 *  
2263 *   private:
2264 *   Parameters &parameters;
2265 *  
2266 * @endcode
2267 *
2268 * The <code>pcout</code> (for <i>%parallel <code>std::cout</code></i>)
2269 * object is used to simplify writing output: each MPI process can use
2270 * this to generate output as usual, but since each of these processes
2271 * will (hopefully) produce the same output it will just be replicated
2272 * many times over; with the ConditionalOStream class, only the output
2273 * generated by one MPI process will actually be printed to screen,
2274 * whereas the output by all the other threads will simply be forgotten.
2275 *
2276 * @code
2277 *   ConditionalOStream pcout;
2278 *  
2279 * @endcode
2280 *
2281 * The following member variables will then again be similar to those in
2282 * @ref step_31 "step-31" (and to other tutorial programs). As mentioned in the
2283 * introduction, we fully distribute computations, so we will have to use
2284 * the parallel::distributed::Triangulation class (see @ref step_40 "step-40") but the
2285 * remainder of these variables is rather standard with two exceptions:
2286 *
2287
2288 *
2289 * - The <code>mapping</code> variable is used to denote a higher-order
2290 * polynomial mapping. As mentioned in the introduction, we use this
2291 * mapping when forming integrals through quadrature for all cells.
2292 *
2293
2294 *
2295 * - In a bit of naming confusion, you will notice below that some of the
2296 * variables from namespace TrilinosWrappers are taken from namespace
2297 * TrilinosWrappers::MPI (such as the right hand side vectors) whereas
2298 * others are not (such as the various matrices). This is due to legacy
2299 * reasons. We will frequently have to query velocities
2300 * and temperatures at arbitrary quadrature points; consequently, rather
2301 * than importing ghost information of a vector whenever we need access
2302 * to degrees of freedom that are relevant locally but owned by another
2303 * processor, we solve linear systems in %parallel but then immediately
2304 * initialize a vector including ghost entries of the solution for further
2305 * processing. The various <code>*_solution</code> vectors are therefore
2306 * filled immediately after solving their respective linear system in
2307 * %parallel and will always contain values for all
2308 * @ref GlossLocallyRelevantDof "locally relevant degrees of freedom";
2309 * the fully distributed vectors that we obtain from the solution process
2310 * and that only ever contain the
2311 * @ref GlossLocallyOwnedDof "locally owned degrees of freedom" are
2312 * destroyed immediately after the solution process and after we have
2313 * copied the relevant values into the member variable vectors.
2314 *
2315 * @code
2316 *   parallel::distributed::Triangulation<dim> triangulation;
2317 *   double global_Omega_diameter;
2318 *  
2319 *   const MappingQ<dim> mapping;
2320 *  
2321 *   const FESystem<dim> stokes_fe;
2322 *   DoFHandler<dim> stokes_dof_handler;
2323 *   AffineConstraints<double> stokes_constraints;
2324 *  
2325 *   TrilinosWrappers::BlockSparseMatrix stokes_matrix;
2326 *   TrilinosWrappers::BlockSparseMatrix stokes_preconditioner_matrix;
2327 *  
2328 *   TrilinosWrappers::MPI::BlockVector stokes_solution;
2329 *   TrilinosWrappers::MPI::BlockVector old_stokes_solution;
2330 *   TrilinosWrappers::MPI::BlockVector stokes_rhs;
2331 *  
2332 *  
2333 *   FE_Q<dim> temperature_fe;
2334 *   DoFHandler<dim> temperature_dof_handler;
2335 *   AffineConstraints<double> temperature_constraints;
2336 *  
2337 *   TrilinosWrappers::SparseMatrix temperature_mass_matrix;
2338 *   TrilinosWrappers::SparseMatrix temperature_stiffness_matrix;
2339 *   TrilinosWrappers::SparseMatrix temperature_matrix;
2340 *  
2341 *   TrilinosWrappers::MPI::Vector temperature_solution;
2342 *   TrilinosWrappers::MPI::Vector old_temperature_solution;
2343 *   TrilinosWrappers::MPI::Vector old_old_temperature_solution;
2344 *   TrilinosWrappers::MPI::Vector temperature_rhs;
2345 *  
2346 *  
2347 *   double time_step;
2348 *   double old_time_step;
2349 *   unsigned int timestep_number;
2350 *  
2351 *   std::shared_ptr<TrilinosWrappers::PreconditionAMG> Amg_preconditioner;
2352 *   std::shared_ptr<TrilinosWrappers::PreconditionJacobi> Mp_preconditioner;
2353 *   std::shared_ptr<TrilinosWrappers::PreconditionJacobi> T_preconditioner;
2354 *  
2355 *   bool rebuild_stokes_matrix;
2356 *   bool rebuild_stokes_preconditioner;
2357 *   bool rebuild_temperature_matrices;
2358 *   bool rebuild_temperature_preconditioner;
2359 *  
2360 * @endcode
2361 *
2362 * The next member variable, <code>computing_timer</code> is used to
2363 * conveniently account for compute time spent in certain "sections" of
2364 * the code that are repeatedly entered. For example, we will enter (and
2365 * leave) sections for Stokes matrix assembly and would like to accumulate
2366 * the run time spent in this section over all time steps. Every so many
2367 * time steps as well as at the end of the program (through the destructor
2368 * of the TimerOutput class) we will then produce a nice summary of the
2369 * times spent in the different sections into which we categorize the
2370 * run-time of this program.
2371 *
2372 * @code
2373 *   TimerOutput computing_timer;
2374 *  
2375 * @endcode
2376 *
2377 * After these member variables we have a number of auxiliary functions
2378 * that have been broken out of the ones listed above. Specifically, there
2379 * are first three functions that we call from <code>setup_dofs</code> and
2380 * then the ones that do the assembling of linear systems:
2381 *
2382 * @code
2383 *   void setup_stokes_matrix(
2384 *   const std::vector<IndexSet> &stokes_partitioning,
2385 *   const std::vector<IndexSet> &stokes_relevant_partitioning);
2386 *   void setup_stokes_preconditioner(
2387 *   const std::vector<IndexSet> &stokes_partitioning,
2388 *   const std::vector<IndexSet> &stokes_relevant_partitioning);
2389 *   void setup_temperature_matrices(
2390 *   const IndexSet &temperature_partitioning,
2391 *   const IndexSet &temperature_relevant_partitioning);
2392 *  
2393 *  
2394 * @endcode
2395 *
2396 * Following the @ref MTWorkStream "task-based parallelization" paradigm,
2397 * we split all the assembly routines into two parts: a first part that
2398 * can do all the calculations on a certain cell without taking care of
2399 * other threads, and a second part (which is writing the local data into
2400 * the global matrices and vectors) which can be entered by only one
2401 * thread at a time. In order to implement that, we provide functions for
2402 * each of those two steps for all the four assembly routines that we use
2403 * in this program. The following eight functions do exactly this:
2404 *
2405 * @code
2406 *   void local_assemble_stokes_preconditioner(
2407 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
2408 *   Assembly::Scratch::StokesPreconditioner<dim> &scratch,
2409 *   Assembly::CopyData::StokesPreconditioner<dim> &data);
2410 *  
2411 *   void copy_local_to_global_stokes_preconditioner(
2412 *   const Assembly::CopyData::StokesPreconditioner<dim> &data);
2413 *  
2414 *  
2415 *   void local_assemble_stokes_system(
2416 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
2417 *   Assembly::Scratch::StokesSystem<dim> &scratch,
2418 *   Assembly::CopyData::StokesSystem<dim> &data);
2419 *  
2420 *   void copy_local_to_global_stokes_system(
2421 *   const Assembly::CopyData::StokesSystem<dim> &data);
2422 *  
2423 *  
2424 *   void local_assemble_temperature_matrix(
2425 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
2426 *   Assembly::Scratch::TemperatureMatrix<dim> &scratch,
2427 *   Assembly::CopyData::TemperatureMatrix<dim> &data);
2428 *  
2429 *   void copy_local_to_global_temperature_matrix(
2430 *   const Assembly::CopyData::TemperatureMatrix<dim> &data);
2431 *  
2432 *  
2433 *  
2434 *   void local_assemble_temperature_rhs(
2435 *   const std::pair<double, double> global_T_range,
2436 *   const double global_max_velocity,
2437 *   const double global_entropy_variation,
2438 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
2439 *   Assembly::Scratch::TemperatureRHS<dim> &scratch,
2440 *   Assembly::CopyData::TemperatureRHS<dim> &data);
2441 *  
2442 *   void copy_local_to_global_temperature_rhs(
2443 *   const Assembly::CopyData::TemperatureRHS<dim> &data);
2444 *  
2445 * @endcode
2446 *
2447 * Finally, we forward declare a member class that we will define later on
2448 * and that will be used to compute a number of quantities from our
2449 * solution vectors that we'd like to put into the output files for
2450 * visualization.
2451 *
2452 * @code
2453 *   class Postprocessor;
2454 *   };
2455 *  
2456 *  
2457 * @endcode
2458 *
2459 *
2460 * <a name="step_32-BoussinesqFlowProblemclassimplementation"></a>
2461 * <h3>BoussinesqFlowProblem class implementation</h3>
2462 *
2463
2464 *
2465 *
2466 * <a name="step_32-BoussinesqFlowProblemParameters"></a>
2467 * <h4>BoussinesqFlowProblem::Parameters</h4>
2468 *
2469
2470 *
2471 * Here comes the definition of the parameters for the Stokes problem. We
2472 * allow to set the end time for the simulation, the level of refinements
2473 * (both global and adaptive, which in the sum specify what maximum level
2474 * the cells are allowed to have), and the interval between refinements in
2475 * the time stepping.
2476 *
2477
2478 *
2479 * Then, we let the user specify constants for the stabilization parameters
2480 * (as discussed in the introduction), the polynomial degree for the Stokes
2481 * velocity space, whether to use the locally conservative discretization
2482 * based on FE_DGP elements for the pressure or not (FE_Q elements for
2483 * pressure), and the polynomial degree for the temperature interpolation.
2484 *
2485
2486 *
2487 * The constructor checks for a valid input file (if not, a file with
2488 * default parameters for the quantities is written), and eventually parses
2489 * the parameters.
2490 *
2491 * @code
2492 *   template <int dim>
2493 *   BoussinesqFlowProblem<dim>::Parameters::Parameters(
2494 *   const std::string &parameter_filename)
2495 *   : end_time(1e8)
2496 *   , initial_global_refinement(2)
2497 *   , initial_adaptive_refinement(2)
2498 *   , adaptive_refinement_interval(10)
2499 *   , stabilization_alpha(2)
2500 *   , stabilization_c_R(0.11)
2501 *   , stabilization_beta(0.078)
2502 *   , stokes_velocity_degree(2)
2503 *   , use_locally_conservative_discretization(true)
2504 *   , temperature_degree(2)
2505 *   {
2506 *   ParameterHandler prm;
2507 *   BoussinesqFlowProblem<dim>::Parameters::declare_parameters(prm);
2508 *  
2509 *   std::ifstream parameter_file(parameter_filename);
2510 *  
2511 *   if (!parameter_file)
2512 *   {
2513 *   parameter_file.close();
2514 *  
2515 *   std::ofstream parameter_out(parameter_filename);
2516 *   prm.print_parameters(parameter_out, ParameterHandler::Text);
2517 *  
2518 *   AssertThrow(
2519 *   false,
2520 *   ExcMessage(
2521 *   "Input parameter file <" + parameter_filename +
2522 *   "> not found. Creating a template file of the same name."));
2523 *   }
2524 *  
2525 *   prm.parse_input(parameter_file);
2526 *   parse_parameters(prm);
2527 *   }
2528 *  
2529 *  
2530 *  
2531 * @endcode
2532 *
2533 * Next we have a function that declares the parameters that we expect in
2534 * the input file, together with their data types, default values and a
2535 * description:
2536 *
2537 * @code
2538 *   template <int dim>
2539 *   void BoussinesqFlowProblem<dim>::Parameters::declare_parameters(
2540 *   ParameterHandler &prm)
2541 *   {
2542 *   prm.declare_entry("End time",
2543 *   "1e8",
2544 *   Patterns::Double(0),
2545 *   "The end time of the simulation in years.");
2546 *   prm.declare_entry("Initial global refinement",
2547 *   "2",
2548 *   Patterns::Integer(0),
2549 *   "The number of global refinement steps performed on "
2550 *   "the initial coarse mesh, before the problem is first "
2551 *   "solved there.");
2552 *   prm.declare_entry("Initial adaptive refinement",
2553 *   "2",
2554 *   Patterns::Integer(0),
2555 *   "The number of adaptive refinement steps performed after "
2556 *   "initial global refinement.");
2557 *   prm.declare_entry("Time steps between mesh refinement",
2558 *   "10",
2559 *   Patterns::Integer(1),
2560 *   "The number of time steps after which the mesh is to be "
2561 *   "adapted based on computed error indicators.");
2562 *   prm.declare_entry("Generate graphical output",
2563 *   "false",
2564 *   Patterns::Bool(),
2565 *   "Whether graphical output is to be generated or not. "
2566 *   "You may not want to get graphical output if the number "
2567 *   "of processors is large.");
2568 *   prm.declare_entry("Time steps between graphical output",
2569 *   "50",
2570 *   Patterns::Integer(1),
2571 *   "The number of time steps between each generation of "
2572 *   "graphical output files.");
2573 *  
2574 *   prm.enter_subsection("Stabilization parameters");
2575 *   {
2576 *   prm.declare_entry("alpha",
2577 *   "2",
2578 *   Patterns::Double(1, 2),
2579 *   "The exponent in the entropy viscosity stabilization.");
2580 *   prm.declare_entry("c_R",
2581 *   "0.11",
2582 *   Patterns::Double(0),
2583 *   "The c_R factor in the entropy viscosity "
2584 *   "stabilization.");
2585 *   prm.declare_entry("beta",
2586 *   "0.078",
2587 *   Patterns::Double(0),
2588 *   "The beta factor in the artificial viscosity "
2589 *   "stabilization. An appropriate value for 2d is 0.052 "
2590 *   "and 0.078 for 3d.");
2591 *   }
2592 *   prm.leave_subsection();
2593 *  
2594 *   prm.enter_subsection("Discretization");
2595 *   {
2596 *   prm.declare_entry(
2597 *   "Stokes velocity polynomial degree",
2598 *   "2",
2599 *   Patterns::Integer(1),
2600 *   "The polynomial degree to use for the velocity variables "
2601 *   "in the Stokes system.");
2602 *   prm.declare_entry(
2603 *   "Temperature polynomial degree",
2604 *   "2",
2605 *   Patterns::Integer(1),
2606 *   "The polynomial degree to use for the temperature variable.");
2607 *   prm.declare_entry(
2608 *   "Use locally conservative discretization",
2609 *   "true",
2610 *   Patterns::Bool(),
2611 *   "Whether to use a Stokes discretization that is locally "
2612 *   "conservative at the expense of a larger number of degrees "
2613 *   "of freedom, or to go with a cheaper discretization "
2614 *   "that does not locally conserve mass (although it is "
2615 *   "globally conservative.");
2616 *   }
2617 *   prm.leave_subsection();
2618 *   }
2619 *  
2620 *  
2621 *  
2622 * @endcode
2623 *
2624 * And then we need a function that reads the contents of the
2625 * ParameterHandler object we get by reading the input file and puts the
2626 * results into variables that store the values of the parameters we have
2627 * previously declared:
2628 *
2629 * @code
2630 *   template <int dim>
2631 *   void BoussinesqFlowProblem<dim>::Parameters::parse_parameters(
2632 *   ParameterHandler &prm)
2633 *   {
2634 *   end_time = prm.get_double("End time");
2635 *   initial_global_refinement = prm.get_integer("Initial global refinement");
2636 *   initial_adaptive_refinement =
2637 *   prm.get_integer("Initial adaptive refinement");
2638 *  
2639 *   adaptive_refinement_interval =
2640 *   prm.get_integer("Time steps between mesh refinement");
2641 *  
2642 *   generate_graphical_output = prm.get_bool("Generate graphical output");
2643 *   graphical_output_interval =
2644 *   prm.get_integer("Time steps between graphical output");
2645 *  
2646 *   prm.enter_subsection("Stabilization parameters");
2647 *   {
2648 *   stabilization_alpha = prm.get_double("alpha");
2649 *   stabilization_c_R = prm.get_double("c_R");
2650 *   stabilization_beta = prm.get_double("beta");
2651 *   }
2652 *   prm.leave_subsection();
2653 *  
2654 *   prm.enter_subsection("Discretization");
2655 *   {
2656 *   stokes_velocity_degree =
2657 *   prm.get_integer("Stokes velocity polynomial degree");
2658 *   temperature_degree = prm.get_integer("Temperature polynomial degree");
2659 *   use_locally_conservative_discretization =
2660 *   prm.get_bool("Use locally conservative discretization");
2661 *   }
2662 *   prm.leave_subsection();
2663 *   }
2664 *  
2665 *  
2666 *  
2667 * @endcode
2668 *
2669 *
2670 * <a name="step_32-BoussinesqFlowProblemBoussinesqFlowProblem"></a>
2671 * <h4>BoussinesqFlowProblem::BoussinesqFlowProblem</h4>
2672 *
2673
2674 *
2675 * The constructor of the problem is very similar to the constructor in
2676 * @ref step_31 "step-31". What is different is the %parallel communication: Trilinos uses
2677 * a message passing interface (MPI) for data distribution. When entering
2678 * the BoussinesqFlowProblem class, we have to decide how the parallelization
2679 * is to be done. We choose a rather simple strategy and let all processors
2680 * that are running the program work together, specified by the communicator
2681 * <code>MPI_COMM_WORLD</code>. Next, we create the output stream (as we
2682 * already did in @ref step_18 "step-18") that only generates output on the first MPI
2683 * process and is completely forgetful on all others. The implementation of
2684 * this idea is to check the process number when <code>pcout</code> gets a
2685 * true argument, and it uses the <code>std::cout</code> stream for
2686 * output. If we are one processor five, for instance, then we will give a
2687 * <code>false</code> argument to <code>pcout</code>, which means that the
2688 * output of that processor will not be printed. With the exception of the
2689 * mapping object (for which we use polynomials of degree 4) all but the
2690 * final member variable are exactly the same as in @ref step_31 "step-31".
2691 *
2692
2693 *
2694 * This final object, the TimerOutput object, is then told to restrict
2695 * output to the <code>pcout</code> stream (processor 0), and then we
2696 * specify that we want to get a summary table at the end of the program
2697 * which shows us wallclock times (as opposed to CPU times). We will
2698 * manually also request intermediate summaries every so many time steps in
2699 * the <code>run()</code> function below.
2700 *
2701 * @code
2702 *   template <int dim>
2703 *   BoussinesqFlowProblem<dim>::BoussinesqFlowProblem(Parameters &parameters_)
2704 *   : parameters(parameters_)
2705 *   , pcout(std::cout, (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0))
2706 *   ,
2707 *  
2708 *   triangulation(MPI_COMM_WORLD,
2712 *   ,
2713 *  
2714 *   global_Omega_diameter(0.)
2715 *   ,
2716 *  
2717 *   mapping(4)
2718 *   ,
2719 *  
2720 *   stokes_fe(FE_Q<dim>(parameters.stokes_velocity_degree) ^ dim,
2721 *   (parameters.use_locally_conservative_discretization ?
2722 *   static_cast<const FiniteElement<dim> &>(
2723 *   FE_DGP<dim>(parameters.stokes_velocity_degree - 1)) :
2724 *   static_cast<const FiniteElement<dim> &>(
2725 *   FE_Q<dim>(parameters.stokes_velocity_degree - 1))))
2726 *   ,
2727 *  
2728 *   stokes_dof_handler(triangulation)
2729 *   ,
2730 *  
2731 *   temperature_fe(parameters.temperature_degree)
2732 *   , temperature_dof_handler(triangulation)
2733 *   ,
2734 *  
2735 *   time_step(0)
2736 *   , old_time_step(0)
2737 *   , timestep_number(0)
2738 *   , rebuild_stokes_matrix(true)
2739 *   , rebuild_stokes_preconditioner(true)
2740 *   , rebuild_temperature_matrices(true)
2741 *   , rebuild_temperature_preconditioner(true)
2742 *   ,
2743 *  
2744 *   computing_timer(MPI_COMM_WORLD,
2745 *   pcout,
2746 *   TimerOutput::summary,
2747 *   TimerOutput::wall_times)
2748 *   {}
2749 *  
2750 *  
2751 *  
2752 * @endcode
2753 *
2754 *
2755 * <a name="step_32-TheBoussinesqFlowProblemhelperfunctions"></a>
2756 * <h4>The BoussinesqFlowProblem helper functions</h4>
2757 *
2758 * <a name="step_32-BoussinesqFlowProblemget_maximal_velocity"></a>
2759 * <h5>BoussinesqFlowProblem::get_maximal_velocity</h5>
2760 *
2761
2762 *
2763 * Except for two small details, the function to compute the global maximum
2764 * of the velocity is the same as in @ref step_31 "step-31". The first detail is actually
2765 * common to all functions that implement loops over all cells in the
2766 * triangulation: When operating in %parallel, each processor can only work
2767 * on a chunk of cells since each processor only has a certain part of the
2768 * entire triangulation. This chunk of cells that we want to work on is
2769 * identified via a so-called <code>subdomain_id</code>, as we also did in
2770 * @ref step_18 "step-18". All we need to change is hence to perform the cell-related
2771 * operations only on cells that are owned by the current process (as
2772 * opposed to ghost or artificial cells), i.e. for which the subdomain id
2773 * equals the number of the process ID. Since this is a commonly used
2774 * operation, there is a shortcut for this operation: we can ask whether the
2775 * cell is owned by the current processor using
2776 * <code>cell-@>is_locally_owned()</code>.
2777 *
2778
2779 *
2780 * The second difference is the way we calculate the maximum value. Before,
2781 * we could simply have a <code>double</code> variable that we checked
2782 * against on each quadrature point for each cell. Now, we have to be a bit
2783 * more careful since each processor only operates on a subset of
2784 * cells. What we do is to first let each processor calculate the maximum
2785 * among its cells, and then do a global communication operation
2786 * <code>Utilities::MPI::max</code> that computes the maximum value among
2787 * all the maximum values of the individual processors. MPI provides such a
2788 * call, but it's even simpler to use the respective function in namespace
2789 * Utilities::MPI using the MPI communicator object since that will do the
2790 * right thing even if we work without MPI and on a single machine only. The
2791 * call to <code>Utilities::MPI::max</code> needs two arguments, namely the
2792 * local maximum (input) and the MPI communicator, which is MPI_COMM_WORLD
2793 * in this example.
2794 *
2795 * @code
2796 *   template <int dim>
2797 *   double BoussinesqFlowProblem<dim>::get_maximal_velocity() const
2798 *   {
2799 *   const QIterated<dim> quadrature_formula(QTrapezoid<1>(),
2800 *   parameters.stokes_velocity_degree);
2801 *   const unsigned int n_q_points = quadrature_formula.size();
2802 *  
2803 *   FEValues<dim> fe_values(mapping,
2804 *   stokes_fe,
2805 *   quadrature_formula,
2806 *   update_values);
2807 *   std::vector<Tensor<1, dim>> velocity_values(n_q_points);
2808 *  
2809 *   const FEValuesExtractors::Vector velocities(0);
2810 *  
2811 *   double max_local_velocity = 0;
2812 *  
2813 *   for (const auto &cell : stokes_dof_handler.active_cell_iterators())
2814 *   if (cell->is_locally_owned())
2815 *   {
2816 *   fe_values.reinit(cell);
2817 *   fe_values[velocities].get_function_values(stokes_solution,
2818 *   velocity_values);
2819 *  
2820 *   for (unsigned int q = 0; q < n_q_points; ++q)
2821 *   max_local_velocity =
2822 *   std::max(max_local_velocity, velocity_values[q].norm());
2823 *   }
2824 *  
2825 *   return Utilities::MPI::max(max_local_velocity, MPI_COMM_WORLD);
2826 *   }
2827 *  
2828 *  
2829 * @endcode
2830 *
2831 *
2832 * <a name="step_32-BoussinesqFlowProblemget_cfl_number"></a>
2833 * <h5>BoussinesqFlowProblem::get_cfl_number</h5>
2834 *
2835
2836 *
2837 * The next function does something similar, but we now compute the CFL
2838 * number, i.e., maximal velocity on a cell divided by the cell
2839 * diameter. This number is necessary to determine the time step size, as we
2840 * use a semi-explicit time stepping scheme for the temperature equation
2841 * (see @ref step_31 "step-31" for a discussion). We compute it in the same way as above:
2842 * Compute the local maximum over all locally owned cells, then exchange it
2843 * via MPI to find the global maximum.
2844 *
2845 * @code
2846 *   template <int dim>
2847 *   double BoussinesqFlowProblem<dim>::get_cfl_number() const
2848 *   {
2849 *   const QIterated<dim> quadrature_formula(QTrapezoid<1>(),
2850 *   parameters.stokes_velocity_degree);
2851 *   const unsigned int n_q_points = quadrature_formula.size();
2852 *  
2853 *   FEValues<dim> fe_values(mapping,
2854 *   stokes_fe,
2855 *   quadrature_formula,
2856 *   update_values);
2857 *   std::vector<Tensor<1, dim>> velocity_values(n_q_points);
2858 *  
2859 *   const FEValuesExtractors::Vector velocities(0);
2860 *  
2861 *   double max_local_cfl = 0;
2862 *  
2863 *   for (const auto &cell : stokes_dof_handler.active_cell_iterators())
2864 *   if (cell->is_locally_owned())
2865 *   {
2866 *   fe_values.reinit(cell);
2867 *   fe_values[velocities].get_function_values(stokes_solution,
2868 *   velocity_values);
2869 *  
2870 *   double max_local_velocity = 1e-10;
2871 *   for (unsigned int q = 0; q < n_q_points; ++q)
2872 *   max_local_velocity =
2873 *   std::max(max_local_velocity, velocity_values[q].norm());
2874 *   max_local_cfl =
2875 *   std::max(max_local_cfl, max_local_velocity / cell->diameter());
2876 *   }
2877 *  
2878 *   return Utilities::MPI::max(max_local_cfl, MPI_COMM_WORLD);
2879 *   }
2880 *  
2881 *  
2882 * @endcode
2883 *
2884 *
2885 * <a name="step_32-BoussinesqFlowProblemget_entropy_variation"></a>
2886 * <h5>BoussinesqFlowProblem::get_entropy_variation</h5>
2887 *
2888
2889 *
2890 * Next comes the computation of the global entropy variation
2891 * @f$\|E(T)-\bar{E}(T)\|_\infty@f$ where the entropy @f$E@f$ is defined as
2892 * discussed in the introduction. This is needed for the evaluation of the
2893 * stabilization in the temperature equation as explained in the
2894 * introduction. The entropy variation is actually only needed if we use
2895 * @f$\alpha=2@f$ as a power in the residual computation. The infinity norm is
2896 * computed by the maxima over quadrature points, as usual in discrete
2897 * computations.
2898 *
2899
2900 *
2901 * In order to compute this quantity, we first have to find the
2902 * space-average @f$\bar{E}(T)@f$ and then evaluate the maximum. However, that
2903 * means that we would need to perform two loops. We can avoid the overhead
2904 * by noting that @f$\|E(T)-\bar{E}(T)\|_\infty =
2905 * \max\big(E_{\textrm{max}}(T)-\bar{E}(T),
2906 * \bar{E}(T)-E_{\textrm{min}}(T)\big)@f$, i.e., the maximum out of the
2907 * deviation from the average entropy in positive and negative
2908 * directions. The four quantities we need for the latter formula (maximum
2909 * entropy, minimum entropy, average entropy, area) can all be evaluated in
2910 * the same loop over all cells, so we choose this simpler variant.
2911 *
2912 * @code
2913 *   template <int dim>
2914 *   double BoussinesqFlowProblem<dim>::get_entropy_variation(
2915 *   const double average_temperature) const
2916 *   {
2917 *   if (parameters.stabilization_alpha != 2)
2918 *   return 1.;
2919 *  
2920 *   const QGauss<dim> quadrature_formula(parameters.temperature_degree + 1);
2921 *   const unsigned int n_q_points = quadrature_formula.size();
2922 *  
2923 *   FEValues<dim> fe_values(temperature_fe,
2924 *   quadrature_formula,
2925 *   update_values | update_JxW_values);
2926 *   std::vector<double> old_temperature_values(n_q_points);
2927 *   std::vector<double> old_old_temperature_values(n_q_points);
2928 *  
2929 * @endcode
2930 *
2931 * In the two functions above we computed the maximum of numbers that were
2932 * all non-negative, so we knew that zero was certainly a lower bound. On
2933 * the other hand, here we need to find the maximum deviation from the
2934 * average value, i.e., we will need to know the maximal and minimal
2935 * values of the entropy for which we don't a priori know the sign.
2936 *
2937
2938 *
2939 * To compute it, we can therefore start with the largest and smallest
2940 * possible values we can store in a double precision number: The minimum
2941 * is initialized with a bigger and the maximum with a smaller number than
2942 * any one that is going to appear. We are then guaranteed that these
2943 * numbers will be overwritten in the loop on the first cell or, if this
2944 * processor does not own any cells, in the communication step at the
2945 * latest. The following loop then computes the minimum and maximum local
2946 * entropy as well as keeps track of the area/volume of the part of the
2947 * domain we locally own and the integral over the entropy on it:
2948 *
2949 * @code
2950 *   double min_entropy = std::numeric_limits<double>::max(),
2951 *   max_entropy = -std::numeric_limits<double>::max(), area = 0,
2952 *   entropy_integrated = 0;
2953 *  
2954 *   for (const auto &cell : temperature_dof_handler.active_cell_iterators())
2955 *   if (cell->is_locally_owned())
2956 *   {
2957 *   fe_values.reinit(cell);
2958 *   fe_values.get_function_values(old_temperature_solution,
2959 *   old_temperature_values);
2960 *   fe_values.get_function_values(old_old_temperature_solution,
2961 *   old_old_temperature_values);
2962 *   for (unsigned int q = 0; q < n_q_points; ++q)
2963 *   {
2964 *   const double T =
2965 *   (old_temperature_values[q] + old_old_temperature_values[q]) / 2;
2966 *   const double entropy =
2967 *   ((T - average_temperature) * (T - average_temperature));
2968 *  
2969 *   min_entropy = std::min(min_entropy, entropy);
2970 *   max_entropy = std::max(max_entropy, entropy);
2971 *   area += fe_values.JxW(q);
2972 *   entropy_integrated += fe_values.JxW(q) * entropy;
2973 *   }
2974 *   }
2975 *  
2976 * @endcode
2977 *
2978 * Now we only need to exchange data between processors: we need to sum
2979 * the two integrals (<code>area</code>, <code>entropy_integrated</code>),
2980 * and get the extrema for maximum and minimum. We could do this through
2981 * four different data exchanges, but we can it with two:
2982 * Utilities::MPI::sum also exists in a variant that takes an array of
2983 * values that are all to be summed up. And we can also utilize the
2984 * Utilities::MPI::max function by realizing that forming the minimum over
2985 * the minimal entropies equals forming the negative of the maximum over
2986 * the negative of the minimal entropies; this maximum can then be
2987 * combined with forming the maximum over the maximal entropies.
2988 *
2989 * @code
2990 *   const double local_sums[2] = {entropy_integrated, area},
2991 *   local_maxima[2] = {-min_entropy, max_entropy};
2992 *   double global_sums[2], global_maxima[2];
2993 *  
2994 *   Utilities::MPI::sum(local_sums, MPI_COMM_WORLD, global_sums);
2995 *   Utilities::MPI::max(local_maxima, MPI_COMM_WORLD, global_maxima);
2996 *  
2997 * @endcode
2998 *
2999 * Having computed everything this way, we can then compute the average
3000 * entropy and find the @f$L^\infty@f$ norm by taking the larger of the
3001 * deviation of the maximum or minimum from the average:
3002 *
3003 * @code
3004 *   const double average_entropy = global_sums[0] / global_sums[1];
3005 *   const double entropy_diff = std::max(global_maxima[1] - average_entropy,
3006 *   average_entropy - (-global_maxima[0]));
3007 *   return entropy_diff;
3008 *   }
3009 *  
3010 *  
3011 *  
3012 * @endcode
3013 *
3014 *
3015 * <a name="step_32-BoussinesqFlowProblemget_extrapolated_temperature_range"></a>
3016 * <h5>BoussinesqFlowProblem::get_extrapolated_temperature_range</h5>
3017 *
3018
3019 *
3020 * The next function computes the minimal and maximal value of the
3021 * extrapolated temperature over the entire domain. Again, this is only a
3022 * slightly modified version of the respective function in @ref step_31 "step-31". As in
3023 * the function above, we collect local minima and maxima and then compute
3024 * the global extrema using the same trick as above.
3025 *
3026
3027 *
3028 * As already discussed in @ref step_31 "step-31", the function needs to distinguish
3029 * between the first and all following time steps because it uses a higher
3030 * order temperature extrapolation scheme when at least two previous time
3031 * steps are available.
3032 *
3033 * @code
3034 *   template <int dim>
3035 *   std::pair<double, double>
3036 *   BoussinesqFlowProblem<dim>::get_extrapolated_temperature_range() const
3037 *   {
3038 *   const QIterated<dim> quadrature_formula(QTrapezoid<1>(),
3039 *   parameters.temperature_degree);
3040 *   const unsigned int n_q_points = quadrature_formula.size();
3041 *  
3042 *   FEValues<dim> fe_values(mapping,
3043 *   temperature_fe,
3044 *   quadrature_formula,
3045 *   update_values);
3046 *   std::vector<double> old_temperature_values(n_q_points);
3047 *   std::vector<double> old_old_temperature_values(n_q_points);
3048 *  
3049 *   double min_local_temperature = std::numeric_limits<double>::max(),
3050 *   max_local_temperature = -std::numeric_limits<double>::max();
3051 *  
3052 *   if (timestep_number != 0)
3053 *   {
3054 *   for (const auto &cell : temperature_dof_handler.active_cell_iterators())
3055 *   if (cell->is_locally_owned())
3056 *   {
3057 *   fe_values.reinit(cell);
3058 *   fe_values.get_function_values(old_temperature_solution,
3059 *   old_temperature_values);
3060 *   fe_values.get_function_values(old_old_temperature_solution,
3061 *   old_old_temperature_values);
3062 *  
3063 *   for (unsigned int q = 0; q < n_q_points; ++q)
3064 *   {
3065 *   const double temperature =
3066 *   (1. + time_step / old_time_step) *
3067 *   old_temperature_values[q] -
3068 *   time_step / old_time_step * old_old_temperature_values[q];
3069 *  
3070 *   min_local_temperature =
3071 *   std::min(min_local_temperature, temperature);
3072 *   max_local_temperature =
3073 *   std::max(max_local_temperature, temperature);
3074 *   }
3075 *   }
3076 *   }
3077 *   else
3078 *   {
3079 *   for (const auto &cell : temperature_dof_handler.active_cell_iterators())
3080 *   if (cell->is_locally_owned())
3081 *   {
3082 *   fe_values.reinit(cell);
3083 *   fe_values.get_function_values(old_temperature_solution,
3084 *   old_temperature_values);
3085 *  
3086 *   for (unsigned int q = 0; q < n_q_points; ++q)
3087 *   {
3088 *   const double temperature = old_temperature_values[q];
3089 *  
3090 *   min_local_temperature =
3091 *   std::min(min_local_temperature, temperature);
3092 *   max_local_temperature =
3093 *   std::max(max_local_temperature, temperature);
3094 *   }
3095 *   }
3096 *   }
3097 *  
3098 *   double local_extrema[2] = {-min_local_temperature, max_local_temperature};
3099 *   double global_extrema[2];
3100 *   Utilities::MPI::max(local_extrema, MPI_COMM_WORLD, global_extrema);
3101 *  
3102 *   return std::make_pair(-global_extrema[0], global_extrema[1]);
3103 *   }
3104 *  
3105 *  
3106 * @endcode
3107 *
3108 *
3109 * <a name="step_32-BoussinesqFlowProblemcompute_viscosity"></a>
3110 * <h5>BoussinesqFlowProblem::compute_viscosity</h5>
3111 *
3112
3113 *
3114 * The function that calculates the viscosity is purely local and so needs
3115 * no communication at all. It is mostly the same as in @ref step_31 "step-31" but with an
3116 * updated formulation of the viscosity if @f$\alpha=2@f$ is chosen:
3117 *
3118 * @code
3119 *   template <int dim>
3120 *   double BoussinesqFlowProblem<dim>::compute_viscosity(
3121 *   const std::vector<double> &old_temperature,
3122 *   const std::vector<double> &old_old_temperature,
3123 *   const std::vector<Tensor<1, dim>> &old_temperature_grads,
3124 *   const std::vector<Tensor<1, dim>> &old_old_temperature_grads,
3125 *   const std::vector<double> &old_temperature_laplacians,
3126 *   const std::vector<double> &old_old_temperature_laplacians,
3127 *   const std::vector<Tensor<1, dim>> &old_velocity_values,
3128 *   const std::vector<Tensor<1, dim>> &old_old_velocity_values,
3129 *   const std::vector<SymmetricTensor<2, dim>> &old_strain_rates,
3130 *   const std::vector<SymmetricTensor<2, dim>> &old_old_strain_rates,
3131 *   const double global_u_infty,
3132 *   const double global_T_variation,
3133 *   const double average_temperature,
3134 *   const double global_entropy_variation,
3135 *   const double cell_diameter) const
3136 *   {
3137 *   if (global_u_infty == 0)
3138 *   return 5e-3 * cell_diameter;
3139 *  
3140 *   const unsigned int n_q_points = old_temperature.size();
3141 *  
3142 *   double max_residual = 0;
3143 *   double max_velocity = 0;
3144 *  
3145 *   for (unsigned int q = 0; q < n_q_points; ++q)
3146 *   {
3147 *   const Tensor<1, dim> u =
3148 *   (old_velocity_values[q] + old_old_velocity_values[q]) / 2;
3149 *  
3150 *   const SymmetricTensor<2, dim> strain_rate =
3151 *   (old_strain_rates[q] + old_old_strain_rates[q]) / 2;
3152 *  
3153 *   const double T = (old_temperature[q] + old_old_temperature[q]) / 2;
3154 *   const double dT_dt =
3155 *   (old_temperature[q] - old_old_temperature[q]) / old_time_step;
3156 *   const double u_grad_T =
3157 *   u * (old_temperature_grads[q] + old_old_temperature_grads[q]) / 2;
3158 *  
3159 *   const double kappa_Delta_T =
3160 *   EquationData::kappa *
3161 *   (old_temperature_laplacians[q] + old_old_temperature_laplacians[q]) /
3162 *   2;
3163 *   const double gamma =
3164 *   ((EquationData::radiogenic_heating * EquationData::density(T) +
3165 *   2 * EquationData::eta * strain_rate * strain_rate) /
3166 *   (EquationData::density(T) * EquationData::specific_heat));
3167 *  
3168 *   double residual = std::abs(dT_dt + u_grad_T - kappa_Delta_T - gamma);
3169 *   if (parameters.stabilization_alpha == 2)
3170 *   residual *= std::abs(T - average_temperature);
3171 *  
3172 *   max_residual = std::max(residual, max_residual);
3173 *   max_velocity = std::max(std::sqrt(u * u), max_velocity);
3174 *   }
3175 *  
3176 *   const double max_viscosity =
3177 *   (parameters.stabilization_beta * max_velocity * cell_diameter);
3178 *   if (timestep_number == 0)
3179 *   return max_viscosity;
3180 *   else
3181 *   {
3182 *   Assert(old_time_step > 0, ExcInternalError());
3183 *  
3184 *   double entropy_viscosity;
3185 *   if (parameters.stabilization_alpha == 2)
3186 *   entropy_viscosity =
3187 *   (parameters.stabilization_c_R * cell_diameter * cell_diameter *
3188 *   max_residual / global_entropy_variation);
3189 *   else
3190 *   entropy_viscosity =
3191 *   (parameters.stabilization_c_R * cell_diameter *
3192 *   global_Omega_diameter * max_velocity * max_residual /
3193 *   (global_u_infty * global_T_variation));
3194 *  
3195 *   return std::min(max_viscosity, entropy_viscosity);
3196 *   }
3197 *   }
3198 *  
3199 *  
3200 *  
3201 * @endcode
3202 *
3203 *
3204 * <a name="step_32-TheBoussinesqFlowProblemsetupfunctions"></a>
3205 * <h4>The BoussinesqFlowProblem setup functions</h4>
3206 *
3207
3208 *
3209 * The following three functions set up the Stokes matrix, the matrix used
3210 * for the Stokes preconditioner, and the temperature matrix. The code is
3211 * mostly the same as in @ref step_31 "step-31", but it has been broken out into three
3212 * functions of their own for simplicity.
3213 *
3214
3215 *
3216 * The main functional difference between the code here and that in @ref step_31 "step-31"
3217 * is that the matrices we want to set up are distributed across multiple
3218 * processors. Since we still want to build up the sparsity pattern first
3219 * for efficiency reasons, we could continue to build the <i>entire</i>
3220 * sparsity pattern as a BlockDynamicSparsityPattern, as we did in
3221 * @ref step_31 "step-31". However, that would be inefficient: every processor would build
3222 * the same sparsity pattern, but only initialize a small part of the matrix
3223 * using it. It also violates the principle that every processor should only
3224 * work on those cells it owns (and, if necessary the layer of ghost cells
3225 * around it).
3226 *
3227
3228 *
3229 * Rather, we use an object of type TrilinosWrappers::BlockSparsityPattern,
3230 * which is (obviously) a wrapper around a sparsity pattern object provided
3231 * by Trilinos. The advantage is that the Trilinos sparsity pattern class
3232 * can communicate across multiple processors: if this processor fills in
3233 * all the nonzero entries that result from the cells it owns, and every
3234 * other processor does so as well, then at the end after some MPI
3235 * communication initiated by the <code>compress()</code> call, we will have
3236 * the globally assembled sparsity pattern available with which the global
3237 * matrix can be initialized.
3238 *
3239
3240 *
3241 * There is one important aspect when initializing Trilinos sparsity
3242 * patterns in parallel: In addition to specifying the locally owned rows
3243 * and columns of the matrices via the @p stokes_partitioning index set, we
3244 * also supply information about all the rows we are possibly going to write
3245 * into when assembling on a certain processor. The set of locally relevant
3246 * rows contains all such rows (possibly also a few unnecessary ones, but it
3247 * is difficult to find the exact row indices before actually getting
3248 * indices on all cells and resolving constraints). This additional
3249 * information allows to exactly determine the structure for the
3250 * off-processor data found during assembly. While Trilinos matrices are
3251 * able to collect this information on the fly as well (when initializing
3252 * them from some other reinit method), it is less efficient and leads to
3253 * problems when assembling matrices with multiple threads. In this program,
3254 * we pessimistically assume that only one processor at a time can write
3255 * into the matrix while assembly (whereas the computation is parallel),
3256 * which is fine for Trilinos matrices. In practice, one can do better by
3257 * hinting WorkStream at cells that do not share vertices, allowing for
3258 * parallelism among those cells (see the graph coloring algorithms and
3259 * WorkStream with colored iterators argument). However, that only works
3260 * when only one MPI processor is present because Trilinos' internal data
3261 * structures for accumulating off-processor data on the fly are not thread
3262 * safe. With the initialization presented here, there is no such problem
3263 * and one could safely introduce graph coloring for this algorithm.
3264 *
3265
3266 *
3267 * The only other change we need to make is to tell the
3268 * DoFTools::make_sparsity_pattern() function that it is only supposed to
3269 * work on a subset of cells, namely the ones whose
3270 * <code>subdomain_id</code> equals the number of the current processor, and
3271 * to ignore all other cells.
3272 *
3273
3274 *
3275 * This strategy is replicated across all three of the following functions.
3276 *
3277
3278 *
3279 * Note that Trilinos matrices store the information contained in the
3280 * sparsity patterns, so we can safely release the <code>sp</code> variable
3281 * once the matrix has been given the sparsity structure.
3282 *
3283 * @code
3284 *   template <int dim>
3285 *   void BoussinesqFlowProblem<dim>::setup_stokes_matrix(
3286 *   const std::vector<IndexSet> &stokes_partitioning,
3287 *   const std::vector<IndexSet> &stokes_relevant_partitioning)
3288 *   {
3289 *   stokes_matrix.clear();
3290 *  
3291 *   TrilinosWrappers::BlockSparsityPattern sp(stokes_partitioning,
3292 *   stokes_partitioning,
3293 *   stokes_relevant_partitioning,
3294 *   MPI_COMM_WORLD);
3295 *  
3296 *   Table<2, DoFTools::Coupling> coupling(dim + 1, dim + 1);
3297 *   for (unsigned int c = 0; c < dim + 1; ++c)
3298 *   for (unsigned int d = 0; d < dim + 1; ++d)
3299 *   if (!((c == dim) && (d == dim)))
3300 *   coupling[c][d] = DoFTools::always;
3301 *   else
3302 *   coupling[c][d] = DoFTools::none;
3303 *  
3304 *   DoFTools::make_sparsity_pattern(stokes_dof_handler,
3305 *   coupling,
3306 *   sp,
3307 *   stokes_constraints,
3308 *   false,
3309 *   Utilities::MPI::this_mpi_process(
3310 *   MPI_COMM_WORLD));
3311 *   sp.compress();
3312 *  
3313 *   stokes_matrix.reinit(sp);
3314 *   }
3315 *  
3316 *  
3317 *  
3318 *   template <int dim>
3319 *   void BoussinesqFlowProblem<dim>::setup_stokes_preconditioner(
3320 *   const std::vector<IndexSet> &stokes_partitioning,
3321 *   const std::vector<IndexSet> &stokes_relevant_partitioning)
3322 *   {
3323 *   Amg_preconditioner.reset();
3324 *   Mp_preconditioner.reset();
3325 *  
3326 *   stokes_preconditioner_matrix.clear();
3327 *  
3328 *   TrilinosWrappers::BlockSparsityPattern sp(stokes_partitioning,
3329 *   stokes_partitioning,
3330 *   stokes_relevant_partitioning,
3331 *   MPI_COMM_WORLD);
3332 *  
3333 *   Table<2, DoFTools::Coupling> coupling(dim + 1, dim + 1);
3334 *   for (unsigned int c = 0; c < dim + 1; ++c)
3335 *   for (unsigned int d = 0; d < dim + 1; ++d)
3336 *   if (c == d)
3337 *   coupling[c][d] = DoFTools::always;
3338 *   else
3339 *   coupling[c][d] = DoFTools::none;
3340 *  
3341 *   DoFTools::make_sparsity_pattern(stokes_dof_handler,
3342 *   coupling,
3343 *   sp,
3344 *   stokes_constraints,
3345 *   false,
3346 *   Utilities::MPI::this_mpi_process(
3347 *   MPI_COMM_WORLD));
3348 *   sp.compress();
3349 *  
3350 *   stokes_preconditioner_matrix.reinit(sp);
3351 *   }
3352 *  
3353 *  
3354 *   template <int dim>
3355 *   void BoussinesqFlowProblem<dim>::setup_temperature_matrices(
3356 *   const IndexSet &temperature_partitioner,
3357 *   const IndexSet &temperature_relevant_partitioner)
3358 *   {
3359 *   T_preconditioner.reset();
3360 *   temperature_mass_matrix.clear();
3361 *   temperature_stiffness_matrix.clear();
3362 *   temperature_matrix.clear();
3363 *  
3364 *   TrilinosWrappers::SparsityPattern sp(temperature_partitioner,
3365 *   temperature_partitioner,
3366 *   temperature_relevant_partitioner,
3367 *   MPI_COMM_WORLD);
3368 *   DoFTools::make_sparsity_pattern(temperature_dof_handler,
3369 *   sp,
3370 *   temperature_constraints,
3371 *   false,
3372 *   Utilities::MPI::this_mpi_process(
3373 *   MPI_COMM_WORLD));
3374 *   sp.compress();
3375 *  
3376 *   temperature_matrix.reinit(sp);
3377 *   temperature_mass_matrix.reinit(sp);
3378 *   temperature_stiffness_matrix.reinit(sp);
3379 *   }
3380 *  
3381 *  
3382 *  
3383 * @endcode
3384 *
3385 * The remainder of the setup function (after splitting out the three
3386 * functions above) mostly has to deal with the things we need to do for
3387 * parallelization across processors. Because setting all of this up is a
3388 * significant compute time expense of the program, we put everything we do
3389 * here into a timer group so that we can get summary information about the
3390 * fraction of time spent in this part of the program at its end.
3391 *
3392
3393 *
3394 * At the top as usual we enumerate degrees of freedom and sort them by
3395 * component/block, followed by writing their numbers to the screen from
3396 * processor zero. The DoFHandler::distributed_dofs() function, when applied
3397 * to a parallel::distributed::Triangulation object, sorts degrees of
3398 * freedom in such a way that all degrees of freedom associated with
3399 * subdomain zero come before all those associated with subdomain one,
3400 * etc. For the Stokes part, this entails, however, that velocities and
3401 * pressures become intermixed, but this is trivially solved by sorting
3402 * again by blocks; it is worth noting that this latter operation leaves the
3403 * relative ordering of all velocities and pressures alone, i.e. within the
3404 * velocity block we will still have all those associated with subdomain
3405 * zero before all velocities associated with subdomain one, etc. This is
3406 * important since we store each of the blocks of this matrix distributed
3407 * across all processors and want this to be done in such a way that each
3408 * processor stores that part of the matrix that is roughly equal to the
3409 * degrees of freedom located on those cells that it will actually work on.
3410 *
3411
3412 *
3413 * When printing the numbers of degrees of freedom, note that these numbers
3414 * are going to be large if we use many processors. Consequently, we let the
3415 * stream put a comma separator in between every three digits. The state of
3416 * the stream, using the locale, is saved from before to after this
3417 * operation. While slightly opaque, the code works because the default
3418 * locale (which we get using the constructor call
3419 * <code>std::locale("")</code>) implies printing numbers with a comma
3420 * separator for every third digit (i.e., thousands, millions, billions).
3421 *
3422
3423 *
3424 * In this function as well as many below, we measure how much time
3425 * we spend here and collect that in a section called "Setup dof
3426 * systems" across function invocations. This is done using an
3427 * TimerOutput::Scope object that gets a timer going in the section
3428 * with above name of the `computing_timer` object upon construction
3429 * of the local variable; the timer is stopped again when the
3430 * destructor of the `timing_section` variable is called. This, of
3431 * course, happens either at the end of the function, or if we leave
3432 * the function through a `return` statement or when an exception is
3433 * thrown somewhere -- in other words, whenever we leave this
3434 * function in any way. The use of such "scope" objects therefore
3435 * makes sure that we do not have to manually add code that tells
3436 * the timer to stop at every location where this function may be
3437 * left.
3438 *
3439 * @code
3440 *   template <int dim>
3441 *   void BoussinesqFlowProblem<dim>::setup_dofs()
3442 *   {
3443 *   TimerOutput::Scope timing_section(computing_timer, "Setup dof systems");
3444 *  
3445 *   stokes_dof_handler.distribute_dofs(stokes_fe);
3446 *  
3447 *   std::vector<unsigned int> stokes_sub_blocks(dim + 1, 0);
3448 *   stokes_sub_blocks[dim] = 1;
3449 *   DoFRenumbering::component_wise(stokes_dof_handler, stokes_sub_blocks);
3450 *  
3451 *   temperature_dof_handler.distribute_dofs(temperature_fe);
3452 *  
3453 *   const std::vector<types::global_dof_index> stokes_dofs_per_block =
3454 *   DoFTools::count_dofs_per_fe_block(stokes_dof_handler, stokes_sub_blocks);
3455 *  
3456 *   const types::global_dof_index n_u = stokes_dofs_per_block[0],
3457 *   n_p = stokes_dofs_per_block[1],
3458 *   n_T = temperature_dof_handler.n_dofs();
3459 *  
3460 *   std::locale s = pcout.get_stream().getloc();
3461 *   pcout.get_stream().imbue(std::locale(""));
3462 *   pcout << "Number of active cells: " << triangulation.n_global_active_cells()
3463 *   << " (on " << triangulation.n_levels() << " levels)" << std::endl
3464 *   << "Number of degrees of freedom: " << n_u + n_p + n_T << " (" << n_u
3465 *   << '+' << n_p << '+' << n_T << ')' << std::endl
3466 *   << std::endl;
3467 *   pcout.get_stream().imbue(s);
3468 *  
3469 *  
3470 * @endcode
3471 *
3472 * After this, we have to set up the various partitioners (of type
3473 * <code>IndexSet</code>, see the introduction) that describe which parts
3474 * of each matrix or vector will be stored where, then call the functions
3475 * that actually set up the matrices, and at the end also resize the
3476 * various vectors we keep around in this program.
3477 *
3478
3479 *
3480 *
3481 * @code
3482 *   const IndexSet &stokes_locally_owned_index_set =
3483 *   stokes_dof_handler.locally_owned_dofs();
3484 *   const IndexSet stokes_locally_relevant_set =
3485 *   DoFTools::extract_locally_relevant_dofs(stokes_dof_handler);
3486 *  
3487 *   std::vector<IndexSet> stokes_partitioning;
3488 *   stokes_partitioning.push_back(
3489 *   stokes_locally_owned_index_set.get_view(0, n_u));
3490 *   stokes_partitioning.push_back(
3491 *   stokes_locally_owned_index_set.get_view(n_u, n_u + n_p));
3492 *  
3493 *   std::vector<IndexSet> stokes_relevant_partitioning;
3494 *   stokes_relevant_partitioning.push_back(
3495 *   stokes_locally_relevant_set.get_view(0, n_u));
3496 *   stokes_relevant_partitioning.push_back(
3497 *   stokes_locally_relevant_set.get_view(n_u, n_u + n_p));
3498 *  
3499 *   const IndexSet temperature_partitioning =
3500 *   temperature_dof_handler.locally_owned_dofs();
3501 *   const IndexSet temperature_relevant_partitioning =
3502 *   DoFTools::extract_locally_relevant_dofs(temperature_dof_handler);
3503 *  
3504 * @endcode
3505 *
3506 * Following this, we can compute constraints for the solution vectors,
3507 * including hanging node constraints and homogeneous and inhomogeneous
3508 * boundary values for the Stokes and temperature fields. Note that as for
3509 * everything else, the constraint objects can not hold <i>all</i>
3510 * constraints on every processor. Rather, each processor needs to store
3511 * only those that are actually necessary for correctness given that it
3512 * only assembles linear systems on cells it owns. As discussed in the
3513 * @ref distributed_paper "this paper", the set of constraints we need to
3514 * know about is exactly the set of constraints on all locally relevant
3515 * degrees of freedom, so this is what we use to initialize the constraint
3516 * objects.
3517 *
3518 * @code
3519 *   {
3520 *   stokes_constraints.clear();
3521 *   stokes_constraints.reinit(stokes_locally_owned_index_set,
3522 *   stokes_locally_relevant_set);
3523 *  
3524 *   DoFTools::make_hanging_node_constraints(stokes_dof_handler,
3525 *   stokes_constraints);
3526 *  
3527 *   const FEValuesExtractors::Vector velocity_components(0);
3528 *   VectorTools::interpolate_boundary_values(
3529 *   stokes_dof_handler,
3530 *   0,
3531 *   Functions::ZeroFunction<dim>(dim + 1),
3532 *   stokes_constraints,
3533 *   stokes_fe.component_mask(velocity_components));
3534 *  
3535 *   std::set<types::boundary_id> no_normal_flux_boundaries;
3536 *   no_normal_flux_boundaries.insert(1);
3537 *   VectorTools::compute_no_normal_flux_constraints(stokes_dof_handler,
3538 *   0,
3539 *   no_normal_flux_boundaries,
3540 *   stokes_constraints,
3541 *   mapping);
3542 *   stokes_constraints.close();
3543 *   }
3544 *   {
3545 *   temperature_constraints.clear();
3546 *   temperature_constraints.reinit(temperature_partitioning,
3547 *   temperature_relevant_partitioning);
3548 *  
3549 *   DoFTools::make_hanging_node_constraints(temperature_dof_handler,
3550 *   temperature_constraints);
3551 *   VectorTools::interpolate_boundary_values(
3552 *   temperature_dof_handler,
3553 *   0,
3554 *   EquationData::TemperatureInitialValues<dim>(),
3555 *   temperature_constraints);
3556 *   VectorTools::interpolate_boundary_values(
3557 *   temperature_dof_handler,
3558 *   1,
3559 *   EquationData::TemperatureInitialValues<dim>(),
3560 *   temperature_constraints);
3561 *   temperature_constraints.close();
3562 *   }
3563 *  
3564 * @endcode
3565 *
3566 * All this done, we can then initialize the various matrix and vector
3567 * objects to their proper sizes. At the end, we also record that all
3568 * matrices and preconditioners have to be re-computed at the beginning of
3569 * the next time step. Note how we initialize the vectors for the Stokes
3570 * and temperature right hand sides: These are writable vectors (last
3571 * boolean argument set to @p true) that have the correct one-to-one
3572 * partitioning of locally owned elements but are still given the relevant
3573 * partitioning for means of figuring out the vector entries that are
3574 * going to be set right away. As for matrices, this allows for writing
3575 * local contributions into the vector with multiple threads (always
3576 * assuming that the same vector entry is not accessed by multiple threads
3577 * at the same time). The other vectors only allow for read access of
3578 * individual elements, including ghosts, but are not suitable for
3579 * solvers.
3580 *
3581 * @code
3582 *   setup_stokes_matrix(stokes_partitioning, stokes_relevant_partitioning);
3583 *   setup_stokes_preconditioner(stokes_partitioning,
3584 *   stokes_relevant_partitioning);
3585 *   setup_temperature_matrices(temperature_partitioning,
3586 *   temperature_relevant_partitioning);
3587 *  
3588 *   stokes_rhs.reinit(stokes_partitioning,
3589 *   stokes_relevant_partitioning,
3590 *   MPI_COMM_WORLD,
3591 *   true);
3592 *   stokes_solution.reinit(stokes_relevant_partitioning, MPI_COMM_WORLD);
3593 *   old_stokes_solution.reinit(stokes_solution);
3594 *  
3595 *   temperature_rhs.reinit(temperature_partitioning,
3596 *   temperature_relevant_partitioning,
3597 *   MPI_COMM_WORLD,
3598 *   true);
3599 *   temperature_solution.reinit(temperature_relevant_partitioning,
3600 *   MPI_COMM_WORLD);
3601 *   old_temperature_solution.reinit(temperature_solution);
3602 *   old_old_temperature_solution.reinit(temperature_solution);
3603 *  
3604 *   rebuild_stokes_matrix = true;
3605 *   rebuild_stokes_preconditioner = true;
3606 *   rebuild_temperature_matrices = true;
3607 *   rebuild_temperature_preconditioner = true;
3608 *   }
3609 *  
3610 *  
3611 *  
3612 * @endcode
3613 *
3614 *
3615 * <a name="step_32-TheBoussinesqFlowProblemassemblyfunctions"></a>
3616 * <h4>The BoussinesqFlowProblem assembly functions</h4>
3617 *
3618
3619 *
3620 * Following the discussion in the introduction and in the @ref threads
3621 * module, we split the assembly functions into different parts:
3622 *
3623
3624 *
3625 * <ul> <li> The local calculations of matrices and right hand sides, given
3626 * a certain cell as input (these functions are named
3627 * <code>local_assemble_*</code> below). The resulting function is, in other
3628 * words, essentially the body of the loop over all cells in @ref step_31 "step-31". Note,
3629 * however, that these functions store the result from the local
3630 * calculations in variables of classes from the CopyData namespace.
3631 *
3632
3633 *
3634 * <li>These objects are then given to the second step which writes the
3635 * local data into the global data structures (these functions are named
3636 * <code>copy_local_to_global_*</code> below). These functions are pretty
3637 * trivial.
3638 *
3639
3640 *
3641 * <li>These two subfunctions are then used in the respective assembly
3642 * routine (called <code>assemble_*</code> below), where a WorkStream object
3643 * is set up and runs over all the cells that belong to the processor's
3644 * subdomain. </ul>
3645 *
3646
3647 *
3648 *
3649 * <a name="step_32-Stokespreconditionerassembly"></a>
3650 * <h5>Stokes preconditioner assembly</h5>
3651 *
3652
3653 *
3654 * Let us start with the functions that builds the Stokes
3655 * preconditioner. The first two of these are pretty trivial, given the
3656 * discussion above. Note in particular that the main point in using the
3657 * scratch data object is that we want to avoid allocating any objects on
3658 * the free space each time we visit a new cell. As a consequence, the
3659 * assembly function below only has automatic local variables, and
3660 * everything else is accessed through the scratch data object, which is
3661 * allocated only once before we start the loop over all cells:
3662 *
3663 * @code
3664 *   template <int dim>
3665 *   void BoussinesqFlowProblem<dim>::local_assemble_stokes_preconditioner(
3666 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
3667 *   Assembly::Scratch::StokesPreconditioner<dim> &scratch,
3668 *   Assembly::CopyData::StokesPreconditioner<dim> &data)
3669 *   {
3670 *   const unsigned int dofs_per_cell = stokes_fe.n_dofs_per_cell();
3671 *   const unsigned int n_q_points =
3672 *   scratch.stokes_fe_values.n_quadrature_points;
3673 *  
3674 *   const FEValuesExtractors::Vector velocities(0);
3675 *   const FEValuesExtractors::Scalar pressure(dim);
3676 *  
3677 *   scratch.stokes_fe_values.reinit(cell);
3678 *   cell->get_dof_indices(data.local_dof_indices);
3679 *  
3680 *   data.local_matrix = 0;
3681 *  
3682 *   for (unsigned int q = 0; q < n_q_points; ++q)
3683 *   {
3684 *   for (unsigned int k = 0; k < dofs_per_cell; ++k)
3685 *   {
3686 *   scratch.grad_phi_u[k] =
3687 *   scratch.stokes_fe_values[velocities].gradient(k, q);
3688 *   scratch.phi_p[k] = scratch.stokes_fe_values[pressure].value(k, q);
3689 *   }
3690 *  
3691 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
3692 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
3693 *   data.local_matrix(i, j) +=
3694 *   (EquationData::eta *
3695 *   scalar_product(scratch.grad_phi_u[i], scratch.grad_phi_u[j]) +
3696 *   (1. / EquationData::eta) * EquationData::pressure_scaling *
3697 *   EquationData::pressure_scaling *
3698 *   (scratch.phi_p[i] * scratch.phi_p[j])) *
3699 *   scratch.stokes_fe_values.JxW(q);
3700 *   }
3701 *   }
3702 *  
3703 *  
3704 *  
3705 *   template <int dim>
3706 *   void BoussinesqFlowProblem<dim>::copy_local_to_global_stokes_preconditioner(
3707 *   const Assembly::CopyData::StokesPreconditioner<dim> &data)
3708 *   {
3709 *   stokes_constraints.distribute_local_to_global(data.local_matrix,
3710 *   data.local_dof_indices,
3711 *   stokes_preconditioner_matrix);
3712 *   }
3713 *  
3714 *  
3715 * @endcode
3716 *
3717 * Now for the function that actually puts things together, using the
3718 * WorkStream functions. WorkStream::run needs a start and end iterator to
3719 * enumerate the cells it is supposed to work on. Typically, one would use
3720 * DoFHandler::begin_active() and DoFHandler::end() for that but here we
3721 * actually only want the subset of cells that in fact are owned by the
3722 * current processor. This is where the FilteredIterator class comes into
3723 * play: you give it a range of cells and it provides an iterator that only
3724 * iterates over that subset of cells that satisfy a certain predicate (a
3725 * predicate is a function of one argument that either returns true or
3726 * false). The predicate we use here is IteratorFilters::LocallyOwnedCell,
3727 * i.e., it returns true exactly if the cell is owned by the current
3728 * processor. The resulting iterator range is then exactly what we need.
3729 *
3730
3731 *
3732 * With this obstacle out of the way, we call the WorkStream::run
3733 * function with this set of cells, scratch and copy objects, and
3734 * with pointers to two functions: the local assembly and
3735 * copy-local-to-global function. These functions need to have very
3736 * specific signatures: three arguments in the first and one
3737 * argument in the latter case (see the documentation of the
3738 * WorkStream::run function for the meaning of these arguments).
3739 * Note how we use a lambda functions to
3740 * create a function object that satisfies this requirement. It uses
3741 * function arguments for the local assembly function that specify
3742 * cell, scratch data, and copy data, as well as function argument
3743 * for the copy function that expects the
3744 * data to be written into the global matrix (also see the discussion in
3745 * @ref step_13 "step-13"'s <code>assemble_linear_system()</code> function). On the other
3746 * hand, the implicit zeroth argument of member functions (namely
3747 * the <code>this</code> pointer of the object on which that member
3748 * function is to operate on) is <i>bound</i> to the
3749 * <code>this</code> pointer of the current function and is captured. The
3750 * WorkStream::run function, as a consequence, does not need to know
3751 * anything about the object these functions work on.
3752 *
3753
3754 *
3755 * When the WorkStream is executed, it will create several local assembly
3756 * routines of the first kind for several cells and let some available
3757 * processors work on them. The function that needs to be synchronized,
3758 * i.e., the write operation into the global matrix, however, is executed by
3759 * only one thread at a time in the prescribed order. Of course, this only
3760 * holds for the parallelization on a single MPI process. Different MPI
3761 * processes will have their own WorkStream objects and do that work
3762 * completely independently (and in different memory spaces). In a
3763 * distributed calculation, some data will accumulate at degrees of freedom
3764 * that are not owned by the respective processor. It would be inefficient
3765 * to send data around every time we encounter such a dof. What happens
3766 * instead is that the Trilinos sparse matrix will keep that data and send
3767 * it to the owner at the end of assembly, by calling the
3768 * <code>compress()</code> command.
3769 *
3770 * @code
3771 *   template <int dim>
3772 *   void BoussinesqFlowProblem<dim>::assemble_stokes_preconditioner()
3773 *   {
3774 *   stokes_preconditioner_matrix = 0;
3775 *  
3776 *   const QGauss<dim> quadrature_formula(parameters.stokes_velocity_degree + 1);
3777 *  
3778 *   using CellFilter =
3780 *  
3781 *   auto worker =
3782 *   [this](const typename DoFHandler<dim>::active_cell_iterator &cell,
3783 *   Assembly::Scratch::StokesPreconditioner<dim> &scratch,
3784 *   Assembly::CopyData::StokesPreconditioner<dim> &data) {
3785 *   this->local_assemble_stokes_preconditioner(cell, scratch, data);
3786 *   };
3787 *  
3788 *   auto copier =
3789 *   [this](const Assembly::CopyData::StokesPreconditioner<dim> &data) {
3790 *   this->copy_local_to_global_stokes_preconditioner(data);
3791 *   };
3792 *  
3794 *   stokes_dof_handler.begin_active()),
3795 *   CellFilter(IteratorFilters::LocallyOwnedCell(),
3796 *   stokes_dof_handler.end()),
3797 *   worker,
3798 *   copier,
3799 *   Assembly::Scratch::StokesPreconditioner<dim>(
3800 *   stokes_fe,
3801 *   quadrature_formula,
3802 *   mapping,
3804 *   Assembly::CopyData::StokesPreconditioner<dim>(stokes_fe));
3805 *  
3806 *   stokes_preconditioner_matrix.compress(VectorOperation::add);
3807 *   }
3808 *  
3809 *  
3810 *  
3811 * @endcode
3812 *
3813 * The final function in this block initiates assembly of the Stokes
3814 * preconditioner matrix and then in fact builds the Stokes
3815 * preconditioner. It is mostly the same as in the serial case. The only
3816 * difference to @ref step_31 "step-31" is that we use a Jacobi preconditioner for the
3817 * pressure mass matrix instead of IC, as discussed in the introduction.
3818 *
3819 * @code
3820 *   template <int dim>
3821 *   void BoussinesqFlowProblem<dim>::build_stokes_preconditioner()
3822 *   {
3823 *   if (rebuild_stokes_preconditioner == false)
3824 *   return;
3825 *  
3826 *   TimerOutput::Scope timer_section(computing_timer,
3827 *   " Build Stokes preconditioner");
3828 *   pcout << " Rebuilding Stokes preconditioner..." << std::flush;
3829 *  
3830 *   assemble_stokes_preconditioner();
3831 *  
3832 *   std::vector<std::vector<bool>> constant_modes;
3833 *   const FEValuesExtractors::Vector velocity_components(0);
3834 *   DoFTools::extract_constant_modes(stokes_dof_handler,
3835 *   stokes_fe.component_mask(
3836 *   velocity_components),
3837 *   constant_modes);
3838 *  
3839 *   Mp_preconditioner =
3840 *   std::make_shared<TrilinosWrappers::PreconditionJacobi>();
3841 *   Amg_preconditioner = std::make_shared<TrilinosWrappers::PreconditionAMG>();
3842 *  
3844 *   Amg_data.constant_modes = constant_modes;
3845 *   Amg_data.elliptic = true;
3846 *   Amg_data.higher_order_elements = true;
3847 *   Amg_data.smoother_sweeps = 2;
3848 *   Amg_data.aggregation_threshold = 0.02;
3849 *  
3850 *   Mp_preconditioner->initialize(stokes_preconditioner_matrix.block(1, 1));
3851 *   Amg_preconditioner->initialize(stokes_preconditioner_matrix.block(0, 0),
3852 *   Amg_data);
3853 *  
3854 *   rebuild_stokes_preconditioner = false;
3855 *  
3856 *   pcout << std::endl;
3857 *   }
3858 *  
3859 *  
3860 * @endcode
3861 *
3862 *
3863 * <a name="step_32-Stokessystemassembly"></a>
3864 * <h5>Stokes system assembly</h5>
3865 *
3866
3867 *
3868 * The next three functions implement the assembly of the Stokes system,
3869 * again split up into a part performing local calculations, one for writing
3870 * the local data into the global matrix and vector, and one for actually
3871 * running the loop over all cells with the help of the WorkStream
3872 * class. Note that the assembly of the Stokes matrix needs only to be done
3873 * in case we have changed the mesh. Otherwise, just the
3874 * (temperature-dependent) right hand side needs to be calculated
3875 * here. Since we are working with distributed matrices and vectors, we have
3876 * to call the respective <code>compress()</code> functions in the end of
3877 * the assembly in order to send non-local data to the owner process.
3878 *
3879 * @code
3880 *   template <int dim>
3881 *   void BoussinesqFlowProblem<dim>::local_assemble_stokes_system(
3882 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
3883 *   Assembly::Scratch::StokesSystem<dim> &scratch,
3884 *   Assembly::CopyData::StokesSystem<dim> &data)
3885 *   {
3886 *   const unsigned int dofs_per_cell =
3887 *   scratch.stokes_fe_values.get_fe().n_dofs_per_cell();
3888 *   const unsigned int n_q_points =
3889 *   scratch.stokes_fe_values.n_quadrature_points;
3890 *  
3891 *   const FEValuesExtractors::Vector velocities(0);
3892 *   const FEValuesExtractors::Scalar pressure(dim);
3893 *  
3894 *   scratch.stokes_fe_values.reinit(cell);
3895 *  
3896 *   const typename DoFHandler<dim>::active_cell_iterator temperature_cell =
3897 *   cell->as_dof_handler_iterator(temperature_dof_handler);
3898 *   scratch.temperature_fe_values.reinit(temperature_cell);
3899 *  
3900 *   if (rebuild_stokes_matrix)
3901 *   data.local_matrix = 0;
3902 *   data.local_rhs = 0;
3903 *  
3904 *   scratch.temperature_fe_values.get_function_values(
3905 *   old_temperature_solution, scratch.old_temperature_values);
3906 *  
3907 *   for (unsigned int q = 0; q < n_q_points; ++q)
3908 *   {
3909 *   const double old_temperature = scratch.old_temperature_values[q];
3910 *  
3911 *   for (unsigned int k = 0; k < dofs_per_cell; ++k)
3912 *   {
3913 *   scratch.phi_u[k] = scratch.stokes_fe_values[velocities].value(k, q);
3914 *   if (rebuild_stokes_matrix)
3915 *   {
3916 *   scratch.grads_phi_u[k] =
3917 *   scratch.stokes_fe_values[velocities].symmetric_gradient(k, q);
3918 *   scratch.div_phi_u[k] =
3919 *   scratch.stokes_fe_values[velocities].divergence(k, q);
3920 *   scratch.phi_p[k] =
3921 *   scratch.stokes_fe_values[pressure].value(k, q);
3922 *   }
3923 *   }
3924 *  
3925 *   if (rebuild_stokes_matrix == true)
3926 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
3927 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
3928 *   data.local_matrix(i, j) +=
3929 *   (EquationData::eta * 2 *
3930 *   (scratch.grads_phi_u[i] * scratch.grads_phi_u[j]) -
3931 *   (EquationData::pressure_scaling * scratch.div_phi_u[i] *
3932 *   scratch.phi_p[j]) -
3933 *   (EquationData::pressure_scaling * scratch.phi_p[i] *
3934 *   scratch.div_phi_u[j])) *
3935 *   scratch.stokes_fe_values.JxW(q);
3936 *  
3937 *   const Tensor<1, dim> gravity = EquationData::gravity_vector(
3938 *   scratch.stokes_fe_values.quadrature_point(q));
3939 *  
3940 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
3941 *   data.local_rhs(i) += (EquationData::density(old_temperature) *
3942 *   gravity * scratch.phi_u[i]) *
3943 *   scratch.stokes_fe_values.JxW(q);
3944 *   }
3945 *  
3946 *   cell->get_dof_indices(data.local_dof_indices);
3947 *   }
3948 *  
3949 *  
3950 *  
3951 *   template <int dim>
3952 *   void BoussinesqFlowProblem<dim>::copy_local_to_global_stokes_system(
3953 *   const Assembly::CopyData::StokesSystem<dim> &data)
3954 *   {
3955 *   if (rebuild_stokes_matrix == true)
3956 *   stokes_constraints.distribute_local_to_global(data.local_matrix,
3957 *   data.local_rhs,
3958 *   data.local_dof_indices,
3959 *   stokes_matrix,
3960 *   stokes_rhs);
3961 *   else
3962 *   stokes_constraints.distribute_local_to_global(data.local_rhs,
3963 *   data.local_dof_indices,
3964 *   stokes_rhs);
3965 *   }
3966 *  
3967 *  
3968 *  
3969 *   template <int dim>
3970 *   void BoussinesqFlowProblem<dim>::assemble_stokes_system()
3971 *   {
3972 *   TimerOutput::Scope timer_section(computing_timer,
3973 *   " Assemble Stokes system");
3974 *  
3975 *   if (rebuild_stokes_matrix == true)
3976 *   stokes_matrix = 0;
3977 *  
3978 *   stokes_rhs = 0;
3979 *  
3980 *   const QGauss<dim> quadrature_formula(parameters.stokes_velocity_degree + 1);
3981 *  
3982 *   using CellFilter =
3984 *  
3985 *   WorkStream::run(
3986 *   CellFilter(IteratorFilters::LocallyOwnedCell(),
3987 *   stokes_dof_handler.begin_active()),
3988 *   CellFilter(IteratorFilters::LocallyOwnedCell(), stokes_dof_handler.end()),
3989 *   [this](const typename DoFHandler<dim>::active_cell_iterator &cell,
3990 *   Assembly::Scratch::StokesSystem<dim> &scratch,
3991 *   Assembly::CopyData::StokesSystem<dim> &data) {
3992 *   this->local_assemble_stokes_system(cell, scratch, data);
3993 *   },
3994 *   [this](const Assembly::CopyData::StokesSystem<dim> &data) {
3995 *   this->copy_local_to_global_stokes_system(data);
3996 *   },
3997 *   Assembly::Scratch::StokesSystem<dim>(
3998 *   stokes_fe,
3999 *   mapping,
4000 *   quadrature_formula,
4002 *   (rebuild_stokes_matrix == true ? update_gradients : UpdateFlags(0))),
4003 *   temperature_fe,
4004 *   update_values),
4005 *   Assembly::CopyData::StokesSystem<dim>(stokes_fe));
4006 *  
4007 *   if (rebuild_stokes_matrix == true)
4008 *   stokes_matrix.compress(VectorOperation::add);
4009 *   stokes_rhs.compress(VectorOperation::add);
4010 *  
4011 *   rebuild_stokes_matrix = false;
4012 *  
4013 *   pcout << std::endl;
4014 *   }
4015 *  
4016 *  
4017 * @endcode
4018 *
4019 *
4020 * <a name="step_32-Temperaturematrixassembly"></a>
4021 * <h5>Temperature matrix assembly</h5>
4022 *
4023
4024 *
4025 * The task to be performed by the next three functions is to calculate a
4026 * mass matrix and a Laplace matrix on the temperature system. These will be
4027 * combined in order to yield the semi-implicit time stepping matrix that
4028 * consists of the mass matrix plus a time step-dependent weight factor
4029 * times the Laplace matrix. This function is again essentially the body of
4030 * the loop over all cells from @ref step_31 "step-31".
4031 *
4032
4033 *
4034 * The two following functions perform similar services as the ones above.
4035 *
4036 * @code
4037 *   template <int dim>
4038 *   void BoussinesqFlowProblem<dim>::local_assemble_temperature_matrix(
4039 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
4040 *   Assembly::Scratch::TemperatureMatrix<dim> &scratch,
4041 *   Assembly::CopyData::TemperatureMatrix<dim> &data)
4042 *   {
4043 *   const unsigned int dofs_per_cell =
4044 *   scratch.temperature_fe_values.get_fe().n_dofs_per_cell();
4045 *   const unsigned int n_q_points =
4046 *   scratch.temperature_fe_values.n_quadrature_points;
4047 *  
4048 *   scratch.temperature_fe_values.reinit(cell);
4049 *   cell->get_dof_indices(data.local_dof_indices);
4050 *  
4051 *   data.local_mass_matrix = 0;
4052 *   data.local_stiffness_matrix = 0;
4053 *  
4054 *   for (unsigned int q = 0; q < n_q_points; ++q)
4055 *   {
4056 *   for (unsigned int k = 0; k < dofs_per_cell; ++k)
4057 *   {
4058 *   scratch.grad_phi_T[k] =
4059 *   scratch.temperature_fe_values.shape_grad(k, q);
4060 *   scratch.phi_T[k] = scratch.temperature_fe_values.shape_value(k, q);
4061 *   }
4062 *  
4063 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
4064 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
4065 *   {
4066 *   data.local_mass_matrix(i, j) +=
4067 *   (scratch.phi_T[i] * scratch.phi_T[j] *
4068 *   scratch.temperature_fe_values.JxW(q));
4069 *   data.local_stiffness_matrix(i, j) +=
4070 *   (EquationData::kappa * scratch.grad_phi_T[i] *
4071 *   scratch.grad_phi_T[j] * scratch.temperature_fe_values.JxW(q));
4072 *   }
4073 *   }
4074 *   }
4075 *  
4076 *  
4077 *  
4078 *   template <int dim>
4079 *   void BoussinesqFlowProblem<dim>::copy_local_to_global_temperature_matrix(
4080 *   const Assembly::CopyData::TemperatureMatrix<dim> &data)
4081 *   {
4082 *   temperature_constraints.distribute_local_to_global(data.local_mass_matrix,
4083 *   data.local_dof_indices,
4084 *   temperature_mass_matrix);
4085 *   temperature_constraints.distribute_local_to_global(
4086 *   data.local_stiffness_matrix,
4087 *   data.local_dof_indices,
4088 *   temperature_stiffness_matrix);
4089 *   }
4090 *  
4091 *  
4092 *   template <int dim>
4093 *   void BoussinesqFlowProblem<dim>::assemble_temperature_matrix()
4094 *   {
4095 *   if (rebuild_temperature_matrices == false)
4096 *   return;
4097 *  
4098 *   TimerOutput::Scope timer_section(computing_timer,
4099 *   " Assemble temperature matrices");
4100 *   temperature_mass_matrix = 0;
4101 *   temperature_stiffness_matrix = 0;
4102 *  
4103 *   const QGauss<dim> quadrature_formula(parameters.temperature_degree + 2);
4104 *  
4105 *   using CellFilter =
4107 *  
4108 *   WorkStream::run(
4109 *   CellFilter(IteratorFilters::LocallyOwnedCell(),
4110 *   temperature_dof_handler.begin_active()),
4111 *   CellFilter(IteratorFilters::LocallyOwnedCell(),
4112 *   temperature_dof_handler.end()),
4113 *   [this](const typename DoFHandler<dim>::active_cell_iterator &cell,
4114 *   Assembly::Scratch::TemperatureMatrix<dim> &scratch,
4115 *   Assembly::CopyData::TemperatureMatrix<dim> &data) {
4116 *   this->local_assemble_temperature_matrix(cell, scratch, data);
4117 *   },
4118 *   [this](const Assembly::CopyData::TemperatureMatrix<dim> &data) {
4119 *   this->copy_local_to_global_temperature_matrix(data);
4120 *   },
4121 *   Assembly::Scratch::TemperatureMatrix<dim>(temperature_fe,
4122 *   mapping,
4123 *   quadrature_formula),
4124 *   Assembly::CopyData::TemperatureMatrix<dim>(temperature_fe));
4125 *  
4126 *   temperature_mass_matrix.compress(VectorOperation::add);
4127 *   temperature_stiffness_matrix.compress(VectorOperation::add);
4128 *  
4129 *   rebuild_temperature_matrices = false;
4130 *   rebuild_temperature_preconditioner = true;
4131 *   }
4132 *  
4133 *  
4134 * @endcode
4135 *
4136 *
4137 * <a name="step_32-Temperaturerighthandsideassembly"></a>
4138 * <h5>Temperature right hand side assembly</h5>
4139 *
4140
4141 *
4142 * This is the last assembly function. It calculates the right hand side of
4143 * the temperature system, which includes the convection and the
4144 * stabilization terms. It includes a lot of evaluations of old solutions at
4145 * the quadrature points (which are necessary for calculating the artificial
4146 * viscosity of stabilization), but is otherwise similar to the other
4147 * assembly functions. Notice, once again, how we resolve the dilemma of
4148 * having inhomogeneous boundary conditions, by just making a right hand
4149 * side at this point (compare the comments for the <code>project()</code>
4150 * function above): We create some matrix columns with exactly the values
4151 * that would be entered for the temperature @ref GlossStiffnessMatrix "stiffness matrix", in case we
4152 * have inhomogeneously constrained dofs. That will account for the correct
4153 * balance of the right hand side vector with the matrix system of
4154 * temperature.
4155 *
4156 * @code
4157 *   template <int dim>
4158 *   void BoussinesqFlowProblem<dim>::local_assemble_temperature_rhs(
4159 *   const std::pair<double, double> global_T_range,
4160 *   const double global_max_velocity,
4161 *   const double global_entropy_variation,
4162 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
4163 *   Assembly::Scratch::TemperatureRHS<dim> &scratch,
4164 *   Assembly::CopyData::TemperatureRHS<dim> &data)
4165 *   {
4166 *   const bool use_bdf2_scheme = (timestep_number != 0);
4167 *  
4168 *   const unsigned int dofs_per_cell =
4169 *   scratch.temperature_fe_values.get_fe().n_dofs_per_cell();
4170 *   const unsigned int n_q_points =
4171 *   scratch.temperature_fe_values.n_quadrature_points;
4172 *  
4173 *   const FEValuesExtractors::Vector velocities(0);
4174 *  
4175 *   data.local_rhs = 0;
4176 *   data.matrix_for_bc = 0;
4177 *   cell->get_dof_indices(data.local_dof_indices);
4178 *  
4179 *   scratch.temperature_fe_values.reinit(cell);
4180 *  
4181 *   typename DoFHandler<dim>::active_cell_iterator stokes_cell =
4182 *   cell->as_dof_handler_iterator(stokes_dof_handler);
4183 *   scratch.stokes_fe_values.reinit(stokes_cell);
4184 *  
4185 *   scratch.temperature_fe_values.get_function_values(
4186 *   old_temperature_solution, scratch.old_temperature_values);
4187 *   scratch.temperature_fe_values.get_function_values(
4188 *   old_old_temperature_solution, scratch.old_old_temperature_values);
4189 *  
4190 *   scratch.temperature_fe_values.get_function_gradients(
4191 *   old_temperature_solution, scratch.old_temperature_grads);
4192 *   scratch.temperature_fe_values.get_function_gradients(
4193 *   old_old_temperature_solution, scratch.old_old_temperature_grads);
4194 *  
4195 *   scratch.temperature_fe_values.get_function_laplacians(
4196 *   old_temperature_solution, scratch.old_temperature_laplacians);
4197 *   scratch.temperature_fe_values.get_function_laplacians(
4198 *   old_old_temperature_solution, scratch.old_old_temperature_laplacians);
4199 *  
4200 *   scratch.stokes_fe_values[velocities].get_function_values(
4201 *   stokes_solution, scratch.old_velocity_values);
4202 *   scratch.stokes_fe_values[velocities].get_function_values(
4203 *   old_stokes_solution, scratch.old_old_velocity_values);
4204 *   scratch.stokes_fe_values[velocities].get_function_symmetric_gradients(
4205 *   stokes_solution, scratch.old_strain_rates);
4206 *   scratch.stokes_fe_values[velocities].get_function_symmetric_gradients(
4207 *   old_stokes_solution, scratch.old_old_strain_rates);
4208 *  
4209 *   const double nu =
4210 *   compute_viscosity(scratch.old_temperature_values,
4211 *   scratch.old_old_temperature_values,
4212 *   scratch.old_temperature_grads,
4213 *   scratch.old_old_temperature_grads,
4214 *   scratch.old_temperature_laplacians,
4215 *   scratch.old_old_temperature_laplacians,
4216 *   scratch.old_velocity_values,
4217 *   scratch.old_old_velocity_values,
4218 *   scratch.old_strain_rates,
4219 *   scratch.old_old_strain_rates,
4220 *   global_max_velocity,
4221 *   global_T_range.second - global_T_range.first,
4222 *   0.5 * (global_T_range.second + global_T_range.first),
4223 *   global_entropy_variation,
4224 *   cell->diameter());
4225 *  
4226 *   for (unsigned int q = 0; q < n_q_points; ++q)
4227 *   {
4228 *   for (unsigned int k = 0; k < dofs_per_cell; ++k)
4229 *   {
4230 *   scratch.phi_T[k] = scratch.temperature_fe_values.shape_value(k, q);
4231 *   scratch.grad_phi_T[k] =
4232 *   scratch.temperature_fe_values.shape_grad(k, q);
4233 *   }
4234 *  
4235 *  
4236 *   const double T_term_for_rhs =
4237 *   (use_bdf2_scheme ?
4238 *   (scratch.old_temperature_values[q] *
4239 *   (1 + time_step / old_time_step) -
4240 *   scratch.old_old_temperature_values[q] * (time_step * time_step) /
4241 *   (old_time_step * (time_step + old_time_step))) :
4242 *   scratch.old_temperature_values[q]);
4243 *  
4244 *   const double ext_T =
4245 *   (use_bdf2_scheme ? (scratch.old_temperature_values[q] *
4246 *   (1 + time_step / old_time_step) -
4247 *   scratch.old_old_temperature_values[q] *
4248 *   time_step / old_time_step) :
4249 *   scratch.old_temperature_values[q]);
4250 *  
4251 *   const Tensor<1, dim> ext_grad_T =
4252 *   (use_bdf2_scheme ? (scratch.old_temperature_grads[q] *
4253 *   (1 + time_step / old_time_step) -
4254 *   scratch.old_old_temperature_grads[q] * time_step /
4255 *   old_time_step) :
4256 *   scratch.old_temperature_grads[q]);
4257 *  
4258 *   const Tensor<1, dim> extrapolated_u =
4259 *   (use_bdf2_scheme ?
4260 *   (scratch.old_velocity_values[q] * (1 + time_step / old_time_step) -
4261 *   scratch.old_old_velocity_values[q] * time_step / old_time_step) :
4262 *   scratch.old_velocity_values[q]);
4263 *  
4264 *   const SymmetricTensor<2, dim> extrapolated_strain_rate =
4265 *   (use_bdf2_scheme ?
4266 *   (scratch.old_strain_rates[q] * (1 + time_step / old_time_step) -
4267 *   scratch.old_old_strain_rates[q] * time_step / old_time_step) :
4268 *   scratch.old_strain_rates[q]);
4269 *  
4270 *   const double gamma =
4271 *   ((EquationData::radiogenic_heating * EquationData::density(ext_T) +
4272 *   2 * EquationData::eta * extrapolated_strain_rate *
4273 *   extrapolated_strain_rate) /
4274 *   (EquationData::density(ext_T) * EquationData::specific_heat));
4275 *  
4276 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
4277 *   {
4278 *   data.local_rhs(i) +=
4279 *   (T_term_for_rhs * scratch.phi_T[i] -
4280 *   time_step * extrapolated_u * ext_grad_T * scratch.phi_T[i] -
4281 *   time_step * nu * ext_grad_T * scratch.grad_phi_T[i] +
4282 *   time_step * gamma * scratch.phi_T[i]) *
4283 *   scratch.temperature_fe_values.JxW(q);
4284 *  
4285 *   if (temperature_constraints.is_inhomogeneously_constrained(
4286 *   data.local_dof_indices[i]))
4287 *   {
4288 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
4289 *   data.matrix_for_bc(j, i) +=
4290 *   (scratch.phi_T[i] * scratch.phi_T[j] *
4291 *   (use_bdf2_scheme ? ((2 * time_step + old_time_step) /
4292 *   (time_step + old_time_step)) :
4293 *   1.) +
4294 *   scratch.grad_phi_T[i] * scratch.grad_phi_T[j] *
4295 *   EquationData::kappa * time_step) *
4296 *   scratch.temperature_fe_values.JxW(q);
4297 *   }
4298 *   }
4299 *   }
4300 *   }
4301 *  
4302 *  
4303 *   template <int dim>
4304 *   void BoussinesqFlowProblem<dim>::copy_local_to_global_temperature_rhs(
4305 *   const Assembly::CopyData::TemperatureRHS<dim> &data)
4306 *   {
4307 *   temperature_constraints.distribute_local_to_global(data.local_rhs,
4308 *   data.local_dof_indices,
4309 *   temperature_rhs,
4310 *   data.matrix_for_bc);
4311 *   }
4312 *  
4313 *  
4314 *  
4315 * @endcode
4316 *
4317 * In the function that runs the WorkStream for actually calculating the
4318 * right hand side, we also generate the final matrix. As mentioned above,
4319 * it is a sum of the mass matrix and the Laplace matrix, times some time
4320 * step-dependent weight. This weight is specified by the BDF-2 time
4321 * integration scheme, see the introduction in @ref step_31 "step-31". What is new in this
4322 * tutorial program (in addition to the use of MPI parallelization and the
4323 * WorkStream class), is that we now precompute the temperature
4324 * preconditioner as well. The reason is that the setup of the Jacobi
4325 * preconditioner takes a noticeable time compared to the solver because we
4326 * usually only need between 10 and 20 iterations for solving the
4327 * temperature system (this might sound strange, as Jacobi really only
4328 * consists of a diagonal, but in Trilinos it is derived from more general
4329 * framework for point relaxation preconditioners which is a bit
4330 * inefficient). Hence, it is more efficient to precompute the
4331 * preconditioner, even though the matrix entries may slightly change
4332 * because the time step might change. This is not too big a problem because
4333 * we remesh every few time steps (and regenerate the preconditioner then).
4334 *
4335 * @code
4336 *   template <int dim>
4337 *   void BoussinesqFlowProblem<dim>::assemble_temperature_system(
4338 *   const double maximal_velocity)
4339 *   {
4340 *   const bool use_bdf2_scheme = (timestep_number != 0);
4341 *  
4342 *   if (use_bdf2_scheme == true)
4343 *   {
4344 *   temperature_matrix.copy_from(temperature_mass_matrix);
4345 *   temperature_matrix *=
4346 *   (2 * time_step + old_time_step) / (time_step + old_time_step);
4347 *   temperature_matrix.add(time_step, temperature_stiffness_matrix);
4348 *   }
4349 *   else
4350 *   {
4351 *   temperature_matrix.copy_from(temperature_mass_matrix);
4352 *   temperature_matrix.add(time_step, temperature_stiffness_matrix);
4353 *   }
4354 *  
4355 *   if (rebuild_temperature_preconditioner == true)
4356 *   {
4357 *   T_preconditioner =
4358 *   std::make_shared<TrilinosWrappers::PreconditionJacobi>();
4359 *   T_preconditioner->initialize(temperature_matrix);
4360 *   rebuild_temperature_preconditioner = false;
4361 *   }
4362 *  
4363 * @endcode
4364 *
4365 * The next part is computing the right hand side vectors. To do so, we
4366 * first compute the average temperature @f$T_m@f$ that we use for evaluating
4367 * the artificial viscosity stabilization through the residual @f$E(T) =
4368 * (T-T_m)^2@f$. We do this by defining the midpoint between maximum and
4369 * minimum temperature as average temperature in the definition of the
4370 * entropy viscosity. An alternative would be to use the integral average,
4371 * but the results are not very sensitive to this choice. The rest then
4372 * only requires calling WorkStream::run again, binding the arguments to
4373 * the <code>local_assemble_temperature_rhs</code> function that are the
4374 * same in every call to the correct values:
4375 *
4376 * @code
4377 *   temperature_rhs = 0;
4378 *  
4379 *   const QGauss<dim> quadrature_formula(parameters.temperature_degree + 2);
4380 *   const std::pair<double, double> global_T_range =
4381 *   get_extrapolated_temperature_range();
4382 *  
4383 *   const double average_temperature =
4384 *   0.5 * (global_T_range.first + global_T_range.second);
4385 *   const double global_entropy_variation =
4386 *   get_entropy_variation(average_temperature);
4387 *  
4388 *   using CellFilter =
4390 *  
4391 *   auto worker =
4392 *   [this, global_T_range, maximal_velocity, global_entropy_variation](
4393 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
4394 *   Assembly::Scratch::TemperatureRHS<dim> &scratch,
4395 *   Assembly::CopyData::TemperatureRHS<dim> &data) {
4396 *   this->local_assemble_temperature_rhs(global_T_range,
4397 *   maximal_velocity,
4398 *   global_entropy_variation,
4399 *   cell,
4400 *   scratch,
4401 *   data);
4402 *   };
4403 *  
4404 *   auto copier = [this](const Assembly::CopyData::TemperatureRHS<dim> &data) {
4405 *   this->copy_local_to_global_temperature_rhs(data);
4406 *   };
4407 *  
4409 *   temperature_dof_handler.begin_active()),
4410 *   CellFilter(IteratorFilters::LocallyOwnedCell(),
4411 *   temperature_dof_handler.end()),
4412 *   worker,
4413 *   copier,
4414 *   Assembly::Scratch::TemperatureRHS<dim>(
4415 *   temperature_fe, stokes_fe, mapping, quadrature_formula),
4416 *   Assembly::CopyData::TemperatureRHS<dim>(temperature_fe));
4417 *  
4418 *   temperature_rhs.compress(VectorOperation::add);
4419 *   }
4420 *  
4421 *  
4422 *  
4423 * @endcode
4424 *
4425 *
4426 * <a name="step_32-BoussinesqFlowProblemsolve"></a>
4427 * <h4>BoussinesqFlowProblem::solve</h4>
4428 *
4429
4430 *
4431 * This function solves the linear systems in each time step of the
4432 * Boussinesq problem. First, we work on the Stokes system and then on the
4433 * temperature system. In essence, it does the same things as the respective
4434 * function in @ref step_31 "step-31". However, there are a few changes here.
4435 *
4436
4437 *
4438 * The first change is related to the way we store our solution: we keep the
4439 * vectors with locally owned degrees of freedom plus ghost nodes on each
4440 * MPI node. When we enter a solver which is supposed to perform
4441 * matrix-vector products with a distributed matrix, this is not the
4442 * appropriate form, though. There, we will want to have the solution vector
4443 * to be distributed in the same way as the matrix, i.e. without any
4444 * ghosts. So what we do first is to generate a distributed vector called
4445 * <code>distributed_stokes_solution</code> and put only the locally owned
4446 * dofs into that, which is neatly done by the <code>operator=</code> of the
4447 * Trilinos vector.
4448 *
4449
4450 *
4451 * Next, we scale the pressure solution (or rather, the initial guess) for
4452 * the solver so that it matches with the length scales in the matrices, as
4453 * discussed in the introduction. We also immediately scale the pressure
4454 * solution back to the correct units after the solution is completed. We
4455 * also need to set the pressure values at hanging nodes to zero. This we
4456 * also did in @ref step_31 "step-31" in order not to disturb the Schur complement by some
4457 * vector entries that actually are irrelevant during the solve stage. As a
4458 * difference to @ref step_31 "step-31", here we do it only for the locally owned pressure
4459 * dofs. After solving for the Stokes solution, each processor copies the
4460 * distributed solution back into the solution vector that also includes
4461 * ghost elements.
4462 *
4463
4464 *
4465 * The third and most obvious change is that we have two variants for the
4466 * Stokes solver: A fast solver that sometimes breaks down, and a robust
4467 * solver that is slower. This is what we already discussed in the
4468 * introduction. Here is how we realize it: First, we perform 30 iterations
4469 * with the fast solver based on the simple preconditioner based on the AMG
4470 * V-cycle instead of an approximate solve (this is indicated by the
4471 * <code>false</code> argument to the
4472 * <code>LinearSolvers::BlockSchurPreconditioner</code> object). If we
4473 * converge, everything is fine. If we do not converge, the solver control
4474 * object will throw an exception SolverControl::NoConvergence. Usually,
4475 * this would abort the program because we don't catch them in our usual
4476 * <code>solve()</code> functions. This is certainly not what we want to
4477 * happen here. Rather, we want to switch to the strong solver and continue
4478 * the solution process with whatever vector we got so far. Hence, we catch
4479 * the exception with the C++ try/catch mechanism. We then simply go through
4480 * the same solver sequence again in the <code>catch</code> clause, this
4481 * time passing the @p true flag to the preconditioner for the strong
4482 * solver, signaling an approximate CG solve.
4483 *
4484 * @code
4485 *   template <int dim>
4486 *   void BoussinesqFlowProblem<dim>::solve()
4487 *   {
4488 *   {
4489 *   TimerOutput::Scope timer_section(computing_timer,
4490 *   " Solve Stokes system");
4491 *  
4492 *   pcout << " Solving Stokes system... " << std::flush;
4493 *  
4494 *   TrilinosWrappers::MPI::BlockVector distributed_stokes_solution(
4495 *   stokes_rhs);
4496 *   distributed_stokes_solution = stokes_solution;
4497 *  
4498 *   distributed_stokes_solution.block(1) /= EquationData::pressure_scaling;
4499 *  
4500 *   const unsigned int
4501 *   start = (distributed_stokes_solution.block(0).size() +
4502 *   distributed_stokes_solution.block(1).local_range().first),
4503 *   end = (distributed_stokes_solution.block(0).size() +
4504 *   distributed_stokes_solution.block(1).local_range().second);
4505 *   for (unsigned int i = start; i < end; ++i)
4506 *   if (stokes_constraints.is_constrained(i))
4507 *   distributed_stokes_solution(i) = 0;
4508 *  
4509 *  
4510 *   PrimitiveVectorMemory<TrilinosWrappers::MPI::BlockVector> mem;
4511 *  
4512 *   unsigned int n_iterations = 0;
4513 *   const double solver_tolerance = 1e-8 * stokes_rhs.l2_norm();
4514 *   SolverControl solver_control(30, solver_tolerance);
4515 *  
4516 *   try
4517 *   {
4518 *   const LinearSolvers::BlockSchurPreconditioner<
4519 *   TrilinosWrappers::PreconditionAMG,
4520 *   TrilinosWrappers::PreconditionJacobi>
4521 *   preconditioner(stokes_matrix,
4522 *   stokes_preconditioner_matrix,
4523 *   *Mp_preconditioner,
4524 *   *Amg_preconditioner,
4525 *   false);
4526 *  
4527 *   SolverFGMRES<TrilinosWrappers::MPI::BlockVector> solver(
4528 *   solver_control,
4529 *   mem,
4530 *   SolverFGMRES<TrilinosWrappers::MPI::BlockVector>::AdditionalData(
4531 *   30));
4532 *   solver.solve(stokes_matrix,
4533 *   distributed_stokes_solution,
4534 *   stokes_rhs,
4535 *   preconditioner);
4536 *  
4537 *   n_iterations = solver_control.last_step();
4538 *   }
4539 *  
4540 *   catch (SolverControl::NoConvergence &)
4541 *   {
4542 *   const LinearSolvers::BlockSchurPreconditioner<
4543 *   TrilinosWrappers::PreconditionAMG,
4544 *   TrilinosWrappers::PreconditionJacobi>
4545 *   preconditioner(stokes_matrix,
4546 *   stokes_preconditioner_matrix,
4547 *   *Mp_preconditioner,
4548 *   *Amg_preconditioner,
4549 *   true);
4550 *  
4551 *   SolverControl solver_control_refined(stokes_matrix.m(),
4552 *   solver_tolerance);
4553 *   SolverFGMRES<TrilinosWrappers::MPI::BlockVector> solver(
4554 *   solver_control_refined,
4555 *   mem,
4556 *   SolverFGMRES<TrilinosWrappers::MPI::BlockVector>::AdditionalData(
4557 *   50));
4558 *   solver.solve(stokes_matrix,
4559 *   distributed_stokes_solution,
4560 *   stokes_rhs,
4561 *   preconditioner);
4562 *  
4563 *   n_iterations =
4564 *   (solver_control.last_step() + solver_control_refined.last_step());
4565 *   }
4566 *  
4567 *  
4568 *   stokes_constraints.distribute(distributed_stokes_solution);
4569 *  
4570 *   distributed_stokes_solution.block(1) *= EquationData::pressure_scaling;
4571 *  
4572 *   stokes_solution = distributed_stokes_solution;
4573 *   pcout << n_iterations << " iterations." << std::endl;
4574 *   }
4575 *  
4576 *  
4577 * @endcode
4578 *
4579 * Now let's turn to the temperature part: First, we compute the time step
4580 * size. We found that we need smaller time steps for 3d than for 2d for
4581 * the shell geometry. This is because the cells are more distorted in
4582 * that case (it is the smallest edge length that determines the CFL
4583 * number). Instead of computing the time step from maximum velocity and
4584 * minimal mesh size as in @ref step_31 "step-31", we compute local CFL numbers, i.e., on
4585 * each cell we compute the maximum velocity times the mesh size, and
4586 * compute the maximum of them. Hence, we need to choose the factor in
4587 * front of the time step slightly smaller. (We later re-considered this
4588 * approach towards time stepping. If you're curious about this, you may
4589 * want to read the time stepping section in @cite HDGB17 .)
4590 *
4591
4592 *
4593 * After temperature right hand side assembly, we solve the linear
4594 * system for temperature (with fully distributed vectors without
4595 * ghost elements and using the solution from the last timestep as
4596 * our initial guess for the iterative solver), apply constraints,
4597 * and copy the vector back to one with ghosts.
4598 *
4599
4600 *
4601 * In the end, we extract the temperature range similarly to @ref step_31 "step-31" to
4602 * produce some output (for example in order to help us choose the
4603 * stabilization constants, as discussed in the introduction). The only
4604 * difference is that we need to exchange maxima over all processors.
4605 *
4606 * @code
4607 *   {
4608 *   TimerOutput::Scope timer_section(computing_timer,
4609 *   " Assemble temperature rhs");
4610 *  
4611 *   old_time_step = time_step;
4612 *  
4613 *   const double scaling = (dim == 3 ? 0.25 : 1.0);
4614 *   time_step = (scaling / (2.1 * dim * std::sqrt(1. * dim)) /
4615 *   (parameters.temperature_degree * get_cfl_number()));
4616 *  
4617 *   const double maximal_velocity = get_maximal_velocity();
4618 *   pcout << " Maximal velocity: "
4619 *   << maximal_velocity * EquationData::year_in_seconds * 100
4620 *   << " cm/year" << std::endl;
4621 *   pcout << " "
4622 *   << "Time step: " << time_step / EquationData::year_in_seconds
4623 *   << " years" << std::endl;
4624 *  
4625 *   assemble_temperature_system(maximal_velocity);
4626 *   }
4627 *  
4628 *   {
4629 *   TimerOutput::Scope timer_section(computing_timer,
4630 *   " Solve temperature system");
4631 *  
4632 *   SolverControl solver_control(temperature_matrix.m(),
4633 *   1e-12 * temperature_rhs.l2_norm());
4634 *   SolverCG<TrilinosWrappers::MPI::Vector> cg(solver_control);
4635 *  
4636 *   TrilinosWrappers::MPI::Vector distributed_temperature_solution(
4637 *   temperature_rhs);
4638 *   distributed_temperature_solution = old_temperature_solution;
4639 *  
4640 *   cg.solve(temperature_matrix,
4641 *   distributed_temperature_solution,
4642 *   temperature_rhs,
4643 *   *T_preconditioner);
4644 *  
4645 *   temperature_constraints.distribute(distributed_temperature_solution);
4646 *   temperature_solution = distributed_temperature_solution;
4647 *  
4648 *   pcout << " " << solver_control.last_step()
4649 *   << " CG iterations for temperature" << std::endl;
4650 *  
4651 *   double temperature[2] = {std::numeric_limits<double>::max(),
4652 *   -std::numeric_limits<double>::max()};
4653 *   double global_temperature[2];
4654 *  
4655 *   for (unsigned int i =
4656 *   distributed_temperature_solution.local_range().first;
4657 *   i < distributed_temperature_solution.local_range().second;
4658 *   ++i)
4659 *   {
4660 *   temperature[0] =
4661 *   std::min<double>(temperature[0],
4662 *   distributed_temperature_solution(i));
4663 *   temperature[1] =
4664 *   std::max<double>(temperature[1],
4665 *   distributed_temperature_solution(i));
4666 *   }
4667 *  
4668 *   temperature[0] *= -1.0;
4669 *   Utilities::MPI::max(temperature, MPI_COMM_WORLD, global_temperature);
4670 *   global_temperature[0] *= -1.0;
4671 *  
4672 *   pcout << " Temperature range: " << global_temperature[0] << ' '
4673 *   << global_temperature[1] << std::endl;
4674 *   }
4675 *   }
4676 *  
4677 *  
4678 * @endcode
4679 *
4680 *
4681 * <a name="step_32-BoussinesqFlowProblemoutput_results"></a>
4682 * <h4>BoussinesqFlowProblem::output_results</h4>
4683 *
4684
4685 *
4686 * Next comes the function that generates the output. The quantities to
4687 * output could be introduced manually like we did in @ref step_31 "step-31". An
4688 * alternative is to hand this task over to a class PostProcessor that
4689 * inherits from the class DataPostprocessor, which can be attached to
4690 * DataOut. This allows us to output derived quantities from the solution,
4691 * like the friction heating included in this example. It overloads the
4692 * virtual function DataPostprocessor::evaluate_vector_field(),
4693 * which is then internally called from DataOut::build_patches(). We have to
4694 * give it values of the numerical solution, its derivatives, normals to the
4695 * cell, the actual evaluation points and any additional quantities. This
4696 * follows the same procedure as discussed in @ref step_29 "step-29" and other programs.
4697 *
4698 * @code
4699 *   template <int dim>
4700 *   class BoussinesqFlowProblem<dim>::Postprocessor
4701 *   : public DataPostprocessor<dim>
4702 *   {
4703 *   public:
4704 *   Postprocessor(const unsigned int partition, const double minimal_pressure);
4705 *  
4706 *   virtual void evaluate_vector_field(
4707 *   const DataPostprocessorInputs::Vector<dim> &inputs,
4708 *   std::vector<Vector<double>> &computed_quantities) const override;
4709 *  
4710 *   virtual std::vector<std::string> get_names() const override;
4711 *  
4712 *   virtual std::vector<
4713 *   DataComponentInterpretation::DataComponentInterpretation>
4714 *   get_data_component_interpretation() const override;
4715 *  
4716 *   virtual UpdateFlags get_needed_update_flags() const override;
4717 *  
4718 *   private:
4719 *   const unsigned int partition;
4720 *   const double minimal_pressure;
4721 *   };
4722 *  
4723 *  
4724 *   template <int dim>
4725 *   BoussinesqFlowProblem<dim>::Postprocessor::Postprocessor(
4726 *   const unsigned int partition,
4727 *   const double minimal_pressure)
4728 *   : partition(partition)
4729 *   , minimal_pressure(minimal_pressure)
4730 *   {}
4731 *  
4732 *  
4733 * @endcode
4734 *
4735 * Here we define the names for the variables we want to output. These are
4736 * the actual solution values for velocity, pressure, and temperature, as
4737 * well as the friction heating and to each cell the number of the processor
4738 * that owns it. This allows us to visualize the partitioning of the domain
4739 * among the processors. Except for the velocity, which is vector-valued,
4740 * all other quantities are scalar.
4741 *
4742 * @code
4743 *   template <int dim>
4744 *   std::vector<std::string>
4745 *   BoussinesqFlowProblem<dim>::Postprocessor::get_names() const
4746 *   {
4747 *   std::vector<std::string> solution_names(dim, "velocity");
4748 *   solution_names.emplace_back("p");
4749 *   solution_names.emplace_back("T");
4750 *   solution_names.emplace_back("friction_heating");
4751 *   solution_names.emplace_back("partition");
4752 *  
4753 *   return solution_names;
4754 *   }
4755 *  
4756 *  
4757 *   template <int dim>
4758 *   std::vector<DataComponentInterpretation::DataComponentInterpretation>
4759 *   BoussinesqFlowProblem<dim>::Postprocessor::get_data_component_interpretation()
4760 *   const
4761 *   {
4762 *   std::vector<DataComponentInterpretation::DataComponentInterpretation>
4763 *   interpretation(dim,
4764 *   DataComponentInterpretation::component_is_part_of_vector);
4765 *  
4766 *   interpretation.push_back(DataComponentInterpretation::component_is_scalar);
4767 *   interpretation.push_back(DataComponentInterpretation::component_is_scalar);
4768 *   interpretation.push_back(DataComponentInterpretation::component_is_scalar);
4769 *   interpretation.push_back(DataComponentInterpretation::component_is_scalar);
4770 *  
4771 *   return interpretation;
4772 *   }
4773 *  
4774 *  
4775 *   template <int dim>
4776 *   UpdateFlags
4777 *   BoussinesqFlowProblem<dim>::Postprocessor::get_needed_update_flags() const
4778 *   {
4779 *   return update_values | update_gradients | update_quadrature_points;
4780 *   }
4781 *  
4782 *  
4783 * @endcode
4784 *
4785 * Now we implement the function that computes the derived quantities. As we
4786 * also did for the output, we rescale the velocity from its SI units to
4787 * something more readable, namely cm/year. Next, the pressure is scaled to
4788 * be between 0 and the maximum pressure. This makes it more easily
4789 * comparable -- in essence making all pressure variables positive or
4790 * zero. Temperature is taken as is, and the friction heating is computed as
4791 * @f$2 \eta \varepsilon(\mathbf{u}) \cdot \varepsilon(\mathbf{u})@f$.
4792 *
4793
4794 *
4795 * The quantities we output here are more for illustration, rather than for
4796 * actual scientific value. We come back to this briefly in the results
4797 * section of this program and explain what one may in fact be interested in.
4798 *
4799 * @code
4800 *   template <int dim>
4801 *   void BoussinesqFlowProblem<dim>::Postprocessor::evaluate_vector_field(
4802 *   const DataPostprocessorInputs::Vector<dim> &inputs,
4803 *   std::vector<Vector<double>> &computed_quantities) const
4804 *   {
4805 *   const unsigned int n_evaluation_points = inputs.solution_values.size();
4806 *   Assert(inputs.solution_gradients.size() == n_evaluation_points,
4807 *   ExcInternalError());
4808 *   Assert(computed_quantities.size() == n_evaluation_points,
4809 *   ExcInternalError());
4810 *   Assert(inputs.solution_values[0].size() == dim + 2, ExcInternalError());
4811 *  
4812 *   for (unsigned int p = 0; p < n_evaluation_points; ++p)
4813 *   {
4814 *   for (unsigned int d = 0; d < dim; ++d)
4815 *   computed_quantities[p](d) = (inputs.solution_values[p](d) *
4816 *   EquationData::year_in_seconds * 100);
4817 *  
4818 *   const double pressure =
4819 *   (inputs.solution_values[p](dim) - minimal_pressure);
4820 *   computed_quantities[p](dim) = pressure;
4821 *  
4822 *   const double temperature = inputs.solution_values[p](dim + 1);
4823 *   computed_quantities[p](dim + 1) = temperature;
4824 *  
4825 *   Tensor<2, dim> grad_u;
4826 *   for (unsigned int d = 0; d < dim; ++d)
4827 *   grad_u[d] = inputs.solution_gradients[p][d];
4828 *   const SymmetricTensor<2, dim> strain_rate = symmetrize(grad_u);
4829 *   computed_quantities[p](dim + 2) =
4830 *   2 * EquationData::eta * strain_rate * strain_rate;
4831 *  
4832 *   computed_quantities[p](dim + 3) = partition;
4833 *   }
4834 *   }
4835 *  
4836 *  
4837 * @endcode
4838 *
4839 * The <code>output_results()</code> function has a similar task to the one
4840 * in @ref step_31 "step-31". However, here we are going to demonstrate a different
4841 * technique on how to merge output from different DoFHandler objects. The
4842 * way we're going to achieve this recombination is to create a joint
4843 * DoFHandler that collects both components, the Stokes solution and the
4844 * temperature solution. This can be nicely done by combining the finite
4845 * elements from the two systems to form one FESystem, and let this
4846 * collective system define a new DoFHandler object. To be sure that
4847 * everything was done correctly, we perform a sanity check that ensures
4848 * that we got all the dofs from both Stokes and temperature even in the
4849 * combined system. We then combine the data vectors. Unfortunately, there
4850 * is no straight-forward relation that tells us how to sort Stokes and
4851 * temperature vector into the joint vector. The way we can get around this
4852 * trouble is to rely on the information collected in the FESystem. For each
4853 * dof on a cell, the joint finite element knows to which equation component
4854 * (velocity component, pressure, or temperature) it belongs – that's the
4855 * information we need! So we step through all cells (with iterators into
4856 * all three DoFHandlers moving in sync), and for each joint cell dof, we
4857 * read out that component using the FiniteElement::system_to_base_index
4858 * function (see there for a description of what the various parts of its
4859 * return value contain). We also need to keep track whether we're on a
4860 * Stokes dof or a temperature dof, which is contained in
4861 * joint_fe.system_to_base_index(i).first.first. Eventually, the dof_indices
4862 * data structures on either of the three systems tell us how the relation
4863 * between global vector and local dofs looks like on the present cell,
4864 * which concludes this tedious work. We make sure that each processor only
4865 * works on the subdomain it owns locally (and not on ghost or artificial
4866 * cells) when building the joint solution vector. The same will then have
4867 * to be done in DataOut::build_patches(), but that function does so
4868 * automatically.
4869 *
4870
4871 *
4872 * What we end up with is a set of patches that we can write using the
4873 * functions in DataOutBase in a variety of output formats. Here, we then
4874 * have to pay attention that what each processor writes is really only its
4875 * own part of the domain, i.e. we will want to write each processor's
4876 * contribution into a separate file. This we do by adding an additional
4877 * number to the filename when we write the solution. This is not really
4878 * new, we did it similarly in @ref step_40 "step-40". Note that we write in the compressed
4879 * format @p .vtu instead of plain vtk files, which saves quite some
4880 * storage.
4881 *
4882
4883 *
4884 * All the rest of the work is done in the PostProcessor class.
4885 *
4886 * @code
4887 *   template <int dim>
4888 *   void BoussinesqFlowProblem<dim>::output_results()
4889 *   {
4890 *   TimerOutput::Scope timer_section(computing_timer, "Postprocessing");
4891 *  
4892 *   const FESystem<dim> joint_fe(stokes_fe, 1, temperature_fe, 1);
4893 *  
4894 *   DoFHandler<dim> joint_dof_handler(triangulation);
4895 *   joint_dof_handler.distribute_dofs(joint_fe);
4896 *   Assert(joint_dof_handler.n_dofs() ==
4897 *   stokes_dof_handler.n_dofs() + temperature_dof_handler.n_dofs(),
4898 *   ExcInternalError());
4899 *  
4900 *   TrilinosWrappers::MPI::Vector joint_solution;
4901 *   joint_solution.reinit(joint_dof_handler.locally_owned_dofs(),
4902 *   MPI_COMM_WORLD);
4903 *  
4904 *   {
4905 *   std::vector<types::global_dof_index> local_joint_dof_indices(
4906 *   joint_fe.n_dofs_per_cell());
4907 *   std::vector<types::global_dof_index> local_stokes_dof_indices(
4908 *   stokes_fe.n_dofs_per_cell());
4909 *   std::vector<types::global_dof_index> local_temperature_dof_indices(
4910 *   temperature_fe.n_dofs_per_cell());
4911 *  
4912 *   typename DoFHandler<dim>::active_cell_iterator
4913 *   joint_cell = joint_dof_handler.begin_active(),
4914 *   joint_endc = joint_dof_handler.end(),
4915 *   stokes_cell = stokes_dof_handler.begin_active(),
4916 *   temperature_cell = temperature_dof_handler.begin_active();
4917 *   for (; joint_cell != joint_endc;
4918 *   ++joint_cell, ++stokes_cell, ++temperature_cell)
4919 *   if (joint_cell->is_locally_owned())
4920 *   {
4921 *   joint_cell->get_dof_indices(local_joint_dof_indices);
4922 *   stokes_cell->get_dof_indices(local_stokes_dof_indices);
4923 *   temperature_cell->get_dof_indices(local_temperature_dof_indices);
4924 *  
4925 *   for (unsigned int i = 0; i < joint_fe.n_dofs_per_cell(); ++i)
4926 *   if (joint_fe.system_to_base_index(i).first.first == 0)
4927 *   {
4928 *   Assert(joint_fe.system_to_base_index(i).second <
4929 *   local_stokes_dof_indices.size(),
4930 *   ExcInternalError());
4931 *  
4932 *   joint_solution(local_joint_dof_indices[i]) = stokes_solution(
4933 *   local_stokes_dof_indices[joint_fe.system_to_base_index(i)
4934 *   .second]);
4935 *   }
4936 *   else
4937 *   {
4938 *   Assert(joint_fe.system_to_base_index(i).first.first == 1,
4939 *   ExcInternalError());
4940 *   Assert(joint_fe.system_to_base_index(i).second <
4941 *   local_temperature_dof_indices.size(),
4942 *   ExcInternalError());
4943 *   joint_solution(local_joint_dof_indices[i]) =
4944 *   temperature_solution(
4945 *   local_temperature_dof_indices
4946 *   [joint_fe.system_to_base_index(i).second]);
4947 *   }
4948 *   }
4949 *   }
4950 *  
4951 *   joint_solution.compress(VectorOperation::insert);
4952 *  
4953 *   const IndexSet locally_relevant_joint_dofs =
4954 *   DoFTools::extract_locally_relevant_dofs(joint_dof_handler);
4955 *   TrilinosWrappers::MPI::Vector locally_relevant_joint_solution;
4956 *   locally_relevant_joint_solution.reinit(locally_relevant_joint_dofs,
4957 *   MPI_COMM_WORLD);
4958 *   locally_relevant_joint_solution = joint_solution;
4959 *  
4960 *   Postprocessor postprocessor(Utilities::MPI::this_mpi_process(
4961 *   MPI_COMM_WORLD),
4962 *   stokes_solution.block(1).min());
4963 *  
4964 *   DataOut<dim> data_out;
4965 *   data_out.attach_dof_handler(joint_dof_handler);
4966 *   data_out.add_data_vector(locally_relevant_joint_solution, postprocessor);
4967 *   data_out.build_patches();
4968 *  
4969 *   static int out_index = 0;
4970 *   data_out.write_vtu_with_pvtu_record(
4971 *   "./", "solution", out_index, MPI_COMM_WORLD, 5);
4972 *  
4973 *   ++out_index;
4974 *   }
4975 *  
4976 *  
4977 *  
4978 * @endcode
4979 *
4980 *
4981 * <a name="step_32-BoussinesqFlowProblemrefine_mesh"></a>
4982 * <h4>BoussinesqFlowProblem::refine_mesh</h4>
4983 *
4984
4985 *
4986 * This function isn't really new either. Since the <code>setup_dofs</code>
4987 * function that we call in the middle has its own timer section, we split
4988 * timing this function into two sections. It will also allow us to easily
4989 * identify which of the two is more expensive.
4990 *
4991
4992 *
4993 * One thing of note, however, is that we only want to compute error
4994 * indicators on the locally owned subdomain. In order to achieve this, we
4995 * pass one additional argument to the KellyErrorEstimator::estimate
4996 * function. Note that the vector for error estimates is resized to the
4997 * number of active cells present on the current process, which is less than
4998 * the total number of active cells on all processors (but more than the
4999 * number of locally owned active cells); each processor only has a few
5000 * coarse cells around the locally owned ones, as also explained in @ref step_40 "step-40".
5001 *
5002
5003 *
5004 * The local error estimates are then handed to a %parallel version of
5006 * also @ref step_40 "step-40") which looks at the errors and finds the cells that need
5007 * refinement by comparing the error values across processors. As in
5008 * @ref step_31 "step-31", we want to limit the maximum grid level. So in case some cells
5009 * have been marked that are already at the finest level, we simply clear
5010 * the refine flags.
5011 *
5012 * @code
5013 *   template <int dim>
5014 *   void
5015 *   BoussinesqFlowProblem<dim>::refine_mesh(const unsigned int max_grid_level)
5016 *   {
5018 *   temperature_trans(temperature_dof_handler);
5021 *   stokes_trans(stokes_dof_handler);
5022 *  
5023 *   {
5024 *   TimerOutput::Scope timer_section(computing_timer,
5025 *   "Refine mesh structure, part 1");
5026 *  
5027 *   Vector<float> estimated_error_per_cell(triangulation.n_active_cells());
5028 *  
5030 *   temperature_dof_handler,
5031 *   QGauss<dim - 1>(parameters.temperature_degree + 1),
5032 *   std::map<types::boundary_id, const Function<dim> *>(),
5033 *   temperature_solution,
5034 *   estimated_error_per_cell,
5035 *   ComponentMask(),
5036 *   nullptr,
5037 *   0,
5038 *   triangulation.locally_owned_subdomain());
5039 *  
5041 *   triangulation, estimated_error_per_cell, 0.3, 0.1);
5042 *  
5043 *   if (triangulation.n_levels() > max_grid_level)
5044 *   for (typename Triangulation<dim>::active_cell_iterator cell =
5045 *   triangulation.begin_active(max_grid_level);
5046 *   cell != triangulation.end();
5047 *   ++cell)
5048 *   cell->clear_refine_flag();
5049 *  
5050 * @endcode
5051 *
5052 * With all flags marked as necessary, we can then tell the
5053 * parallel::distributed::SolutionTransfer objects to get ready to
5054 * transfer data from one mesh to the next, which they will do when
5055 * notified by
5056 * Triangulation as part of the @p execute_coarsening_and_refinement() call.
5057 * The syntax is similar to the non-%parallel solution transfer (with the
5058 * exception that here a pointer to the vector entries is enough). The
5059 * remainder of the function further down below is then concerned with
5060 * setting up the data structures again after mesh refinement and
5061 * restoring the solution vectors on the new mesh.
5062 *
5063 * @code
5064 *   const std::vector<const TrilinosWrappers::MPI::Vector *> x_temperature = {
5065 *   &temperature_solution, &old_temperature_solution};
5066 *   const std::vector<const TrilinosWrappers::MPI::BlockVector *> x_stokes = {
5067 *   &stokes_solution, &old_stokes_solution};
5068 *  
5069 *   triangulation.prepare_coarsening_and_refinement();
5070 *  
5071 *   temperature_trans.prepare_for_coarsening_and_refinement(x_temperature);
5072 *   stokes_trans.prepare_for_coarsening_and_refinement(x_stokes);
5073 *  
5074 *   triangulation.execute_coarsening_and_refinement();
5075 *   }
5076 *  
5077 *   setup_dofs();
5078 *  
5079 *   {
5080 *   TimerOutput::Scope timer_section(computing_timer,
5081 *   "Refine mesh structure, part 2");
5082 *  
5083 *   {
5084 *   TrilinosWrappers::MPI::Vector distributed_temp1(temperature_rhs);
5085 *   TrilinosWrappers::MPI::Vector distributed_temp2(temperature_rhs);
5086 *  
5087 *   std::vector<TrilinosWrappers::MPI::Vector *> tmp = {&distributed_temp1,
5088 *   &distributed_temp2};
5089 *   temperature_trans.interpolate(tmp);
5090 *  
5091 * @endcode
5092 *
5093 * enforce constraints to make the interpolated solution conforming on
5094 * the new mesh:
5095 *
5096 * @code
5097 *   temperature_constraints.distribute(distributed_temp1);
5098 *   temperature_constraints.distribute(distributed_temp2);
5099 *  
5100 *   temperature_solution = distributed_temp1;
5101 *   old_temperature_solution = distributed_temp2;
5102 *  
5103 *   Assert(old_temperature_solution.has_ghost_elements(),
5104 *   ExcInternalError());
5105 *   }
5106 *  
5107 *   {
5108 *   TrilinosWrappers::MPI::BlockVector distributed_stokes(stokes_rhs);
5109 *   TrilinosWrappers::MPI::BlockVector old_distributed_stokes(stokes_rhs);
5110 *  
5111 *   std::vector<TrilinosWrappers::MPI::BlockVector *> stokes_tmp = {
5112 *   &distributed_stokes, &old_distributed_stokes};
5113 *  
5114 *   stokes_trans.interpolate(stokes_tmp);
5115 *  
5116 * @endcode
5117 *
5118 * enforce constraints to make the interpolated solution conforming on
5119 * the new mesh:
5120 *
5121 * @code
5122 *   stokes_constraints.distribute(distributed_stokes);
5123 *   stokes_constraints.distribute(old_distributed_stokes);
5124 *  
5125 *   stokes_solution = distributed_stokes;
5126 *   old_stokes_solution = old_distributed_stokes;
5127 *   }
5128 *   }
5129 *   }
5130 *  
5131 *  
5132 *  
5133 * @endcode
5134 *
5135 *
5136 * <a name="step_32-BoussinesqFlowProblemrun"></a>
5137 * <h4>BoussinesqFlowProblem::run</h4>
5138 *
5139
5140 *
5141 * This is the final and controlling function in this class. It, in fact,
5142 * runs the entire rest of the program and is, once more, very similar to
5143 * @ref step_31 "step-31". The only substantial difference is that we use a different mesh
5144 * now (a GridGenerator::hyper_shell instead of a simple cube geometry).
5145 *
5146 * @code
5147 *   template <int dim>
5148 *   void BoussinesqFlowProblem<dim>::run()
5149 *   {
5151 *   Point<dim>(),
5152 *   EquationData::R0,
5153 *   EquationData::R1,
5154 *   (dim == 3) ? 96 : 12,
5155 *   true);
5156 *  
5157 *   global_Omega_diameter = GridTools::diameter(triangulation);
5158 *  
5159 *   triangulation.refine_global(parameters.initial_global_refinement);
5160 *  
5161 *   setup_dofs();
5162 *  
5163 *   unsigned int pre_refinement_step = 0;
5164 *  
5165 *   start_time_iteration:
5166 *  
5167 *   {
5168 *   TrilinosWrappers::MPI::Vector solution(
5169 *   temperature_dof_handler.locally_owned_dofs());
5170 * @endcode
5171 *
5172 * VectorTools::project supports parallel vector classes with most
5173 * standard finite elements via deal.II's own native MatrixFree framework:
5174 * since we use standard Lagrange elements of moderate order this function
5175 * works well here.
5176 *
5177 * @code
5178 *   VectorTools::project(temperature_dof_handler,
5179 *   temperature_constraints,
5180 *   QGauss<dim>(parameters.temperature_degree + 2),
5181 *   EquationData::TemperatureInitialValues<dim>(),
5182 *   solution);
5183 * @endcode
5184 *
5185 * Having so computed the current temperature field, let us set the member
5186 * variable that holds the temperature nodes. Strictly speaking, we really
5187 * only need to set <code>old_temperature_solution</code> since the first
5188 * thing we will do is to compute the Stokes solution that only requires
5189 * the previous time step's temperature field. That said, nothing good can
5190 * come from not initializing the other vectors as well (especially since
5191 * it's a relatively cheap operation and we only have to do it once at the
5192 * beginning of the program) if we ever want to extend our numerical
5193 * method or physical model, and so we initialize
5194 * <code>old_temperature_solution</code> and
5195 * <code>old_old_temperature_solution</code> as well. The assignment makes
5196 * sure that the vectors on the left hand side (which where initialized to
5197 * contain ghost elements as well) also get the correct ghost elements. In
5198 * other words, the assignment here requires communication between
5199 * processors:
5200 *
5201 * @code
5202 *   temperature_solution = solution;
5203 *   old_temperature_solution = solution;
5204 *   old_old_temperature_solution = solution;
5205 *   }
5206 *  
5207 *   timestep_number = 0;
5208 *   time_step = old_time_step = 0;
5209 *  
5210 *   double time = 0;
5211 *  
5212 *   do
5213 *   {
5214 *   pcout << "Timestep " << timestep_number
5215 *   << ": t=" << time / EquationData::year_in_seconds << " years"
5216 *   << std::endl;
5217 *  
5218 *   assemble_stokes_system();
5219 *   build_stokes_preconditioner();
5220 *   assemble_temperature_matrix();
5221 *  
5222 *   solve();
5223 *  
5224 *   pcout << std::endl;
5225 *  
5226 *   if ((timestep_number == 0) &&
5227 *   (pre_refinement_step < parameters.initial_adaptive_refinement))
5228 *   {
5229 *   refine_mesh(parameters.initial_global_refinement +
5230 *   parameters.initial_adaptive_refinement);
5231 *   ++pre_refinement_step;
5232 *   goto start_time_iteration;
5233 *   }
5234 *   else if ((timestep_number > 0) &&
5235 *   (timestep_number % parameters.adaptive_refinement_interval ==
5236 *   0))
5237 *   refine_mesh(parameters.initial_global_refinement +
5238 *   parameters.initial_adaptive_refinement);
5239 *  
5240 *   if ((parameters.generate_graphical_output == true) &&
5241 *   (timestep_number % parameters.graphical_output_interval == 0))
5242 *   output_results();
5243 *  
5244 * @endcode
5245 *
5246 * In order to speed up linear solvers, we extrapolate the solutions
5247 * from the old time levels to the new one. This gives a very good
5248 * initial guess, cutting the number of iterations needed in solvers
5249 * by more than one half. We do not need to extrapolate in the last
5250 * iteration, so if we reached the final time, we stop here.
5251 *
5252
5253 *
5254 * As the last thing during a time step (before actually bumping up
5255 * the number of the time step), we check whether the current time
5256 * step number is divisible by 100, and if so we let the computing
5257 * timer print a summary of CPU times spent so far.
5258 *
5259 * @code
5260 *   if (time > parameters.end_time * EquationData::year_in_seconds)
5261 *   break;
5262 *  
5263 *   TrilinosWrappers::MPI::BlockVector old_old_stokes_solution;
5264 *   old_old_stokes_solution = old_stokes_solution;
5265 *   old_stokes_solution = stokes_solution;
5266 *   old_old_temperature_solution = old_temperature_solution;
5267 *   old_temperature_solution = temperature_solution;
5268 *   if (old_time_step > 0)
5269 *   {
5270 * @endcode
5271 *
5272 * Trilinos sadd does not like ghost vectors even as input. Copy
5273 * into distributed vectors for now:
5274 *
5275 * @code
5276 *   {
5277 *   TrilinosWrappers::MPI::BlockVector distr_solution(stokes_rhs);
5278 *   distr_solution = stokes_solution;
5279 *   TrilinosWrappers::MPI::BlockVector distr_old_solution(stokes_rhs);
5280 *   distr_old_solution = old_old_stokes_solution;
5281 *   distr_solution.sadd(1. + time_step / old_time_step,
5282 *   -time_step / old_time_step,
5283 *   distr_old_solution);
5284 *   stokes_solution = distr_solution;
5285 *   }
5286 *   {
5287 *   TrilinosWrappers::MPI::Vector distr_solution(temperature_rhs);
5288 *   distr_solution = temperature_solution;
5289 *   TrilinosWrappers::MPI::Vector distr_old_solution(temperature_rhs);
5290 *   distr_old_solution = old_old_temperature_solution;
5291 *   distr_solution.sadd(1. + time_step / old_time_step,
5292 *   -time_step / old_time_step,
5293 *   distr_old_solution);
5294 *   temperature_solution = distr_solution;
5295 *   }
5296 *   }
5297 *  
5298 *   if ((timestep_number > 0) && (timestep_number % 100 == 0))
5299 *   computing_timer.print_summary();
5300 *  
5301 *   time += time_step;
5302 *   ++timestep_number;
5303 *   }
5304 *   while (true);
5305 *  
5306 * @endcode
5307 *
5308 * If we are generating graphical output, do so also for the last time
5309 * step unless we had just done so before we left the do-while loop
5310 *
5311 * @code
5312 *   if ((parameters.generate_graphical_output == true) &&
5313 *   !((timestep_number - 1) % parameters.graphical_output_interval == 0))
5314 *   output_results();
5315 *   }
5316 *   } // namespace Step32
5317 *  
5318 *  
5319 *  
5320 * @endcode
5321 *
5322 *
5323 * <a name="step_32-Thecodemaincodefunction"></a>
5324 * <h3>The <code>main</code> function</h3>
5325 *
5326
5327 *
5328 * The main function is short as usual and very similar to the one in
5329 * @ref step_31 "step-31". Since we use a parameter file which is specified as an argument in
5330 * the command line, we have to read it in here and pass it on to the
5331 * Parameters class for parsing. If no filename is given in the command line,
5332 * we simply use the <code>step-32.prm</code> file which is distributed
5333 * together with the program.
5334 *
5335
5336 *
5337 * Because 3d computations are simply very slow unless you throw a lot of
5338 * processors at them, the program defaults to 2d. You can get the 3d version
5339 * by changing the constant dimension below to 3.
5340 *
5341 * @code
5342 *   int main(int argc, char *argv[])
5343 *   {
5344 *   try
5345 *   {
5346 *   using namespace Step32;
5347 *   using namespace dealii;
5348 *  
5349 *   Utilities::MPI::MPI_InitFinalize mpi_initialization(
5350 *   argc, argv, numbers::invalid_unsigned_int);
5351 *  
5352 *   std::string parameter_filename;
5353 *   if (argc >= 2)
5354 *   parameter_filename = argv[1];
5355 *   else
5356 *   parameter_filename = "step-32.prm";
5357 *  
5358 *   const int dim = 2;
5359 *   BoussinesqFlowProblem<dim>::Parameters parameters(parameter_filename);
5360 *   BoussinesqFlowProblem<dim> flow_problem(parameters);
5361 *   flow_problem.run();
5362 *   }
5363 *   catch (std::exception &exc)
5364 *   {
5365 *   std::cerr << std::endl
5366 *   << std::endl
5367 *   << "----------------------------------------------------"
5368 *   << std::endl;
5369 *   std::cerr << "Exception on processing: " << std::endl
5370 *   << exc.what() << std::endl
5371 *   << "Aborting!" << std::endl
5372 *   << "----------------------------------------------------"
5373 *   << std::endl;
5374 *  
5375 *   return 1;
5376 *   }
5377 *   catch (...)
5378 *   {
5379 *   std::cerr << std::endl
5380 *   << std::endl
5381 *   << "----------------------------------------------------"
5382 *   << std::endl;
5383 *   std::cerr << "Unknown exception!" << std::endl
5384 *   << "Aborting!" << std::endl
5385 *   << "----------------------------------------------------"
5386 *   << std::endl;
5387 *   return 1;
5388 *   }
5389 *  
5390 *   return 0;
5391 *   }
5392 * @endcode
5393<a name="step_32-Results"></a><h1>Results</h1>
5394
5395
5396When run, the program simulates convection in 3d in much the same way
5397as @ref step_31 "step-31" did, though with an entirely different testcase.
5398
5399
5400<a name="step_32-Comparisonofresultswithstep31"></a><h3>Comparison of results with step-31</h3>
5401
5402
5403Before we go to this testcase, however, let us show a few results from a
5404slightly earlier version of this program that was solving exactly the
5405testcase we used in @ref step_31 "step-31", just that we now solve it in parallel and with
5406much higher resolution. We show these results mainly for comparison.
5407
5408Here are two images that show this higher resolution if we choose a 3d
5409computation in <code>main()</code> and if we set
5410<code>initial_refinement=3</code> and
5411<code>n_pre_refinement_steps=4</code>. At the time steps shown, the
5412meshes had around 72,000 and 236,000 cells, for a total of 2,680,000
5413and 8,250,000 degrees of freedom, respectively, more than an order of
5414magnitude more than we had available in @ref step_31 "step-31":
5415
5416<table align="center" class="doxtable">
5417 <tr>
5418 <td>
5419 <img src="https://www.dealii.org/images/steps/developer/step-32.3d.cube.0.png" alt="">
5420 </td>
5421 </tr>
5422 <tr>
5423 <td>
5424 <img src="https://www.dealii.org/images/steps/developer/step-32.3d.cube.1.png" alt="">
5425 </td>
5426 </tr>
5427</table>
5428
5429The computation was done on a subset of 50 processors of the Brazos
5430cluster at Texas A&amp;M University.
5431
5432
5433<a name="step_32-Resultsfora2dcircularshelltestcase"></a><h3>Results for a 2d circular shell testcase</h3>
5434
5435
5436Next, we will run @ref step_32 "step-32" with the parameter file in the directory with one
5437change: we increase the final time to 1e9. Here we are using 16 processors. The
5438command to launch is (note that @ref step_32 "step-32".prm is the default):
5439
5440<code>
5441<pre>
5442\$ mpirun -np 16 ./step-32
5443</pre>
5444</code>
5445
5446Note that running a job on a cluster typically requires going through a job
5447scheduler, which we won't discuss here. The output will look roughly like
5448this:
5449
5450<code>
5451<pre>
5452\$ mpirun -np 16 ./step-32
5453Number of active cells: 12,288 (on 6 levels)
5454Number of degrees of freedom: 186,624 (99,840+36,864+49,920)
5455
5456Timestep 0: t=0 years
5457
5458 Rebuilding Stokes preconditioner...
5459 Solving Stokes system... 41 iterations.
5460 Maximal velocity: 60.4935 cm/year
5461 Time step: 18166.9 years
5462 17 CG iterations for temperature
5463 Temperature range: 973 4273.16
5464
5465Number of active cells: 15,921 (on 7 levels)
5466Number of degrees of freedom: 252,723 (136,640+47,763+68,320)
5467
5468Timestep 0: t=0 years
5469
5470 Rebuilding Stokes preconditioner...
5471 Solving Stokes system... 50 iterations.
5472 Maximal velocity: 60.3223 cm/year
5473 Time step: 10557.6 years
5474 19 CG iterations for temperature
5475 Temperature range: 973 4273.16
5476
5477Number of active cells: 19,926 (on 8 levels)
5478Number of degrees of freedom: 321,246 (174,312+59,778+87,156)
5479
5480Timestep 0: t=0 years
5481
5482 Rebuilding Stokes preconditioner...
5483 Solving Stokes system... 50 iterations.
5484 Maximal velocity: 57.8396 cm/year
5485 Time step: 5453.78 years
5486 18 CG iterations for temperature
5487 Temperature range: 973 4273.16
5488
5489Timestep 1: t=5453.78 years
5490
5491 Solving Stokes system... 49 iterations.
5492 Maximal velocity: 59.0231 cm/year
5493 Time step: 5345.86 years
5494 18 CG iterations for temperature
5495 Temperature range: 973 4273.16
5496
5497Timestep 2: t=10799.6 years
5498
5499 Solving Stokes system... 24 iterations.
5500 Maximal velocity: 60.2139 cm/year
5501 Time step: 5241.51 years
5502 17 CG iterations for temperature
5503 Temperature range: 973 4273.16
5504
5505[...]
5506
5507Timestep 100: t=272151 years
5508
5509 Solving Stokes system... 21 iterations.
5510 Maximal velocity: 161.546 cm/year
5511 Time step: 1672.96 years
5512 17 CG iterations for temperature
5513 Temperature range: 973 4282.57
5514
5515Number of active cells: 56,085 (on 8 levels)
5516Number of degrees of freedom: 903,408 (490,102+168,255+245,051)
5517
5518
5519
5520+---------------------------------------------+------------+------------+
5521| Total wallclock time elapsed since start | 115s | |
5522| | | |
5523| Section | no. calls | wall time | % of total |
5524+---------------------------------+-----------+------------+------------+
5525| Assemble Stokes system | 103 | 2.82s | 2.5% |
5526| Assemble temperature matrices | 12 | 0.452s | 0.39% |
5527| Assemble temperature rhs | 103 | 11.5s | 10% |
5528| Build Stokes preconditioner | 12 | 2.09s | 1.8% |
5529| Solve Stokes system | 103 | 90.4s | 79% |
5530| Solve temperature system | 103 | 1.53s | 1.3% |
5531| Postprocessing | 3 | 0.532s | 0.46% |
5532| Refine mesh structure, part 1 | 12 | 0.93s | 0.81% |
5533| Refine mesh structure, part 2 | 12 | 0.384s | 0.33% |
5534| Setup dof systems | 13 | 2.96s | 2.6% |
5535+---------------------------------+-----------+------------+------------+
5536
5537[...]
5538
5539+---------------------------------------------+------------+------------+
5540| Total wallclock time elapsed since start | 9.14e+04s | |
5541| | | |
5542| Section | no. calls | wall time | % of total |
5543+---------------------------------+-----------+------------+------------+
5544| Assemble Stokes system | 47045 | 2.05e+03s | 2.2% |
5545| Assemble temperature matrices | 4707 | 310s | 0.34% |
5546| Assemble temperature rhs | 47045 | 8.7e+03s | 9.5% |
5547| Build Stokes preconditioner | 4707 | 1.48e+03s | 1.6% |
5548| Solve Stokes system | 47045 | 7.34e+04s | 80% |
5549| Solve temperature system | 47045 | 1.46e+03s | 1.6% |
5550| Postprocessing | 1883 | 222s | 0.24% |
5551| Refine mesh structure, part 1 | 4706 | 641s | 0.7% |
5552| Refine mesh structure, part 2 | 4706 | 259s | 0.28% |
5553| Setup dof systems | 4707 | 1.86e+03s | 2% |
5554+---------------------------------+-----------+------------+------------+
5555</pre>
5556</code>
5557
5558The simulation terminates when the time reaches the 1 billion years
5559selected in the input file. You can extrapolate from this how long a
5560simulation would take for a different final time (the time step size
5561ultimately settles on somewhere around 20,000 years, so computing for
5562two billion years will take 100,000 time steps, give or take 20%). As
5563can be seen here, we spend most of the compute time in assembling
5564linear systems and &mdash; above all &mdash; in solving Stokes
5565systems.
5566
5567
5568To demonstrate the output we show the output from every 1250th time step here:
5569<table>
5570 <tr>
5571 <td>
5572 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-000.png" alt="">
5573 </td>
5574 <td>
5575 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-050.png" alt="">
5576 </td>
5577 <td>
5578 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-100.png" alt="">
5579 </td>
5580 </tr>
5581 <tr>
5582 <td>
5583 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-150.png" alt="">
5584 </td>
5585 <td>
5586 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-200.png" alt="">
5587 </td>
5588 <td>
5589 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-250.png" alt="">
5590 </td>
5591 </tr>
5592 <tr>
5593 <td>
5594 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-300.png" alt="">
5595 </td>
5596 <td>
5597 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-350.png" alt="">
5598 </td>
5599 <td>
5600 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-400.png" alt="">
5601 </td>
5602 </tr>
5603 <tr>
5604 <td>
5605 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-450.png" alt="">
5606 </td>
5607 <td>
5608 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-500.png" alt="">
5609 </td>
5610 <td>
5611 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-550.png" alt="">
5612 </td>
5613 </tr>
5614 <tr>
5615 <td>
5616 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-time-600.png" alt="">
5617 </td>
5618 <td>
5619 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-cells.png" alt="">
5620 </td>
5621 <td>
5622 <img src="https://www.dealii.org/images/steps/developer/step-32-2d-partition.png" alt="">
5623 </td>
5624 </tr>
5625</table>
5626
5627The last two images show the grid as well as the partitioning of the mesh for
5628the same computation with 16 subdomains and 16 processors. The full dynamics of
5629this simulation are really only visible by looking at an animation, for example
5630the one <a
5631href="https://www.dealii.org/images/steps/developer/step-32-2d-temperature.webm">shown
5632on this site</a>. This image is well worth watching due to its artistic quality
5633and entrancing depiction of the evolution of the magma plumes.
5634
5635If you watch the movie, you'll see that the convection pattern goes
5636through several stages: First, it gets rid of the instable temperature
5637layering with the hot material overlain by the dense cold
5638material. After this great driver is removed and we have a sort of
5639stable situation, a few blobs start to separate from the hot boundary
5640layer at the inner ring and rise up, with a few cold fingers also
5641dropping down from the outer boundary layer. During this phase, the solution
5642remains mostly symmetric, reflecting the 12-fold symmetry of the
5643original mesh. In a final phase, the fluid enters vigorous chaotic
5644stirring in which all symmetries are lost. This is a pattern that then
5645continues to dominate flow.
5646
5647These different phases can also be identified if we look at the
5648maximal velocity as a function of time in the simulation:
5649
5650<img src="https://www.dealii.org/images/steps/developer/step-32.2d.t_vs_vmax.png" alt="">
5651
5652Here, the velocity (shown in centimeters per year) becomes very large,
5653to the order of several meters per year) at the beginning when the
5654temperature layering is instable. It then calms down to relatively
5655small values before picking up again in the chaotic stirring
5656regime. There, it remains in the range of 10-40 centimeters per year,
5657quite within the physically expected region.
5658
5659
5660<a name="step_32-Resultsfora3dsphericalshelltestcase"></a><h3>Results for a 3d spherical shell testcase</h3>
5661
5662
56633d computations are very expensive computationally. Furthermore, as
5664seen above, interesting behavior only starts after quite a long time
5665requiring more CPU hours than is available on a typical
5666cluster. Consequently, rather than showing a complete simulation here,
5667let us simply show a couple of pictures we have obtained using the
5668successor to this program, called <i>ASPECT</i> (short for <i>Advanced
5669%Solver for Problems in Earth's ConvecTion</i>), that is being
5670developed independently of deal.II and that already incorporates some
5671of the extensions discussed below. The following two pictures show
5672isocontours of the temperature and the partition of the domain (along
5673with the mesh) onto 512 processors:
5674
5675<p align="center">
5676<img src="https://www.dealii.org/images/steps/developer/step-32.3d-sphere.solution.png" alt="">
5677
5678<img src="https://www.dealii.org/images/steps/developer/step-32.3d-sphere.partition.png" alt="">
5679</p>
5680
5681
5682<a name="step-32-extensions"></a>
5683<a name="step_32-Possibilitiesforextensions"></a><h3>Possibilities for extensions</h3>
5684
5685
5686There are many directions in which this program could be extended. As
5687mentioned at the end of the introduction, most of these are under active
5688development in the <i>ASPECT</i> (short for <i>Advanced %Solver for Problems
5689in Earth's ConvecTion</i>) code at the time this tutorial program is being
5690finished. Specifically, the following are certainly topics that one should
5691address to make the program more useful:
5692
5693<ul>
5694 <li> <b>Adiabatic heating/cooling:</b>
5695 The temperature field we get in our simulations after a while
5696 is mostly constant with boundary layers at the inner and outer
5697 boundary, and streamers of cold and hot material mixing
5698 everything. Yet, this doesn't match our expectation that things
5699 closer to the earth core should be hotter than closer to the
5700 surface. The reason is that the energy equation we have used does
5701 not include a term that describes adiabatic cooling and heating:
5702 rock, like gas, heats up as you compress it. Consequently, material
5703 that rises up cools adiabatically, and cold material that sinks down
5704 heats adiabatically. The correct temperature equation would
5705 therefore look somewhat like this:
5706 @f{eqnarray*}{
5707 \frac{D T}{Dt}
5708 -
5709 \nabla \cdot \kappa \nabla T &=& \gamma + \tau\frac{Dp}{Dt},
5710 @f}
5711 or, expanding the advected derivative @f$\frac{D}{Dt} =
5712 \frac{\partial}{\partial t} + \mathbf u \cdot \nabla@f$:
5713 @f{eqnarray*}{
5714 \frac{\partial T}{\partial t}
5715 +
5716 {\mathbf u} \cdot \nabla T
5717 -
5718 \nabla \cdot \kappa \nabla T &=& \gamma +
5719 \tau\left\{\frac{\partial
5720 p}{\partial t} + \mathbf u \cdot \nabla p \right\}.
5721 @f}
5722 In other words, as pressure increases in a rock volume
5723 (@f$\frac{Dp}{Dt}>0@f$) we get an additional heat source, and vice
5724 versa.
5725
5726 The time derivative of the pressure is a bit awkward to
5727 implement. If necessary, one could approximate using the fact
5728 outlined in the introduction that the pressure can be decomposed
5729 into a dynamic component due to temperature differences and the
5730 resulting flow, and a static component that results solely from the
5731 static pressure of the overlying rock. Since the latter is much
5732 bigger, one may approximate @f$p\approx p_{\text{static}}=-\rho_{\text{ref}}
5733 [1+\beta T_{\text{ref}}] \varphi@f$, and consequently
5734 @f$\frac{Dp}{Dt} \approx \left\{- \mathbf u \cdot \nabla \rho_{\text{ref}}
5735 [1+\beta T_{\text{ref}}]\varphi\right\} = \rho_{\text{ref}}
5736 [1+\beta T_{\text{ref}}] \mathbf u \cdot \mathbf g@f$.
5737 In other words, if the fluid is moving in the direction of gravity
5738 (downward) it will be compressed and because in that case @f$\mathbf u
5739 \cdot \mathbf g > 0@f$ we get a positive heat source. Conversely, the
5740 fluid will cool down if it moves against the direction of gravity.
5741
5742<li> <b>Compressibility:</b>
5743 As already hinted at in the temperature model above,
5744 mantle rocks are not incompressible. Rather, given the enormous pressures in
5745 the earth mantle (at the core-mantle boundary, the pressure is approximately
5746 140 GPa, equivalent to 1,400,000 times atmospheric pressure), rock actually
5747 does compress to something around 1.5 times the density it would have
5748 at surface pressure. Modeling this presents any number of
5749 difficulties. Primarily, the mass conservation equation is no longer
5750 @f$\textrm{div}\;\mathbf u=0@f$ but should read
5751 @f$\textrm{div}(\rho\mathbf u)=0@f$ where the density @f$\rho@f$ is now no longer
5752 spatially constant but depends on temperature and pressure. A consequence is
5753 that the model is now no longer linear; a linearized version of the Stokes
5754 equation is also no longer symmetric requiring us to rethink preconditioners
5755 and, possibly, even the discretization. We won't go into detail here as to
5756 how this can be resolved.
5757
5758<li> <b>Nonlinear material models:</b> As already hinted at in various places,
5759 material parameters such as the density, the viscosity, and the various
5760 thermal parameters are not constant throughout the earth mantle. Rather,
5761 they nonlinearly depend on the pressure and temperature, and in the case of
5762 the viscosity on the strain rate @f$\varepsilon(\mathbf u)@f$. For complicated
5763 models, the only way to solve such models accurately may be to actually
5764 iterate this dependence out in each time step, rather than simply freezing
5765 coefficients at values extrapolated from the previous time step(s).
5766
5767<li> <b>Checkpoint/restart:</b> Running this program in 2d on a number of
5768 processors allows solving realistic models in a day or two. However, in 3d,
5769 compute times are so large that one runs into two typical problems: (i) On
5770 most compute clusters, the queuing system limits run times for individual
5771 jobs are to 2 or 3 days; (ii) losing the results of a computation due to
5772 hardware failures, misconfigurations, or power outages is a shame when
5773 running on hundreds of processors for a couple of days. Both of these
5774 problems can be addressed by periodically saving the state of the program
5775 and, if necessary, restarting the program at this point. This technique is
5776 commonly called <i>checkpoint/restart</i> and it requires that the entire
5777 state of the program is written to a permanent storage location (e.g. a hard
5778 drive). Given the complexity of the data structures of this program, this is
5779 not entirely trivial (it may also involve writing gigabytes or more of
5780 data), but it can be made easier by realizing that one can save the state
5781 between two time steps where it essentially only consists of the mesh and
5782 solution vectors; during restart one would then first re-enumerate degrees
5783 of freedom in the same way as done before and then re-assemble
5784 matrices. Nevertheless, given the distributed nature of the data structures
5785 involved here, saving and restoring the state of a program is not
5786 trivial. An additional complexity is introduced by the fact that one may
5787 want to change the number of processors between runs, for example because
5788 one may wish to continue computing on a mesh that is finer than the one used
5789 to precompute a starting temperature field at an intermediate time.
5790
5791<li> <b>Predictive postprocessing:</b> The point of computations like this is
5792 not simply to solve the equations. Rather, it is typically the exploration
5793 of different physical models and their comparison with things that we can
5794 measure at the earth surface, in order to find which models are realistic
5795 and which are contradicted by reality. To this end, we need to compute
5796 quantities from our solution vectors that are related to what we can
5797 observe. Among these are, for example, heatfluxes at the surface of the
5798 earth, as well as seismic velocities throughout the mantle as these affect
5799 earthquake waves that are recorded by seismographs.
5800
5801<li> <b>Better refinement criteria:</b> As can be seen above for the
58023d case, the mesh in 3d is primarily refined along the inner
5803boundary. This is because the boundary layer there is stronger than
5804any other transition in the domain, leading us to refine there almost
5805exclusively and basically not at all following the plumes. One
5806certainly needs better refinement criteria to track the parts of the
5807solution we are really interested in better than the criterion used
5808here, namely the KellyErrorEstimator applied to the temperature, is
5809able to.
5810</ul>
5811
5812
5813There are many other ways to extend the current program. However, rather than
5814discussing them here, let us point to the much larger open
5815source code ASPECT (see https://aspect.geodynamics.org/ ) that constitutes the
5816further development of @ref step_32 "step-32" and that already includes many such possible
5817extensions.
5818 *
5819 *
5820<a name="step_32-PlainProg"></a>
5821<h1> The plain program</h1>
5822@include "step-32.cc"
5823*/
virtual void build_patches(const unsigned int n_subdivisions=0)
Definition data_out.cc:1062
void reinit(const Triangulation< dim, spacedim > &tria)
active_cell_iterator begin_active(const unsigned int level=0) const
Definition fe_q.h:550
std::pair< std::pair< unsigned int, unsigned int >, unsigned int > system_to_base_index(const unsigned int index) const
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
static void estimate(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Quadrature< dim - 1 > &quadrature, const std::map< types::boundary_id, const Function< spacedim, Number > * > &neumann_bc, const ReadVector< Number > &solution, Vector< float > &error, const ComponentMask &component_mask={}, const Function< spacedim > *coefficients=nullptr, const unsigned int n_threads=numbers::invalid_unsigned_int, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id, const types::material_id material_id=numbers::invalid_material_id, const Strategy strategy=cell_diameter_over_24)
Definition point.h:111
numbers::NumberTraits< Number >::real_type norm() const
Point< 3 > vertices[4]
Point< 2 > second
Definition grid_out.cc:4624
Point< 2 > first
Definition grid_out.cc:4623
unsigned int level
Definition grid_out.cc:4626
__global__ void set(Number *val, const Number s, const size_type N)
#define Assert(cond, exc)
#define AssertThrow(cond, exc)
typename ActiveSelector::active_cell_iterator active_cell_iterator
void loop(IteratorType begin, std_cxx20::type_identity_t< IteratorType > end, DOFINFO &dinfo, INFOBOX &info, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(DOFINFO &, DOFINFO &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, AssemblerType &assembler, const LoopControl &lctrl=LoopControl())
Definition loop.h:442
UpdateFlags
@ update_values
Shape function values.
@ update_JxW_values
Transformed quadrature weights.
@ update_gradients
Shape function gradients.
@ update_quadrature_points
Transformed quadrature points.
std::vector< value_type > split(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const value_type parent_value)
const Event initial
Definition event.cc:64
const Event remesh
Definition event.cc:65
void approximate(const SynchronousIterators< std::tuple< typename DoFHandler< dim, spacedim >::active_cell_iterator, Vector< float >::iterator > > &cell, const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof_handler, const InputVector &solution, const unsigned int component)
Expression sign(const Expression &x)
void extract_constant_modes(const DoFHandler< dim, spacedim > &dof_handler, const ComponentMask &component_mask, std::vector< std::vector< bool > > &constant_modes)
void extrapolate(const DoFHandler< dim, spacedim > &dof1, const InVector &z1, const DoFHandler< dim, spacedim > &dof2, OutVector &z2)
void hyper_shell(Triangulation< dim > &tria, const Point< dim > &center, const double inner_radius, const double outer_radius, const unsigned int n_cells=0, bool colorize=false)
void refine(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold, const unsigned int max_to_mark=numbers::invalid_unsigned_int)
void scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
spacedim & mapping
spacedim const Point< spacedim > & p
Definition grid_tools.h:990
const std::vector< bool > & used
spacedim & mesh
Definition grid_tools.h:989
double volume(const Triangulation< dim, spacedim > &tria)
double diameter(const Triangulation< dim, spacedim > &tria)
if(marked_vertices.size() !=0) for(auto it
for(unsigned int j=best_vertex+1;j< vertices.size();++j) if(vertices_to_use[j])
@ valid
Iterator points to a valid object.
@ matrix
Contents is actually a matrix.
@ symmetric
Matrix is symmetric.
double norm(const FEValuesBase< dim > &fe, const ArrayView< const std::vector< Tensor< 1, dim > > > &Du)
Definition divergence.h:471
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition utilities.cc:191
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
std::vector< unsigned int > serial(const std::vector< unsigned int > &targets, const std::function< RequestType(const unsigned int)> &create_request, const std::function< AnswerType(const unsigned int, const RequestType &)> &answer_request, const std::function< void(const unsigned int, const AnswerType &)> &process_answer, const MPI_Comm comm)
T sum(const T &t, const MPI_Comm mpi_communicator)
T max(const T &t, const MPI_Comm mpi_communicator)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
Definition mpi.cc:107
std::string compress(const std::string &input)
Definition utilities.cc:389
void project(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const AffineConstraints< typename VectorType::value_type > &constraints, const Quadrature< dim > &quadrature, const Function< spacedim, typename VectorType::value_type > &function, VectorType &vec, const bool enforce_zero_boundary=false, const Quadrature< dim - 1 > &q_boundary=(dim > 1 ? QGauss< dim - 1 >(2) :Quadrature< dim - 1 >(0)), const bool project_to_boundary_first=false)
spacedim const DoFHandler< dim, spacedim > const FullMatrix< double > & transfer
void run(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length, const unsigned int chunk_size)
void run(const std::vector< std::vector< Iterator > > &colored_iterators, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length=2 *MultithreadInfo::n_threads(), const unsigned int chunk_size=8)
void abort(const ExceptionBase &exc) noexcept
bool check(const ConstraintKinds kind_in, const unsigned int dim)
long double gamma(const unsigned int n)
int(&) functions(const void *v1, const void *v2)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
static constexpr double PI
Definition numbers.h:259
void refine_and_coarsen_fixed_fraction(::Triangulation< dim, spacedim > &tria, const ::Vector< Number > &criteria, const double top_fraction_of_error, const double bottom_fraction_of_error, const VectorTools::NormType norm_type=VectorTools::L1_norm)
const InputIterator OutputIterator out
Definition parallel.h:167
const Iterator const std_cxx20::type_identity_t< Iterator > & end
Definition parallel.h:610
const InputIterator OutputIterator const Function & function
Definition parallel.h:168
STL namespace.
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > cos(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sin(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
Definition types.h:32
unsigned int subdomain_id
Definition types.h:43
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation