deal.II version GIT relicensing-2173-gae8fc9d14b 2024-11-24 06:40:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
MultipointFluxMixedFiniteElementMethods.h
Go to the documentation of this file.
1
167 *  
168 *   #ifndef MFMFE_DATA_H
169 *   #define MFMFE_DATA_H
170 *  
171 *   #include <deal.II/base/function.h>
172 *   #include <deal.II/base/tensor_function.h>
173 *  
174 * @endcode
175 *
176 *
177 * <a name="data.h-Dataandexactsolution"></a>
178 * <h3>Data and exact solution.</h3>
179 *
180
181 *
182 * This file declares the classes for the given data, i.e.
183 * right-hand side, exact solution, permeability tensor and
184 * boundary conditions. For simplicity only 2d cases are
185 * provided, but 3d can be added straightforwardly.
186 *
187
188 *
189 *
190 * @code
191 *   namespace MFMFE
192 *   {
193 *   using namespace dealii;
194 *  
195 *   template <int dim>
196 *   class RightHandSide : public Function<dim>
197 *   {
198 *   public:
199 *   RightHandSide () : Function<dim>(1) {}
200 *  
201 *   virtual double value (const Point<dim> &p,
202 *   const unsigned int component = 0) const override;
203 *   };
204 *  
205 *   template <int dim>
206 *   double RightHandSide<dim>::value (const Point<dim> &p,
207 *   const unsigned int /*component*/) const
208 *   {
209 *   const double x = p[0];
210 *   const double y = p[1];
211 *  
212 *   switch (dim)
213 *   {
214 *   case 2:
215 *   return -(x*(y*y*y*y)*6.0-(y*y)*sin(x*y*2.0)*2.0+2.0)*(x*2.0+x*x+y*y+1.0)-sin(x*y)*(cos(x*y*2.0)+(x*x)*(y*y*y)*1.2E1
216 *   -x*y*sin(x*y*2.0)*2.0)*2.0-(x*2.0+2.0)*(x*2.0+(x*x)*(y*y*y*y)*3.0+y*cos(x*y*2.0))+(x*x)*(sin(x*y*2.0)
217 *   -x*(y*y)*6.0)*pow(x+1.0,2.0)*2.0-x*cos(x*y)*(x*2.0+(x*x)*(y*y*y*y)*3.0+y*(pow(cos(x*y),2.0)*2.0-1.0))
218 *   -x*y*cos(x*y)*((x*x)*(y*y*y)*4.0+pow(cos(x*y),2.0)*2.0-1.0);
219 *   default:
220 *   Assert(false, ExcMessage("The RHS data for dim != 2 is not provided"));
221 *   }
222 *   }
223 *  
224 *  
225 *  
226 *   template <int dim>
227 *   class PressureBoundaryValues : public Function<dim>
228 *   {
229 *   public:
230 *   PressureBoundaryValues () : Function<dim>(1) {}
231 *  
232 *   virtual double value (const Point<dim> &p,
233 *   const unsigned int component = 0) const override;
234 *   };
235 *  
236 *   template <int dim>
237 *   double PressureBoundaryValues<dim>::value (const Point<dim> &p,
238 *   const unsigned int /*component*/) const
239 *   {
240 *   const double x = p[0];
241 *   const double y = p[1];
242 *  
243 *   switch (dim)
244 *   {
245 *   case 2:
246 *   return (x*x*x)*(y*y*y*y)+cos(x*y)*sin(x*y)+x*x;
247 *   default:
248 *   Assert(false, ExcMessage("The BC data for dim != 2 is not provided"));
249 *   }
250 *   }
251 *  
252 *  
253 *  
254 *   template <int dim>
255 *   class ExactSolution : public Function<dim>
256 *   {
257 *   public:
258 *   ExactSolution () : Function<dim>(dim+1) {}
259 *  
260 *   virtual void vector_value (const Point<dim> &p,
261 *   Vector<double> &value) const override;
262 *  
263 *   virtual void vector_gradient (const Point<dim> &p,
264 *   std::vector<Tensor<1,dim,double>> &grads) const override;
265 *   };
266 *  
267 *   template <int dim>
268 *   void
269 *   ExactSolution<dim>::vector_value (const Point<dim> &p,
270 *   Vector<double> &values) const
271 *   {
272 *   Assert (values.size() == dim+1,
273 *   ExcDimensionMismatch (values.size(), dim+1));
274 *  
275 *   const double x = p[0];
276 *   const double y = p[1];
277 *  
278 *   switch (dim)
279 *   {
280 *   case 2:
281 *   values(0) = -(x*2.0+(x*x)*(y*y*y*y)*3.0+y*cos(x*y*2.0))*(x*2.0+x*x+y*y+1.0)-x*sin(x*y)*(cos(x*y*2.0)+(x*x)*(y*y*y)*4.0);
282 *   values(1) = -sin(x*y)*(x*2.0+(x*x)*(y*y*y*y)*3.0+y*cos(x*y*2.0))-x*(cos(x*y*2.0)+(x*x)*(y*y*y)*4.0)*pow(x+1.0,2.0);
283 *   values(2) = (x*x*x)*(y*y*y*y)+cos(x*y)*sin(x*y)+x*x;
284 *   break;
285 *   default:
286 *   Assert(false, ExcMessage("The exact solution for dim != 2 is not provided"));
287 *   }
288 *   }
289 *  
290 *   template <int dim>
291 *   void
292 *   ExactSolution<dim>::vector_gradient (const Point<dim> &p,
293 *   std::vector<Tensor<1,dim,double>> &grads) const
294 *   {
295 *   const double x = p[0];
296 *   const double y = p[1];
297 *  
298 *   switch (dim)
299 *   {
300 *   case 2:
301 *   grads[0][0] = -(x*(y*y*y*y)*6.0-(y*y)*sin(x*y*2.0)*2.0+2.0)*(x*2.0+x*x+y*y+1.0)-sin(x*y)*(cos(x*y*2.0)
302 *   +(x*x)*(y*y*y)*1.2E1-x*y*sin(x*y*2.0)*2.0)-(x*2.0+2.0)*(x*2.0+(x*x)*(y*y*y*y)*3.0
303 *   +y*cos(x*y*2.0))-x*y*cos(x*y)*((x*x)*(y*y*y)*4.0+pow(cos(x*y),2.0)*2.0-1.0);
304 *   grads[0][1] = -(cos(x*y*2.0)+(x*x)*(y*y*y)*1.2E1-x*y*sin(x*y*2.0)*2.0)*(x*2.0+x*x+y*y+1.0)
305 *   -y*(x*2.0+(x*x)*(y*y*y*y)*3.0+y*cos(x*y*2.0))*2.0-(x*x)*cos(x*y)*((x*x)*(y*y*y)*4.0
306 *   +pow(cos(x*y),2.0)*2.0-1.0)+(x*x)*sin(x*y)*(sin(x*y*2.0)-x*(y*y)*6.0)*2.0;
307 *   grads[1][0] = -sin(x*y)*(x*(y*y*y*y)*6.0-(y*y)*sin(x*y*2.0)*2.0+2.0)-pow(x+1.0,2.0)*(cos(x*y*2.0)
308 *   +(x*x)*(y*y*y)*1.2E1-x*y*sin(x*y*2.0)*2.0)-x*(cos(x*y*2.0)+(x*x)*(y*y*y)*4.0)*(x*2.0+2.0)
309 *   -y*cos(x*y)*(x*2.0+(x*x)*(y*y*y*y)*3.0+y*(pow(cos(x*y),2.0)*2.0-1.0));
310 *   grads[1][1] = -sin(x*y)*(cos(x*y*2.0)+(x*x)*(y*y*y)*1.2E1-x*y*sin(x*y*2.0)*2.0)+(x*x)*(sin(x*y*2.0)
311 *   -x*(y*y)*6.0)*pow(x+1.0,2.0)*2.0-x*cos(x*y)*(x*2.0+(x*x)*(y*y*y*y)*3.0
312 *   +y*(pow(cos(x*y),2.0)*2.0-1.0));
313 *   grads[2] = 0;
314 *   break;
315 *   default:
316 *   Assert(false, ExcMessage("The exact solution's gradient for dim != 2 is not provided"));
317 *   }
318 *   }
319 *  
320 *  
321 *  
322 *   template <int dim>
323 *   class KInverse : public TensorFunction<2,dim>
324 *   {
325 *   public:
326 *   KInverse () : TensorFunction<2,dim>() {}
327 *  
328 *   virtual void value_list (const std::vector<Point<dim> > &points,
329 *   std::vector<Tensor<2,dim> > &values) const override;
330 *   };
331 *  
332 *   template <int dim>
333 *   void
334 *   KInverse<dim>::value_list (const std::vector<Point<dim> > &points,
335 *   std::vector<Tensor<2,dim> > &values) const
336 *   {
337 *   Assert (points.size() == values.size(),
338 *   ExcDimensionMismatch (points.size(), values.size()));
339 *  
340 *   for (unsigned int p=0; p<points.size(); ++p)
341 *   {
342 *   values[p].clear ();
343 *  
344 *   const double x = points[p][0];
345 *   const double y = points[p][1];
346 *  
347 *   switch (dim)
348 *   {
349 *   case 2:
350 *   values[p][0][0] = pow(x+1.0,2.0)/(x*4.0+(x*x)*(y*y)-pow(sin(x*y),2.0)+x*(y*y)*2.0+(x*x)*6.0+(x*x*x)*4.0+x*x*x*x+y*y+1.0);
351 *   values[p][0][1] = -sin(x*y)/(x*4.0+(x*x)*(y*y)-pow(sin(x*y),2.0)+x*(y*y)*2.0+(x*x)*6.0+(x*x*x)*4.0+x*x*x*x+y*y+1.0);
352 *   values[p][1][0] = -sin(x*y)/(x*4.0+(x*x)*(y*y)-pow(sin(x*y),2.0)+x*(y*y)*2.0+(x*x)*6.0+(x*x*x)*4.0+x*x*x*x+y*y+1.0);
353 *   values[p][1][1] = (x*2.0+x*x+y*y+1.0)/(x*4.0+(x*x)*(y*y)-pow(sin(x*y),2.0)+x*(y*y)*2.0+(x*x)*6.0+(x*x*x)*4.0+x*x*x*x+y*y+1.0);
354 *   break;
355 *   default:
356 *   Assert(false, ExcMessage("The inverse of permeability tensor for dim != 2 is not provided"));
357 *   }
358 *   }
359 *   }
360 *   }
361 *  
362 *   #endif //MFMFE_DATA_H
363 * @endcode
364
365
366<a name="ann-mfmfe.cc"></a>
367<h1>Annotated version of mfmfe.cc</h1>
368 *
369 *
370 *
371 *
372 * @code
373 *   /* -----------------------------------------------------------------------------
374 *   *
375 *   * SPDX-License-Identifier: LGPL-2.1-or-later
376 *   * Copyright (C) 2018 Ilona Ambartsumyan
377 *   * Copyright (C) 2018 Eldar Khattatov
378 *   *
379 *   * This file is part of the deal.II code gallery.
380 *   *
381 *   * -----------------------------------------------------------------------------
382 *   *
383 *   * Author: Ilona Ambartsumyan, Eldar Khattatov, University of Pittsburgh, 2018
384 *   */
385 *  
386 *  
387 * @endcode
388 *
389 *
390 * <a name="mfmfe.cc-Includefiles"></a>
391 * <h3>Include files</h3>
392 *
393
394 *
395 * As usual, the list of necessary header files. There is not
396 * much new here, the files are included in order
397 * base-lac-grid-dofs-numerics followed by the C++ headers.
398 *
399 * @code
400 *   #include <deal.II/base/convergence_table.h>
401 *   #include <deal.II/base/quadrature_lib.h>
402 *   #include <deal.II/base/logstream.h>
403 *   #include <deal.II/base/timer.h>
404 *   #include <deal.II/base/utilities.h>
405 *   #include <deal.II/base/work_stream.h>
406 *  
407 *   #include <deal.II/lac/full_matrix.h>
408 *   #include <deal.II/lac/solver_cg.h>
409 *   #include <deal.II/lac/block_sparse_matrix.h>
410 *   #include <deal.II/lac/block_vector.h>
411 *   #include <deal.II/lac/precondition.h>
412 *  
413 *   #include <deal.II/grid/grid_generator.h>
414 *   #include <deal.II/grid/grid_tools.h>
415 *   #include <deal.II/grid/grid_in.h>
416 *   #include <deal.II/grid/tria.h>
417 *   #include <deal.II/dofs/dof_renumbering.h>
418 *   #include <deal.II/dofs/dof_tools.h>
419 *   #include <deal.II/fe/fe_dgq.h>
420 *   #include <deal.II/fe/fe_system.h>
421 *   #include <deal.II/fe/fe_tools.h>
422 *   #include <deal.II/numerics/vector_tools.h>
423 *   #include <deal.II/numerics/matrix_tools.h>
424 *   #include <deal.II/numerics/data_out.h>
425 *  
426 *   #include <fstream>
427 *   #include <unordered_map>
428 *  
429 * @endcode
430 *
431 * This is a header needed for the purposes of the
432 * multipoint flux mixed method, as it declares the
433 * new enhanced Raviart-Thomas finite element.
434 *
435 * @code
436 *   #include <deal.II/fe/fe_rt_bubbles.h>
437 *  
438 * @endcode
439 *
440 * For the sake of readability, the classes representing
441 * data, i.e. RHS, BCs, permeability tensor and the exact
442 * solution are placed in a file data.h which is included
443 * here
444 *
445 * @code
446 *   #include "data.h"
447 *  
448 * @endcode
449 *
450 * As always the program is in the namespace of its own with
451 * the deal.II classes and functions imported into it
452 *
453 * @code
454 *   namespace MFMFE
455 *   {
456 *   using namespace dealii;
457 *  
458 * @endcode
459 *
460 *
461 * <a name="mfmfe.cc-Definitionofmultipointfluxassemblydatastructures"></a>
462 * <h3>Definition of multipoint flux assembly data structures</h3>
463 *
464
465 *
466 * The main idea of the MFMFE method is to perform local elimination
467 * of the velocity variables in order to obtain the resulting
468 * pressure system. Since in deal.II assembly happens cell-wise,
469 * some extra work needs to be done in order to get the local
470 * mass matrices @f$A_i@f$ and the corresponding to them @f$B_i@f$.
471 *
472 * @code
473 *   namespace DataStructures
474 *   {
475 * @endcode
476 *
477 * This will be achieved by assembling cell-wise, but instead of placing
478 * the terms into a global system matrix, they will populate node-associated
479 * full matrices. For this, a data structure with fast lookup is crucial, hence
480 * the hash table, with the keys as Point<dim>
481 *
482 * @code
483 *   template <int dim>
484 *   struct hash_points
485 *   {
486 *   size_t operator()(const Point<dim> &p) const
487 *   {
488 *   size_t h1,h2,h3;
489 *   h1 = std::hash<double>()(p[0]);
490 *  
491 *   switch (dim)
492 *   {
493 *   case 1:
494 *   return h1;
495 *   case 2:
496 *   h2 = std::hash<double>()(p[1]);
497 *   return (h1 ^ h2);
498 *   case 3:
499 *   h2 = std::hash<double>()(p[1]);
500 *   h3 = std::hash<double>()(p[2]);
501 *   return (h1 ^ (h2 << 1)) ^ h3;
502 *   default:
503 *   Assert(false, ExcNotImplemented());
504 *   }
505 *   }
506 *   };
507 *  
508 * @endcode
509 *
510 * Here, the actual hash-tables are defined. We use the C++ STL <code>unordered_map</code>,
511 * with the hash function specified above. For convenience these are aliased as follows
512 *
513 * @code
514 *   template <int dim>
515 *   using PointToMatrixMap = std::unordered_map<Point<dim>, std::map<std::pair<types::global_dof_index,types::global_dof_index>, double>, hash_points<dim>>;
516 *  
517 *   template <int dim>
518 *   using PointToVectorMap = std::unordered_map<Point<dim>, std::map<types::global_dof_index, double>, hash_points<dim>>;
519 *  
520 *   template <int dim>
521 *   using PointToIndexMap = std::unordered_map<Point<dim>, std::set<types::global_dof_index>, hash_points<dim>>;
522 *  
523 * @endcode
524 *
525 * Next, since this particular program allows for the use of
526 * multiple threads, the helper CopyData structures
527 * are defined. There are two kinds of these, one is used
528 * for the copying cell-wise contributions to the corresponding
529 * node-associated data structures...
530 *
531 * @code
532 *   template <int dim>
533 *   struct NodeAssemblyCopyData
534 *   {
535 *   PointToMatrixMap<dim> cell_mat;
536 *   PointToVectorMap<dim> cell_vec;
537 *   PointToIndexMap<dim> local_pres_indices;
538 *   PointToIndexMap<dim> local_vel_indices;
539 *   std::vector<types::global_dof_index> local_dof_indices;
540 *   };
541 *  
542 * @endcode
543 *
544 * ... and the other one for the actual process of
545 * local velocity elimination and assembling the global
546 * pressure system:
547 *
548 * @code
549 *   template <int dim>
550 *   struct NodeEliminationCopyData
551 *   {
552 *   FullMatrix<double> node_pres_matrix;
553 *   Vector<double> node_pres_rhs;
554 *   FullMatrix<double> Ainverse;
555 *   FullMatrix<double> pressure_matrix;
556 *   Vector<double> velocity_rhs;
557 *   Vector<double> vertex_vel_solution;
558 *   Point<dim> p;
559 *   };
560 *  
561 * @endcode
562 *
563 * Similarly, two ScratchData classes are defined.
564 * One for the assembly part, where we need
565 * FEValues, FEFaceValues, Quadrature and storage
566 * for the basis functions...
567 *
568 * @code
569 *   template <int dim>
570 *   struct NodeAssemblyScratchData
571 *   {
572 *   NodeAssemblyScratchData (const FiniteElement<dim> &fe,
573 *   const Triangulation<dim> &tria,
574 *   const Quadrature<dim> &quad,
575 *   const Quadrature<dim-1> &f_quad);
576 *  
577 *   NodeAssemblyScratchData (const NodeAssemblyScratchData &scratch_data);
578 *  
579 *   FEValues<dim> fe_values;
580 *   FEFaceValues<dim> fe_face_values;
581 *   std::vector<unsigned int> n_faces_at_vertex;
582 *  
583 *   const unsigned long num_cells;
584 *  
585 *   std::vector<Tensor<2,dim>> k_inverse_values;
586 *   std::vector<double> rhs_values;
587 *   std::vector<double> pres_bc_values;
588 *  
589 *   std::vector<Tensor<1,dim> > phi_u;
590 *   std::vector<double> div_phi_u;
591 *   std::vector<double> phi_p;
592 *   };
593 *  
594 *   template <int dim>
595 *   NodeAssemblyScratchData<dim>::
596 *   NodeAssemblyScratchData (const FiniteElement<dim> &fe,
597 *   const Triangulation<dim> &tria,
598 *   const Quadrature<dim> &quad,
599 *   const Quadrature<dim-1> &f_quad)
600 *   :
601 *   fe_values (fe,
602 *   quad,
605 *   fe_face_values (fe,
606 *   f_quad,
609 *   num_cells(tria.n_active_cells()),
610 *   k_inverse_values(quad.size()),
611 *   rhs_values(quad.size()),
612 *   pres_bc_values(f_quad.size()),
613 *   phi_u(fe.dofs_per_cell),
614 *   div_phi_u(fe.dofs_per_cell),
615 *   phi_p(fe.dofs_per_cell)
616 *   {
617 *   n_faces_at_vertex.resize(tria.n_vertices(), 0);
618 *   typename Triangulation<dim>::active_face_iterator face = tria.begin_active_face(), endf = tria.end_face();
619 *  
620 *   for (; face != endf; ++face)
621 *   for (unsigned int v=0; v<GeometryInfo<dim>::vertices_per_face; ++v)
622 *   n_faces_at_vertex[face->vertex_index(v)] += 1;
623 *   }
624 *  
625 *   template <int dim>
626 *   NodeAssemblyScratchData<dim>::
627 *   NodeAssemblyScratchData (const NodeAssemblyScratchData &scratch_data)
628 *   :
629 *   fe_values (scratch_data.fe_values.get_fe(),
630 *   scratch_data.fe_values.get_quadrature(),
633 *   fe_face_values (scratch_data.fe_face_values.get_fe(),
634 *   scratch_data.fe_face_values.get_quadrature(),
637 *   n_faces_at_vertex(scratch_data.n_faces_at_vertex),
638 *   num_cells(scratch_data.num_cells),
639 *   k_inverse_values(scratch_data.k_inverse_values),
640 *   rhs_values(scratch_data.rhs_values),
641 *   pres_bc_values(scratch_data.pres_bc_values),
642 *   phi_u(scratch_data.phi_u),
643 *   div_phi_u(scratch_data.div_phi_u),
644 *   phi_p(scratch_data.phi_p)
645 *   {}
646 *  
647 * @endcode
648 *
649 * ...and the other, simpler one, for the velocity elimination and recovery
650 *
651 * @code
652 *   struct VertexEliminationScratchData
653 *   {
654 *   VertexEliminationScratchData () = default;
655 *   VertexEliminationScratchData (const VertexEliminationScratchData &scratch_data);
656 *  
657 *   FullMatrix<double> velocity_matrix;
658 *   Vector<double> pressure_rhs;
659 *  
660 *   Vector<double> local_pressure_solution;
661 *   Vector<double> tmp_rhs1;
662 *   Vector<double> tmp_rhs2;
663 *   Vector<double> tmp_rhs3;
664 *   };
665 *  
666 *   VertexEliminationScratchData::
667 *   VertexEliminationScratchData (const VertexEliminationScratchData &scratch_data)
668 *   :
669 *   velocity_matrix(scratch_data.velocity_matrix),
670 *   pressure_rhs(scratch_data.pressure_rhs),
671 *   local_pressure_solution(scratch_data.local_pressure_solution),
672 *   tmp_rhs1(scratch_data.tmp_rhs1),
673 *   tmp_rhs2(scratch_data.tmp_rhs2),
674 *   tmp_rhs3(scratch_data.tmp_rhs3)
675 *   {}
676 *   }
677 *  
678 *  
679 *  
680 * @endcode
681 *
682 *
683 * <a name="mfmfe.cc-ThecodeMultipointMixedDarcyProblemcodeclasstemplate"></a>
684 * <h3>The <code>MultipointMixedDarcyProblem</code> class template</h3>
685 *
686
687 *
688 * The main class, besides the constructor and destructor, has only one public member
689 * <code>run()</code>, similarly to the tutorial programs. The private members can
690 * be grouped into the ones that are used for the cell-wise assembly, vertex elimination,
691 * pressure solve, vertex velocity recovery and postprocessing. Apart from the
692 * MFMFE-specific data structures, the rest of the members should look familiar.
693 *
694 * @code
695 *   template <int dim>
696 *   class MultipointMixedDarcyProblem
697 *   {
698 *   public:
699 *   MultipointMixedDarcyProblem (const unsigned int degree);
700 *   ~MultipointMixedDarcyProblem ();
701 *   void run (const unsigned int refine);
702 *   private:
703 *   void assemble_system_cell (const typename DoFHandler<dim>::active_cell_iterator &cell,
704 *   DataStructures::NodeAssemblyScratchData<dim> &scratch_data,
705 *   DataStructures::NodeAssemblyCopyData<dim> &copy_data);
706 *   void copy_cell_to_node(const DataStructures::NodeAssemblyCopyData<dim> &copy_data);
707 *   void node_assembly();
708 *   void make_cell_centered_sp ();
709 *   void nodal_elimination(const typename DataStructures::PointToMatrixMap<dim>::iterator &n_it,
710 *   DataStructures::VertexEliminationScratchData &scratch_data,
711 *   DataStructures::NodeEliminationCopyData<dim> &copy_data);
712 *   void copy_node_to_system(const DataStructures::NodeEliminationCopyData<dim> &copy_data);
713 *   void pressure_assembly ();
714 *   void solve_pressure ();
715 *   void velocity_assembly (const typename DataStructures::PointToMatrixMap<dim>::iterator &n_it,
716 *   DataStructures::VertexEliminationScratchData &scratch_data,
717 *   DataStructures::NodeEliminationCopyData<dim> &copy_data);
718 *   void copy_node_velocity_to_global(const DataStructures::NodeEliminationCopyData<dim> &copy_data);
719 *   void velocity_recovery ();
720 *   void reset_data_structures ();
721 *   void compute_errors (const unsigned int cycle);
722 *   void output_results (const unsigned int cycle, const unsigned int refine);
723 *  
724 *   const unsigned int degree;
726 *   FESystem<dim> fe;
727 *   DoFHandler<dim> dof_handler;
728 *   BlockVector<double> solution;
729 *  
730 *   SparsityPattern cell_centered_sp;
731 *   SparseMatrix<double> pres_system_matrix;
732 *   Vector<double> pres_rhs;
733 *  
734 *   std::unordered_map<Point<dim>, FullMatrix<double>, DataStructures::hash_points<dim>> pressure_matrix;
735 *   std::unordered_map<Point<dim>, FullMatrix<double>, DataStructures::hash_points<dim>> A_inverse;
736 *   std::unordered_map<Point<dim>, Vector<double>, DataStructures::hash_points<dim>> velocity_rhs;
737 *  
738 *   DataStructures::PointToMatrixMap<dim> node_matrix;
739 *   DataStructures::PointToVectorMap<dim> node_rhs;
740 *  
741 *   DataStructures::PointToIndexMap<dim> pressure_indices;
742 *   DataStructures::PointToIndexMap<dim> velocity_indices;
743 *  
744 *   unsigned long n_v, n_p;
745 *  
746 *   Vector<double> pres_solution;
747 *   Vector<double> vel_solution;
748 *  
749 *   ConvergenceTable convergence_table;
750 *   TimerOutput computing_timer;
751 *   };
752 *  
753 * @endcode
754 *
755 *
756 * <a name="mfmfe.cc-Constructoranddestructorcodereset_data_structurescode"></a>
757 * <h4>Constructor and destructor, <code>reset_data_structures</code></h4>
758 *
759
760 *
761 * In the constructor of this class, we store the value that was
762 * passed in concerning the degree of the finite elements we shall use (a
763 * degree of one would mean the use of @ref FE_RT_Bubbles(1) and @ref FE_DGQ(0)),
764 * and then construct the vector valued element belonging to the space @f$V_h^k@f$ described
765 * in the introduction. The constructor also takes care of initializing the
766 * computing timer, as it is of interest for us how well our method performs.
767 *
768 * @code
769 *   template <int dim>
770 *   MultipointMixedDarcyProblem<dim>::MultipointMixedDarcyProblem (const unsigned int degree)
771 *   :
772 *   degree(degree),
773 *   fe(FE_RT_Bubbles<dim>(degree), 1,
774 *   FE_DGQ<dim>(degree-1), 1),
775 *   dof_handler(triangulation),
776 *   computing_timer(std::cout, TimerOutput::summary,
778 *   {}
779 *  
780 *  
781 * @endcode
782 *
783 * The destructor clears the <code>dof_handler</code> and
784 * all of the data structures we used for the method.
785 *
786 * @code
787 *   template <int dim>
788 *   MultipointMixedDarcyProblem<dim>::~MultipointMixedDarcyProblem()
789 *   {
790 *   reset_data_structures ();
791 *   dof_handler.clear();
792 *   }
793 *  
794 *  
795 * @endcode
796 *
797 * This method clears all the data that was used after one refinement
798 * cycle.
799 *
800 * @code
801 *   template <int dim>
802 *   void MultipointMixedDarcyProblem<dim>::reset_data_structures ()
803 *   {
804 *   pressure_indices.clear();
805 *   velocity_indices.clear();
806 *   velocity_rhs.clear();
807 *   A_inverse.clear();
808 *   pressure_matrix.clear();
809 *   node_matrix.clear();
810 *   node_rhs.clear();
811 *   }
812 *  
813 *  
814 * @endcode
815 *
816 *
817 * <a name="mfmfe.cc-Cellwiseassemblyandcreationofthelocalnodalbaseddatastructures"></a>
818 * <h4>Cell-wise assembly and creation of the local, nodal-based data structures</h4>
819 *
820
821 *
822 * First, the function that copies local cell contributions to the corresponding nodal
823 * matrices and vectors is defined. It places the values obtained from local cell integration
824 * into the correct place in a matrix/vector corresponding to a specific node.
825 *
826 * @code
827 *   template <int dim>
828 *   void MultipointMixedDarcyProblem<dim>::copy_cell_to_node(const DataStructures::NodeAssemblyCopyData<dim> &copy_data)
829 *   {
830 *   for (auto m : copy_data.cell_mat)
831 *   {
832 *   for (auto p : m.second)
833 *   node_matrix[m.first][p.first] += p.second;
834 *  
835 *   for (auto p : copy_data.cell_vec.at(m.first))
836 *   node_rhs[m.first][p.first] += p.second;
837 *  
838 *   for (auto p : copy_data.local_pres_indices.at(m.first))
839 *   pressure_indices[m.first].insert(p);
840 *  
841 *   for (auto p : copy_data.local_vel_indices.at(m.first))
842 *   velocity_indices[m.first].insert(p);
843 *   }
844 *   }
845 *  
846 *  
847 *  
848 * @endcode
849 *
850 * Second, the function that does the cell assembly is defined. While it is
851 * similar to the tutorial programs in a way it uses scrath and copy data
852 * structures, the need to localize the DOFs leads to several differences.
853 *
854 * @code
855 *   template <int dim>
856 *   void MultipointMixedDarcyProblem<dim>::
857 *   assemble_system_cell (const typename DoFHandler<dim>::active_cell_iterator &cell,
858 *   DataStructures::NodeAssemblyScratchData<dim> &scratch_data,
859 *   DataStructures::NodeAssemblyCopyData<dim> &copy_data)
860 *   {
861 *   copy_data.cell_mat.clear();
862 *   copy_data.cell_vec.clear();
863 *   copy_data.local_vel_indices.clear();
864 *   copy_data.local_pres_indices.clear();
865 *  
866 *   const unsigned int dofs_per_cell = fe.dofs_per_cell;
867 *   const unsigned int n_q_points = scratch_data.fe_values.get_quadrature().size();
868 *   const unsigned int n_face_q_points = scratch_data.fe_face_values.get_quadrature().size();
869 *  
870 *   copy_data.local_dof_indices.resize(dofs_per_cell);
871 *   cell->get_dof_indices (copy_data.local_dof_indices);
872 *  
873 *   scratch_data.fe_values.reinit (cell);
874 *  
875 *   const KInverse<dim> k_inverse;
876 *   const RightHandSide<dim> rhs;
877 *   const PressureBoundaryValues<dim> pressure_bc;
878 *  
879 *   k_inverse.value_list (scratch_data.fe_values.get_quadrature_points(), scratch_data.k_inverse_values);
880 *   rhs.value_list(scratch_data.fe_values.get_quadrature_points(), scratch_data.rhs_values);
881 *  
882 *   const FEValuesExtractors::Vector velocity (0);
883 *   const FEValuesExtractors::Scalar pressure (dim);
884 *  
885 *   const unsigned int n_vel = dim*Utilities::pow(degree+1,dim);
886 *   std::unordered_map<unsigned int, std::unordered_map<unsigned int, double>> div_map;
887 *  
888 * @endcode
889 *
890 * One, we need to be able to assemble the communication between velocity and
891 * pressure variables and put it on the right place in our final, local version
892 * of the B matrix. This is a little messy, as such communication is not in fact
893 * local, so we do it in two steps. First, we compute all relevant LHS and RHS
894 *
895 * @code
896 *   for (unsigned int q=0; q<n_q_points; ++q)
897 *   {
898 *   const Point<dim> p = scratch_data.fe_values.quadrature_point(q);
899 *  
900 *   for (unsigned int k=0; k<dofs_per_cell; ++k)
901 *   {
902 *   scratch_data.phi_u[k] = scratch_data.fe_values[velocity].value(k, q);
903 *   scratch_data.div_phi_u[k] = scratch_data.fe_values[velocity].divergence (k, q);
904 *   scratch_data.phi_p[k] = scratch_data.fe_values[pressure].value (k, q);
905 *   }
906 *  
907 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
908 *   {
909 *   for (unsigned int j=n_vel; j<dofs_per_cell; ++j)
910 *   {
911 *   double div_term = (- scratch_data.div_phi_u[i] * scratch_data.phi_p[j]
912 *   - scratch_data.phi_p[i] * scratch_data.div_phi_u[j]) * scratch_data.fe_values.JxW(q);
913 *  
914 *   if (std::abs(div_term) > 1.e-12)
915 *   div_map[i][j] += div_term;
916 *   }
917 *  
918 *   double source_term = -scratch_data.phi_p[i] * scratch_data.rhs_values[q] * scratch_data.fe_values.JxW(q);
919 *  
920 *   if (std::abs(scratch_data.phi_p[i]) > 1.e-12 || std::abs(source_term) > 1.e-12)
921 *   copy_data.cell_vec[p][copy_data.local_dof_indices[i]] += source_term;
922 *   }
923 *   }
924 *  
925 * @endcode
926 *
927 * Then, by making another pass, we compute the mass matrix terms and incorporate the
928 * divergence form and RHS accordingly. This second pass, allows us to know where
929 * the total contribution will be put in the nodal data structures, as with this
930 * choice of quadrature rule and finite element only the basis functions corresponding
931 * to the same quadrature points yield non-zero contribution.
932 *
933 * @code
934 *   for (unsigned int q=0; q<n_q_points; ++q)
935 *   {
936 *   std::set<types::global_dof_index> vel_indices;
937 *   const Point<dim> p = scratch_data.fe_values.quadrature_point(q);
938 *  
939 *   for (unsigned int k=0; k<dofs_per_cell; ++k)
940 *   {
941 *   scratch_data.phi_u[k] = scratch_data.fe_values[velocity].value(k, q);
942 *   scratch_data.div_phi_u[k] = scratch_data.fe_values[velocity].divergence (k, q);
943 *   scratch_data.phi_p[k] = scratch_data.fe_values[pressure].value (k, q);
944 *   }
945 *  
946 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
947 *   for (unsigned int j=i; j<dofs_per_cell; ++j)
948 *   {
949 *   double mass_term = scratch_data.phi_u[i]
950 *   * scratch_data.k_inverse_values[q]
951 *   * scratch_data.phi_u[j]
952 *   * scratch_data.fe_values.JxW(q);
953 *  
954 *   if (std::abs(mass_term) > 1.e-12)
955 *   {
956 *   copy_data.cell_mat[p][std::make_pair(copy_data.local_dof_indices[i], copy_data.local_dof_indices[j])] +=
957 *   mass_term;
958 *   vel_indices.insert(i);
959 *   copy_data.local_vel_indices[p].insert(copy_data.local_dof_indices[j]);
960 *   }
961 *   }
962 *  
963 *   for (auto i : vel_indices)
964 *   for (auto el : div_map[i])
965 *   if (std::abs(el.second) > 1.e-12)
966 *   {
967 *   copy_data.cell_mat[p][std::make_pair(copy_data.local_dof_indices[i],
968 *   copy_data.local_dof_indices[el.first])] += el.second;
969 *   copy_data.local_pres_indices[p].insert(copy_data.local_dof_indices[el.first]);
970 *   }
971 *   }
972 *  
973 * @endcode
974 *
975 * The pressure boundary conditions are computed as in @ref step_20 "step-20",
976 *
977 * @code
978 *   std::map<types::global_dof_index,double> pres_bc;
979 *   for (unsigned int face_no=0;
980 *   face_no<GeometryInfo<dim>::faces_per_cell;
981 *   ++face_no)
982 *   if (cell->at_boundary(face_no))
983 *   {
984 *   scratch_data.fe_face_values.reinit (cell, face_no);
985 *   pressure_bc.value_list(scratch_data.fe_face_values.get_quadrature_points(), scratch_data.pres_bc_values);
986 *  
987 *   for (unsigned int q=0; q<n_face_q_points; ++q)
988 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
989 *   {
990 *   double tmp = -(scratch_data.fe_face_values[velocity].value(i, q) *
991 *   scratch_data.fe_face_values.normal_vector(q) *
992 *   scratch_data.pres_bc_values[q] *
993 *   scratch_data.fe_face_values.JxW(q));
994 *  
995 *   if (std::abs(tmp) > 1.e-12)
996 *   pres_bc[copy_data.local_dof_indices[i]] += tmp;
997 *   }
998 *   }
999 *  
1000 * @endcode
1001 *
1002 * ...but we distribute them to the corresponding nodal data structures
1003 *
1004 * @code
1005 *   for (auto m : copy_data.cell_vec)
1006 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
1007 *   if (std::abs(pres_bc[copy_data.local_dof_indices[i]]) > 1.e-12)
1008 *   copy_data.cell_vec[m.first][copy_data.local_dof_indices[i]] += pres_bc[copy_data.local_dof_indices[i]];
1009 *   }
1010 *  
1011 *  
1012 * @endcode
1013 *
1014 * Finally, <code>node_assembly()</code> takes care of all the
1015 * local computations via WorkStream mechanism. Notice that the choice
1016 * of the quadrature rule here is dictated by the formulation of the
1017 * method. It has to be <code>degree+1</code> points Gauss-Lobatto
1018 * for the volume integrals and <code>degree</code> for the face ones,
1019 * as mentioned in the introduction.
1020 *
1021 * @code
1022 *   template <int dim>
1023 *   void MultipointMixedDarcyProblem<dim>::node_assembly()
1024 *   {
1025 *   TimerOutput::Scope t(computing_timer, "Nodal assembly");
1026 *  
1027 *   dof_handler.distribute_dofs(fe);
1028 *   DoFRenumbering::component_wise (dof_handler);
1029 *   const std::vector<types::global_dof_index> dofs_per_component
1030 *   = DoFTools::count_dofs_per_fe_component (dof_handler);
1031 *  
1032 *   QGaussLobatto<dim> quad(degree+1);
1033 *   QGauss<dim-1> face_quad(degree);
1034 *  
1035 *   n_v = dofs_per_component[0];
1036 *   n_p = dofs_per_component[dim];
1037 *  
1038 *   pres_rhs.reinit(n_p);
1039 *  
1040 *   WorkStream::run(dof_handler.begin_active(),
1041 *   dof_handler.end(),
1042 *   *this,
1043 *   &MultipointMixedDarcyProblem::assemble_system_cell,
1044 *   &MultipointMixedDarcyProblem::copy_cell_to_node,
1045 *   DataStructures::NodeAssemblyScratchData<dim>(fe, triangulation,quad,face_quad),
1046 *   DataStructures::NodeAssemblyCopyData<dim>());
1047 *   }
1048 *  
1049 * @endcode
1050 *
1051 *
1052 * <a name="mfmfe.cc-Makingthesparsitypattern"></a>
1053 * <h4>Making the sparsity pattern</h4>
1054 *
1055
1056 *
1057 * Having computed all the local contributions, we actually have
1058 * all the information needed to make a cell-centered sparsity
1059 * pattern manually. We do this here, because @ref SparseMatrixEZ
1060 * leads to a slower solution.
1061 *
1062 * @code
1063 *   template <int dim>
1064 *   void MultipointMixedDarcyProblem<dim>::make_cell_centered_sp()
1065 *   {
1066 *   TimerOutput::Scope t(computing_timer, "Make sparsity pattern");
1067 *   DynamicSparsityPattern dsp(n_p, n_p);
1068 *  
1069 *   std::set<types::global_dof_index>::iterator pi_it, pj_it;
1070 *   unsigned int i, j;
1071 *   for (auto el : node_matrix)
1072 *   for (pi_it = pressure_indices[el.first].begin(), i = 0;
1073 *   pi_it != pressure_indices[el.first].end();
1074 *   ++pi_it, ++i)
1075 *   for (pj_it = pi_it, j = 0;
1076 *   pj_it != pressure_indices[el.first].end();
1077 *   ++pj_it, ++j)
1078 *   dsp.add(*pi_it - n_v, *pj_it - n_v);
1079 *  
1080 *  
1081 *   dsp.symmetrize();
1082 *   cell_centered_sp.copy_from(dsp);
1083 *   pres_system_matrix.reinit (cell_centered_sp);
1084 *   }
1085 *  
1086 *  
1087 * @endcode
1088 *
1089 *
1090 * <a name="mfmfe.cc-Thelocaleliminationprocedure"></a>
1091 * <h4>The local elimination procedure</h4>
1092 *
1093
1094 *
1095 * This function finally performs the local elimination procedure.
1096 * Mathematically, it follows the same idea as in computing the
1097 * Schur complement (as mentioned in the introduction) but we do
1098 * so locally. Namely, local velocity DOFs are expressed in terms
1099 * of corresponding pressure values, and then used for the local
1100 * pressure systems.
1101 *
1102 * @code
1103 *   template <int dim>
1104 *   void MultipointMixedDarcyProblem<dim>::
1105 *   nodal_elimination(const typename DataStructures::PointToMatrixMap<dim>::iterator &n_it,
1106 *   DataStructures::VertexEliminationScratchData &scratch_data,
1107 *   DataStructures::NodeEliminationCopyData<dim> &copy_data)
1108 *   {
1109 *   unsigned int n_edges = velocity_indices.at((*n_it).first).size();
1110 *   unsigned int n_cells = pressure_indices.at((*n_it).first).size();
1111 *  
1112 *   scratch_data.velocity_matrix.reinit(n_edges,n_edges);
1113 *   copy_data.pressure_matrix.reinit(n_edges,n_cells);
1114 *  
1115 *   copy_data.velocity_rhs.reinit(n_edges);
1116 *   scratch_data.pressure_rhs.reinit(n_cells);
1117 *  
1118 *   {
1119 *   std::set<types::global_dof_index>::iterator vi_it, vj_it, p_it;
1120 *   unsigned int i;
1121 *   for (vi_it = velocity_indices.at((*n_it).first).begin(), i = 0;
1122 *   vi_it != velocity_indices.at((*n_it).first).end();
1123 *   ++vi_it, ++i)
1124 *   {
1125 *   unsigned int j;
1126 *   for (vj_it = velocity_indices.at((*n_it).first).begin(), j = 0;
1127 *   vj_it != velocity_indices.at((*n_it).first).end();
1128 *   ++vj_it, ++j)
1129 *   {
1130 *   scratch_data.velocity_matrix.add(i, j, node_matrix[(*n_it).first][std::make_pair(*vi_it, *vj_it)]);
1131 *   if (j != i)
1132 *   scratch_data.velocity_matrix.add(j, i, node_matrix[(*n_it).first][std::make_pair(*vi_it, *vj_it)]);
1133 *   }
1134 *  
1135 *   for (p_it = pressure_indices.at((*n_it).first).begin(), j = 0;
1136 *   p_it != pressure_indices.at((*n_it).first).end();
1137 *   ++p_it, ++j)
1138 *   copy_data.pressure_matrix.add(i, j, node_matrix[(*n_it).first][std::make_pair(*vi_it, *p_it)]);
1139 *  
1140 *   copy_data.velocity_rhs(i) += node_rhs.at((*n_it).first)[*vi_it];
1141 *   }
1142 *  
1143 *   for (p_it = pressure_indices.at((*n_it).first).begin(), i = 0;
1144 *   p_it != pressure_indices.at((*n_it).first).end();
1145 *   ++p_it, ++i)
1146 *   scratch_data.pressure_rhs(i) += node_rhs.at((*n_it).first)[*p_it];
1147 *   }
1148 *  
1149 *   copy_data.Ainverse.reinit(n_edges,n_edges);
1150 *  
1151 *   scratch_data.tmp_rhs1.reinit(n_edges);
1152 *   scratch_data.tmp_rhs2.reinit(n_edges);
1153 *   scratch_data.tmp_rhs3.reinit(n_cells);
1154 *  
1155 *   copy_data.Ainverse.invert(scratch_data.velocity_matrix);
1156 *   copy_data.node_pres_matrix.reinit(n_cells, n_cells);
1157 *   copy_data.node_pres_rhs = scratch_data.pressure_rhs;
1158 *  
1159 *   copy_data.node_pres_matrix = 0;
1160 *   copy_data.node_pres_matrix.triple_product(copy_data.Ainverse,
1161 *   copy_data.pressure_matrix,
1162 *   copy_data.pressure_matrix, true, false);
1163 *  
1164 *   copy_data.Ainverse.vmult(scratch_data.tmp_rhs1, copy_data.velocity_rhs, false);
1165 *   copy_data.pressure_matrix.Tvmult(scratch_data.tmp_rhs3, scratch_data.tmp_rhs1, false);
1166 *   copy_data.node_pres_rhs *= -1.0;
1167 *   copy_data.node_pres_rhs += scratch_data.tmp_rhs3;
1168 *  
1169 *   copy_data.p = (*n_it).first;
1170 *   }
1171 *  
1172 *  
1173 * @endcode
1174 *
1175 * Each node's pressure system is then distributed to a global pressure
1176 * system, using the indices we computed in the previous stages.
1177 *
1178 * @code
1179 *   template <int dim>
1180 *   void MultipointMixedDarcyProblem<dim>::
1181 *   copy_node_to_system(const DataStructures::NodeEliminationCopyData<dim> &copy_data)
1182 *   {
1183 *   A_inverse[copy_data.p] = copy_data.Ainverse;
1184 *   pressure_matrix[copy_data.p] = copy_data.pressure_matrix;
1185 *   velocity_rhs[copy_data.p] = copy_data.velocity_rhs;
1186 *  
1187 *   {
1188 *   std::set<types::global_dof_index>::iterator pi_it, pj_it;
1189 *   unsigned int i;
1190 *   for (pi_it = pressure_indices[copy_data.p].begin(), i = 0;
1191 *   pi_it != pressure_indices[copy_data.p].end();
1192 *   ++pi_it, ++i)
1193 *   {
1194 *   unsigned int j;
1195 *   for (pj_it = pressure_indices[copy_data.p].begin(), j = 0;
1196 *   pj_it != pressure_indices[copy_data.p].end();
1197 *   ++pj_it, ++j)
1198 *   pres_system_matrix.add(*pi_it - n_v, *pj_it - n_v, copy_data.node_pres_matrix(i, j));
1199 *  
1200 *   pres_rhs(*pi_it - n_v) += copy_data.node_pres_rhs(i);
1201 *   }
1202 *   }
1203 *   }
1204 *  
1205 *  
1206 * @endcode
1207 *
1208 * The @ref WorkStream mechanism is again used for the assembly
1209 * of the global system for the pressure variable, where the
1210 * previous functions are used to perform local computations.
1211 *
1212 * @code
1213 *   template <int dim>
1214 *   void MultipointMixedDarcyProblem<dim>::pressure_assembly()
1215 *   {
1216 *   TimerOutput::Scope t(computing_timer, "Pressure matrix assembly");
1217 *  
1218 *   QGaussLobatto<dim> quad(degree+1);
1219 *   QGauss<dim-1> face_quad(degree);
1220 *  
1221 *   pres_rhs.reinit(n_p);
1222 *  
1223 *   WorkStream::run(node_matrix.begin(),
1224 *   node_matrix.end(),
1225 *   *this,
1226 *   &MultipointMixedDarcyProblem::nodal_elimination,
1227 *   &MultipointMixedDarcyProblem::copy_node_to_system,
1228 *   DataStructures::VertexEliminationScratchData(),
1229 *   DataStructures::NodeEliminationCopyData<dim>());
1230 *   }
1231 *  
1232 *  
1233 *  
1234 * @endcode
1235 *
1236 *
1237 * <a name="mfmfe.cc-Velocitysolutionrecovery"></a>
1238 * <h4>Velocity solution recovery</h4>
1239 *
1240
1241 *
1242 * After solving for the pressure variable, we want to follow
1243 * the above procedure backwards, in order to obtain the
1244 * velocity solution (again, this is similar in nature to the
1245 * Schur complement approach, see @ref step_20 "step-20", but here it is done
1246 * locally at each node). We have almost everything computed and
1247 * stored already, including inverses of local mass matrices,
1248 * so the following is a relatively straightforward implementation.
1249 *
1250 * @code
1251 *   template <int dim>
1252 *   void MultipointMixedDarcyProblem<dim>::
1253 *   velocity_assembly (const typename DataStructures::PointToMatrixMap<dim>::iterator &n_it,
1254 *   DataStructures::VertexEliminationScratchData &scratch_data,
1255 *   DataStructures::NodeEliminationCopyData<dim> &copy_data)
1256 *   {
1257 *   unsigned int n_edges = velocity_indices.at((*n_it).first).size();
1258 *   unsigned int n_cells = pressure_indices.at((*n_it).first).size();
1259 *  
1260 *   scratch_data.tmp_rhs1.reinit(n_edges);
1261 *   scratch_data.tmp_rhs2.reinit(n_edges);
1262 *   scratch_data.tmp_rhs3.reinit(n_cells);
1263 *   scratch_data.local_pressure_solution.reinit(n_cells);
1264 *  
1265 *   copy_data.vertex_vel_solution.reinit(n_edges);
1266 *  
1267 *   std::set<types::global_dof_index>::iterator p_it;
1268 *   unsigned int i;
1269 *  
1270 *   for (p_it = pressure_indices[(*n_it).first].begin(), i = 0;
1271 *   p_it != pressure_indices[(*n_it).first].end();
1272 *   ++p_it, ++i)
1273 *   scratch_data.local_pressure_solution(i) = pres_solution(*p_it - n_v);
1274 *  
1275 *   pressure_matrix[(*n_it).first].vmult(scratch_data.tmp_rhs2, scratch_data.local_pressure_solution, false);
1276 *   scratch_data.tmp_rhs2 *= -1.0;
1277 *   scratch_data.tmp_rhs2+=velocity_rhs[(*n_it).first];
1278 *   A_inverse[(*n_it).first].vmult(copy_data.vertex_vel_solution, scratch_data.tmp_rhs2, false);
1279 *  
1280 *   copy_data.p = (*n_it).first;
1281 *   }
1282 *  
1283 *  
1284 * @endcode
1285 *
1286 * Copy nodal velocities to a global solution vector by using
1287 * local computations and indices from early stages.
1288 *
1289 * @code
1290 *   template <int dim>
1291 *   void MultipointMixedDarcyProblem<dim>::
1292 *   copy_node_velocity_to_global(const DataStructures::NodeEliminationCopyData<dim> &copy_data)
1293 *   {
1294 *   std::set<types::global_dof_index>::iterator vi_it;
1295 *   unsigned int i;
1296 *  
1297 *   for (vi_it = velocity_indices[copy_data.p].begin(), i = 0;
1298 *   vi_it != velocity_indices[copy_data.p].end();
1299 *   ++vi_it, ++i)
1300 *   vel_solution(*vi_it) += copy_data.vertex_vel_solution(i);
1301 *   }
1302 *  
1303 *  
1304 * @endcode
1305 *
1306 * Use @ref WorkStream to run everything concurrently.
1307 *
1308 * @code
1309 *   template <int dim>
1310 *   void MultipointMixedDarcyProblem<dim>::velocity_recovery()
1311 *   {
1312 *   TimerOutput::Scope t(computing_timer, "Velocity solution recovery");
1313 *  
1314 *   QGaussLobatto<dim> quad(degree+1);
1315 *   QGauss<dim-1> face_quad(degree);
1316 *  
1317 *   vel_solution.reinit(n_v);
1318 *  
1319 *   WorkStream::run(node_matrix.begin(),
1320 *   node_matrix.end(),
1321 *   *this,
1322 *   &MultipointMixedDarcyProblem::velocity_assembly,
1323 *   &MultipointMixedDarcyProblem::copy_node_velocity_to_global,
1324 *   DataStructures::VertexEliminationScratchData(),
1325 *   DataStructures::NodeEliminationCopyData<dim>());
1326 *  
1327 *   solution.reinit(2);
1328 *   solution.block(0) = vel_solution;
1329 *   solution.block(1) = pres_solution;
1330 *   solution.collect_sizes();
1331 *   }
1332 *  
1333 *  
1334 *  
1335 * @endcode
1336 *
1337 *
1338 * <a name="mfmfe.cc-Pressuresystemsolver"></a>
1339 * <h4>Pressure system solver</h4>
1340 *
1341
1342 *
1343 * The solver part is trivial. We use the CG solver with no
1344 * preconditioner for simplicity.
1345 *
1346 * @code
1347 *   template <int dim>
1348 *   void MultipointMixedDarcyProblem<dim>::solve_pressure()
1349 *   {
1350 *   TimerOutput::Scope t(computing_timer, "Pressure CG solve");
1351 *  
1352 *   pres_solution.reinit(n_p);
1353 *  
1354 *   SolverControl solver_control (static_cast<int>(2.0*n_p), 1e-10);
1355 *   SolverCG<> solver (solver_control);
1356 *  
1357 *   PreconditionIdentity identity;
1358 *   solver.solve(pres_system_matrix, pres_solution, pres_rhs, identity);
1359 *   }
1360 *  
1361 *  
1362 *  
1363 * @endcode
1364 *
1365 *
1366 * <a name="mfmfe.cc-Postprocessing"></a>
1367 * <h3>Postprocessing</h3>
1368 *
1369
1370 *
1371 * We have two postprocessing steps here, first one computes the
1372 * errors in order to populate the convergence tables. The other
1373 * one takes care of the output of the solutions in <code>.vtk</code>
1374 * format.
1375 *
1376
1377 *
1378 *
1379 * <a name="mfmfe.cc-Computeerrors"></a>
1380 * <h4>Compute errors</h4>
1381 *
1382
1383 *
1384 * The implementation of this function is almost identical to @ref step_20 "step-20".
1385 * We use @ref ComponentSelectFunction as masks to use the right
1386 * solution component (velocity or pressure) and @ref integrate_difference
1387 * to compute the errors. Since we also want to compute Hdiv seminorm of the
1388 * velocity error, one must provide gradients in the <code>ExactSolution</code>
1389 * class implementation to avoid exceptions. The only noteworthy thing here
1390 * is that we again use lower order quadrature rule instead of projecting the
1391 * solution to an appropriate space in order to show superconvergence, which is
1392 * mathematically justified.
1393 *
1394 * @code
1395 *   template <int dim>
1396 *   void MultipointMixedDarcyProblem<dim>::compute_errors(const unsigned cycle)
1397 *   {
1398 *   TimerOutput::Scope t(computing_timer, "Compute errors");
1399 *  
1400 *   const ComponentSelectFunction<dim> pressure_mask(dim, dim+1);
1401 *   const ComponentSelectFunction<dim> velocity_mask(std::make_pair(0, dim), dim+1);
1402 *  
1403 *   ExactSolution<dim> exact_solution;
1404 *  
1405 *   Vector<double> cellwise_errors (triangulation.n_active_cells());
1406 *  
1407 *   QTrapezoid<1> q_trapez;
1408 *   QIterated<dim> quadrature(q_trapez,degree+2);
1409 *   QGauss<dim> quadrature_super(degree);
1410 *  
1411 *   VectorTools::integrate_difference (dof_handler, solution, exact_solution,
1412 *   cellwise_errors, quadrature,
1413 *   VectorTools::L2_norm,
1414 *   &pressure_mask);
1415 *   const double p_l2_error = cellwise_errors.l2_norm();
1416 *  
1417 *   VectorTools::integrate_difference (dof_handler, solution, exact_solution,
1418 *   cellwise_errors, quadrature_super,
1419 *   VectorTools::L2_norm,
1420 *   &pressure_mask);
1421 *   const double p_l2_mid_error = cellwise_errors.l2_norm();
1422 *  
1423 *   VectorTools::integrate_difference (dof_handler, solution, exact_solution,
1424 *   cellwise_errors, quadrature,
1425 *   VectorTools::L2_norm,
1426 *   &velocity_mask);
1427 *   const double u_l2_error = cellwise_errors.l2_norm();
1428 *  
1429 *   VectorTools::integrate_difference (dof_handler, solution, exact_solution,
1430 *   cellwise_errors, quadrature,
1431 *   VectorTools::Hdiv_seminorm,
1432 *   &velocity_mask);
1433 *   const double u_hd_error = cellwise_errors.l2_norm();
1434 *  
1435 *   const unsigned int n_active_cells=triangulation.n_active_cells();
1436 *   const unsigned int n_dofs=dof_handler.n_dofs();
1437 *  
1438 *   convergence_table.add_value("cycle", cycle);
1439 *   convergence_table.add_value("cells", n_active_cells);
1440 *   convergence_table.add_value("dofs", n_dofs);
1441 *   convergence_table.add_value("Velocity,L2", u_l2_error);
1442 *   convergence_table.add_value("Velocity,Hdiv", u_hd_error);
1443 *   convergence_table.add_value("Pressure,L2", p_l2_error);
1444 *   convergence_table.add_value("Pressure,L2-nodal", p_l2_mid_error);
1445 *   }
1446 *  
1447 *  
1448 *  
1449 * @endcode
1450 *
1451 *
1452 * <a name="mfmfe.cc-Outputresults"></a>
1453 * <h4>Output results</h4>
1454 *
1455
1456 *
1457 * This function also follows the same idea as in @ref step_20 "step-20" tutorial
1458 * program. The only modification to it is the part involving
1459 * a convergence table.
1460 *
1461 * @code
1462 *   template <int dim>
1463 *   void MultipointMixedDarcyProblem<dim>::output_results(const unsigned int cycle, const unsigned int refine)
1464 *   {
1465 *   TimerOutput::Scope t(computing_timer, "Output results");
1466 *  
1467 *   std::vector<std::string> solution_names(dim, "u");
1468 *   solution_names.push_back ("p");
1469 *   std::vector<DataComponentInterpretation::DataComponentInterpretation>
1470 *   interpretation (dim, DataComponentInterpretation::component_is_part_of_vector);
1471 *   interpretation.push_back (DataComponentInterpretation::component_is_scalar);
1472 *  
1473 *   DataOut<dim> data_out;
1474 *   data_out.add_data_vector (dof_handler, solution, solution_names, interpretation);
1475 *   data_out.build_patches ();
1476 *  
1477 *   std::ofstream output ("solution" + std::to_string(dim) + "d-" + std::to_string(cycle) + ".vtk");
1478 *   data_out.write_vtk (output);
1479 *  
1480 *   convergence_table.set_precision("Velocity,L2", 3);
1481 *   convergence_table.set_precision("Velocity,Hdiv", 3);
1482 *   convergence_table.set_precision("Pressure,L2", 3);
1483 *   convergence_table.set_precision("Pressure,L2-nodal", 3);
1484 *   convergence_table.set_scientific("Velocity,L2", true);
1485 *   convergence_table.set_scientific("Velocity,Hdiv", true);
1486 *   convergence_table.set_scientific("Pressure,L2", true);
1487 *   convergence_table.set_scientific("Pressure,L2-nodal", true);
1488 *   convergence_table.set_tex_caption("cells", "\\# cells");
1489 *   convergence_table.set_tex_caption("dofs", "\\# dofs");
1490 *   convergence_table.set_tex_caption("Velocity,L2", " \\|\\u - \\u_h\\|_{L^2} ");
1491 *   convergence_table.set_tex_caption("Velocity,Hdiv", " \\|\\nabla\\cdot(\\u - \\u_h)\\|_{L^2} ");
1492 *   convergence_table.set_tex_caption("Pressure,L2", " \\|p - p_h\\|_{L^2} ");
1493 *   convergence_table.set_tex_caption("Pressure,L2-nodal", " \\|Qp - p_h\\|_{L^2} ");
1494 *   convergence_table.set_tex_format("cells", "r");
1495 *   convergence_table.set_tex_format("dofs", "r");
1496 *  
1497 *   convergence_table.evaluate_convergence_rates("Velocity,L2", ConvergenceTable::reduction_rate_log2);
1498 *   convergence_table.evaluate_convergence_rates("Velocity,Hdiv", ConvergenceTable::reduction_rate_log2);
1499 *   convergence_table.evaluate_convergence_rates("Pressure,L2", ConvergenceTable::reduction_rate_log2);
1500 *   convergence_table.evaluate_convergence_rates("Pressure,L2-nodal", ConvergenceTable::reduction_rate_log2);
1501 *  
1502 *   std::ofstream error_table_file("error" + std::to_string(dim) + "d.tex");
1503 *  
1504 *   if (cycle == refine-1)
1505 *   {
1506 *   convergence_table.write_text(std::cout);
1507 *   convergence_table.write_tex(error_table_file);
1508 *   }
1509 *   }
1510 *  
1511 *  
1512 *  
1513 * @endcode
1514 *
1515 *
1516 * <a name="mfmfe.cc-Runfunction"></a>
1517 * <h3>Run function</h3>
1518 *
1519
1520 *
1521 * The driver method <code>run()</code>
1522 * takes care of mesh generation and arranging calls to member methods in
1523 * the right way. It also resets data structures and clear triangulation and
1524 * DOF handler as we run the method on a sequence of refinements in order
1525 * to record convergence rates.
1526 *
1527 * @code
1528 *   template <int dim>
1529 *   void MultipointMixedDarcyProblem<dim>::run(const unsigned int refine)
1530 *   {
1531 *   Assert(refine > 0, ExcMessage("Must at least have 1 refinement cycle!"));
1532 *  
1533 *   dof_handler.clear();
1534 *   triangulation.clear();
1535 *   convergence_table.clear();
1536 *  
1537 *   for (unsigned int cycle=0; cycle<refine; ++cycle)
1538 *   {
1539 *   if (cycle == 0)
1540 *   {
1541 * @endcode
1542 *
1543 * We first generate the hyper cube and refine it twice
1544 * so that we could distort the grid slightly and
1545 * demonstrate the method's ability to work in such a
1546 * case.
1547 *
1548 * @code
1550 *   triangulation.refine_global(2);
1551 *   GridTools::distort_random (0.3, triangulation, true);
1552 *   }
1553 *   else
1554 *   triangulation.refine_global(1);
1555 *  
1556 *   node_assembly();
1557 *   make_cell_centered_sp();
1558 *   pressure_assembly();
1559 *   solve_pressure ();
1560 *   velocity_recovery ();
1561 *   compute_errors (cycle);
1562 *   output_results (cycle, refine);
1563 *   reset_data_structures ();
1564 *  
1565 *   computing_timer.print_summary ();
1566 *   computing_timer.reset ();
1567 *   }
1568 *   }
1569 *   }
1570 *  
1571 *  
1572 * @endcode
1573 *
1574 *
1575 * <a name="mfmfe.cc-Thecodemaincodefunction"></a>
1576 * <h3>The <code>main</code> function</h3>
1577 *
1578
1579 *
1580 * In the main functione we pass the order of the Finite Element as an argument
1581 * to the constructor of the Multipoint Flux Mixed Darcy problem, and the number
1582 * of refinement cycles as an argument for the run method.
1583 *
1584 * @code
1585 *   int main ()
1586 *   {
1587 *   try
1588 *   {
1589 *   using namespace dealii;
1590 *   using namespace MFMFE;
1591 *  
1593 *  
1594 *   MultipointMixedDarcyProblem<2> mfmfe_problem(2);
1595 *   mfmfe_problem.run(6);
1596 *   }
1597 *   catch (std::exception &exc)
1598 *   {
1599 *   std::cerr << std::endl << std::endl
1600 *   << "----------------------------------------------------"
1601 *   << std::endl;
1602 *   std::cerr << "Exception on processing: " << std::endl
1603 *   << exc.what() << std::endl
1604 *   << "Aborting!" << std::endl
1605 *   << "----------------------------------------------------"
1606 *   << std::endl;
1607 *  
1608 *   return 1;
1609 *   }
1610 *   catch (...)
1611 *   {
1612 *   std::cerr << std::endl << std::endl
1613 *   << "----------------------------------------------------"
1614 *   << std::endl;
1615 *   std::cerr << "Unknown exception!" << std::endl
1616 *   << "Aborting!" << std::endl
1617 *   << "----------------------------------------------------"
1618 *   << std::endl;
1619 *   return 1;
1620 *   }
1621 *  
1622 *   return 0;
1623 *   }
1624 * @endcode
1625
1626
1627*/
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType > > &gradients) const
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
static void set_thread_limit(const unsigned int max_threads=numbers::invalid_unsigned_int)
Definition point.h:111
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< value_type > &values) const
@ wall_times
Definition timer.h:651
Point< 2 > second
Definition grid_out.cc:4624
Point< 2 > first
Definition grid_out.cc:4623
#define Assert(cond, exc)
typename ActiveSelector::active_cell_iterator active_cell_iterator
@ update_values
Shape function values.
@ update_normal_vectors
Normal vectors.
@ update_JxW_values
Transformed quadrature weights.
@ update_gradients
Shape function gradients.
@ update_quadrature_points
Transformed quadrature points.
std::vector< index_type > data
Definition mpi.cc:735
void component_wise(DoFHandler< dim, spacedim > &dof_handler, const std::vector< unsigned int > &target_component=std::vector< unsigned int >())
std::vector< types::global_dof_index > count_dofs_per_fe_component(const DoFHandler< dim, spacedim > &dof_handler, const bool vector_valued_once=false, const std::vector< unsigned int > &target_component={})
void hyper_cube(Triangulation< dim, spacedim > &tria, const double left=0., const double right=1., const bool colorize=false)
double volume(const Triangulation< dim, spacedim > &tria)
void distort_random(const double factor, Triangulation< dim, spacedim > &triangulation, const bool keep_boundary=true, const unsigned int seed=boost::random::mt19937::default_seed)
@ matrix
Contents is actually a matrix.
SymmetricTensor< 2, dim, Number > C(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
VectorType::value_type * begin(VectorType &V)
constexpr T pow(const T base, const int iexp)
Definition utilities.h:966
void run(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length, const unsigned int chunk_size)
void run(const std::vector< std::vector< Iterator > > &colored_iterators, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length=2 *MultithreadInfo::n_threads(), const unsigned int chunk_size=8)
unsigned int n_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
Definition tria.cc:14871
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:70
STL namespace.
::VectorizedArray< Number, width > cos(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sin(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation