deal.II version 9.7.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
two_phase_flow.h
Go to the documentation of this file.
1
245 *  
246 *   #include <deal.II/base/quadrature_lib.h>
247 *   #include <deal.II/base/function.h>
248 *   #include <deal.II/lac/affine_constraints.h>
249 *   #include <deal.II/lac/vector.h>
250 *   #include <deal.II/lac/full_matrix.h>
251 *   #include <deal.II/lac/solver_cg.h>
252 *   #include <deal.II/lac/petsc_sparse_matrix.h>
253 *   #include <deal.II/lac/petsc_sparse_matrix.h>
254 *   #include <deal.II/lac/petsc_vector.h>
255 *   #include <deal.II/lac/petsc_solver.h>
256 *   #include <deal.II/lac/petsc_precondition.h>
257 *   #include <deal.II/grid/grid_generator.h>
258 *   #include <deal.II/grid/tria_accessor.h>
259 *   #include <deal.II/grid/tria_iterator.h>
260 *   #include <deal.II/dofs/dof_handler.h>
261 *   #include <deal.II/dofs/dof_accessor.h>
262 *   #include <deal.II/dofs/dof_tools.h>
263 *   #include <deal.II/fe/fe_values.h>
264 *   #include <deal.II/fe/fe_q.h>
265 *   #include <deal.II/numerics/vector_tools.h>
266 *   #include <deal.II/numerics/data_out.h>
267 *   #include <deal.II/numerics/error_estimator.h>
268 *   #include <deal.II/base/utilities.h>
269 *   #include <deal.II/base/conditional_ostream.h>
270 *   #include <deal.II/base/index_set.h>
271 *   #include <deal.II/lac/sparsity_tools.h>
272 *   #include <deal.II/distributed/tria.h>
273 *   #include <deal.II/distributed/grid_refinement.h>
274 *   #include <deal.II/lac/vector.h>
275 *   #include <deal.II/base/convergence_table.h>
276 *   #include <deal.II/base/timer.h>
277 *   #include <deal.II/base/parameter_handler.h>
278 *   #include <deal.II/grid/grid_tools.h>
279 *   #include <deal.II/fe/mapping_q.h>
280 *  
281 *   #include <mpi.h>
282 *  
283 *   #include <fstream>
284 *   #include <iostream>
285 *   #include <memory>
286 *  
287 *   using namespace dealii;
288 *  
289 * @endcode
290 *
291 * FLAGS
292 *
293 * @code
294 *   #define NUM_ITER 1
295 *   #define CHECK_MAX_PRINCIPLE 0
296 *  
297 * @endcode
298 *
299 * LOG FOR LEVEL SET FROM -1 to 1
300 *
301 * @code
302 *   #define ENTROPY(phi) std::log(std::abs(1-phi*phi)+1E-14)
303 *   #define ENTROPY_GRAD(phi,phix) 2*phi*phix*((1-phi*phi>=0) ? -1 : 1)/(std::abs(1-phi*phi)+1E-14)
304 *  
305 * @endcode
306 *
307 *
308 *
309 *
310 * This is a solver for the transpor solver.
311 * We assume the velocity is divergence free
312 * and solve the equation in conservation form.
313 *
314 * ---------- NOTATION ----------
315 *
316 * We use notation popular in the literature of conservation laws.
317 * For this reason the solution is denoted as u, unm1, unp1, etc.
318 * and the velocity is treated as vx, vy and vz.
319 *
320 * @code
321 *   template <int dim>
322 *   class LevelSetSolver
323 *   {
324 *   public:
325 * @endcode
326 *
327 *
328 * INITIAL CONDITIONS
329 *
330 *
331 * @code
332 *   void initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_u,
333 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx,
334 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy);
335 *   void initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_u,
336 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx,
337 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy,
338 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz);
339 * @endcode
340 *
341 *
342 * BOUNDARY CONDITIONS
343 *
344 *
345 * @code
346 *   void set_boundary_conditions(std::vector<types::global_dof_index> &boundary_values_id_u,
347 *   std::vector<double> boundary_values_u);
348 * @endcode
349 *
350 *
351 * SET VELOCITY
352 *
353 *
354 * @code
355 *   void set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_vx,
356 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy);
357 *   void set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_vx,
358 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy,
359 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz);
360 * @endcode
361 *
362 *
363 * SET AND GET ALPHA
364 *
365 *
366 * @code
367 *   void get_unp1(PETScWrappers::MPI::Vector &locally_relevant_solution_u);
368 * @endcode
369 *
370 *
371 * NTH TIME STEP
372 *
373 *
374 * @code
375 *   void nth_time_step();
376 * @endcode
377 *
378 *
379 * SETUP
380 *
381 *
382 * @code
383 *   void setup();
384 *  
385 *   LevelSetSolver (const unsigned int degree_LS,
386 *   const unsigned int degree_U,
387 *   const double time_step,
388 *   const double cK,
389 *   const double cE,
390 *   const bool verbose,
391 *   std::string ALGORITHM,
392 *   const unsigned int TIME_INTEGRATION,
394 *   MPI_Comm &mpi_communicator);
395 *   ~LevelSetSolver();
396 *  
397 *   private:
398 * @endcode
399 *
400 *
401 * ASSEMBLE MASS (and other) MATRICES
402 *
403 *
404 * @code
405 *   void assemble_ML();
406 *   void invert_ML();
407 *   void assemble_MC();
408 * @endcode
409 *
410 *
411 * LOW ORDER METHOD (DiJ Viscosity)
412 *
413 *
414 * @code
415 *   void assemble_C_Matrix();
416 *   void assemble_K_times_vector(PETScWrappers::MPI::Vector &solution);
417 *   void assemble_K_DL_DH_times_vector(PETScWrappers::MPI::Vector &solution);
418 * @endcode
419 *
420 *
421 * ENTROPY VISCOSITY
422 *
423 *
424 * @code
425 *   void assemble_EntRes_Matrix();
426 * @endcode
427 *
428 *
429 * FOR MAXIMUM PRINCIPLE
430 *
431 *
432 * @code
433 *   void compute_bounds(PETScWrappers::MPI::Vector &un_solution);
434 *   void check_max_principle(PETScWrappers::MPI::Vector &unp1_solution);
435 * @endcode
436 *
437 *
438 * COMPUTE SOLUTIONS
439 *
440 *
441 * @code
442 *   void compute_MPP_uL_and_NMPP_uH(PETScWrappers::MPI::Vector &MPP_uL_solution,
443 *   PETScWrappers::MPI::Vector &NMPP_uH_solution,
444 *   PETScWrappers::MPI::Vector &un_solution);
445 *   void compute_MPP_uH(PETScWrappers::MPI::Vector &MPP_uH_solution,
446 *   PETScWrappers::MPI::Vector &MPP_uL_solution_ghosted,
447 *   PETScWrappers::MPI::Vector &NMPP_uH_solution_ghosted,
448 *   PETScWrappers::MPI::Vector &un_solution);
449 *   void compute_MPP_uH_with_iterated_FCT(PETScWrappers::MPI::Vector &MPP_uH_solution,
450 *   PETScWrappers::MPI::Vector &MPP_uL_solution_ghosted,
451 *   PETScWrappers::MPI::Vector &NMPP_uH_solution_ghosted,
452 *   PETScWrappers::MPI::Vector &un_solution);
453 *   void compute_solution(PETScWrappers::MPI::Vector &unp1,
455 *   std::string algorithm);
456 *   void compute_solution_SSP33(PETScWrappers::MPI::Vector &unp1,
458 *   std::string algorithm);
459 * @endcode
460 *
461 *
462 * UTILITIES
463 *
464 *
465 * @code
466 *   void get_sparsity_pattern();
467 *   void get_map_from_Q1_to_Q2();
468 *   void solve(const AffineConstraints<double> &constraints,
470 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner,
471 *   PETScWrappers::MPI::Vector &completely_distributed_solution,
472 *   const PETScWrappers::MPI::Vector &rhs);
473 *   void save_old_solution();
474 *   void save_old_vel_solution();
475 * @endcode
476 *
477 *
478 * MY PETSC WRAPPERS
479 *
480 *
481 * @code
482 *   void get_vector_values(PETScWrappers::VectorBase &vector,
483 *   const std::vector<types::global_dof_index> &indices,
484 *   std::vector<PetscScalar> &values);
485 *   void get_vector_values(PETScWrappers::VectorBase &vector,
486 *   const std::vector<types::global_dof_index> &indices,
487 *   std::map<types::global_dof_index, types::global_dof_index> &map_from_Q1_to_Q2,
488 *   std::vector<PetscScalar> &values);
489 *  
490 *   MPI_Comm mpi_communicator;
491 *  
492 * @endcode
493 *
494 * FINITE ELEMENT SPACE
495 *
496 * @code
497 *   int degree_MAX;
498 *   int degree_LS;
499 *   DoFHandler<dim> dof_handler_LS;
500 *   FE_Q<dim> fe_LS;
501 *   IndexSet locally_owned_dofs_LS;
502 *   IndexSet locally_relevant_dofs_LS;
503 *  
504 *   int degree_U;
505 *   DoFHandler<dim> dof_handler_U;
506 *   FE_Q<dim> fe_U;
507 *   IndexSet locally_owned_dofs_U;
508 *   IndexSet locally_relevant_dofs_U;
509 *  
510 * @endcode
511 *
512 * OPERATORS times SOLUTION VECTOR
513 *
514 * @code
515 *   PETScWrappers::MPI::Vector K_times_solution;
516 *   PETScWrappers::MPI::Vector DL_times_solution;
517 *   PETScWrappers::MPI::Vector DH_times_solution;
518 *  
519 * @endcode
520 *
521 * MASS MATRIX
522 *
523 * @code
525 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> MC_preconditioner;
526 *  
527 * @endcode
528 *
529 * BOUNDARIES
530 *
531 * @code
532 *   std::vector<types::global_dof_index> boundary_values_id_u;
533 *   std::vector<double> boundary_values_u;
534 *  
535 * @endcode
536 *
537 *
538 * MATRICES
539 *
540 * FOR FIRST ORDER VISCOSITY
541 *
542 * @code
543 *   PETScWrappers::MPI::SparseMatrix Cx_matrix, CTx_matrix, Cy_matrix, CTy_matrix, Cz_matrix, CTz_matrix;
544 *   PETScWrappers::MPI::SparseMatrix dLij_matrix;
545 * @endcode
546 *
547 * FOR ENTROPY VISCOSITY
548 *
549 * @code
550 *   PETScWrappers::MPI::SparseMatrix EntRes_matrix, SuppSize_matrix, dCij_matrix;
551 * @endcode
552 *
553 * FOR FCT (flux and limited flux)
554 *
555 * @code
556 *   PETScWrappers::MPI::SparseMatrix A_matrix, LxA_matrix;
557 * @endcode
558 *
559 * FOR ITERATIVE FCT
560 *
561 * @code
562 *   PETScWrappers::MPI::SparseMatrix Akp1_matrix, LxAkp1_matrix;
563 *  
564 * @endcode
565 *
566 * GHOSTED VECTORS
567 *
568 * @code
569 *   PETScWrappers::MPI::Vector uStage1, uStage2;
570 *   PETScWrappers::MPI::Vector unm1, un;
571 *   PETScWrappers::MPI::Vector R_pos_vector, R_neg_vector;
572 *   PETScWrappers::MPI::Vector MPP_uL_solution_ghosted, MPP_uLkp1_solution_ghosted, NMPP_uH_solution_ghosted;
573 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx;
574 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy;
575 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz;
576 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx_old;
577 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy_old;
578 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz_old;
579 *  
580 * @endcode
581 *
582 * NON-GHOSTED VECTORS
583 *
584 * @code
585 *   PETScWrappers::MPI::Vector uStage1_nonGhosted, uStage2_nonGhosted;
587 *   PETScWrappers::MPI::Vector R_pos_vector_nonGhosted, R_neg_vector_nonGhosted;
588 *   PETScWrappers::MPI::Vector umin_vector, umax_vector;
589 *   PETScWrappers::MPI::Vector MPP_uL_solution, NMPP_uH_solution, MPP_uH_solution;
591 *  
592 * @endcode
593 *
594 * LUMPED MASS MATRIX
595 *
596 * @code
597 *   PETScWrappers::MPI::Vector ML_vector, ones_vector;
598 *   PETScWrappers::MPI::Vector inverse_ML_vector;
599 *  
600 * @endcode
601 *
602 * CONSTRAINTS
603 *
604 * @code
605 *   AffineConstraints<double> constraints;
606 *  
607 * @endcode
608 *
609 * TIME STEPPING
610 *
611 * @code
612 *   double time_step;
613 *  
614 * @endcode
615 *
616 * SOME PARAMETERS
617 *
618 * @code
619 *   double cE, cK;
620 *   double solver_tolerance;
621 *   double entropy_normalization_factor;
622 *  
623 * @endcode
624 *
625 * UTILITIES
626 *
627 * @code
628 *   bool verbose;
629 *   std::string ALGORITHM;
630 *   unsigned int TIME_INTEGRATION;
631 *  
632 *   ConditionalOStream pcout;
633 *  
634 *   std::map<types::global_dof_index, types::global_dof_index> map_from_Q1_to_Q2;
635 *   std::map<types::global_dof_index, std::vector<types::global_dof_index> > sparsity_pattern;
636 *   };
637 *  
638 *   template <int dim>
639 *   LevelSetSolver<dim>::LevelSetSolver (const unsigned int degree_LS,
640 *   const unsigned int degree_U,
641 *   const double time_step,
642 *   const double cK,
643 *   const double cE,
644 *   const bool verbose,
645 *   std::string ALGORITHM,
646 *   const unsigned int TIME_INTEGRATION,
648 *   MPI_Comm &mpi_communicator)
649 *   :
650 *   mpi_communicator (mpi_communicator),
651 *   degree_LS(degree_LS),
652 *   dof_handler_LS (triangulation),
653 *   fe_LS (degree_LS),
654 *   degree_U(degree_U),
655 *   dof_handler_U (triangulation),
656 *   fe_U (degree_U),
657 *   time_step(time_step),
658 *   cE(cE),
659 *   cK(cK),
660 *   verbose(verbose),
661 *   ALGORITHM(ALGORITHM),
662 *   TIME_INTEGRATION(TIME_INTEGRATION),
663 *   pcout (std::cout,(Utilities::MPI::this_mpi_process(mpi_communicator)== 0))
664 *   {
665 *   pcout << "********** LEVEL SET SETUP **********" << std::endl;
666 *   setup();
667 *   }
668 *  
669 *   template <int dim>
670 *   LevelSetSolver<dim>::~LevelSetSolver ()
671 *   {
672 *   dof_handler_LS.clear ();
673 *   dof_handler_U.clear ();
674 *   }
675 *  
676 * @endcode
677 *
678 *
679 *
680 *
681 *
682 *
683 *
684 *
685 * @code
686 *   template<int dim>
687 *   void LevelSetSolver<dim>::initial_condition (PETScWrappers::MPI::Vector un,
688 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx,
689 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy)
690 *   {
691 *   this->un = un;
692 *   this->locally_relevant_solution_vx = locally_relevant_solution_vx;
693 *   this->locally_relevant_solution_vy = locally_relevant_solution_vy;
694 * @endcode
695 *
696 * initialize old vectors with current solution, this just happens the first time
697 *
698 * @code
699 *   unm1 = un;
700 *   locally_relevant_solution_vx_old = locally_relevant_solution_vx;
701 *   locally_relevant_solution_vy_old = locally_relevant_solution_vy;
702 *   }
703 *  
704 *   template<int dim>
705 *   void LevelSetSolver<dim>::initial_condition (PETScWrappers::MPI::Vector un,
706 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx,
707 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy,
708 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz)
709 *   {
710 *   this->un = un;
711 *   this->locally_relevant_solution_vx = locally_relevant_solution_vx;
712 *   this->locally_relevant_solution_vy = locally_relevant_solution_vy;
713 *   this->locally_relevant_solution_vz = locally_relevant_solution_vz;
714 * @endcode
715 *
716 * initialize old vectors with current solution, this just happens the first time
717 *
718 * @code
719 *   unm1 = un;
720 *   locally_relevant_solution_vx_old = locally_relevant_solution_vx;
721 *   locally_relevant_solution_vy_old = locally_relevant_solution_vy;
722 *   locally_relevant_solution_vz_old = locally_relevant_solution_vz;
723 *   }
724 *  
725 * @endcode
726 *
727 *
728 *
729 *
730 *
731 * @code
732 *   template <int dim>
733 *   void LevelSetSolver<dim>::set_boundary_conditions(std::vector<types::global_dof_index> &boundary_values_id_u,
734 *   std::vector<double> boundary_values_u)
735 *   {
736 *   this->boundary_values_id_u = boundary_values_id_u;
737 *   this->boundary_values_u = boundary_values_u;
738 *   }
739 *  
740 * @endcode
741 *
742 *
743 *
744 *
745 *
746 * @code
747 *   template <int dim>
748 *   void LevelSetSolver<dim>::set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_vx,
749 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy)
750 *   {
751 * @endcode
752 *
753 * SAVE OLD SOLUTION
754 *
755 * @code
756 *   save_old_vel_solution();
757 * @endcode
758 *
759 * update velocity
760 *
761 * @code
762 *   this->locally_relevant_solution_vx=locally_relevant_solution_vx;
763 *   this->locally_relevant_solution_vy=locally_relevant_solution_vy;
764 *   }
765 *  
766 *   template <int dim>
767 *   void LevelSetSolver<dim>::set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_vx,
768 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy,
769 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz)
770 *   {
771 * @endcode
772 *
773 * SAVE OLD SOLUTION
774 *
775 * @code
776 *   save_old_vel_solution();
777 * @endcode
778 *
779 * update velocity
780 *
781 * @code
782 *   this->locally_relevant_solution_vx=locally_relevant_solution_vx;
783 *   this->locally_relevant_solution_vy=locally_relevant_solution_vy;
784 *   this->locally_relevant_solution_vz=locally_relevant_solution_vz;
785 *   }
786 *  
787 * @endcode
788 *
789 *
790 *
791 *
792 *
793 * @code
794 *   template<int dim>
795 *   void LevelSetSolver<dim>::get_unp1(PETScWrappers::MPI::Vector &unp1) {unp1=this->unp1;}
796 *  
797 * @endcode
798 *
799 * -------------------------------------------------------------------------------
800 * ------------------------------ COMPUTE SOLUTIONS ------------------------------
801 * -------------------------------------------------------------------------------
802 *
803 * @code
804 *   template <int dim>
805 *   void LevelSetSolver<dim>::nth_time_step()
806 *   {
807 *   assemble_EntRes_Matrix();
808 * @endcode
809 *
810 * COMPUTE SOLUTION
811 *
812 * @code
813 *   if (TIME_INTEGRATION==FORWARD_EULER)
814 *   compute_solution(unp1,un,ALGORITHM);
815 *   else
816 *   compute_solution_SSP33(unp1,un,ALGORITHM);
817 * @endcode
818 *
819 * BOUNDARY CONDITIONS
820 *
821 * @code
822 *   unp1.set(boundary_values_id_u,boundary_values_u);
823 *   unp1.compress(VectorOperation::insert);
824 * @endcode
825 *
826 * CHECK MAXIMUM PRINCIPLE
827 *
828 * @code
829 *   if (CHECK_MAX_PRINCIPLE)
830 *   {
831 *   compute_bounds(un);
832 *   check_max_principle(unp1);
833 *   }
834 * @endcode
835 *
836 * pcout << "*********************************************************************... "
837 * << unp1.min() << ", " << unp1.max() << std::endl;
838 *
839 * @code
840 *   save_old_solution();
841 *   }
842 *  
843 * @endcode
844 *
845 * --------------------------------------------------------------------
846 * ------------------------------ SETUP ------------------------------
847 * --------------------------------------------------------------------
848 *
849 * @code
850 *   template <int dim>
851 *   void LevelSetSolver<dim>::setup()
852 *   {
853 *   solver_tolerance=1E-6;
854 *   degree_MAX = std::max(degree_LS,degree_U);
855 * @endcode
856 *
857 *
858 * SETUP FOR DOF HANDLERS
859 *
860 * setup system LS
861 *
862 * @code
863 *   dof_handler_LS.distribute_dofs (fe_LS);
864 *   locally_owned_dofs_LS = dof_handler_LS.locally_owned_dofs ();
865 *   locally_relevant_dofs_LS = DoFTools::extract_locally_relevant_dofs (dof_handler_LS);
866 * @endcode
867 *
868 * setup system U
869 *
870 * @code
871 *   dof_handler_U.distribute_dofs (fe_U);
872 *   locally_owned_dofs_U = dof_handler_U.locally_owned_dofs ();
873 *   locally_relevant_dofs_U = DoFTools::extract_locally_relevant_dofs (dof_handler_U);
874 * @endcode
875 *
876 *
877 * INIT CONSTRAINTS
878 *
879 *
880 * @code
881 *   constraints.clear ();
882 *   #if DEAL_II_VERSION_GTE(9, 6, 0)
883 *   constraints.reinit (locally_owned_dofs_LS, locally_relevant_dofs_LS);
884 *   #else
885 *   constraints.reinit (locally_relevant_dofs_LS);
886 *   #endif
887 *   DoFTools::make_hanging_node_constraints (dof_handler_LS, constraints);
888 *   constraints.close ();
889 * @endcode
890 *
891 *
892 * NON-GHOSTED VECTORS
893 *
894 *
895 * @code
896 *   MPP_uL_solution.reinit(locally_owned_dofs_LS,mpi_communicator);
897 *   NMPP_uH_solution.reinit(locally_owned_dofs_LS,mpi_communicator);
898 *   RHS.reinit(locally_owned_dofs_LS,mpi_communicator);
899 *   uStage1_nonGhosted.reinit (locally_owned_dofs_LS,mpi_communicator);
900 *   uStage2_nonGhosted.reinit (locally_owned_dofs_LS,mpi_communicator);
901 *   unp1.reinit (locally_owned_dofs_LS,mpi_communicator);
902 *   MPP_uH_solution.reinit (locally_owned_dofs_LS,mpi_communicator);
903 * @endcode
904 *
905 * vectors for lumped mass matrix
906 *
907 * @code
908 *   ML_vector.reinit(locally_owned_dofs_LS,mpi_communicator);
909 *   inverse_ML_vector.reinit(locally_owned_dofs_LS,mpi_communicator);
910 *   ones_vector.reinit(locally_owned_dofs_LS,mpi_communicator);
911 *   ones_vector = 1.;
912 * @endcode
913 *
914 * operators times solution
915 *
916 * @code
917 *   K_times_solution.reinit(locally_owned_dofs_LS,mpi_communicator);
918 *   DL_times_solution.reinit(locally_owned_dofs_LS,mpi_communicator);
919 *   DH_times_solution.reinit(locally_owned_dofs_LS,mpi_communicator);
920 * @endcode
921 *
922 * LIMITERS (FCT)
923 *
924 * @code
925 *   R_pos_vector_nonGhosted.reinit (locally_owned_dofs_LS,mpi_communicator);
926 *   R_neg_vector_nonGhosted.reinit (locally_owned_dofs_LS,mpi_communicator);
927 *   umin_vector.reinit (locally_owned_dofs_LS,mpi_communicator);
928 *   umax_vector.reinit (locally_owned_dofs_LS,mpi_communicator);
929 * @endcode
930 *
931 *
932 * GHOSTED VECTORS (used within some assemble process)
933 *
934 *
935 * @code
936 *   uStage1.reinit (locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
937 *   uStage2.reinit (locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
938 *   unm1.reinit (locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
939 *   un.reinit (locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
940 *   MPP_uL_solution_ghosted.reinit (locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
941 *   MPP_uLkp1_solution_ghosted.reinit (locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
942 *   NMPP_uH_solution_ghosted.reinit (locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
943 * @endcode
944 *
945 * init vectors for vx
946 *
947 * @code
948 *   locally_relevant_solution_vx.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
949 *   locally_relevant_solution_vx_old.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
950 * @endcode
951 *
952 * init vectors for vy
953 *
954 * @code
955 *   locally_relevant_solution_vy.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
956 *   locally_relevant_solution_vy_old.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
957 * @endcode
958 *
959 * init vectors for vz
960 *
961 * @code
962 *   locally_relevant_solution_vz.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
963 *   locally_relevant_solution_vz_old.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
964 * @endcode
965 *
966 * LIMITERS (FCT)
967 *
968 * @code
969 *   R_pos_vector.reinit(locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
970 *   R_neg_vector.reinit(locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
971 * @endcode
972 *
973 *
974 * SETUP MATRICES
975 *
976 * MATRICES
977 *
978 * @code
979 *   DynamicSparsityPattern dsp (locally_relevant_dofs_LS);
980 *   DoFTools::make_sparsity_pattern (dof_handler_LS,dsp,constraints,false);
982 *   dof_handler_LS.locally_owned_dofs(),
983 *   mpi_communicator,
984 *   locally_relevant_dofs_LS);
985 *   MC_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
986 *   dof_handler_LS.locally_owned_dofs(),
987 *   dsp, mpi_communicator);
988 *   Cx_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
989 *   dof_handler_LS.locally_owned_dofs(),
990 *   dsp, mpi_communicator);
991 *   CTx_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
992 *   dof_handler_LS.locally_owned_dofs(),
993 *   dsp, mpi_communicator);
994 *   Cy_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
995 *   dof_handler_LS.locally_owned_dofs(),
996 *   dsp, mpi_communicator);
997 *   CTy_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
998 *   dof_handler_LS.locally_owned_dofs(),
999 *   dsp, mpi_communicator);
1000 *   if (dim==3)
1001 *   {
1002 *   Cz_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
1003 *   dof_handler_LS.locally_owned_dofs(),
1004 *   dsp, mpi_communicator);
1005 *   CTz_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
1006 *   dof_handler_LS.locally_owned_dofs(),
1007 *   dsp, mpi_communicator);
1008 *   }
1009 *   dLij_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
1010 *   dof_handler_LS.locally_owned_dofs(),
1011 *   dsp, mpi_communicator);
1012 *   EntRes_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
1013 *   dof_handler_LS.locally_owned_dofs(),
1014 *   dsp, mpi_communicator);
1015 *   SuppSize_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
1016 *   dof_handler_LS.locally_owned_dofs(),
1017 *   dsp, mpi_communicator);
1018 *   dCij_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
1019 *   dof_handler_LS.locally_owned_dofs(),
1020 *   dsp, mpi_communicator);
1021 *   A_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
1022 *   dof_handler_LS.locally_owned_dofs(),
1023 *   dsp, mpi_communicator);
1024 *   LxA_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
1025 *   dof_handler_LS.locally_owned_dofs(),
1026 *   dsp, mpi_communicator);
1027 *   Akp1_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
1028 *   dof_handler_LS.locally_owned_dofs(),
1029 *   dsp, mpi_communicator);
1030 *   LxAkp1_matrix.reinit (dof_handler_LS.locally_owned_dofs(),
1031 *   dof_handler_LS.locally_owned_dofs(),
1032 *   dsp, mpi_communicator);
1033 * @endcode
1034 *
1035 * COMPUTE MASS MATRICES (AND OTHERS) FOR FIRST TIME STEP
1036 *
1037 * @code
1038 *   assemble_ML();
1039 *   invert_ML();
1040 *   assemble_MC();
1041 *   assemble_C_Matrix();
1042 * @endcode
1043 *
1044 * get mat for DOFs between Q1 and Q2
1045 *
1046 * @code
1047 *   get_map_from_Q1_to_Q2();
1048 *   get_sparsity_pattern();
1049 *   }
1050 *  
1051 * @endcode
1052 *
1053 * ----------------------------------------------------------------------------
1054 * ------------------------------ MASS MATRICES ------------------------------
1055 * ----------------------------------------------------------------------------
1056 *
1057 * @code
1058 *   template<int dim>
1059 *   void LevelSetSolver<dim>::assemble_ML()
1060 *   {
1061 *   ML_vector=0;
1062 *  
1063 *   const QGauss<dim> quadrature_formula(degree_MAX+1);
1064 *   FEValues<dim> fe_values_LS (fe_LS, quadrature_formula,
1067 *   update_JxW_values);
1068 *  
1069 *   const unsigned int dofs_per_cell = fe_LS.dofs_per_cell;
1070 *   const unsigned int n_q_points = quadrature_formula.size();
1071 *  
1072 *   Vector<double> cell_ML (dofs_per_cell);
1073 *   std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1074 *  
1076 *   cell_LS = dof_handler_LS.begin_active(),
1077 *   endc_LS = dof_handler_LS.end();
1078 *  
1079 *   for (; cell_LS!=endc_LS; ++cell_LS)
1080 *   if (cell_LS->is_locally_owned())
1081 *   {
1082 *   cell_ML = 0;
1083 *   fe_values_LS.reinit (cell_LS);
1084 *   for (unsigned int q_point=0; q_point<n_q_points; ++q_point)
1085 *   {
1086 *   const double JxW = fe_values_LS.JxW(q_point);
1087 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
1088 *   cell_ML (i) += fe_values_LS.shape_value(i,q_point)*JxW;
1089 *   }
1090 * @endcode
1091 *
1092 * distribute
1093 *
1094 * @code
1095 *   cell_LS->get_dof_indices (local_dof_indices);
1096 *   constraints.distribute_local_to_global (cell_ML,local_dof_indices,ML_vector);
1097 *   }
1098 * @endcode
1099 *
1100 * compress
1101 *
1102 * @code
1103 *   ML_vector.compress(VectorOperation::add);
1104 *   }
1105 *  
1106 *   template<int dim>
1107 *   void LevelSetSolver<dim>::invert_ML()
1108 *   {
1109 * @endcode
1110 *
1111 * loop on locally owned i-DOFs (rows)
1112 *
1113 * @code
1114 *   IndexSet::ElementIterator idofs_iter = locally_owned_dofs_LS.begin();
1115 *   for (; idofs_iter!=locally_owned_dofs_LS.end(); ++idofs_iter)
1116 *   {
1117 *   int gi = *idofs_iter;
1118 *   inverse_ML_vector(gi) = 1./ML_vector(gi);
1119 *   }
1120 *   inverse_ML_vector.compress(VectorOperation::insert);
1121 *   }
1122 *  
1123 *   template<int dim>
1124 *   void LevelSetSolver<dim>::assemble_MC()
1125 *   {
1126 *   MC_matrix=0;
1127 *  
1128 *   const QGauss<dim> quadrature_formula(degree_MAX+1);
1129 *   FEValues<dim> fe_values_LS (fe_LS, quadrature_formula,
1132 *   update_JxW_values);
1133 *  
1134 *   const unsigned int dofs_per_cell = fe_LS.dofs_per_cell;
1135 *   const unsigned int n_q_points = quadrature_formula.size();
1136 *  
1137 *   FullMatrix<double> cell_MC (dofs_per_cell, dofs_per_cell);
1138 *   std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1139 *   std::vector<double> shape_values(dofs_per_cell);
1140 *  
1142 *   cell_LS = dof_handler_LS.begin_active(),
1143 *   endc_LS = dof_handler_LS.end();
1144 *  
1145 *   for (; cell_LS!=endc_LS; ++cell_LS)
1146 *   if (cell_LS->is_locally_owned())
1147 *   {
1148 *   cell_MC = 0;
1149 *   fe_values_LS.reinit (cell_LS);
1150 *   for (unsigned int q_point=0; q_point<n_q_points; ++q_point)
1151 *   {
1152 *   const double JxW = fe_values_LS.JxW(q_point);
1153 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
1154 *   shape_values[i] = fe_values_LS.shape_value(i,q_point);
1155 *  
1156 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
1157 *   for (unsigned int j=0; j<dofs_per_cell; ++j)
1158 *   cell_MC(i,j) += shape_values[i]*shape_values[j]*JxW;
1159 *   }
1160 * @endcode
1161 *
1162 * distribute
1163 *
1164 * @code
1165 *   cell_LS->get_dof_indices (local_dof_indices);
1166 *   constraints.distribute_local_to_global (cell_MC,local_dof_indices,MC_matrix);
1167 *   }
1168 * @endcode
1169 *
1170 * compress
1171 *
1172 * @code
1173 *   MC_matrix.compress(VectorOperation::add);
1174 *   MC_preconditioner.reset(new PETScWrappers::PreconditionBoomerAMG(MC_matrix,PETScWrappers::PreconditionBoomerAMG::AdditionalData(true)));
1175 *   }
1176 *  
1177 * @endcode
1178 *
1179 * ---------------------------------------------------------------------------------------
1180 * ------------------------------ LO METHOD (Dij Viscosity) ------------------------------
1181 * ---------------------------------------------------------------------------------------
1182 *
1183 * @code
1184 *   template <int dim>
1185 *   void LevelSetSolver<dim>::assemble_C_Matrix ()
1186 *   {
1187 *   Cx_matrix=0;
1188 *   CTx_matrix=0;
1189 *   Cy_matrix=0;
1190 *   CTy_matrix=0;
1191 *   Cz_matrix=0;
1192 *   CTz_matrix=0;
1193 *  
1194 *   const QGauss<dim> quadrature_formula(degree_MAX+1);
1195 *   FEValues<dim> fe_values_LS (fe_LS, quadrature_formula,
1198 *   update_JxW_values);
1199 *  
1200 *   const unsigned int dofs_per_cell_LS = fe_LS.dofs_per_cell;
1201 *   const unsigned int n_q_points = quadrature_formula.size();
1202 *  
1203 *   FullMatrix<double> cell_Cij_x (dofs_per_cell_LS, dofs_per_cell_LS);
1204 *   FullMatrix<double> cell_Cij_y (dofs_per_cell_LS, dofs_per_cell_LS);
1205 *   FullMatrix<double> cell_Cij_z (dofs_per_cell_LS, dofs_per_cell_LS);
1206 *   FullMatrix<double> cell_Cji_x (dofs_per_cell_LS, dofs_per_cell_LS);
1207 *   FullMatrix<double> cell_Cji_y (dofs_per_cell_LS, dofs_per_cell_LS);
1208 *   FullMatrix<double> cell_Cji_z (dofs_per_cell_LS, dofs_per_cell_LS);
1209 *  
1210 *   std::vector<Tensor<1, dim> > shape_grads_LS(dofs_per_cell_LS);
1211 *   std::vector<double> shape_values_LS(dofs_per_cell_LS);
1212 *  
1213 *   std::vector<types::global_dof_index> local_dof_indices_LS (dofs_per_cell_LS);
1214 *  
1215 *   typename DoFHandler<dim>::active_cell_iterator cell_LS, endc_LS;
1216 *   cell_LS = dof_handler_LS.begin_active();
1217 *   endc_LS = dof_handler_LS.end();
1218 *  
1219 *   for (; cell_LS!=endc_LS; ++cell_LS)
1220 *   if (cell_LS->is_locally_owned())
1221 *   {
1222 *   cell_Cij_x = 0;
1223 *   cell_Cij_y = 0;
1224 *   cell_Cji_x = 0;
1225 *   cell_Cji_y = 0;
1226 *   if (dim==3)
1227 *   {
1228 *   cell_Cij_z = 0;
1229 *   cell_Cji_z = 0;
1230 *   }
1231 *  
1232 *   fe_values_LS.reinit (cell_LS);
1233 *   cell_LS->get_dof_indices (local_dof_indices_LS);
1234 *  
1235 *   for (unsigned int q_point=0; q_point<n_q_points; ++q_point)
1236 *   {
1237 *   const double JxW = fe_values_LS.JxW(q_point);
1238 *   for (unsigned int i=0; i<dofs_per_cell_LS; ++i)
1239 *   {
1240 *   shape_values_LS[i] = fe_values_LS.shape_value(i,q_point);
1241 *   shape_grads_LS [i] = fe_values_LS.shape_grad (i,q_point);
1242 *   }
1243 *  
1244 *   for (unsigned int i=0; i<dofs_per_cell_LS; ++i)
1245 *   for (unsigned int j=0; j < dofs_per_cell_LS; ++j)
1246 *   {
1247 *   cell_Cij_x(i,j) += (shape_grads_LS[j][0])*shape_values_LS[i]*JxW;
1248 *   cell_Cij_y(i,j) += (shape_grads_LS[j][1])*shape_values_LS[i]*JxW;
1249 *   cell_Cji_x(i,j) += (shape_grads_LS[i][0])*shape_values_LS[j]*JxW;
1250 *   cell_Cji_y(i,j) += (shape_grads_LS[i][1])*shape_values_LS[j]*JxW;
1251 *   if (dim==3)
1252 *   {
1253 *   cell_Cij_z(i,j) += (shape_grads_LS[j][2])*shape_values_LS[i]*JxW;
1254 *   cell_Cji_z(i,j) += (shape_grads_LS[i][2])*shape_values_LS[j]*JxW;
1255 *   }
1256 *   }
1257 *   }
1258 * @endcode
1259 *
1260 * Distribute
1261 *
1262 * @code
1263 *   constraints.distribute_local_to_global(cell_Cij_x,local_dof_indices_LS,Cx_matrix);
1264 *   constraints.distribute_local_to_global(cell_Cji_x,local_dof_indices_LS,CTx_matrix);
1265 *   constraints.distribute_local_to_global(cell_Cij_y,local_dof_indices_LS,Cy_matrix);
1266 *   constraints.distribute_local_to_global(cell_Cji_y,local_dof_indices_LS,CTy_matrix);
1267 *   if (dim==3)
1268 *   {
1269 *   constraints.distribute_local_to_global(cell_Cij_z,local_dof_indices_LS,Cz_matrix);
1270 *   constraints.distribute_local_to_global(cell_Cji_z,local_dof_indices_LS,CTz_matrix);
1271 *   }
1272 *   }
1273 * @endcode
1274 *
1275 * COMPRESS
1276 *
1277 * @code
1278 *   Cx_matrix.compress(VectorOperation::add);
1279 *   CTx_matrix.compress(VectorOperation::add);
1280 *   Cy_matrix.compress(VectorOperation::add);
1281 *   CTy_matrix.compress(VectorOperation::add);
1282 *   if (dim==3)
1283 *   {
1284 *   Cz_matrix.compress(VectorOperation::add);
1285 *   CTz_matrix.compress(VectorOperation::add);
1286 *   }
1287 *   }
1288 *  
1289 *   template<int dim>
1290 *   void LevelSetSolver<dim>::assemble_K_times_vector(PETScWrappers::MPI::Vector &solution)
1291 *   {
1292 *   K_times_solution = 0;
1293 *  
1294 *   const QGauss<dim> quadrature_formula(degree_MAX+1);
1295 *   FEValues<dim> fe_values_LS (fe_LS, quadrature_formula,
1298 *   update_JxW_values);
1299 *   FEValues<dim> fe_values_U (fe_U, quadrature_formula,
1302 *   update_JxW_values);
1303 *   const unsigned int dofs_per_cell = fe_LS.dofs_per_cell;
1304 *   const unsigned int n_q_points = quadrature_formula.size();
1305 *  
1306 *   Vector<double> cell_K_times_solution (dofs_per_cell);
1307 *  
1308 *   std::vector<Tensor<1,dim> > un_grads (n_q_points);
1309 *   std::vector<double> old_vx_values (n_q_points);
1310 *   std::vector<double> old_vy_values (n_q_points);
1311 *   std::vector<double> old_vz_values (n_q_points);
1312 *  
1313 *   std::vector<double> shape_values(dofs_per_cell);
1314 *   std::vector<Tensor<1,dim> > shape_grads(dofs_per_cell);
1315 *  
1316 *   Vector<double> un_dofs(dofs_per_cell);
1317 *  
1318 *   std::vector<types::global_dof_index> indices_LS (dofs_per_cell);
1319 *  
1320 * @endcode
1321 *
1322 * loop on cells
1323 *
1324 * @code
1326 *   cell_LS = dof_handler_LS.begin_active(),
1327 *   endc_LS = dof_handler_LS.end();
1329 *   cell_U = dof_handler_U.begin_active();
1330 *  
1331 *   Tensor<1,dim> v;
1332 *   for (; cell_LS!=endc_LS; ++cell_U, ++cell_LS)
1333 *   if (cell_LS->is_locally_owned())
1334 *   {
1335 *   cell_K_times_solution=0;
1336 *  
1337 *   fe_values_LS.reinit (cell_LS);
1338 *   cell_LS->get_dof_indices (indices_LS);
1339 *   fe_values_LS.get_function_gradients(solution,un_grads);
1340 *  
1341 *   fe_values_U.reinit (cell_U);
1342 *   fe_values_U.get_function_values(locally_relevant_solution_vx,old_vx_values);
1343 *   fe_values_U.get_function_values(locally_relevant_solution_vy,old_vy_values);
1344 *   if (dim==3) fe_values_U.get_function_values(locally_relevant_solution_vz,old_vz_values);
1345 *  
1346 * @endcode
1347 *
1348 * compute cell_K_times_solution
1349 *
1350 * @code
1351 *   for (unsigned int q_point=0; q_point<n_q_points; ++q_point)
1352 *   {
1353 *   v[0] = old_vx_values[q_point];
1354 *   v[1] = old_vy_values[q_point];
1355 *   if (dim==3) v[2] = old_vz_values[q_point]; //dim=3
1356 *  
1357 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
1358 *   cell_K_times_solution(i) += (v*un_grads[q_point])
1359 *   *fe_values_LS.shape_value(i,q_point)*fe_values_LS.JxW(q_point);
1360 *   }
1361 * @endcode
1362 *
1363 * distribute
1364 *
1365 * @code
1366 *   constraints.distribute_local_to_global (cell_K_times_solution, indices_LS, K_times_solution);
1367 *   }
1368 *   K_times_solution.compress(VectorOperation::add);
1369 *   }
1370 *  
1371 *   template <int dim>
1372 *   void LevelSetSolver<dim>::assemble_K_DL_DH_times_vector
1373 *   (PETScWrappers::MPI::Vector &solution)
1374 *   {
1375 * @endcode
1376 *
1377 * K_times_solution=0;
1378 *
1379 * @code
1380 *   DL_times_solution=0;
1381 *   DH_times_solution=0;
1382 *   dLij_matrix = 0;
1383 *   dCij_matrix = 0;
1384 *  
1385 *   PetscInt ncolumns;
1386 *   const PetscInt *gj;
1387 *   const PetscScalar *Cxi, *Cyi, *Czi, *CTxi, *CTyi, *CTzi;
1388 *   const PetscScalar *EntResi, *SuppSizei, *MCi;
1389 *   double solni;
1390 *  
1391 *   Tensor<1,dim> vi,vj;
1392 *   Tensor<1,dim> C, CT;
1393 * @endcode
1394 *
1395 * loop on locally owned i-DOFs (rows)
1396 *
1397 * @code
1398 *   IndexSet::ElementIterator idofs_iter = locally_owned_dofs_LS.begin();
1399 *  
1400 *   for (; idofs_iter!=locally_owned_dofs_LS.end(); ++idofs_iter)
1401 *   {
1402 *   PetscInt gi = *idofs_iter;
1403 * @endcode
1404 *
1405 * double ith_K_times_solution = 0;
1406 *
1407
1408 *
1409 * read velocity of i-th DOF
1410 *
1411 * @code
1412 *   vi[0] = locally_relevant_solution_vx(map_from_Q1_to_Q2[gi]);
1413 *   vi[1] = locally_relevant_solution_vy(map_from_Q1_to_Q2[gi]);
1414 *   if (dim==3) vi[2] = locally_relevant_solution_vz(map_from_Q1_to_Q2[gi]);
1415 *   solni = solution(gi);
1416 *  
1417 * @endcode
1418 *
1419 * get i-th row of C matrices
1420 *
1421 * @code
1422 *   MatGetRow(Cx_matrix,gi,&ncolumns,&gj,&Cxi);
1423 *   MatGetRow(Cy_matrix,gi,&ncolumns,&gj,&Cyi);
1424 *   MatGetRow(CTx_matrix,gi,&ncolumns,&gj,&CTxi);
1425 *   MatGetRow(CTy_matrix,gi,&ncolumns,&gj,&CTyi);
1426 *   if (dim==3)
1427 *   {
1428 *   MatGetRow(Cz_matrix,gi,&ncolumns,&gj,&Czi);
1429 *   MatGetRow(CTz_matrix,gi,&ncolumns,&gj,&CTzi);
1430 *   }
1431 *   MatGetRow(EntRes_matrix,gi,&ncolumns,&gj,&EntResi);
1432 *   MatGetRow(SuppSize_matrix,gi,&ncolumns,&gj,&SuppSizei);
1433 *   MatGetRow(MC_matrix,gi,&ncolumns,&gj,&MCi);
1434 *  
1435 * @endcode
1436 *
1437 * get vector values for column indices
1438 *
1439 * @code
1440 *   const std::vector<types::global_dof_index> gj_indices (gj,gj+ncolumns);
1441 *   std::vector<double> soln(ncolumns);
1442 *   std::vector<double> vx(ncolumns);
1443 *   std::vector<double> vy(ncolumns);
1444 *   std::vector<double> vz(ncolumns);
1445 *   get_vector_values(solution,gj_indices,soln);
1446 *   get_vector_values(locally_relevant_solution_vx,gj_indices,map_from_Q1_to_Q2,vx);
1447 *   get_vector_values(locally_relevant_solution_vy,gj_indices,map_from_Q1_to_Q2,vy);
1448 *   if (dim==3)
1449 *   get_vector_values(locally_relevant_solution_vz,gj_indices,map_from_Q1_to_Q2,vz);
1450 *  
1451 * @endcode
1452 *
1453 * Array for i-th row of matrices
1454 *
1455 * @code
1456 *   std::vector<double> dLi(ncolumns), dCi(ncolumns);
1457 *   double dLii = 0, dCii = 0;
1458 * @endcode
1459 *
1460 * loop on sparsity pattern of i-th DOF
1461 *
1462 * @code
1463 *   for (int j =0; j < ncolumns; ++j)
1464 *   {
1465 *   C[0] = Cxi[j];
1466 *   C[1] = Cyi[j];
1467 *   CT[0]= CTxi[j];
1468 *   CT[1]= CTyi[j];
1469 *   vj[0] = vx[j];
1470 *   vj[1] = vy[j];
1471 *   if (dim==3)
1472 *   {
1473 *   C[2] = Czi[j];
1474 *   CT[2] = CTzi[j];
1475 *   vj[2] = vz[j];
1476 *   }
1477 *  
1478 * @endcode
1479 *
1480 * ith_K_times_solution += soln[j]*(vj*C);
1481 *
1482 * @code
1483 *   if (gi!=gj[j])
1484 *   {
1485 * @endcode
1486 *
1487 * low order dissipative matrix
1488 *
1489 * @code
1490 *   dLi[j] = -std::max(std::abs(vi*C),std::abs(vj*CT));
1491 *   dLii -= dLi[j];
1492 * @endcode
1493 *
1494 * high order dissipative matrix (entropy viscosity)
1495 *
1496 * @code
1497 *   double dEij = -std::min(-dLi[j],
1498 *   cE*std::abs(EntResi[j])/(entropy_normalization_factor*MCi[j]/SuppSizei[j]));
1499 * @endcode
1500 *
1501 * high order compression matrix
1502 *
1503 * @code
1504 *   double Compij = cK*std::max(1-std::pow(0.5*(solni+soln[j]),2),0.0)/(std::abs(solni-soln[j])+1E-14);
1505 *   dCi[j] = dEij*std::max(1-Compij,0.0);
1506 *   dCii -= dCi[j];
1507 *   }
1508 *   }
1509 * @endcode
1510 *
1511 * save K times solution vector
1512 * K_times_solution(gi)=ith_K_times_solution;
1513 * save i-th row of matrices on global matrices
1514 *
1515 * @code
1516 *   MatSetValuesRow(dLij_matrix,gi,&dLi[0]); // BTW: there is a dealii wrapper for this
1517 *   dLij_matrix.set(gi,gi,dLii);
1518 *   MatSetValuesRow(dCij_matrix,gi,&dCi[0]); // BTW: there is a dealii wrapper for this
1519 *   dCij_matrix.set(gi,gi,dCii);
1520 *  
1521 * @endcode
1522 *
1523 * Restore matrices after reading rows
1524 *
1525 * @code
1526 *   MatRestoreRow(Cx_matrix,gi,&ncolumns,&gj,&Cxi);
1527 *   MatRestoreRow(Cy_matrix,gi,&ncolumns,&gj,&Cyi);
1528 *   MatRestoreRow(CTx_matrix,gi,&ncolumns,&gj,&CTxi);
1529 *   MatRestoreRow(CTy_matrix,gi,&ncolumns,&gj,&CTyi);
1530 *   if (dim==3)
1531 *   {
1532 *   MatRestoreRow(Cz_matrix,gi,&ncolumns,&gj,&Czi);
1533 *   MatRestoreRow(CTz_matrix,gi,&ncolumns,&gj,&CTzi);
1534 *   }
1535 *   MatRestoreRow(EntRes_matrix,gi,&ncolumns,&gj,&EntResi);
1536 *   MatRestoreRow(SuppSize_matrix,gi,&ncolumns,&gj,&SuppSizei);
1537 *   MatRestoreRow(MC_matrix,gi,&ncolumns,&gj,&MCi);
1538 *   }
1539 * @endcode
1540 *
1541 * compress
1542 * K_times_solution.compress(VectorOperation::insert);
1543 *
1544 * @code
1545 *   dLij_matrix.compress(VectorOperation::insert);
1546 *   dCij_matrix.compress(VectorOperation::insert);
1547 * @endcode
1548 *
1549 * get matrices times vector
1550 *
1551 * @code
1552 *   dLij_matrix.vmult(DL_times_solution,solution);
1553 *   dCij_matrix.vmult(DH_times_solution,solution);
1554 *   }
1555 *  
1556 * @endcode
1557 *
1558 * --------------------------------------------------------------------------------------
1559 * ------------------------------ ENTROPY VISCOSITY ------------------------------
1560 * --------------------------------------------------------------------------------------
1561 *
1562 * @code
1563 *   template <int dim>
1564 *   void LevelSetSolver<dim>::assemble_EntRes_Matrix ()
1565 *   {
1566 *   EntRes_matrix=0;
1567 *   entropy_normalization_factor=0;
1568 *   SuppSize_matrix=0;
1569 *  
1570 *   const QGauss<dim> quadrature_formula(degree_MAX+1);
1571 *   FEValues<dim> fe_values_U (fe_U, quadrature_formula,
1574 *   update_JxW_values);
1575 *   FEValues<dim> fe_values_LS (fe_LS, quadrature_formula,
1578 *   update_JxW_values);
1579 *  
1580 *   const unsigned int dofs_per_cell_LS = fe_LS.dofs_per_cell;
1581 *   const unsigned int n_q_points = quadrature_formula.size();
1582 *  
1583 *   std::vector<double> uqn (n_q_points); // un at q point
1584 *   std::vector<double> uqnm1 (n_q_points);
1585 *   std::vector<Tensor<1,dim> > guqn (n_q_points); //grad of uqn
1586 *   std::vector<Tensor<1,dim> > guqnm1 (n_q_points);
1587 *  
1588 *   std::vector<double> vxqn (n_q_points);
1589 *   std::vector<double> vyqn (n_q_points);
1590 *   std::vector<double> vzqn (n_q_points);
1591 *   std::vector<double> vxqnm1 (n_q_points);
1592 *   std::vector<double> vyqnm1 (n_q_points);
1593 *   std::vector<double> vzqnm1 (n_q_points);
1594 *  
1595 *   FullMatrix<double> cell_EntRes (dofs_per_cell_LS, dofs_per_cell_LS);
1596 *   FullMatrix<double> cell_volume (dofs_per_cell_LS, dofs_per_cell_LS);
1597 *  
1598 *   std::vector<Tensor<1, dim> > shape_grads_LS(dofs_per_cell_LS);
1599 *   std::vector<double> shape_values_LS(dofs_per_cell_LS);
1600 *  
1601 *   std::vector<types::global_dof_index> local_dof_indices_LS (dofs_per_cell_LS);
1602 *  
1603 *   typename DoFHandler<dim>::active_cell_iterator cell_LS, endc_LS;
1604 *   cell_LS = dof_handler_LS.begin_active();
1605 *   endc_LS = dof_handler_LS.end();
1607 *   cell_U = dof_handler_U.begin_active();
1608 *  
1609 *   double Rk;
1610 *   double max_entropy=-1E10, min_entropy=1E10;
1611 *   double cell_max_entropy, cell_min_entropy;
1612 *   double cell_entropy_mass, entropy_mass=0;
1613 *   double cell_volume_double, volume=0;
1614 *  
1615 *   for (; cell_LS!=endc_LS; ++cell_LS, ++cell_U)
1616 *   if (cell_LS->is_locally_owned())
1617 *   {
1618 *   cell_entropy_mass = 0;
1619 *   cell_volume_double = 0;
1620 *   cell_max_entropy = -1E10;
1621 *   cell_min_entropy = 1E10;
1622 *   cell_EntRes = 0;
1623 *   cell_volume = 0;
1624 *  
1625 * @endcode
1626 *
1627 * get solutions at quadrature points
1628 *
1629 * @code
1630 *   fe_values_LS.reinit(cell_LS);
1631 *   cell_LS->get_dof_indices (local_dof_indices_LS);
1632 *   fe_values_LS.get_function_values(un,uqn);
1633 *   fe_values_LS.get_function_values(unm1,uqnm1);
1634 *   fe_values_LS.get_function_gradients(un,guqn);
1635 *   fe_values_LS.get_function_gradients(unm1,guqnm1);
1636 *  
1637 *   fe_values_U.reinit(cell_U);
1638 *   fe_values_U.get_function_values(locally_relevant_solution_vx,vxqn);
1639 *   fe_values_U.get_function_values(locally_relevant_solution_vy,vyqn);
1640 *   if (dim==3) fe_values_U.get_function_values(locally_relevant_solution_vz,vzqn);
1641 *   fe_values_U.get_function_values(locally_relevant_solution_vx_old,vxqnm1);
1642 *   fe_values_U.get_function_values(locally_relevant_solution_vy_old,vyqnm1);
1643 *   if (dim==3) fe_values_U.get_function_values(locally_relevant_solution_vz_old,vzqnm1);
1644 *  
1645 *   for (unsigned int q=0; q<n_q_points; ++q)
1646 *   {
1647 *   Rk = 1./time_step*(ENTROPY(uqn[q])-ENTROPY(uqnm1[q]))
1648 *   +(vxqn[q]*ENTROPY_GRAD(uqn[q],guqn[q][0])+vyqn[q]*ENTROPY_GRAD(uqn[q],guqn[q][1]))/2.
1649 *   +(vxqnm1[q]*ENTROPY_GRAD(uqnm1[q],guqnm1[q][0])+vyqnm1[q]*ENTROPY_GRAD(uqnm1[q],guqnm1[q][1]))/2.;
1650 *   if (dim==3)
1651 *   Rk += 0.5*(vzqn[q]*ENTROPY_GRAD(uqn[q],guqn[q][2])+vzqnm1[q]*ENTROPY_GRAD(uqnm1[q],guqnm1[q][2]));
1652 *  
1653 *   const double JxW = fe_values_LS.JxW(q);
1654 *   for (unsigned int i=0; i<dofs_per_cell_LS; ++i)
1655 *   {
1656 *   shape_values_LS[i] = fe_values_LS.shape_value(i,q);
1657 *   shape_grads_LS [i] = fe_values_LS.shape_grad (i,q);
1658 *   }
1659 *  
1660 *   for (unsigned int i=0; i<dofs_per_cell_LS; ++i)
1661 *   for (unsigned int j=0; j < dofs_per_cell_LS; ++j)
1662 *   {
1663 *   cell_EntRes (i,j) += Rk*shape_values_LS[i]*shape_values_LS[j]*JxW;
1664 *   cell_volume (i,j) += JxW;
1665 *   }
1666 *   cell_entropy_mass += ENTROPY(uqn[q])*JxW;
1667 *   cell_volume_double += JxW;
1668 *  
1669 *   cell_min_entropy = std::min(cell_min_entropy,ENTROPY(uqn[q]));
1670 *   cell_max_entropy = std::max(cell_max_entropy,ENTROPY(uqn[q]));
1671 *   }
1672 *   entropy_mass += cell_entropy_mass;
1673 *   volume += cell_volume_double;
1674 *  
1675 *   min_entropy = std::min(min_entropy,cell_min_entropy);
1676 *   max_entropy = std::max(max_entropy,cell_max_entropy);
1677 * @endcode
1678 *
1679 * Distribute
1680 *
1681 * @code
1682 *   constraints.distribute_local_to_global(cell_EntRes,local_dof_indices_LS,EntRes_matrix);
1683 *   constraints.distribute_local_to_global(cell_volume,local_dof_indices_LS,SuppSize_matrix);
1684 *   }
1685 *   EntRes_matrix.compress(VectorOperation::add);
1686 *   SuppSize_matrix.compress(VectorOperation::add);
1687 * @endcode
1688 *
1689 * ENTROPY NORM FACTOR
1690 *
1691 * @code
1692 *   volume = Utilities::MPI::sum(volume,mpi_communicator);
1693 *   entropy_mass = Utilities::MPI::sum(entropy_mass,mpi_communicator)/volume;
1694 *   min_entropy = Utilities::MPI::min(min_entropy,mpi_communicator);
1695 *   max_entropy = Utilities::MPI::max(max_entropy,mpi_communicator);
1696 *   entropy_normalization_factor = std::max(std::abs(max_entropy-entropy_mass), std::abs(min_entropy-entropy_mass));
1697 *   }
1698 *  
1699 * @endcode
1700 *
1701 * ------------------------------------------------------------------------------------
1702 * ------------------------------ TO CHECK MAX PRINCIPLE ------------------------------
1703 * ------------------------------------------------------------------------------------
1704 *
1705 * @code
1706 *   template<int dim>
1707 *   void LevelSetSolver<dim>::compute_bounds(PETScWrappers::MPI::Vector &un_solution)
1708 *   {
1709 *   umin_vector = 0;
1710 *   umax_vector = 0;
1711 * @endcode
1712 *
1713 * loop on locally owned i-DOFs (rows)
1714 *
1715 * @code
1716 *   IndexSet::ElementIterator idofs_iter = locally_owned_dofs_LS.begin();
1717 *   for (; idofs_iter!=locally_owned_dofs_LS.end(); ++idofs_iter)
1718 *   {
1719 *   int gi = *idofs_iter;
1720 *  
1721 * @endcode
1722 *
1723 * get solution at DOFs on the sparsity pattern of i-th DOF
1724 *
1725 * @code
1726 *   std::vector<types::global_dof_index> gj_indices = sparsity_pattern[gi];
1727 *   std::vector<double> soln(gj_indices.size());
1728 *   get_vector_values(un_solution,gj_indices,soln);
1729 * @endcode
1730 *
1731 * compute bounds, ith row of flux matrix, P vectors
1732 *
1733 * @code
1734 *   double mini=1E10, maxi=-1E10;
1735 *   for (unsigned int j =0; j < gj_indices.size(); ++j)
1736 *   {
1737 * @endcode
1738 *
1739 * bounds
1740 *
1741 * @code
1742 *   mini = std::min(mini,soln[j]);
1743 *   maxi = std::max(maxi,soln[j]);
1744 *   }
1745 *   umin_vector(gi) = mini;
1746 *   umax_vector(gi) = maxi;
1747 *   }
1748 *   umin_vector.compress(VectorOperation::insert);
1749 *   umax_vector.compress(VectorOperation::insert);
1750 *   }
1751 *  
1752 *   template<int dim>
1753 *   void LevelSetSolver<dim>::check_max_principle(PETScWrappers::MPI::Vector &unp1_solution)
1754 *   {
1755 * @endcode
1756 *
1757 * compute min and max vectors
1758 *
1759 * @code
1760 *   const unsigned int dofs_per_cell = fe_LS.dofs_per_cell;
1761 *   std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);
1762 *  
1763 *   double tol=1e-10;
1765 *   cell_LS = dof_handler_LS.begin_active(),
1766 *   endc_LS = dof_handler_LS.end();
1767 *  
1768 *   for (; cell_LS!=endc_LS; ++cell_LS)
1769 *   if (cell_LS->is_locally_owned() && !cell_LS->at_boundary())
1770 *   {
1771 *   cell_LS->get_dof_indices(local_dof_indices);
1772 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
1773 *   if (locally_owned_dofs_LS.is_element(local_dof_indices[i]))
1774 *   {
1775 *   double solni = unp1_solution(local_dof_indices[i]);
1776 *   if (solni - umin_vector(local_dof_indices[i]) < -tol || umax_vector(local_dof_indices[i]) - solni < -tol)
1777 *   {
1778 *   pcout << "MAX Principle violated" << std::endl;
1779 *   abort();
1780 *   }
1781 *   }
1782 *   }
1783 *   }
1784 *  
1785 * @endcode
1786 *
1787 * -------------------------------------------------------------------------------
1788 * ------------------------------ COMPUTE SOLUTIONS ------------------------------
1789 * -------------------------------------------------------------------------------
1790 *
1791 * @code
1792 *   template<int dim>
1793 *   void LevelSetSolver<dim>::compute_MPP_uL_and_NMPP_uH
1794 *   (PETScWrappers::MPI::Vector &MPP_uL_solution,
1795 *   PETScWrappers::MPI::Vector &NMPP_uH_solution,
1796 *   PETScWrappers::MPI::Vector &un_solution)
1797 *   {
1798 * @endcode
1799 *
1800 * NON-GHOSTED VECTORS: MPP_uL_solution, NMPP_uH_solution
1801 * GHOSTED VECTORS: un_solution
1802 *
1803 * @code
1804 *   MPP_uL_solution=un_solution;
1805 *   NMPP_uH_solution=un_solution; // to start iterative solver at un_solution (instead of zero)
1806 * @endcode
1807 *
1808 * assemble RHS VECTORS
1809 *
1810 * @code
1811 *   assemble_K_times_vector(un_solution);
1812 *   assemble_K_DL_DH_times_vector(un_solution);
1813 * @endcode
1814 *
1815 *
1816 * COMPUTE MPP u1 solution
1817 *
1818 *
1819 * @code
1820 *   MPP_uL_solution.scale(ML_vector);
1821 *   MPP_uL_solution.add(-time_step,K_times_solution);
1822 *   MPP_uL_solution.add(-time_step,DL_times_solution);
1823 *   MPP_uL_solution.scale(inverse_ML_vector);
1824 * @endcode
1825 *
1826 *
1827 * COMPUTE GALERKIN u2 solution
1828 *
1829 *
1830 * @code
1831 *   MC_matrix.vmult(RHS,un_solution);
1832 *   RHS.add(-time_step,K_times_solution,-time_step,DH_times_solution);
1833 *   solve(constraints,MC_matrix,MC_preconditioner,NMPP_uH_solution,RHS);
1834 *   }
1835 *  
1836 *   template <int dim>
1837 *   void LevelSetSolver<dim>::compute_MPP_uH
1838 *   (PETScWrappers::MPI::Vector &MPP_uH_solution,
1839 *   PETScWrappers::MPI::Vector &MPP_uL_solution_ghosted,
1840 *   PETScWrappers::MPI::Vector &NMPP_uH_solution_ghosted,
1841 *   PETScWrappers::MPI::Vector &solution)
1842 *   {
1843 *   MPP_uH_solution=0;
1844 * @endcode
1845 *
1846 * loop on locally owned i-DOFs (rows)
1847 *
1848 * @code
1849 *   IndexSet::ElementIterator idofs_iter = locally_owned_dofs_LS.begin();
1850 *  
1851 *   PetscInt ncolumns;
1852 *   const PetscInt *gj;
1853 *   const PetscScalar *MCi, *dLi, *dCi;
1854 *   double solni, mi, solLi, solHi;
1855 *  
1856 *   for (; idofs_iter!=locally_owned_dofs_LS.end(); ++idofs_iter)
1857 *   {
1858 *   int gi = *idofs_iter;
1859 * @endcode
1860 *
1861 * read vectors at i-th DOF
1862 *
1863 * @code
1864 *   solni=solution(gi);
1865 *   solHi=NMPP_uH_solution_ghosted(gi);
1866 *   solLi=MPP_uL_solution_ghosted(gi);
1867 *   mi=ML_vector(gi);
1868 *  
1869 * @endcode
1870 *
1871 * get i-th row of matrices
1872 *
1873 * @code
1874 *   MatGetRow(MC_matrix,gi,&ncolumns,&gj,&MCi);
1875 *   MatGetRow(dLij_matrix,gi,&ncolumns,&gj,&dLi);
1876 *   MatGetRow(dCij_matrix,gi,&ncolumns,&gj,&dCi);
1877 *  
1878 * @endcode
1879 *
1880 * get vector values for support of i-th DOF
1881 *
1882 * @code
1883 *   const std::vector<types::global_dof_index> gj_indices (gj,gj+ncolumns);
1884 *   std::vector<double> soln(ncolumns);
1885 *   std::vector<double> solH(ncolumns);
1886 *   get_vector_values(solution,gj_indices,soln);
1887 *   get_vector_values(NMPP_uH_solution_ghosted,gj_indices,solH);
1888 *  
1889 * @endcode
1890 *
1891 * Array for i-th row of matrices
1892 *
1893 * @code
1894 *   std::vector<double> Ai(ncolumns);
1895 * @endcode
1896 *
1897 * compute bounds, ith row of flux matrix, P vectors
1898 *
1899 * @code
1900 *   double mini=1E10, maxi=-1E10;
1901 *   double Pposi=0 ,Pnegi=0;
1902 *   for (int j =0; j < ncolumns; ++j)
1903 *   {
1904 * @endcode
1905 *
1906 * bounds
1907 *
1908 * @code
1909 *   mini = std::min(mini,soln[j]);
1910 *   maxi = std::max(maxi,soln[j]);
1911 *  
1912 * @endcode
1913 *
1914 * i-th row of flux matrix A
1915 *
1916 * @code
1917 *   Ai[j] = (((gi==gj[j]) ? 1 : 0)*mi - MCi[j])*(solH[j]-soln[j] - (solHi-solni))
1918 *   +time_step*(dLi[j]-dCi[j])*(soln[j]-solni);
1919 *  
1920 * @endcode
1921 *
1922 * compute P vectors
1923 *
1924 * @code
1925 *   Pposi += Ai[j]*((Ai[j] > 0) ? 1. : 0.);
1926 *   Pnegi += Ai[j]*((Ai[j] < 0) ? 1. : 0.);
1927 *   }
1928 * @endcode
1929 *
1930 * save i-th row of flux matrix A
1931 *
1932 * @code
1933 *   MatSetValuesRow(A_matrix,gi,&Ai[0]);
1934 *  
1935 * @endcode
1936 *
1937 * compute Q vectors
1938 *
1939 * @code
1940 *   double Qposi = mi*(maxi-solLi);
1941 *   double Qnegi = mi*(mini-solLi);
1942 *  
1943 * @endcode
1944 *
1945 * compute R vectors
1946 *
1947 * @code
1948 *   R_pos_vector_nonGhosted(gi) = ((Pposi==0) ? 1. : std::min(1.0,Qposi/Pposi));
1949 *   R_neg_vector_nonGhosted(gi) = ((Pnegi==0) ? 1. : std::min(1.0,Qnegi/Pnegi));
1950 *  
1951 * @endcode
1952 *
1953 * Restore matrices after reading rows
1954 *
1955 * @code
1956 *   MatRestoreRow(MC_matrix,gi,&ncolumns,&gj,&MCi);
1957 *   MatRestoreRow(dLij_matrix,gi,&ncolumns,&gj,&dLi);
1958 *   MatRestoreRow(dCij_matrix,gi,&ncolumns,&gj,&dCi);
1959 *   }
1960 * @endcode
1961 *
1962 * compress A matrix
1963 *
1964 * @code
1965 *   A_matrix.compress(VectorOperation::insert);
1966 * @endcode
1967 *
1968 * compress R vectors
1969 *
1970 * @code
1971 *   R_pos_vector_nonGhosted.compress(VectorOperation::insert);
1972 *   R_neg_vector_nonGhosted.compress(VectorOperation::insert);
1973 * @endcode
1974 *
1975 * update ghost values for R vectors
1976 *
1977 * @code
1978 *   R_pos_vector = R_pos_vector_nonGhosted;
1979 *   R_neg_vector = R_neg_vector_nonGhosted;
1980 *  
1981 * @endcode
1982 *
1983 * compute limiters. NOTE: this is a different loop due to need of i- and j-th entries of R vectors
1984 *
1985 * @code
1986 *   const double *Ai;
1987 *   double Rposi, Rnegi;
1988 *   idofs_iter=locally_owned_dofs_LS.begin();
1989 *   for (; idofs_iter!=locally_owned_dofs_LS.end(); ++idofs_iter)
1990 *   {
1991 *   int gi = *idofs_iter;
1992 *   Rposi = R_pos_vector(gi);
1993 *   Rnegi = R_neg_vector(gi);
1994 *  
1995 * @endcode
1996 *
1997 * get i-th row of A matrix
1998 *
1999 * @code
2000 *   MatGetRow(A_matrix,gi,&ncolumns,&gj,&Ai);
2001 *  
2002 * @endcode
2003 *
2004 * get vector values for column indices
2005 *
2006 * @code
2007 *   const std::vector<types::global_dof_index> gj_indices (gj,gj+ncolumns);
2008 *   std::vector<double> Rpos(ncolumns);
2009 *   std::vector<double> Rneg(ncolumns);
2010 *   get_vector_values(R_pos_vector,gj_indices,Rpos);
2011 *   get_vector_values(R_neg_vector,gj_indices,Rneg);
2012 *  
2013 * @endcode
2014 *
2015 * Array for i-th row of A_times_L matrix
2016 *
2017 * @code
2018 *   std::vector<double> LxAi(ncolumns);
2019 * @endcode
2020 *
2021 * loop in sparsity pattern of i-th DOF
2022 *
2023 * @code
2024 *   for (int j =0; j < ncolumns; ++j)
2025 *   LxAi[j] = Ai[j] * ((Ai[j]>0) ? std::min(Rposi,Rneg[j]) : std::min(Rnegi,Rpos[j]));
2026 *  
2027 * @endcode
2028 *
2029 * save i-th row of LxA
2030 *
2031 * @code
2032 *   MatSetValuesRow(LxA_matrix,gi,&LxAi[0]); // BTW: there is a dealii wrapper for this
2033 * @endcode
2034 *
2035 * restore A matrix after reading it
2036 *
2037 * @code
2038 *   MatRestoreRow(A_matrix,gi,&ncolumns,&gj,&Ai);
2039 *   }
2040 *   LxA_matrix.compress(VectorOperation::insert);
2041 *   LxA_matrix.vmult(MPP_uH_solution,ones_vector);
2042 *   MPP_uH_solution.scale(inverse_ML_vector);
2043 *   MPP_uH_solution.add(1.0,MPP_uL_solution_ghosted);
2044 *   }
2045 *  
2046 *   template<int dim>
2047 *   void LevelSetSolver<dim>::compute_MPP_uH_with_iterated_FCT
2048 *   (PETScWrappers::MPI::Vector &MPP_uH_solution,
2049 *   PETScWrappers::MPI::Vector &MPP_uL_solution_ghosted,
2050 *   PETScWrappers::MPI::Vector &NMPP_uH_solution_ghosted,
2051 *   PETScWrappers::MPI::Vector &un_solution)
2052 *   {
2053 *   MPP_uH_solution=0;
2054 *   compute_MPP_uH(MPP_uH_solution,MPP_uL_solution_ghosted,NMPP_uH_solution_ghosted,un_solution);
2055 *  
2056 *   if (NUM_ITER>0)
2057 *   {
2058 *   Akp1_matrix.copy_from(A_matrix);
2059 *   LxAkp1_matrix.copy_from(LxA_matrix);
2060 *  
2061 * @endcode
2062 *
2063 * loop in num of FCT iterations
2064 *
2065 * @code
2066 *   PetscInt ncolumns;
2067 *   const PetscInt *gj;
2068 *   const PetscScalar *Akp1i;
2069 *   double mi;
2070 *   for (int iter=0; iter<NUM_ITER; ++iter)
2071 *   {
2072 *   MPP_uLkp1_solution_ghosted = MPP_uH_solution;
2073 *   Akp1_matrix.add(-1.0, LxAkp1_matrix); //new matrix to limit: A-LxA
2074 *  
2075 * @endcode
2076 *
2077 * loop on locally owned i-DOFs (rows)
2078 *
2079 * @code
2080 *   IndexSet::ElementIterator idofs_iter = locally_owned_dofs_LS.begin();
2081 *   for (; idofs_iter!=locally_owned_dofs_LS.end(); ++idofs_iter)
2082 *   {
2083 *   int gi = *idofs_iter;
2084 *  
2085 * @endcode
2086 *
2087 * read vectors at i-th DOF
2088 *
2089 * @code
2090 *   mi=ML_vector(gi);
2091 *   double solLi = MPP_uLkp1_solution_ghosted(gi);
2092 *  
2093 * @endcode
2094 *
2095 * get i-th row of matrices
2096 *
2097 * @code
2098 *   MatGetRow(Akp1_matrix,gi,&ncolumns,&gj,&Akp1i);
2099 * @endcode
2100 *
2101 * get vector values for support of i-th DOF
2102 *
2103 * @code
2104 *   const std::vector<types::global_dof_index> gj_indices (gj,gj+ncolumns);
2105 *   std::vector<double> soln(ncolumns);
2106 *   get_vector_values(un_solution,gj_indices,soln);
2107 *  
2108 * @endcode
2109 *
2110 * compute bounds, ith row of flux matrix, P vectors
2111 *
2112 * @code
2113 *   double mini=1E10, maxi=-1E10;
2114 *   double Pposi=0 ,Pnegi=0;
2115 *   for (int j =0; j < ncolumns; ++j)
2116 *   {
2117 * @endcode
2118 *
2119 * bounds
2120 *
2121 * @code
2122 *   mini = std::min(mini,soln[j]);
2123 *   maxi = std::max(maxi,soln[j]);
2124 *  
2125 * @endcode
2126 *
2127 * compute P vectors
2128 *
2129 * @code
2130 *   Pposi += Akp1i[j]*((Akp1i[j] > 0) ? 1. : 0.);
2131 *   Pnegi += Akp1i[j]*((Akp1i[j] < 0) ? 1. : 0.);
2132 *   }
2133 * @endcode
2134 *
2135 * compute Q vectors
2136 *
2137 * @code
2138 *   double Qposi = mi*(maxi-solLi);
2139 *   double Qnegi = mi*(mini-solLi);
2140 *  
2141 * @endcode
2142 *
2143 * compute R vectors
2144 *
2145 * @code
2146 *   R_pos_vector_nonGhosted(gi) = ((Pposi==0) ? 1. : std::min(1.0,Qposi/Pposi));
2147 *   R_neg_vector_nonGhosted(gi) = ((Pnegi==0) ? 1. : std::min(1.0,Qnegi/Pnegi));
2148 *  
2149 * @endcode
2150 *
2151 * Restore matrices after reading rows
2152 *
2153 * @code
2154 *   MatRestoreRow(Akp1_matrix,gi,&ncolumns,&gj,&Akp1i);
2155 *   }
2156 * @endcode
2157 *
2158 * compress R vectors
2159 *
2160 * @code
2161 *   R_pos_vector_nonGhosted.compress(VectorOperation::insert);
2162 *   R_neg_vector_nonGhosted.compress(VectorOperation::insert);
2163 * @endcode
2164 *
2165 * update ghost values for R vectors
2166 *
2167 * @code
2168 *   R_pos_vector = R_pos_vector_nonGhosted;
2169 *   R_neg_vector = R_neg_vector_nonGhosted;
2170 *  
2171 * @endcode
2172 *
2173 * compute limiters. NOTE: this is a different loop due to need of i- and j-th entries of R vectors
2174 *
2175 * @code
2176 *   double Rposi, Rnegi;
2177 *   idofs_iter=locally_owned_dofs_LS.begin();
2178 *   for (; idofs_iter!=locally_owned_dofs_LS.end(); ++idofs_iter)
2179 *   {
2180 *   int gi = *idofs_iter;
2181 *   Rposi = R_pos_vector(gi);
2182 *   Rnegi = R_neg_vector(gi);
2183 *  
2184 * @endcode
2185 *
2186 * get i-th row of Akp1 matrix
2187 *
2188 * @code
2189 *   MatGetRow(Akp1_matrix,gi,&ncolumns,&gj,&Akp1i);
2190 *  
2191 * @endcode
2192 *
2193 * get vector values for column indices
2194 *
2195 * @code
2196 *   const std::vector<types::global_dof_index> gj_indices(gj,gj+ncolumns);
2197 *   std::vector<double> Rpos(ncolumns);
2198 *   std::vector<double> Rneg(ncolumns);
2199 *   get_vector_values(R_pos_vector,gj_indices,Rpos);
2200 *   get_vector_values(R_neg_vector,gj_indices,Rneg);
2201 *  
2202 * @endcode
2203 *
2204 * Array for i-th row of LxAkp1 matrix
2205 *
2206 * @code
2207 *   std::vector<double> LxAkp1i(ncolumns);
2208 *   for (int j =0; j < ncolumns; ++j)
2209 *   LxAkp1i[j] = Akp1i[j] * ((Akp1i[j]>0) ? std::min(Rposi,Rneg[j]) : std::min(Rnegi,Rpos[j]));
2210 *  
2211 * @endcode
2212 *
2213 * save i-th row of LxA
2214 *
2215 * @code
2216 *   MatSetValuesRow(LxAkp1_matrix,gi,&LxAkp1i[0]); // BTW: there is a dealii wrapper for this
2217 * @endcode
2218 *
2219 * restore A matrix after reading it
2220 *
2221 * @code
2222 *   MatRestoreRow(Akp1_matrix,gi,&ncolumns,&gj,&Akp1i);
2223 *   }
2224 *   LxAkp1_matrix.compress(VectorOperation::insert);
2225 *   LxAkp1_matrix.vmult(MPP_uH_solution,ones_vector);
2226 *   MPP_uH_solution.scale(inverse_ML_vector);
2227 *   MPP_uH_solution.add(1.0,MPP_uLkp1_solution_ghosted);
2228 *   }
2229 *   }
2230 *   }
2231 *  
2232 *   template<int dim>
2233 *   void LevelSetSolver<dim>::compute_solution(PETScWrappers::MPI::Vector &unp1,
2235 *   std::string algorithm)
2236 *   {
2237 *   unp1=0;
2238 * @endcode
2239 *
2240 * COMPUTE MPP LOW-ORDER SOLN and NMPP HIGH-ORDER SOLN
2241 *
2242 * @code
2243 *   compute_MPP_uL_and_NMPP_uH(MPP_uL_solution,NMPP_uH_solution,un);
2244 *  
2245 *   if (algorithm.compare("MPP_u1")==0)
2246 *   unp1=MPP_uL_solution;
2247 *   else if (algorithm.compare("NMPP_uH")==0)
2248 *   unp1=NMPP_uH_solution;
2249 *   else if (algorithm.compare("MPP_uH")==0)
2250 *   {
2251 *   MPP_uL_solution_ghosted = MPP_uL_solution;
2252 *   NMPP_uH_solution_ghosted=NMPP_uH_solution;
2253 *   compute_MPP_uH_with_iterated_FCT(MPP_uH_solution,MPP_uL_solution_ghosted,NMPP_uH_solution_ghosted,un);
2254 *   unp1=MPP_uH_solution;
2255 *   }
2256 *   else
2257 *   {
2258 *   pcout << "Error in algorithm" << std::endl;
2259 *   abort();
2260 *   }
2261 *   }
2262 *  
2263 *   template<int dim>
2264 *   void LevelSetSolver<dim>::compute_solution_SSP33(PETScWrappers::MPI::Vector &unp1,
2266 *   std::string algorithm)
2267 *   {
2268 * @endcode
2269 *
2270 * GHOSTED VECTORS: un
2271 * NON-GHOSTED VECTORS: unp1
2272 *
2273 * @code
2274 *   unp1=0;
2275 *   uStage1=0., uStage2=0.;
2276 *   uStage1_nonGhosted=0., uStage2_nonGhosted=0.;
2277 * @endcode
2278 *
2279 *
2280 * FIRST STAGE
2281 *
2282 * u1=un-dt*RH*un
2283 *
2284 * @code
2285 *   compute_solution(uStage1_nonGhosted,un,algorithm);
2286 *   uStage1=uStage1_nonGhosted;
2287 * @endcode
2288 *
2289 *
2290 * SECOND STAGE
2291 *
2292 * u2=3/4*un+1/4*(u1-dt*RH*u1)
2293 *
2294 * @code
2295 *   compute_solution(uStage2_nonGhosted,uStage1,algorithm);
2296 *   uStage2_nonGhosted*=1./4;
2297 *   uStage2_nonGhosted.add(3./4,un);
2298 *   uStage2=uStage2_nonGhosted;
2299 * @endcode
2300 *
2301 *
2302 * THIRD STAGE
2303 *
2304 * unp1=1/3*un+2/3*(u2-dt*RH*u2)
2305 *
2306 * @code
2307 *   compute_solution(unp1,uStage2,algorithm);
2308 *   unp1*=2./3;
2309 *   unp1.add(1./3,un);
2310 *   }
2311 *  
2312 * @endcode
2313 *
2314 * -----------------------------------------------------------------------
2315 * ------------------------------ UTILITIES ------------------------------
2316 * -----------------------------------------------------------------------
2317 *
2318 * @code
2319 *   template<int dim>
2320 *   void LevelSetSolver<dim>::get_sparsity_pattern()
2321 *   {
2322 * @endcode
2323 *
2324 * loop on DOFs
2325 *
2326 * @code
2327 *   IndexSet::ElementIterator idofs_iter = locally_owned_dofs_LS.begin();
2328 *   PetscInt ncolumns;
2329 *   const PetscInt *gj;
2330 *   const PetscScalar *MCi;
2331 *  
2332 *   for (; idofs_iter!=locally_owned_dofs_LS.end(); ++idofs_iter)
2333 *   {
2334 *   PetscInt gi = *idofs_iter;
2335 * @endcode
2336 *
2337 * get i-th row of mass matrix (dummy, I just need the indices gj)
2338 *
2339 * @code
2340 *   MatGetRow(MC_matrix,gi,&ncolumns,&gj,&MCi);
2341 *   sparsity_pattern[gi] = std::vector<types::global_dof_index>(gj,gj+ncolumns);
2342 *   MatRestoreRow(MC_matrix,gi,&ncolumns,&gj,&MCi);
2343 *   }
2344 *   }
2345 *  
2346 *   template<int dim>
2347 *   void LevelSetSolver<dim>::get_map_from_Q1_to_Q2()
2348 *   {
2349 *   map_from_Q1_to_Q2.clear();
2350 *   const unsigned int dofs_per_cell_LS = fe_LS.dofs_per_cell;
2351 *   std::vector<types::global_dof_index> local_dof_indices_LS (dofs_per_cell_LS);
2352 *   const unsigned int dofs_per_cell_U = fe_U.dofs_per_cell;
2353 *   std::vector<types::global_dof_index> local_dof_indices_U (dofs_per_cell_U);
2354 *  
2356 *   cell_LS = dof_handler_LS.begin_active(),
2357 *   endc_LS = dof_handler_LS.end();
2359 *   cell_U = dof_handler_U.begin_active();
2360 *  
2361 *   for (; cell_LS!=endc_LS; ++cell_LS, ++cell_U)
2362 *   if (!cell_LS->is_artificial()) // loop on ghost cells as well
2363 *   {
2364 *   cell_LS->get_dof_indices(local_dof_indices_LS);
2365 *   cell_U->get_dof_indices(local_dof_indices_U);
2366 *   for (unsigned int i=0; i<dofs_per_cell_LS; ++i)
2367 *   map_from_Q1_to_Q2[local_dof_indices_LS[i]] = local_dof_indices_U[i];
2368 *   }
2369 *   }
2370 *  
2371 *   template <int dim>
2372 *   void LevelSetSolver<dim>::solve(const AffineConstraints<double> &constraints,
2374 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner,
2375 *   PETScWrappers::MPI::Vector &completely_distributed_solution,
2376 *   const PETScWrappers::MPI::Vector &rhs)
2377 *   {
2378 * @endcode
2379 *
2380 * all vectors are NON-GHOSTED
2381 *
2382 * @code
2383 *   SolverControl solver_control (dof_handler_LS.n_dofs(), solver_tolerance);
2384 *   PETScWrappers::SolverCG solver(solver_control);
2385 *   constraints.distribute (completely_distributed_solution);
2386 *   solver.solve (Matrix, completely_distributed_solution, rhs, *preconditioner);
2387 *   constraints.distribute (completely_distributed_solution);
2388 *   if (verbose==true) pcout << " Solved in " << solver_control.last_step() << " iterations." << std::endl;
2389 *   }
2390 *  
2391 *   template <int dim>
2392 *   void LevelSetSolver<dim>::save_old_solution()
2393 *   {
2394 *   unm1 = un;
2395 *   un = unp1;
2396 *   }
2397 *  
2398 *   template <int dim>
2399 *   void LevelSetSolver<dim>::save_old_vel_solution()
2400 *   {
2401 *   locally_relevant_solution_vx_old = locally_relevant_solution_vx;
2402 *   locally_relevant_solution_vy_old = locally_relevant_solution_vy;
2403 *   if (dim==3)
2404 *   locally_relevant_solution_vz_old = locally_relevant_solution_vz;
2405 *   }
2406 *  
2407 * @endcode
2408 *
2409 * -------------------------------------------------------------------------------
2410 * ------------------------------ MY PETSC WRAPPERS ------------------------------
2411 * -------------------------------------------------------------------------------
2412 *
2413 * @code
2414 *   template<int dim>
2415 *   void LevelSetSolver<dim>::get_vector_values (PETScWrappers::VectorBase &vector,
2416 *   const std::vector<types::global_dof_index> &indices,
2417 *   std::vector<PetscScalar> &values)
2418 *   {
2419 * @endcode
2420 *
2421 * PETSc wrapper to get sets of values from a petsc vector.
2422 * we assume the vector is ghosted
2423 * We need to figure out which elements we
2424 * own locally. Then get a pointer to the
2425 * elements that are stored here (both the
2426 * ones we own as well as the ghost elements).
2427 * In this array, the locally owned elements
2428 * come first followed by the ghost elements whose
2429 * position we can get from an index set
2430 *
2431
2432 *
2433 *
2434 * @code
2435 *   IndexSet ghost_indices = locally_relevant_dofs_LS;
2436 *   ghost_indices.subtract_set(locally_owned_dofs_LS);
2437 *  
2438 *   PetscInt n_idx, begin, end, i;
2439 *   n_idx = indices.size();
2440 *  
2441 *   VecGetOwnershipRange (vector, &begin, &end);
2442 *  
2443 *   Vec solution_in_local_form = nullptr;
2444 *   VecGhostGetLocalForm(vector, &solution_in_local_form);
2445 *  
2446 *   PetscScalar *soln;
2447 *   VecGetArray(solution_in_local_form, &soln);
2448 *  
2449 *   for (i = 0; i < n_idx; ++i)
2450 *   {
2451 *   int index = indices[i];
2452 *   if (index >= begin && index < end)
2453 *   values[i] = *(soln+index-begin);
2454 *   else //ghost
2455 *   {
2456 *   const unsigned int ghostidx = ghost_indices.index_within_set(index);
2457 *   values[i] = *(soln+ghostidx+end-begin);
2458 *   }
2459 *   }
2460 *   VecRestoreArray(solution_in_local_form, &soln);
2461 *   VecGhostRestoreLocalForm(vector, &solution_in_local_form);
2462 *   }
2463 *  
2464 *   template<int dim>
2465 *   void LevelSetSolver<dim>::get_vector_values (PETScWrappers::VectorBase &vector,
2466 *   const std::vector<types::global_dof_index> &indices,
2467 *   std::map<types::global_dof_index, types::global_dof_index> &map_from_Q1_to_Q2,
2468 *   std::vector<PetscScalar> &values)
2469 *   {
2470 * @endcode
2471 *
2472 * THIS IS MEANT TO BE USED WITH VELOCITY VECTORS
2473 * PETSc wrapper to get sets of values from a petsc vector.
2474 * we assume the vector is ghosted
2475 * We need to figure out which elements we
2476 * own locally. Then get a pointer to the
2477 * elements that are stored here (both the
2478 * ones we own as well as the ghost elements).
2479 * In this array, the locally owned elements
2480 * come first followed by the ghost elements whose
2481 * position we can get from an index set
2482 *
2483
2484 *
2485 *
2486 * @code
2487 *   IndexSet ghost_indices = locally_relevant_dofs_U;
2488 *   ghost_indices.subtract_set(locally_owned_dofs_U);
2489 *  
2490 *   PetscInt n_idx, begin, end, i;
2491 *   n_idx = indices.size();
2492 *  
2493 *   VecGetOwnershipRange (vector, &begin, &end);
2494 *  
2495 *   Vec solution_in_local_form = nullptr;
2496 *   VecGhostGetLocalForm(vector, &solution_in_local_form);
2497 *  
2498 *   PetscScalar *soln;
2499 *   VecGetArray(solution_in_local_form, &soln);
2500 *  
2501 *   for (i = 0; i < n_idx; ++i)
2502 *   {
2503 *   int index = map_from_Q1_to_Q2[indices[i]];
2504 *   if (index >= begin && index < end)
2505 *   values[i] = *(soln+index-begin);
2506 *   else //ghost
2507 *   {
2508 *   const unsigned int ghostidx = ghost_indices.index_within_set(index);
2509 *   values[i] = *(soln+ghostidx+end-begin);
2510 *   }
2511 *   }
2512 *   VecRestoreArray(solution_in_local_form, &soln);
2513 *   VecGhostRestoreLocalForm(vector, &solution_in_local_form);
2514 *   }
2515 *  
2516 * @endcode
2517
2518
2519<a name="ann-MultiPhase.cc"></a>
2520<h1>Annotated version of MultiPhase.cc</h1>
2521 *
2522 *
2523 *
2524 *
2525 * @code
2526 *   /* -----------------------------------------------------------------------------
2527 *   *
2528 *   * SPDX-License-Identifier: LGPL-2.1-or-later
2529 *   * Copyright (C) 2016 Manuel Quezada de Luna
2530 *   *
2531 *   * This file is part of the deal.II code gallery.
2532 *   *
2533 *   * -----------------------------------------------------------------------------
2534 *   */
2535 *  
2536 *   #include <deal.II/base/quadrature_lib.h>
2537 *   #include <deal.II/base/function.h>
2538 *   #include <deal.II/lac/affine_constraints.h>
2539 *   #include <deal.II/lac/vector.h>
2540 *   #include <deal.II/lac/full_matrix.h>
2541 *   #include <deal.II/lac/solver_cg.h>
2542 *   #include <deal.II/lac/petsc_sparse_matrix.h>
2543 *   #include <deal.II/lac/petsc_vector.h>
2544 *   #include <deal.II/lac/petsc_solver.h>
2545 *   #include <deal.II/lac/petsc_precondition.h>
2546 *   #include <deal.II/grid/grid_generator.h>
2547 *   #include <deal.II/grid/tria_accessor.h>
2548 *   #include <deal.II/grid/tria_iterator.h>
2549 *   #include <deal.II/dofs/dof_handler.h>
2550 *   #include <deal.II/dofs/dof_accessor.h>
2551 *   #include <deal.II/dofs/dof_tools.h>
2552 *   #include <deal.II/fe/fe_values.h>
2553 *   #include <deal.II/fe/fe_q.h>
2554 *   #include <deal.II/numerics/vector_tools.h>
2555 *   #include <deal.II/numerics/data_out.h>
2556 *   #include <deal.II/numerics/error_estimator.h>
2557 *   #include <deal.II/base/utilities.h>
2558 *   #include <deal.II/base/conditional_ostream.h>
2559 *   #include <deal.II/base/index_set.h>
2560 *   #include <deal.II/lac/sparsity_tools.h>
2561 *   #include <deal.II/distributed/tria.h>
2562 *   #include <deal.II/distributed/grid_refinement.h>
2563 *   #include <deal.II/base/convergence_table.h>
2564 *   #include <deal.II/base/timer.h>
2565 *   #include <deal.II/base/parameter_handler.h>
2566 *   #include <fstream>
2567 *   #include <iostream>
2568 *   #include <deal.II/grid/grid_tools.h>
2569 *   #include <deal.II/fe/mapping_q.h>
2570 *  
2571 *   using namespace dealii;
2572 *  
2573 * @endcode
2574 *
2575 *
2576 * FOR TRANSPORT PROBLEM
2577 *
2578 * TIME_INTEGRATION
2579 *
2580 * @code
2581 *   #define FORWARD_EULER 0
2582 *   #define SSP33 1
2583 * @endcode
2584 *
2585 * PROBLEM
2586 *
2587 * @code
2588 *   #define FILLING_TANK 0
2589 *   #define BREAKING_DAM 1
2590 *   #define FALLING_DROP 2
2591 *   #define SMALL_WAVE_PERTURBATION 3
2592 *  
2593 *   #include "NavierStokesSolver.cc"
2594 *   #include "LevelSetSolver.cc"
2595 *   #include "utilities.cc"
2596 *  
2597 * @endcode
2598 *
2599 *
2600 *
2601 *
2602 *
2603 * @code
2604 *   template <int dim>
2605 *   class MultiPhase
2606 *   {
2607 *   public:
2608 *   MultiPhase (const unsigned int degree_LS,
2609 *   const unsigned int degree_U);
2610 *   ~MultiPhase ();
2611 *   void run ();
2612 *  
2613 *   private:
2614 *   void set_boundary_inlet();
2615 *   void get_boundary_values_U();
2616 *   void get_boundary_values_phi(std::vector<types::global_dof_index> &boundary_values_id_phi,
2617 *   std::vector<double> &boundary_values_phi);
2618 *   void output_results();
2619 *   void output_vectors();
2620 *   void output_rho();
2621 *   void setup();
2622 *   void initial_condition();
2623 *   void init_constraints();
2624 *  
2625 *   MPI_Comm mpi_communicator;
2627 *  
2628 *   int degree_LS;
2629 *   DoFHandler<dim> dof_handler_LS;
2630 *   FE_Q<dim> fe_LS;
2631 *   IndexSet locally_owned_dofs_LS;
2632 *   IndexSet locally_relevant_dofs_LS;
2633 *  
2634 *  
2635 *   int degree_U;
2636 *   DoFHandler<dim> dof_handler_U;
2637 *   FE_Q<dim> fe_U;
2638 *   IndexSet locally_owned_dofs_U;
2639 *   IndexSet locally_relevant_dofs_U;
2640 *  
2641 *   DoFHandler<dim> dof_handler_P;
2642 *   FE_Q<dim> fe_P;
2643 *   IndexSet locally_owned_dofs_P;
2644 *   IndexSet locally_relevant_dofs_P;
2645 *  
2646 *   ConditionalOStream pcout;
2647 *  
2648 * @endcode
2649 *
2650 * SOLUTION VECTORS
2651 *
2652 * @code
2653 *   PETScWrappers::MPI::Vector locally_relevant_solution_phi;
2654 *   PETScWrappers::MPI::Vector locally_relevant_solution_u;
2655 *   PETScWrappers::MPI::Vector locally_relevant_solution_v;
2656 *   PETScWrappers::MPI::Vector locally_relevant_solution_p;
2657 *   PETScWrappers::MPI::Vector completely_distributed_solution_phi;
2658 *   PETScWrappers::MPI::Vector completely_distributed_solution_u;
2659 *   PETScWrappers::MPI::Vector completely_distributed_solution_v;
2660 *   PETScWrappers::MPI::Vector completely_distributed_solution_p;
2661 * @endcode
2662 *
2663 * BOUNDARY VECTORS
2664 *
2665 * @code
2666 *   std::vector<types::global_dof_index> boundary_values_id_u;
2667 *   std::vector<types::global_dof_index> boundary_values_id_v;
2668 *   std::vector<types::global_dof_index> boundary_values_id_phi;
2669 *   std::vector<double> boundary_values_u;
2670 *   std::vector<double> boundary_values_v;
2671 *   std::vector<double> boundary_values_phi;
2672 *  
2673 *   AffineConstraints<double> constraints;
2674 *  
2675 *   double time;
2676 *   double time_step;
2677 *   double final_time;
2678 *   unsigned int timestep_number;
2679 *   double cfl;
2680 *   double umax;
2681 *   double min_h;
2682 *  
2683 *   double sharpness;
2684 *   int sharpness_integer;
2685 *  
2686 *   unsigned int n_refinement;
2687 *   unsigned int output_number;
2688 *   double output_time;
2689 *   bool get_output;
2690 *  
2691 *   bool verbose;
2692 *  
2693 * @endcode
2694 *
2695 * FOR NAVIER STOKES
2696 *
2697 * @code
2698 *   double rho_fluid;
2699 *   double nu_fluid;
2700 *   double rho_air;
2701 *   double nu_air;
2702 *   double nu;
2703 *   double eps;
2704 *  
2705 * @endcode
2706 *
2707 * FOR TRANSPORT
2708 *
2709 * @code
2710 *   double cK; //compression coeff
2711 *   double cE; //entropy-visc coeff
2712 *   unsigned int TRANSPORT_TIME_INTEGRATION;
2713 *   std::string ALGORITHM;
2714 *   unsigned int PROBLEM;
2715 *   };
2716 *  
2717 *   template <int dim>
2718 *   MultiPhase<dim>::MultiPhase (const unsigned int degree_LS,
2719 *   const unsigned int degree_U)
2720 *   :
2721 *   mpi_communicator (MPI_COMM_WORLD),
2722 *   triangulation (mpi_communicator,
2726 *   degree_LS(degree_LS),
2727 *   dof_handler_LS (triangulation),
2728 *   fe_LS (degree_LS),
2729 *   degree_U(degree_U),
2730 *   dof_handler_U (triangulation),
2731 *   fe_U (degree_U),
2732 *   dof_handler_P (triangulation),
2733 *   fe_P (degree_U-1),
2734 *   pcout (std::cout,(Utilities::MPI::this_mpi_process(mpi_communicator)== 0))
2735 *   {}
2736 *  
2737 *   template <int dim>
2738 *   MultiPhase<dim>::~MultiPhase ()
2739 *   {
2740 *   dof_handler_LS.clear ();
2741 *   dof_handler_U.clear ();
2742 *   dof_handler_P.clear ();
2743 *   }
2744 *  
2745 * @endcode
2746 *
2747 *
2748 *
2749 *
2750 *
2751 * @code
2752 *   template <int dim>
2753 *   void MultiPhase<dim>::setup()
2754 *   {
2755 * @endcode
2756 *
2757 * setup system LS
2758 *
2759 * @code
2760 *   dof_handler_LS.distribute_dofs (fe_LS);
2761 *   locally_owned_dofs_LS = dof_handler_LS.locally_owned_dofs ();
2762 *   locally_relevant_dofs_LS = DoFTools::extract_locally_relevant_dofs (dof_handler_LS);
2763 * @endcode
2764 *
2765 * setup system U
2766 *
2767 * @code
2768 *   dof_handler_U.distribute_dofs (fe_U);
2769 *   locally_owned_dofs_U = dof_handler_U.locally_owned_dofs ();
2770 *   locally_relevant_dofs_U = DoFTools::extract_locally_relevant_dofs (dof_handler_U);
2771 * @endcode
2772 *
2773 * setup system P
2774 *
2775 * @code
2776 *   dof_handler_P.distribute_dofs (fe_P);
2777 *   locally_owned_dofs_P = dof_handler_P.locally_owned_dofs ();
2778 *   locally_relevant_dofs_P = DoFTools::extract_locally_relevant_dofs (dof_handler_P);
2779 * @endcode
2780 *
2781 * init vectors for phi
2782 *
2783 * @code
2784 *   locally_relevant_solution_phi.reinit(locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
2785 *   locally_relevant_solution_phi = 0;
2786 *   completely_distributed_solution_phi.reinit (locally_owned_dofs_P,mpi_communicator);
2787 * @endcode
2788 *
2789 * init vectors for u
2790 *
2791 * @code
2792 *   locally_relevant_solution_u.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
2793 *   locally_relevant_solution_u = 0;
2794 *   completely_distributed_solution_u.reinit (locally_owned_dofs_U,mpi_communicator);
2795 * @endcode
2796 *
2797 * init vectors for v
2798 *
2799 * @code
2800 *   locally_relevant_solution_v.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
2801 *   locally_relevant_solution_v = 0;
2802 *   completely_distributed_solution_v.reinit (locally_owned_dofs_U,mpi_communicator);
2803 * @endcode
2804 *
2805 * init vectors for p
2806 *
2807 * @code
2808 *   locally_relevant_solution_p.reinit (locally_owned_dofs_P,locally_relevant_dofs_P,mpi_communicator);
2809 *   locally_relevant_solution_p = 0;
2810 *   completely_distributed_solution_p.reinit (locally_owned_dofs_P,mpi_communicator);
2811 * @endcode
2812 *
2813 * INIT CONSTRAINTS
2814 *
2815 * @code
2816 *   init_constraints();
2817 *   }
2818 *  
2819 *   template <int dim>
2820 *   void MultiPhase<dim>::initial_condition()
2821 *   {
2822 *   time=0;
2823 * @endcode
2824 *
2825 * Initial conditions
2826 * init condition for phi
2827 *
2828 * @code
2829 *   completely_distributed_solution_phi = 0;
2830 *   VectorTools::interpolate(dof_handler_LS,
2831 *   InitialPhi<dim>(PROBLEM, sharpness),
2832 *   completely_distributed_solution_phi);
2833 *   constraints.distribute (completely_distributed_solution_phi);
2834 *   locally_relevant_solution_phi = completely_distributed_solution_phi;
2835 * @endcode
2836 *
2837 * init condition for u=0
2838 *
2839 * @code
2840 *   completely_distributed_solution_u = 0;
2841 *   VectorTools::interpolate(dof_handler_U,
2843 *   completely_distributed_solution_u);
2844 *   constraints.distribute (completely_distributed_solution_u);
2845 *   locally_relevant_solution_u = completely_distributed_solution_u;
2846 * @endcode
2847 *
2848 * init condition for v
2849 *
2850 * @code
2851 *   completely_distributed_solution_v = 0;
2852 *   VectorTools::interpolate(dof_handler_U,
2854 *   completely_distributed_solution_v);
2855 *   constraints.distribute (completely_distributed_solution_v);
2856 *   locally_relevant_solution_v = completely_distributed_solution_v;
2857 * @endcode
2858 *
2859 * init condition for p
2860 *
2861 * @code
2862 *   completely_distributed_solution_p = 0;
2863 *   VectorTools::interpolate(dof_handler_P,
2865 *   completely_distributed_solution_p);
2866 *   constraints.distribute (completely_distributed_solution_p);
2867 *   locally_relevant_solution_p = completely_distributed_solution_p;
2868 *   }
2869 *  
2870 *   template <int dim>
2871 *   void MultiPhase<dim>::init_constraints()
2872 *   {
2873 *   constraints.clear ();
2874 *   #if DEAL_II_VERSION_GTE(9, 6, 0)
2875 *   constraints.reinit (locally_owned_dofs_LS, locally_relevant_dofs_LS);
2876 *   #else
2877 *   constraints.reinit (locally_relevant_dofs_LS);
2878 *   #endif
2879 *   DoFTools::make_hanging_node_constraints (dof_handler_LS, constraints);
2880 *   constraints.close ();
2881 *   }
2882 *  
2883 *   template <int dim>
2884 *   void MultiPhase<dim>::get_boundary_values_U()
2885 *   {
2886 *   std::map<types::global_dof_index, double> map_boundary_values_u;
2887 *   std::map<types::global_dof_index, double> map_boundary_values_v;
2888 *   std::map<types::global_dof_index, double> map_boundary_values_w;
2889 *  
2890 * @endcode
2891 *
2892 * NO-SLIP CONDITION
2893 *
2894 * @code
2895 *   if (PROBLEM==BREAKING_DAM || PROBLEM==FALLING_DROP)
2896 *   {
2897 * @endcode
2898 *
2899 * LEFT
2900 *
2901 * @code
2902 *   VectorTools::interpolate_boundary_values (dof_handler_U,0,Functions::ZeroFunction<dim>(),map_boundary_values_u);
2903 *   VectorTools::interpolate_boundary_values (dof_handler_U,0,Functions::ZeroFunction<dim>(),map_boundary_values_v);
2904 * @endcode
2905 *
2906 * RIGHT
2907 *
2908 * @code
2909 *   VectorTools::interpolate_boundary_values (dof_handler_U,1,Functions::ZeroFunction<dim>(),map_boundary_values_u);
2910 *   VectorTools::interpolate_boundary_values (dof_handler_U,1,Functions::ZeroFunction<dim>(),map_boundary_values_v);
2911 * @endcode
2912 *
2913 * BOTTOM
2914 *
2915 * @code
2916 *   VectorTools::interpolate_boundary_values (dof_handler_U,2,Functions::ZeroFunction<dim>(),map_boundary_values_u);
2917 *   VectorTools::interpolate_boundary_values (dof_handler_U,2,Functions::ZeroFunction<dim>(),map_boundary_values_v);
2918 * @endcode
2919 *
2920 * TOP
2921 *
2922 * @code
2923 *   VectorTools::interpolate_boundary_values (dof_handler_U,3,Functions::ZeroFunction<dim>(),map_boundary_values_u);
2924 *   VectorTools::interpolate_boundary_values (dof_handler_U,3,Functions::ZeroFunction<dim>(),map_boundary_values_v);
2925 *   }
2926 *   else if (PROBLEM==SMALL_WAVE_PERTURBATION)
2927 *   {
2928 * @endcode
2929 *
2930 * no slip in bottom and top and slip in left and right
2931 * LEFT
2932 *
2933 * @code
2934 *   VectorTools::interpolate_boundary_values (dof_handler_U,0,Functions::ZeroFunction<dim>(),map_boundary_values_u);
2935 * @endcode
2936 *
2937 * RIGHT
2938 *
2939 * @code
2940 *   VectorTools::interpolate_boundary_values (dof_handler_U,1,Functions::ZeroFunction<dim>(),map_boundary_values_u);
2941 * @endcode
2942 *
2943 * BOTTOM
2944 *
2945 * @code
2946 *   VectorTools::interpolate_boundary_values (dof_handler_U,2,Functions::ZeroFunction<dim>(),map_boundary_values_u);
2947 *   VectorTools::interpolate_boundary_values (dof_handler_U,2,Functions::ZeroFunction<dim>(),map_boundary_values_v);
2948 * @endcode
2949 *
2950 * TOP
2951 *
2952 * @code
2953 *   VectorTools::interpolate_boundary_values (dof_handler_U,3,Functions::ZeroFunction<dim>(),map_boundary_values_u);
2954 *   VectorTools::interpolate_boundary_values (dof_handler_U,3,Functions::ZeroFunction<dim>(),map_boundary_values_v);
2955 *   }
2956 *   else if (PROBLEM==FILLING_TANK)
2957 *   {
2958 * @endcode
2959 *
2960 * LEFT: entry in x, zero in y
2961 *
2962 * @code
2963 *   VectorTools::interpolate_boundary_values (dof_handler_U,0,BoundaryU<dim>(PROBLEM),map_boundary_values_u);
2964 *   VectorTools::interpolate_boundary_values (dof_handler_U,0,Functions::ZeroFunction<dim>(),map_boundary_values_v);
2965 * @endcode
2966 *
2967 * RIGHT: no-slip condition
2968 *
2969 * @code
2970 *   VectorTools::interpolate_boundary_values (dof_handler_U,1,Functions::ZeroFunction<dim>(),map_boundary_values_u);
2971 *   VectorTools::interpolate_boundary_values (dof_handler_U,1,Functions::ZeroFunction<dim>(),map_boundary_values_v);
2972 * @endcode
2973 *
2974 * BOTTOM: non-slip
2975 *
2976 * @code
2977 *   VectorTools::interpolate_boundary_values (dof_handler_U,2,Functions::ZeroFunction<dim>(),map_boundary_values_u);
2978 *   VectorTools::interpolate_boundary_values (dof_handler_U,2,Functions::ZeroFunction<dim>(),map_boundary_values_v);
2979 * @endcode
2980 *
2981 * TOP: exit in y, zero in x
2982 *
2983 * @code
2984 *   VectorTools::interpolate_boundary_values (dof_handler_U,3,Functions::ZeroFunction<dim>(),map_boundary_values_u);
2985 *   VectorTools::interpolate_boundary_values (dof_handler_U,3,BoundaryV<dim>(PROBLEM),map_boundary_values_v);
2986 *   }
2987 *   else
2988 *   {
2989 *   pcout << "Error in type of PROBLEM at Boundary Conditions" << std::endl;
2990 *   abort();
2991 *   }
2992 *   boundary_values_id_u.resize(map_boundary_values_u.size());
2993 *   boundary_values_id_v.resize(map_boundary_values_v.size());
2994 *   boundary_values_u.resize(map_boundary_values_u.size());
2995 *   boundary_values_v.resize(map_boundary_values_v.size());
2996 *   std::map<types::global_dof_index,double>::const_iterator boundary_value_u =map_boundary_values_u.begin();
2997 *   std::map<types::global_dof_index,double>::const_iterator boundary_value_v =map_boundary_values_v.begin();
2998 *  
2999 *   for (int i=0; boundary_value_u !=map_boundary_values_u.end(); ++boundary_value_u, ++i)
3000 *   {
3001 *   boundary_values_id_u[i]=boundary_value_u->first;
3002 *   boundary_values_u[i]=boundary_value_u->second;
3003 *   }
3004 *   for (int i=0; boundary_value_v !=map_boundary_values_v.end(); ++boundary_value_v, ++i)
3005 *   {
3006 *   boundary_values_id_v[i]=boundary_value_v->first;
3007 *   boundary_values_v[i]=boundary_value_v->second;
3008 *   }
3009 *   }
3010 *  
3011 *   template <int dim>
3012 *   void MultiPhase<dim>::set_boundary_inlet()
3013 *   {
3014 *   const QGauss<dim-1> face_quadrature_formula(1); // center of the face
3015 *   FEFaceValues<dim> fe_face_values (fe_U,face_quadrature_formula,
3018 *   const unsigned int n_face_q_points = face_quadrature_formula.size();
3019 *   std::vector<double> u_value (n_face_q_points);
3020 *   std::vector<double> v_value (n_face_q_points);
3021 *  
3023 *   cell_U = dof_handler_U.begin_active(),
3024 *   endc_U = dof_handler_U.end();
3025 *   Tensor<1,dim> u;
3026 *  
3027 *   for (; cell_U!=endc_U; ++cell_U)
3028 *   if (cell_U->is_locally_owned())
3029 *   for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
3030 *   if (cell_U->face(face)->at_boundary())
3031 *   {
3032 *   fe_face_values.reinit(cell_U,face);
3033 *   fe_face_values.get_function_values(locally_relevant_solution_u,u_value);
3034 *   fe_face_values.get_function_values(locally_relevant_solution_v,v_value);
3035 *   u[0]=u_value[0];
3036 *   u[1]=v_value[0];
3037 *   if (fe_face_values.normal_vector(0)*u < -1e-14)
3038 *   cell_U->face(face)->set_boundary_id(10); // SET ID 10 to inlet BOUNDARY (10 is an arbitrary number)
3039 *   }
3040 *   }
3041 *  
3042 *   template <int dim>
3043 *   void MultiPhase<dim>::get_boundary_values_phi(std::vector<types::global_dof_index> &boundary_values_id_phi,
3044 *   std::vector<double> &boundary_values_phi)
3045 *   {
3046 *   std::map<types::global_dof_index, double> map_boundary_values_phi;
3047 *   unsigned int boundary_id=0;
3048 *  
3049 *   set_boundary_inlet();
3050 *   boundary_id=10; // inlet
3051 *   VectorTools::interpolate_boundary_values (dof_handler_LS,boundary_id,BoundaryPhi<dim>(1.0),map_boundary_values_phi);
3052 *   boundary_values_id_phi.resize(map_boundary_values_phi.size());
3053 *   boundary_values_phi.resize(map_boundary_values_phi.size());
3054 *   std::map<types::global_dof_index,double>::const_iterator boundary_value_phi = map_boundary_values_phi.begin();
3055 *   for (int i=0; boundary_value_phi !=map_boundary_values_phi.end(); ++boundary_value_phi, ++i)
3056 *   {
3057 *   boundary_values_id_phi[i]=boundary_value_phi->first;
3058 *   boundary_values_phi[i]=boundary_value_phi->second;
3059 *   }
3060 *   }
3061 *  
3062 *   template<int dim>
3063 *   void MultiPhase<dim>::output_results()
3064 *   {
3065 * @endcode
3066 *
3067 * output_vectors();
3068 *
3069 * @code
3070 *   output_rho();
3071 *   output_number++;
3072 *   }
3073 *  
3074 *   template <int dim>
3075 *   void MultiPhase<dim>::output_vectors()
3076 *   {
3077 *   DataOut<dim> data_out;
3078 *   data_out.attach_dof_handler (dof_handler_LS);
3079 *   data_out.add_data_vector (locally_relevant_solution_phi, "phi");
3080 *   data_out.build_patches ();
3081 *  
3082 *   const std::string filename = ("sol_vectors-" +
3083 *   Utilities::int_to_string (output_number, 3) +
3084 *   "." +
3086 *   (triangulation.locally_owned_subdomain(), 4));
3087 *   std::ofstream output ((filename + ".vtu").c_str());
3088 *   data_out.write_vtu (output);
3089 *  
3090 *   if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
3091 *   {
3092 *   std::vector<std::string> filenames;
3093 *   for (unsigned int i=0;
3094 *   i<Utilities::MPI::n_mpi_processes(mpi_communicator);
3095 *   ++i)
3096 *   filenames.push_back ("sol_vectors-" +
3097 *   Utilities::int_to_string (output_number, 3) +
3098 *   "." +
3099 *   Utilities::int_to_string (i, 4) +
3100 *   ".vtu");
3101 *  
3102 *   std::ofstream master_output ((filename + ".pvtu").c_str());
3103 *   data_out.write_pvtu_record (master_output, filenames);
3104 *   }
3105 *   }
3106 *  
3107 *   template <int dim>
3108 *   void MultiPhase<dim>::output_rho()
3109 *   {
3110 *   Postprocessor<dim> postprocessor(eps,rho_air,rho_fluid);
3111 *   DataOut<dim> data_out;
3112 *   data_out.attach_dof_handler (dof_handler_LS);
3113 *   data_out.add_data_vector (locally_relevant_solution_phi, postprocessor);
3114 *  
3115 *   data_out.build_patches ();
3116 *  
3117 *   const std::string filename = ("sol_rho-" +
3118 *   Utilities::int_to_string (output_number, 3) +
3119 *   "." +
3121 *   (triangulation.locally_owned_subdomain(), 4));
3122 *   std::ofstream output ((filename + ".vtu").c_str());
3123 *   data_out.write_vtu (output);
3124 *  
3125 *   if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
3126 *   {
3127 *   std::vector<std::string> filenames;
3128 *   for (unsigned int i=0;
3129 *   i<Utilities::MPI::n_mpi_processes(mpi_communicator);
3130 *   ++i)
3131 *   filenames.push_back ("sol_rho-" +
3132 *   Utilities::int_to_string (output_number, 3) +
3133 *   "." +
3134 *   Utilities::int_to_string (i, 4) +
3135 *   ".vtu");
3136 *  
3137 *   std::ofstream master_output ((filename + ".pvtu").c_str());
3138 *   data_out.write_pvtu_record (master_output, filenames);
3139 *   }
3140 *   }
3141 *  
3142 *   template <int dim>
3143 *   void MultiPhase<dim>::run()
3144 *   {
3145 * @endcode
3146 *
3147 *
3148 * GENERAL PARAMETERS
3149 *
3150 *
3151 * @code
3152 *   umax=1;
3153 *   cfl=0.1;
3154 *   verbose = true;
3155 *   get_output = true;
3156 *   output_number = 0;
3157 *   n_refinement=8;
3158 *   output_time = 0.1;
3159 *   final_time = 10.0;
3160 * @endcode
3161 *
3162 *
3163 * PARAMETERS FOR THE NAVIER STOKES PROBLEM
3164 *
3165 *
3166 * @code
3167 *   rho_fluid = 1000.;
3168 *   nu_fluid = 1.0;
3169 *   rho_air = 1.0;
3170 *   nu_air = 1.8e-2;
3171 *   PROBLEM=BREAKING_DAM;
3172 * @endcode
3173 *
3174 * PROBLEM=FILLING_TANK;
3175 * PROBLEM=SMALL_WAVE_PERTURBATION;
3176 * PROBLEM=FALLING_DROP;
3177 *
3178
3179 *
3180 *
3181 * @code
3182 *   ForceTerms<dim> force_function(std::vector<double> {0.0,-1.0});
3183 * @endcode
3184 *
3185 *
3186 * PARAMETERS FOR TRANSPORT PROBLEM
3187 *
3188 *
3189 * @code
3190 *   cK = 1.0;
3191 *   cE = 1.0;
3192 *   sharpness_integer=10; //this will be multiplied by min_h
3193 * @endcode
3194 *
3195 * TRANSPORT_TIME_INTEGRATION=FORWARD_EULER;
3196 *
3197 * @code
3198 *   TRANSPORT_TIME_INTEGRATION=SSP33;
3199 * @endcode
3200 *
3201 * ALGORITHM = "MPP_u1";
3202 * ALGORITHM = "NMPP_uH";
3203 *
3204 * @code
3205 *   ALGORITHM = "MPP_uH";
3206 *  
3207 * @endcode
3208 *
3209 * ADJUST PARAMETERS ACCORDING TO PROBLEM
3210 *
3211 * @code
3212 *   if (PROBLEM==FALLING_DROP)
3213 *   n_refinement=7;
3214 *  
3215 * @endcode
3216 *
3217 *
3218 * GEOMETRY
3219 *
3220 *
3221 * @code
3222 *   if (PROBLEM==FILLING_TANK)
3223 *   GridGenerator::hyper_rectangle(triangulation,
3224 *   Point<dim>(0.0,0.0), Point<dim>(0.4,0.4), true);
3225 *   else if (PROBLEM==BREAKING_DAM || PROBLEM==SMALL_WAVE_PERTURBATION)
3226 *   {
3227 *   std::vector< unsigned int > repetitions;
3228 *   repetitions.push_back(2);
3229 *   repetitions.push_back(1);
3231 *   (triangulation, repetitions, Point<dim>(0.0,0.0), Point<dim>(1.0,0.5), true);
3232 *   }
3233 *   else if (PROBLEM==FALLING_DROP)
3234 *   {
3235 *   std::vector< unsigned int > repetitions;
3236 *   repetitions.push_back(1);
3237 *   repetitions.push_back(4);
3239 *   (triangulation, repetitions, Point<dim>(0.0,0.0), Point<dim>(0.3,0.9), true);
3240 *   }
3241 *   triangulation.refine_global (n_refinement);
3242 * @endcode
3243 *
3244 * SETUP
3245 *
3246 * @code
3247 *   setup();
3248 *  
3249 * @endcode
3250 *
3251 * PARAMETERS FOR TIME STEPPING
3252 *
3253 * @code
3254 *   min_h = GridTools::minimal_cell_diameter(triangulation)/std::sqrt(2);
3255 *   time_step = cfl*min_h/umax;
3256 *   eps=1.*min_h; //For reconstruction of density in Navier Stokes
3257 *   sharpness=sharpness_integer*min_h; //adjust value of sharpness (for init cond of phi)
3258 *  
3259 * @endcode
3260 *
3261 * INITIAL CONDITIONS
3262 *
3263 * @code
3264 *   initial_condition();
3265 *   output_results();
3266 *  
3267 * @endcode
3268 *
3269 * NAVIER STOKES SOLVER
3270 *
3271 * @code
3272 *   NavierStokesSolver<dim> navier_stokes (degree_LS,degree_U,
3273 *   time_step,eps,
3274 *   rho_air,nu_air,
3275 *   rho_fluid,nu_fluid,
3276 *   force_function,
3277 *   verbose,
3278 *   triangulation,mpi_communicator);
3279 * @endcode
3280 *
3281 * BOUNDARY CONDITIONS FOR NAVIER STOKES
3282 *
3283 * @code
3284 *   get_boundary_values_U();
3285 *   navier_stokes.set_boundary_conditions(boundary_values_id_u, boundary_values_id_v,
3286 *   boundary_values_u, boundary_values_v);
3287 *  
3288 * @endcode
3289 *
3290 * set INITIAL CONDITION within NAVIER STOKES
3291 *
3292 * @code
3293 *   navier_stokes.initial_condition(locally_relevant_solution_phi,
3294 *   locally_relevant_solution_u,
3295 *   locally_relevant_solution_v,
3296 *   locally_relevant_solution_p);
3297 * @endcode
3298 *
3299 * TRANSPORT SOLVER
3300 *
3301 * @code
3302 *   LevelSetSolver<dim> transport_solver (degree_LS,degree_U,
3303 *   time_step,cK,cE,
3304 *   verbose,
3305 *   ALGORITHM,
3306 *   TRANSPORT_TIME_INTEGRATION,
3307 *   triangulation,
3308 *   mpi_communicator);
3309 * @endcode
3310 *
3311 * BOUNDARY CONDITIONS FOR PHI
3312 *
3313 * @code
3314 *   get_boundary_values_phi(boundary_values_id_phi,boundary_values_phi);
3315 *   transport_solver.set_boundary_conditions(boundary_values_id_phi,boundary_values_phi);
3316 *  
3317 * @endcode
3318 *
3319 * set INITIAL CONDITION within TRANSPORT PROBLEM
3320 *
3321 * @code
3322 *   transport_solver.initial_condition(locally_relevant_solution_phi,
3323 *   locally_relevant_solution_u,
3324 *   locally_relevant_solution_v);
3325 *   int dofs_U = 2*dof_handler_U.n_dofs();
3326 *   int dofs_P = 2*dof_handler_P.n_dofs();
3327 *   int dofs_LS = dof_handler_LS.n_dofs();
3328 *   int dofs_TOTAL = dofs_U+dofs_P+dofs_LS;
3329 *  
3330 * @endcode
3331 *
3332 * NO BOUNDARY CONDITIONS for LEVEL SET
3333 *
3334 * @code
3335 *   pcout << "Cfl: " << cfl << "; umax: " << umax << "; min h: " << min_h
3336 *   << "; time step: " << time_step << std::endl;
3337 *   pcout << " Number of active cells: "
3338 *   << triangulation.n_global_active_cells() << std::endl
3339 *   << " Number of degrees of freedom: " << std::endl
3340 *   << " U: " << dofs_U << std::endl
3341 *   << " P: " << dofs_P << std::endl
3342 *   << " LS: " << dofs_LS << std::endl
3343 *   << " TOTAL: " << dofs_TOTAL
3344 *   << std::endl;
3345 *  
3346 * @endcode
3347 *
3348 * TIME STEPPING
3349 *
3350 * @code
3351 *   for (timestep_number=1, time=time_step; time<=final_time;
3352 *   time+=time_step,++timestep_number)
3353 *   {
3354 *   pcout << "Time step " << timestep_number
3355 *   << " at t=" << time
3356 *   << std::endl;
3357 * @endcode
3358 *
3359 * GET NAVIER STOKES VELOCITY
3360 *
3361 * @code
3362 *   navier_stokes.set_phi(locally_relevant_solution_phi);
3363 *   navier_stokes.nth_time_step();
3364 *   navier_stokes.get_velocity(locally_relevant_solution_u,locally_relevant_solution_v);
3365 *   transport_solver.set_velocity(locally_relevant_solution_u,locally_relevant_solution_v);
3366 * @endcode
3367 *
3368 * GET LEVEL SET SOLUTION
3369 *
3370 * @code
3371 *   transport_solver.nth_time_step();
3372 *   transport_solver.get_unp1(locally_relevant_solution_phi);
3373 *   if (get_output && time-(output_number)*output_time>0)
3374 *   output_results();
3375 *   }
3376 *   navier_stokes.get_velocity(locally_relevant_solution_u, locally_relevant_solution_v);
3377 *   transport_solver.get_unp1(locally_relevant_solution_phi);
3378 *   if (get_output)
3379 *   output_results();
3380 *   }
3381 *  
3382 *   int main(int argc, char *argv[])
3383 *   {
3384 *   try
3385 *   {
3386 *   using namespace dealii;
3387 *   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
3388 *   deallog.depth_console (0);
3389 *   {
3390 *   unsigned int degree_LS = 1;
3391 *   unsigned int degree_U = 2;
3392 *   MultiPhase<2> multi_phase(degree_LS, degree_U);
3393 *   multi_phase.run();
3394 *   }
3395 *   }
3396 *  
3397 *   catch (std::exception &exc)
3398 *   {
3399 *   std::cerr << std::endl << std::endl
3400 *   << "----------------------------------------------------"
3401 *   << std::endl;
3402 *   std::cerr << "Exception on processing: " << std::endl
3403 *   << exc.what() << std::endl
3404 *   << "Aborting!" << std::endl
3405 *   << "----------------------------------------------------"
3406 *   << std::endl;
3407 *   return 1;
3408 *   }
3409 *   catch (...)
3410 *   {
3411 *   std::cerr << std::endl << std::endl
3412 *   << "----------------------------------------------------"
3413 *   << std::endl;
3414 *   std::cerr << "Unknown exception!" << std::endl
3415 *   << "Aborting!" << std::endl
3416 *   << "----------------------------------------------------"
3417 *   << std::endl;
3418 *   return 1;
3419 *   }
3420 *   return 0;
3421 *   }
3422 * @endcode
3423
3424
3425<a name="ann-NavierStokesSolver.cc"></a>
3426<h1>Annotated version of NavierStokesSolver.cc</h1>
3427 *
3428 *
3429 *
3430 *
3431 * @code
3432 *   /* -----------------------------------------------------------------------------
3433 *   *
3434 *   * SPDX-License-Identifier: LGPL-2.1-or-later
3435 *   * Copyright (C) 2016 Manuel Quezada de Luna
3436 *   *
3437 *   * This file is part of the deal.II code gallery.
3438 *   *
3439 *   * -----------------------------------------------------------------------------
3440 *   */
3441 *  
3442 *   #include <deal.II/base/quadrature_lib.h>
3443 *   #include <deal.II/base/function.h>
3444 *   #include <deal.II/lac/affine_constraints.h>
3445 *   #include <deal.II/lac/vector.h>
3446 *   #include <deal.II/lac/full_matrix.h>
3447 *   #include <deal.II/lac/solver_cg.h>
3448 *   #include <deal.II/lac/petsc_sparse_matrix.h>
3449 *   #include <deal.II/lac/petsc_vector.h>
3450 *   #include <deal.II/lac/petsc_solver.h>
3451 *   #include <deal.II/lac/petsc_precondition.h>
3452 *   #include <deal.II/grid/grid_generator.h>
3453 *   #include <deal.II/grid/tria_accessor.h>
3454 *   #include <deal.II/grid/tria_iterator.h>
3455 *   #include <deal.II/dofs/dof_handler.h>
3456 *   #include <deal.II/dofs/dof_accessor.h>
3457 *   #include <deal.II/dofs/dof_tools.h>
3458 *   #include <deal.II/fe/fe_values.h>
3459 *   #include <deal.II/fe/fe_q.h>
3460 *   #include <deal.II/numerics/vector_tools.h>
3461 *   #include <deal.II/numerics/data_out.h>
3462 *   #include <deal.II/numerics/error_estimator.h>
3463 *   #include <deal.II/base/utilities.h>
3464 *   #include <deal.II/base/conditional_ostream.h>
3465 *   #include <deal.II/base/index_set.h>
3466 *   #include <deal.II/lac/sparsity_tools.h>
3467 *   #include <deal.II/distributed/tria.h>
3468 *   #include <deal.II/distributed/grid_refinement.h>
3469 *   #include <deal.II/lac/petsc_vector.h>
3470 *   #include <deal.II/base/convergence_table.h>
3471 *   #include <deal.II/base/timer.h>
3472 *   #include <deal.II/base/parameter_handler.h>
3473 *   #include <deal.II/grid/grid_tools.h>
3474 *   #include <deal.II/fe/mapping_q.h>
3475 *  
3476 *   #include <fstream>
3477 *   #include <iostream>
3478 *   #include <memory>
3479 *  
3480 *   using namespace dealii;
3481 *  
3482 *   #define MAX_NUM_ITER_TO_RECOMPUTE_PRECONDITIONER 10
3483 *  
3484 * @endcode
3485 *
3486 *
3487 *
3488 *
3489 *
3490 * @code
3491 *   template<int dim>
3492 *   class NavierStokesSolver
3493 *   {
3494 *   public:
3495 * @endcode
3496 *
3497 * constructor for using LEVEL SET
3498 *
3499 * @code
3500 *   NavierStokesSolver(const unsigned int degree_LS,
3501 *   const unsigned int degree_U,
3502 *   const double time_step,
3503 *   const double eps,
3504 *   const double rho_air,
3505 *   const double nu_air,
3506 *   const double rho_fluid,
3507 *   const double nu_fluid,
3508 *   Function<dim> &force_function,
3509 *   const bool verbose,
3511 *   MPI_Comm &mpi_communicator);
3512 * @endcode
3513 *
3514 * constructor for NOT LEVEL SET
3515 *
3516 * @code
3517 *   NavierStokesSolver(const unsigned int degree_LS,
3518 *   const unsigned int degree_U,
3519 *   const double time_step,
3520 *   Function<dim> &force_function,
3521 *   Function<dim> &rho_function,
3522 *   Function<dim> &nu_function,
3523 *   const bool verbose,
3525 *   MPI_Comm &mpi_communicator);
3526 *  
3527 * @endcode
3528 *
3529 * rho and nu functions
3530 *
3531 * @code
3532 *   void set_rho_and_nu_functions(const Function<dim> &rho_function,
3533 *   const Function<dim> &nu_function);
3534 * @endcode
3535 *
3536 * initial conditions
3537 *
3538 * @code
3539 *   void initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_rho,
3540 *   PETScWrappers::MPI::Vector locally_relevant_solution_u,
3541 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3542 *   PETScWrappers::MPI::Vector locally_relevant_solution_p);
3543 *   void initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_rho,
3544 *   PETScWrappers::MPI::Vector locally_relevant_solution_u,
3545 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3546 *   PETScWrappers::MPI::Vector locally_relevant_solution_w,
3547 *   PETScWrappers::MPI::Vector locally_relevant_solution_p);
3548 * @endcode
3549 *
3550 * boundary conditions
3551 *
3552 * @code
3553 *   void set_boundary_conditions(std::vector<types::global_dof_index> boundary_values_id_u,
3554 *   std::vector<types::global_dof_index> boundary_values_id_v, std::vector<double> boundary_values_u,
3555 *   std::vector<double> boundary_values_v);
3556 *   void set_boundary_conditions(std::vector<types::global_dof_index> boundary_values_id_u,
3557 *   std::vector<types::global_dof_index> boundary_values_id_v,
3558 *   std::vector<types::global_dof_index> boundary_values_id_w, std::vector<double> boundary_values_u,
3559 *   std::vector<double> boundary_values_v, std::vector<double> boundary_values_w);
3560 *   void set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_u,
3561 *   PETScWrappers::MPI::Vector locally_relevant_solution_v);
3562 *   void set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_u,
3563 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3564 *   PETScWrappers::MPI::Vector locally_relevant_solution_w);
3565 *   void set_phi(PETScWrappers::MPI::Vector locally_relevant_solution_phi);
3566 *   void get_pressure(PETScWrappers::MPI::Vector &locally_relevant_solution_p);
3567 *   void get_velocity(PETScWrappers::MPI::Vector &locally_relevant_solution_u,
3568 *   PETScWrappers::MPI::Vector &locally_relevant_solution_v);
3569 *   void get_velocity(PETScWrappers::MPI::Vector &locally_relevant_solution_u,
3570 *   PETScWrappers::MPI::Vector &locally_relevant_solution_v,
3571 *   PETScWrappers::MPI::Vector &locally_relevant_solution_w);
3572 * @endcode
3573 *
3574 * DO STEPS
3575 *
3576 * @code
3577 *   void nth_time_step();
3578 * @endcode
3579 *
3580 * SETUP
3581 *
3582 * @code
3583 *   void setup();
3584 *  
3585 *   ~NavierStokesSolver();
3586 *  
3587 *   private:
3588 * @endcode
3589 *
3590 * SETUP AND INITIAL CONDITION
3591 *
3592 * @code
3593 *   void setup_DOF();
3594 *   void setup_VECTORS();
3595 *   void init_constraints();
3596 * @endcode
3597 *
3598 * ASSEMBLE SYSTEMS
3599 *
3600 * @code
3601 *   void assemble_system_U();
3602 *   void assemble_system_dpsi_q();
3603 * @endcode
3604 *
3605 * SOLVERS
3606 *
3607 * @code
3608 *   void solve_U(const AffineConstraints<double> &constraints, PETScWrappers::MPI::SparseMatrix &Matrix,
3609 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner,
3610 *   PETScWrappers::MPI::Vector &completely_distributed_solution,
3611 *   const PETScWrappers::MPI::Vector &rhs);
3612 *   void solve_P(const AffineConstraints<double> &constraints, PETScWrappers::MPI::SparseMatrix &Matrix,
3613 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner,
3614 *   PETScWrappers::MPI::Vector &completely_distributed_solution,
3615 *   const PETScWrappers::MPI::Vector &rhs);
3616 * @endcode
3617 *
3618 * GET DIFFERENT FIELDS
3619 *
3620 * @code
3621 *   void get_rho_and_nu(double phi);
3622 *   void get_velocity();
3623 *   void get_pressure();
3624 * @endcode
3625 *
3626 * OTHERS
3627 *
3628 * @code
3629 *   void save_old_solution();
3630 *  
3631 *   MPI_Comm &mpi_communicator;
3633 *  
3634 *   int degree_LS;
3635 *   DoFHandler<dim> dof_handler_LS;
3636 *   FE_Q<dim> fe_LS;
3637 *   IndexSet locally_owned_dofs_LS;
3638 *   IndexSet locally_relevant_dofs_LS;
3639 *  
3640 *   int degree_U;
3641 *   DoFHandler<dim> dof_handler_U;
3642 *   FE_Q<dim> fe_U;
3643 *   IndexSet locally_owned_dofs_U;
3644 *   IndexSet locally_relevant_dofs_U;
3645 *  
3646 *   DoFHandler<dim> dof_handler_P;
3647 *   FE_Q<dim> fe_P;
3648 *   IndexSet locally_owned_dofs_P;
3649 *   IndexSet locally_relevant_dofs_P;
3650 *  
3651 *   Function<dim> &force_function;
3652 *   Function<dim> &rho_function;
3653 *   Function<dim> &nu_function;
3654 *  
3655 *   double rho_air;
3656 *   double nu_air;
3657 *   double rho_fluid;
3658 *   double nu_fluid;
3659 *  
3660 *   double time_step;
3661 *   double eps;
3662 *  
3663 *   bool verbose;
3664 *   unsigned int LEVEL_SET;
3665 *   unsigned int RHO_TIMES_RHS;
3666 *  
3667 *   ConditionalOStream pcout;
3668 *  
3669 *   double rho_min;
3670 *   double rho_value;
3671 *   double nu_value;
3672 *  
3673 *   double h;
3674 *   double umax;
3675 *  
3676 *   int degree_MAX;
3677 *  
3678 *   AffineConstraints<double> constraints;
3679 *   AffineConstraints<double> constraints_psi;
3680 *  
3681 *   std::vector<types::global_dof_index> boundary_values_id_u;
3682 *   std::vector<types::global_dof_index> boundary_values_id_v;
3683 *   std::vector<types::global_dof_index> boundary_values_id_w;
3684 *   std::vector<double> boundary_values_u;
3685 *   std::vector<double> boundary_values_v;
3686 *   std::vector<double> boundary_values_w;
3687 *  
3688 *   PETScWrappers::MPI::SparseMatrix system_Matrix_u;
3689 *   PETScWrappers::MPI::SparseMatrix system_Matrix_v;
3690 *   PETScWrappers::MPI::SparseMatrix system_Matrix_w;
3691 *   bool rebuild_Matrix_U;
3692 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_Matrix_u;
3693 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_Matrix_v;
3694 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_Matrix_w;
3696 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_S;
3698 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_M;
3699 *   bool rebuild_S_M;
3700 *   bool rebuild_Matrix_U_preconditioners;
3701 *   bool rebuild_S_M_preconditioners;
3702 *   PETScWrappers::MPI::Vector system_rhs_u;
3703 *   PETScWrappers::MPI::Vector system_rhs_v;
3704 *   PETScWrappers::MPI::Vector system_rhs_w;
3705 *   PETScWrappers::MPI::Vector system_rhs_psi;
3706 *   PETScWrappers::MPI::Vector system_rhs_q;
3707 *   PETScWrappers::MPI::Vector locally_relevant_solution_phi;
3708 *   PETScWrappers::MPI::Vector locally_relevant_solution_u;
3709 *   PETScWrappers::MPI::Vector locally_relevant_solution_v;
3710 *   PETScWrappers::MPI::Vector locally_relevant_solution_w;
3711 *   PETScWrappers::MPI::Vector locally_relevant_solution_u_old;
3712 *   PETScWrappers::MPI::Vector locally_relevant_solution_v_old;
3713 *   PETScWrappers::MPI::Vector locally_relevant_solution_w_old;
3714 *  
3715 *   PETScWrappers::MPI::Vector locally_relevant_solution_psi;
3716 *   PETScWrappers::MPI::Vector locally_relevant_solution_psi_old;
3717 *   PETScWrappers::MPI::Vector locally_relevant_solution_p;
3718 *  
3719 *   PETScWrappers::MPI::Vector completely_distributed_solution_u;
3720 *   PETScWrappers::MPI::Vector completely_distributed_solution_v;
3721 *   PETScWrappers::MPI::Vector completely_distributed_solution_w;
3722 *   PETScWrappers::MPI::Vector completely_distributed_solution_psi;
3723 *   PETScWrappers::MPI::Vector completely_distributed_solution_q;
3724 *   PETScWrappers::MPI::Vector completely_distributed_solution_p;
3725 *   };
3726 *  
3727 * @endcode
3728 *
3729 * CONSTRUCTOR FOR LEVEL SET
3730 *
3731 * @code
3732 *   template<int dim>
3733 *   NavierStokesSolver<dim>::NavierStokesSolver(const unsigned int degree_LS,
3734 *   const unsigned int degree_U,
3735 *   const double time_step,
3736 *   const double eps,
3737 *   const double rho_air,
3738 *   const double nu_air,
3739 *   const double rho_fluid,
3740 *   const double nu_fluid,
3741 *   Function<dim> &force_function,
3742 *   const bool verbose,
3744 *   MPI_Comm &mpi_communicator)
3745 *   :
3746 *   mpi_communicator(mpi_communicator),
3747 *   triangulation(triangulation),
3748 *   degree_LS(degree_LS),
3749 *   dof_handler_LS(triangulation),
3750 *   fe_LS(degree_LS),
3751 *   degree_U(degree_U),
3752 *   dof_handler_U(triangulation),
3753 *   fe_U(degree_U),
3754 *   dof_handler_P(triangulation),
3755 *   fe_P(degree_U-1),
3756 *   force_function(force_function),
3757 * @endcode
3758 *
3759 * This is dummy since rho and nu functions won't be used
3760 *
3761 * @code
3762 *   rho_function(force_function),
3763 *   nu_function(force_function),
3764 *   rho_air(rho_air),
3765 *   nu_air(nu_air),
3766 *   rho_fluid(rho_fluid),
3767 *   nu_fluid(nu_fluid),
3768 *   time_step(time_step),
3769 *   eps(eps),
3770 *   verbose(verbose),
3771 *   LEVEL_SET(1),
3772 *   RHO_TIMES_RHS(1),
3773 *   pcout(std::cout,(Utilities::MPI::this_mpi_process(mpi_communicator)==0)),
3774 *   rebuild_Matrix_U(true),
3775 *   rebuild_S_M(true),
3776 *   rebuild_Matrix_U_preconditioners(true),
3777 *   rebuild_S_M_preconditioners(true)
3778 *   {setup();}
3779 *  
3780 * @endcode
3781 *
3782 * CONSTRUCTOR NOT FOR LEVEL SET
3783 *
3784 * @code
3785 *   template<int dim>
3786 *   NavierStokesSolver<dim>::NavierStokesSolver(const unsigned int degree_LS,
3787 *   const unsigned int degree_U,
3788 *   const double time_step,
3789 *   Function<dim> &force_function,
3790 *   Function<dim> &rho_function,
3791 *   Function<dim> &nu_function,
3792 *   const bool verbose,
3793 *   parallel::distributed::Triangulation<dim> &triangulation,
3794 *   MPI_Comm &mpi_communicator) :
3795 *   mpi_communicator(mpi_communicator),
3796 *   triangulation(triangulation),
3797 *   degree_LS(degree_LS),
3798 *   dof_handler_LS(triangulation),
3799 *   fe_LS(degree_LS),
3800 *   degree_U(degree_U),
3801 *   dof_handler_U(triangulation),
3802 *   fe_U(degree_U),
3803 *   dof_handler_P(triangulation),
3804 *   fe_P(degree_U-1),
3805 *   force_function(force_function),
3806 *   rho_function(rho_function),
3807 *   nu_function(nu_function),
3808 *   time_step(time_step),
3809 *   verbose(verbose),
3810 *   LEVEL_SET(0),
3811 *   RHO_TIMES_RHS(0),
3812 *   pcout(std::cout,(Utilities::MPI::this_mpi_process(mpi_communicator)==0)),
3813 *   rebuild_Matrix_U(true),
3814 *   rebuild_S_M(true),
3815 *   rebuild_Matrix_U_preconditioners(true),
3816 *   rebuild_S_M_preconditioners(true)
3817 *   {setup();}
3818 *  
3819 *   template<int dim>
3820 *   NavierStokesSolver<dim>::~NavierStokesSolver()
3821 *   {
3822 *   dof_handler_LS.clear();
3823 *   dof_handler_U.clear();
3824 *   dof_handler_P.clear();
3825 *   }
3826 *  
3827 * @endcode
3828 *
3829 * /////////////////////////////////////////////////////////
3830 * ////////////////// SETTERS AND GETTERS //////////////////
3831 * /////////////////////////////////////////////////////////
3832 *
3833 * @code
3834 *   template<int dim>
3835 *   void NavierStokesSolver<dim>::set_rho_and_nu_functions(const Function<dim> &rho_function,
3836 *   const Function<dim> &nu_function)
3837 *   {
3838 *   this->rho_function=rho_function;
3839 *   this->nu_function=nu_function;
3840 *   }
3841 *  
3842 *   template<int dim>
3843 *   void NavierStokesSolver<dim>::initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_phi,
3844 *   PETScWrappers::MPI::Vector locally_relevant_solution_u,
3845 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3846 *   PETScWrappers::MPI::Vector locally_relevant_solution_p)
3847 *   {
3848 *   this->locally_relevant_solution_phi=locally_relevant_solution_phi;
3849 *   this->locally_relevant_solution_u=locally_relevant_solution_u;
3850 *   this->locally_relevant_solution_v=locally_relevant_solution_v;
3851 *   this->locally_relevant_solution_p=locally_relevant_solution_p;
3852 * @endcode
3853 *
3854 * set old vectors to the initial condition (just for first time step)
3855 *
3856 * @code
3857 *   save_old_solution();
3858 *   }
3859 *  
3860 *   template<int dim>
3861 *   void NavierStokesSolver<dim>::initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_phi,
3862 *   PETScWrappers::MPI::Vector locally_relevant_solution_u,
3863 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3864 *   PETScWrappers::MPI::Vector locally_relevant_solution_w,
3865 *   PETScWrappers::MPI::Vector locally_relevant_solution_p)
3866 *   {
3867 *   this->locally_relevant_solution_phi=locally_relevant_solution_phi;
3868 *   this->locally_relevant_solution_u=locally_relevant_solution_u;
3869 *   this->locally_relevant_solution_v=locally_relevant_solution_v;
3870 *   this->locally_relevant_solution_w=locally_relevant_solution_w;
3871 *   this->locally_relevant_solution_p=locally_relevant_solution_p;
3872 * @endcode
3873 *
3874 * set old vectors to the initial condition (just for first time step)
3875 *
3876 * @code
3877 *   save_old_solution();
3878 *   }
3879 *  
3880 *   template<int dim>
3881 *   void NavierStokesSolver<dim>::set_boundary_conditions(std::vector<types::global_dof_index> boundary_values_id_u,
3882 *   std::vector<types::global_dof_index> boundary_values_id_v,
3883 *   std::vector<double> boundary_values_u,
3884 *   std::vector<double> boundary_values_v)
3885 *   {
3886 *   this->boundary_values_id_u=boundary_values_id_u;
3887 *   this->boundary_values_id_v=boundary_values_id_v;
3888 *   this->boundary_values_u=boundary_values_u;
3889 *   this->boundary_values_v=boundary_values_v;
3890 *   }
3891 *  
3892 *   template<int dim>
3893 *   void NavierStokesSolver<dim>::set_boundary_conditions(std::vector<types::global_dof_index> boundary_values_id_u,
3894 *   std::vector<types::global_dof_index> boundary_values_id_v,
3895 *   std::vector<types::global_dof_index> boundary_values_id_w,
3896 *   std::vector<double> boundary_values_u,
3897 *   std::vector<double> boundary_values_v,
3898 *   std::vector<double> boundary_values_w)
3899 *   {
3900 *   this->boundary_values_id_u=boundary_values_id_u;
3901 *   this->boundary_values_id_v=boundary_values_id_v;
3902 *   this->boundary_values_id_w=boundary_values_id_w;
3903 *   this->boundary_values_u=boundary_values_u;
3904 *   this->boundary_values_v=boundary_values_v;
3905 *   this->boundary_values_w=boundary_values_w;
3906 *   }
3907 *  
3908 *   template<int dim>
3909 *   void NavierStokesSolver<dim>::set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_u,
3910 *   PETScWrappers::MPI::Vector locally_relevant_solution_v)
3911 *   {
3912 *   this->locally_relevant_solution_u=locally_relevant_solution_u;
3913 *   this->locally_relevant_solution_v=locally_relevant_solution_v;
3914 *   }
3915 *  
3916 *   template<int dim>
3917 *   void NavierStokesSolver<dim>::set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_u,
3918 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3919 *   PETScWrappers::MPI::Vector locally_relevant_solution_w)
3920 *   {
3921 *   this->locally_relevant_solution_u=locally_relevant_solution_u;
3922 *   this->locally_relevant_solution_v=locally_relevant_solution_v;
3923 *   this->locally_relevant_solution_w=locally_relevant_solution_w;
3924 *   }
3925 *  
3926 *   template<int dim>
3927 *   void NavierStokesSolver<dim>::set_phi(PETScWrappers::MPI::Vector locally_relevant_solution_phi)
3928 *   {
3929 *   this->locally_relevant_solution_phi=locally_relevant_solution_phi;
3930 *   }
3931 *  
3932 *   template<int dim>
3933 *   void NavierStokesSolver<dim>::get_rho_and_nu(double phi)
3934 *   {
3935 *   double H=0;
3936 * @endcode
3937 *
3938 * get rho, nu
3939 *
3940 * @code
3941 *   if (phi>eps)
3942 *   H=1;
3943 *   else if (phi<-eps)
3944 *   H=-1;
3945 *   else
3946 *   H=phi/eps;
3947 *   rho_value=rho_fluid*(1+H)/2.+rho_air*(1-H)/2.;
3948 *   nu_value=nu_fluid*(1+H)/2.+nu_air*(1-H)/2.;
3949 * @endcode
3950 *
3951 * rho_value=rho_fluid*(1+phi)/2.+rho_air*(1-phi)/2.;
3952 * nu_value=nu_fluid*(1+phi)/2.+nu_air*(1-phi)/2.;
3953 *
3954 * @code
3955 *   }
3956 *  
3957 *   template<int dim>
3958 *   void NavierStokesSolver<dim>::get_pressure(PETScWrappers::MPI::Vector &locally_relevant_solution_p)
3959 *   {
3960 *   locally_relevant_solution_p=this->locally_relevant_solution_p;
3961 *   }
3962 *  
3963 *   template<int dim>
3964 *   void NavierStokesSolver<dim>::get_velocity(PETScWrappers::MPI::Vector &locally_relevant_solution_u,
3965 *   PETScWrappers::MPI::Vector &locally_relevant_solution_v)
3966 *   {
3967 *   locally_relevant_solution_u=this->locally_relevant_solution_u;
3968 *   locally_relevant_solution_v=this->locally_relevant_solution_v;
3969 *   }
3970 *  
3971 *   template<int dim>
3972 *   void NavierStokesSolver<dim>::get_velocity(PETScWrappers::MPI::Vector &locally_relevant_solution_u,
3973 *   PETScWrappers::MPI::Vector &locally_relevant_solution_v,
3974 *   PETScWrappers::MPI::Vector &locally_relevant_solution_w)
3975 *   {
3976 *   locally_relevant_solution_u=this->locally_relevant_solution_u;
3977 *   locally_relevant_solution_v=this->locally_relevant_solution_v;
3978 *   locally_relevant_solution_w=this->locally_relevant_solution_w;
3979 *   }
3980 *  
3981 * @endcode
3982 *
3983 * ///////////////////////////////////////////////////
3984 * /////////// SETUP AND INITIAL CONDITION ///////////
3985 * ///////////////////////////////////////////////////
3986 *
3987 * @code
3988 *   template<int dim>
3989 *   void NavierStokesSolver<dim>::setup()
3990 *   {
3991 *   pcout<<"***** SETUP IN NAVIER STOKES SOLVER *****"<<std::endl;
3992 *   setup_DOF();
3993 *   init_constraints();
3994 *   setup_VECTORS();
3995 *   }
3996 *  
3997 *   template<int dim>
3998 *   void NavierStokesSolver<dim>::setup_DOF()
3999 *   {
4000 *   rho_min = 1.;
4001 *   degree_MAX=std::max(degree_LS,degree_U);
4002 * @endcode
4003 *
4004 * setup system LS
4005 *
4006 * @code
4007 *   dof_handler_LS.distribute_dofs(fe_LS);
4008 *   locally_owned_dofs_LS = dof_handler_LS.locally_owned_dofs();
4009 *   locally_relevant_dofs_LS = DoFTools::extract_locally_relevant_dofs(dof_handler_LS);
4010 * @endcode
4011 *
4012 * setup system U
4013 *
4014 * @code
4015 *   dof_handler_U.distribute_dofs(fe_U);
4016 *   locally_owned_dofs_U = dof_handler_U.locally_owned_dofs();
4017 *   locally_relevant_dofs_U = DoFTools::extract_locally_relevant_dofs(dof_handler_U);
4018 * @endcode
4019 *
4020 * setup system P
4021 *
4022 * @code
4023 *   dof_handler_P.distribute_dofs(fe_P);
4024 *   locally_owned_dofs_P = dof_handler_P.locally_owned_dofs();
4025 *   locally_relevant_dofs_P = DoFTools::extract_locally_relevant_dofs(dof_handler_P);
4026 *   }
4027 *  
4028 *   template<int dim>
4029 *   void NavierStokesSolver<dim>::setup_VECTORS()
4030 *   {
4031 * @endcode
4032 *
4033 * init vectors for phi
4034 *
4035 * @code
4036 *   locally_relevant_solution_phi.reinit(locally_owned_dofs_LS,locally_relevant_dofs_LS,
4037 *   mpi_communicator);
4038 *   locally_relevant_solution_phi=0;
4039 * @endcode
4040 *
4041 * init vectors for u
4042 *
4043 * @code
4044 *   locally_relevant_solution_u.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4045 *   mpi_communicator);
4046 *   locally_relevant_solution_u=0;
4047 *   completely_distributed_solution_u.reinit(locally_owned_dofs_U,mpi_communicator);
4048 *   system_rhs_u.reinit(locally_owned_dofs_U,mpi_communicator);
4049 * @endcode
4050 *
4051 * init vectors for u_old
4052 *
4053 * @code
4054 *   locally_relevant_solution_u_old.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4055 *   mpi_communicator);
4056 *   locally_relevant_solution_u_old=0;
4057 * @endcode
4058 *
4059 * init vectors for v
4060 *
4061 * @code
4062 *   locally_relevant_solution_v.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4063 *   mpi_communicator);
4064 *   locally_relevant_solution_v=0;
4065 *   completely_distributed_solution_v.reinit(locally_owned_dofs_U,mpi_communicator);
4066 *   system_rhs_v.reinit(locally_owned_dofs_U,mpi_communicator);
4067 * @endcode
4068 *
4069 * init vectors for v_old
4070 *
4071 * @code
4072 *   locally_relevant_solution_v_old.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4073 *   mpi_communicator);
4074 *   locally_relevant_solution_v_old=0;
4075 * @endcode
4076 *
4077 * init vectors for w
4078 *
4079 * @code
4080 *   locally_relevant_solution_w.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4081 *   mpi_communicator);
4082 *   locally_relevant_solution_w=0;
4083 *   completely_distributed_solution_w.reinit(locally_owned_dofs_U,mpi_communicator);
4084 *   system_rhs_w.reinit(locally_owned_dofs_U,mpi_communicator);
4085 * @endcode
4086 *
4087 * init vectors for w_old
4088 *
4089 * @code
4090 *   locally_relevant_solution_w_old.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4091 *   mpi_communicator);
4092 *   locally_relevant_solution_w_old=0;
4093 * @endcode
4094 *
4095 * init vectors for dpsi
4096 *
4097 * @code
4098 *   locally_relevant_solution_psi.reinit(locally_owned_dofs_P,locally_relevant_dofs_P,
4099 *   mpi_communicator);
4100 *   locally_relevant_solution_psi=0;
4101 *   system_rhs_psi.reinit(locally_owned_dofs_P,mpi_communicator);
4102 * @endcode
4103 *
4104 * init vectors for dpsi old
4105 *
4106 * @code
4107 *   locally_relevant_solution_psi_old.reinit(locally_owned_dofs_P,locally_relevant_dofs_P,
4108 *   mpi_communicator);
4109 *   locally_relevant_solution_psi_old=0;
4110 * @endcode
4111 *
4112 * init vectors for q
4113 *
4114 * @code
4115 *   completely_distributed_solution_q.reinit(locally_owned_dofs_P,mpi_communicator);
4116 *   system_rhs_q.reinit(locally_owned_dofs_P,mpi_communicator);
4117 * @endcode
4118 *
4119 * init vectors for psi
4120 *
4121 * @code
4122 *   completely_distributed_solution_psi.reinit(locally_owned_dofs_P,mpi_communicator);
4123 * @endcode
4124 *
4125 * init vectors for p
4126 *
4127 * @code
4128 *   locally_relevant_solution_p.reinit(locally_owned_dofs_P,locally_relevant_dofs_P,
4129 *   mpi_communicator);
4130 *   locally_relevant_solution_p=0;
4131 *   completely_distributed_solution_p.reinit(locally_owned_dofs_P,mpi_communicator);
4132 * @endcode
4133 *
4134 * ////////////////////////
4135 * Initialize constraints
4136 * ////////////////////////
4137 *
4138 * @code
4139 *   init_constraints();
4140 * @endcode
4141 *
4142 * //////////////////
4143 * Sparsity pattern
4144 * //////////////////
4145 * sparsity pattern for A
4146 *
4147 * @code
4148 *   DynamicSparsityPattern dsp_Matrix(locally_relevant_dofs_U);
4149 *   DoFTools::make_sparsity_pattern(dof_handler_U,dsp_Matrix,constraints,false);
4150 *   SparsityTools::distribute_sparsity_pattern(dsp_Matrix,
4151 *   dof_handler_U.locally_owned_dofs(),
4152 *   mpi_communicator,
4153 *   locally_relevant_dofs_U);
4154 *   system_Matrix_u.reinit(dof_handler_U.locally_owned_dofs(),
4155 *   dof_handler_U.locally_owned_dofs(),
4156 *   dsp_Matrix,
4157 *   mpi_communicator);
4158 *   system_Matrix_v.reinit(dof_handler_U.locally_owned_dofs(),
4159 *   dof_handler_U.locally_owned_dofs(),
4160 *   dsp_Matrix,
4161 *   mpi_communicator);
4162 *   system_Matrix_w.reinit(dof_handler_U.locally_owned_dofs(),
4163 *   dof_handler_U.locally_owned_dofs(),
4164 *   dsp_Matrix,
4165 *   mpi_communicator);
4166 *   rebuild_Matrix_U=true;
4167 * @endcode
4168 *
4169 * sparsity pattern for S
4170 *
4171 * @code
4172 *   DynamicSparsityPattern dsp_S(locally_relevant_dofs_P);
4173 *   DoFTools::make_sparsity_pattern(dof_handler_P,dsp_S,constraints_psi,false);
4174 *   SparsityTools::distribute_sparsity_pattern(dsp_S,
4175 *   dof_handler_P.locally_owned_dofs(),
4176 *   mpi_communicator,
4177 *   locally_relevant_dofs_P);
4178 *   system_S.reinit(dof_handler_P.locally_owned_dofs(),
4179 *   dof_handler_P.locally_owned_dofs(),
4180 *   dsp_S,
4181 *   mpi_communicator);
4182 * @endcode
4183 *
4184 * sparsity pattern for M
4185 *
4186 * @code
4187 *   DynamicSparsityPattern dsp_M(locally_relevant_dofs_P);
4188 *   DoFTools::make_sparsity_pattern(dof_handler_P,dsp_M,constraints_psi,false);
4189 *   SparsityTools::distribute_sparsity_pattern(dsp_M,
4190 *   dof_handler_P.locally_owned_dofs(),
4191 *   mpi_communicator,
4192 *   locally_relevant_dofs_P);
4193 *   system_M.reinit(dof_handler_P.locally_owned_dofs(),
4194 *   dof_handler_P.locally_owned_dofs(),
4195 *   dsp_M,
4196 *   mpi_communicator);
4197 *   rebuild_S_M=true;
4198 *   }
4199 *  
4200 *   template<int dim>
4201 *   void NavierStokesSolver<dim>::init_constraints()
4202 *   {
4203 * @endcode
4204 *
4205 * grl constraints
4206 *
4207 * @code
4208 *   constraints.clear();
4209 *   #if DEAL_II_VERSION_GTE(9, 6, 0)
4210 *   constraints.reinit(locally_owned_dofs_U, locally_relevant_dofs_U);
4211 *   #else
4212 *   constraints.reinit(locally_relevant_dofs_U);
4213 *   #endif
4214 *   DoFTools::make_hanging_node_constraints(dof_handler_U,constraints);
4215 *   constraints.close();
4216 * @endcode
4217 *
4218 * constraints for dpsi
4219 *
4220 * @code
4221 *   constraints_psi.clear();
4222 *   #if DEAL_II_VERSION_GTE(9, 6, 0)
4223 *   constraints_psi.reinit(locally_owned_dofs_P, locally_relevant_dofs_P);
4224 *   #else
4225 *   constraints_psi.reinit(locally_relevant_dofs_P);
4226 *   #endif
4227 *   DoFTools::make_hanging_node_constraints(dof_handler_P,constraints_psi);
4228 * @endcode
4229 *
4230 * if (constraints_psi.can_store_line(0))
4231 * constraints_psi.add_line(0); //constraint u0 = 0
4232 *
4233 * @code
4234 *   constraints_psi.close();
4235 *   }
4236 *  
4237 * @endcode
4238 *
4239 * ///////////////////////////////////////////////////
4240 * //////////////// ASSEMBLE SYSTEMS /////////////////
4241 * ///////////////////////////////////////////////////
4242 *
4243 * @code
4244 *   template<int dim>
4245 *   void NavierStokesSolver<dim>::assemble_system_U()
4246 *   {
4247 *   if (rebuild_Matrix_U==true)
4248 *   {
4249 *   system_Matrix_u=0;
4250 *   system_Matrix_v=0;
4251 *   system_Matrix_w=0;
4252 *   }
4253 *   system_rhs_u=0;
4254 *   system_rhs_v=0;
4255 *   system_rhs_w=0;
4256 *  
4257 *   const QGauss<dim> quadrature_formula(degree_MAX+1);
4258 *   FEValues<dim> fe_values_LS(fe_LS,quadrature_formula,
4259 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4260 *   FEValues<dim> fe_values_U(fe_U,quadrature_formula,
4261 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4262 *   FEValues<dim> fe_values_P(fe_P,quadrature_formula,
4263 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4264 *  
4265 *   const unsigned int dofs_per_cell=fe_U.dofs_per_cell;
4266 *   const unsigned int n_q_points=quadrature_formula.size();
4267 *  
4268 *   FullMatrix<double> cell_A_u(dofs_per_cell,dofs_per_cell);
4269 *   Vector<double> cell_rhs_u(dofs_per_cell);
4270 *   Vector<double> cell_rhs_v(dofs_per_cell);
4271 *   Vector<double> cell_rhs_w(dofs_per_cell);
4272 *  
4273 *   std::vector<double> phiqnp1(n_q_points);
4274 *  
4275 *   std::vector<double> uqn(n_q_points);
4276 *   std::vector<double> uqnm1(n_q_points);
4277 *   std::vector<double> vqn(n_q_points);
4278 *   std::vector<double> vqnm1(n_q_points);
4279 *   std::vector<double> wqn(n_q_points);
4280 *   std::vector<double> wqnm1(n_q_points);
4281 *  
4282 * @endcode
4283 *
4284 * FOR Explicit nonlinearity
4285 * std::vector<Tensor<1, dim> > grad_un(n_q_points);
4286 * std::vector<Tensor<1, dim> > grad_vn(n_q_points);
4287 * std::vector<Tensor<1, dim> > grad_wn(n_q_points);
4288 * Tensor<1, dim> Un;
4289 *
4290
4291 *
4292 *
4293 * @code
4294 *   std::vector<Tensor<1, dim> > grad_pqn(n_q_points);
4295 *   std::vector<Tensor<1, dim> > grad_psiqn(n_q_points);
4296 *   std::vector<Tensor<1, dim> > grad_psiqnm1(n_q_points);
4297 *  
4298 *   std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
4299 *   std::vector<Tensor<1, dim> > shape_grad(dofs_per_cell);
4300 *   std::vector<double> shape_value(dofs_per_cell);
4301 *  
4302 *   double force_u;
4303 *   double force_v;
4304 *   double force_w;
4305 *   double pressure_grad_u;
4306 *   double pressure_grad_v;
4307 *   double pressure_grad_w;
4308 *   double u_star=0;
4309 *   double v_star=0;
4310 *   double w_star=0;
4311 *   double rho_star;
4312 *   double rho;
4313 *   Vector<double> force_terms(dim);
4314 *  
4315 *   typename DoFHandler<dim>::active_cell_iterator
4316 *   cell_U=dof_handler_U.begin_active(), endc_U=dof_handler_U.end();
4317 *   typename DoFHandler<dim>::active_cell_iterator cell_P=dof_handler_P.begin_active();
4318 *   typename DoFHandler<dim>::active_cell_iterator cell_LS=dof_handler_LS.begin_active();
4319 *  
4320 *   for (; cell_U!=endc_U; ++cell_U,++cell_P,++cell_LS)
4321 *   if (cell_U->is_locally_owned())
4322 *   {
4323 *   cell_A_u=0;
4324 *   cell_rhs_u=0;
4325 *   cell_rhs_v=0;
4326 *   cell_rhs_w=0;
4327 *  
4328 *   fe_values_LS.reinit(cell_LS);
4329 *   fe_values_U.reinit(cell_U);
4330 *   fe_values_P.reinit(cell_P);
4331 *  
4332 * @endcode
4333 *
4334 * get function values for LS
4335 *
4336 * @code
4337 *   fe_values_LS.get_function_values(locally_relevant_solution_phi,phiqnp1);
4338 * @endcode
4339 *
4340 * get function values for U
4341 *
4342 * @code
4343 *   fe_values_U.get_function_values(locally_relevant_solution_u,uqn);
4344 *   fe_values_U.get_function_values(locally_relevant_solution_u_old,uqnm1);
4345 *   fe_values_U.get_function_values(locally_relevant_solution_v,vqn);
4346 *   fe_values_U.get_function_values(locally_relevant_solution_v_old,vqnm1);
4347 *   if (dim==3)
4348 *   {
4349 *   fe_values_U.get_function_values(locally_relevant_solution_w,wqn);
4350 *   fe_values_U.get_function_values(locally_relevant_solution_w_old,wqnm1);
4351 *   }
4352 * @endcode
4353 *
4354 * For explicit nonlinearity
4355 * get gradient values for U
4356 * fe_values_U.get_function_gradients(locally_relevant_solution_u,grad_un);
4357 * fe_values_U.get_function_gradients(locally_relevant_solution_v,grad_vn);
4358 * if (dim==3)
4359 * fe_values_U.get_function_gradients(locally_relevant_solution_w,grad_wn);
4360 *
4361
4362 *
4363 * get values and gradients for p and dpsi
4364 *
4365 * @code
4366 *   fe_values_P.get_function_gradients(locally_relevant_solution_p,grad_pqn);
4367 *   fe_values_P.get_function_gradients(locally_relevant_solution_psi,grad_psiqn);
4368 *   fe_values_P.get_function_gradients(locally_relevant_solution_psi_old,grad_psiqnm1);
4369 *  
4370 *   for (unsigned int q_point=0; q_point<n_q_points; ++q_point)
4371 *   {
4372 *   const double JxW=fe_values_U.JxW(q_point);
4373 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
4374 *   {
4375 *   shape_grad[i]=fe_values_U.shape_grad(i,q_point);
4376 *   shape_value[i]=fe_values_U.shape_value(i,q_point);
4377 *   }
4378 *  
4379 *   pressure_grad_u=(grad_pqn[q_point][0]+4./3*grad_psiqn[q_point][0]-1./3*grad_psiqnm1[q_point][0]);
4380 *   pressure_grad_v=(grad_pqn[q_point][1]+4./3*grad_psiqn[q_point][1]-1./3*grad_psiqnm1[q_point][1]);
4381 *   if (dim==3)
4382 *   pressure_grad_w=(grad_pqn[q_point][2]+4./3*grad_psiqn[q_point][2]-1./3*grad_psiqnm1[q_point][2]);
4383 *  
4384 *   if (LEVEL_SET==1) // use level set to define rho and nu
4385 *   get_rho_and_nu(phiqnp1[q_point]);
4386 *   else // rho and nu are defined through functions
4387 *   {
4388 *   rho_value=rho_function.value(fe_values_U.quadrature_point(q_point));
4389 *   nu_value=nu_function.value(fe_values_U.quadrature_point(q_point));
4390 *   }
4391 *  
4392 * @endcode
4393 *
4394 * Non-linearity: for semi-implicit
4395 *
4396 * @code
4397 *   u_star=2*uqn[q_point]-uqnm1[q_point];
4398 *   v_star=2*vqn[q_point]-vqnm1[q_point];
4399 *   if (dim==3)
4400 *   w_star=2*wqn[q_point]-wqnm1[q_point];
4401 *  
4402 * @endcode
4403 *
4404 * for explicit nonlinearity
4405 * Un[0] = uqn[q_point];
4406 * Un[1] = vqn[q_point];
4407 * if (dim==3)
4408 * Un[2] = wqn[q_point];
4409 *
4410
4411 *
4412 * double nonlinearity_u = Un*grad_un[q_point];
4413 * double nonlinearity_v = Un*grad_vn[q_point];
4414 * double nonlinearity_w = 0;
4415 * if (dim==3)
4416 * nonlinearity_w = Un*grad_wn[q_point];
4417 *
4418
4419 *
4420 *
4421 * @code
4422 *   rho_star=rho_value; // This is because we consider rho*u_t instead of (rho*u)_t
4423 *   rho=rho_value;
4424 *  
4425 * @endcode
4426 *
4427 * FORCE TERMS
4428 *
4429 * @code
4430 *   force_function.vector_value(fe_values_U.quadrature_point(q_point),force_terms);
4431 *   force_u=force_terms[0];
4432 *   force_v=force_terms[1];
4433 *   if (dim==3)
4434 *   force_w=force_terms[2];
4435 *   if (RHO_TIMES_RHS==1)
4436 *   {
4437 *   force_u*=rho;
4438 *   force_v*=rho;
4439 *   if (dim==3)
4440 *   force_w*=rho;
4441 *   }
4442 *  
4443 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
4444 *   {
4445 *   cell_rhs_u(i)+=((4./3*rho*uqn[q_point]-1./3*rho*uqnm1[q_point]
4446 *   +2./3*time_step*(force_u-pressure_grad_u)
4447 * @endcode
4448 *
4449 * -2./3*time_step*rho*nonlinearity_u
4450 *
4451 * @code
4452 *   )*shape_value[i])*JxW;
4453 *   cell_rhs_v(i)+=((4./3*rho*vqn[q_point]-1./3*rho*vqnm1[q_point]
4454 *   +2./3*time_step*(force_v-pressure_grad_v)
4455 * @endcode
4456 *
4457 * -2./3*time_step*rho*nonlinearity_v
4458 *
4459 * @code
4460 *   )*shape_value[i])*JxW;
4461 *   if (dim==3)
4462 *   cell_rhs_w(i)+=((4./3*rho*wqn[q_point]-1./3*rho*wqnm1[q_point]
4463 *   +2./3*time_step*(force_w-pressure_grad_w)
4464 * @endcode
4465 *
4466 * -2./3*time_step*rho*nonlinearity_w
4467 *
4468 * @code
4469 *   )*shape_value[i])*JxW;
4470 *   if (rebuild_Matrix_U==true)
4471 *   for (unsigned int j=0; j<dofs_per_cell; ++j)
4472 *   {
4473 *   if (dim==2)
4474 *   cell_A_u(i,j)+=(rho_star*shape_value[i]*shape_value[j]
4475 *   +2./3*time_step*nu_value*(shape_grad[i]*shape_grad[j])
4476 *   +2./3*time_step*rho*shape_value[i]
4477 *   *(u_star*shape_grad[j][0]+v_star*shape_grad[j][1]) // semi-implicit NL
4478 *   )*JxW;
4479 *   else //dim==3
4480 *   cell_A_u(i,j)+=(rho_star*shape_value[i]*shape_value[j]
4481 *   +2./3*time_step*nu_value*(shape_grad[i]*shape_grad[j])
4482 *   +2./3*time_step*rho*shape_value[i]
4483 *   *(u_star*shape_grad[j][0]+v_star*shape_grad[j][1]+w_star*shape_grad[j][2]) // semi-implicit NL
4484 *   )*JxW;
4485 *   }
4486 *   }
4487 *   }
4488 *   cell_U->get_dof_indices(local_dof_indices);
4489 * @endcode
4490 *
4491 * distribute
4492 *
4493 * @code
4494 *   if (rebuild_Matrix_U==true)
4495 *   constraints.distribute_local_to_global(cell_A_u,local_dof_indices,system_Matrix_u);
4496 *   constraints.distribute_local_to_global(cell_rhs_u,local_dof_indices,system_rhs_u);
4497 *   constraints.distribute_local_to_global(cell_rhs_v,local_dof_indices,system_rhs_v);
4498 *   if (dim==3)
4499 *   constraints.distribute_local_to_global(cell_rhs_w,local_dof_indices,system_rhs_w);
4500 *   }
4501 *   system_rhs_u.compress(VectorOperation::add);
4502 *   system_rhs_v.compress(VectorOperation::add);
4503 *   if (dim==3) system_rhs_w.compress(VectorOperation::add);
4504 *   if (rebuild_Matrix_U==true)
4505 *   {
4506 *   system_Matrix_u.compress(VectorOperation::add);
4507 *   system_Matrix_v.copy_from(system_Matrix_u);
4508 *   if (dim==3)
4509 *   system_Matrix_w.copy_from(system_Matrix_u);
4510 *   }
4511 * @endcode
4512 *
4513 * BOUNDARY CONDITIONS
4514 *
4515 * @code
4516 *   system_rhs_u.set(boundary_values_id_u,boundary_values_u);
4517 *   system_rhs_u.compress(VectorOperation::insert);
4518 *   system_rhs_v.set(boundary_values_id_v,boundary_values_v);
4519 *   system_rhs_v.compress(VectorOperation::insert);
4520 *   if (dim==3)
4521 *   {
4522 *   system_rhs_w.set(boundary_values_id_w,boundary_values_w);
4523 *   system_rhs_w.compress(VectorOperation::insert);
4524 *   }
4525 *   if (rebuild_Matrix_U)
4526 *   {
4527 *   system_Matrix_u.clear_rows(boundary_values_id_u,1);
4528 *   system_Matrix_v.clear_rows(boundary_values_id_v,1);
4529 *   if (dim==3)
4530 *   system_Matrix_w.clear_rows(boundary_values_id_w,1);
4531 *   if (rebuild_Matrix_U_preconditioners)
4532 *   {
4533 * @endcode
4534 *
4535 * PRECONDITIONERS
4536 *
4537 * @code
4538 *   rebuild_Matrix_U_preconditioners=false;
4539 *   preconditioner_Matrix_u.reset(new PETScWrappers::PreconditionBoomerAMG
4540 *   (system_Matrix_u,PETScWrappers::PreconditionBoomerAMG::AdditionalData(false)));
4541 *   preconditioner_Matrix_v.reset( new PETScWrappers::PreconditionBoomerAMG
4542 *   (system_Matrix_v,PETScWrappers::PreconditionBoomerAMG::AdditionalData(false)));
4543 *   if (dim==3)
4544 *   preconditioner_Matrix_w.reset(new PETScWrappers::PreconditionBoomerAMG
4545 *   (system_Matrix_w,PETScWrappers::PreconditionBoomerAMG::AdditionalData(false)));
4546 *   }
4547 *   }
4548 *   rebuild_Matrix_U=true;
4549 *   }
4550 *  
4551 *   template<int dim>
4552 *   void NavierStokesSolver<dim>::assemble_system_dpsi_q()
4553 *   {
4554 *   if (rebuild_S_M==true)
4555 *   {
4556 *   system_S=0;
4557 *   system_M=0;
4558 *   }
4559 *   system_rhs_psi=0;
4560 *   system_rhs_q=0;
4561 *  
4562 *   const QGauss<dim> quadrature_formula(degree_MAX+1);
4563 *  
4564 *   FEValues<dim> fe_values_U(fe_U,quadrature_formula,
4565 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4566 *   FEValues<dim> fe_values_P(fe_P,quadrature_formula,
4567 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4568 *   FEValues<dim> fe_values_LS(fe_LS,quadrature_formula,
4569 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4570 *  
4571 *   const unsigned int dofs_per_cell=fe_P.dofs_per_cell;
4572 *   const unsigned int n_q_points=quadrature_formula.size();
4573 *  
4574 *   FullMatrix<double> cell_S(dofs_per_cell,dofs_per_cell);
4575 *   FullMatrix<double> cell_M(dofs_per_cell,dofs_per_cell);
4576 *   Vector<double> cell_rhs_psi(dofs_per_cell);
4577 *   Vector<double> cell_rhs_q(dofs_per_cell);
4578 *  
4579 *   std::vector<double> phiqnp1(n_q_points);
4580 *   std::vector<Tensor<1, dim> > gunp1(n_q_points);
4581 *   std::vector<Tensor<1, dim> > gvnp1(n_q_points);
4582 *   std::vector<Tensor<1, dim> > gwnp1(n_q_points);
4583 *  
4584 *   std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
4585 *   std::vector<double> shape_value(dofs_per_cell);
4586 *   std::vector<Tensor<1, dim> > shape_grad(dofs_per_cell);
4587 *  
4588 *   typename DoFHandler<dim>::active_cell_iterator
4589 *   cell_P=dof_handler_P.begin_active(), endc_P=dof_handler_P.end();
4590 *   typename DoFHandler<dim>::active_cell_iterator cell_U=dof_handler_U.begin_active();
4591 *   typename DoFHandler<dim>::active_cell_iterator cell_LS=dof_handler_LS.begin_active();
4592 *  
4593 *   for (; cell_P!=endc_P; ++cell_P,++cell_U,++cell_LS)
4594 *   if (cell_P->is_locally_owned())
4595 *   {
4596 *   cell_S=0;
4597 *   cell_M=0;
4598 *   cell_rhs_psi=0;
4599 *   cell_rhs_q=0;
4600 *  
4601 *   fe_values_P.reinit(cell_P);
4602 *   fe_values_U.reinit(cell_U);
4603 *   fe_values_LS.reinit(cell_LS);
4604 *  
4605 * @endcode
4606 *
4607 * get function values for LS
4608 *
4609 * @code
4610 *   fe_values_LS.get_function_values(locally_relevant_solution_phi,phiqnp1);
4611 *  
4612 * @endcode
4613 *
4614 * get function grads for u and v
4615 *
4616 * @code
4617 *   fe_values_U.get_function_gradients(locally_relevant_solution_u,gunp1);
4618 *   fe_values_U.get_function_gradients(locally_relevant_solution_v,gvnp1);
4619 *   if (dim==3)
4620 *   fe_values_U.get_function_gradients(locally_relevant_solution_w,gwnp1);
4621 *  
4622 *   for (unsigned int q_point=0; q_point<n_q_points; ++q_point)
4623 *   {
4624 *   const double JxW=fe_values_P.JxW(q_point);
4625 *   double divU = gunp1[q_point][0]+gvnp1[q_point][1];
4626 *   if (dim==3) divU += gwnp1[q_point][2];
4627 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
4628 *   {
4629 *   shape_value[i]=fe_values_P.shape_value(i,q_point);
4630 *   shape_grad[i]=fe_values_P.shape_grad(i,q_point);
4631 *   }
4632 *   if (LEVEL_SET==1) // use level set to define rho and nu
4633 *   get_rho_and_nu (phiqnp1[q_point]);
4634 *   else // rho and nu are defined through functions
4635 *   nu_value=nu_function.value(fe_values_U.quadrature_point(q_point));
4636 *  
4637 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
4638 *   {
4639 *   cell_rhs_psi(i)+=-3./2./time_step*rho_min*divU*shape_value[i]*JxW;
4640 *   cell_rhs_q(i)-=nu_value*divU*shape_value[i]*JxW;
4641 *   if (rebuild_S_M==true)
4642 *   {
4643 *   for (unsigned int j=0; j<dofs_per_cell; ++j)
4644 *   if (i==j)
4645 *   {
4646 *   cell_S(i,j)+=shape_grad[i]*shape_grad[j]*JxW+1E-10;
4647 *   cell_M(i,j)+=shape_value[i]*shape_value[j]*JxW;
4648 *   }
4649 *   else
4650 *   {
4651 *   cell_S(i,j)+=shape_grad[i]*shape_grad[j]*JxW;
4652 *   cell_M(i,j)+=shape_value[i]*shape_value[j]*JxW;
4653 *   }
4654 *   }
4655 *   }
4656 *   }
4657 *   cell_P->get_dof_indices(local_dof_indices);
4658 * @endcode
4659 *
4660 * Distribute
4661 *
4662 * @code
4663 *   if (rebuild_S_M==true)
4664 *   {
4665 *   constraints_psi.distribute_local_to_global(cell_S,local_dof_indices,system_S);
4666 *   constraints_psi.distribute_local_to_global(cell_M,local_dof_indices,system_M);
4667 *   }
4668 *   constraints_psi.distribute_local_to_global(cell_rhs_q,local_dof_indices,system_rhs_q);
4669 *   constraints_psi.distribute_local_to_global(cell_rhs_psi,local_dof_indices,system_rhs_psi);
4670 *   }
4671 *   if (rebuild_S_M==true)
4672 *   {
4673 *   system_M.compress(VectorOperation::add);
4674 *   system_S.compress(VectorOperation::add);
4675 *   if (rebuild_S_M_preconditioners)
4676 *   {
4677 *   rebuild_S_M_preconditioners=false;
4678 *   preconditioner_S.reset(new PETScWrappers::PreconditionBoomerAMG
4679 *   (system_S,PETScWrappers::PreconditionBoomerAMG::AdditionalData(true)));
4680 *   preconditioner_M.reset(new PETScWrappers::PreconditionBoomerAMG
4681 *   (system_M,PETScWrappers::PreconditionBoomerAMG::AdditionalData(true)));
4682 *   }
4683 *   }
4684 *   system_rhs_psi.compress(VectorOperation::add);
4685 *   system_rhs_q.compress(VectorOperation::add);
4686 *   rebuild_S_M=false;
4687 *   }
4688 *  
4689 * @endcode
4690 *
4691 * ///////////////////////////////////////////////////
4692 * ///////////////////// SOLVERS /////////////////////
4693 * ///////////////////////////////////////////////////
4694 *
4695 * @code
4696 *   template<int dim>
4697 *   void NavierStokesSolver<dim>::solve_U(const AffineConstraints<double> &constraints,
4698 *   PETScWrappers::MPI::SparseMatrix &Matrix,
4699 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner,
4700 *   PETScWrappers::MPI::Vector &completely_distributed_solution,
4701 *   const PETScWrappers::MPI::Vector &rhs)
4702 *   {
4703 *   SolverControl solver_control(dof_handler_U.n_dofs(),1e-6);
4704 * @endcode
4705 *
4706 * PETScWrappers::SolverCG solver(solver_control);
4707 * PETScWrappers::SolverGMRES solver(solver_control);
4708 * PETScWrappers::SolverChebychev solver(solver_control);
4709 *
4710 * @code
4711 *   PETScWrappers::SolverBicgstab solver(solver_control);
4712 *   constraints.distribute(completely_distributed_solution);
4713 *   solver.solve(Matrix,completely_distributed_solution,rhs,*preconditioner);
4714 *   constraints.distribute(completely_distributed_solution);
4715 *   if (solver_control.last_step() > MAX_NUM_ITER_TO_RECOMPUTE_PRECONDITIONER)
4716 *   rebuild_Matrix_U_preconditioners=true;
4717 *   if (verbose==true)
4718 *   pcout<<" Solved U in "<<solver_control.last_step()<<" iterations."<<std::endl;
4719 *   }
4720 *  
4721 *   template<int dim>
4722 *   void NavierStokesSolver<dim>::solve_P(const AffineConstraints<double> &constraints,
4723 *   PETScWrappers::MPI::SparseMatrix &Matrix,
4724 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner,
4725 *   PETScWrappers::MPI::Vector &completely_distributed_solution,
4726 *   const PETScWrappers::MPI::Vector &rhs)
4727 *   {
4728 *   SolverControl solver_control(dof_handler_P.n_dofs(),1e-6);
4729 *   PETScWrappers::SolverCG solver(solver_control);
4730 * @endcode
4731 *
4732 * PETScWrappers::SolverGMRES solver(solver_control);
4733 *
4734 * @code
4735 *   constraints.distribute(completely_distributed_solution);
4736 *   solver.solve(Matrix,completely_distributed_solution,rhs,*preconditioner);
4737 *   constraints.distribute(completely_distributed_solution);
4738 *   if (solver_control.last_step() > MAX_NUM_ITER_TO_RECOMPUTE_PRECONDITIONER)
4739 *   rebuild_S_M_preconditioners=true;
4740 *   if (verbose==true)
4741 *   pcout<<" Solved P in "<<solver_control.last_step()<<" iterations."<<std::endl;
4742 *   }
4743 *  
4744 * @endcode
4745 *
4746 * ///////////////////////////////////////////////////
4747 * ////////////// get different fields ///////////////
4748 * ///////////////////////////////////////////////////
4749 *
4750 * @code
4751 *   template<int dim>
4752 *   void NavierStokesSolver<dim>::get_velocity()
4753 *   {
4754 *   assemble_system_U();
4755 *   save_old_solution();
4756 *   solve_U(constraints,system_Matrix_u,preconditioner_Matrix_u,completely_distributed_solution_u,system_rhs_u);
4757 *   locally_relevant_solution_u=completely_distributed_solution_u;
4758 *   solve_U(constraints,system_Matrix_v,preconditioner_Matrix_v,completely_distributed_solution_v,system_rhs_v);
4759 *   locally_relevant_solution_v=completely_distributed_solution_v;
4760 *   if (dim==3)
4761 *   {
4762 *   solve_U(constraints,system_Matrix_w,preconditioner_Matrix_w,completely_distributed_solution_w,system_rhs_w);
4763 *   locally_relevant_solution_w=completely_distributed_solution_w;
4764 *   }
4765 *   }
4766 *  
4767 *   template<int dim>
4768 *   void NavierStokesSolver<dim>::get_pressure()
4769 *   {
4770 * @endcode
4771 *
4772 * GET DPSI
4773 *
4774 * @code
4775 *   assemble_system_dpsi_q();
4776 *   solve_P(constraints_psi,system_S,preconditioner_S,completely_distributed_solution_psi,system_rhs_psi);
4777 *   locally_relevant_solution_psi=completely_distributed_solution_psi;
4778 * @endcode
4779 *
4780 * SOLVE Q
4781 *
4782 * @code
4783 *   solve_P(constraints,system_M,preconditioner_M,completely_distributed_solution_q,system_rhs_q);
4784 * @endcode
4785 *
4786 * UPDATE THE PRESSURE
4787 *
4788 * @code
4789 *   completely_distributed_solution_p.add(1,completely_distributed_solution_psi);
4790 *   completely_distributed_solution_p.add(1,completely_distributed_solution_q);
4791 *   locally_relevant_solution_p = completely_distributed_solution_p;
4792 *   }
4793 *  
4794 * @endcode
4795 *
4796 * ///////////////////////////////////////////////////
4797 * ///////////////////// DO STEPS ////////////////////
4798 * ///////////////////////////////////////////////////
4799 *
4800 * @code
4801 *   template<int dim>
4802 *   void NavierStokesSolver<dim>::nth_time_step()
4803 *   {
4804 *   get_velocity();
4805 *   get_pressure();
4806 *   }
4807 *  
4808 * @endcode
4809 *
4810 * ///////////////////////////////////////////////////
4811 * ////////////////////// OTHERS /////////////////////
4812 * ///////////////////////////////////////////////////
4813 *
4814 * @code
4815 *   template<int dim>
4816 *   void NavierStokesSolver<dim>::save_old_solution()
4817 *   {
4818 *   locally_relevant_solution_u_old=locally_relevant_solution_u;
4819 *   locally_relevant_solution_v_old=locally_relevant_solution_v;
4820 *   locally_relevant_solution_w_old=locally_relevant_solution_w;
4821 *   locally_relevant_solution_psi_old=locally_relevant_solution_psi;
4822 *   }
4823 *  
4824 * @endcode
4825
4826
4827<a name="ann-TestLevelSet.cc"></a>
4828<h1>Annotated version of TestLevelSet.cc</h1>
4829 *
4830 *
4831 *
4832 *
4833 * @code
4834 *   /* -----------------------------------------------------------------------------
4835 *   *
4836 *   * SPDX-License-Identifier: LGPL-2.1-or-later
4837 *   * Copyright (C) 2016 Manuel Quezada de Luna
4838 *   *
4839 *   * This file is part of the deal.II code gallery.
4840 *   *
4841 *   * -----------------------------------------------------------------------------
4842 *   */
4843 *  
4844 *   #include <deal.II/base/quadrature_lib.h>
4845 *   #include <deal.II/base/function.h>
4846 *   #include <deal.II/lac/affine_constraints.h>
4847 *   #include <deal.II/lac/vector.h>
4848 *   #include <deal.II/lac/full_matrix.h>
4849 *   #include <deal.II/lac/solver_cg.h>
4850 *   #include <deal.II/lac/petsc_sparse_matrix.h>
4851 *   #include <deal.II/lac/petsc_vector.h>
4852 *   #include <deal.II/lac/petsc_solver.h>
4853 *   #include <deal.II/lac/petsc_precondition.h>
4854 *   #include <deal.II/grid/grid_generator.h>
4855 *   #include <deal.II/grid/tria_accessor.h>
4856 *   #include <deal.II/grid/tria_iterator.h>
4857 *   #include <deal.II/dofs/dof_handler.h>
4858 *   #include <deal.II/dofs/dof_accessor.h>
4859 *   #include <deal.II/dofs/dof_tools.h>
4860 *   #include <deal.II/fe/fe_values.h>
4861 *   #include <deal.II/fe/fe_q.h>
4862 *   #include <deal.II/numerics/vector_tools.h>
4863 *   #include <deal.II/numerics/data_out.h>
4864 *   #include <deal.II/numerics/error_estimator.h>
4865 *   #include <deal.II/base/utilities.h>
4866 *   #include <deal.II/base/conditional_ostream.h>
4867 *   #include <deal.II/base/index_set.h>
4868 *   #include <deal.II/lac/sparsity_tools.h>
4869 *   #include <deal.II/distributed/tria.h>
4870 *   #include <deal.II/distributed/grid_refinement.h>
4871 *   #include <deal.II/lac/petsc_vector.h>
4872 *   #include <deal.II/base/convergence_table.h>
4873 *   #include <deal.II/base/timer.h>
4874 *   #include <deal.II/base/parameter_handler.h>
4875 *   #include <deal.II/grid/grid_tools.h>
4876 *   #include <deal.II/fe/mapping_q.h>
4877 *   #include <deal.II/fe/fe_system.h>
4878 *  
4879 *   #include <fstream>
4880 *   #include <iostream>
4881 *   #include <memory>
4882 *  
4883 *   using namespace dealii;
4884 *  
4885 * @endcode
4886 *
4887 * ///////////////////////
4888 * FOR TRANSPORT PROBLEM
4889 * ///////////////////////
4890 * TIME_INTEGRATION
4891 *
4892 * @code
4893 *   #define FORWARD_EULER 0
4894 *   #define SSP33 1
4895 * @endcode
4896 *
4897 * PROBLEM
4898 *
4899 * @code
4900 *   #define CIRCULAR_ROTATION 0
4901 *   #define DIAGONAL_ADVECTION 1
4902 * @endcode
4903 *
4904 * OTHER FLAGS
4905 *
4906 * @code
4907 *   #define VARIABLE_VELOCITY 0
4908 *  
4909 *   #include "utilities_test_LS.cc"
4910 *   #include "LevelSetSolver.cc"
4911 *  
4912 * @endcode
4913 *
4914 * ///////////////////////////////////////////////////
4915 * /////////////////// MAIN CLASS ////////////////////
4916 * ///////////////////////////////////////////////////
4917 *
4918 * @code
4919 *   template <int dim>
4920 *   class TestLevelSet
4921 *   {
4922 *   public:
4923 *   TestLevelSet (const unsigned int degree_LS,
4924 *   const unsigned int degree_U);
4925 *   ~TestLevelSet ();
4926 *   void run ();
4927 *  
4928 *   private:
4929 * @endcode
4930 *
4931 * BOUNDARY
4932 *
4933 * @code
4934 *   void set_boundary_inlet();
4935 *   void get_boundary_values_phi(std::vector<unsigned int> &boundary_values_id_phi,
4936 *   std::vector<double> &boundary_values_phi);
4937 * @endcode
4938 *
4939 * VELOCITY
4940 *
4941 * @code
4942 *   void get_interpolated_velocity();
4943 * @endcode
4944 *
4945 * SETUP AND INIT CONDITIONS
4946 *
4947 * @code
4948 *   void setup();
4949 *   void initial_condition();
4950 *   void init_constraints();
4951 * @endcode
4952 *
4953 * POST PROCESSING
4954 *
4955 * @code
4956 *   void process_solution(parallel::distributed::Triangulation<dim> &triangulation,
4957 *   DoFHandler<dim> &dof_handler_LS,
4958 *   PETScWrappers::MPI::Vector &solution);
4959 *   void output_results();
4960 *   void output_solution();
4961 *  
4962 * @endcode
4963 *
4964 * SOLUTION VECTORS
4965 *
4966 * @code
4967 *   PETScWrappers::MPI::Vector locally_relevant_solution_phi;
4968 *   PETScWrappers::MPI::Vector locally_relevant_solution_u;
4969 *   PETScWrappers::MPI::Vector locally_relevant_solution_v;
4970 *   PETScWrappers::MPI::Vector locally_relevant_solution_w;
4971 *   PETScWrappers::MPI::Vector completely_distributed_solution_phi;
4972 *   PETScWrappers::MPI::Vector completely_distributed_solution_u;
4973 *   PETScWrappers::MPI::Vector completely_distributed_solution_v;
4974 *   PETScWrappers::MPI::Vector completely_distributed_solution_w;
4975 * @endcode
4976 *
4977 * BOUNDARY VECTORS
4978 *
4979 * @code
4980 *   std::vector<unsigned int> boundary_values_id_phi;
4981 *   std::vector<double> boundary_values_phi;
4982 *  
4983 * @endcode
4984 *
4985 * GENERAL
4986 *
4987 * @code
4988 *   MPI_Comm mpi_communicator;
4989 *   parallel::distributed::Triangulation<dim> triangulation;
4990 *  
4991 *   int degree;
4992 *   int degree_LS;
4993 *   DoFHandler<dim> dof_handler_LS;
4994 *   FE_Q<dim> fe_LS;
4995 *   IndexSet locally_owned_dofs_LS;
4996 *   IndexSet locally_relevant_dofs_LS;
4997 *  
4998 *   int degree_U;
4999 *   DoFHandler<dim> dof_handler_U;
5000 *   FE_Q<dim> fe_U;
5001 *   IndexSet locally_owned_dofs_U;
5002 *   IndexSet locally_relevant_dofs_U;
5003 *  
5004 *   DoFHandler<dim> dof_handler_U_disp_field;
5005 *   FESystem<dim> fe_U_disp_field;
5006 *   IndexSet locally_owned_dofs_U_disp_field;
5007 *   IndexSet locally_relevant_dofs_U_disp_field;
5008 *  
5009 *   AffineConstraints<double> constraints;
5010 *   AffineConstraints<double> constraints_disp_field;
5011 *  
5012 *   double time;
5013 *   double time_step;
5014 *   double final_time;
5015 *   unsigned int timestep_number;
5016 *   double cfl;
5017 *   double min_h;
5018 *  
5019 *   double sharpness;
5020 *   int sharpness_integer;
5021 *  
5022 *   unsigned int n_refinement;
5023 *   unsigned int output_number;
5024 *   double output_time;
5025 *   bool get_output;
5026 *  
5027 *   bool verbose;
5028 *   ConditionalOStream pcout;
5029 *  
5030 * @endcode
5031 *
5032 * FOR TRANSPORT
5033 *
5034 * @code
5035 *   double cK; //compression coeff
5036 *   double cE; //entropy-visc coeff
5037 *   unsigned int TRANSPORT_TIME_INTEGRATION;
5038 *   std::string ALGORITHM;
5039 *   unsigned int PROBLEM;
5040 *  
5041 * @endcode
5042 *
5043 * FOR RECONSTRUCTION OF MATERIAL FIELDS
5044 *
5045 * @code
5046 *   double eps, rho_air, rho_fluid;
5047 *  
5048 * @endcode
5049 *
5050 * MASS MATRIX
5051 *
5052 * @code
5053 *   PETScWrappers::MPI::SparseMatrix matrix_MC, matrix_MC_tnm1;
5054 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_MC;
5055 *  
5056 *   };
5057 *  
5058 *   template <int dim>
5059 *   TestLevelSet<dim>::TestLevelSet (const unsigned int degree_LS,
5060 *   const unsigned int degree_U)
5061 *   :
5062 *   mpi_communicator (MPI_COMM_WORLD),
5063 *   triangulation (mpi_communicator,
5064 *   typename Triangulation<dim>::MeshSmoothing
5065 *   (Triangulation<dim>::smoothing_on_refinement |
5066 *   Triangulation<dim>::smoothing_on_coarsening)),
5067 *   degree_LS(degree_LS),
5068 *   dof_handler_LS (triangulation),
5069 *   fe_LS (degree_LS),
5070 *   degree_U(degree_U),
5071 *   dof_handler_U (triangulation),
5072 *   fe_U (degree_U),
5073 *   dof_handler_U_disp_field(triangulation),
5074 *   fe_U_disp_field(FE_Q<dim>(degree_U),dim),
5075 *   pcout (std::cout,(Utilities::MPI::this_mpi_process(mpi_communicator)== 0))
5076 *   {}
5077 *  
5078 *   template <int dim>
5079 *   TestLevelSet<dim>::~TestLevelSet ()
5080 *   {
5081 *   dof_handler_U_disp_field.clear();
5082 *   dof_handler_LS.clear ();
5083 *   dof_handler_U.clear ();
5084 *   }
5085 *  
5086 * @endcode
5087 *
5088 * VELOCITY
5089 * //////////
5090 *
5091 * @code
5092 *   template <int dim>
5093 *   void TestLevelSet<dim>::get_interpolated_velocity()
5094 *   {
5095 * @endcode
5096 *
5097 * velocity in x
5098 *
5099 * @code
5100 *   completely_distributed_solution_u = 0;
5101 *   VectorTools::interpolate(dof_handler_U,
5102 *   ExactU<dim>(PROBLEM,time),
5103 *   completely_distributed_solution_u);
5104 *   constraints.distribute (completely_distributed_solution_u);
5105 *   locally_relevant_solution_u = completely_distributed_solution_u;
5106 * @endcode
5107 *
5108 * velocity in y
5109 *
5110 * @code
5111 *   completely_distributed_solution_v = 0;
5112 *   VectorTools::interpolate(dof_handler_U,
5113 *   ExactV<dim>(PROBLEM,time),
5114 *   completely_distributed_solution_v);
5115 *   constraints.distribute (completely_distributed_solution_v);
5116 *   locally_relevant_solution_v = completely_distributed_solution_v;
5117 *   if (dim==3)
5118 *   {
5119 *   completely_distributed_solution_w = 0;
5120 *   VectorTools::interpolate(dof_handler_U,
5121 *   ExactW<dim>(PROBLEM,time),
5122 *   completely_distributed_solution_w);
5123 *   constraints.distribute (completely_distributed_solution_w);
5124 *   locally_relevant_solution_w = completely_distributed_solution_w;
5125 *   }
5126 *   }
5127 *  
5128 * @endcode
5129 *
5130 * //////////
5131 * BOUNDARY
5132 * //////////
5133 *
5134 * @code
5135 *   template <int dim>
5136 *   void TestLevelSet<dim>::set_boundary_inlet()
5137 *   {
5138 *   const QGauss<dim-1> face_quadrature_formula(1); // center of the face
5139 *   FEFaceValues<dim> fe_face_values (fe_U,face_quadrature_formula,
5140 *   update_values | update_quadrature_points |
5141 *   update_normal_vectors);
5142 *   const unsigned int n_face_q_points = face_quadrature_formula.size();
5143 *   std::vector<double> u_value (n_face_q_points);
5144 *   std::vector<double> v_value (n_face_q_points);
5145 *   std::vector<double> w_value (n_face_q_points);
5146 *  
5147 *   typename DoFHandler<dim>::active_cell_iterator
5148 *   cell_U = dof_handler_U.begin_active(),
5149 *   endc_U = dof_handler_U.end();
5150 *   Tensor<1,dim> u;
5151 *  
5152 *   for (; cell_U!=endc_U; ++cell_U)
5153 *   if (cell_U->is_locally_owned())
5154 *   for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
5155 *   if (cell_U->face(face)->at_boundary())
5156 *   {
5157 *   fe_face_values.reinit(cell_U,face);
5158 *   fe_face_values.get_function_values(locally_relevant_solution_u,u_value);
5159 *   fe_face_values.get_function_values(locally_relevant_solution_v,v_value);
5160 *   if (dim==3)
5161 *   fe_face_values.get_function_values(locally_relevant_solution_w,w_value);
5162 *   u[0]=u_value[0];
5163 *   u[1]=v_value[0];
5164 *   if (dim==3)
5165 *   u[2]=w_value[0];
5166 *   if (fe_face_values.normal_vector(0)*u < -1e-14)
5167 *   cell_U->face(face)->set_boundary_id(10);
5168 *   }
5169 *   }
5170 *  
5171 *   template <int dim>
5172 *   void TestLevelSet<dim>::get_boundary_values_phi(std::vector<unsigned int> &boundary_values_id_phi,
5173 *   std::vector<double> &boundary_values_phi)
5174 *   {
5175 *   std::map<unsigned int, double> map_boundary_values_phi;
5176 *   unsigned int boundary_id=0;
5177 *  
5178 *   set_boundary_inlet();
5179 *   boundary_id=10; // inlet
5180 *   VectorTools::interpolate_boundary_values (dof_handler_LS,
5181 *   boundary_id,BoundaryPhi<dim>(),
5182 *   map_boundary_values_phi);
5183 *  
5184 *   boundary_values_id_phi.resize(map_boundary_values_phi.size());
5185 *   boundary_values_phi.resize(map_boundary_values_phi.size());
5186 *   std::map<unsigned int,double>::const_iterator boundary_value_phi = map_boundary_values_phi.begin();
5187 *   for (int i=0; boundary_value_phi !=map_boundary_values_phi.end(); ++boundary_value_phi, ++i)
5188 *   {
5189 *   boundary_values_id_phi[i]=boundary_value_phi->first;
5190 *   boundary_values_phi[i]=boundary_value_phi->second;
5191 *   }
5192 *   }
5193 *  
5194 * @endcode
5195 *
5196 * ///////////////////////////////
5197 * SETUP AND INITIAL CONDITIONS
5198 * //////////////////////////////
5199 *
5200 * @code
5201 *   template <int dim>
5202 *   void TestLevelSet<dim>::setup()
5203 *   {
5204 *   degree = std::max(degree_LS,degree_U);
5205 * @endcode
5206 *
5207 * setup system LS
5208 *
5209 * @code
5210 *   dof_handler_LS.distribute_dofs (fe_LS);
5211 *   locally_owned_dofs_LS = dof_handler_LS.locally_owned_dofs ();
5212 *   locally_relevant_dofs_LS = DoFTools::extract_locally_relevant_dofs (dof_handler_LS);
5213 * @endcode
5214 *
5215 * setup system U
5216 *
5217 * @code
5218 *   dof_handler_U.distribute_dofs (fe_U);
5219 *   locally_owned_dofs_U = dof_handler_U.locally_owned_dofs ();
5220 *   locally_relevant_dofs_U = DoFTools::extract_locally_relevant_dofs (dof_handler_U);
5221 * @endcode
5222 *
5223 * setup system U for disp field
5224 *
5225 * @code
5226 *   dof_handler_U_disp_field.distribute_dofs (fe_U_disp_field);
5227 *   locally_owned_dofs_U_disp_field = dof_handler_U_disp_field.locally_owned_dofs ();
5228 *   locally_relevant_dofs_U_disp_field = DoFTools::extract_locally_relevant_dofs (dof_handler_U_disp_field);
5229 * @endcode
5230 *
5231 * init vectors for phi
5232 *
5233 * @code
5234 *   locally_relevant_solution_phi.reinit(locally_owned_dofs_LS,
5235 *   locally_relevant_dofs_LS,
5236 *   mpi_communicator);
5237 *   locally_relevant_solution_phi = 0;
5238 *   completely_distributed_solution_phi.reinit(mpi_communicator,
5239 *   dof_handler_LS.n_dofs(),
5240 *   dof_handler_LS.n_locally_owned_dofs());
5241 * @endcode
5242 *
5243 * init vectors for u
5244 *
5245 * @code
5246 *   locally_relevant_solution_u.reinit(locally_owned_dofs_U,
5247 *   locally_relevant_dofs_U,
5248 *   mpi_communicator);
5249 *   locally_relevant_solution_u = 0;
5250 *   completely_distributed_solution_u.reinit(mpi_communicator,
5251 *   dof_handler_U.n_dofs(),
5252 *   dof_handler_U.n_locally_owned_dofs());
5253 * @endcode
5254 *
5255 * init vectors for v
5256 *
5257 * @code
5258 *   locally_relevant_solution_v.reinit(locally_owned_dofs_U,
5259 *   locally_relevant_dofs_U,
5260 *   mpi_communicator);
5261 *   locally_relevant_solution_v = 0;
5262 *   completely_distributed_solution_v.reinit(mpi_communicator,
5263 *   dof_handler_U.n_dofs(),
5264 *   dof_handler_U.n_locally_owned_dofs());
5265 * @endcode
5266 *
5267 * init vectors for w
5268 *
5269 * @code
5270 *   locally_relevant_solution_w.reinit(locally_owned_dofs_U,
5271 *   locally_relevant_dofs_U,
5272 *   mpi_communicator);
5273 *   locally_relevant_solution_w = 0;
5274 *   completely_distributed_solution_w.reinit(mpi_communicator,
5275 *   dof_handler_U.n_dofs(),
5276 *   dof_handler_U.n_locally_owned_dofs());
5277 *   init_constraints();
5278 * @endcode
5279 *
5280 * MASS MATRIX
5281 *
5282 * @code
5283 *   DynamicSparsityPattern dsp (locally_relevant_dofs_LS);
5284 *   DoFTools::make_sparsity_pattern (dof_handler_LS,dsp,constraints,false);
5285 *  
5286 *   const std::vector<types::global_dof_index> n_locally_owned_dofs_per_processor =
5287 *   Utilities::MPI::all_gather(mpi_communicator, dof_handler_LS.n_locally_owned_dofs());
5288 *  
5289 *   SparsityTools::distribute_sparsity_pattern (dsp,
5290 *   n_locally_owned_dofs_per_processor,
5291 *   mpi_communicator,
5292 *   locally_relevant_dofs_LS);
5293 *   matrix_MC.reinit (mpi_communicator,
5294 *   dsp,
5295 *   n_locally_owned_dofs_per_processor,
5296 *   n_locally_owned_dofs_per_processor,
5297 *   Utilities::MPI::this_mpi_process(mpi_communicator));
5298 *   matrix_MC_tnm1.reinit (mpi_communicator,
5299 *   dsp,
5300 *   n_locally_owned_dofs_per_processor,
5301 *   n_locally_owned_dofs_per_processor,
5302 *   Utilities::MPI::this_mpi_process(mpi_communicator));
5303 *   }
5304 *  
5305 *   template <int dim>
5306 *   void TestLevelSet<dim>::initial_condition()
5307 *   {
5308 *   time=0;
5309 * @endcode
5310 *
5311 * Initial conditions
5312 * init condition for phi
5313 *
5314 * @code
5315 *   completely_distributed_solution_phi = 0;
5316 *   VectorTools::interpolate(dof_handler_LS,
5317 *   InitialPhi<dim>(PROBLEM, sharpness),
5318 * @endcode
5319 *
5320 * Functions::ZeroFunction<dim>(),
5321 *
5322 * @code
5323 *   completely_distributed_solution_phi);
5324 *   constraints.distribute (completely_distributed_solution_phi);
5325 *   locally_relevant_solution_phi = completely_distributed_solution_phi;
5326 * @endcode
5327 *
5328 * init condition for u=0
5329 *
5330 * @code
5331 *   completely_distributed_solution_u = 0;
5332 *   VectorTools::interpolate(dof_handler_U,
5333 *   ExactU<dim>(PROBLEM,time),
5334 *   completely_distributed_solution_u);
5335 *   constraints.distribute (completely_distributed_solution_u);
5336 *   locally_relevant_solution_u = completely_distributed_solution_u;
5337 * @endcode
5338 *
5339 * init condition for v
5340 *
5341 * @code
5342 *   completely_distributed_solution_v = 0;
5343 *   VectorTools::interpolate(dof_handler_U,
5344 *   ExactV<dim>(PROBLEM,time),
5345 *   completely_distributed_solution_v);
5346 *   constraints.distribute (completely_distributed_solution_v);
5347 *   locally_relevant_solution_v = completely_distributed_solution_v;
5348 *   }
5349 *  
5350 *   template <int dim>
5351 *   void TestLevelSet<dim>::init_constraints()
5352 *   {
5353 *   constraints.clear ();
5354 *   #if DEAL_II_VERSION_GTE(9, 6, 0)
5355 *   constraints.reinit (locally_owned_dofs_LS, locally_relevant_dofs_LS);
5356 *   #else
5357 *   constraints.reinit (locally_relevant_dofs_LS);
5358 *   #endif
5359 *   DoFTools::make_hanging_node_constraints (dof_handler_LS, constraints);
5360 *   constraints.close ();
5361 *   constraints_disp_field.clear ();
5362 *   #if DEAL_II_VERSION_GTE(9, 6, 0)
5363 *   constraints_disp_field.reinit (locally_owned_dofs_LS, locally_relevant_dofs_LS);
5364 *   #else
5365 *   constraints_disp_field.reinit (locally_relevant_dofs_LS);
5366 *   #endif
5367 *   DoFTools::make_hanging_node_constraints (dof_handler_LS, constraints_disp_field);
5368 *   constraints_disp_field.close ();
5369 *   }
5370 *  
5371 * @endcode
5372 *
5373 * /////////////////
5374 * POST PROCESSING
5375 * /////////////////
5376 *
5377 * @code
5378 *   template <int dim>
5379 *   void TestLevelSet<dim>::process_solution(parallel::distributed::Triangulation<dim> &triangulation,
5380 *   DoFHandler<dim> &dof_handler_LS,
5381 *   PETScWrappers::MPI::Vector &solution)
5382 *   {
5383 *   Vector<double> difference_per_cell (triangulation.n_active_cells());
5384 * @endcode
5385 *
5386 * error for phi
5387 *
5388 * @code
5389 *   VectorTools::integrate_difference (dof_handler_LS,
5390 *   solution,
5391 *   InitialPhi<dim>(PROBLEM,sharpness),
5392 *   difference_per_cell,
5393 *   QGauss<dim>(degree_LS+3),
5394 *   VectorTools::L1_norm);
5395 *  
5396 *   double u_L1_error = difference_per_cell.l1_norm();
5397 *   u_L1_error = std::sqrt(Utilities::MPI::sum(u_L1_error * u_L1_error, mpi_communicator));
5398 *  
5399 *   VectorTools::integrate_difference (dof_handler_LS,
5400 *   solution,
5401 *   InitialPhi<dim>(PROBLEM,sharpness),
5402 *   difference_per_cell,
5403 *   QGauss<dim>(degree_LS+3),
5404 *   VectorTools::L2_norm);
5405 *   double u_L2_error = difference_per_cell.l2_norm();
5406 *   u_L2_error = std::sqrt(Utilities::MPI::sum(u_L2_error * u_L2_error, mpi_communicator));
5407 *  
5408 *   pcout << "L1 error: " << u_L1_error << std::endl;
5409 *   pcout << "L2 error: " << u_L2_error << std::endl;
5410 *   }
5411 *  
5412 *   template<int dim>
5413 *   void TestLevelSet<dim>::output_results()
5414 *   {
5415 *   output_solution();
5416 *   output_number++;
5417 *   }
5418 *  
5419 *   template <int dim>
5420 *   void TestLevelSet<dim>::output_solution()
5421 *   {
5422 *   DataOut<dim> data_out;
5423 *   data_out.attach_dof_handler(dof_handler_LS);
5424 *   data_out.add_data_vector (locally_relevant_solution_phi, "phi");
5425 *   data_out.build_patches();
5426 *  
5427 *   const std::string filename = ("solution-" +
5428 *   Utilities::int_to_string (output_number, 3) +
5429 *   "." +
5430 *   Utilities::int_to_string
5431 *   (triangulation.locally_owned_subdomain(), 4));
5432 *   std::ofstream output ((filename + ".vtu").c_str());
5433 *   data_out.write_vtu (output);
5434 *  
5435 *   if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
5436 *   {
5437 *   std::vector<std::string> filenames;
5438 *   for (unsigned int i=0;
5439 *   i<Utilities::MPI::n_mpi_processes(mpi_communicator);
5440 *   ++i)
5441 *   filenames.push_back ("solution-" +
5442 *   Utilities::int_to_string (output_number, 3) +
5443 *   "." +
5444 *   Utilities::int_to_string (i, 4) +
5445 *   ".vtu");
5446 *  
5447 *   std::ofstream master_output ((filename + ".pvtu").c_str());
5448 *   data_out.write_pvtu_record (master_output, filenames);
5449 *   }
5450 *   }
5451 *  
5452 *   template <int dim>
5453 *   void TestLevelSet<dim>::run()
5454 *   {
5455 * @endcode
5456 *
5457 * ////////////////////
5458 * GENERAL PARAMETERS
5459 * ////////////////////
5460 *
5461 * @code
5462 *   cfl=0.1;
5463 *   verbose = false;
5464 *   get_output = true;
5465 *   output_number = 0;
5466 *   Timer t;
5467 *   n_refinement=6;
5468 *   output_time = 0.1;
5469 *   final_time = 1.0;
5470 *   PROBLEM=CIRCULAR_ROTATION;
5471 * @endcode
5472 *
5473 * PROBLEM=DIAGONAL_ADVECTION;
5474 *
5475 * @code
5476 *   double umax = 0;
5477 *   if (PROBLEM==CIRCULAR_ROTATION)
5478 *   umax = std::sqrt(2)*numbers::PI;
5479 *   else
5480 *   umax = std::sqrt(2);
5481 *  
5482 * @endcode
5483 *
5484 * //////////////////////////////////
5485 * PARAMETERS FOR TRANSPORT PROBLEM
5486 * //////////////////////////////////
5487 *
5488 * @code
5489 *   cK = 1.0; // compression constant
5490 *   cE = 1.0; // entropy viscosity constant
5491 *   sharpness_integer=1; //this will be multiplied by min_h
5492 * @endcode
5493 *
5494 * TRANSPORT_TIME_INTEGRATION=FORWARD_EULER;
5495 *
5496 * @code
5497 *   TRANSPORT_TIME_INTEGRATION=SSP33;
5498 * @endcode
5499 *
5500 * ALGORITHM = "MPP_u1";
5501 *
5502 * @code
5503 *   ALGORITHM = "NMPP_uH";
5504 * @endcode
5505 *
5506 * ALGORITHM = "MPP_uH";
5507 *
5508
5509 *
5510 * //////////
5511 * GEOMETRY
5512 * //////////
5513 *
5514 * @code
5515 *   if (PROBLEM==CIRCULAR_ROTATION || PROBLEM==DIAGONAL_ADVECTION)
5516 *   GridGenerator::hyper_cube(triangulation);
5517 * @endcode
5518 *
5519 * GridGenerator::hyper_rectangle(triangulation, Point<dim>(0.0,0.0), Point<dim>(1.0,1.0), true);
5520 *
5521 * @code
5522 *   triangulation.refine_global (n_refinement);
5523 *  
5524 * @endcode
5525 *
5526 * ///////
5527 * SETUP
5528 * ///////
5529 *
5530 * @code
5531 *   setup();
5532 *  
5533 * @endcode
5534 *
5535 * for Reconstruction of MATERIAL FIELDS
5536 *
5537 * @code
5538 *   min_h = GridTools::minimal_cell_diameter(triangulation)/std::sqrt(dim)/degree;
5539 *   eps=1*min_h; //For reconstruction of density in Navier Stokes
5540 *   sharpness=sharpness_integer*min_h; //adjust value of sharpness (for init cond of phi)
5541 *   rho_fluid = 1000;
5542 *   rho_air = 1;
5543 *  
5544 * @endcode
5545 *
5546 * GET TIME STEP
5547 *
5548 * @code
5549 *   time_step = cfl*min_h/umax;
5550 *  
5551 * @endcode
5552 *
5553 * //////////////////
5554 * TRANSPORT SOLVER
5555 * //////////////////
5556 *
5557 * @code
5558 *   LevelSetSolver<dim> level_set (degree_LS,degree_U,
5559 *   time_step,cK,cE,
5560 *   verbose,
5561 *   ALGORITHM,
5562 *   TRANSPORT_TIME_INTEGRATION,
5563 *   triangulation,
5564 *   mpi_communicator);
5565 *  
5566 * @endcode
5567 *
5568 * ///////////////////
5569 * INITIAL CONDITION
5570 * ///////////////////
5571 *
5572 * @code
5573 *   initial_condition();
5574 *   output_results();
5575 *   if (dim==2)
5576 *   level_set.initial_condition(locally_relevant_solution_phi,
5577 *   locally_relevant_solution_u,locally_relevant_solution_v);
5578 *   else //dim=3
5579 *   level_set.initial_condition(locally_relevant_solution_phi,
5580 *   locally_relevant_solution_u,locally_relevant_solution_v,locally_relevant_solution_w);
5581 *  
5582 * @endcode
5583 *
5584 * /////////////////////////////
5585 * BOUNDARY CONDITIONS FOR PHI
5586 * /////////////////////////////
5587 *
5588 * @code
5589 *   get_boundary_values_phi(boundary_values_id_phi,boundary_values_phi);
5590 *   level_set.set_boundary_conditions(boundary_values_id_phi,boundary_values_phi);
5591 *  
5592 * @endcode
5593 *
5594 * OUTPUT DATA REGARDING TIME STEPPING AND MESH
5595 *
5596 * @code
5597 *   int dofs_LS = dof_handler_LS.n_dofs();
5598 *   pcout << "Cfl: " << cfl << std::endl;
5599 *   pcout << " Number of active cells: "
5600 *   << triangulation.n_global_active_cells() << std::endl
5601 *   << " Number of degrees of freedom: " << std::endl
5602 *   << " LS: " << dofs_LS << std::endl;
5603 *  
5604 * @endcode
5605 *
5606 * TIME STEPPING
5607 *
5608 * @code
5609 *   timestep_number=0;
5610 *   time=0;
5611 *   while (time<final_time)
5612 *   {
5613 *   timestep_number++;
5614 *   if (time+time_step > final_time)
5615 *   {
5616 *   pcout << "FINAL TIME STEP... " << std::endl;
5617 *   time_step = final_time-time;
5618 *   }
5619 *   pcout << "Time step " << timestep_number
5620 *   << "\twith dt=" << time_step
5621 *   << "\tat tn=" << time << std::endl;
5622 *  
5623 * @endcode
5624 *
5625 * //////////////
5626 * GET VELOCITY // (NS or interpolate from a function) at current time tn
5627 * //////////////
5628 *
5629 * @code
5630 *   if (VARIABLE_VELOCITY)
5631 *   {
5632 *   get_interpolated_velocity();
5633 * @endcode
5634 *
5635 * SET VELOCITY TO LEVEL SET SOLVER
5636 *
5637 * @code
5638 *   level_set.set_velocity(locally_relevant_solution_u,locally_relevant_solution_v);
5639 *   }
5640 * @endcode
5641 *
5642 * ////////////////////////
5643 * GET LEVEL SET SOLUTION // (at tnp1)
5644 * ////////////////////////
5645 *
5646 * @code
5647 *   level_set.nth_time_step();
5648 *  
5649 * @endcode
5650 *
5651 * /////////////
5652 * UPDATE TIME
5653 * /////////////
5654 *
5655 * @code
5656 *   time+=time_step; // time tnp1
5657 *  
5658 * @endcode
5659 *
5660 * ////////
5661 * OUTPUT
5662 * ////////
5663 *
5664 * @code
5665 *   if (get_output && time-(output_number)*output_time>=0)
5666 *   {
5667 *   level_set.get_unp1(locally_relevant_solution_phi);
5668 *   output_results();
5669 *   }
5670 *   }
5671 *   pcout << "FINAL TIME T=" << time << std::endl;
5672 *   }
5673 *  
5674 *   int main(int argc, char *argv[])
5675 *   {
5676 *   try
5677 *   {
5678 *   using namespace dealii;
5679 *   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
5680 *   deallog.depth_console (0);
5681 *   {
5682 *   unsigned int degree = 1;
5683 *   TestLevelSet<2> multiphase(degree, degree);
5684 *   multiphase.run();
5685 *   }
5686 *   }
5687 *   catch (std::exception &exc)
5688 *   {
5689 *   std::cerr << std::endl << std::endl
5690 *   << "----------------------------------------------------"
5691 *   << std::endl;
5692 *   std::cerr << "Exception on processing: " << std::endl
5693 *   << exc.what() << std::endl
5694 *   << "Aborting!" << std::endl
5695 *   << "----------------------------------------------------"
5696 *   << std::endl;
5697 *   return 1;
5698 *   }
5699 *   catch (...)
5700 *   {
5701 *   std::cerr << std::endl << std::endl
5702 *   << "----------------------------------------------------"
5703 *   << std::endl;
5704 *   std::cerr << "Unknown exception!" << std::endl
5705 *   << "Aborting!" << std::endl
5706 *   << "----------------------------------------------------"
5707 *   << std::endl;
5708 *   return 1;
5709 *   }
5710 *   return 0;
5711 *   }
5712 *  
5713 *  
5714 * @endcode
5715
5716
5717<a name="ann-TestNavierStokes.cc"></a>
5718<h1>Annotated version of TestNavierStokes.cc</h1>
5719 *
5720 *
5721 *
5722 *
5723 * @code
5724 *   /* -----------------------------------------------------------------------------
5725 *   *
5726 *   * SPDX-License-Identifier: LGPL-2.1-or-later
5727 *   * Copyright (C) 2016 Manuel Quezada de Luna
5728 *   *
5729 *   * This file is part of the deal.II code gallery.
5730 *   *
5731 *   * -----------------------------------------------------------------------------
5732 *   */
5733 *  
5734 *   #include <deal.II/base/quadrature_lib.h>
5735 *   #include <deal.II/base/function.h>
5736 *   #include <deal.II/lac/affine_constraints.h>
5737 *   #include <deal.II/lac/vector.h>
5738 *   #include <deal.II/lac/full_matrix.h>
5739 *   #include <deal.II/lac/solver_cg.h>
5740 *   #include <deal.II/lac/petsc_sparse_matrix.h>
5741 *   #include <deal.II/lac/petsc_vector.h>
5742 *   #include <deal.II/lac/petsc_solver.h>
5743 *   #include <deal.II/lac/petsc_precondition.h>
5744 *   #include <deal.II/grid/grid_generator.h>
5745 *   #include <deal.II/grid/tria_accessor.h>
5746 *   #include <deal.II/grid/tria_iterator.h>
5747 *   #include <deal.II/dofs/dof_handler.h>
5748 *   #include <deal.II/dofs/dof_accessor.h>
5749 *   #include <deal.II/dofs/dof_tools.h>
5750 *   #include <deal.II/fe/fe_values.h>
5751 *   #include <deal.II/fe/fe_q.h>
5752 *   #include <deal.II/numerics/vector_tools.h>
5753 *   #include <deal.II/numerics/data_out.h>
5754 *   #include <deal.II/numerics/error_estimator.h>
5755 *   #include <deal.II/base/utilities.h>
5756 *   #include <deal.II/base/conditional_ostream.h>
5757 *   #include <deal.II/base/index_set.h>
5758 *   #include <deal.II/lac/sparsity_tools.h>
5759 *   #include <deal.II/distributed/tria.h>
5760 *   #include <deal.II/distributed/grid_refinement.h>
5761 *   #include <deal.II/lac/petsc_vector.h>
5762 *   #include <deal.II/base/convergence_table.h>
5763 *   #include <deal.II/base/timer.h>
5764 *   #include <deal.II/base/parameter_handler.h>
5765 *   #include <fstream>
5766 *   #include <iostream>
5767 *   #include <deal.II/grid/grid_tools.h>
5768 *   #include <deal.II/fe/mapping_q.h>
5769 *   #include <deal.II/base/function.h>
5770 *  
5771 *   using namespace dealii;
5772 *  
5773 *   #include "utilities_test_NS.cc"
5774 *   #include "NavierStokesSolver.cc"
5775 *  
5776 * @endcode
5777 *
5778 * ///////////////////////////////////////////////////
5779 * /////////////////// MAIN CLASS ////////////////////
5780 * ///////////////////////////////////////////////////
5781 *
5782 * @code
5783 *   template <int dim>
5784 *   class TestNavierStokes
5785 *   {
5786 *   public:
5787 *   TestNavierStokes (const unsigned int degree_LS,
5788 *   const unsigned int degree_U);
5789 *   ~TestNavierStokes ();
5790 *   void run ();
5791 *  
5792 *   private:
5793 *   void get_boundary_values_U(double t);
5794 *   void fix_pressure();
5795 *   void output_results();
5796 *   void process_solution(const unsigned int cycle);
5797 *   void setup();
5798 *   void initial_condition();
5799 *   void init_constraints();
5800 *  
5801 *   PETScWrappers::MPI::Vector locally_relevant_solution_rho;
5802 *   PETScWrappers::MPI::Vector locally_relevant_solution_u;
5803 *   PETScWrappers::MPI::Vector locally_relevant_solution_v;
5804 *   PETScWrappers::MPI::Vector locally_relevant_solution_w;
5805 *   PETScWrappers::MPI::Vector locally_relevant_solution_p;
5806 *   PETScWrappers::MPI::Vector completely_distributed_solution_rho;
5807 *   PETScWrappers::MPI::Vector completely_distributed_solution_u;
5808 *   PETScWrappers::MPI::Vector completely_distributed_solution_v;
5809 *   PETScWrappers::MPI::Vector completely_distributed_solution_w;
5810 *   PETScWrappers::MPI::Vector completely_distributed_solution_p;
5811 *  
5812 *   std::vector<unsigned int> boundary_values_id_u;
5813 *   std::vector<unsigned int> boundary_values_id_v;
5814 *   std::vector<unsigned int> boundary_values_id_w;
5815 *   std::vector<double> boundary_values_u;
5816 *   std::vector<double> boundary_values_v;
5817 *   std::vector<double> boundary_values_w;
5818 *  
5819 *   double rho_fluid;
5820 *   double nu_fluid;
5821 *   double rho_air;
5822 *   double nu_air;
5823 *  
5824 *   MPI_Comm mpi_communicator;
5825 *   parallel::distributed::Triangulation<dim> triangulation;
5826 *  
5827 *   int degree_LS;
5828 *   DoFHandler<dim> dof_handler_LS;
5829 *   FE_Q<dim> fe_LS;
5830 *   IndexSet locally_owned_dofs_LS;
5831 *   IndexSet locally_relevant_dofs_LS;
5832 *  
5833 *   int degree_U;
5834 *   DoFHandler<dim> dof_handler_U;
5835 *   FE_Q<dim> fe_U;
5836 *   IndexSet locally_owned_dofs_U;
5837 *   IndexSet locally_relevant_dofs_U;
5838 *  
5839 *   DoFHandler<dim> dof_handler_P;
5840 *   FE_Q<dim> fe_P;
5841 *   IndexSet locally_owned_dofs_P;
5842 *   IndexSet locally_relevant_dofs_P;
5843 *  
5844 *   AffineConstraints<double> constraints;
5845 *  
5846 * @endcode
5847 *
5848 * TimerOutput timer;
5849 *
5850
5851 *
5852 *
5853 * @code
5854 *   double time;
5855 *   double time_step;
5856 *   double final_time;
5857 *   unsigned int timestep_number;
5858 *   double cfl;
5859 *  
5860 *   double min_h;
5861 *  
5862 *   unsigned int n_cycles;
5863 *   unsigned int n_refinement;
5864 *   unsigned int output_number;
5865 *   double output_time;
5866 *   bool get_output;
5867 *  
5868 *   double h;
5869 *   double umax;
5870 *  
5871 *   bool verbose;
5872 *  
5873 *   ConditionalOStream pcout;
5874 *   ConvergenceTable convergence_table;
5875 *  
5876 *   double nu;
5877 *   };
5878 *  
5879 *   template <int dim>
5880 *   TestNavierStokes<dim>::TestNavierStokes (const unsigned int degree_LS,
5881 *   const unsigned int degree_U)
5882 *   :
5883 *   mpi_communicator (MPI_COMM_WORLD),
5884 *   triangulation (mpi_communicator,
5885 *   typename Triangulation<dim>::MeshSmoothing
5886 *   (Triangulation<dim>::smoothing_on_refinement |
5887 *   Triangulation<dim>::smoothing_on_coarsening)),
5888 *   degree_LS(degree_LS),
5889 *   dof_handler_LS (triangulation),
5890 *   fe_LS (degree_LS),
5891 *   degree_U(degree_U),
5892 *   dof_handler_U (triangulation),
5893 *   fe_U (degree_U),
5894 *   dof_handler_P (triangulation),
5895 *   fe_P (degree_U-1), //TODO: change this to be degree_Q-1
5896 * @endcode
5897 *
5898 * timer(std::cout, TimerOutput::summary, TimerOutput::wall_times),
5899 *
5900 * @code
5901 *   pcout (std::cout,(Utilities::MPI::this_mpi_process(mpi_communicator)== 0))
5902 *   {}
5903 *  
5904 *   template <int dim>
5905 *   TestNavierStokes<dim>::~TestNavierStokes ()
5906 *   {
5907 *   dof_handler_LS.clear ();
5908 *   dof_handler_U.clear ();
5909 *   dof_handler_P.clear ();
5910 *   }
5911 *  
5912 * @endcode
5913 *
5914 * /////////////////////////////////////
5915 * /////////////// SETUP ///////////////
5916 * /////////////////////////////////////
5917 *
5918 * @code
5919 *   template <int dim>
5920 *   void TestNavierStokes<dim>::setup()
5921 *   {
5922 * @endcode
5923 *
5924 * setup system LS
5925 *
5926 * @code
5927 *   dof_handler_LS.distribute_dofs (fe_LS);
5928 *   locally_owned_dofs_LS = dof_handler_LS.locally_owned_dofs ();
5929 *   locally_relevant_dofs_LS = DoFTools::extract_locally_relevant_dofs (dof_handler_LS);
5930 * @endcode
5931 *
5932 * setup system U
5933 *
5934 * @code
5935 *   dof_handler_U.distribute_dofs (fe_U);
5936 *   locally_owned_dofs_U = dof_handler_U.locally_owned_dofs ();
5937 *   locally_relevant_dofs_U = DoFTools::extract_locally_relevant_dofs (dof_handler_U);
5938 * @endcode
5939 *
5940 * setup system P
5941 *
5942 * @code
5943 *   dof_handler_P.distribute_dofs (fe_P);
5944 *   locally_owned_dofs_P = dof_handler_P.locally_owned_dofs ();
5945 *   locally_relevant_dofs_P = DoFTools::extract_locally_relevant_dofs (dof_handler_P);
5946 *   init_constraints();
5947 * @endcode
5948 *
5949 * init vectors for rho
5950 *
5951 * @code
5952 *   locally_relevant_solution_rho.reinit (locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
5953 *   locally_relevant_solution_rho = 0;
5954 *   completely_distributed_solution_rho.reinit(locally_owned_dofs_LS,mpi_communicator);
5955 * @endcode
5956 *
5957 * init vectors for u
5958 *
5959 * @code
5960 *   locally_relevant_solution_u.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
5961 *   locally_relevant_solution_u = 0;
5962 *   completely_distributed_solution_u.reinit(locally_owned_dofs_U,mpi_communicator);
5963 * @endcode
5964 *
5965 * init vectors for v
5966 *
5967 * @code
5968 *   locally_relevant_solution_v.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
5969 *   locally_relevant_solution_v = 0;
5970 *   completely_distributed_solution_v.reinit(locally_owned_dofs_U,mpi_communicator);
5971 * @endcode
5972 *
5973 * init vectors for w
5974 *
5975 * @code
5976 *   locally_relevant_solution_w.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
5977 *   locally_relevant_solution_w = 0;
5978 *   completely_distributed_solution_w.reinit(locally_owned_dofs_U,mpi_communicator);
5979 * @endcode
5980 *
5981 * init vectors for p
5982 *
5983 * @code
5984 *   locally_relevant_solution_p.reinit(locally_owned_dofs_P,locally_relevant_dofs_P,mpi_communicator);
5985 *   locally_relevant_solution_p = 0;
5986 *   completely_distributed_solution_p.reinit(locally_owned_dofs_P,mpi_communicator);
5987 *   }
5988 *  
5989 *   template <int dim>
5990 *   void TestNavierStokes<dim>::initial_condition()
5991 *   {
5992 *   time=0;
5993 * @endcode
5994 *
5995 * Initial conditions
5996 * init condition for rho
5997 *
5998 * @code
5999 *   completely_distributed_solution_rho = 0;
6000 *   VectorTools::interpolate(dof_handler_LS,
6001 *   RhoFunction<dim>(0),
6002 *   completely_distributed_solution_rho);
6003 *   constraints.distribute (completely_distributed_solution_rho);
6004 *   locally_relevant_solution_rho = completely_distributed_solution_rho;
6005 * @endcode
6006 *
6007 * init condition for u
6008 *
6009 * @code
6010 *   completely_distributed_solution_u = 0;
6011 *   VectorTools::interpolate(dof_handler_U,
6012 *   ExactSolution_and_BC_U<dim>(0,0),
6013 *   completely_distributed_solution_u);
6014 *   constraints.distribute (completely_distributed_solution_u);
6015 *   locally_relevant_solution_u = completely_distributed_solution_u;
6016 * @endcode
6017 *
6018 * init condition for v
6019 *
6020 * @code
6021 *   completely_distributed_solution_v = 0;
6022 *   VectorTools::interpolate(dof_handler_U,
6023 *   ExactSolution_and_BC_U<dim>(0,1),
6024 *   completely_distributed_solution_v);
6025 *   constraints.distribute (completely_distributed_solution_v);
6026 *   locally_relevant_solution_v = completely_distributed_solution_v;
6027 * @endcode
6028 *
6029 * init condition for w
6030 *
6031 * @code
6032 *   if (dim == 3)
6033 *   {
6034 *   completely_distributed_solution_w = 0;
6035 *   VectorTools::interpolate(dof_handler_U,
6036 *   ExactSolution_and_BC_U<dim>(0,2),
6037 *   completely_distributed_solution_w);
6038 *   constraints.distribute (completely_distributed_solution_w);
6039 *   locally_relevant_solution_w = completely_distributed_solution_w;
6040 *   }
6041 * @endcode
6042 *
6043 * init condition for p
6044 *
6045 * @code
6046 *   completely_distributed_solution_p = 0;
6047 *   VectorTools::interpolate(dof_handler_P,
6048 *   ExactSolution_p<dim>(0),
6049 *   completely_distributed_solution_p);
6050 *   constraints.distribute (completely_distributed_solution_p);
6051 *   locally_relevant_solution_p = completely_distributed_solution_p;
6052 *   }
6053 *  
6054 *   template <int dim>
6055 *   void TestNavierStokes<dim>::init_constraints()
6056 *   {
6057 *   constraints.clear ();
6058 *   #if DEAL_II_VERSION_GTE(9, 6, 0)
6059 *   constraints.reinit (locally_owned_dofs_LS, locally_relevant_dofs_LS);
6060 *   #else
6061 *   constraints.reinit (locally_relevant_dofs_LS);
6062 *   #endif
6063 *   DoFTools::make_hanging_node_constraints (dof_handler_LS, constraints);
6064 *   constraints.close ();
6065 *   }
6066 *  
6067 *   template<int dim>
6068 *   void TestNavierStokes<dim>::fix_pressure()
6069 *   {
6070 * @endcode
6071 *
6072 * fix the constant in the pressure
6073 *
6074 * @code
6075 *   completely_distributed_solution_p = locally_relevant_solution_p;
6076 *   double mean_value = VectorTools::compute_mean_value(dof_handler_P,
6077 *   QGauss<dim>(3),
6078 *   locally_relevant_solution_p,
6079 *   0);
6080 *   if (dim==2)
6081 *   completely_distributed_solution_p.add(-mean_value+std::sin(1)*(std::cos(time)-cos(1+time)));
6082 *   else
6083 *   completely_distributed_solution_p.add(-mean_value+8*std::pow(std::sin(0.5),3)*std::sin(1.5+time));
6084 *   locally_relevant_solution_p = completely_distributed_solution_p;
6085 *   }
6086 *  
6087 *   template <int dim>
6088 *   void TestNavierStokes<dim>::output_results ()
6089 *   {
6090 *   DataOut<dim> data_out;
6091 *   data_out.attach_dof_handler (dof_handler_U);
6092 *   data_out.add_data_vector (locally_relevant_solution_u, "u");
6093 *   data_out.add_data_vector (locally_relevant_solution_v, "v");
6094 *   if (dim==3) data_out.add_data_vector (locally_relevant_solution_w, "w");
6095 *  
6096 *   Vector<float> subdomain (triangulation.n_active_cells());
6097 *   for (unsigned int i=0; i<subdomain.size(); ++i)
6098 *   subdomain(i) = triangulation.locally_owned_subdomain();
6099 *   data_out.add_data_vector (subdomain, "subdomain");
6100 *  
6101 *   data_out.build_patches ();
6102 *  
6103 *   const std::string filename = ("solution-" +
6104 *   Utilities::int_to_string (output_number, 3) +
6105 *   "." +
6106 *   Utilities::int_to_string
6107 *   (triangulation.locally_owned_subdomain(), 4));
6108 *   std::ofstream output ((filename + ".vtu").c_str());
6109 *   data_out.write_vtu (output);
6110 *  
6111 *   if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
6112 *   {
6113 *   std::vector<std::string> filenames;
6114 *   for (unsigned int i=0;
6115 *   i<Utilities::MPI::n_mpi_processes(mpi_communicator);
6116 *   ++i)
6117 *   filenames.push_back ("solution-" +
6118 *   Utilities::int_to_string (output_number, 3) +
6119 *   "." +
6120 *   Utilities::int_to_string (i, 4) +
6121 *   ".vtu");
6122 *  
6123 *   std::ofstream master_output ((filename + ".pvtu").c_str());
6124 *   data_out.write_pvtu_record (master_output, filenames);
6125 *   }
6126 *   output_number++;
6127 *   }
6128 *  
6129 *   template <int dim>
6130 *   void TestNavierStokes<dim>::process_solution(const unsigned int cycle)
6131 *   {
6132 *   Vector<double> difference_per_cell (triangulation.n_active_cells());
6133 * @endcode
6134 *
6135 * error for u
6136 *
6137 * @code
6138 *   VectorTools::integrate_difference (dof_handler_U,
6139 *   locally_relevant_solution_u,
6140 *   ExactSolution_and_BC_U<dim>(time,0),
6141 *   difference_per_cell,
6142 *   QGauss<dim>(degree_U+1),
6143 *   VectorTools::L2_norm);
6144 *   double u_L2_error = difference_per_cell.l2_norm();
6145 *   u_L2_error =
6146 *   std::sqrt(Utilities::MPI::sum(u_L2_error * u_L2_error, mpi_communicator));
6147 *   VectorTools::integrate_difference (dof_handler_U,
6148 *   locally_relevant_solution_u,
6149 *   ExactSolution_and_BC_U<dim>(time,0),
6150 *   difference_per_cell,
6151 *   QGauss<dim>(degree_U+1),
6152 *   VectorTools::H1_norm);
6153 *   double u_H1_error = difference_per_cell.l2_norm();
6154 *   u_H1_error =
6155 *   std::sqrt(Utilities::MPI::sum(u_H1_error * u_H1_error, mpi_communicator));
6156 * @endcode
6157 *
6158 * error for v
6159 *
6160 * @code
6161 *   VectorTools::integrate_difference (dof_handler_U,
6162 *   locally_relevant_solution_v,
6163 *   ExactSolution_and_BC_U<dim>(time,1),
6164 *   difference_per_cell,
6165 *   QGauss<dim>(degree_U+1),
6166 *   VectorTools::L2_norm);
6167 *   double v_L2_error = difference_per_cell.l2_norm();
6168 *   v_L2_error =
6169 *   std::sqrt(Utilities::MPI::sum(v_L2_error * v_L2_error,
6170 *   mpi_communicator));
6171 *   VectorTools::integrate_difference (dof_handler_U,
6172 *   locally_relevant_solution_v,
6173 *   ExactSolution_and_BC_U<dim>(time,1),
6174 *   difference_per_cell,
6175 *   QGauss<dim>(degree_U+1),
6176 *   VectorTools::H1_norm);
6177 *   double v_H1_error = difference_per_cell.l2_norm();
6178 *   v_H1_error =
6179 *   std::sqrt(Utilities::MPI::sum(v_H1_error *
6180 *   v_H1_error, mpi_communicator));
6181 * @endcode
6182 *
6183 * error for w
6184 *
6185 * @code
6186 *   double w_L2_error = 0;
6187 *   double w_H1_error = 0;
6188 *   if (dim == 3)
6189 *   {
6190 *   VectorTools::integrate_difference (dof_handler_U,
6191 *   locally_relevant_solution_w,
6192 *   ExactSolution_and_BC_U<dim>(time,2),
6193 *   difference_per_cell,
6194 *   QGauss<dim>(degree_U+1),
6195 *   VectorTools::L2_norm);
6196 *   w_L2_error = difference_per_cell.l2_norm();
6197 *   w_L2_error =
6198 *   std::sqrt(Utilities::MPI::sum(w_L2_error * w_L2_error,
6199 *   mpi_communicator));
6200 *   VectorTools::integrate_difference (dof_handler_U,
6201 *   locally_relevant_solution_w,
6202 *   ExactSolution_and_BC_U<dim>(time,2),
6203 *   difference_per_cell,
6204 *   QGauss<dim>(degree_U+1),
6205 *   VectorTools::H1_norm);
6206 *   w_H1_error = difference_per_cell.l2_norm();
6207 *   w_H1_error =
6208 *   std::sqrt(Utilities::MPI::sum(w_H1_error *
6209 *   w_H1_error, mpi_communicator));
6210 *   }
6211 * @endcode
6212 *
6213 * error for p
6214 *
6215 * @code
6216 *   VectorTools::integrate_difference (dof_handler_P,
6217 *   locally_relevant_solution_p,
6218 *   ExactSolution_p<dim>(time),
6219 *   difference_per_cell,
6220 *   QGauss<dim>(degree_U+1),
6221 *   VectorTools::L2_norm);
6222 *   double p_L2_error = difference_per_cell.l2_norm();
6223 *   p_L2_error =
6224 *   std::sqrt(Utilities::MPI::sum(p_L2_error * p_L2_error,
6225 *   mpi_communicator));
6226 *   VectorTools::integrate_difference (dof_handler_P,
6227 *   locally_relevant_solution_p,
6228 *   ExactSolution_p<dim>(time),
6229 *   difference_per_cell,
6230 *   QGauss<dim>(degree_U+1),
6231 *   VectorTools::H1_norm);
6232 *   double p_H1_error = difference_per_cell.l2_norm();
6233 *   p_H1_error =
6234 *   std::sqrt(Utilities::MPI::sum(p_H1_error * p_H1_error,
6235 *   mpi_communicator));
6236 *  
6237 *   const unsigned int n_active_cells=triangulation.n_active_cells();
6238 *   const unsigned int n_dofs_U=dof_handler_U.n_dofs();
6239 *   const unsigned int n_dofs_P=dof_handler_P.n_dofs();
6240 *  
6241 *   convergence_table.add_value("cycle", cycle);
6242 *   convergence_table.add_value("cells", n_active_cells);
6243 *   convergence_table.add_value("dofs_U", n_dofs_U);
6244 *   convergence_table.add_value("dofs_P", n_dofs_P);
6245 *   convergence_table.add_value("dt", time_step);
6246 *   convergence_table.add_value("u L2", u_L2_error);
6247 *   convergence_table.add_value("u H1", u_H1_error);
6248 *   convergence_table.add_value("v L2", v_L2_error);
6249 *   convergence_table.add_value("v H1", v_H1_error);
6250 *   if (dim==3)
6251 *   {
6252 *   convergence_table.add_value("w L2", w_L2_error);
6253 *   convergence_table.add_value("w H1", w_H1_error);
6254 *   }
6255 *   convergence_table.add_value("p L2", p_L2_error);
6256 *   convergence_table.add_value("p H1", p_H1_error);
6257 *   }
6258 *  
6259 *   template <int dim>
6260 *   void TestNavierStokes<dim>::get_boundary_values_U(double t)
6261 *   {
6262 *   std::map<unsigned int, double> map_boundary_values_u;
6263 *   std::map<unsigned int, double> map_boundary_values_v;
6264 *  
6265 *   VectorTools::interpolate_boundary_values (dof_handler_U,0,ExactSolution_and_BC_U<dim>(t,0),map_boundary_values_u);
6266 *   VectorTools::interpolate_boundary_values (dof_handler_U,0,ExactSolution_and_BC_U<dim>(t,1),map_boundary_values_v);
6267 *  
6268 *   boundary_values_id_u.resize(map_boundary_values_u.size());
6269 *   boundary_values_id_v.resize(map_boundary_values_v.size());
6270 *   boundary_values_u.resize(map_boundary_values_u.size());
6271 *   boundary_values_v.resize(map_boundary_values_v.size());
6272 *   std::map<unsigned int,double>::const_iterator boundary_value_u =map_boundary_values_u.begin();
6273 *   std::map<unsigned int,double>::const_iterator boundary_value_v =map_boundary_values_v.begin();
6274 *   if (dim==3)
6275 *   {
6276 *   std::map<unsigned int, double> map_boundary_values_w;
6277 *   VectorTools::interpolate_boundary_values (dof_handler_U,0,ExactSolution_and_BC_U<dim>(t,2),map_boundary_values_w);
6278 *   boundary_values_id_w.resize(map_boundary_values_w.size());
6279 *   boundary_values_w.resize(map_boundary_values_w.size());
6280 *   std::map<unsigned int,double>::const_iterator boundary_value_w =map_boundary_values_w.begin();
6281 *   for (int i=0; boundary_value_w !=map_boundary_values_w.end(); ++boundary_value_w, ++i)
6282 *   {
6283 *   boundary_values_id_w[i]=boundary_value_w->first;
6284 *   boundary_values_w[i]=boundary_value_w->second;
6285 *   }
6286 *   }
6287 *   for (int i=0; boundary_value_u !=map_boundary_values_u.end(); ++boundary_value_u, ++i)
6288 *   {
6289 *   boundary_values_id_u[i]=boundary_value_u->first;
6290 *   boundary_values_u[i]=boundary_value_u->second;
6291 *   }
6292 *   for (int i=0; boundary_value_v !=map_boundary_values_v.end(); ++boundary_value_v, ++i)
6293 *   {
6294 *   boundary_values_id_v[i]=boundary_value_v->first;
6295 *   boundary_values_v[i]=boundary_value_v->second;
6296 *   }
6297 *   }
6298 *  
6299 *   template <int dim>
6300 *   void TestNavierStokes<dim>::run()
6301 *   {
6302 *   if (Utilities::MPI::this_mpi_process(mpi_communicator)== 0)
6303 *   {
6304 *   std::cout << "***** CONVERGENCE TEST FOR NS *****" << std::endl;
6305 *   std::cout << "DEGREE LS: " << degree_LS << std::endl;
6306 *   std::cout << "DEGREE U: " << degree_U << std::endl;
6307 *   }
6308 * @endcode
6309 *
6310 * PARAMETERS FOR THE NAVIER STOKES PROBLEM
6311 *
6312 * @code
6313 *   final_time = 1.0;
6314 *   time_step=0.1;
6315 *   n_cycles=6;
6316 *   n_refinement=6;
6317 *   ForceTerms<dim> force_function;
6318 *   RhoFunction<dim> rho_function;
6319 *   NuFunction<dim> nu_function;
6320 *  
6321 *   output_time=0.1;
6322 *   output_number=0;
6323 *   bool get_output = false;
6324 *   bool get_error = true;
6325 *   verbose = true;
6326 *  
6327 *   for (unsigned int cycle=0; cycle<n_cycles; ++cycle)
6328 *   {
6329 *   if (cycle == 0)
6330 *   {
6331 *   GridGenerator::hyper_cube (triangulation);
6332 *   triangulation.refine_global (n_refinement);
6333 *   setup();
6334 *   initial_condition();
6335 *   }
6336 *   else
6337 *   {
6338 *   triangulation.refine_global(1);
6339 *   setup();
6340 *   initial_condition();
6341 *   time_step*=0.5;
6342 *   }
6343 *  
6344 *   output_results();
6345 * @endcode
6346 *
6347 * if (cycle==0)
6348 *
6349 * @code
6350 *   NavierStokesSolver<dim> navier_stokes (degree_LS,
6351 *   degree_U,
6352 *   time_step,
6353 *   force_function,
6354 *   rho_function,
6355 *   nu_function,
6356 *   verbose,
6357 *   triangulation,
6358 *   mpi_communicator);
6359 * @endcode
6360 *
6361 * set INITIAL CONDITION within TRANSPORT PROBLEM
6362 *
6363 * @code
6364 *   if (dim==2)
6365 *   navier_stokes.initial_condition(locally_relevant_solution_rho,
6366 *   locally_relevant_solution_u,
6367 *   locally_relevant_solution_v,
6368 *   locally_relevant_solution_p);
6369 *   else //dim=3
6370 *   navier_stokes.initial_condition(locally_relevant_solution_rho,
6371 *   locally_relevant_solution_u,
6372 *   locally_relevant_solution_v,
6373 *   locally_relevant_solution_w,
6374 *   locally_relevant_solution_p);
6375 *  
6376 *   pcout << "Cycle " << cycle << ':' << std::endl;
6377 *   pcout << " Cycle " << cycle
6378 *   << " Number of active cells: "
6379 *   << triangulation.n_global_active_cells() << std::endl
6380 *   << " Number of degrees of freedom (velocity): "
6381 *   << dof_handler_U.n_dofs() << std::endl
6382 *   << " min h=" << GridTools::minimal_cell_diameter(triangulation)/std::sqrt(2)/degree_U
6383 *   << std::endl;
6384 *  
6385 * @endcode
6386 *
6387 * TIME STEPPING
6388 *
6389 * @code
6390 *   timestep_number=0;
6391 *   time=0;
6392 *   double time_step_backup=time_step;
6393 *   while (time<final_time)
6394 *   {
6395 *   timestep_number++;
6396 * @endcode
6397 *
6398 * ///////////////
6399 * GET TIME_STEP
6400 * ///////////////
6401 *
6402 * @code
6403 *   if (time+time_step > final_time-1E-10)
6404 *   {
6405 *   pcout << "FINAL TIME STEP..." << std::endl;
6406 *   time_step_backup=time_step;
6407 *   time_step=final_time-time;
6408 *   }
6409 *   pcout << "Time step " << timestep_number
6410 *   << "\twith dt=" << time_step
6411 *   << "\tat tn=" << time
6412 *   << std::endl;
6413 * @endcode
6414 *
6415 * /////////////
6416 * FORCE TERMS
6417 * /////////////
6418 *
6419 * @code
6420 *   force_function.set_time(time+time_step);
6421 * @endcode
6422 *
6423 * /////////////////////////////
6424 * DENSITY AND VISCOSITY FIELD
6425 * /////////////////////////////
6426 *
6427 * @code
6428 *   rho_function.set_time(time+time_step);
6429 *   nu_function.set_time(time+time_step);
6430 * @endcode
6431 *
6432 * /////////////////////
6433 * BOUNDARY CONDITIONS
6434 * /////////////////////
6435 *
6436 * @code
6437 *   get_boundary_values_U(time+time_step);
6438 *   if (dim==2) navier_stokes.set_boundary_conditions(boundary_values_id_u, boundary_values_id_v,
6439 *   boundary_values_u, boundary_values_v);
6440 *   else navier_stokes.set_boundary_conditions(boundary_values_id_u,
6441 *   boundary_values_id_v,
6442 *   boundary_values_id_w,
6443 *   boundary_values_u, boundary_values_v, boundary_values_w);
6444 * @endcode
6445 *
6446 * //////////////
6447 * GET SOLUTION
6448 * //////////////
6449 *
6450 * @code
6451 *   navier_stokes.nth_time_step();
6452 *   if (dim==2)
6453 *   navier_stokes.get_velocity(locally_relevant_solution_u,locally_relevant_solution_v);
6454 *   else
6455 *   navier_stokes.get_velocity(locally_relevant_solution_u,
6456 *   locally_relevant_solution_v,
6457 *   locally_relevant_solution_w);
6458 *   navier_stokes.get_pressure(locally_relevant_solution_p);
6459 *  
6460 * @endcode
6461 *
6462 * //////////////
6463 * FIX PRESSURE
6464 * //////////////
6465 *
6466 * @code
6467 *   fix_pressure();
6468 *  
6469 * @endcode
6470 *
6471 * /////////////
6472 * UPDATE TIME
6473 * /////////////
6474 *
6475 * @code
6476 *   time+=time_step;
6477 *  
6478 * @endcode
6479 *
6480 * ////////
6481 * OUTPUT
6482 * ////////
6483 *
6484 * @code
6485 *   if (get_output && time-(output_number)*output_time>=1E-10)
6486 *   output_results();
6487 *   }
6488 *   pcout << "FINAL TIME: " << time << std::endl;
6489 *   time_step=time_step_backup;
6490 *   if (get_error)
6491 *   process_solution(cycle);
6492 *  
6493 *   if (get_error)
6494 *   {
6495 *   convergence_table.set_precision("u L2", 2);
6496 *   convergence_table.set_precision("u H1", 2);
6497 *   convergence_table.set_scientific("u L2",true);
6498 *   convergence_table.set_scientific("u H1",true);
6499 *  
6500 *   convergence_table.set_precision("v L2", 2);
6501 *   convergence_table.set_precision("v H1", 2);
6502 *   convergence_table.set_scientific("v L2",true);
6503 *   convergence_table.set_scientific("v H1",true);
6504 *  
6505 *   if (dim==3)
6506 *   {
6507 *   convergence_table.set_precision("w L2", 2);
6508 *   convergence_table.set_precision("w H1", 2);
6509 *   convergence_table.set_scientific("w L2",true);
6510 *   convergence_table.set_scientific("w H1",true);
6511 *   }
6512 *  
6513 *   convergence_table.set_precision("p L2", 2);
6514 *   convergence_table.set_precision("p H1", 2);
6515 *   convergence_table.set_scientific("p L2",true);
6516 *   convergence_table.set_scientific("p H1",true);
6517 *  
6518 *   convergence_table.set_tex_format("cells","r");
6519 *   convergence_table.set_tex_format("dofs_U","r");
6520 *   convergence_table.set_tex_format("dofs_P","r");
6521 *   convergence_table.set_tex_format("dt","r");
6522 *  
6523 *   if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
6524 *   {
6525 *   std::cout << std::endl;
6526 *   convergence_table.write_text(std::cout);
6527 *   }
6528 *   }
6529 *   }
6530 *   }
6531 *  
6532 *   int main(int argc, char *argv[])
6533 *   {
6534 *   try
6535 *   {
6536 *   using namespace dealii;
6537 *   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
6538 *   deallog.depth_console (0);
6539 *   {
6540 *   unsigned int degree_LS = 1;
6541 *   unsigned int degree_U = 2;
6542 *   TestNavierStokes<2> test_navier_stokes(degree_LS, degree_U);
6543 *   test_navier_stokes.run();
6544 *   }
6545 *   }
6546 *  
6547 *   catch (std::exception &exc)
6548 *   {
6549 *   std::cerr << std::endl << std::endl
6550 *   << "----------------------------------------------------"
6551 *   << std::endl;
6552 *   std::cerr << "Exception on processing: " << std::endl
6553 *   << exc.what() << std::endl
6554 *   << "Aborting!" << std::endl
6555 *   << "----------------------------------------------------"
6556 *   << std::endl;
6557 *  
6558 *   return 1;
6559 *   }
6560 *   catch (...)
6561 *   {
6562 *   std::cerr << std::endl << std::endl
6563 *   << "----------------------------------------------------"
6564 *   << std::endl;
6565 *   std::cerr << "Unknown exception!" << std::endl
6566 *   << "Aborting!" << std::endl
6567 *   << "----------------------------------------------------"
6568 *   << std::endl;
6569 *   return 1;
6570 *   }
6571 *  
6572 *   return 0;
6573 *   }
6574 * @endcode
6575
6576
6577<a name="ann-clean.sh"></a>
6578<h1>Annotated version of clean.sh</h1>
6579@code{.sh}
6580rm -rf CMakeFiles CMakeCache.txt Makefile cmake_install.cmake *~
6581rm -f MultiPhase TestLevelSet TestNavierStokes
6582rm -f sol*
6583rm -f *#*
6584rm -f *.visit
6585@endcode
6586
6587
6588<a name="ann-utilities.cc"></a>
6589<h1>Annotated version of utilities.cc</h1>
6590 *
6591 *
6592 *
6593 *
6594 * @code
6595 *   /* -----------------------------------------------------------------------------
6596 *   *
6597 *   * SPDX-License-Identifier: LGPL-2.1-or-later
6598 *   * Copyright (C) 2016 Manuel Quezada de Luna
6599 *   *
6600 *   * This file is part of the deal.II code gallery.
6601 *   *
6602 *   * -----------------------------------------------------------------------------
6603 *   */
6604 *  
6605 * @endcode
6606 *
6607 * /////////////////////////////////////////////////
6608 * ////////////////// INITIAL PHI //////////////////
6609 * /////////////////////////////////////////////////
6610 *
6611 * @code
6612 *   template <int dim>
6613 *   class InitialPhi : public Function <dim>
6614 *   {
6615 *   public:
6616 *   InitialPhi (unsigned int PROBLEM, double sharpness=0.005) : Function<dim>(),
6617 *   sharpness(sharpness),
6618 *   PROBLEM(PROBLEM) {}
6619 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const override;
6620 *   double sharpness;
6621 *   unsigned int PROBLEM;
6622 *   };
6623 *   template <int dim>
6624 *   double InitialPhi<dim>::value (const Point<dim> &p,
6625 *   const unsigned int) const
6626 *   {
6627 *   double x = p[0];
6628 *   double y = p[1];
6629 *   double pi=numbers::PI;
6630 *  
6631 *   if (PROBLEM==FILLING_TANK)
6632 *   return 0.5*(-std::tanh((y-0.3)/sharpness)*std::tanh((y-0.35)/sharpness)+1)
6633 *   *(-std::tanh((x-0.02)/sharpness)+1)-1;
6634 *   else if (PROBLEM==BREAKING_DAM)
6635 *   return 0.5*(-std::tanh((x-0.35)/sharpness)*std::tanh((x-0.65)/sharpness)+1)
6636 *   *(1-std::tanh((y-0.35)/sharpness))-1;
6637 *   else if (PROBLEM==FALLING_DROP)
6638 *   {
6639 *   double x0=0.15;
6640 *   double y0=0.75;
6641 *   double r0=0.1;
6642 *   double r = std::sqrt(std::pow(x-x0,2)+std::pow(y-y0,2));
6643 *   return 1-(std::tanh((r-r0)/sharpness)+std::tanh((y-0.3)/sharpness));
6644 *   }
6645 *   else if (PROBLEM==SMALL_WAVE_PERTURBATION)
6646 *   {
6647 *   double wave = 0.1*std::sin(pi*x)+0.25;
6648 *   return -std::tanh((y-wave)/sharpness);
6649 *   }
6650 *   else
6651 *   {
6652 *   std::cout << "Error in type of PROBLEM" << std::endl;
6653 *   abort();
6654 *   }
6655 *   }
6656 *  
6657 * @endcode
6658 *
6659 * ///////////////////////////////////////////////////
6660 * ////////////////// FORCE TERMS ///// //////////////
6661 * ///////////////////////////////////////////////////
6662 *
6663 * @code
6664 *   template <int dim>
6665 *   class ForceTerms : public Functions::ConstantFunction <dim>
6666 *   {
6667 *   public:
6668 *   ForceTerms (const std::vector<double> values) : Functions::ConstantFunction<dim>(values) {}
6669 *   };
6670 *  
6671 * @endcode
6672 *
6673 * /////////////////////////////////////////////////
6674 * ////////////////// BOUNDARY PHI /////////////////
6675 * /////////////////////////////////////////////////
6676 *
6677 * @code
6678 *   template <int dim>
6679 *   class BoundaryPhi : public Functions::ConstantFunction <dim>
6680 *   {
6681 *   public:
6682 *   BoundaryPhi (const double value, const unsigned int n_components=1) : Functions::ConstantFunction<dim>(value,n_components) {}
6683 *   };
6684 *  
6685 * @endcode
6686 *
6687 * //////////////////////////////////////////////////////
6688 * ////////////////// BOUNDARY VELOCITY /////////////////
6689 * //////////////////////////////////////////////////////
6690 *
6691 * @code
6692 *   template <int dim>
6693 *   class BoundaryU : public Function <dim>
6694 *   {
6695 *   public:
6696 *   BoundaryU (unsigned int PROBLEM, double t=0) : Function<dim>(), PROBLEM(PROBLEM) {this->set_time(t);}
6697 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const override;
6698 *   unsigned PROBLEM;
6699 *   };
6700 *   template <int dim>
6701 *   double BoundaryU<dim>::value (const Point<dim> &p, const unsigned int) const
6702 *   {
6703 * @endcode
6704 *
6705 * //////////////////
6706 * FILLING THE TANK
6707 * //////////////////
6708 * boundary for filling the tank (inlet)
6709 *
6710 * @code
6711 *   double x = p[0];
6712 *   double y = p[1];
6713 *  
6714 *   if (PROBLEM==FILLING_TANK)
6715 *   {
6716 *   if (x==0 && y>=0.3 && y<=0.35)
6717 *   return 0.25;
6718 *   else
6719 *   return 0.0;
6720 *   }
6721 *   else
6722 *   {
6723 *   std::cout << "Error in PROBLEM definition" << std::endl;
6724 *   abort();
6725 *   }
6726 *   }
6727 *  
6728 *   template <int dim>
6729 *   class BoundaryV : public Function <dim>
6730 *   {
6731 *   public:
6732 *   BoundaryV (unsigned int PROBLEM, double t=0) : Function<dim>(), PROBLEM(PROBLEM) {this->set_time(t);}
6733 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const override;
6734 *   unsigned int PROBLEM;
6735 *   };
6736 *   template <int dim>
6737 *   double BoundaryV<dim>::value (const Point<dim> &p, const unsigned int) const
6738 *   {
6739 * @endcode
6740 *
6741 * boundary for filling the tank (outlet)
6742 *
6743 * @code
6744 *   double x = p[0];
6745 *   double y = p[1];
6746 *   double return_value = 0;
6747 *  
6748 *   if (PROBLEM==FILLING_TANK)
6749 *   {
6750 *   if (y==0.4 && x>=0.3 && x<=0.35)
6751 *   return_value = 0.25;
6752 *   }
6753 *   return return_value;
6754 *   }
6755 *  
6756 * @endcode
6757 *
6758 * ///////////////////////////////////////////////////
6759 * ///////////////// POST-PROCESSING /////////////////
6760 * ///////////////////////////////////////////////////
6761 *
6762 * @code
6763 *   template <int dim>
6764 *   class Postprocessor : public DataPostprocessorScalar <dim>
6765 *   {
6766 *   public:
6767 *   Postprocessor(double eps, double rho_air, double rho_fluid)
6768 *   :
6769 *   DataPostprocessorScalar<dim>("Density",update_values)
6770 *   {
6771 *   this->eps=eps;
6772 *   this->rho_air=rho_air;
6773 *   this->rho_fluid=rho_fluid;
6774 *   }
6775 *  
6776 *   virtual
6777 *   void
6778 *   evaluate_scalar_field (const DataPostprocessorInputs::Scalar<dim> &input_data,
6779 *   std::vector<Vector<double> > &computed_quantities) const override;
6780 *  
6781 *   double eps;
6782 *   double rho_air;
6783 *   double rho_fluid;
6784 *   };
6785 *  
6786 *  
6787 *   template <int dim>
6788 *   void
6789 *   Postprocessor<dim>::
6790 *   evaluate_scalar_field (const DataPostprocessorInputs::Scalar<dim> &input_data,
6791 *   std::vector<Vector<double> > &computed_quantities) const
6792 *   {
6793 *   const unsigned int n_quadrature_points = input_data.solution_values.size();
6794 *   for (unsigned int q=0; q<n_quadrature_points; ++q)
6795 *   {
6796 *   double H;
6797 *   double rho_value;
6798 *   double phi_value=input_data.solution_values[q];
6799 *   if (phi_value > eps)
6800 *   H=1;
6801 *   else if (phi_value < -eps)
6802 *   H=-1;
6803 *   else
6804 *   H=phi_value/eps;
6805 *   rho_value = rho_fluid*(1+H)/2. + rho_air*(1-H)/2.;
6806 *   computed_quantities[q] = rho_value;
6807 *   }
6808 *   }
6809 *  
6810 * @endcode
6811
6812
6813<a name="ann-utilities_test_LS.cc"></a>
6814<h1>Annotated version of utilities_test_LS.cc</h1>
6815 *
6816 *
6817 *
6818 *
6819 * @code
6820 *   /* -----------------------------------------------------------------------------
6821 *   *
6822 *   * SPDX-License-Identifier: LGPL-2.1-or-later
6823 *   * Copyright (C) 2016 Manuel Quezada de Luna
6824 *   *
6825 *   * This file is part of the deal.II code gallery.
6826 *   *
6827 *   * -----------------------------------------------------------------------------
6828 *   */
6829 *  
6830 * @endcode
6831 *
6832 * ///////////////////////////////////////////////////
6833 * ////////////////// INITIAL PHI //////////////////
6834 * ///////////////////////////////////////////////////
6835 *
6836 * @code
6837 *   template <int dim>
6838 *   class InitialPhi : public Function <dim>
6839 *   {
6840 *   public:
6841 *   InitialPhi (unsigned int PROBLEM, double sharpness=0.005) : Function<dim>(),
6842 *   sharpness(sharpness),
6843 *   PROBLEM(PROBLEM) {}
6844 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
6845 *   double sharpness;
6846 *   unsigned int PROBLEM;
6847 *   };
6848 *   template <int dim>
6849 *   double InitialPhi<dim>::value (const Point<dim> &p,
6850 *   const unsigned int) const
6851 *   {
6852 *   double x = p[0];
6853 *   double y = p[1];
6854 *   double return_value = -1.;
6855 *  
6856 *   if (PROBLEM==CIRCULAR_ROTATION)
6857 *   {
6858 *   double x0=0.5;
6859 *   double y0=0.75;
6860 *   double r0=0.15;
6861 *   double r = std::sqrt(std::pow(x-x0,2)+std::pow(y-y0,2));
6862 *   return_value = -std::tanh((r-r0)/sharpness);
6863 *   }
6864 *   else // (PROBLEM==DIAGONAL_ADVECTION)
6865 *   {
6866 *   double x0=0.25;
6867 *   double y0=0.25;
6868 *   double r0=0.15;
6869 *   double r=0;
6870 *   if (dim==2)
6871 *   r = std::sqrt(std::pow(x-x0,2)+std::pow(y-y0,2));
6872 *   else
6873 *   {
6874 *   double z0=0.25;
6875 *   double z=p[2];
6876 *   r = std::sqrt(std::pow(x-x0,2)+std::pow(y-y0,2)+std::pow(z-z0,2));
6877 *   }
6878 *   return_value = -std::tanh((r-r0)/sharpness);
6879 *   }
6880 *   return return_value;
6881 *   }
6882 *  
6883 * @endcode
6884 *
6885 * /////////////////////////////////////////////////
6886 * ////////////////// BOUNDARY PHI /////////////////
6887 * /////////////////////////////////////////////////
6888 *
6889 * @code
6890 *   template <int dim>
6891 *   class BoundaryPhi : public Function <dim>
6892 *   {
6893 *   public:
6894 *   BoundaryPhi (double t=0)
6895 *   :
6896 *   Function<dim>()
6897 *   {this->set_time(t);}
6898 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
6899 *   };
6900 *  
6901 *   template <int dim>
6902 *   double BoundaryPhi<dim>::value (const Point<dim> &, const unsigned int) const
6903 *   {
6904 *   return -1.0;
6905 *   }
6906 *  
6907 * @endcode
6908 *
6909 * ///////////////////////////////////////////////////
6910 * ////////////////// EXACT VELOCITY /////////////////
6911 * ///////////////////////////////////////////////////
6912 *
6913 * @code
6914 *   template <int dim>
6915 *   class ExactU : public Function <dim>
6916 *   {
6917 *   public:
6918 *   ExactU (unsigned int PROBLEM, double time=0) : Function<dim>(), PROBLEM(PROBLEM), time(time) {}
6919 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
6920 *   void set_time(double time) {this->time=time;};
6921 *   unsigned PROBLEM;
6922 *   double time;
6923 *   };
6924 *  
6925 *   template <int dim>
6926 *   double ExactU<dim>::value (const Point<dim> &p, const unsigned int) const
6927 *   {
6928 *   if (PROBLEM==CIRCULAR_ROTATION)
6929 *   return -2*numbers::PI*(p[1]-0.5);
6930 *   else // (PROBLEM==DIAGONAL_ADVECTION)
6931 *   return 1.0;
6932 *   }
6933 *  
6934 *   template <int dim>
6935 *   class ExactV : public Function <dim>
6936 *   {
6937 *   public:
6938 *   ExactV (unsigned int PROBLEM, double time=0) : Function<dim>(), PROBLEM(PROBLEM), time(time) {}
6939 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
6940 *   void set_time(double time) {this->time=time;};
6941 *   unsigned int PROBLEM;
6942 *   double time;
6943 *   };
6944 *  
6945 *   template <int dim>
6946 *   double ExactV<dim>::value (const Point<dim> &p, const unsigned int) const
6947 *   {
6948 *   if (PROBLEM==CIRCULAR_ROTATION)
6949 *   return 2*numbers::PI*(p[0]-0.5);
6950 *   else // (PROBLEM==DIAGONAL_ADVECTION)
6951 *   return 1.0;
6952 *   }
6953 *  
6954 *   template <int dim>
6955 *   class ExactW : public Function <dim>
6956 *   {
6957 *   public:
6958 *   ExactW (unsigned int PROBLEM, double time=0) : Function<dim>(), PROBLEM(PROBLEM), time(time) {}
6959 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
6960 *   void set_time(double time) {this->time=time;};
6961 *   unsigned int PROBLEM;
6962 *   double time;
6963 *   };
6964 *  
6965 *   template <int dim>
6966 *   double ExactW<dim>::value (const Point<dim> &, const unsigned int) const
6967 *   {
6968 * @endcode
6969 *
6970 * PROBLEM = 3D_DIAGONAL_ADVECTION
6971 *
6972 * @code
6973 *   return 1.0;
6974 *   }
6975 *  
6976 * @endcode
6977
6978
6979<a name="ann-utilities_test_NS.cc"></a>
6980<h1>Annotated version of utilities_test_NS.cc</h1>
6981 *
6982 *
6983 *
6984 *
6985 * @code
6986 *   /* -----------------------------------------------------------------------------
6987 *   *
6988 *   * SPDX-License-Identifier: LGPL-2.1-or-later
6989 *   * Copyright (C) 2016 Manuel Quezada de Luna
6990 *   *
6991 *   * This file is part of the deal.II code gallery.
6992 *   *
6993 *   * -----------------------------------------------------------------------------
6994 *   */
6995 *  
6996 * @endcode
6997 *
6998 * ///////////////////////////////////////////////////
6999 * ////////// EXACT SOLUTION RHO TO TEST NS //////////
7000 * ///////////////////////////////////////////////////
7001 *
7002 * @code
7003 *   template <int dim>
7004 *   class RhoFunction : public Function <dim>
7005 *   {
7006 *   public:
7007 *   RhoFunction (double t=0) : Function<dim>() {this->set_time(t);}
7008 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
7009 *   };
7010 *   template <int dim>
7011 *   double RhoFunction<dim>::value (const Point<dim> &p,
7012 *   const unsigned int) const
7013 *   {
7014 *   double t = this->get_time();
7015 *   double return_value = 0;
7016 *   if (dim==2)
7017 *   return_value = std::pow(std::sin(p[0]+p[1]+t),2)+1;
7018 *   else //dim=3
7019 *   return_value = std::pow(std::sin(p[0]+p[1]+p[2]+t),2)+1;
7020 *   return return_value;
7021 *   }
7022 *  
7023 *   template <int dim>
7024 *   class NuFunction : public Function <dim>
7025 *   {
7026 *   public:
7027 *   NuFunction (double t=0) : Function<dim>() {this->set_time(t);}
7028 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
7029 *   };
7030 *   template <int dim>
7031 *   double NuFunction<dim>::value (const Point<dim> &, const unsigned int) const
7032 *   {
7033 *   return 1.;
7034 *   }
7035 *  
7036 * @endcode
7037 *
7038 * //////////////////////////////////////////////////////////////
7039 * ///////////////// EXACT SOLUTION U to TEST NS ////////////////
7040 * //////////////////////////////////////////////////////////////
7041 *
7042 * @code
7043 *   template <int dim>
7044 *   class ExactSolution_and_BC_U : public Function <dim>
7045 *   {
7046 *   public:
7047 *   ExactSolution_and_BC_U (double t=0, int field=0)
7048 *   :
7049 *   Function<dim>(),
7050 *   field(field)
7051 *   {
7052 *   this->set_time(t);
7053 *   }
7054 *   virtual double value (const Point<dim> &p, const unsigned int component=1) const;
7055 *   virtual Tensor<1,dim> gradient (const Point<dim> &p, const unsigned int component=1) const;
7056 *   virtual void set_field(int field) {this->field=field;}
7057 *   int field;
7058 *   unsigned int type_simulation;
7059 *   };
7060 *   template <int dim>
7061 *   double ExactSolution_and_BC_U<dim>::value (const Point<dim> &p,
7062 *   const unsigned int) const
7063 *   {
7064 *   double t = this->get_time();
7065 *   double return_value = 0;
7066 *   double Pi = numbers::PI;
7067 *   double x = p[0];
7068 *   double y = p[1];
7069 *   double z = 0;
7070 *  
7071 *   if (dim == 2)
7072 *   if (field == 0)
7073 *   return_value = std::sin(x)*std::sin(y+t);
7074 *   else
7075 *   return_value = std::cos(x)*std::cos(y+t);
7076 *   else //dim=3
7077 *   {
7078 *   z = p[2];
7079 *   if (field == 0)
7080 *   return_value = std::cos(t)*std::cos(Pi*y)*std::cos(Pi*z)*std::sin(Pi*x);
7081 *   else if (field == 1)
7082 *   return_value = std::cos(t)*std::cos(Pi*x)*std::cos(Pi*z)*std::sin(Pi*y);
7083 *   else
7084 *   return_value = -2*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*y)*std::sin(Pi*z);
7085 *   }
7086 *   return return_value;
7087 *   }
7088 *   template <int dim>
7089 *   Tensor<1,dim> ExactSolution_and_BC_U<dim>::gradient (const Point<dim> &p,
7090 *   const unsigned int) const
7091 *   {
7092 * @endcode
7093 *
7094 * THIS IS USED JUST FOR TESTING NS
7095 *
7096 * @code
7097 *   Tensor<1,dim> return_value;
7098 *   double t = this->get_time();
7099 *   double Pi = numbers::PI;
7100 *   double x = p[0];
7101 *   double y = p[1];
7102 *   double z = 0;
7103 *   if (dim == 2)
7104 *   if (field == 0)
7105 *   {
7106 *   return_value[0] = std::cos(x)*std::sin(y+t);
7107 *   return_value[1] = std::sin(x)*std::cos(y+t);
7108 *   }
7109 *   else
7110 *   {
7111 *   return_value[0] = -std::sin(x)*std::cos(y+t);
7112 *   return_value[1] = -std::cos(x)*std::sin(y+t);
7113 *   }
7114 *   else //dim=3
7115 *   {
7116 *   z=p[2];
7117 *   if (field == 0)
7118 *   {
7119 *   return_value[0] = Pi*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*y)*std::cos(Pi*z);
7120 *   return_value[1] = -(Pi*std::cos(t)*std::cos(Pi*z)*std::sin(Pi*x)*std::sin(Pi*y));
7121 *   return_value[2] = -(Pi*std::cos(t)*std::cos(Pi*y)*std::sin(Pi*x)*std::sin(Pi*z));
7122 *   }
7123 *   else if (field == 1)
7124 *   {
7125 *   return_value[0] = -(Pi*std::cos(t)*std::cos(Pi*z)*std::sin(Pi*x)*std::sin(Pi*y));
7126 *   return_value[1] = Pi*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*y)*std::cos(Pi*z);
7127 *   return_value[2] = -(Pi*std::cos(t)*std::cos(Pi*x)*std::sin(Pi*y)*std::sin(Pi*z));
7128 *   }
7129 *   else
7130 *   {
7131 *   return_value[0] = 2*Pi*std::cos(t)*std::cos(Pi*y)*std::sin(Pi*x)*std::sin(Pi*z);
7132 *   return_value[1] = 2*Pi*std::cos(t)*std::cos(Pi*x)*std::sin(Pi*y)*std::sin(Pi*z);
7133 *   return_value[2] = -2*Pi*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*y)*std::cos(Pi*z);
7134 *   }
7135 *   }
7136 *   return return_value;
7137 *   }
7138 *  
7139 * @endcode
7140 *
7141 * ///////////////////////////////////////////////////
7142 * ///////// EXACT SOLUTION FOR p TO TEST NS /////////
7143 * ///////////////////////////////////////////////////
7144 *
7145 * @code
7146 *   template <int dim>
7147 *   class ExactSolution_p : public Function <dim>
7148 *   {
7149 *   public:
7150 *   ExactSolution_p (double t=0) : Function<dim>() {this->set_time(t);}
7151 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
7152 *   virtual Tensor<1,dim> gradient (const Point<dim> &p, const unsigned int component = 0) const;
7153 *   };
7154 *  
7155 *   template <int dim>
7156 *   double ExactSolution_p<dim>::value (const Point<dim> &p, const unsigned int) const
7157 *   {
7158 *   double t = this->get_time();
7159 *   double return_value = 0;
7160 *   if (dim == 2)
7161 *   return_value = std::cos(p[0])*std::sin(p[1]+t);
7162 *   else //dim=3
7163 *   return_value = std::sin(p[0]+p[1]+p[2]+t);
7164 *   return return_value;
7165 *   }
7166 *  
7167 *   template <int dim>
7168 *   Tensor<1,dim> ExactSolution_p<dim>::gradient (const Point<dim> &p, const unsigned int) const
7169 *   {
7170 *   Tensor<1,dim> return_value;
7171 *   double t = this->get_time();
7172 *   if (dim == 2)
7173 *   {
7174 *   return_value[0] = -std::sin(p[0])*std::sin(p[1]+t);
7175 *   return_value[1] = std::cos(p[0])*std::cos(p[1]+t);
7176 *   }
7177 *   else //dim=3
7178 *   {
7179 *   return_value[0] = std::cos(t+p[0]+p[1]+p[2]);
7180 *   return_value[1] = std::cos(t+p[0]+p[1]+p[2]);
7181 *   return_value[2] = std::cos(t+p[0]+p[1]+p[2]);
7182 *   }
7183 *   return return_value;
7184 *   }
7185 *  
7186 * @endcode
7187 *
7188 * //////////////////////////////////////////////////////////////
7189 * ////////////////// FORCE TERMS to TEST NS ////////////////////
7190 * //////////////////////////////////////////////////////////////
7191 *
7192 * @code
7193 *   template <int dim>
7194 *   class ForceTerms : public Function <dim>
7195 *   {
7196 *   public:
7197 *   ForceTerms (double t=0)
7198 *   :
7199 *   Function<dim>()
7200 *   {
7201 *   this->set_time(t);
7202 *   nu = 1.;
7203 *   }
7204 *   virtual void vector_value (const Point<dim> &p, Vector<double> &values) const;
7205 *   double nu;
7206 *   };
7207 *  
7208 *   template <int dim>
7209 *   void ForceTerms<dim>::vector_value (const Point<dim> &p, Vector<double> &values) const
7210 *   {
7211 *   double x = p[0];
7212 *   double y = p[1];
7213 *   double z = 0;
7214 *   double t = this->get_time();
7215 *   double Pi = numbers::PI;
7216 *  
7217 *   if (dim == 2)
7218 *   {
7219 * @endcode
7220 *
7221 * force in x
7222 *
7223 * @code
7224 *   values[0] = std::cos(t+y)*std::sin(x)*(1+std::pow(std::sin(t+x+y),2)) // time derivative
7225 *   +2*nu*std::sin(x)*std::sin(t+y) // viscosity
7226 *   +std::cos(x)*std::sin(x)*(1+std::pow(std::sin(t+x+y),2)) // non-linearity
7227 *   -std::sin(x)*std::sin(y+t); // pressure
7228 * @endcode
7229 *
7230 * force in y
7231 *
7232 * @code
7233 *   values[1] = -(std::cos(x)*std::sin(t+y)*(1+std::pow(std::sin(t+x+y),2))) // time derivative
7234 *   +2*nu*std::cos(x)*std::cos(t+y) // viscosity
7235 *   -(std::sin(2*(t+y))*(1+std::pow(std::sin(t+x+y),2)))/2. // non-linearity
7236 *   +std::cos(x)*std::cos(y+t); // pressure
7237 *   }
7238 *   else //3D
7239 *   {
7240 *   z = p[2];
7241 * @endcode
7242 *
7243 * force in x
7244 *
7245 * @code
7246 *   values[0]=
7247 *   -(std::cos(Pi*y)*std::cos(Pi*z)*std::sin(t)*std::sin(Pi*x)*(1+std::pow(std::sin(t+x+y+z),2))) //time der.
7248 *   +3*std::pow(Pi,2)*std::cos(t)*std::cos(Pi*y)*std::cos(Pi*z)*std::sin(Pi*x) //viscosity
7249 *   -(Pi*std::pow(std::cos(t),2)*(-3+std::cos(2*(t+x+y+z)))*std::sin(2*Pi*x)*(std::cos(2*Pi*y)+std::pow(std::sin(Pi*z),2)))/4. //NL
7250 *   +std::cos(t+x+y+z); // pressure
7251 *   values[1]=
7252 *   -(std::cos(Pi*x)*std::cos(Pi*z)*std::sin(t)*std::sin(Pi*y)*(1+std::pow(std::sin(t+x+y+z),2))) //time der
7253 *   +3*std::pow(Pi,2)*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*z)*std::sin(Pi*y) //viscosity
7254 *   -(Pi*std::pow(std::cos(t),2)*(-3+std::cos(2*(t+x+y+z)))*std::sin(2*Pi*y)*(std::cos(2*Pi*x)+std::pow(std::sin(Pi*z),2)))/4. //NL
7255 *   +std::cos(t+x+y+z); // pressure
7256 *   values[2]=
7257 *   2*std::cos(Pi*x)*std::cos(Pi*y)*std::sin(t)*std::sin(Pi*z)*(1+std::pow(std::sin(t+x+y+z),2)) //time der
7258 *   -6*std::pow(Pi,2)*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*y)*std::sin(Pi*z) //viscosity
7259 *   -(Pi*std::pow(std::cos(t),2)*(2+std::cos(2*Pi*x)+std::cos(2*Pi*y))*(-3+std::cos(2*(t+x+y+z)))*std::sin(2*Pi*z))/4. //NL
7260 *   +std::cos(t+x+y+z); // pressure
7261 *   }
7262 *   }
7263 * @endcode
7264
7265
7266*/
void attach_dof_handler(const DoFHandler< dim, spacedim > &)
Definition fe_q.h:554
void subtract_set(const IndexSet &other)
Definition index_set.cc:480
Definition point.h:113
@ smoothing_on_refinement
Definition tria.h:1524
@ smoothing_on_coarsening
Definition tria.h:1530
#define DEAL_II_VERSION_GTE(major, minor, subminor)
Definition config.h:407
typename ActiveSelector::active_cell_iterator active_cell_iterator
void loop(IteratorType begin, std_cxx20::type_identity_t< IteratorType > end, DOFINFO &dinfo, INFOBOX &info, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, AssemblerType &assembler, const LoopControl &lctrl=LoopControl())
Definition loop.h:564
void make_hanging_node_constraints(const DoFHandler< dim, spacedim > &dof_handler, AffineConstraints< number > &constraints)
void make_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity_pattern, const AffineConstraints< number > &constraints={}, const bool keep_constrained_dofs=true, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id)
@ 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.
LogStream deallog
Definition logstream.cc:38
const Event initial
Definition event.cc:68
CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt K
IndexSet extract_locally_relevant_dofs(const DoFHandler< dim, spacedim > &dof_handler)
void hyper_rectangle(Triangulation< dim, spacedim > &tria, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
void subdivided_hyper_rectangle(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &repetitions, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
double minimal_cell_diameter(const Triangulation< dim, spacedim > &triangulation, const Mapping< dim, spacedim > &mapping=(ReferenceCells::get_hypercube< dim >() .template get_default_linear_mapping< dim, spacedim >()))
double volume(const Triangulation< dim, spacedim > &tria)
@ matrix
Contents is actually a matrix.
constexpr char U
constexpr types::blas_int zero
constexpr char A
SymmetricTensor< 2, dim, Number > C(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
void distribute_sparsity_pattern(DynamicSparsityPattern &dsp, const IndexSet &locally_owned_rows, const MPI_Comm mpi_comm, const IndexSet &locally_relevant_rows)
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
T sum(const T &t, const MPI_Comm mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
Definition mpi.cc:105
T max(const T &t, const MPI_Comm mpi_communicator)
T min(const T &t, const MPI_Comm mpi_communicator)
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
Definition mpi.cc:120
std::string compress(const std::string &input)
Definition utilities.cc:383
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition utilities.cc:466
void interpolate(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Function< spacedim, typename VectorType::value_type > &function, VectorType &vec, const ComponentMask &component_mask={}, const unsigned int level=numbers::invalid_unsigned_int)
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={})
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 abort(const ExceptionBase &exc) noexcept
int(& functions)(const void *v1, const void *v2)
void assemble(const MeshWorker::DoFInfoBox< dim, DOFINFO > &dinfo, A *assembler)
Definition loop.h:70
constexpr double E
Definition numbers.h:214
::VectorizedArray< Number, width > log(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
unsigned int boundary_id
Definition types.h:161