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