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