Reference documentation for deal.II version 9.5.0
\(\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-44.h
Go to the documentation of this file.
1)
1885 *   {}
1886 *  
1887 * @endcode
1888 *
1889 * Solve for the displacement using a Newton-Raphson method. We break this
1890 * function into the nonlinear loop and the function that solves the
1891 * linearized Newton-Raphson step:
1892 *
1893 * @code
1894 *   void solve_nonlinear_timestep(BlockVector<double> &solution_delta);
1895 *  
1896 *   std::pair<unsigned int, double>
1897 *   solve_linear_system(BlockVector<double> &newton_update);
1898 *  
1899 * @endcode
1900 *
1901 * Solution retrieval as well as post-processing and writing data to file :
1902 *
1903 * @code
1905 *   get_total_solution(const BlockVector<double> &solution_delta) const;
1906 *  
1907 *   void output_results() const;
1908 *  
1909 * @endcode
1910 *
1911 * Finally, some member variables that describe the current state: A
1912 * collection of the parameters used to describe the problem setup...
1913 *
1914 * @code
1915 *   Parameters::AllParameters parameters;
1916 *  
1917 * @endcode
1918 *
1919 * ...the volume of the reference configuration...
1920 *
1921 * @code
1922 *   double vol_reference;
1923 *  
1924 * @endcode
1925 *
1926 * ...and description of the geometry on which the problem is solved:
1927 *
1928 * @code
1930 *  
1931 * @endcode
1932 *
1933 * Also, keep track of the current time and the time spent evaluating
1934 * certain functions
1935 *
1936 * @code
1937 *   Time time;
1938 *   mutable TimerOutput timer;
1939 *  
1940 * @endcode
1941 *
1942 * A storage object for quadrature point information. As opposed to
1943 * @ref step_18 "step-18", deal.II's native quadrature point data manager is employed
1944 * here.
1945 *
1946 * @code
1947 *   CellDataStorage<typename Triangulation<dim>::cell_iterator,
1948 *   PointHistory<dim>>
1949 *   quadrature_point_history;
1950 *  
1951 * @endcode
1952 *
1953 * A description of the finite-element system including the displacement
1954 * polynomial degree, the degree-of-freedom handler, number of DoFs per
1955 * cell and the extractor objects used to retrieve information from the
1956 * solution vectors:
1957 *
1958 * @code
1959 *   const unsigned int degree;
1960 *   const FESystem<dim> fe;
1961 *   DoFHandler<dim> dof_handler;
1962 *   const unsigned int dofs_per_cell;
1963 *   const FEValuesExtractors::Vector u_fe;
1964 *   const FEValuesExtractors::Scalar p_fe;
1965 *   const FEValuesExtractors::Scalar J_fe;
1966 *  
1967 * @endcode
1968 *
1969 * Description of how the block-system is arranged. There are 3 blocks,
1970 * the first contains a vector DOF @f$\mathbf{u}@f$ while the other two
1971 * describe scalar DOFs, @f$\widetilde{p}@f$ and @f$\widetilde{J}@f$.
1972 *
1973 * @code
1974 *   static const unsigned int n_blocks = 3;
1975 *   static const unsigned int n_components = dim + 2;
1976 *   static const unsigned int first_u_component = 0;
1977 *   static const unsigned int p_component = dim;
1978 *   static const unsigned int J_component = dim + 1;
1979 *  
1980 *   enum
1981 *   {
1982 *   u_dof = 0,
1983 *   p_dof = 1,
1984 *   J_dof = 2
1985 *   };
1986 *  
1987 *   std::vector<types::global_dof_index> dofs_per_block;
1988 *   std::vector<types::global_dof_index> element_indices_u;
1989 *   std::vector<types::global_dof_index> element_indices_p;
1990 *   std::vector<types::global_dof_index> element_indices_J;
1991 *  
1992 * @endcode
1993 *
1994 * Rules for Gauss-quadrature on both the cell and faces. The number of
1995 * quadrature points on both cells and faces is recorded.
1996 *
1997 * @code
1998 *   const QGauss<dim> qf_cell;
1999 *   const QGauss<dim - 1> qf_face;
2000 *   const unsigned int n_q_points;
2001 *   const unsigned int n_q_points_f;
2002 *  
2003 * @endcode
2004 *
2005 * Objects that store the converged solution and right-hand side vectors,
2006 * as well as the tangent matrix. There is an AffineConstraints object used
2007 * to keep track of constraints. We make use of a sparsity pattern
2008 * designed for a block system.
2009 *
2010 * @code
2011 *   AffineConstraints<double> constraints;
2012 *   BlockSparsityPattern sparsity_pattern;
2013 *   BlockSparseMatrix<double> tangent_matrix;
2014 *   BlockVector<double> system_rhs;
2015 *   BlockVector<double> solution_n;
2016 *  
2017 * @endcode
2018 *
2019 * Then define a number of variables to store norms and update norms and
2020 * normalization factors.
2021 *
2022 * @code
2023 *   struct Errors
2024 *   {
2025 *   Errors()
2026 *   : norm(1.0)
2027 *   , u(1.0)
2028 *   , p(1.0)
2029 *   , J(1.0)
2030 *   {}
2031 *  
2032 *   void reset()
2033 *   {
2034 *   norm = 1.0;
2035 *   u = 1.0;
2036 *   p = 1.0;
2037 *   J = 1.0;
2038 *   }
2039 *   void normalize(const Errors &rhs)
2040 *   {
2041 *   if (rhs.norm != 0.0)
2042 *   norm /= rhs.norm;
2043 *   if (rhs.u != 0.0)
2044 *   u /= rhs.u;
2045 *   if (rhs.p != 0.0)
2046 *   p /= rhs.p;
2047 *   if (rhs.J != 0.0)
2048 *   J /= rhs.J;
2049 *   }
2050 *  
2051 *   double norm, u, p, J;
2052 *   };
2053 *  
2054 *   Errors error_residual, error_residual_0, error_residual_norm, error_update,
2055 *   error_update_0, error_update_norm;
2056 *  
2057 * @endcode
2058 *
2059 * Methods to calculate error measures
2060 *
2061 * @code
2062 *   void get_error_residual(Errors &error_residual);
2063 *  
2064 *   void get_error_update(const BlockVector<double> &newton_update,
2065 *   Errors & error_update);
2066 *  
2067 *   std::pair<double, double> get_error_dilation() const;
2068 *  
2069 * @endcode
2070 *
2071 * Compute the volume in the spatial configuration
2072 *
2073 * @code
2074 *   double compute_vol_current() const;
2075 *  
2076 * @endcode
2077 *
2078 * Print information to screen in a pleasing way...
2079 *
2080 * @code
2081 *   static void print_conv_header();
2082 *  
2083 *   void print_conv_footer();
2084 *   };
2085 *  
2086 * @endcode
2087 *
2088 *
2089 * <a name="ImplementationofthecodeSolidcodeclass"></a>
2090 * <h3>Implementation of the <code>Solid</code> class</h3>
2091 *
2092
2093 *
2094 *
2095 * <a name="Publicinterface"></a>
2096 * <h4>Public interface</h4>
2097 *
2098
2099 *
2100 * We initialize the Solid class using data extracted from the parameter file.
2101 *
2102 * @code
2103 *   template <int dim>
2104 *   Solid<dim>::Solid(const std::string &input_file)
2105 *   : parameters(input_file)
2106 *   , vol_reference(0.)
2107 *   , triangulation(Triangulation<dim>::maximum_smoothing)
2108 *   , time(parameters.end_time, parameters.delta_t)
2109 *   , timer(std::cout, TimerOutput::summary, TimerOutput::wall_times)
2110 *   , degree(parameters.poly_degree)
2111 *   ,
2112 * @endcode
2113 *
2114 * The Finite Element System is composed of dim continuous displacement
2115 * DOFs, and discontinuous pressure and dilatation DOFs. In an attempt to
2116 * satisfy the Babuska-Brezzi or LBB stability conditions (see Hughes
2117 * (2000)), we set up a @f$Q_n \times DGP_{n-1} \times DGP_{n-1}@f$
2118 * system. @f$Q_2 \times DGP_1 \times DGP_1@f$ elements satisfy this
2119 * condition, while @f$Q_1 \times DGP_0 \times DGP_0@f$ elements do
2120 * not. However, it has been shown that the latter demonstrate good
2121 * convergence characteristics nonetheless.
2122 *
2123 * @code
2124 *   fe(FE_Q<dim>(parameters.poly_degree),
2125 *   dim, // displacement
2126 *   FE_DGP<dim>(parameters.poly_degree - 1),
2127 *   1, // pressure
2128 *   FE_DGP<dim>(parameters.poly_degree - 1),
2129 *   1) // dilatation
2130 *   , dof_handler(triangulation)
2131 *   , dofs_per_cell(fe.n_dofs_per_cell())
2132 *   , u_fe(first_u_component)
2133 *   , p_fe(p_component)
2134 *   , J_fe(J_component)
2135 *   , dofs_per_block(n_blocks)
2136 *   , qf_cell(parameters.quad_order)
2137 *   , qf_face(parameters.quad_order)
2138 *   , n_q_points(qf_cell.size())
2139 *   , n_q_points_f(qf_face.size())
2140 *   {
2141 *   Assert(dim == 2 || dim == 3,
2142 *   ExcMessage("This problem only works in 2 or 3 space dimensions."));
2143 *   determine_component_extractors();
2144 *   }
2145 *  
2146 *  
2147 * @endcode
2148 *
2149 * In solving the quasi-static problem, the time becomes a loading parameter,
2150 * i.e. we increasing the loading linearly with time, making the two concepts
2151 * interchangeable. We choose to increment time linearly using a constant time
2152 * step size.
2153 *
2154
2155 *
2156 * We start the function with preprocessing, setting the initial dilatation
2157 * values, and then output the initial grid before starting the simulation
2158 * proper with the first time (and loading)
2159 * increment.
2160 *
2161
2162 *
2163 * Care must be taken (or at least some thought given) when imposing the
2164 * constraint @f$\widetilde{J}=1@f$ on the initial solution field. The constraint
2165 * corresponds to the determinant of the deformation gradient in the
2166 * undeformed configuration, which is the identity tensor. We use
2167 * FE_DGP bases to interpolate the dilatation field, thus we can't
2168 * simply set the corresponding dof to unity as they correspond to the
2169 * coefficients of a truncated Legendre polynomial.
2170 * Thus we use the VectorTools::project function to do the work for us.
2171 * The VectorTools::project function requires an argument
2172 * indicating the hanging node constraints. We have none in this program
2173 * So we have to create a constraint object. In its original state, constraint
2174 * objects are unsorted, and have to be sorted (using the
2175 * AffineConstraints::close function) before they can be used. Have a look at
2176 * @ref step_21 "step-21" for more information. We only need to enforce the initial condition
2177 * on the dilatation. In order to do this, we make use of a
2178 * ComponentSelectFunction which acts as a mask and sets the J_component of
2179 * n_components to 1. This is exactly what we want. Have a look at its usage
2180 * in @ref step_20 "step-20" for more information.
2181 *
2182 * @code
2183 *   template <int dim>
2184 *   void Solid<dim>::run()
2185 *   {
2186 *   make_grid();
2187 *   system_setup();
2188 *   {
2189 *   AffineConstraints<double> constraints;
2190 *   constraints.close();
2191 *  
2192 *   const ComponentSelectFunction<dim> J_mask(J_component, n_components);
2193 *  
2195 *   dof_handler, constraints, QGauss<dim>(degree + 2), J_mask, solution_n);
2196 *   }
2197 *   output_results();
2198 *   time.increment();
2199 *  
2200 * @endcode
2201 *
2202 * We then declare the incremental solution update @f$\varDelta
2203 * \mathbf{\Xi} \dealcoloneq \{\varDelta \mathbf{u},\varDelta \widetilde{p},
2204 * \varDelta \widetilde{J} \}@f$ and start the loop over the time domain.
2205 *
2206
2207 *
2208 * At the beginning, we reset the solution update for this time step...
2209 *
2210 * @code
2211 *   BlockVector<double> solution_delta(dofs_per_block);
2212 *   while (time.current() < time.end())
2213 *   {
2214 *   solution_delta = 0.0;
2215 *  
2216 * @endcode
2217 *
2218 * ...solve the current time step and update total solution vector
2219 * @f$\mathbf{\Xi}_{\textrm{n}} = \mathbf{\Xi}_{\textrm{n-1}} +
2220 * \varDelta \mathbf{\Xi}@f$...
2221 *
2222 * @code
2223 *   solve_nonlinear_timestep(solution_delta);
2224 *   solution_n += solution_delta;
2225 *  
2226 * @endcode
2227 *
2228 * ...and plot the results before moving on happily to the next time
2229 * step:
2230 *
2231 * @code
2232 *   output_results();
2233 *   time.increment();
2234 *   }
2235 *   }
2236 *  
2237 *  
2238 * @endcode
2239 *
2240 *
2241 * <a name="Privateinterface"></a>
2242 * <h3>Private interface</h3>
2243 *
2244
2245 *
2246 *
2247 * <a name="Threadingbuildingblocksstructures"></a>
2248 * <h4>Threading-building-blocks structures</h4>
2249 *
2250
2251 *
2252 * The first group of private member functions is related to parallelization.
2253 * We use the Threading Building Blocks library (TBB) to perform as many
2254 * computationally intensive distributed tasks as possible. In particular, we
2255 * assemble the tangent matrix and right hand side vector, the static
2256 * condensation contributions, and update data stored at the quadrature points
2257 * using TBB. Our main tool for this is the WorkStream class (see the @ref
2258 * threads module for more information).
2259 *
2260
2261 *
2262 * Firstly we deal with the tangent matrix and right-hand side assembly
2263 * structures. The PerTaskData object stores local contributions to the global
2264 * system.
2265 *
2266 * @code
2267 *   template <int dim>
2268 *   struct Solid<dim>::PerTaskData_ASM
2269 *   {
2270 *   FullMatrix<double> cell_matrix;
2271 *   Vector<double> cell_rhs;
2272 *   std::vector<types::global_dof_index> local_dof_indices;
2273 *  
2274 *   PerTaskData_ASM(const unsigned int dofs_per_cell)
2275 *   : cell_matrix(dofs_per_cell, dofs_per_cell)
2276 *   , cell_rhs(dofs_per_cell)
2277 *   , local_dof_indices(dofs_per_cell)
2278 *   {}
2279 *  
2280 *   void reset()
2281 *   {
2282 *   cell_matrix = 0.0;
2283 *   cell_rhs = 0.0;
2284 *   }
2285 *   };
2286 *  
2287 *  
2288 * @endcode
2289 *
2290 * On the other hand, the ScratchData object stores the larger objects such as
2291 * the shape-function values array (<code>Nx</code>) and a shape function
2292 * gradient and symmetric gradient vector which we will use during the
2293 * assembly.
2294 *
2295 * @code
2296 *   template <int dim>
2297 *   struct Solid<dim>::ScratchData_ASM
2298 *   {
2299 *   FEValues<dim> fe_values;
2300 *   FEFaceValues<dim> fe_face_values;
2301 *  
2302 *   std::vector<std::vector<double>> Nx;
2303 *   std::vector<std::vector<Tensor<2, dim>>> grad_Nx;
2304 *   std::vector<std::vector<SymmetricTensor<2, dim>>> symm_grad_Nx;
2305 *  
2306 *   ScratchData_ASM(const FiniteElement<dim> &fe_cell,
2307 *   const QGauss<dim> & qf_cell,
2308 *   const UpdateFlags uf_cell,
2309 *   const QGauss<dim - 1> & qf_face,
2310 *   const UpdateFlags uf_face)
2311 *   : fe_values(fe_cell, qf_cell, uf_cell)
2312 *   , fe_face_values(fe_cell, qf_face, uf_face)
2313 *   , Nx(qf_cell.size(), std::vector<double>(fe_cell.n_dofs_per_cell()))
2314 *   , grad_Nx(qf_cell.size(),
2315 *   std::vector<Tensor<2, dim>>(fe_cell.n_dofs_per_cell()))
2316 *   , symm_grad_Nx(qf_cell.size(),
2317 *   std::vector<SymmetricTensor<2, dim>>(
2318 *   fe_cell.n_dofs_per_cell()))
2319 *   {}
2320 *  
2321 *   ScratchData_ASM(const ScratchData_ASM &rhs)
2322 *   : fe_values(rhs.fe_values.get_fe(),
2323 *   rhs.fe_values.get_quadrature(),
2324 *   rhs.fe_values.get_update_flags())
2325 *   , fe_face_values(rhs.fe_face_values.get_fe(),
2326 *   rhs.fe_face_values.get_quadrature(),
2327 *   rhs.fe_face_values.get_update_flags())
2328 *   , Nx(rhs.Nx)
2329 *   , grad_Nx(rhs.grad_Nx)
2330 *   , symm_grad_Nx(rhs.symm_grad_Nx)
2331 *   {}
2332 *  
2333 *   void reset()
2334 *   {
2335 *   const unsigned int n_q_points = Nx.size();
2336 *   const unsigned int n_dofs_per_cell = Nx[0].size();
2337 *   for (unsigned int q_point = 0; q_point < n_q_points; ++q_point)
2338 *   {
2339 *   Assert(Nx[q_point].size() == n_dofs_per_cell, ExcInternalError());
2340 *   Assert(grad_Nx[q_point].size() == n_dofs_per_cell,
2341 *   ExcInternalError());
2342 *   Assert(symm_grad_Nx[q_point].size() == n_dofs_per_cell,
2343 *   ExcInternalError());
2344 *   for (unsigned int k = 0; k < n_dofs_per_cell; ++k)
2345 *   {
2346 *   Nx[q_point][k] = 0.0;
2347 *   grad_Nx[q_point][k] = 0.0;
2348 *   symm_grad_Nx[q_point][k] = 0.0;
2349 *   }
2350 *   }
2351 *   }
2352 *   };
2353 *  
2354 *  
2355 * @endcode
2356 *
2357 * Then we define structures to assemble the statically condensed tangent
2358 * matrix. Recall that we wish to solve for a displacement-based formulation.
2359 * We do the condensation at the element level as the @f$\widetilde{p}@f$ and
2360 * @f$\widetilde{J}@f$ fields are element-wise discontinuous. As these operations
2361 * are matrix-based, we need to set up a number of matrices to store the local
2362 * contributions from a number of the tangent matrix sub-blocks. We place
2363 * these in the PerTaskData struct.
2364 *
2365
2366 *
2367 * We choose not to reset any data in the <code>reset()</code> function as the
2368 * matrix extraction and replacement tools will take care of this
2369 *
2370 * @code
2371 *   template <int dim>
2372 *   struct Solid<dim>::PerTaskData_SC
2373 *   {
2375 *   std::vector<types::global_dof_index> local_dof_indices;
2376 *  
2377 *   FullMatrix<double> k_orig;
2378 *   FullMatrix<double> k_pu;
2379 *   FullMatrix<double> k_pJ;
2380 *   FullMatrix<double> k_JJ;
2381 *   FullMatrix<double> k_pJ_inv;
2382 *   FullMatrix<double> k_bbar;
2383 *   FullMatrix<double> A;
2384 *   FullMatrix<double> B;
2385 *   FullMatrix<double> C;
2386 *  
2387 *   PerTaskData_SC(const unsigned int dofs_per_cell,
2388 *   const unsigned int n_u,
2389 *   const unsigned int n_p,
2390 *   const unsigned int n_J)
2391 *   : cell_matrix(dofs_per_cell, dofs_per_cell)
2392 *   , local_dof_indices(dofs_per_cell)
2393 *   , k_orig(dofs_per_cell, dofs_per_cell)
2394 *   , k_pu(n_p, n_u)
2395 *   , k_pJ(n_p, n_J)
2396 *   , k_JJ(n_J, n_J)
2397 *   , k_pJ_inv(n_p, n_J)
2398 *   , k_bbar(n_u, n_u)
2399 *   , A(n_J, n_u)
2400 *   , B(n_J, n_u)
2401 *   , C(n_p, n_u)
2402 *   {}
2403 *  
2404 *   void reset()
2405 *   {}
2406 *   };
2407 *  
2408 *  
2409 * @endcode
2410 *
2411 * The ScratchData object for the operations we wish to perform here is empty
2412 * since we need no temporary data, but it still needs to be defined for the
2413 * current implementation of TBB in deal.II. So we create a dummy struct for
2414 * this purpose.
2415 *
2416 * @code
2417 *   template <int dim>
2418 *   struct Solid<dim>::ScratchData_SC
2419 *   {
2420 *   void reset()
2421 *   {}
2422 *   };
2423 *  
2424 *  
2425 * @endcode
2426 *
2427 * And finally we define the structures to assist with updating the quadrature
2428 * point information. Similar to the SC assembly process, we do not need the
2429 * PerTaskData object (since there is nothing to store here) but must define
2430 * one nonetheless. Note that this is because for the operation that we have
2431 * here -- updating the data on quadrature points -- the operation is purely
2432 * local: the things we do on every cell get consumed on every cell, without
2433 * any global aggregation operation as is usually the case when using the
2434 * WorkStream class. The fact that we still have to define a per-task data
2435 * structure points to the fact that the WorkStream class may be ill-suited to
2436 * this operation (we could, in principle simply create a new task using
2437 * Threads::new_task for each cell) but there is not much harm done to doing
2438 * it this way anyway.
2439 * Furthermore, should there be different material models associated with a
2440 * quadrature point, requiring varying levels of computational expense, then
2441 * the method used here could be advantageous.
2442 *
2443 * @code
2444 *   template <int dim>
2445 *   struct Solid<dim>::PerTaskData_UQPH
2446 *   {
2447 *   void reset()
2448 *   {}
2449 *   };
2450 *  
2451 *  
2452 * @endcode
2453 *
2454 * The ScratchData object will be used to store an alias for the solution
2455 * vector so that we don't have to copy this large data structure. We then
2456 * define a number of vectors to extract the solution values and gradients at
2457 * the quadrature points.
2458 *
2459 * @code
2460 *   template <int dim>
2461 *   struct Solid<dim>::ScratchData_UQPH
2462 *   {
2463 *   const BlockVector<double> &solution_total;
2464 *  
2465 *   std::vector<Tensor<2, dim>> solution_grads_u_total;
2466 *   std::vector<double> solution_values_p_total;
2467 *   std::vector<double> solution_values_J_total;
2468 *  
2469 *   FEValues<dim> fe_values;
2470 *  
2471 *   ScratchData_UQPH(const FiniteElement<dim> & fe_cell,
2472 *   const QGauss<dim> & qf_cell,
2473 *   const UpdateFlags uf_cell,
2474 *   const BlockVector<double> &solution_total)
2475 *   : solution_total(solution_total)
2476 *   , solution_grads_u_total(qf_cell.size())
2477 *   , solution_values_p_total(qf_cell.size())
2478 *   , solution_values_J_total(qf_cell.size())
2479 *   , fe_values(fe_cell, qf_cell, uf_cell)
2480 *   {}
2481 *  
2482 *   ScratchData_UQPH(const ScratchData_UQPH &rhs)
2483 *   : solution_total(rhs.solution_total)
2484 *   , solution_grads_u_total(rhs.solution_grads_u_total)
2485 *   , solution_values_p_total(rhs.solution_values_p_total)
2486 *   , solution_values_J_total(rhs.solution_values_J_total)
2487 *   , fe_values(rhs.fe_values.get_fe(),
2488 *   rhs.fe_values.get_quadrature(),
2489 *   rhs.fe_values.get_update_flags())
2490 *   {}
2491 *  
2492 *   void reset()
2493 *   {
2494 *   const unsigned int n_q_points = solution_grads_u_total.size();
2495 *   for (unsigned int q = 0; q < n_q_points; ++q)
2496 *   {
2497 *   solution_grads_u_total[q] = 0.0;
2498 *   solution_values_p_total[q] = 0.0;
2499 *   solution_values_J_total[q] = 0.0;
2500 *   }
2501 *   }
2502 *   };
2503 *  
2504 *  
2505 * @endcode
2506 *
2507 *
2508 * <a name="Solidmake_grid"></a>
2509 * <h4>Solid::make_grid</h4>
2510 *
2511
2512 *
2513 * On to the first of the private member functions. Here we create the
2514 * triangulation of the domain, for which we choose the scaled cube with each
2515 * face given a boundary ID number. The grid must be refined at least once
2516 * for the indentation problem.
2517 *
2518
2519 *
2520 * We then determine the volume of the reference configuration and print it
2521 * for comparison:
2522 *
2523 * @code
2524 *   template <int dim>
2525 *   void Solid<dim>::make_grid()
2526 *   {
2527 *   GridGenerator::hyper_rectangle(
2528 *   triangulation,
2529 *   (dim == 3 ? Point<dim>(0.0, 0.0, 0.0) : Point<dim>(0.0, 0.0)),
2530 *   (dim == 3 ? Point<dim>(1.0, 1.0, 1.0) : Point<dim>(1.0, 1.0)),
2531 *   true);
2532 *   GridTools::scale(parameters.scale, triangulation);
2533 *   triangulation.refine_global(std::max(1U, parameters.global_refinement));
2534 *  
2535 *   vol_reference = GridTools::volume(triangulation);
2536 *   std::cout << "Grid:\n\t Reference volume: " << vol_reference << std::endl;
2537 *  
2538 * @endcode
2539 *
2540 * Since we wish to apply a Neumann BC to a patch on the top surface, we
2541 * must find the cell faces in this part of the domain and mark them with
2542 * a distinct boundary ID number. The faces we are looking for are on the
2543 * +y surface and will get boundary ID 6 (zero through five are already
2544 * used when creating the six faces of the cube domain):
2545 *
2546 * @code
2547 *   for (const auto &cell : triangulation.active_cell_iterators())
2548 *   for (const auto &face : cell->face_iterators())
2549 *   {
2550 *   if (face->at_boundary() == true &&
2551 *   face->center()[1] == 1.0 * parameters.scale)
2552 *   {
2553 *   if (dim == 3)
2554 *   {
2555 *   if (face->center()[0] < 0.5 * parameters.scale &&
2556 *   face->center()[2] < 0.5 * parameters.scale)
2557 *   face->set_boundary_id(6);
2558 *   }
2559 *   else
2560 *   {
2561 *   if (face->center()[0] < 0.5 * parameters.scale)
2562 *   face->set_boundary_id(6);
2563 *   }
2564 *   }
2565 *   }
2566 *   }
2567 *  
2568 *  
2569 * @endcode
2570 *
2571 *
2572 * <a name="Solidsystem_setup"></a>
2573 * <h4>Solid::system_setup</h4>
2574 *
2575
2576 *
2577 * Next we describe how the FE system is setup. We first determine the number
2578 * of components per block. Since the displacement is a vector component, the
2579 * first dim components belong to it, while the next two describe scalar
2580 * pressure and dilatation DOFs.
2581 *
2582 * @code
2583 *   template <int dim>
2584 *   void Solid<dim>::system_setup()
2585 *   {
2586 *   timer.enter_subsection("Setup system");
2587 *  
2588 *   std::vector<unsigned int> block_component(n_components,
2589 *   u_dof); // Displacement
2590 *   block_component[p_component] = p_dof; // Pressure
2591 *   block_component[J_component] = J_dof; // Dilatation
2592 *  
2593 * @endcode
2594 *
2595 * The DOF handler is then initialized and we renumber the grid in an
2596 * efficient manner. We also record the number of DOFs per block.
2597 *
2598 * @code
2599 *   dof_handler.distribute_dofs(fe);
2600 *   DoFRenumbering::Cuthill_McKee(dof_handler);
2601 *   DoFRenumbering::component_wise(dof_handler, block_component);
2602 *  
2603 *   dofs_per_block =
2604 *   DoFTools::count_dofs_per_fe_block(dof_handler, block_component);
2605 *  
2606 *   std::cout << "Triangulation:"
2607 *   << "\n\t Number of active cells: "
2608 *   << triangulation.n_active_cells()
2609 *   << "\n\t Number of degrees of freedom: " << dof_handler.n_dofs()
2610 *   << std::endl;
2611 *  
2612 * @endcode
2613 *
2614 * Setup the sparsity pattern and tangent matrix
2615 *
2616 * @code
2617 *   tangent_matrix.clear();
2618 *   {
2619 *   BlockDynamicSparsityPattern dsp(dofs_per_block, dofs_per_block);
2620 *  
2621 * @endcode
2622 *
2623 * The global system matrix initially has the following structure
2624 * @f{align*}
2625 * \underbrace{\begin{bmatrix}
2626 * \mathsf{\mathbf{K}}_{uu} & \mathsf{\mathbf{K}}_{u\widetilde{p}} &
2627 * \mathbf{0}
2628 * \\ \mathsf{\mathbf{K}}_{\widetilde{p}u} & \mathbf{0} &
2629 * \mathsf{\mathbf{K}}_{\widetilde{p}\widetilde{J}}
2630 * \\ \mathbf{0} & \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{p}} &
2631 * \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{J}}
2632 * \end{bmatrix}}_{\mathsf{\mathbf{K}}(\mathbf{\Xi}_{\textrm{i}})}
2633 * \underbrace{\begin{bmatrix}
2634 * d \mathsf{u}
2635 * \\ d \widetilde{\mathsf{\mathbf{p}}}
2636 * \\ d \widetilde{\mathsf{\mathbf{J}}}
2637 * \end{bmatrix}}_{d \mathbf{\Xi}}
2638 * =
2639 * \underbrace{\begin{bmatrix}
2640 * \mathsf{\mathbf{F}}_{u}(\mathbf{u}_{\textrm{i}})
2641 * \\ \mathsf{\mathbf{F}}_{\widetilde{p}}(\widetilde{p}_{\textrm{i}})
2642 * \\ \mathsf{\mathbf{F}}_{\widetilde{J}}(\widetilde{J}_{\textrm{i}})
2643 * \end{bmatrix}}_{ \mathsf{\mathbf{F}}(\mathbf{\Xi}_{\textrm{i}}) } \, .
2644 * @f}
2645 * We optimize the sparsity pattern to reflect this structure
2646 * and prevent unnecessary data creation for the right-diagonal
2647 * block components.
2648 *
2649 * @code
2650 *   Table<2, DoFTools::Coupling> coupling(n_components, n_components);
2651 *   for (unsigned int ii = 0; ii < n_components; ++ii)
2652 *   for (unsigned int jj = 0; jj < n_components; ++jj)
2653 *   if (((ii < p_component) && (jj == J_component)) ||
2654 *   ((ii == J_component) && (jj < p_component)) ||
2655 *   ((ii == p_component) && (jj == p_component)))
2656 *   coupling[ii][jj] = DoFTools::none;
2657 *   else
2658 *   coupling[ii][jj] = DoFTools::always;
2659 *   DoFTools::make_sparsity_pattern(
2660 *   dof_handler, coupling, dsp, constraints, false);
2661 *   sparsity_pattern.copy_from(dsp);
2662 *   }
2663 *  
2664 *   tangent_matrix.reinit(sparsity_pattern);
2665 *  
2666 * @endcode
2667 *
2668 * We then set up storage vectors
2669 *
2670 * @code
2671 *   system_rhs.reinit(dofs_per_block);
2672 *   solution_n.reinit(dofs_per_block);
2673 *  
2674 * @endcode
2675 *
2676 * ...and finally set up the quadrature
2677 * point history:
2678 *
2679 * @code
2680 *   setup_qph();
2681 *  
2682 *   timer.leave_subsection();
2683 *   }
2684 *  
2685 *  
2686 * @endcode
2687 *
2688 *
2689 * <a name="Soliddetermine_component_extractors"></a>
2690 * <h4>Solid::determine_component_extractors</h4>
2691 * Next we compute some information from the FE system that describes which
2692 * local element DOFs are attached to which block component. This is used
2693 * later to extract sub-blocks from the global matrix.
2694 *
2695
2696 *
2697 * In essence, all we need is for the FESystem object to indicate to which
2698 * block component a DOF on the reference cell is attached to. Currently, the
2699 * interpolation fields are setup such that 0 indicates a displacement DOF, 1
2700 * a pressure DOF and 2 a dilatation DOF.
2701 *
2702 * @code
2703 *   template <int dim>
2704 *   void Solid<dim>::determine_component_extractors()
2705 *   {
2706 *   element_indices_u.clear();
2707 *   element_indices_p.clear();
2708 *   element_indices_J.clear();
2709 *  
2710 *   for (unsigned int k = 0; k < fe.n_dofs_per_cell(); ++k)
2711 *   {
2712 *   const unsigned int k_group = fe.system_to_base_index(k).first.first;
2713 *   if (k_group == u_dof)
2714 *   element_indices_u.push_back(k);
2715 *   else if (k_group == p_dof)
2716 *   element_indices_p.push_back(k);
2717 *   else if (k_group == J_dof)
2718 *   element_indices_J.push_back(k);
2719 *   else
2720 *   {
2721 *   Assert(k_group <= J_dof, ExcInternalError());
2722 *   }
2723 *   }
2724 *   }
2725 *  
2726 * @endcode
2727 *
2728 *
2729 * <a name="Solidsetup_qph"></a>
2730 * <h4>Solid::setup_qph</h4>
2731 * The method used to store quadrature information is already described in
2732 * @ref step_18 "step-18". Here we implement a similar setup for a SMP machine.
2733 *
2734
2735 *
2736 * Firstly the actual QPH data objects are created. This must be done only
2737 * once the grid is refined to its finest level.
2738 *
2739 * @code
2740 *   template <int dim>
2741 *   void Solid<dim>::setup_qph()
2742 *   {
2743 *   std::cout << " Setting up quadrature point data..." << std::endl;
2744 *  
2745 *   quadrature_point_history.initialize(triangulation.begin_active(),
2746 *   triangulation.end(),
2747 *   n_q_points);
2748 *  
2749 * @endcode
2750 *
2751 * Next we set up the initial quadrature point data.
2752 * Note that when the quadrature point data is retrieved,
2753 * it is returned as a vector of smart pointers.
2754 *
2755 * @code
2756 *   for (const auto &cell : triangulation.active_cell_iterators())
2757 *   {
2758 *   const std::vector<std::shared_ptr<PointHistory<dim>>> lqph =
2759 *   quadrature_point_history.get_data(cell);
2760 *   Assert(lqph.size() == n_q_points, ExcInternalError());
2761 *  
2762 *   for (unsigned int q_point = 0; q_point < n_q_points; ++q_point)
2763 *   lqph[q_point]->setup_lqp(parameters);
2764 *   }
2765 *   }
2766 *  
2767 * @endcode
2768 *
2769 *
2770 * <a name="Solidupdate_qph_incremental"></a>
2771 * <h4>Solid::update_qph_incremental</h4>
2772 * As the update of QP information occurs frequently and involves a number of
2773 * expensive operations, we define a multithreaded approach to distributing
2774 * the task across a number of CPU cores.
2775 *
2776
2777 *
2778 * To start this, we first we need to obtain the total solution as it stands
2779 * at this Newton increment and then create the initial copy of the scratch
2780 * and copy data objects:
2781 *
2782 * @code
2783 *   template <int dim>
2784 *   void
2785 *   Solid<dim>::update_qph_incremental(const BlockVector<double> &solution_delta)
2786 *   {
2787 *   timer.enter_subsection("Update QPH data");
2788 *   std::cout << " UQPH " << std::flush;
2789 *  
2790 *   const BlockVector<double> solution_total(
2791 *   get_total_solution(solution_delta));
2792 *  
2793 *   const UpdateFlags uf_UQPH(update_values | update_gradients);
2794 *   PerTaskData_UQPH per_task_data_UQPH;
2795 *   ScratchData_UQPH scratch_data_UQPH(fe, qf_cell, uf_UQPH, solution_total);
2796 *  
2797 * @endcode
2798 *
2799 * We then pass them and the one-cell update function to the WorkStream to
2800 * be processed:
2801 *
2802 * @code
2803 *   WorkStream::run(dof_handler.active_cell_iterators(),
2804 *   *this,
2805 *   &Solid::update_qph_incremental_one_cell,
2806 *   &Solid::copy_local_to_global_UQPH,
2807 *   scratch_data_UQPH,
2808 *   per_task_data_UQPH);
2809 *  
2810 *   timer.leave_subsection();
2811 *   }
2812 *  
2813 *  
2814 * @endcode
2815 *
2816 * Now we describe how we extract data from the solution vector and pass it
2817 * along to each QP storage object for processing.
2818 *
2819 * @code
2820 *   template <int dim>
2821 *   void Solid<dim>::update_qph_incremental_one_cell(
2822 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
2823 *   ScratchData_UQPH & scratch,
2824 *   PerTaskData_UQPH & /*data*/)
2825 *   {
2826 *   const std::vector<std::shared_ptr<PointHistory<dim>>> lqph =
2827 *   quadrature_point_history.get_data(cell);
2828 *   Assert(lqph.size() == n_q_points, ExcInternalError());
2829 *  
2830 *   Assert(scratch.solution_grads_u_total.size() == n_q_points,
2831 *   ExcInternalError());
2832 *   Assert(scratch.solution_values_p_total.size() == n_q_points,
2833 *   ExcInternalError());
2834 *   Assert(scratch.solution_values_J_total.size() == n_q_points,
2835 *   ExcInternalError());
2836 *  
2837 *   scratch.reset();
2838 *  
2839 * @endcode
2840 *
2841 * We first need to find the values and gradients at quadrature points
2842 * inside the current cell and then we update each local QP using the
2843 * displacement gradient and total pressure and dilatation solution
2844 * values:
2845 *
2846 * @code
2847 *   scratch.fe_values.reinit(cell);
2848 *   scratch.fe_values[u_fe].get_function_gradients(
2849 *   scratch.solution_total, scratch.solution_grads_u_total);
2850 *   scratch.fe_values[p_fe].get_function_values(
2851 *   scratch.solution_total, scratch.solution_values_p_total);
2852 *   scratch.fe_values[J_fe].get_function_values(
2853 *   scratch.solution_total, scratch.solution_values_J_total);
2854 *  
2855 *   for (const unsigned int q_point :
2856 *   scratch.fe_values.quadrature_point_indices())
2857 *   lqph[q_point]->update_values(scratch.solution_grads_u_total[q_point],
2858 *   scratch.solution_values_p_total[q_point],
2859 *   scratch.solution_values_J_total[q_point]);
2860 *   }
2861 *  
2862 *  
2863 * @endcode
2864 *
2865 *
2866 * <a name="Solidsolve_nonlinear_timestep"></a>
2867 * <h4>Solid::solve_nonlinear_timestep</h4>
2868 *
2869
2870 *
2871 * The next function is the driver method for the Newton-Raphson scheme. At
2872 * its top we create a new vector to store the current Newton update step,
2873 * reset the error storage objects and print solver header.
2874 *
2875 * @code
2876 *   template <int dim>
2877 *   void Solid<dim>::solve_nonlinear_timestep(BlockVector<double> &solution_delta)
2878 *   {
2879 *   std::cout << std::endl
2880 *   << "Timestep " << time.get_timestep() << " @ " << time.current()
2881 *   << 's' << std::endl;
2882 *  
2883 *   BlockVector<double> newton_update(dofs_per_block);
2884 *  
2885 *   error_residual.reset();
2886 *   error_residual_0.reset();
2887 *   error_residual_norm.reset();
2888 *   error_update.reset();
2889 *   error_update_0.reset();
2890 *   error_update_norm.reset();
2891 *  
2892 *   print_conv_header();
2893 *  
2894 * @endcode
2895 *
2896 * We now perform a number of Newton iterations to iteratively solve the
2897 * nonlinear problem. Since the problem is fully nonlinear and we are
2898 * using a full Newton method, the data stored in the tangent matrix and
2899 * right-hand side vector is not reusable and must be cleared at each
2900 * Newton step. We then initially build the linear system and
2901 * check for convergence (and store this value in the first iteration).
2902 * The unconstrained DOFs of the rhs vector hold the out-of-balance
2903 * forces, and collectively determine whether or not the equilibrium
2904 * solution has been attained.
2905 *
2906
2907 *
2908 * Although for this particular problem we could potentially construct the
2909 * RHS vector before assembling the system matrix, for the sake of
2910 * extensibility we choose not to do so. The benefit to assembling the RHS
2911 * vector and system matrix separately is that the latter is an expensive
2912 * operation and we can potentially avoid an extra assembly process by not
2913 * assembling the tangent matrix when convergence is attained. However, this
2914 * makes parallelizing the code using MPI more difficult. Furthermore, when
2915 * extending the problem to the transient case additional contributions to
2916 * the RHS may result from the time discretization and application of
2917 * constraints for the velocity and acceleration fields.
2918 *
2919 * @code
2920 *   unsigned int newton_iteration = 0;
2921 *   for (; newton_iteration < parameters.max_iterations_NR; ++newton_iteration)
2922 *   {
2923 *   std::cout << ' ' << std::setw(2) << newton_iteration << ' '
2924 *   << std::flush;
2925 *  
2926 * @endcode
2927 *
2928 * We construct the linear system, but hold off on solving it
2929 * (a step that should be significantly more expensive than assembly):
2930 *
2931 * @code
2932 *   make_constraints(newton_iteration);
2933 *   assemble_system();
2934 *  
2935 * @endcode
2936 *
2937 * We can now determine the normalized residual error and check for
2938 * solution convergence:
2939 *
2940 * @code
2941 *   get_error_residual(error_residual);
2942 *   if (newton_iteration == 0)
2943 *   error_residual_0 = error_residual;
2944 *  
2945 *   error_residual_norm = error_residual;
2946 *   error_residual_norm.normalize(error_residual_0);
2947 *  
2948 *   if (newton_iteration > 0 && error_update_norm.u <= parameters.tol_u &&
2949 *   error_residual_norm.u <= parameters.tol_f)
2950 *   {
2951 *   std::cout << " CONVERGED! " << std::endl;
2952 *   print_conv_footer();
2953 *  
2954 *   break;
2955 *   }
2956 *  
2957 * @endcode
2958 *
2959 * If we have decided that we want to continue with the iteration, we
2960 * solve the linearized system:
2961 *
2962 * @code
2963 *   const std::pair<unsigned int, double> lin_solver_output =
2964 *   solve_linear_system(newton_update);
2965 *  
2966 * @endcode
2967 *
2968 * We can now determine the normalized Newton update error:
2969 *
2970 * @code
2971 *   get_error_update(newton_update, error_update);
2972 *   if (newton_iteration == 0)
2973 *   error_update_0 = error_update;
2974 *  
2975 *   error_update_norm = error_update;
2976 *   error_update_norm.normalize(error_update_0);
2977 *  
2978 * @endcode
2979 *
2980 * Lastly, since we implicitly accept the solution step we can perform
2981 * the actual update of the solution increment for the current time
2982 * step, update all quadrature point information pertaining to
2983 * this new displacement and stress state and continue iterating:
2984 *
2985 * @code
2986 *   solution_delta += newton_update;
2987 *   update_qph_incremental(solution_delta);
2988 *  
2989 *   std::cout << " | " << std::fixed << std::setprecision(3) << std::setw(7)
2990 *   << std::scientific << lin_solver_output.first << " "
2991 *   << lin_solver_output.second << " "
2992 *   << error_residual_norm.norm << " " << error_residual_norm.u
2993 *   << " " << error_residual_norm.p << " "
2994 *   << error_residual_norm.J << " " << error_update_norm.norm
2995 *   << " " << error_update_norm.u << " " << error_update_norm.p
2996 *   << " " << error_update_norm.J << " " << std::endl;
2997 *   }
2998 *  
2999 * @endcode
3000 *
3001 * At the end, if it turns out that we have in fact done more iterations
3002 * than the parameter file allowed, we raise an exception that can be
3003 * caught in the main() function. The call <code>AssertThrow(condition,
3004 * exc_object)</code> is in essence equivalent to <code>if (!cond) throw
3005 * exc_object;</code> but the former form fills certain fields in the
3006 * exception object that identify the location (filename and line number)
3007 * where the exception was raised to make it simpler to identify where the
3008 * problem happened.
3009 *
3010 * @code
3011 *   AssertThrow(newton_iteration < parameters.max_iterations_NR,
3012 *   ExcMessage("No convergence in nonlinear solver!"));
3013 *   }
3014 *  
3015 *  
3016 * @endcode
3017 *
3018 *
3019 * <a name="Solidprint_conv_headerandSolidprint_conv_footer"></a>
3020 * <h4>Solid::print_conv_header and Solid::print_conv_footer</h4>
3021 *
3022
3023 *
3024 * This program prints out data in a nice table that is updated
3025 * on a per-iteration basis. The next two functions set up the table
3026 * header and footer:
3027 *
3028 * @code
3029 *   template <int dim>
3030 *   void Solid<dim>::print_conv_header()
3031 *   {
3032 *   static const unsigned int l_width = 150;
3033 *  
3034 *   for (unsigned int i = 0; i < l_width; ++i)
3035 *   std::cout << '_';
3036 *   std::cout << std::endl;
3037 *  
3038 *   std::cout << " SOLVER STEP "
3039 *   << " | LIN_IT LIN_RES RES_NORM "
3040 *   << " RES_U RES_P RES_J NU_NORM "
3041 *   << " NU_U NU_P NU_J " << std::endl;
3042 *  
3043 *   for (unsigned int i = 0; i < l_width; ++i)
3044 *   std::cout << '_';
3045 *   std::cout << std::endl;
3046 *   }
3047 *  
3048 *  
3049 *  
3050 *   template <int dim>
3051 *   void Solid<dim>::print_conv_footer()
3052 *   {
3053 *   static const unsigned int l_width = 150;
3054 *  
3055 *   for (unsigned int i = 0; i < l_width; ++i)
3056 *   std::cout << '_';
3057 *   std::cout << std::endl;
3058 *  
3059 *   const std::pair<double, double> error_dil = get_error_dilation();
3060 *  
3061 *   std::cout << "Relative errors:" << std::endl
3062 *   << "Displacement:\t" << error_update.u / error_update_0.u
3063 *   << std::endl
3064 *   << "Force: \t\t" << error_residual.u / error_residual_0.u
3065 *   << std::endl
3066 *   << "Dilatation:\t" << error_dil.first << std::endl
3067 *   << "v / V_0:\t" << error_dil.second * vol_reference << " / "
3068 *   << vol_reference << " = " << error_dil.second << std::endl;
3069 *   }
3070 *  
3071 *  
3072 * @endcode
3073 *
3074 *
3075 * <a name="Solidget_error_dilation"></a>
3076 * <h4>Solid::get_error_dilation</h4>
3077 *
3078
3079 *
3080 * Calculate the volume of the domain in the spatial configuration
3081 *
3082 * @code
3083 *   template <int dim>
3084 *   double Solid<dim>::compute_vol_current() const
3085 *   {
3086 *   double vol_current = 0.0;
3087 *  
3088 *   FEValues<dim> fe_values(fe, qf_cell, update_JxW_values);
3089 *  
3090 *   for (const auto &cell : triangulation.active_cell_iterators())
3091 *   {
3092 *   fe_values.reinit(cell);
3093 *  
3094 * @endcode
3095 *
3096 * In contrast to that which was previously called for,
3097 * in this instance the quadrature point data is specifically
3098 * non-modifiable since we will only be accessing data.
3099 * We ensure that the right get_data function is called by
3100 * marking this update function as constant.
3101 *
3102 * @code
3103 *   const std::vector<std::shared_ptr<const PointHistory<dim>>> lqph =
3104 *   quadrature_point_history.get_data(cell);
3105 *   Assert(lqph.size() == n_q_points, ExcInternalError());
3106 *  
3107 *   for (const unsigned int q_point : fe_values.quadrature_point_indices())
3108 *   {
3109 *   const double det_F_qp = lqph[q_point]->get_det_F();
3110 *   const double JxW = fe_values.JxW(q_point);
3111 *  
3112 *   vol_current += det_F_qp * JxW;
3113 *   }
3114 *   }
3115 *   Assert(vol_current > 0.0, ExcInternalError());
3116 *   return vol_current;
3117 *   }
3118 *  
3119 * @endcode
3120 *
3121 * Calculate how well the dilatation @f$\widetilde{J}@f$ agrees with @f$J
3122 * \dealcoloneq \textrm{det}\ \mathbf{F}@f$ from the @f$L^2@f$ error @f$ \bigl[
3123 * \int_{\Omega_0} {[ J - \widetilde{J}]}^{2}\textrm{d}V \bigr]^{1/2}@f$.
3124 * We also return the ratio of the current volume of the
3125 * domain to the reference volume. This is of interest for incompressible
3126 * media where we want to check how well the isochoric constraint has been
3127 * enforced.
3128 *
3129 * @code
3130 *   template <int dim>
3131 *   std::pair<double, double> Solid<dim>::get_error_dilation() const
3132 *   {
3133 *   double dil_L2_error = 0.0;
3134 *  
3135 *   FEValues<dim> fe_values(fe, qf_cell, update_JxW_values);
3136 *  
3137 *   for (const auto &cell : triangulation.active_cell_iterators())
3138 *   {
3139 *   fe_values.reinit(cell);
3140 *  
3141 *   const std::vector<std::shared_ptr<const PointHistory<dim>>> lqph =
3142 *   quadrature_point_history.get_data(cell);
3143 *   Assert(lqph.size() == n_q_points, ExcInternalError());
3144 *  
3145 *   for (const unsigned int q_point : fe_values.quadrature_point_indices())
3146 *   {
3147 *   const double det_F_qp = lqph[q_point]->get_det_F();
3148 *   const double J_tilde_qp = lqph[q_point]->get_J_tilde();
3149 *   const double the_error_qp_squared =
3150 *   std::pow((det_F_qp - J_tilde_qp), 2);
3151 *   const double JxW = fe_values.JxW(q_point);
3152 *  
3153 *   dil_L2_error += the_error_qp_squared * JxW;
3154 *   }
3155 *   }
3156 *  
3157 *   return std::make_pair(std::sqrt(dil_L2_error),
3158 *   compute_vol_current() / vol_reference);
3159 *   }
3160 *  
3161 *  
3162 * @endcode
3163 *
3164 *
3165 * <a name="Solidget_error_residual"></a>
3166 * <h4>Solid::get_error_residual</h4>
3167 *
3168
3169 *
3170 * Determine the true residual error for the problem. That is, determine the
3171 * error in the residual for the unconstrained degrees of freedom. Note that
3172 * to do so, we need to ignore constrained DOFs by setting the residual in
3173 * these vector components to zero.
3174 *
3175 * @code
3176 *   template <int dim>
3177 *   void Solid<dim>::get_error_residual(Errors &error_residual)
3178 *   {
3179 *   BlockVector<double> error_res(dofs_per_block);
3180 *  
3181 *   for (unsigned int i = 0; i < dof_handler.n_dofs(); ++i)
3182 *   if (!constraints.is_constrained(i))
3183 *   error_res(i) = system_rhs(i);
3184 *  
3185 *   error_residual.norm = error_res.l2_norm();
3186 *   error_residual.u = error_res.block(u_dof).l2_norm();
3187 *   error_residual.p = error_res.block(p_dof).l2_norm();
3188 *   error_residual.J = error_res.block(J_dof).l2_norm();
3189 *   }
3190 *  
3191 *  
3192 * @endcode
3193 *
3194 *
3195 * <a name="Solidget_error_update"></a>
3196 * <h4>Solid::get_error_update</h4>
3197 *
3198
3199 *
3200 * Determine the true Newton update error for the problem
3201 *
3202 * @code
3203 *   template <int dim>
3204 *   void Solid<dim>::get_error_update(const BlockVector<double> &newton_update,
3205 *   Errors & error_update)
3206 *   {
3207 *   BlockVector<double> error_ud(dofs_per_block);
3208 *   for (unsigned int i = 0; i < dof_handler.n_dofs(); ++i)
3209 *   if (!constraints.is_constrained(i))
3210 *   error_ud(i) = newton_update(i);
3211 *  
3212 *   error_update.norm = error_ud.l2_norm();
3213 *   error_update.u = error_ud.block(u_dof).l2_norm();
3214 *   error_update.p = error_ud.block(p_dof).l2_norm();
3215 *   error_update.J = error_ud.block(J_dof).l2_norm();
3216 *   }
3217 *  
3218 *  
3219 *  
3220 * @endcode
3221 *
3222 *
3223 * <a name="Solidget_total_solution"></a>
3224 * <h4>Solid::get_total_solution</h4>
3225 *
3226
3227 *
3228 * This function provides the total solution, which is valid at any Newton
3229 * step. This is required as, to reduce computational error, the total
3230 * solution is only updated at the end of the timestep.
3231 *
3232 * @code
3233 *   template <int dim>
3234 *   BlockVector<double> Solid<dim>::get_total_solution(
3235 *   const BlockVector<double> &solution_delta) const
3236 *   {
3237 *   BlockVector<double> solution_total(solution_n);
3238 *   solution_total += solution_delta;
3239 *   return solution_total;
3240 *   }
3241 *  
3242 *  
3243 * @endcode
3244 *
3245 *
3246 * <a name="Solidassemble_system"></a>
3247 * <h4>Solid::assemble_system</h4>
3248 *
3249
3250 *
3251 * Since we use TBB for assembly, we simply setup a copy of the
3252 * data structures required for the process and pass them, along
3253 * with the assembly functions to the WorkStream object for processing. Note
3254 * that we must ensure that the matrix and RHS vector are reset before any
3255 * assembly operations can occur. Furthermore, since we are describing a
3256 * problem with Neumann BCs, we will need the face normals and so must specify
3257 * this in the face update flags.
3258 *
3259 * @code
3260 *   template <int dim>
3261 *   void Solid<dim>::assemble_system()
3262 *   {
3263 *   timer.enter_subsection("Assemble system");
3264 *   std::cout << " ASM_SYS " << std::flush;
3265 *  
3266 *   tangent_matrix = 0.0;
3267 *   system_rhs = 0.0;
3268 *  
3269 *   const UpdateFlags uf_cell(update_values | update_gradients |
3270 *   update_JxW_values);
3271 *   const UpdateFlags uf_face(update_values | update_normal_vectors |
3272 *   update_JxW_values);
3273 *  
3274 *   PerTaskData_ASM per_task_data(dofs_per_cell);
3275 *   ScratchData_ASM scratch_data(fe, qf_cell, uf_cell, qf_face, uf_face);
3276 *  
3277 * @endcode
3278 *
3279 * The syntax used here to pass data to the WorkStream class
3280 * is discussed in @ref step_13 "step-13".
3281 *
3282 * @code
3283 *   WorkStream::run(
3284 *   dof_handler.active_cell_iterators(),
3285 *   [this](const typename DoFHandler<dim>::active_cell_iterator &cell,
3286 *   ScratchData_ASM & scratch,
3287 *   PerTaskData_ASM & data) {
3288 *   this->assemble_system_one_cell(cell, scratch, data);
3289 *   },
3290 *   [this](const PerTaskData_ASM &data) {
3291 *   this->constraints.distribute_local_to_global(data.cell_matrix,
3292 *   data.cell_rhs,
3293 *   data.local_dof_indices,
3294 *   tangent_matrix,
3295 *   system_rhs);
3296 *   },
3297 *   scratch_data,
3298 *   per_task_data);
3299 *  
3300 *   timer.leave_subsection();
3301 *   }
3302 *  
3303 * @endcode
3304 *
3305 * Of course, we still have to define how we assemble the tangent matrix
3306 * contribution for a single cell. We first need to reset and initialize some
3307 * of the scratch data structures and retrieve some basic information
3308 * regarding the DOF numbering on this cell. We can precalculate the cell
3309 * shape function values and gradients. Note that the shape function gradients
3310 * are defined with regard to the current configuration. That is
3311 * @f$\textrm{grad}\ \boldsymbol{\varphi} = \textrm{Grad}\ \boldsymbol{\varphi}
3312 * \ \mathbf{F}^{-1}@f$.
3313 *
3314 * @code
3315 *   template <int dim>
3316 *   void Solid<dim>::assemble_system_one_cell(
3317 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
3318 *   ScratchData_ASM & scratch,
3319 *   PerTaskData_ASM & data) const
3320 *   {
3321 *   data.reset();
3322 *   scratch.reset();
3323 *   scratch.fe_values.reinit(cell);
3324 *   cell->get_dof_indices(data.local_dof_indices);
3325 *  
3326 *   const std::vector<std::shared_ptr<const PointHistory<dim>>> lqph =
3327 *   quadrature_point_history.get_data(cell);
3328 *   Assert(lqph.size() == n_q_points, ExcInternalError());
3329 *  
3330 *   for (const unsigned int q_point :
3331 *   scratch.fe_values.quadrature_point_indices())
3332 *   {
3333 *   const Tensor<2, dim> F_inv = lqph[q_point]->get_F_inv();
3334 *   for (const unsigned int k : scratch.fe_values.dof_indices())
3335 *   {
3336 *   const unsigned int k_group = fe.system_to_base_index(k).first.first;
3337 *  
3338 *   if (k_group == u_dof)
3339 *   {
3340 *   scratch.grad_Nx[q_point][k] =
3341 *   scratch.fe_values[u_fe].gradient(k, q_point) * F_inv;
3342 *   scratch.symm_grad_Nx[q_point][k] =
3343 *   symmetrize(scratch.grad_Nx[q_point][k]);
3344 *   }
3345 *   else if (k_group == p_dof)
3346 *   scratch.Nx[q_point][k] =
3347 *   scratch.fe_values[p_fe].value(k, q_point);
3348 *   else if (k_group == J_dof)
3349 *   scratch.Nx[q_point][k] =
3350 *   scratch.fe_values[J_fe].value(k, q_point);
3351 *   else
3352 *   Assert(k_group <= J_dof, ExcInternalError());
3353 *   }
3354 *   }
3355 *  
3356 * @endcode
3357 *
3358 * Now we build the local cell @ref GlossStiffnessMatrix "stiffness matrix" and RHS vector. Since the
3359 * global and local system matrices are symmetric, we can exploit this
3360 * property by building only the lower half of the local matrix and copying
3361 * the values to the upper half. So we only assemble half of the
3362 * @f$\mathsf{\mathbf{k}}_{uu}@f$, @f$\mathsf{\mathbf{k}}_{\widetilde{p}
3363 * \widetilde{p}} = \mathbf{0}@f$, @f$\mathsf{\mathbf{k}}_{\widetilde{J}
3364 * \widetilde{J}}@f$ blocks, while the whole
3365 * @f$\mathsf{\mathbf{k}}_{\widetilde{p} \widetilde{J}}@f$,
3366 * @f$\mathsf{\mathbf{k}}_{u \widetilde{J}} = \mathbf{0}@f$,
3367 * @f$\mathsf{\mathbf{k}}_{u \widetilde{p}}@f$ blocks are built.
3368 *
3369
3370 *
3371 * In doing so, we first extract some configuration dependent variables
3372 * from our quadrature history objects for the current quadrature point.
3373 *
3374 * @code
3375 *   for (const unsigned int q_point :
3376 *   scratch.fe_values.quadrature_point_indices())
3377 *   {
3378 *   const SymmetricTensor<2, dim> tau = lqph[q_point]->get_tau();
3379 *   const Tensor<2, dim> tau_ns = lqph[q_point]->get_tau();
3380 *   const SymmetricTensor<4, dim> Jc = lqph[q_point]->get_Jc();
3381 *   const double det_F = lqph[q_point]->get_det_F();
3382 *   const double p_tilde = lqph[q_point]->get_p_tilde();
3383 *   const double J_tilde = lqph[q_point]->get_J_tilde();
3384 *   const double dPsi_vol_dJ = lqph[q_point]->get_dPsi_vol_dJ();
3385 *   const double d2Psi_vol_dJ2 = lqph[q_point]->get_d2Psi_vol_dJ2();
3386 *   const SymmetricTensor<2, dim> &I =
3387 *   Physics::Elasticity::StandardTensors<dim>::I;
3388 *  
3389 * @endcode
3390 *
3391 * These two tensors store some precomputed data. Their use will
3392 * explained shortly.
3393 *
3394 * @code
3395 *   SymmetricTensor<2, dim> symm_grad_Nx_i_x_Jc;
3396 *   Tensor<1, dim> grad_Nx_i_comp_i_x_tau;
3397 *  
3398 * @endcode
3399 *
3400 * Next we define some aliases to make the assembly process easier to
3401 * follow.
3402 *
3403 * @code
3404 *   const std::vector<double> & N = scratch.Nx[q_point];
3405 *   const std::vector<SymmetricTensor<2, dim>> &symm_grad_Nx =
3406 *   scratch.symm_grad_Nx[q_point];
3407 *   const std::vector<Tensor<2, dim>> &grad_Nx = scratch.grad_Nx[q_point];
3408 *   const double JxW = scratch.fe_values.JxW(q_point);
3409 *  
3410 *   for (const unsigned int i : scratch.fe_values.dof_indices())
3411 *   {
3412 *   const unsigned int component_i =
3413 *   fe.system_to_component_index(i).first;
3414 *   const unsigned int i_group = fe.system_to_base_index(i).first.first;
3415 *  
3416 * @endcode
3417 *
3418 * We first compute the contributions
3419 * from the internal forces. Note, by
3420 * definition of the rhs as the negative
3421 * of the residual, these contributions
3422 * are subtracted.
3423 *
3424 * @code
3425 *   if (i_group == u_dof)
3426 *   data.cell_rhs(i) -= (symm_grad_Nx[i] * tau) * JxW;
3427 *   else if (i_group == p_dof)
3428 *   data.cell_rhs(i) -= N[i] * (det_F - J_tilde) * JxW;
3429 *   else if (i_group == J_dof)
3430 *   data.cell_rhs(i) -= N[i] * (dPsi_vol_dJ - p_tilde) * JxW;
3431 *   else
3432 *   Assert(i_group <= J_dof, ExcInternalError());
3433 *  
3434 * @endcode
3435 *
3436 * Before we go into the inner loop, we have one final chance to
3437 * introduce some optimizations. We've already taken into account
3438 * the symmetry of the system, and we can now precompute some
3439 * common terms that are repeatedly applied in the inner loop.
3440 * We won't be excessive here, but will rather focus on expensive
3441 * operations, namely those involving the rank-4 material stiffness
3442 * tensor and the rank-2 stress tensor.
3443 *
3444
3445 *
3446 * What we may observe is that both of these tensors are contracted
3447 * with shape function gradients indexed on the "i" DoF. This
3448 * implies that this particular operation remains constant as we
3449 * loop over the "j" DoF. For that reason, we can extract this from
3450 * the inner loop and save the many operations that, for each
3451 * quadrature point and DoF index "i" and repeated over index "j"
3452 * are required to double contract a rank-2 symmetric tensor with a
3453 * rank-4 symmetric tensor, and a rank-1 tensor with a rank-2
3454 * tensor.
3455 *
3456
3457 *
3458 * At the loss of some readability, this small change will reduce
3459 * the assembly time of the symmetrized system by about half when
3460 * using the simulation default parameters, and becomes more
3461 * significant as the h-refinement level increases.
3462 *
3463 * @code
3464 *   if (i_group == u_dof)
3465 *   {
3466 *   symm_grad_Nx_i_x_Jc = symm_grad_Nx[i] * Jc;
3467 *   grad_Nx_i_comp_i_x_tau = grad_Nx[i][component_i] * tau_ns;
3468 *   }
3469 *  
3470 * @endcode
3471 *
3472 * Now we're prepared to compute the tangent matrix contributions:
3473 *
3474 * @code
3475 *   for (const unsigned int j :
3476 *   scratch.fe_values.dof_indices_ending_at(i))
3477 *   {
3478 *   const unsigned int component_j =
3479 *   fe.system_to_component_index(j).first;
3480 *   const unsigned int j_group =
3481 *   fe.system_to_base_index(j).first.first;
3482 *  
3483 * @endcode
3484 *
3485 * This is the @f$\mathsf{\mathbf{k}}_{uu}@f$
3486 * contribution. It comprises a material contribution, and a
3487 * geometrical stress contribution which is only added along
3488 * the local matrix diagonals:
3489 *
3490 * @code
3491 *   if ((i_group == j_group) && (i_group == u_dof))
3492 *   {
3493 * @endcode
3494 *
3495 * The material contribution:
3496 *
3497 * @code
3498 *   data.cell_matrix(i, j) += symm_grad_Nx_i_x_Jc *
3499 *   symm_grad_Nx[j] * JxW;
3500 *  
3501 * @endcode
3502 *
3503 * The geometrical stress contribution:
3504 *
3505 * @code
3506 *   if (component_i == component_j)
3507 *   data.cell_matrix(i, j) +=
3508 *   grad_Nx_i_comp_i_x_tau * grad_Nx[j][component_j] * JxW;
3509 *   }
3510 * @endcode
3511 *
3512 * Next is the @f$\mathsf{\mathbf{k}}_{ \widetilde{p} u}@f$
3513 * contribution
3514 *
3515 * @code
3516 *   else if ((i_group == p_dof) && (j_group == u_dof))
3517 *   {
3518 *   data.cell_matrix(i, j) += N[i] * det_F *
3519 *   (symm_grad_Nx[j] * I) * JxW;
3520 *   }
3521 * @endcode
3522 *
3523 * and lastly the @f$\mathsf{\mathbf{k}}_{ \widetilde{J}
3524 * \widetilde{p}}@f$ and @f$\mathsf{\mathbf{k}}_{ \widetilde{J}
3525 * \widetilde{J}}@f$ contributions:
3526 *
3527 * @code
3528 *   else if ((i_group == J_dof) && (j_group == p_dof))
3529 *   data.cell_matrix(i, j) -= N[i] * N[j] * JxW;
3530 *   else if ((i_group == j_group) && (i_group == J_dof))
3531 *   data.cell_matrix(i, j) += N[i] * d2Psi_vol_dJ2 * N[j] * JxW;
3532 *   else
3533 *   Assert((i_group <= J_dof) && (j_group <= J_dof),
3534 *   ExcInternalError());
3535 *   }
3536 *   }
3537 *   }
3538 *  
3539 * @endcode
3540 *
3541 * Next we assemble the Neumann contribution. We first check to see it the
3542 * cell face exists on a boundary on which a traction is applied and add
3543 * the contribution if this is the case.
3544 *
3545 * @code
3546 *   for (const auto &face : cell->face_iterators())
3547 *   if (face->at_boundary() && face->boundary_id() == 6)
3548 *   {
3549 *   scratch.fe_face_values.reinit(cell, face);
3550 *  
3551 *   for (const unsigned int f_q_point :
3552 *   scratch.fe_face_values.quadrature_point_indices())
3553 *   {
3554 *   const Tensor<1, dim> &N =
3555 *   scratch.fe_face_values.normal_vector(f_q_point);
3556 *  
3557 * @endcode
3558 *
3559 * Using the face normal at this quadrature point we specify the
3560 * traction in reference configuration. For this problem, a
3561 * defined pressure is applied in the reference configuration.
3562 * The direction of the applied traction is assumed not to
3563 * evolve with the deformation of the domain. The traction is
3564 * defined using the first Piola-Kirchhoff stress is simply
3565 * @f$\mathbf{t} = \mathbf{P}\mathbf{N} = [p_0 \mathbf{I}]
3566 * \mathbf{N} = p_0 \mathbf{N}@f$ We use the time variable to
3567 * linearly ramp up the pressure load.
3568 *
3569
3570 *
3571 * Note that the contributions to the right hand side vector we
3572 * compute here only exist in the displacement components of the
3573 * vector.
3574 *
3575 * @code
3576 *   static const double p0 =
3577 *   -4.0 / (parameters.scale * parameters.scale);
3578 *   const double time_ramp = (time.current() / time.end());
3579 *   const double pressure = p0 * parameters.p_p0 * time_ramp;
3580 *   const Tensor<1, dim> traction = pressure * N;
3581 *  
3582 *   for (const unsigned int i : scratch.fe_values.dof_indices())
3583 *   {
3584 *   const unsigned int i_group =
3585 *   fe.system_to_base_index(i).first.first;
3586 *  
3587 *   if (i_group == u_dof)
3588 *   {
3589 *   const unsigned int component_i =
3590 *   fe.system_to_component_index(i).first;
3591 *   const double Ni =
3592 *   scratch.fe_face_values.shape_value(i, f_q_point);
3593 *   const double JxW = scratch.fe_face_values.JxW(f_q_point);
3594 *  
3595 *   data.cell_rhs(i) += (Ni * traction[component_i]) * JxW;
3596 *   }
3597 *   }
3598 *   }
3599 *   }
3600 *  
3601 * @endcode
3602 *
3603 * Finally, we need to copy the lower half of the local matrix into the
3604 * upper half:
3605 *
3606 * @code
3607 *   for (const unsigned int i : scratch.fe_values.dof_indices())
3608 *   for (const unsigned int j :
3609 *   scratch.fe_values.dof_indices_starting_at(i + 1))
3610 *   data.cell_matrix(i, j) = data.cell_matrix(j, i);
3611 *   }
3612 *  
3613 *  
3614 *  
3615 * @endcode
3616 *
3617 *
3618 * <a name="Solidmake_constraints"></a>
3619 * <h4>Solid::make_constraints</h4>
3620 * The constraints for this problem are simple to describe.
3621 * In this particular example, the boundary values will be calculated for
3622 * the two first iterations of Newton's algorithm. In general, one would
3623 * build non-homogeneous constraints in the zeroth iteration (that is, when
3624 * `apply_dirichlet_bc == true` in the code block that follows) and build
3625 * only the corresponding homogeneous constraints in the following step. While
3626 * the current example has only homogeneous constraints, previous experiences
3627 * have shown that a common error is forgetting to add the extra condition
3628 * when refactoring the code to specific uses. This could lead to errors that
3629 * are hard to debug. In this spirit, we choose to make the code more verbose
3630 * in terms of what operations are performed at each Newton step.
3631 *
3632 * @code
3633 *   template <int dim>
3634 *   void Solid<dim>::make_constraints(const int it_nr)
3635 *   {
3636 * @endcode
3637 *
3638 * Since we (a) are dealing with an iterative Newton method, (b) are using
3639 * an incremental formulation for the displacement, and (c) apply the
3640 * constraints to the incremental displacement field, any non-homogeneous
3641 * constraints on the displacement update should only be specified at the
3642 * zeroth iteration. No subsequent contributions are to be made since the
3643 * constraints will be exactly satisfied after that iteration.
3644 *
3645 * @code
3646 *   const bool apply_dirichlet_bc = (it_nr == 0);
3647 *  
3648 * @endcode
3649 *
3650 * Furthermore, after the first Newton iteration within a timestep, the
3651 * constraints remain the same and we do not need to modify or rebuild them
3652 * so long as we do not clear the @p constraints object.
3653 *
3654 * @code
3655 *   if (it_nr > 1)
3656 *   {
3657 *   std::cout << " --- " << std::flush;
3658 *   return;
3659 *   }
3660 *  
3661 *   std::cout << " CST " << std::flush;
3662 *  
3663 *   if (apply_dirichlet_bc)
3664 *   {
3665 * @endcode
3666 *
3667 * At the zeroth Newton iteration we wish to apply the full set of
3668 * non-homogeneous and homogeneous constraints that represent the
3669 * boundary conditions on the displacement increment. Since in general
3670 * the constraints may be different at each time step, we need to clear
3671 * the constraints matrix and completely rebuild it. An example case
3672 * would be if a surface is accelerating; in such a scenario the change
3673 * in displacement is non-constant between each time step.
3674 *
3675 * @code
3676 *   constraints.clear();
3677 *  
3678 * @endcode
3679 *
3680 * The boundary conditions for the indentation problem in 3d are as
3681 * follows: On the -x, -y and -z faces (IDs 0,2,4) we set up a symmetry
3682 * condition to allow only planar movement while the +x and +z faces
3683 * (IDs 1,5) are traction free. In this contrived problem, part of the
3684 * +y face (ID 3) is set to have no motion in the x- and z-component.
3685 * Finally, as described earlier, the other part of the +y face has an
3686 * the applied pressure but is also constrained in the x- and
3687 * z-directions.
3688 *
3689
3690 *
3691 * In the following, we will have to tell the function interpolation
3692 * boundary values which components of the solution vector should be
3693 * constrained (i.e., whether it's the x-, y-, z-displacements or
3694 * combinations thereof). This is done using ComponentMask objects (see
3695 * @ref GlossComponentMask) which we can get from the finite element if we
3696 * provide it with an extractor object for the component we wish to
3697 * select. To this end we first set up such extractor objects and later
3698 * use it when generating the relevant component masks:
3699 *
3700 * @code
3701 *   const FEValuesExtractors::Scalar x_displacement(0);
3702 *   const FEValuesExtractors::Scalar y_displacement(1);
3703 *  
3704 *   {
3705 *   const int boundary_id = 0;
3706 *  
3708 *   dof_handler,
3709 *   boundary_id,
3710 *   Functions::ZeroFunction<dim>(n_components),
3711 *   constraints,
3712 *   fe.component_mask(x_displacement));
3713 *   }
3714 *   {
3715 *   const int boundary_id = 2;
3716 *  
3718 *   dof_handler,
3719 *   boundary_id,
3720 *   Functions::ZeroFunction<dim>(n_components),
3721 *   constraints,
3722 *   fe.component_mask(y_displacement));
3723 *   }
3724 *  
3725 *   if (dim == 3)
3726 *   {
3727 *   const FEValuesExtractors::Scalar z_displacement(2);
3728 *  
3729 *   {
3730 *   const int boundary_id = 3;
3731 *  
3733 *   dof_handler,
3734 *   boundary_id,
3735 *   Functions::ZeroFunction<dim>(n_components),
3736 *   constraints,
3737 *   (fe.component_mask(x_displacement) |
3738 *   fe.component_mask(z_displacement)));
3739 *   }
3740 *   {
3741 *   const int boundary_id = 4;
3742 *  
3744 *   dof_handler,
3745 *   boundary_id,
3746 *   Functions::ZeroFunction<dim>(n_components),
3747 *   constraints,
3748 *   fe.component_mask(z_displacement));
3749 *   }
3750 *  
3751 *   {
3752 *   const int boundary_id = 6;
3753 *  
3755 *   dof_handler,
3756 *   boundary_id,
3757 *   Functions::ZeroFunction<dim>(n_components),
3758 *   constraints,
3759 *   (fe.component_mask(x_displacement) |
3760 *   fe.component_mask(z_displacement)));
3761 *   }
3762 *   }
3763 *   else
3764 *   {
3765 *   {
3766 *   const int boundary_id = 3;
3767 *  
3769 *   dof_handler,
3770 *   boundary_id,
3771 *   Functions::ZeroFunction<dim>(n_components),
3772 *   constraints,
3773 *   (fe.component_mask(x_displacement)));
3774 *   }
3775 *   {
3776 *   const int boundary_id = 6;
3777 *  
3779 *   dof_handler,
3780 *   boundary_id,
3781 *   Functions::ZeroFunction<dim>(n_components),
3782 *   constraints,
3783 *   (fe.component_mask(x_displacement)));
3784 *   }
3785 *   }
3786 *   }
3787 *   else
3788 *   {
3789 * @endcode
3790 *
3791 * As all Dirichlet constraints are fulfilled exactly after the zeroth
3792 * Newton iteration, we want to ensure that no further modification are
3793 * made to those entries. This implies that we want to convert
3794 * all non-homogeneous Dirichlet constraints into homogeneous ones.
3795 *
3796
3797 *
3798 * In this example the procedure to do this is quite straightforward,
3799 * and in fact we can (and will) circumvent any unnecessary operations
3800 * when only homogeneous boundary conditions are applied.
3801 * In a more general problem one should be mindful of hanging node
3802 * and periodic constraints, which may also introduce some
3803 * inhomogeneities. It might then be advantageous to keep disparate
3804 * objects for the different types of constraints, and merge them
3805 * together once the homogeneous Dirichlet constraints have been
3806 * constructed.
3807 *
3808 * @code
3809 *   if (constraints.has_inhomogeneities())
3810 *   {
3811 * @endcode
3812 *
3813 * Since the affine constraints were finalized at the previous
3814 * Newton iteration, they may not be modified directly. So
3815 * we need to copy them to another temporary object and make
3816 * modification there. Once we're done, we'll transfer them
3817 * back to the main @p constraints object.
3818 *
3819 * @code
3820 *   AffineConstraints<double> homogeneous_constraints(constraints);
3821 *   for (unsigned int dof = 0; dof != dof_handler.n_dofs(); ++dof)
3822 *   if (homogeneous_constraints.is_inhomogeneously_constrained(dof))
3823 *   homogeneous_constraints.set_inhomogeneity(dof, 0.0);
3824 *  
3825 *   constraints.clear();
3826 *   constraints.copy_from(homogeneous_constraints);
3827 *   }
3828 *   }
3829 *  
3830 *   constraints.close();
3831 *   }
3832 *  
3833 * @endcode
3834 *
3835 *
3836 * <a name="Solidassemble_sc"></a>
3837 * <h4>Solid::assemble_sc</h4>
3838 * Solving the entire block system is a bit problematic as there are no
3839 * contributions to the @f$\mathsf{\mathbf{K}}_{ \widetilde{J} \widetilde{J}}@f$
3840 * block, rendering it noninvertible (when using an iterative solver).
3841 * Since the pressure and dilatation variables DOFs are discontinuous, we can
3842 * condense them out to form a smaller displacement-only system which
3843 * we will then solve and subsequently post-process to retrieve the
3844 * pressure and dilatation solutions.
3845 *
3846
3847 *
3848 * The static condensation process could be performed at a global level but we
3849 * need the inverse of one of the blocks. However, since the pressure and
3850 * dilatation variables are discontinuous, the static condensation (SC)
3851 * operation can also be done on a per-cell basis and we can produce the
3852 * inverse of the block-diagonal
3853 * @f$\mathsf{\mathbf{K}}_{\widetilde{p}\widetilde{J}}@f$ block by inverting the
3854 * local blocks. We can again use TBB to do this since each operation will be
3855 * independent of one another.
3856 *
3857
3858 *
3859 * Using the TBB via the WorkStream class, we assemble the contributions to
3860 * form
3861 * @f$
3862 * \mathsf{\mathbf{K}}_{\textrm{con}}
3863 * = \bigl[ \mathsf{\mathbf{K}}_{uu} +
3864 * \overline{\overline{\mathsf{\mathbf{K}}}}~ \bigr]
3865 * @f$
3866 * from each element's contributions. These contributions are then added to
3867 * the global stiffness matrix. Given this description, the following two
3868 * functions should be clear:
3869 *
3870 * @code
3871 *   template <int dim>
3872 *   void Solid<dim>::assemble_sc()
3873 *   {
3874 *   timer.enter_subsection("Perform static condensation");
3875 *   std::cout << " ASM_SC " << std::flush;
3876 *  
3877 *   PerTaskData_SC per_task_data(dofs_per_cell,
3878 *   element_indices_u.size(),
3879 *   element_indices_p.size(),
3880 *   element_indices_J.size());
3881 *   ScratchData_SC scratch_data;
3882 *  
3883 *   WorkStream::run(dof_handler.active_cell_iterators(),
3884 *   *this,
3885 *   &Solid::assemble_sc_one_cell,
3886 *   &Solid::copy_local_to_global_sc,
3887 *   scratch_data,
3888 *   per_task_data);
3889 *  
3890 *   timer.leave_subsection();
3891 *   }
3892 *  
3893 *  
3894 *   template <int dim>
3895 *   void Solid<dim>::copy_local_to_global_sc(const PerTaskData_SC &data)
3896 *   {
3897 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
3898 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
3899 *   tangent_matrix.add(data.local_dof_indices[i],
3900 *   data.local_dof_indices[j],
3901 *   data.cell_matrix(i, j));
3902 *   }
3903 *  
3904 *  
3905 * @endcode
3906 *
3907 * Now we describe the static condensation process. As per usual, we must
3908 * first find out which global numbers the degrees of freedom on this cell
3909 * have and reset some data structures:
3910 *
3911 * @code
3912 *   template <int dim>
3913 *   void Solid<dim>::assemble_sc_one_cell(
3914 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
3915 *   ScratchData_SC & scratch,
3916 *   PerTaskData_SC & data)
3917 *   {
3918 *   data.reset();
3919 *   scratch.reset();
3920 *   cell->get_dof_indices(data.local_dof_indices);
3921 *  
3922 * @endcode
3923 *
3924 * We now extract the contribution of the dofs associated with the current
3925 * cell to the global stiffness matrix. The discontinuous nature of the
3926 * @f$\widetilde{p}@f$ and @f$\widetilde{J}@f$ interpolations mean that their is
3927 * no coupling of the local contributions at the global level. This is not
3928 * the case with the @f$\mathbf{u}@f$ dof. In other words,
3929 * @f$\mathsf{\mathbf{k}}_{\widetilde{J} \widetilde{p}}@f$,
3930 * @f$\mathsf{\mathbf{k}}_{\widetilde{p} \widetilde{p}}@f$ and
3931 * @f$\mathsf{\mathbf{k}}_{\widetilde{J} \widetilde{p}}@f$, when extracted
3932 * from the global stiffness matrix are the element contributions. This
3933 * is not the case for @f$\mathsf{\mathbf{k}}_{uu}@f$.
3934 *
3935
3936 *
3937 * Note: A lower-case symbol is used to denote element stiffness matrices.
3938 *
3939
3940 *
3941 * Currently the matrix corresponding to
3942 * the dof associated with the current element
3943 * (denoted somewhat loosely as @f$\mathsf{\mathbf{k}}@f$)
3944 * is of the form:
3945 * @f{align*}
3946 * \begin{bmatrix}
3947 * \mathsf{\mathbf{k}}_{uu} & \mathsf{\mathbf{k}}_{u\widetilde{p}}
3948 * & \mathbf{0}
3949 * \\ \mathsf{\mathbf{k}}_{\widetilde{p}u} & \mathbf{0} &
3950 * \mathsf{\mathbf{k}}_{\widetilde{p}\widetilde{J}}
3951 * \\ \mathbf{0} & \mathsf{\mathbf{k}}_{\widetilde{J}\widetilde{p}} &
3952 * \mathsf{\mathbf{k}}_{\widetilde{J}\widetilde{J}} \end{bmatrix}
3953 * @f}
3954 *
3955
3956 *
3957 * We now need to modify it such that it appear as
3958 * @f{align*}
3959 * \begin{bmatrix}
3960 * \mathsf{\mathbf{k}}_{\textrm{con}} &
3961 * \mathsf{\mathbf{k}}_{u\widetilde{p}} & \mathbf{0}
3962 * \\ \mathsf{\mathbf{k}}_{\widetilde{p}u} & \mathbf{0} &
3963 * \mathsf{\mathbf{k}}_{\widetilde{p}\widetilde{J}}^{-1}
3964 * \\ \mathbf{0} & \mathsf{\mathbf{k}}_{\widetilde{J}\widetilde{p}} &
3965 * \mathsf{\mathbf{k}}_{\widetilde{J}\widetilde{J}} \end{bmatrix}
3966 * @f}
3967 * with @f$\mathsf{\mathbf{k}}_{\textrm{con}} = \bigl[
3968 * \mathsf{\mathbf{k}}_{uu} +\overline{\overline{\mathsf{\mathbf{k}}}}~
3969 * \bigr]@f$ where @f$ \overline{\overline{\mathsf{\mathbf{k}}}}
3970 * \dealcoloneq \mathsf{\mathbf{k}}_{u\widetilde{p}}
3971 * \overline{\mathsf{\mathbf{k}}} \mathsf{\mathbf{k}}_{\widetilde{p}u}
3972 * @f$
3973 * and
3974 * @f$
3975 * \overline{\mathsf{\mathbf{k}}} =
3976 * \mathsf{\mathbf{k}}_{\widetilde{J}\widetilde{p}}^{-1}
3977 * \mathsf{\mathbf{k}}_{\widetilde{J}\widetilde{J}}
3978 * \mathsf{\mathbf{k}}_{\widetilde{p}\widetilde{J}}^{-1}
3979 * @f$.
3980 *
3981
3982 *
3983 * At this point, we need to take note of
3984 * the fact that global data already exists
3985 * in the @f$\mathsf{\mathbf{K}}_{uu}@f$,
3986 * @f$\mathsf{\mathbf{K}}_{\widetilde{p} \widetilde{J}}@f$
3987 * and
3988 * @f$\mathsf{\mathbf{K}}_{\widetilde{J} \widetilde{p}}@f$
3989 * sub-blocks. So if we are to modify them, we must account for the data
3990 * that is already there (i.e. simply add to it or remove it if
3991 * necessary). Since the copy_local_to_global operation is a "+="
3992 * operation, we need to take this into account
3993 *
3994
3995 *
3996 * For the @f$\mathsf{\mathbf{K}}_{uu}@f$ block in particular, this means that
3997 * contributions have been added from the surrounding cells, so we need to
3998 * be careful when we manipulate this block. We can't just erase the
3999 * sub-blocks.
4000 *
4001
4002 *
4003 * This is the strategy we will employ to get the sub-blocks we want:
4004 *
4005
4006 *
4007 * - @f$ {\mathsf{\mathbf{k}}}_{\textrm{store}}@f$:
4008 * Since we don't have access to @f$\mathsf{\mathbf{k}}_{uu}@f$,
4009 * but we know its contribution is added to
4010 * the global @f$\mathsf{\mathbf{K}}_{uu}@f$ matrix, we just want
4011 * to add the element wise
4012 * static-condensation @f$\overline{\overline{\mathsf{\mathbf{k}}}}@f$.
4013 *
4014
4015 *
4016 * - @f$\mathsf{\mathbf{k}}^{-1}_{\widetilde{p} \widetilde{J}}@f$:
4017 * Similarly, @f$\mathsf{\mathbf{k}}_{\widetilde{p}
4018 * \widetilde{J}}@f$ exists in
4019 * the subblock. Since the copy
4020 * operation is a += operation, we
4021 * need to subtract the existing
4022 * @f$\mathsf{\mathbf{k}}_{\widetilde{p} \widetilde{J}}@f$
4023 * submatrix in addition to
4024 * "adding" that which we wish to
4025 * replace it with.
4026 *
4027
4028 *
4029 * - @f$\mathsf{\mathbf{k}}^{-1}_{\widetilde{J} \widetilde{p}}@f$:
4030 * Since the global matrix
4031 * is symmetric, this block is the
4032 * same as the one above and we
4033 * can simply use
4034 * @f$\mathsf{\mathbf{k}}^{-1}_{\widetilde{p} \widetilde{J}}@f$
4035 * as a substitute for this one.
4036 *
4037
4038 *
4039 * We first extract element data from the
4040 * system matrix. So first we get the
4041 * entire subblock for the cell, then
4042 * extract @f$\mathsf{\mathbf{k}}@f$
4043 * for the dofs associated with
4044 * the current element
4045 *
4046 * @code
4047 *   data.k_orig.extract_submatrix_from(tangent_matrix,
4048 *   data.local_dof_indices,
4049 *   data.local_dof_indices);
4050 * @endcode
4051 *
4052 * and next the local matrices for
4053 * @f$\mathsf{\mathbf{k}}_{ \widetilde{p} u}@f$
4054 * @f$\mathsf{\mathbf{k}}_{ \widetilde{p} \widetilde{J}}@f$
4055 * and
4056 * @f$\mathsf{\mathbf{k}}_{ \widetilde{J} \widetilde{J}}@f$:
4057 *
4058 * @code
4059 *   data.k_pu.extract_submatrix_from(data.k_orig,
4060 *   element_indices_p,
4061 *   element_indices_u);
4062 *   data.k_pJ.extract_submatrix_from(data.k_orig,
4063 *   element_indices_p,
4064 *   element_indices_J);
4065 *   data.k_JJ.extract_submatrix_from(data.k_orig,
4066 *   element_indices_J,
4067 *   element_indices_J);
4068 *  
4069 * @endcode
4070 *
4071 * To get the inverse of @f$\mathsf{\mathbf{k}}_{\widetilde{p}
4072 * \widetilde{J}}@f$, we invert it directly. This operation is relatively
4073 * inexpensive since @f$\mathsf{\mathbf{k}}_{\widetilde{p} \widetilde{J}}@f$
4074 * since block-diagonal.
4075 *
4076 * @code
4077 *   data.k_pJ_inv.invert(data.k_pJ);
4078 *  
4079 * @endcode
4080 *
4081 * Now we can make condensation terms to
4082 * add to the @f$\mathsf{\mathbf{k}}_{uu}@f$
4083 * block and put them in
4084 * the cell local matrix
4085 * @f$
4086 * \mathsf{\mathbf{A}}
4087 * =
4088 * \mathsf{\mathbf{k}}^{-1}_{\widetilde{p} \widetilde{J}}
4089 * \mathsf{\mathbf{k}}_{\widetilde{p} u}
4090 * @f$:
4091 *
4092 * @code
4093 *   data.k_pJ_inv.mmult(data.A, data.k_pu);
4094 * @endcode
4095 *
4096 * @f$
4097 * \mathsf{\mathbf{B}}
4098 * =
4099 * \mathsf{\mathbf{k}}^{-1}_{\widetilde{J} \widetilde{J}}
4100 * \mathsf{\mathbf{k}}^{-1}_{\widetilde{p} \widetilde{J}}
4101 * \mathsf{\mathbf{k}}_{\widetilde{p} u}
4102 * @f$
4103 *
4104 * @code
4105 *   data.k_JJ.mmult(data.B, data.A);
4106 * @endcode
4107 *
4108 * @f$
4109 * \mathsf{\mathbf{C}}
4110 * =
4111 * \mathsf{\mathbf{k}}^{-1}_{\widetilde{J} \widetilde{p}}
4112 * \mathsf{\mathbf{k}}^{-1}_{\widetilde{J} \widetilde{J}}
4113 * \mathsf{\mathbf{k}}^{-1}_{\widetilde{p} \widetilde{J}}
4114 * \mathsf{\mathbf{k}}_{\widetilde{p} u}
4115 * @f$
4116 *
4117 * @code
4118 *   data.k_pJ_inv.Tmmult(data.C, data.B);
4119 * @endcode
4120 *
4121 * @f$
4122 * \overline{\overline{\mathsf{\mathbf{k}}}}
4123 * =
4124 * \mathsf{\mathbf{k}}_{u \widetilde{p}}
4125 * \mathsf{\mathbf{k}}^{-1}_{\widetilde{J} \widetilde{p}}
4126 * \mathsf{\mathbf{k}}^{-1}_{\widetilde{J} \widetilde{J}}
4127 * \mathsf{\mathbf{k}}^{-1}_{\widetilde{p} \widetilde{J}}
4128 * \mathsf{\mathbf{k}}_{\widetilde{p} u}
4129 * @f$
4130 *
4131 * @code
4132 *   data.k_pu.Tmmult(data.k_bbar, data.C);
4133 *   data.k_bbar.scatter_matrix_to(element_indices_u,
4134 *   element_indices_u,
4135 *   data.cell_matrix);
4136 *  
4137 * @endcode
4138 *
4139 * Next we place
4140 * @f$\mathsf{\mathbf{k}}^{-1}_{ \widetilde{p} \widetilde{J}}@f$
4141 * in the
4142 * @f$\mathsf{\mathbf{k}}_{ \widetilde{p} \widetilde{J}}@f$
4143 * block for post-processing. Note again
4144 * that we need to remove the
4145 * contribution that already exists there.
4146 *
4147 * @code
4148 *   data.k_pJ_inv.add(-1.0, data.k_pJ);
4149 *   data.k_pJ_inv.scatter_matrix_to(element_indices_p,
4150 *   element_indices_J,
4151 *   data.cell_matrix);
4152 *   }
4153 *  
4154 * @endcode
4155 *
4156 *
4157 * <a name="Solidsolve_linear_system"></a>
4158 * <h4>Solid::solve_linear_system</h4>
4159 * We now have all of the necessary components to use one of two possible
4160 * methods to solve the linearised system. The first is to perform static
4161 * condensation on an element level, which requires some alterations
4162 * to the tangent matrix and RHS vector. Alternatively, the full block
4163 * system can be solved by performing condensation on a global level.
4164 * Below we implement both approaches.
4165 *
4166 * @code
4167 *   template <int dim>
4168 *   std::pair<unsigned int, double>
4169 *   Solid<dim>::solve_linear_system(BlockVector<double> &newton_update)
4170 *   {
4171 *   unsigned int lin_it = 0;
4172 *   double lin_res = 0.0;
4173 *  
4174 *   if (parameters.use_static_condensation == true)
4175 *   {
4176 * @endcode
4177 *
4178 * Firstly, here is the approach using the (permanent) augmentation of
4179 * the tangent matrix. For the following, recall that
4180 * @f{align*}
4181 * \mathsf{\mathbf{K}}_{\textrm{store}}
4182 * \dealcoloneq
4183 * \begin{bmatrix}
4184 * \mathsf{\mathbf{K}}_{\textrm{con}} &
4185 * \mathsf{\mathbf{K}}_{u\widetilde{p}} & \mathbf{0}
4186 * \\ \mathsf{\mathbf{K}}_{\widetilde{p}u} & \mathbf{0} &
4187 * \mathsf{\mathbf{K}}_{\widetilde{p}\widetilde{J}}^{-1}
4188 * \\ \mathbf{0} &
4189 * \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{p}} &
4190 * \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{J}} \end{bmatrix} \, .
4191 * @f}
4192 * and
4193 * @f{align*}
4194 * d \widetilde{\mathsf{\mathbf{p}}}
4195 * & =
4196 * \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{p}}^{-1}
4197 * \bigl[
4198 * \mathsf{\mathbf{F}}_{\widetilde{J}}
4199 * -
4200 * \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{J}}
4201 * d \widetilde{\mathsf{\mathbf{J}}} \bigr]
4202 * \\ d \widetilde{\mathsf{\mathbf{J}}}
4203 * & =
4204 * \mathsf{\mathbf{K}}_{\widetilde{p}\widetilde{J}}^{-1}
4205 * \bigl[
4206 * \mathsf{\mathbf{F}}_{\widetilde{p}}
4207 * - \mathsf{\mathbf{K}}_{\widetilde{p}u} d
4208 * \mathsf{\mathbf{u}} \bigr]
4209 * \\ \Rightarrow d \widetilde{\mathsf{\mathbf{p}}}
4210 * &= \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{p}}^{-1}
4211 * \mathsf{\mathbf{F}}_{\widetilde{J}}
4212 * -
4213 * \underbrace{\bigl[\mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{p}}^{-1}
4214 * \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{J}}
4215 * \mathsf{\mathbf{K}}_{\widetilde{p}\widetilde{J}}^{-1}\bigr]}_{\overline{\mathsf{\mathbf{K}}}}\bigl[
4216 * \mathsf{\mathbf{F}}_{\widetilde{p}}
4217 * - \mathsf{\mathbf{K}}_{\widetilde{p}u} d
4218 * \mathsf{\mathbf{u}} \bigr]
4219 * @f}
4220 * and thus
4221 * @f[
4222 * \underbrace{\bigl[ \mathsf{\mathbf{K}}_{uu} +
4223 * \overline{\overline{\mathsf{\mathbf{K}}}}~ \bigr]
4224 * }_{\mathsf{\mathbf{K}}_{\textrm{con}}} d
4225 * \mathsf{\mathbf{u}}
4226 * =
4227 * \underbrace{
4228 * \Bigl[
4229 * \mathsf{\mathbf{F}}_{u}
4230 * - \mathsf{\mathbf{K}}_{u\widetilde{p}} \bigl[
4231 * \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{p}}^{-1}
4232 * \mathsf{\mathbf{F}}_{\widetilde{J}}
4233 * -
4234 * \overline{\mathsf{\mathbf{K}}}\mathsf{\mathbf{F}}_{\widetilde{p}}
4235 * \bigr]
4236 * \Bigr]}_{\mathsf{\mathbf{F}}_{\textrm{con}}}
4237 * @f]
4238 * where
4239 * @f[
4240 * \overline{\overline{\mathsf{\mathbf{K}}}} \dealcoloneq
4241 * \mathsf{\mathbf{K}}_{u\widetilde{p}}
4242 * \overline{\mathsf{\mathbf{K}}}
4243 * \mathsf{\mathbf{K}}_{\widetilde{p}u} \, .
4244 * @f]
4245 *
4246
4247 *
4248 * At the top, we allocate two temporary vectors to help with the
4249 * static condensation, and variables to store the number of
4250 * linear solver iterations and the (hopefully converged) residual.
4251 *
4252 * @code
4253 *   BlockVector<double> A(dofs_per_block);
4254 *   BlockVector<double> B(dofs_per_block);
4255 *  
4256 *  
4257 * @endcode
4258 *
4259 * In the first step of this function, we solve for the incremental
4260 * displacement @f$d\mathbf{u}@f$. To this end, we perform static
4261 * condensation to make
4262 * @f$\mathsf{\mathbf{K}}_{\textrm{con}}
4263 * = \bigl[ \mathsf{\mathbf{K}}_{uu} +
4264 * \overline{\overline{\mathsf{\mathbf{K}}}}~ \bigr]@f$
4265 * and put
4266 * @f$\mathsf{\mathbf{K}}^{-1}_{\widetilde{p} \widetilde{J}}@f$
4267 * in the original @f$\mathsf{\mathbf{K}}_{\widetilde{p} \widetilde{J}}@f$
4268 * block. That is, we make @f$\mathsf{\mathbf{K}}_{\textrm{store}}@f$.
4269 *
4270 * @code
4271 *   {
4272 *   assemble_sc();
4273 *  
4274 * @endcode
4275 *
4276 * @f$
4277 * \mathsf{\mathbf{A}}_{\widetilde{J}}
4278 * =
4279 * \mathsf{\mathbf{K}}^{-1}_{\widetilde{p} \widetilde{J}}
4280 * \mathsf{\mathbf{F}}_{\widetilde{p}}
4281 * @f$
4282 *
4283 * @code
4284 *   tangent_matrix.block(p_dof, J_dof)
4285 *   .vmult(A.block(J_dof), system_rhs.block(p_dof));
4286 * @endcode
4287 *
4288 * @f$
4289 * \mathsf{\mathbf{B}}_{\widetilde{J}}
4290 * =
4291 * \mathsf{\mathbf{K}}_{\widetilde{J} \widetilde{J}}
4292 * \mathsf{\mathbf{K}}^{-1}_{\widetilde{p} \widetilde{J}}
4293 * \mathsf{\mathbf{F}}_{\widetilde{p}}
4294 * @f$
4295 *
4296 * @code
4297 *   tangent_matrix.block(J_dof, J_dof)
4298 *   .vmult(B.block(J_dof), A.block(J_dof));
4299 * @endcode
4300 *
4301 * @f$
4302 * \mathsf{\mathbf{A}}_{\widetilde{J}}
4303 * =
4304 * \mathsf{\mathbf{F}}_{\widetilde{J}}
4305 * -
4306 * \mathsf{\mathbf{K}}_{\widetilde{J} \widetilde{J}}
4307 * \mathsf{\mathbf{K}}^{-1}_{\widetilde{p} \widetilde{J}}
4308 * \mathsf{\mathbf{F}}_{\widetilde{p}}
4309 * @f$
4310 *
4311 * @code
4312 *   A.block(J_dof) = system_rhs.block(J_dof);
4313 *   A.block(J_dof) -= B.block(J_dof);
4314 * @endcode
4315 *
4316 * @f$
4317 * \mathsf{\mathbf{A}}_{\widetilde{J}}
4318 * =
4319 * \mathsf{\mathbf{K}}^{-1}_{\widetilde{J} \widetilde{p}}
4320 * [
4321 * \mathsf{\mathbf{F}}_{\widetilde{J}}
4322 * -
4323 * \mathsf{\mathbf{K}}_{\widetilde{J} \widetilde{J}}
4324 * \mathsf{\mathbf{K}}^{-1}_{\widetilde{p} \widetilde{J}}
4325 * \mathsf{\mathbf{F}}_{\widetilde{p}}
4326 * ]
4327 * @f$
4328 *
4329 * @code
4330 *   tangent_matrix.block(p_dof, J_dof)
4331 *   .Tvmult(A.block(p_dof), A.block(J_dof));
4332 * @endcode
4333 *
4334 * @f$
4335 * \mathsf{\mathbf{A}}_{u}
4336 * =
4337 * \mathsf{\mathbf{K}}_{u \widetilde{p}}
4338 * \mathsf{\mathbf{K}}^{-1}_{\widetilde{J} \widetilde{p}}
4339 * [
4340 * \mathsf{\mathbf{F}}_{\widetilde{J}}
4341 * -
4342 * \mathsf{\mathbf{K}}_{\widetilde{J} \widetilde{J}}
4343 * \mathsf{\mathbf{K}}^{-1}_{\widetilde{p} \widetilde{J}}
4344 * \mathsf{\mathbf{F}}_{\widetilde{p}}
4345 * ]
4346 * @f$
4347 *
4348 * @code
4349 *   tangent_matrix.block(u_dof, p_dof)
4350 *   .vmult(A.block(u_dof), A.block(p_dof));
4351 * @endcode
4352 *
4353 * @f$
4354 * \mathsf{\mathbf{F}}_{\text{con}}
4355 * =
4356 * \mathsf{\mathbf{F}}_{u}
4357 * -
4358 * \mathsf{\mathbf{K}}_{u \widetilde{p}}
4359 * \mathsf{\mathbf{K}}^{-1}_{\widetilde{J} \widetilde{p}}
4360 * [
4361 * \mathsf{\mathbf{F}}_{\widetilde{J}}
4362 * -
4363 * \mathsf{\mathbf{K}}_{\widetilde{J} \widetilde{J}}
4364 * \mathsf{\mathbf{K}}^{-1}_{\widetilde{p} \widetilde{J}}
4365 * \mathsf{\mathbf{F}}_{\widetilde{p}}
4366 * ]
4367 * @f$
4368 *
4369 * @code
4370 *   system_rhs.block(u_dof) -= A.block(u_dof);
4371 *  
4372 *   timer.enter_subsection("Linear solver");
4373 *   std::cout << " SLV " << std::flush;
4374 *   if (parameters.type_lin == "CG")
4375 *   {
4376 *   const auto solver_its = static_cast<unsigned int>(
4377 *   tangent_matrix.block(u_dof, u_dof).m() *
4378 *   parameters.max_iterations_lin);
4379 *   const double tol_sol =
4380 *   parameters.tol_lin * system_rhs.block(u_dof).l2_norm();
4381 *  
4382 *   SolverControl solver_control(solver_its, tol_sol);
4383 *  
4384 *   GrowingVectorMemory<Vector<double>> GVM;
4385 *   SolverCG<Vector<double>> solver_CG(solver_control, GVM);
4386 *  
4387 * @endcode
4388 *
4389 * We've chosen by default a SSOR preconditioner as it appears to
4390 * provide the fastest solver convergence characteristics for this
4391 * problem on a single-thread machine. However, this might not be
4392 * true for different problem sizes.
4393 *
4394 * @code
4396 *   preconditioner(parameters.preconditioner_type,
4397 *   parameters.preconditioner_relaxation);
4398 *   preconditioner.use_matrix(tangent_matrix.block(u_dof, u_dof));
4399 *  
4400 *   solver_CG.solve(tangent_matrix.block(u_dof, u_dof),
4401 *   newton_update.block(u_dof),
4402 *   system_rhs.block(u_dof),
4403 *   preconditioner);
4404 *  
4405 *   lin_it = solver_control.last_step();
4406 *   lin_res = solver_control.last_value();
4407 *   }
4408 *   else if (parameters.type_lin == "Direct")
4409 *   {
4410 * @endcode
4411 *
4412 * Otherwise if the problem is small
4413 * enough, a direct solver can be
4414 * utilised.
4415 *
4416 * @code
4417 *   SparseDirectUMFPACK A_direct;
4418 *   A_direct.initialize(tangent_matrix.block(u_dof, u_dof));
4419 *   A_direct.vmult(newton_update.block(u_dof),
4420 *   system_rhs.block(u_dof));
4421 *  
4422 *   lin_it = 1;
4423 *   lin_res = 0.0;
4424 *   }
4425 *   else
4426 *   Assert(false, ExcMessage("Linear solver type not implemented"));
4427 *  
4428 *   timer.leave_subsection();
4429 *   }
4430 *  
4431 * @endcode
4432 *
4433 * Now that we have the displacement update, distribute the constraints
4434 * back to the Newton update:
4435 *
4436 * @code
4437 *   constraints.distribute(newton_update);
4438 *  
4439 *   timer.enter_subsection("Linear solver postprocessing");
4440 *   std::cout << " PP " << std::flush;
4441 *  
4442 * @endcode
4443 *
4444 * The next step after solving the displacement
4445 * problem is to post-process to get the
4446 * dilatation solution from the
4447 * substitution:
4448 * @f$
4449 * d \widetilde{\mathsf{\mathbf{J}}}
4450 * = \mathsf{\mathbf{K}}_{\widetilde{p}\widetilde{J}}^{-1} \bigl[
4451 * \mathsf{\mathbf{F}}_{\widetilde{p}}
4452 * - \mathsf{\mathbf{K}}_{\widetilde{p}u} d \mathsf{\mathbf{u}}
4453 * \bigr]
4454 * @f$
4455 *
4456 * @code
4457 *   {
4458 * @endcode
4459 *
4460 * @f$
4461 * \mathsf{\mathbf{A}}_{\widetilde{p}}
4462 * =
4463 * \mathsf{\mathbf{K}}_{\widetilde{p}u} d \mathsf{\mathbf{u}}
4464 * @f$
4465 *
4466 * @code
4467 *   tangent_matrix.block(p_dof, u_dof)
4468 *   .vmult(A.block(p_dof), newton_update.block(u_dof));
4469 * @endcode
4470 *
4471 * @f$
4472 * \mathsf{\mathbf{A}}_{\widetilde{p}}
4473 * =
4474 * -\mathsf{\mathbf{K}}_{\widetilde{p}u} d \mathsf{\mathbf{u}}
4475 * @f$
4476 *
4477 * @code
4478 *   A.block(p_dof) *= -1.0;
4479 * @endcode
4480 *
4481 * @f$
4482 * \mathsf{\mathbf{A}}_{\widetilde{p}}
4483 * =
4484 * \mathsf{\mathbf{F}}_{\widetilde{p}}
4485 * -\mathsf{\mathbf{K}}_{\widetilde{p}u} d \mathsf{\mathbf{u}}
4486 * @f$
4487 *
4488 * @code
4489 *   A.block(p_dof) += system_rhs.block(p_dof);
4490 * @endcode
4491 *
4492 * @f$
4493 * d\mathsf{\mathbf{\widetilde{J}}}
4494 * =
4495 * \mathsf{\mathbf{K}}^{-1}_{\widetilde{p}\widetilde{J}}
4496 * [
4497 * \mathsf{\mathbf{F}}_{\widetilde{p}}
4498 * -\mathsf{\mathbf{K}}_{\widetilde{p}u} d \mathsf{\mathbf{u}}
4499 * ]
4500 * @f$
4501 *
4502 * @code
4503 *   tangent_matrix.block(p_dof, J_dof)
4504 *   .vmult(newton_update.block(J_dof), A.block(p_dof));
4505 *   }
4506 *  
4507 * @endcode
4508 *
4509 * we ensure here that any Dirichlet constraints
4510 * are distributed on the updated solution:
4511 *
4512 * @code
4513 *   constraints.distribute(newton_update);
4514 *  
4515 * @endcode
4516 *
4517 * Finally we solve for the pressure
4518 * update with the substitution:
4519 * @f$
4520 * d \widetilde{\mathsf{\mathbf{p}}}
4521 * =
4522 * \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{p}}^{-1}
4523 * \bigl[
4524 * \mathsf{\mathbf{F}}_{\widetilde{J}}
4525 * - \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{J}}
4526 * d \widetilde{\mathsf{\mathbf{J}}}
4527 * \bigr]
4528 * @f$
4529 *
4530 * @code
4531 *   {
4532 * @endcode
4533 *
4534 * @f$
4535 * \mathsf{\mathbf{A}}_{\widetilde{J}}
4536 * =
4537 * \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{J}}
4538 * d \widetilde{\mathsf{\mathbf{J}}}
4539 * @f$
4540 *
4541 * @code
4542 *   tangent_matrix.block(J_dof, J_dof)
4543 *   .vmult(A.block(J_dof), newton_update.block(J_dof));
4544 * @endcode
4545 *
4546 * @f$
4547 * \mathsf{\mathbf{A}}_{\widetilde{J}}
4548 * =
4549 * -\mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{J}}
4550 * d \widetilde{\mathsf{\mathbf{J}}}
4551 * @f$
4552 *
4553 * @code
4554 *   A.block(J_dof) *= -1.0;
4555 * @endcode
4556 *
4557 * @f$
4558 * \mathsf{\mathbf{A}}_{\widetilde{J}}
4559 * =
4560 * \mathsf{\mathbf{F}}_{\widetilde{J}}
4561 * -
4562 * \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{J}}
4563 * d \widetilde{\mathsf{\mathbf{J}}}
4564 * @f$
4565 *
4566 * @code
4567 *   A.block(J_dof) += system_rhs.block(J_dof);
4568 * @endcode
4569 *
4570 * and finally....
4571 * @f$
4572 * d \widetilde{\mathsf{\mathbf{p}}}
4573 * =
4574 * \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{p}}^{-1}
4575 * \bigl[
4576 * \mathsf{\mathbf{F}}_{\widetilde{J}}
4577 * - \mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{J}}
4578 * d \widetilde{\mathsf{\mathbf{J}}}
4579 * \bigr]
4580 * @f$
4581 *
4582 * @code
4583 *   tangent_matrix.block(p_dof, J_dof)
4584 *   .Tvmult(newton_update.block(p_dof), A.block(J_dof));
4585 *   }
4586 *  
4587 * @endcode
4588 *
4589 * We are now at the end, so we distribute all
4590 * constrained dofs back to the Newton
4591 * update:
4592 *
4593 * @code
4594 *   constraints.distribute(newton_update);
4595 *  
4596 *   timer.leave_subsection();
4597 *   }
4598 *   else
4599 *   {
4600 *   std::cout << " ------ " << std::flush;
4601 *  
4602 *   timer.enter_subsection("Linear solver");
4603 *   std::cout << " SLV " << std::flush;
4604 *  
4605 *   if (parameters.type_lin == "CG")
4606 *   {
4607 * @endcode
4608 *
4609 * Manual condensation of the dilatation and pressure fields on
4610 * a local level, and subsequent post-processing, took quite a
4611 * bit of effort to achieve. To recap, we had to produce the
4612 * inverse matrix
4613 * @f$\mathsf{\mathbf{K}}_{\widetilde{p}\widetilde{J}}^{-1}@f$, which
4614 * was permanently written into the global tangent matrix. We then
4615 * permanently modified @f$\mathsf{\mathbf{K}}_{uu}@f$ to produce
4616 * @f$\mathsf{\mathbf{K}}_{\textrm{con}}@f$. This involved the
4617 * extraction and manipulation of local sub-blocks of the tangent
4618 * matrix. After solving for the displacement, the individual
4619 * matrix-vector operations required to solve for dilatation and
4620 * pressure were carefully implemented. Contrast these many sequence
4621 * of steps to the much simpler and transparent implementation using
4622 * functionality provided by the LinearOperator class.
4623 *
4624
4625 *
4626 * For ease of later use, we define some aliases for
4627 * blocks in the RHS vector
4628 *
4629 * @code
4630 *   const Vector<double> &f_u = system_rhs.block(u_dof);
4631 *   const Vector<double> &f_p = system_rhs.block(p_dof);
4632 *   const Vector<double> &f_J = system_rhs.block(J_dof);
4633 *  
4634 * @endcode
4635 *
4636 * ... and for blocks in the Newton update vector.
4637 *
4638 * @code
4639 *   Vector<double> &d_u = newton_update.block(u_dof);
4640 *   Vector<double> &d_p = newton_update.block(p_dof);
4641 *   Vector<double> &d_J = newton_update.block(J_dof);
4642 *  
4643 * @endcode
4644 *
4645 * We next define some linear operators for the tangent matrix
4646 * sub-blocks We will exploit the symmetry of the system, so not all
4647 * blocks are required.
4648 *
4649 * @code
4650 *   const auto K_uu =
4651 *   linear_operator(tangent_matrix.block(u_dof, u_dof));
4652 *   const auto K_up =
4653 *   linear_operator(tangent_matrix.block(u_dof, p_dof));
4654 *   const auto K_pu =
4655 *   linear_operator(tangent_matrix.block(p_dof, u_dof));
4656 *   const auto K_Jp =
4657 *   linear_operator(tangent_matrix.block(J_dof, p_dof));
4658 *   const auto K_JJ =
4659 *   linear_operator(tangent_matrix.block(J_dof, J_dof));
4660 *  
4661 * @endcode
4662 *
4663 * We then construct a LinearOperator that represents the inverse of
4664 * (square block)
4665 * @f$\mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{p}}@f$. Since it is
4666 * diagonal (or, when a higher order ansatz it used, nearly
4667 * diagonal), a Jacobi preconditioner is suitable.
4668 *
4669 * @code
4671 *   preconditioner_K_Jp_inv("jacobi");
4672 *   preconditioner_K_Jp_inv.use_matrix(
4673 *   tangent_matrix.block(J_dof, p_dof));
4674 *   ReductionControl solver_control_K_Jp_inv(
4675 *   static_cast<unsigned int>(tangent_matrix.block(J_dof, p_dof).m() *
4676 *   parameters.max_iterations_lin),
4677 *   1.0e-30,
4678 *   parameters.tol_lin);
4679 *   SolverSelector<Vector<double>> solver_K_Jp_inv;
4680 *   solver_K_Jp_inv.select("cg");
4681 *   solver_K_Jp_inv.set_control(solver_control_K_Jp_inv);
4682 *   const auto K_Jp_inv =
4683 *   inverse_operator(K_Jp, solver_K_Jp_inv, preconditioner_K_Jp_inv);
4684 *  
4685 * @endcode
4686 *
4687 * Now we can construct that transpose of
4688 * @f$\mathsf{\mathbf{K}}_{\widetilde{J}\widetilde{p}}^{-1}@f$ and a
4689 * linear operator that represents the condensed operations
4690 * @f$\overline{\mathsf{\mathbf{K}}}@f$ and
4691 * @f$\overline{\overline{\mathsf{\mathbf{K}}}}@f$ and the final
4692 * augmented matrix
4693 * @f$\mathsf{\mathbf{K}}_{\textrm{con}}@f$.
4694 * Note that the schur_complement() operator could also be of use
4695 * here, but for clarity and the purpose of demonstrating the
4696 * similarities between the formulation and implementation of the
4697 * linear solution scheme, we will perform these operations
4698 * manually.
4699 *
4700 * @code
4701 *   const auto K_pJ_inv = transpose_operator(K_Jp_inv);
4702 *   const auto K_pp_bar = K_Jp_inv * K_JJ * K_pJ_inv;
4703 *   const auto K_uu_bar_bar = K_up * K_pp_bar * K_pu;
4704 *   const auto K_uu_con = K_uu + K_uu_bar_bar;
4705 *  
4706 * @endcode
4707 *
4708 * Lastly, we define an operator for inverse of augmented stiffness
4709 * matrix, namely @f$\mathsf{\mathbf{K}}_{\textrm{con}}^{-1}@f$. Note
4710 * that the preconditioner for the augmented stiffness matrix is
4711 * different to the case when we use static condensation. In this
4712 * instance, the preconditioner is based on a non-modified
4713 * @f$\mathsf{\mathbf{K}}_{uu}@f$, while with the first approach we
4714 * actually modified the entries of this sub-block. However, since
4715 * @f$\mathsf{\mathbf{K}}_{\textrm{con}}@f$ and
4716 * @f$\mathsf{\mathbf{K}}_{uu}@f$ operate on the same space, it remains
4717 * adequate for this problem.
4718 *
4719 * @code
4721 *   preconditioner_K_con_inv(parameters.preconditioner_type,
4722 *   parameters.preconditioner_relaxation);
4723 *   preconditioner_K_con_inv.use_matrix(
4724 *   tangent_matrix.block(u_dof, u_dof));
4725 *   ReductionControl solver_control_K_con_inv(
4726 *   static_cast<unsigned int>(tangent_matrix.block(u_dof, u_dof).m() *
4727 *   parameters.max_iterations_lin),
4728 *   1.0e-30,
4729 *   parameters.tol_lin);
4730 *   SolverSelector<Vector<double>> solver_K_con_inv;
4731 *   solver_K_con_inv.select("cg");
4732 *   solver_K_con_inv.set_control(solver_control_K_con_inv);
4733 *   const auto K_uu_con_inv =
4734 *   inverse_operator(K_uu_con,
4735 *   solver_K_con_inv,
4736 *   preconditioner_K_con_inv);
4737 *  
4738 * @endcode
4739 *
4740 * Now we are in a position to solve for the displacement field.
4741 * We can nest the linear operations, and the result is immediately
4742 * written to the Newton update vector.
4743 * It is clear that the implementation closely mimics the derivation
4744 * stated in the introduction.
4745 *
4746 * @code
4747 *   d_u =
4748 *   K_uu_con_inv * (f_u - K_up * (K_Jp_inv * f_J - K_pp_bar * f_p));
4749 *  
4750 *   timer.leave_subsection();
4751 *  
4752 * @endcode
4753 *
4754 * The operations need to post-process for the dilatation and
4755 * pressure fields are just as easy to express.
4756 *
4757 * @code
4758 *   timer.enter_subsection("Linear solver postprocessing");
4759 *   std::cout << " PP " << std::flush;
4760 *  
4761 *   d_J = K_pJ_inv * (f_p - K_pu * d_u);
4762 *   d_p = K_Jp_inv * (f_J - K_JJ * d_J);
4763 *  
4764 *   lin_it = solver_control_K_con_inv.last_step();
4765 *   lin_res = solver_control_K_con_inv.last_value();
4766 *   }
4767 *   else if (parameters.type_lin == "Direct")
4768 *   {
4769 * @endcode
4770 *
4771 * Solve the full block system with
4772 * a direct solver. As it is relatively
4773 * robust, it may be immune to problem
4774 * arising from the presence of the zero
4775 * @f$\mathsf{\mathbf{K}}_{ \widetilde{J} \widetilde{J}}@f$
4776 * block.
4777 *
4778 * @code
4779 *   SparseDirectUMFPACK A_direct;
4780 *   A_direct.initialize(tangent_matrix);
4781 *   A_direct.vmult(newton_update, system_rhs);
4782 *  
4783 *   lin_it = 1;
4784 *   lin_res = 0.0;
4785 *  
4786 *   std::cout << " -- " << std::flush;
4787 *   }
4788 *   else
4789 *   Assert(false, ExcMessage("Linear solver type not implemented"));
4790 *  
4791 *   timer.leave_subsection();
4792 *  
4793 * @endcode
4794 *
4795 * Finally, we again ensure here that any Dirichlet
4796 * constraints are distributed on the updated solution:
4797 *
4798 * @code
4799 *   constraints.distribute(newton_update);
4800 *   }
4801 *  
4802 *   return std::make_pair(lin_it, lin_res);
4803 *   }
4804 *  
4805 * @endcode
4806 *
4807 *
4808 * <a name="Solidoutput_results"></a>
4809 * <h4>Solid::output_results</h4>
4810 * Here we present how the results are written to file to be viewed
4811 * using ParaView or VisIt. The method is similar to that shown in previous
4812 * tutorials so will not be discussed in detail.
4813 *
4814
4815 *
4816 * @note As of 2023, Visit 3.3.3 can still not deal with higher-order cells.
4817 * Rather, it simply reports that there is no data to show. To view the
4818 * results of this program with Visit, you will want to comment out the
4819 * line that sets `output_flags.write_higher_order_cells = true;`. On the
4820 * other hand, Paraview is able to understand VTU files with higher order
4821 * cells just fine.
4822 *
4823 * @code
4824 *   template <int dim>
4825 *   void Solid<dim>::output_results() const
4826 *   {
4827 *   DataOut<dim> data_out;
4828 *   std::vector<DataComponentInterpretation::DataComponentInterpretation>
4829 *   data_component_interpretation(
4831 *   data_component_interpretation.push_back(
4833 *   data_component_interpretation.push_back(
4835 *  
4836 *   std::vector<std::string> solution_name(dim, "displacement");
4837 *   solution_name.emplace_back("pressure");
4838 *   solution_name.emplace_back("dilatation");
4839 *  
4840 *   DataOutBase::VtkFlags output_flags;
4841 *   output_flags.write_higher_order_cells = true;
4842 *   output_flags.physical_units["displacement"] = "m";
4843 *   data_out.set_flags(output_flags);
4844 *  
4845 *   data_out.attach_dof_handler(dof_handler);
4846 *   data_out.add_data_vector(solution_n,
4847 *   solution_name,
4849 *   data_component_interpretation);
4850 *  
4851 * @endcode
4852 *
4853 * Since we are dealing with a large deformation problem, it would be nice
4854 * to display the result on a displaced grid! The MappingQEulerian class
4855 * linked with the DataOut class provides an interface through which this
4856 * can be achieved without physically moving the grid points in the
4857 * Triangulation object ourselves. We first need to copy the solution to
4858 * a temporary vector and then create the Eulerian mapping. We also
4859 * specify the polynomial degree to the DataOut object in order to produce
4860 * a more refined output data set when higher order polynomials are used.
4861 *
4862 * @code
4863 *   Vector<double> soln(solution_n.size());
4864 *   for (unsigned int i = 0; i < soln.size(); ++i)
4865 *   soln(i) = solution_n(i);
4866 *   MappingQEulerian<dim> q_mapping(degree, dof_handler, soln);
4867 *   data_out.build_patches(q_mapping, degree);
4868 *  
4869 *   std::ofstream output("solution-" + std::to_string(dim) + "d-" +
4870 *   std::to_string(time.get_timestep()) + ".vtu");
4871 *   data_out.write_vtu(output);
4872 *   }
4873 *  
4874 *   } // namespace Step44
4875 *  
4876 *  
4877 * @endcode
4878 *
4879 *
4880 * <a name="Mainfunction"></a>
4881 * <h3>Main function</h3>
4882 * Lastly we provide the main driver function which appears
4883 * no different to the other tutorials.
4884 *
4885 * @code
4886 *   int main()
4887 *   {
4888 *   using namespace Step44;
4889 *  
4890 *   try
4891 *   {
4892 *   const unsigned int dim = 3;
4893 *   Solid<dim> solid("parameters.prm");
4894 *   solid.run();
4895 *   }
4896 *   catch (std::exception &exc)
4897 *   {
4898 *   std::cerr << std::endl
4899 *   << std::endl
4900 *   << "----------------------------------------------------"
4901 *   << std::endl;
4902 *   std::cerr << "Exception on processing: " << std::endl
4903 *   << exc.what() << std::endl
4904 *   << "Aborting!" << std::endl
4905 *   << "----------------------------------------------------"
4906 *   << std::endl;
4907 *  
4908 *   return 1;
4909 *   }
4910 *   catch (...)
4911 *   {
4912 *   std::cerr << std::endl
4913 *   << std::endl
4914 *   << "----------------------------------------------------"
4915 *   << std::endl;
4916 *   std::cerr << "Unknown exception!" << std::endl
4917 *   << "Aborting!" << std::endl
4918 *   << "----------------------------------------------------"
4919 *   << std::endl;
4920 *   return 1;
4921 *   }
4922 *  
4923 *   return 0;
4924 *   }
4925 * @endcode
4926<a name="Results"></a><h1>Results</h1>
4927
4928
4929Firstly, we present a comparison of a series of 3-d results with those
4930in the literature (see Reese et al (2000)) to demonstrate that the program works as expected.
4931
4932We begin with a comparison of the convergence with mesh refinement for the @f$Q_1-DGPM_0-DGPM_0@f$ and
4933@f$Q_2-DGPM_1-DGPM_1@f$ formulations, as summarised in the figure below.
4934The vertical displacement of the midpoint of the upper surface of the block is used to assess convergence.
4935Both schemes demonstrate good convergence properties for varying values of the load parameter @f$p/p_0@f$.
4936The results agree with those in the literature.
4937The lower-order formulation typically overestimates the displacement for low levels of refinement,
4938while the higher-order interpolation scheme underestimates it, but be a lesser degree.
4939This benchmark, and a series of others not shown here, give us confidence that the code is working
4940as it should.
4941
4942<table align="center" class="tutorial" cellspacing="3" cellpadding="3">
4943 <tr>
4944 <td align="center">
4945 <img src="https://www.dealii.org/images/steps/developer/step-44.Q1-P0_convergence.png" alt="">
4946 <p align="center">
4947 Convergence of the @f$Q_1-DGPM_0-DGPM_0@f$ formulation in 3-d.
4948 </p>
4949 </td>
4950 <td align="center">
4951 <img src="https://www.dealii.org/images/steps/developer/step-44.Q2-P1_convergence.png" alt="">
4952 <p align="center">
4953 Convergence of the @f$Q_2-DGPM_1-DGPM_1@f$ formulation in 3-d.
4954 </p>
4955 </td>
4956 </tr>
4957</table>
4958
4959
4960A typical screen output generated by running the problem is shown below.
4961The particular case demonstrated is that of the @f$Q_2-DGPM_1-DGPM_1@f$ formulation.
4962It is clear that, using the Newton-Raphson method, quadratic convergence of the solution is obtained.
4963Solution convergence is achieved within 5 Newton increments for all time-steps.
4964The converged displacement's @f$L_2@f$-norm is several orders of magnitude less than the geometry scale.
4965
4966@code
4967Grid:
4968 Reference volume: 1e-09
4970 Number of active cells: 64
4971 Number of degrees of freedom: 2699
4972 Setting up quadrature point data...
4973
4974Timestep 1 @ 0.1s
4975___________________________________________________________________________________________________________________________________________________________
4976 SOLVER STEP | LIN_IT LIN_RES RES_NORM RES_U RES_P RES_J NU_NORM NU_U NU_P NU_J
4977___________________________________________________________________________________________________________________________________________________________
4978 0 ASM_R ASM_K CST ASM_SC SLV PP UQPH | 786 2.118e-06 1.000e+00 1.000e+00 0.000e+00 0.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00
4979 1 ASM_R ASM_K CST ASM_SC SLV PP UQPH | 552 1.031e-03 8.563e-02 8.563e-02 9.200e-13 3.929e-08 1.060e-01 3.816e-02 1.060e-01 1.060e-01
4980 2 ASM_R ASM_K CST ASM_SC SLV PP UQPH | 667 5.602e-06 2.482e-03 2.482e-03 3.373e-15 2.982e-10 2.936e-03 2.053e-04 2.936e-03 2.936e-03
4981 3 ASM_R ASM_K CST ASM_SC SLV PP UQPH | 856 6.469e-10 2.129e-06 2.129e-06 2.245e-19 1.244e-13 1.887e-06 7.289e-07 1.887e-06 1.887e-06
4982 4 ASM_R CONVERGED!
4983___________________________________________________________________________________________________________________________________________________________
4984Relative errors:
4985Displacement: 7.289e-07
4986Force: 2.451e-10
4987Dilatation: 1.353e-07
4988v / V_0: 1.000e-09 / 1.000e-09 = 1.000e+00
4989
4990
4991[...]
4992
4993Timestep 10 @ 1.000e+00s
4994___________________________________________________________________________________________________________________________________________________________
4995 SOLVER STEP | LIN_IT LIN_RES RES_NORM RES_U RES_P RES_J NU_NORM NU_U NU_P NU_J
4996___________________________________________________________________________________________________________________________________________________________
4997 0 ASM_R ASM_K CST ASM_SC SLV PP UQPH | 874 2.358e-06 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00 1.000e+00
4998 1 ASM_R ASM_K CST ASM_SC SLV PP UQPH | 658 2.942e-04 1.544e-01 1.544e-01 1.208e+13 1.855e+06 6.014e-02 7.398e-02 6.014e-02 6.014e-02
4999 2 ASM_R ASM_K CST ASM_SC SLV PP UQPH | 790 2.206e-06 2.908e-03 2.908e-03 7.302e+10 2.067e+03 2.716e-03 1.433e-03 2.716e-03 2.717e-03
5000 3 ASM_R ASM_K CST ASM_SC SLV PP UQPH | 893 2.374e-09 1.919e-06 1.919e-06 4.527e+07 4.100e+00 1.672e-06 6.842e-07 1.672e-06 1.672e-06
5001 4 ASM_R CONVERGED!
5002___________________________________________________________________________________________________________________________________________________________
5003Relative errors:
5004Displacement: 6.842e-07
5005Force: 8.995e-10
5006Dilatation: 1.528e-06
5007v / V_0: 1.000e-09 / 1.000e-09 = 1.000e+00
5008@endcode
5009
5010
5011
5012Using the Timer class, we can discern which parts of the code require the highest computational expense.
5013For a case with a large number of degrees-of-freedom (i.e. a high level of refinement), a typical output of the Timer is given below.
5014Much of the code in the tutorial has been developed based on the optimizations described,
5015discussed and demonstrated in @ref step_18 "step-18" and others.
5016With over 93% of the time being spent in the linear solver, it is obvious that it may be necessary
5017to invest in a better solver for large three-dimensional problems.
5018The SSOR preconditioner is not multithreaded but is effective for this class of solid problems.
5019It may be beneficial to investigate the use of another solver such as those available through the Trilinos library.
5020
5021
5022@code
5023+---------------------------------------------+------------+------------+
5024| Total wallclock time elapsed since start | 9.874e+02s | |
5025| | | |
5026| Section | no. calls | wall time | % of total |
5027+---------------------------------+-----------+------------+------------+
5028| Assemble system right-hand side | 53 | 1.727e+00s | 1.75e-01% |
5029| Assemble tangent matrix | 43 | 2.707e+01s | 2.74e+00% |
5030| Linear solver | 43 | 9.248e+02s | 9.37e+01% |
5031| Linear solver postprocessing | 43 | 2.743e-02s | 2.78e-03% |
5032| Perform static condensation | 43 | 1.437e+01s | 1.46e+00% |
5033| Setup system | 1 | 3.897e-01s | 3.95e-02% |
5034| Update QPH data | 43 | 5.770e-01s | 5.84e-02% |
5035+---------------------------------+-----------+------------+------------+
5036@endcode
5037
5038
5039We then used ParaView to visualize the results for two cases.
5040The first was for the coarsest grid and the lowest-order interpolation method: @f$Q_1-DGPM_0-DGPM_0@f$.
5041The second was on a refined grid using a @f$Q_2-DGPM_1-DGPM_1@f$ formulation.
5042The vertical component of the displacement, the pressure @f$\widetilde{p}@f$ and the dilatation @f$\widetilde{J}@f$ fields
5043are shown below.
5044
5045
5046For the first case it is clear that the coarse spatial discretization coupled with large displacements leads to a low quality solution
5047(the loading ratio is @f$p/p_0=80@f$).
5048Additionally, the pressure difference between elements is very large.
5049The constant pressure field on the element means that the large pressure gradient is not captured.
5050However, it should be noted that locking, which would be present in a standard @f$Q_1@f$ displacement formulation does not arise
5051even in this poorly discretised case.
5052The final vertical displacement of the tracked node on the top surface of the block is still within 12.5% of the converged solution.
5053The pressure solution is very coarse and has large jumps between adjacent cells.
5054It is clear that the volume nearest to the applied traction undergoes compression while the outer extents
5055of the domain are in a state of expansion.
5056The dilatation solution field and pressure field are clearly linked,
5057with positive dilatation indicating regions of positive pressure and negative showing regions placed in compression.
5058As discussed in the Introduction, a compressive pressure has a negative sign
5059while an expansive pressure takes a positive sign.
5060This stems from the definition of the volumetric strain energy function
5061and is opposite to the physically realistic interpretation of pressure.
5062
5063
5064<table align="center" class="tutorial" cellspacing="3" cellpadding="3">
5065 <tr>
5066 <td align="center">
5067 <img src="https://www.dealii.org/images/steps/developer/step-44.Q1-P0_gr_1_p_ratio_80-displacement.png" alt="">
5068 <p align="center">
5069 Z-displacement solution for the 3-d problem.
5070 </p>
5071 </td>
5072 <td align="center">
5073 <img src="https://www.dealii.org/images/steps/developer/step-44.Q1-P0_gr_1_p_ratio_80-pressure.png" alt="">
5074 <p align="center">
5075 Discontinuous piece-wise constant pressure field.
5076 </p>
5077 </td>
5078 <td align="center">
5079 <img src="https://www.dealii.org/images/steps/developer/step-44.Q1-P0_gr_1_p_ratio_80-dilatation.png" alt="">
5080 <p align="center">
5081 Discontinuous piece-wise constant dilatation field.
5082 </p>
5083 </td>
5084 </tr>
5085</table>
5086
5087Combining spatial refinement and a higher-order interpolation scheme results in a high-quality solution.
5088Three grid refinements coupled with a @f$Q_2-DGPM_1-DGPM_1@f$ formulation produces
5089a result that clearly captures the mechanics of the problem.
5090The deformation of the traction surface is well resolved.
5091We can now observe the actual extent of the applied traction, with the maximum force being applied
5092at the central point of the surface causing the largest compression.
5093Even though very high strains are experienced in the domain,
5094especially at the boundary of the region of applied traction,
5095the solution remains accurate.
5096The pressure field is captured in far greater detail than before.
5097There is a clear distinction and transition between regions of compression and expansion,
5098and the linear approximation of the pressure field allows a refined visualization
5099of the pressure at the sub-element scale.
5100It should however be noted that the pressure field remains discontinuous
5101and could be smoothed on a continuous grid for the post-processing purposes.
5102
5103
5104
5105<table align="center" class="tutorial" cellspacing="3" cellpadding="3">
5106 <tr>
5107 <td align="center">
5108 <img src="https://www.dealii.org/images/steps/developer/step-44.Q2-P1_gr_3_p_ratio_80-displacement.png" alt="">
5109 <p align="center">
5110 Z-displacement solution for the 3-d problem.
5111 </p>
5112 </td>
5113 <td align="center">
5114 <img src="https://www.dealii.org/images/steps/developer/step-44.Q2-P1_gr_3_p_ratio_80-pressure.png" alt="">
5115 <p align="center">
5116 Discontinuous linear pressure field.
5117 </p>
5118 </td>
5119 <td align="center">
5120 <img src="https://www.dealii.org/images/steps/developer/step-44.Q2-P1_gr_3_p_ratio_80-dilatation.png" alt="">
5121 <p align="center">
5122 Discontinuous linear dilatation field.
5123 </p>
5124 </td>
5125 </tr>
5126</table>
5127
5128This brief analysis of the results demonstrates that the three-field formulation is effective
5129in circumventing volumetric locking for highly-incompressible media.
5130The mixed formulation is able to accurately simulate the displacement of a
5131near-incompressible block under compression.
5132The command-line output indicates that the volumetric change under extreme compression resulted in
5133less than 0.01% volume change for a Poisson's ratio of 0.4999.
5134
5135In terms of run-time, the @f$Q_2-DGPM_1-DGPM_1@f$ formulation tends to be more computationally expensive
5136than the @f$Q_1-DGPM_0-DGPM_0@f$ for a similar number of degrees-of-freedom
5137(produced by adding an extra grid refinement level for the lower-order interpolation).
5138This is shown in the graph below for a batch of tests run consecutively on a single 4-core (8-thread) machine.
5139The increase in computational time for the higher-order method is likely due to
5140the increased band-width required for the higher-order elements.
5141As previously mentioned, the use of a better solver and preconditioner may mitigate the
5142expense of using a higher-order formulation.
5143It was observed that for the given problem using the multithreaded Jacobi preconditioner can reduce the
5144computational runtime by up to 72% (for the worst case being a higher-order formulation with a large number
5145of degrees-of-freedom) in comparison to the single-thread SSOR preconditioner.
5146However, it is the author's experience that the Jacobi method of preconditioning may not be suitable for
5147some finite-strain problems involving alternative constitutive models.
5148
5149
5150<table align="center" class="tutorial" cellspacing="3" cellpadding="3">
5151 <tr>
5152 <td align="center">
5153 <img src="https://www.dealii.org/images/steps/developer/step-44.Normalised_runtime.png" alt="">
5154 <p align="center">
5155 Runtime on a 4-core machine, normalised against the lowest grid resolution @f$Q_1-DGPM_0-DGPM_0@f$ solution that utilised a SSOR preconditioner.
5156 </p>
5157 </td>
5158 </tr>
5159</table>
5160
5161
5162Lastly, results for the displacement solution for the 2-d problem are showcased below for
5163two different levels of grid refinement.
5164It is clear that due to the extra constraints imposed by simulating in 2-d that the resulting
5165displacement field, although qualitatively similar, is different to that of the 3-d case.
5166
5167
5168<table align="center" class="tutorial" cellspacing="3" cellpadding="3">
5169 <tr>
5170 <td align="center">
5171 <img src="https://www.dealii.org/images/steps/developer/step-44.2d-gr_2.png" alt="">
5172 <p align="center">
5173 Y-displacement solution in 2-d for 2 global grid refinement levels.
5174 </p>
5175 </td>
5176 <td align="center">
5177 <img src="https://www.dealii.org/images/steps/developer/step-44.2d-gr_5.png" alt="">
5178 <p align="center">
5179 Y-displacement solution in 2-d for 5 global grid refinement levels.
5180 </p>
5181 </td>
5182 </tr>
5183</table>
5184
5185<a name="extensions"></a>
5186<a name="Possibilitiesforextensions"></a><h3>Possibilities for extensions</h3>
5187
5188
5189There are a number of obvious extensions for this work:
5190
5191- Firstly, an additional constraint could be added to the free-energy
5192 function in order to enforce a high degree of incompressibility in
5193 materials. An additional Lagrange multiplier would be introduced,
5194 but this could most easily be dealt with using the principle of
5195 augmented Lagrange multipliers. This is demonstrated in <em>Simo and
5196 Taylor (1991) </em>.
5197- The constitutive relationship used in this
5198 model is relatively basic. It may be beneficial to split the material
5199 class into two separate classes, one dealing with the volumetric
5200 response and the other the isochoric response, and produce a generic
5201 materials class (i.e. having abstract virtual functions that derived
5202 classes have to implement) that would allow for the addition of more complex
5203 material models. Such models could include other hyperelastic
5204 materials, plasticity and viscoelastic materials and others.
5205- The program has been developed for solving problems on single-node
5206 multicore machines. With a little effort, the program could be
5207 extended to a large-scale computing environment through the use of
5208 PETSc or Trilinos, using a similar technique to that demonstrated in
5209 @ref step_40 "step-40". This would mostly involve changes to the setup, assembly,
5210 <code>PointHistory</code> and linear solver routines.
5211- As this program assumes quasi-static equilibrium, extensions to
5212 include dynamic effects would be necessary to study problems where
5213 inertial effects are important, e.g. problems involving impact.
5214- Load and solution limiting procedures may be necessary for highly
5215 nonlinear problems. It is possible to add a linesearch algorithm to
5216 limit the step size within a Newton increment to ensure optimum
5217 convergence. It may also be necessary to use a load limiting method,
5218 such as the Riks method, to solve unstable problems involving
5219 geometric instability such as buckling and snap-through.
5220- Many physical problems involve contact. It is possible to include
5221 the effect of frictional or frictionless contact between objects
5222 into this program. This would involve the addition of an extra term
5223 in the free-energy functional and therefore an addition to the
5224 assembly routine. One would also need to manage the contact problem
5225 (detection and stress calculations) itself. An alternative to
5226 additional penalty terms in the free-energy functional would be to
5227 use active set methods such as the one used in @ref step_41 "step-41".
5228- The complete condensation procedure using LinearOperators has been
5229 coded into the linear solver routine. This could also have been
5230 achieved through the application of the schur_complement()
5231 operator to condense out one or more of the fields in a more
5232 automated manner.
5233- Finally, adaptive mesh refinement, as demonstrated in @ref step_6 "step-6" and
5234 @ref step_18 "step-18", could provide additional solution accuracy.
5235 *
5236 *
5237<a name="PlainProg"></a>
5238<h1> The plain program</h1>
5239@include "step-44.cc"
5240*/
void select(const std::string &name)
void initialize(const SparsityPattern &sparsity_pattern)
Definition timer.h:118
Point< 3 > center
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
Point< 2 > second
Definition grid_out.cc:4616
Point< 2 > first
Definition grid_out.cc:4615
unsigned int level
Definition grid_out.cc:4618
__global__ void set(Number *val, const Number s, const size_type N)
#define Assert(cond, exc)
LinearOperator< Range, Domain, Payload > linear_operator(const OperatorExemplar &, const Matrix &)
LinearOperator< Domain, Range, Payload > transpose_operator(const LinearOperator< Range, Domain, Payload > &op)
LinearOperator< Range_2, Domain_2, Payload > schur_complement(const LinearOperator< Domain_1, Range_1, Payload > &A_inv, const LinearOperator< Range_1, Domain_2, Payload > &B, const LinearOperator< Range_2, Domain_1, Payload > &C, const LinearOperator< Range_2, Domain_2, Payload > &D)
LinearOperator< Domain, Range, Payload > inverse_operator(const LinearOperator< Range, Domain, Payload > &op, Solver &solver, const Preconditioner &preconditioner)
void loop(ITERATOR begin, std_cxx20::type_identity_t< ITERATOR > end, DOFINFO &dinfo, INFOBOX &info, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(DOFINFO &, DOFINFO &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, ASSEMBLER &assembler, const LoopControl &lctrl=LoopControl())
Definition loop.h:439
UpdateFlags
Task< RT > new_task(const std::function< RT()> &function)
std::vector< value_type > split(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const value_type parent_value)
const Event initial
Definition event.cc:65
CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt K
Expression sign(const Expression &x)
void scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
double volume(const Triangulation< dim, spacedim > &tria)
@ matrix
Contents is actually a matrix.
@ symmetric
Matrix is symmetric.
@ diagonal
Matrix is diagonal.
@ general
No special properties.
void cell_matrix(FullMatrix< double > &M, const FEValuesBase< dim > &fe, const FEValuesBase< dim > &fetest, const ArrayView< const std::vector< double > > &velocity, const double factor=1.)
Definition advection.h:75
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition utilities.cc:189
SymmetricTensor< 2, dim, Number > C(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
Tensor< 2, dim, Number > F(const Tensor< 2, dim, Number > &Grad_u)
VectorType::value_type * end(VectorType &V)
void free(T *&pointer)
Definition cuda.h:97
void interpolate_boundary_values(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const std::map< types::boundary_id, const Function< spacedim, number > * > &function_map, std::map< types::global_dof_index, number > &boundary_values, const ComponentMask &component_mask=ComponentMask())
void project(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const AffineConstraints< typename VectorType::value_type > &constraints, const Quadrature< dim > &quadrature, const Function< spacedim, typename VectorType::value_type > &function, VectorType &vec, const bool enforce_zero_boundary=false, const Quadrature< dim - 1 > &q_boundary=(dim > 1 ? QGauss< dim - 1 >(2) :Quadrature< dim - 1 >(0)), const bool project_to_boundary_first=false)
bool check(const ConstraintKinds kind_in, const unsigned int dim)
DEAL_II_HOST constexpr TableIndices< 2 > merge(const TableIndices< 2 > &previous_indices, const unsigned int new_index, const unsigned int position)
void copy(const T *begin, const T *end, U *dest)
int(&) functions(const void *v1, const void *v2)
void assemble(const MeshWorker::DoFInfoBox< dim, DOFINFO > &dinfo, A *assembler)
Definition loop.h:71
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition types.h:33
unsigned int boundary_id
Definition types.h:141
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation