deal.II version GIT relicensing-2173-gae8fc9d14b 2024-11-24 06:40:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
two_phase_flow.h
Go to the documentation of this file.
1
245 *  
246 *   #include <deal.II/base/quadrature_lib.h>
247 *   #include <deal.II/base/function.h>
248 *   #include <deal.II/lac/affine_constraints.h>
249 *   #include <deal.II/lac/vector.h>
250 *   #include <deal.II/lac/full_matrix.h>
251 *   #include <deal.II/lac/solver_cg.h>
252 *   #include <deal.II/lac/petsc_sparse_matrix.h>
253 *   #include <deal.II/lac/petsc_sparse_matrix.h>
254 *   #include <deal.II/lac/petsc_vector.h>
255 *   #include <deal.II/lac/petsc_solver.h>
256 *   #include <deal.II/lac/petsc_precondition.h>
257 *   #include <deal.II/grid/grid_generator.h>
258 *   #include <deal.II/grid/tria_accessor.h>
259 *   #include <deal.II/grid/tria_iterator.h>
260 *   #include <deal.II/dofs/dof_handler.h>
261 *   #include <deal.II/dofs/dof_accessor.h>
262 *   #include <deal.II/dofs/dof_tools.h>
263 *   #include <deal.II/fe/fe_values.h>
264 *   #include <deal.II/fe/fe_q.h>
265 *   #include <deal.II/numerics/vector_tools.h>
266 *   #include <deal.II/numerics/data_out.h>
267 *   #include <deal.II/numerics/error_estimator.h>
268 *   #include <deal.II/base/utilities.h>
269 *   #include <deal.II/base/conditional_ostream.h>
270 *   #include <deal.II/base/index_set.h>
271 *   #include <deal.II/lac/sparsity_tools.h>
272 *   #include <deal.II/distributed/tria.h>
273 *   #include <deal.II/distributed/grid_refinement.h>
274 *   #include <deal.II/lac/vector.h>
275 *   #include <deal.II/base/convergence_table.h>
276 *   #include <deal.II/base/timer.h>
277 *   #include <deal.II/base/parameter_handler.h>
278 *   #include <deal.II/grid/grid_tools.h>
279 *   #include <deal.II/fe/mapping_q.h>
280 *  
281 *   #include <mpi.h>
282 *  
283 *   #include <fstream>
284 *   #include <iostream>
285 *   #include <memory>
286 *  
287 *   using namespace dealii;
288 *  
289 * @endcode
290 *
291 * FLAGS
292 *
293 * @code
294 *   #define NUM_ITER 1
295 *   #define CHECK_MAX_PRINCIPLE 0
296 *  
297 * @endcode
298 *
299 * LOG FOR LEVEL SET FROM -1 to 1
300 *
301 * @code
302 *   #define ENTROPY(phi) std::log(std::abs(1-phi*phi)+1E-14)
303 *   #define ENTROPY_GRAD(phi,phix) 2*phi*phix*((1-phi*phi>=0) ? -1 : 1)/(std::abs(1-phi*phi)+1E-14)
304 *  
305 * @endcode
306 *
307 *
308 *
309 *
310 * This is a solver for the transpor solver.
311 * We assume the velocity is divergence free
312 * and solve the equation in conservation form.
313 *
314 * ---------- NOTATION ----------
315 *
316 * We use notation popular in the literature of conservation laws.
317 * For this reason the solution is denoted as u, unm1, unp1, etc.
318 * and the velocity is treated as vx, vy and vz.
319 *
320 * @code
321 *   template <int dim>
322 *   class LevelSetSolver
323 *   {
324 *   public:
325 * @endcode
326 *
327 *
328 * INITIAL CONDITIONS
329 *
330 *
331 * @code
332 *   void initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_u,
333 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx,
334 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy);
335 *   void initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_u,
336 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx,
337 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy,
338 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz);
339 * @endcode
340 *
341 *
342 * BOUNDARY CONDITIONS
343 *
344 *
345 * @code
346 *   void set_boundary_conditions(std::vector<types::global_dof_index> &boundary_values_id_u,
347 *   std::vector<double> boundary_values_u);
348 * @endcode
349 *
350 *
351 * SET VELOCITY
352 *
353 *
354 * @code
355 *   void set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_vx,
356 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy);
357 *   void set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_vx,
358 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy,
359 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz);
360 * @endcode
361 *
362 *
363 * SET AND GET ALPHA
364 *
365 *
366 * @code
367 *   void get_unp1(PETScWrappers::MPI::Vector &locally_relevant_solution_u);
368 * @endcode
369 *
370 *
371 * NTH TIME STEP
372 *
373 *
374 * @code
375 *   void nth_time_step();
376 * @endcode
377 *
378 *
379 * SETUP
380 *
381 *
382 * @code
383 *   void setup();
384 *  
385 *   LevelSetSolver (const unsigned int degree_LS,
386 *   const unsigned int degree_U,
387 *   const double time_step,
388 *   const double cK,
389 *   const double cE,
390 *   const bool verbose,
391 *   std::string ALGORITHM,
392 *   const unsigned int TIME_INTEGRATION,
394 *   MPI_Comm &mpi_communicator);
395 *   ~LevelSetSolver();
396 *  
397 *   private:
398 * @endcode
399 *
400 *
401 * ASSEMBLE MASS (and other) MATRICES
402 *
403 *
404 * @code
405 *   void assemble_ML();
406 *   void invert_ML();
407 *   void assemble_MC();
408 * @endcode
409 *
410 *
411 * LOW ORDER METHOD (DiJ Viscosity)
412 *
413 *
414 * @code
415 *   void assemble_C_Matrix();
416 *   void assemble_K_times_vector(PETScWrappers::MPI::Vector &solution);
417 *   void assemble_K_DL_DH_times_vector(PETScWrappers::MPI::Vector &solution);
418 * @endcode
419 *
420 *
421 * ENTROPY VISCOSITY
422 *
423 *
424 * @code
425 *   void assemble_EntRes_Matrix();
426 * @endcode
427 *
428 *
429 * FOR MAXIMUM PRINCIPLE
430 *
431 *
432 * @code
433 *   void compute_bounds(PETScWrappers::MPI::Vector &un_solution);
434 *   void check_max_principle(PETScWrappers::MPI::Vector &unp1_solution);
435 * @endcode
436 *
437 *
438 * COMPUTE SOLUTIONS
439 *
440 *
441 * @code
442 *   void compute_MPP_uL_and_NMPP_uH(PETScWrappers::MPI::Vector &MPP_uL_solution,
443 *   PETScWrappers::MPI::Vector &NMPP_uH_solution,
444 *   PETScWrappers::MPI::Vector &un_solution);
445 *   void compute_MPP_uH(PETScWrappers::MPI::Vector &MPP_uH_solution,
446 *   PETScWrappers::MPI::Vector &MPP_uL_solution_ghosted,
447 *   PETScWrappers::MPI::Vector &NMPP_uH_solution_ghosted,
448 *   PETScWrappers::MPI::Vector &un_solution);
449 *   void compute_MPP_uH_with_iterated_FCT(PETScWrappers::MPI::Vector &MPP_uH_solution,
450 *   PETScWrappers::MPI::Vector &MPP_uL_solution_ghosted,
451 *   PETScWrappers::MPI::Vector &NMPP_uH_solution_ghosted,
452 *   PETScWrappers::MPI::Vector &un_solution);
453 *   void compute_solution(PETScWrappers::MPI::Vector &unp1,
455 *   std::string algorithm);
456 *   void compute_solution_SSP33(PETScWrappers::MPI::Vector &unp1,
458 *   std::string algorithm);
459 * @endcode
460 *
461 *
462 * UTILITIES
463 *
464 *
465 * @code
466 *   void get_sparsity_pattern();
467 *   void get_map_from_Q1_to_Q2();
468 *   void solve(const AffineConstraints<double> &constraints,
470 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner,
471 *   PETScWrappers::MPI::Vector &completely_distributed_solution,
472 *   const PETScWrappers::MPI::Vector &rhs);
473 *   void save_old_solution();
474 *   void save_old_vel_solution();
475 * @endcode
476 *
477 *
478 * MY PETSC WRAPPERS
479 *
480 *
481 * @code
482 *   void get_vector_values(PETScWrappers::VectorBase &vector,
483 *   const std::vector<types::global_dof_index> &indices,
484 *   std::vector<PetscScalar> &values);
485 *   void get_vector_values(PETScWrappers::VectorBase &vector,
486 *   const std::vector<types::global_dof_index> &indices,
487 *   std::map<types::global_dof_index, types::global_dof_index> &map_from_Q1_to_Q2,
488 *   std::vector<PetscScalar> &values);
489 *  
490 *   MPI_Comm mpi_communicator;
491 *  
492 * @endcode
493 *
494 * FINITE ELEMENT SPACE
495 *
496 * @code
497 *   int degree_MAX;
498 *   int degree_LS;
499 *   DoFHandler<dim> dof_handler_LS;
500 *   FE_Q<dim> fe_LS;
501 *   IndexSet locally_owned_dofs_LS;
502 *   IndexSet locally_relevant_dofs_LS;
503 *  
504 *   int degree_U;
505 *   DoFHandler<dim> dof_handler_U;
506 *   FE_Q<dim> fe_U;
507 *   IndexSet locally_owned_dofs_U;
508 *   IndexSet locally_relevant_dofs_U;
509 *  
510 * @endcode
511 *
512 * OPERATORS times SOLUTION VECTOR
513 *
514 * @code
515 *   PETScWrappers::MPI::Vector K_times_solution;
516 *   PETScWrappers::MPI::Vector DL_times_solution;
517 *   PETScWrappers::MPI::Vector DH_times_solution;
518 *  
519 * @endcode
520 *
521 * MASS MATRIX
522 *
523 * @code
525 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> MC_preconditioner;
526 *  
527 * @endcode
528 *
529 * BOUNDARIES
530 *
531 * @code
532 *   std::vector<types::global_dof_index> boundary_values_id_u;
533 *   std::vector<double> boundary_values_u;
534 *  
535 * @endcode
536 *
537 *
538 * MATRICES
539 *
540 * FOR FIRST ORDER VISCOSITY
541 *
542 * @code
543 *   PETScWrappers::MPI::SparseMatrix Cx_matrix, CTx_matrix, Cy_matrix, CTy_matrix, Cz_matrix, CTz_matrix;
544 *   PETScWrappers::MPI::SparseMatrix dLij_matrix;
545 * @endcode
546 *
547 * FOR ENTROPY VISCOSITY
548 *
549 * @code
550 *   PETScWrappers::MPI::SparseMatrix EntRes_matrix, SuppSize_matrix, dCij_matrix;
551 * @endcode
552 *
553 * FOR FCT (flux and limited flux)
554 *
555 * @code
556 *   PETScWrappers::MPI::SparseMatrix A_matrix, LxA_matrix;
557 * @endcode
558 *
559 * FOR ITERATIVE FCT
560 *
561 * @code
562 *   PETScWrappers::MPI::SparseMatrix Akp1_matrix, LxAkp1_matrix;
563 *  
564 * @endcode
565 *
566 * GHOSTED VECTORS
567 *
568 * @code
569 *   PETScWrappers::MPI::Vector uStage1, uStage2;
570 *   PETScWrappers::MPI::Vector unm1, un;
571 *   PETScWrappers::MPI::Vector R_pos_vector, R_neg_vector;
572 *   PETScWrappers::MPI::Vector MPP_uL_solution_ghosted, MPP_uLkp1_solution_ghosted, NMPP_uH_solution_ghosted;
573 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx;
574 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy;
575 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz;
576 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx_old;
577 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy_old;
578 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz_old;
579 *  
580 * @endcode
581 *
582 * NON-GHOSTED VECTORS
583 *
584 * @code
585 *   PETScWrappers::MPI::Vector uStage1_nonGhosted, uStage2_nonGhosted;
587 *   PETScWrappers::MPI::Vector R_pos_vector_nonGhosted, R_neg_vector_nonGhosted;
588 *   PETScWrappers::MPI::Vector umin_vector, umax_vector;
589 *   PETScWrappers::MPI::Vector MPP_uL_solution, NMPP_uH_solution, MPP_uH_solution;
591 *  
592 * @endcode
593 *
594 * LUMPED MASS MATRIX
595 *
596 * @code
597 *   PETScWrappers::MPI::Vector ML_vector, ones_vector;
598 *   PETScWrappers::MPI::Vector inverse_ML_vector;
599 *  
600 * @endcode
601 *
602 * CONSTRAINTS
603 *
604 * @code
605 *   AffineConstraints<double> constraints;
606 *  
607 * @endcode
608 *
609 * TIME STEPPING
610 *
611 * @code
612 *   double time_step;
613 *  
614 * @endcode
615 *
616 * SOME PARAMETERS
617 *
618 * @code
619 *   double cE, cK;
620 *   double solver_tolerance;
621 *   double entropy_normalization_factor;
622 *  
623 * @endcode
624 *
625 * UTILITIES
626 *
627 * @code
628 *   bool verbose;
629 *   std::string ALGORITHM;
630 *   unsigned int TIME_INTEGRATION;
631 *  
632 *   ConditionalOStream pcout;
633 *  
634 *   std::map<types::global_dof_index, types::global_dof_index> map_from_Q1_to_Q2;
635 *   std::map<types::global_dof_index, std::vector<types::global_dof_index> > sparsity_pattern;
636 *   };
637 *  
638 *   template <int dim>
639 *   LevelSetSolver<dim>::LevelSetSolver (const unsigned int degree_LS,
640 *   const unsigned int degree_U,
641 *   const double time_step,
642 *   const double cK,
643 *   const double cE,
644 *   const bool verbose,
645 *   std::string ALGORITHM,
646 *   const unsigned int TIME_INTEGRATION,
648 *   MPI_Comm &mpi_communicator)
649 *   :
650 *   mpi_communicator (mpi_communicator),
651 *   degree_LS(degree_LS),
652 *   dof_handler_LS (triangulation),
653 *   fe_LS (degree_LS),
654 *   degree_U(degree_U),
655 *   dof_handler_U (triangulation),
656 *   fe_U (degree_U),
657 *   time_step(time_step),
658 *   cE(cE),
659 *   cK(cK),
660 *   verbose(verbose),
661 *   ALGORITHM(ALGORITHM),
662 *   TIME_INTEGRATION(TIME_INTEGRATION),
663 *   pcout (std::cout,(Utilities::MPI::this_mpi_process(mpi_communicator)== 0))
664 *   {
665 *   pcout << "********** LEVEL SET SETUP **********" << std::endl;
666 *   setup();
667 *   }
668 *  
669 *   template <int dim>
670 *   LevelSetSolver<dim>::~LevelSetSolver ()
671 *   {
672 *   dof_handler_LS.clear ();
673 *   dof_handler_U.clear ();
674 *   }
675 *  
676 * @endcode
677 *
678 *
679 *
680 *
681 *
682 *
683 *
684 *
685 * @code
686 *   template<int dim>
687 *   void LevelSetSolver<dim>::initial_condition (PETScWrappers::MPI::Vector un,
688 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx,
689 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy)
690 *   {
691 *   this->un = un;
692 *   this->locally_relevant_solution_vx = locally_relevant_solution_vx;
693 *   this->locally_relevant_solution_vy = locally_relevant_solution_vy;
694 * @endcode
695 *
696 * initialize old vectors with current solution, this just happens the first time
697 *
698 * @code
699 *   unm1 = un;
700 *   locally_relevant_solution_vx_old = locally_relevant_solution_vx;
701 *   locally_relevant_solution_vy_old = locally_relevant_solution_vy;
702 *   }
703 *  
704 *   template<int dim>
705 *   void LevelSetSolver<dim>::initial_condition (PETScWrappers::MPI::Vector un,
706 *   PETScWrappers::MPI::Vector locally_relevant_solution_vx,
707 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy,
708 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz)
709 *   {
710 *   this->un = un;
711 *   this->locally_relevant_solution_vx = locally_relevant_solution_vx;
712 *   this->locally_relevant_solution_vy = locally_relevant_solution_vy;
713 *   this->locally_relevant_solution_vz = locally_relevant_solution_vz;
714 * @endcode
715 *
716 * initialize old vectors with current solution, this just happens the first time
717 *
718 * @code
719 *   unm1 = un;
720 *   locally_relevant_solution_vx_old = locally_relevant_solution_vx;
721 *   locally_relevant_solution_vy_old = locally_relevant_solution_vy;
722 *   locally_relevant_solution_vz_old = locally_relevant_solution_vz;
723 *   }
724 *  
725 * @endcode
726 *
727 *
728 *
729 *
730 *
731 * @code
732 *   template <int dim>
733 *   void LevelSetSolver<dim>::set_boundary_conditions(std::vector<types::global_dof_index> &boundary_values_id_u,
734 *   std::vector<double> boundary_values_u)
735 *   {
736 *   this->boundary_values_id_u = boundary_values_id_u;
737 *   this->boundary_values_u = boundary_values_u;
738 *   }
739 *  
740 * @endcode
741 *
742 *
743 *
744 *
745 *
746 * @code
747 *   template <int dim>
748 *   void LevelSetSolver<dim>::set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_vx,
749 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy)
750 *   {
751 * @endcode
752 *
753 * SAVE OLD SOLUTION
754 *
755 * @code
756 *   save_old_vel_solution();
757 * @endcode
758 *
759 * update velocity
760 *
761 * @code
762 *   this->locally_relevant_solution_vx=locally_relevant_solution_vx;
763 *   this->locally_relevant_solution_vy=locally_relevant_solution_vy;
764 *   }
765 *  
766 *   template <int dim>
767 *   void LevelSetSolver<dim>::set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_vx,
768 *   PETScWrappers::MPI::Vector locally_relevant_solution_vy,
769 *   PETScWrappers::MPI::Vector locally_relevant_solution_vz)
770 *   {
771 * @endcode
772 *
773 * SAVE OLD SOLUTION
774 *
775 * @code
776 *   save_old_vel_solution();
777 * @endcode
778 *
779 * update velocity
780 *
781 * @code
782 *   this->locally_relevant_solution_vx=locally_relevant_solution_vx;
783 *   this->locally_relevant_solution_vy=locally_relevant_solution_vy;
784 *   this->locally_relevant_solution_vz=locally_relevant_solution_vz;
785 *   }
786 *  
787 * @endcode
788 *
789 *
790 *
791 *
792 *
793 * @code
794 *   template<int dim>
795 *   void LevelSetSolver<dim>::get_unp1(PETScWrappers::MPI::Vector &unp1) {unp1=this->unp1;}
796 *  
797 * @endcode
798 *
799 * -------------------------------------------------------------------------------
800 * ------------------------------ COMPUTE SOLUTIONS ------------------------------
801 * -------------------------------------------------------------------------------
802 *
803 * @code
804 *   template <int dim>
805 *   void LevelSetSolver<dim>::nth_time_step()
806 *   {
807 *   assemble_EntRes_Matrix();
808 * @endcode
809 *
810 * COMPUTE SOLUTION
811 *
812 * @code
813 *   if (TIME_INTEGRATION==FORWARD_EULER)
814 *   compute_solution(unp1,un,ALGORITHM);
815 *   else
816 *   compute_solution_SSP33(unp1,un,ALGORITHM);
817 * @endcode
818 *
819 * BOUNDARY CONDITIONS
820 *
821 * @code
822 *   unp1.set(boundary_values_id_u,boundary_values_u);
823 *   unp1.compress(VectorOperation::insert);
824 * @endcode
825 *
826 * CHECK MAXIMUM PRINCIPLE
827 *
828 * @code
829 *   if (CHECK_MAX_PRINCIPLE)
830 *   {
831 *   compute_bounds(un);
832 *   check_max_principle(unp1);
833 *   }
834 * @endcode
835 *
836 * pcout << "*********************************************************************... "
837 * << unp1.min() << ", " << unp1.max() << std::endl;
838 *
839 * @code
840 *   save_old_solution();
841 *   }
842 *  
843 * @endcode
844 *
845 * --------------------------------------------------------------------
846 * ------------------------------ SETUP ------------------------------
847 * --------------------------------------------------------------------
848 *
849 * @code
850 *   template <int dim>
851 *   void LevelSetSolver<dim>::setup()
852 *   {
853 *   solver_tolerance=1E-6;
854 *   degree_MAX = std::max(degree_LS,degree_U);
855 * @endcode
856 *
857 *
858 * SETUP FOR DOF HANDLERS
859 *
860 * setup system LS
861 *
862 * @code
863 *   dof_handler_LS.distribute_dofs (fe_LS);
864 *   locally_owned_dofs_LS = dof_handler_LS.locally_owned_dofs ();
865 *   locally_relevant_dofs_LS = DoFTools::extract_locally_relevant_dofs (dof_handler_LS);
866 * @endcode
867 *
868 * setup system U
869 *
870 * @code
871 *   dof_handler_U.distribute_dofs (fe_U);
872 *   locally_owned_dofs_U = dof_handler_U.locally_owned_dofs ();
873 *   locally_relevant_dofs_U = DoFTools::extract_locally_relevant_dofs (dof_handler_U);
874 * @endcode
875 *
876 *
877 * INIT CONSTRAINTS
878 *
879 *
880 * @code
881 *   constraints.clear ();
882 *   constraints.reinit (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,
1063 *   update_JxW_values);
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,
1128 *   update_JxW_values);
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);
1170 *   MC_preconditioner.reset(new PETScWrappers::PreconditionBoomerAMG(MC_matrix,PETScWrappers::PreconditionBoomerAMG::AdditionalData(true)));
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,
1194 *   update_JxW_values);
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,
1294 *   update_JxW_values);
1295 *   FEValues<dim> fe_values_U (fe_U, quadrature_formula,
1298 *   update_JxW_values);
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,
1570 *   update_JxW_values);
1571 *   FEValues<dim> fe_values_LS (fe_LS, quadrature_formula,
1574 *   update_JxW_values);
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, mpi_communicator);
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_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)
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
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 *   PetscInitialize(&argc, &argv, nullptr, nullptr);
3381 *   deallog.depth_console (0);
3382 *   {
3383 *   unsigned int degree_LS = 1;
3384 *   unsigned int degree_U = 2;
3385 *   MultiPhase<2> multi_phase(degree_LS, degree_U);
3386 *   multi_phase.run();
3387 *   }
3388 *   PetscFinalize();
3389 *   }
3390 *  
3391 *   catch (std::exception &exc)
3392 *   {
3393 *   std::cerr << std::endl << std::endl
3394 *   << "----------------------------------------------------"
3395 *   << std::endl;
3396 *   std::cerr << "Exception on processing: " << std::endl
3397 *   << exc.what() << std::endl
3398 *   << "Aborting!" << std::endl
3399 *   << "----------------------------------------------------"
3400 *   << std::endl;
3401 *   return 1;
3402 *   }
3403 *   catch (...)
3404 *   {
3405 *   std::cerr << std::endl << std::endl
3406 *   << "----------------------------------------------------"
3407 *   << std::endl;
3408 *   std::cerr << "Unknown exception!" << std::endl
3409 *   << "Aborting!" << std::endl
3410 *   << "----------------------------------------------------"
3411 *   << std::endl;
3412 *   return 1;
3413 *   }
3414 *   return 0;
3415 *   }
3416 * @endcode
3417
3418
3419<a name="ann-NavierStokesSolver.cc"></a>
3420<h1>Annotated version of NavierStokesSolver.cc</h1>
3421 *
3422 *
3423 *
3424 *
3425 * @code
3426 *   /* -----------------------------------------------------------------------------
3427 *   *
3428 *   * SPDX-License-Identifier: LGPL-2.1-or-later
3429 *   * Copyright (C) 2016 Manuel Quezada de Luna
3430 *   *
3431 *   * This file is part of the deal.II code gallery.
3432 *   *
3433 *   * -----------------------------------------------------------------------------
3434 *   */
3435 *  
3436 *   #include <deal.II/base/quadrature_lib.h>
3437 *   #include <deal.II/base/function.h>
3438 *   #include <deal.II/lac/affine_constraints.h>
3439 *   #include <deal.II/lac/vector.h>
3440 *   #include <deal.II/lac/full_matrix.h>
3441 *   #include <deal.II/lac/solver_cg.h>
3442 *   #include <deal.II/lac/petsc_sparse_matrix.h>
3443 *   #include <deal.II/lac/petsc_vector.h>
3444 *   #include <deal.II/lac/petsc_solver.h>
3445 *   #include <deal.II/lac/petsc_precondition.h>
3446 *   #include <deal.II/grid/grid_generator.h>
3447 *   #include <deal.II/grid/tria_accessor.h>
3448 *   #include <deal.II/grid/tria_iterator.h>
3449 *   #include <deal.II/dofs/dof_handler.h>
3450 *   #include <deal.II/dofs/dof_accessor.h>
3451 *   #include <deal.II/dofs/dof_tools.h>
3452 *   #include <deal.II/fe/fe_values.h>
3453 *   #include <deal.II/fe/fe_q.h>
3454 *   #include <deal.II/numerics/vector_tools.h>
3455 *   #include <deal.II/numerics/data_out.h>
3456 *   #include <deal.II/numerics/error_estimator.h>
3457 *   #include <deal.II/base/utilities.h>
3458 *   #include <deal.II/base/conditional_ostream.h>
3459 *   #include <deal.II/base/index_set.h>
3460 *   #include <deal.II/lac/sparsity_tools.h>
3461 *   #include <deal.II/distributed/tria.h>
3462 *   #include <deal.II/distributed/grid_refinement.h>
3463 *   #include <deal.II/lac/petsc_vector.h>
3464 *   #include <deal.II/base/convergence_table.h>
3465 *   #include <deal.II/base/timer.h>
3466 *   #include <deal.II/base/parameter_handler.h>
3467 *   #include <deal.II/grid/grid_tools.h>
3468 *   #include <deal.II/fe/mapping_q.h>
3469 *  
3470 *   #include <fstream>
3471 *   #include <iostream>
3472 *   #include <memory>
3473 *  
3474 *   using namespace dealii;
3475 *  
3476 *   #define MAX_NUM_ITER_TO_RECOMPUTE_PRECONDITIONER 10
3477 *  
3478 * @endcode
3479 *
3480 *
3481 *
3482 *
3483 *
3484 * @code
3485 *   template<int dim>
3486 *   class NavierStokesSolver
3487 *   {
3488 *   public:
3489 * @endcode
3490 *
3491 * constructor for using LEVEL SET
3492 *
3493 * @code
3494 *   NavierStokesSolver(const unsigned int degree_LS,
3495 *   const unsigned int degree_U,
3496 *   const double time_step,
3497 *   const double eps,
3498 *   const double rho_air,
3499 *   const double nu_air,
3500 *   const double rho_fluid,
3501 *   const double nu_fluid,
3502 *   Function<dim> &force_function,
3503 *   const bool verbose,
3505 *   MPI_Comm &mpi_communicator);
3506 * @endcode
3507 *
3508 * constructor for NOT LEVEL SET
3509 *
3510 * @code
3511 *   NavierStokesSolver(const unsigned int degree_LS,
3512 *   const unsigned int degree_U,
3513 *   const double time_step,
3514 *   Function<dim> &force_function,
3515 *   Function<dim> &rho_function,
3516 *   Function<dim> &nu_function,
3517 *   const bool verbose,
3519 *   MPI_Comm &mpi_communicator);
3520 *  
3521 * @endcode
3522 *
3523 * rho and nu functions
3524 *
3525 * @code
3526 *   void set_rho_and_nu_functions(const Function<dim> &rho_function,
3527 *   const Function<dim> &nu_function);
3528 * @endcode
3529 *
3530 * initial conditions
3531 *
3532 * @code
3533 *   void initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_rho,
3534 *   PETScWrappers::MPI::Vector locally_relevant_solution_u,
3535 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3536 *   PETScWrappers::MPI::Vector locally_relevant_solution_p);
3537 *   void initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_rho,
3538 *   PETScWrappers::MPI::Vector locally_relevant_solution_u,
3539 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3540 *   PETScWrappers::MPI::Vector locally_relevant_solution_w,
3541 *   PETScWrappers::MPI::Vector locally_relevant_solution_p);
3542 * @endcode
3543 *
3544 * boundary conditions
3545 *
3546 * @code
3547 *   void set_boundary_conditions(std::vector<types::global_dof_index> boundary_values_id_u,
3548 *   std::vector<types::global_dof_index> boundary_values_id_v, std::vector<double> boundary_values_u,
3549 *   std::vector<double> boundary_values_v);
3550 *   void set_boundary_conditions(std::vector<types::global_dof_index> boundary_values_id_u,
3551 *   std::vector<types::global_dof_index> boundary_values_id_v,
3552 *   std::vector<types::global_dof_index> boundary_values_id_w, std::vector<double> boundary_values_u,
3553 *   std::vector<double> boundary_values_v, std::vector<double> boundary_values_w);
3554 *   void set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_u,
3555 *   PETScWrappers::MPI::Vector locally_relevant_solution_v);
3556 *   void set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_u,
3557 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3558 *   PETScWrappers::MPI::Vector locally_relevant_solution_w);
3559 *   void set_phi(PETScWrappers::MPI::Vector locally_relevant_solution_phi);
3560 *   void get_pressure(PETScWrappers::MPI::Vector &locally_relevant_solution_p);
3561 *   void get_velocity(PETScWrappers::MPI::Vector &locally_relevant_solution_u,
3562 *   PETScWrappers::MPI::Vector &locally_relevant_solution_v);
3563 *   void get_velocity(PETScWrappers::MPI::Vector &locally_relevant_solution_u,
3564 *   PETScWrappers::MPI::Vector &locally_relevant_solution_v,
3565 *   PETScWrappers::MPI::Vector &locally_relevant_solution_w);
3566 * @endcode
3567 *
3568 * DO STEPS
3569 *
3570 * @code
3571 *   void nth_time_step();
3572 * @endcode
3573 *
3574 * SETUP
3575 *
3576 * @code
3577 *   void setup();
3578 *  
3579 *   ~NavierStokesSolver();
3580 *  
3581 *   private:
3582 * @endcode
3583 *
3584 * SETUP AND INITIAL CONDITION
3585 *
3586 * @code
3587 *   void setup_DOF();
3588 *   void setup_VECTORS();
3589 *   void init_constraints();
3590 * @endcode
3591 *
3592 * ASSEMBLE SYSTEMS
3593 *
3594 * @code
3595 *   void assemble_system_U();
3596 *   void assemble_system_dpsi_q();
3597 * @endcode
3598 *
3599 * SOLVERS
3600 *
3601 * @code
3602 *   void solve_U(const AffineConstraints<double> &constraints, PETScWrappers::MPI::SparseMatrix &Matrix,
3603 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner,
3604 *   PETScWrappers::MPI::Vector &completely_distributed_solution,
3605 *   const PETScWrappers::MPI::Vector &rhs);
3606 *   void solve_P(const AffineConstraints<double> &constraints, PETScWrappers::MPI::SparseMatrix &Matrix,
3607 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner,
3608 *   PETScWrappers::MPI::Vector &completely_distributed_solution,
3609 *   const PETScWrappers::MPI::Vector &rhs);
3610 * @endcode
3611 *
3612 * GET DIFFERENT FIELDS
3613 *
3614 * @code
3615 *   void get_rho_and_nu(double phi);
3616 *   void get_velocity();
3617 *   void get_pressure();
3618 * @endcode
3619 *
3620 * OTHERS
3621 *
3622 * @code
3623 *   void save_old_solution();
3624 *  
3625 *   MPI_Comm &mpi_communicator;
3627 *  
3628 *   int degree_LS;
3629 *   DoFHandler<dim> dof_handler_LS;
3630 *   FE_Q<dim> fe_LS;
3631 *   IndexSet locally_owned_dofs_LS;
3632 *   IndexSet locally_relevant_dofs_LS;
3633 *  
3634 *   int degree_U;
3635 *   DoFHandler<dim> dof_handler_U;
3636 *   FE_Q<dim> fe_U;
3637 *   IndexSet locally_owned_dofs_U;
3638 *   IndexSet locally_relevant_dofs_U;
3639 *  
3640 *   DoFHandler<dim> dof_handler_P;
3641 *   FE_Q<dim> fe_P;
3642 *   IndexSet locally_owned_dofs_P;
3643 *   IndexSet locally_relevant_dofs_P;
3644 *  
3645 *   Function<dim> &force_function;
3646 *   Function<dim> &rho_function;
3647 *   Function<dim> &nu_function;
3648 *  
3649 *   double rho_air;
3650 *   double nu_air;
3651 *   double rho_fluid;
3652 *   double nu_fluid;
3653 *  
3654 *   double time_step;
3655 *   double eps;
3656 *  
3657 *   bool verbose;
3658 *   unsigned int LEVEL_SET;
3659 *   unsigned int RHO_TIMES_RHS;
3660 *  
3661 *   ConditionalOStream pcout;
3662 *  
3663 *   double rho_min;
3664 *   double rho_value;
3665 *   double nu_value;
3666 *  
3667 *   double h;
3668 *   double umax;
3669 *  
3670 *   int degree_MAX;
3671 *  
3672 *   AffineConstraints<double> constraints;
3673 *   AffineConstraints<double> constraints_psi;
3674 *  
3675 *   std::vector<types::global_dof_index> boundary_values_id_u;
3676 *   std::vector<types::global_dof_index> boundary_values_id_v;
3677 *   std::vector<types::global_dof_index> boundary_values_id_w;
3678 *   std::vector<double> boundary_values_u;
3679 *   std::vector<double> boundary_values_v;
3680 *   std::vector<double> boundary_values_w;
3681 *  
3682 *   PETScWrappers::MPI::SparseMatrix system_Matrix_u;
3683 *   PETScWrappers::MPI::SparseMatrix system_Matrix_v;
3684 *   PETScWrappers::MPI::SparseMatrix system_Matrix_w;
3685 *   bool rebuild_Matrix_U;
3686 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_Matrix_u;
3687 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_Matrix_v;
3688 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_Matrix_w;
3690 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_S;
3692 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_M;
3693 *   bool rebuild_S_M;
3694 *   bool rebuild_Matrix_U_preconditioners;
3695 *   bool rebuild_S_M_preconditioners;
3696 *   PETScWrappers::MPI::Vector system_rhs_u;
3697 *   PETScWrappers::MPI::Vector system_rhs_v;
3698 *   PETScWrappers::MPI::Vector system_rhs_w;
3699 *   PETScWrappers::MPI::Vector system_rhs_psi;
3700 *   PETScWrappers::MPI::Vector system_rhs_q;
3701 *   PETScWrappers::MPI::Vector locally_relevant_solution_phi;
3702 *   PETScWrappers::MPI::Vector locally_relevant_solution_u;
3703 *   PETScWrappers::MPI::Vector locally_relevant_solution_v;
3704 *   PETScWrappers::MPI::Vector locally_relevant_solution_w;
3705 *   PETScWrappers::MPI::Vector locally_relevant_solution_u_old;
3706 *   PETScWrappers::MPI::Vector locally_relevant_solution_v_old;
3707 *   PETScWrappers::MPI::Vector locally_relevant_solution_w_old;
3708 *  
3709 *   PETScWrappers::MPI::Vector locally_relevant_solution_psi;
3710 *   PETScWrappers::MPI::Vector locally_relevant_solution_psi_old;
3711 *   PETScWrappers::MPI::Vector locally_relevant_solution_p;
3712 *  
3713 *   PETScWrappers::MPI::Vector completely_distributed_solution_u;
3714 *   PETScWrappers::MPI::Vector completely_distributed_solution_v;
3715 *   PETScWrappers::MPI::Vector completely_distributed_solution_w;
3716 *   PETScWrappers::MPI::Vector completely_distributed_solution_psi;
3717 *   PETScWrappers::MPI::Vector completely_distributed_solution_q;
3718 *   PETScWrappers::MPI::Vector completely_distributed_solution_p;
3719 *   };
3720 *  
3721 * @endcode
3722 *
3723 * CONSTRUCTOR FOR LEVEL SET
3724 *
3725 * @code
3726 *   template<int dim>
3727 *   NavierStokesSolver<dim>::NavierStokesSolver(const unsigned int degree_LS,
3728 *   const unsigned int degree_U,
3729 *   const double time_step,
3730 *   const double eps,
3731 *   const double rho_air,
3732 *   const double nu_air,
3733 *   const double rho_fluid,
3734 *   const double nu_fluid,
3735 *   Function<dim> &force_function,
3736 *   const bool verbose,
3738 *   MPI_Comm &mpi_communicator)
3739 *   :
3740 *   mpi_communicator(mpi_communicator),
3742 *   degree_LS(degree_LS),
3743 *   dof_handler_LS(triangulation),
3744 *   fe_LS(degree_LS),
3745 *   degree_U(degree_U),
3746 *   dof_handler_U(triangulation),
3747 *   fe_U(degree_U),
3748 *   dof_handler_P(triangulation),
3749 *   fe_P(degree_U-1),
3750 *   force_function(force_function),
3751 * @endcode
3752 *
3753 * This is dummy since rho and nu functions won't be used
3754 *
3755 * @code
3756 *   rho_function(force_function),
3757 *   nu_function(force_function),
3758 *   rho_air(rho_air),
3759 *   nu_air(nu_air),
3760 *   rho_fluid(rho_fluid),
3761 *   nu_fluid(nu_fluid),
3762 *   time_step(time_step),
3763 *   eps(eps),
3764 *   verbose(verbose),
3765 *   LEVEL_SET(1),
3766 *   RHO_TIMES_RHS(1),
3767 *   pcout(std::cout,(Utilities::MPI::this_mpi_process(mpi_communicator)==0)),
3768 *   rebuild_Matrix_U(true),
3769 *   rebuild_S_M(true),
3770 *   rebuild_Matrix_U_preconditioners(true),
3771 *   rebuild_S_M_preconditioners(true)
3772 *   {setup();}
3773 *  
3774 * @endcode
3775 *
3776 * CONSTRUCTOR NOT FOR LEVEL SET
3777 *
3778 * @code
3779 *   template<int dim>
3780 *   NavierStokesSolver<dim>::NavierStokesSolver(const unsigned int degree_LS,
3781 *   const unsigned int degree_U,
3782 *   const double time_step,
3783 *   Function<dim> &force_function,
3784 *   Function<dim> &rho_function,
3785 *   Function<dim> &nu_function,
3786 *   const bool verbose,
3787 *   parallel::distributed::Triangulation<dim> &triangulation,
3788 *   MPI_Comm &mpi_communicator) :
3789 *   mpi_communicator(mpi_communicator),
3790 *   triangulation(triangulation),
3791 *   degree_LS(degree_LS),
3792 *   dof_handler_LS(triangulation),
3793 *   fe_LS(degree_LS),
3794 *   degree_U(degree_U),
3795 *   dof_handler_U(triangulation),
3796 *   fe_U(degree_U),
3797 *   dof_handler_P(triangulation),
3798 *   fe_P(degree_U-1),
3799 *   force_function(force_function),
3800 *   rho_function(rho_function),
3801 *   nu_function(nu_function),
3802 *   time_step(time_step),
3803 *   verbose(verbose),
3804 *   LEVEL_SET(0),
3805 *   RHO_TIMES_RHS(0),
3806 *   pcout(std::cout,(Utilities::MPI::this_mpi_process(mpi_communicator)==0)),
3807 *   rebuild_Matrix_U(true),
3808 *   rebuild_S_M(true),
3809 *   rebuild_Matrix_U_preconditioners(true),
3810 *   rebuild_S_M_preconditioners(true)
3811 *   {setup();}
3812 *  
3813 *   template<int dim>
3814 *   NavierStokesSolver<dim>::~NavierStokesSolver()
3815 *   {
3816 *   dof_handler_LS.clear();
3817 *   dof_handler_U.clear();
3818 *   dof_handler_P.clear();
3819 *   }
3820 *  
3821 * @endcode
3822 *
3823 * /////////////////////////////////////////////////////////
3824 * ////////////////// SETTERS AND GETTERS //////////////////
3825 * /////////////////////////////////////////////////////////
3826 *
3827 * @code
3828 *   template<int dim>
3829 *   void NavierStokesSolver<dim>::set_rho_and_nu_functions(const Function<dim> &rho_function,
3830 *   const Function<dim> &nu_function)
3831 *   {
3832 *   this->rho_function=rho_function;
3833 *   this->nu_function=nu_function;
3834 *   }
3835 *  
3836 *   template<int dim>
3837 *   void NavierStokesSolver<dim>::initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_phi,
3838 *   PETScWrappers::MPI::Vector locally_relevant_solution_u,
3839 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3840 *   PETScWrappers::MPI::Vector locally_relevant_solution_p)
3841 *   {
3842 *   this->locally_relevant_solution_phi=locally_relevant_solution_phi;
3843 *   this->locally_relevant_solution_u=locally_relevant_solution_u;
3844 *   this->locally_relevant_solution_v=locally_relevant_solution_v;
3845 *   this->locally_relevant_solution_p=locally_relevant_solution_p;
3846 * @endcode
3847 *
3848 * set old vectors to the initial condition (just for first time step)
3849 *
3850 * @code
3851 *   save_old_solution();
3852 *   }
3853 *  
3854 *   template<int dim>
3855 *   void NavierStokesSolver<dim>::initial_condition(PETScWrappers::MPI::Vector locally_relevant_solution_phi,
3856 *   PETScWrappers::MPI::Vector locally_relevant_solution_u,
3857 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3858 *   PETScWrappers::MPI::Vector locally_relevant_solution_w,
3859 *   PETScWrappers::MPI::Vector locally_relevant_solution_p)
3860 *   {
3861 *   this->locally_relevant_solution_phi=locally_relevant_solution_phi;
3862 *   this->locally_relevant_solution_u=locally_relevant_solution_u;
3863 *   this->locally_relevant_solution_v=locally_relevant_solution_v;
3864 *   this->locally_relevant_solution_w=locally_relevant_solution_w;
3865 *   this->locally_relevant_solution_p=locally_relevant_solution_p;
3866 * @endcode
3867 *
3868 * set old vectors to the initial condition (just for first time step)
3869 *
3870 * @code
3871 *   save_old_solution();
3872 *   }
3873 *  
3874 *   template<int dim>
3875 *   void NavierStokesSolver<dim>::set_boundary_conditions(std::vector<types::global_dof_index> boundary_values_id_u,
3876 *   std::vector<types::global_dof_index> boundary_values_id_v,
3877 *   std::vector<double> boundary_values_u,
3878 *   std::vector<double> boundary_values_v)
3879 *   {
3880 *   this->boundary_values_id_u=boundary_values_id_u;
3881 *   this->boundary_values_id_v=boundary_values_id_v;
3882 *   this->boundary_values_u=boundary_values_u;
3883 *   this->boundary_values_v=boundary_values_v;
3884 *   }
3885 *  
3886 *   template<int dim>
3887 *   void NavierStokesSolver<dim>::set_boundary_conditions(std::vector<types::global_dof_index> boundary_values_id_u,
3888 *   std::vector<types::global_dof_index> boundary_values_id_v,
3889 *   std::vector<types::global_dof_index> boundary_values_id_w,
3890 *   std::vector<double> boundary_values_u,
3891 *   std::vector<double> boundary_values_v,
3892 *   std::vector<double> boundary_values_w)
3893 *   {
3894 *   this->boundary_values_id_u=boundary_values_id_u;
3895 *   this->boundary_values_id_v=boundary_values_id_v;
3896 *   this->boundary_values_id_w=boundary_values_id_w;
3897 *   this->boundary_values_u=boundary_values_u;
3898 *   this->boundary_values_v=boundary_values_v;
3899 *   this->boundary_values_w=boundary_values_w;
3900 *   }
3901 *  
3902 *   template<int dim>
3903 *   void NavierStokesSolver<dim>::set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_u,
3904 *   PETScWrappers::MPI::Vector locally_relevant_solution_v)
3905 *   {
3906 *   this->locally_relevant_solution_u=locally_relevant_solution_u;
3907 *   this->locally_relevant_solution_v=locally_relevant_solution_v;
3908 *   }
3909 *  
3910 *   template<int dim>
3911 *   void NavierStokesSolver<dim>::set_velocity(PETScWrappers::MPI::Vector locally_relevant_solution_u,
3912 *   PETScWrappers::MPI::Vector locally_relevant_solution_v,
3913 *   PETScWrappers::MPI::Vector locally_relevant_solution_w)
3914 *   {
3915 *   this->locally_relevant_solution_u=locally_relevant_solution_u;
3916 *   this->locally_relevant_solution_v=locally_relevant_solution_v;
3917 *   this->locally_relevant_solution_w=locally_relevant_solution_w;
3918 *   }
3919 *  
3920 *   template<int dim>
3921 *   void NavierStokesSolver<dim>::set_phi(PETScWrappers::MPI::Vector locally_relevant_solution_phi)
3922 *   {
3923 *   this->locally_relevant_solution_phi=locally_relevant_solution_phi;
3924 *   }
3925 *  
3926 *   template<int dim>
3927 *   void NavierStokesSolver<dim>::get_rho_and_nu(double phi)
3928 *   {
3929 *   double H=0;
3930 * @endcode
3931 *
3932 * get rho, nu
3933 *
3934 * @code
3935 *   if (phi>eps)
3936 *   H=1;
3937 *   else if (phi<-eps)
3938 *   H=-1;
3939 *   else
3940 *   H=phi/eps;
3941 *   rho_value=rho_fluid*(1+H)/2.+rho_air*(1-H)/2.;
3942 *   nu_value=nu_fluid*(1+H)/2.+nu_air*(1-H)/2.;
3943 * @endcode
3944 *
3945 * rho_value=rho_fluid*(1+phi)/2.+rho_air*(1-phi)/2.;
3946 * nu_value=nu_fluid*(1+phi)/2.+nu_air*(1-phi)/2.;
3947 *
3948 * @code
3949 *   }
3950 *  
3951 *   template<int dim>
3952 *   void NavierStokesSolver<dim>::get_pressure(PETScWrappers::MPI::Vector &locally_relevant_solution_p)
3953 *   {
3954 *   locally_relevant_solution_p=this->locally_relevant_solution_p;
3955 *   }
3956 *  
3957 *   template<int dim>
3958 *   void NavierStokesSolver<dim>::get_velocity(PETScWrappers::MPI::Vector &locally_relevant_solution_u,
3959 *   PETScWrappers::MPI::Vector &locally_relevant_solution_v)
3960 *   {
3961 *   locally_relevant_solution_u=this->locally_relevant_solution_u;
3962 *   locally_relevant_solution_v=this->locally_relevant_solution_v;
3963 *   }
3964 *  
3965 *   template<int dim>
3966 *   void NavierStokesSolver<dim>::get_velocity(PETScWrappers::MPI::Vector &locally_relevant_solution_u,
3967 *   PETScWrappers::MPI::Vector &locally_relevant_solution_v,
3968 *   PETScWrappers::MPI::Vector &locally_relevant_solution_w)
3969 *   {
3970 *   locally_relevant_solution_u=this->locally_relevant_solution_u;
3971 *   locally_relevant_solution_v=this->locally_relevant_solution_v;
3972 *   locally_relevant_solution_w=this->locally_relevant_solution_w;
3973 *   }
3974 *  
3975 * @endcode
3976 *
3977 * ///////////////////////////////////////////////////
3978 * /////////// SETUP AND INITIAL CONDITION ///////////
3979 * ///////////////////////////////////////////////////
3980 *
3981 * @code
3982 *   template<int dim>
3983 *   void NavierStokesSolver<dim>::setup()
3984 *   {
3985 *   pcout<<"***** SETUP IN NAVIER STOKES SOLVER *****"<<std::endl;
3986 *   setup_DOF();
3987 *   init_constraints();
3988 *   setup_VECTORS();
3989 *   }
3990 *  
3991 *   template<int dim>
3992 *   void NavierStokesSolver<dim>::setup_DOF()
3993 *   {
3994 *   rho_min = 1.;
3995 *   degree_MAX=std::max(degree_LS,degree_U);
3996 * @endcode
3997 *
3998 * setup system LS
3999 *
4000 * @code
4001 *   dof_handler_LS.distribute_dofs(fe_LS);
4002 *   locally_owned_dofs_LS = dof_handler_LS.locally_owned_dofs();
4003 *   locally_relevant_dofs_LS = DoFTools::extract_locally_relevant_dofs(dof_handler_LS);
4004 * @endcode
4005 *
4006 * setup system U
4007 *
4008 * @code
4009 *   dof_handler_U.distribute_dofs(fe_U);
4010 *   locally_owned_dofs_U = dof_handler_U.locally_owned_dofs();
4011 *   locally_relevant_dofs_U = DoFTools::extract_locally_relevant_dofs(dof_handler_U);
4012 * @endcode
4013 *
4014 * setup system P
4015 *
4016 * @code
4017 *   dof_handler_P.distribute_dofs(fe_P);
4018 *   locally_owned_dofs_P = dof_handler_P.locally_owned_dofs();
4019 *   locally_relevant_dofs_P = DoFTools::extract_locally_relevant_dofs(dof_handler_P);
4020 *   }
4021 *  
4022 *   template<int dim>
4023 *   void NavierStokesSolver<dim>::setup_VECTORS()
4024 *   {
4025 * @endcode
4026 *
4027 * init vectors for phi
4028 *
4029 * @code
4030 *   locally_relevant_solution_phi.reinit(locally_owned_dofs_LS,locally_relevant_dofs_LS,
4031 *   mpi_communicator);
4032 *   locally_relevant_solution_phi=0;
4033 * @endcode
4034 *
4035 * init vectors for u
4036 *
4037 * @code
4038 *   locally_relevant_solution_u.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4039 *   mpi_communicator);
4040 *   locally_relevant_solution_u=0;
4041 *   completely_distributed_solution_u.reinit(locally_owned_dofs_U,mpi_communicator);
4042 *   system_rhs_u.reinit(locally_owned_dofs_U,mpi_communicator);
4043 * @endcode
4044 *
4045 * init vectors for u_old
4046 *
4047 * @code
4048 *   locally_relevant_solution_u_old.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4049 *   mpi_communicator);
4050 *   locally_relevant_solution_u_old=0;
4051 * @endcode
4052 *
4053 * init vectors for v
4054 *
4055 * @code
4056 *   locally_relevant_solution_v.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4057 *   mpi_communicator);
4058 *   locally_relevant_solution_v=0;
4059 *   completely_distributed_solution_v.reinit(locally_owned_dofs_U,mpi_communicator);
4060 *   system_rhs_v.reinit(locally_owned_dofs_U,mpi_communicator);
4061 * @endcode
4062 *
4063 * init vectors for v_old
4064 *
4065 * @code
4066 *   locally_relevant_solution_v_old.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4067 *   mpi_communicator);
4068 *   locally_relevant_solution_v_old=0;
4069 * @endcode
4070 *
4071 * init vectors for w
4072 *
4073 * @code
4074 *   locally_relevant_solution_w.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4075 *   mpi_communicator);
4076 *   locally_relevant_solution_w=0;
4077 *   completely_distributed_solution_w.reinit(locally_owned_dofs_U,mpi_communicator);
4078 *   system_rhs_w.reinit(locally_owned_dofs_U,mpi_communicator);
4079 * @endcode
4080 *
4081 * init vectors for w_old
4082 *
4083 * @code
4084 *   locally_relevant_solution_w_old.reinit(locally_owned_dofs_U,locally_relevant_dofs_U,
4085 *   mpi_communicator);
4086 *   locally_relevant_solution_w_old=0;
4087 * @endcode
4088 *
4089 * init vectors for dpsi
4090 *
4091 * @code
4092 *   locally_relevant_solution_psi.reinit(locally_owned_dofs_P,locally_relevant_dofs_P,
4093 *   mpi_communicator);
4094 *   locally_relevant_solution_psi=0;
4095 *   system_rhs_psi.reinit(locally_owned_dofs_P,mpi_communicator);
4096 * @endcode
4097 *
4098 * init vectors for dpsi old
4099 *
4100 * @code
4101 *   locally_relevant_solution_psi_old.reinit(locally_owned_dofs_P,locally_relevant_dofs_P,
4102 *   mpi_communicator);
4103 *   locally_relevant_solution_psi_old=0;
4104 * @endcode
4105 *
4106 * init vectors for q
4107 *
4108 * @code
4109 *   completely_distributed_solution_q.reinit(locally_owned_dofs_P,mpi_communicator);
4110 *   system_rhs_q.reinit(locally_owned_dofs_P,mpi_communicator);
4111 * @endcode
4112 *
4113 * init vectors for psi
4114 *
4115 * @code
4116 *   completely_distributed_solution_psi.reinit(locally_owned_dofs_P,mpi_communicator);
4117 * @endcode
4118 *
4119 * init vectors for p
4120 *
4121 * @code
4122 *   locally_relevant_solution_p.reinit(locally_owned_dofs_P,locally_relevant_dofs_P,
4123 *   mpi_communicator);
4124 *   locally_relevant_solution_p=0;
4125 *   completely_distributed_solution_p.reinit(locally_owned_dofs_P,mpi_communicator);
4126 * @endcode
4127 *
4128 * ////////////////////////
4129 * Initialize constraints
4130 * ////////////////////////
4131 *
4132 * @code
4133 *   init_constraints();
4134 * @endcode
4135 *
4136 * //////////////////
4137 * Sparsity pattern
4138 * //////////////////
4139 * sparsity pattern for A
4140 *
4141 * @code
4142 *   DynamicSparsityPattern dsp_Matrix(locally_relevant_dofs_U);
4143 *   DoFTools::make_sparsity_pattern(dof_handler_U,dsp_Matrix,constraints,false);
4144 *   SparsityTools::distribute_sparsity_pattern(dsp_Matrix,
4145 *   dof_handler_U.locally_owned_dofs(),
4146 *   mpi_communicator,
4147 *   locally_relevant_dofs_U);
4148 *   system_Matrix_u.reinit(dof_handler_U.locally_owned_dofs(),
4149 *   dof_handler_U.locally_owned_dofs(),
4150 *   dsp_Matrix,
4151 *   mpi_communicator);
4152 *   system_Matrix_v.reinit(dof_handler_U.locally_owned_dofs(),
4153 *   dof_handler_U.locally_owned_dofs(),
4154 *   dsp_Matrix,
4155 *   mpi_communicator);
4156 *   system_Matrix_w.reinit(dof_handler_U.locally_owned_dofs(),
4157 *   dof_handler_U.locally_owned_dofs(),
4158 *   dsp_Matrix,
4159 *   mpi_communicator);
4160 *   rebuild_Matrix_U=true;
4161 * @endcode
4162 *
4163 * sparsity pattern for S
4164 *
4165 * @code
4166 *   DynamicSparsityPattern dsp_S(locally_relevant_dofs_P);
4167 *   DoFTools::make_sparsity_pattern(dof_handler_P,dsp_S,constraints_psi,false);
4168 *   SparsityTools::distribute_sparsity_pattern(dsp_S,
4169 *   dof_handler_P.locally_owned_dofs(),
4170 *   mpi_communicator,
4171 *   locally_relevant_dofs_P);
4172 *   system_S.reinit(dof_handler_P.locally_owned_dofs(),
4173 *   dof_handler_P.locally_owned_dofs(),
4174 *   dsp_S,
4175 *   mpi_communicator);
4176 * @endcode
4177 *
4178 * sparsity pattern for M
4179 *
4180 * @code
4181 *   DynamicSparsityPattern dsp_M(locally_relevant_dofs_P);
4182 *   DoFTools::make_sparsity_pattern(dof_handler_P,dsp_M,constraints_psi,false);
4183 *   SparsityTools::distribute_sparsity_pattern(dsp_M,
4184 *   dof_handler_P.locally_owned_dofs(),
4185 *   mpi_communicator,
4186 *   locally_relevant_dofs_P);
4187 *   system_M.reinit(dof_handler_P.locally_owned_dofs(),
4188 *   dof_handler_P.locally_owned_dofs(),
4189 *   dsp_M,
4190 *   mpi_communicator);
4191 *   rebuild_S_M=true;
4192 *   }
4193 *  
4194 *   template<int dim>
4195 *   void NavierStokesSolver<dim>::init_constraints()
4196 *   {
4197 * @endcode
4198 *
4199 * grl constraints
4200 *
4201 * @code
4202 *   constraints.clear();
4203 *   constraints.reinit(locally_relevant_dofs_U);
4204 *   DoFTools::make_hanging_node_constraints(dof_handler_U,constraints);
4205 *   constraints.close();
4206 * @endcode
4207 *
4208 * constraints for dpsi
4209 *
4210 * @code
4211 *   constraints_psi.clear();
4212 *   constraints_psi.reinit(locally_relevant_dofs_P);
4213 *   DoFTools::make_hanging_node_constraints(dof_handler_P,constraints_psi);
4214 * @endcode
4215 *
4216 * if (constraints_psi.can_store_line(0))
4217 * constraints_psi.add_line(0); //constraint u0 = 0
4218 *
4219 * @code
4220 *   constraints_psi.close();
4221 *   }
4222 *  
4223 * @endcode
4224 *
4225 * ///////////////////////////////////////////////////
4226 * //////////////// ASSEMBLE SYSTEMS /////////////////
4227 * ///////////////////////////////////////////////////
4228 *
4229 * @code
4230 *   template<int dim>
4231 *   void NavierStokesSolver<dim>::assemble_system_U()
4232 *   {
4233 *   if (rebuild_Matrix_U==true)
4234 *   {
4235 *   system_Matrix_u=0;
4236 *   system_Matrix_v=0;
4237 *   system_Matrix_w=0;
4238 *   }
4239 *   system_rhs_u=0;
4240 *   system_rhs_v=0;
4241 *   system_rhs_w=0;
4242 *  
4243 *   const QGauss<dim> quadrature_formula(degree_MAX+1);
4244 *   FEValues<dim> fe_values_LS(fe_LS,quadrature_formula,
4245 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4246 *   FEValues<dim> fe_values_U(fe_U,quadrature_formula,
4247 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4248 *   FEValues<dim> fe_values_P(fe_P,quadrature_formula,
4249 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4250 *  
4251 *   const unsigned int dofs_per_cell=fe_U.dofs_per_cell;
4252 *   const unsigned int n_q_points=quadrature_formula.size();
4253 *  
4254 *   FullMatrix<double> cell_A_u(dofs_per_cell,dofs_per_cell);
4255 *   Vector<double> cell_rhs_u(dofs_per_cell);
4256 *   Vector<double> cell_rhs_v(dofs_per_cell);
4257 *   Vector<double> cell_rhs_w(dofs_per_cell);
4258 *  
4259 *   std::vector<double> phiqnp1(n_q_points);
4260 *  
4261 *   std::vector<double> uqn(n_q_points);
4262 *   std::vector<double> uqnm1(n_q_points);
4263 *   std::vector<double> vqn(n_q_points);
4264 *   std::vector<double> vqnm1(n_q_points);
4265 *   std::vector<double> wqn(n_q_points);
4266 *   std::vector<double> wqnm1(n_q_points);
4267 *  
4268 * @endcode
4269 *
4270 * FOR Explicit nonlinearity
4271 * std::vector<Tensor<1, dim> > grad_un(n_q_points);
4272 * std::vector<Tensor<1, dim> > grad_vn(n_q_points);
4273 * std::vector<Tensor<1, dim> > grad_wn(n_q_points);
4274 * Tensor<1, dim> Un;
4275 *
4276
4277 *
4278 *
4279 * @code
4280 *   std::vector<Tensor<1, dim> > grad_pqn(n_q_points);
4281 *   std::vector<Tensor<1, dim> > grad_psiqn(n_q_points);
4282 *   std::vector<Tensor<1, dim> > grad_psiqnm1(n_q_points);
4283 *  
4284 *   std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
4285 *   std::vector<Tensor<1, dim> > shape_grad(dofs_per_cell);
4286 *   std::vector<double> shape_value(dofs_per_cell);
4287 *  
4288 *   double force_u;
4289 *   double force_v;
4290 *   double force_w;
4291 *   double pressure_grad_u;
4292 *   double pressure_grad_v;
4293 *   double pressure_grad_w;
4294 *   double u_star=0;
4295 *   double v_star=0;
4296 *   double w_star=0;
4297 *   double rho_star;
4298 *   double rho;
4299 *   Vector<double> force_terms(dim);
4300 *  
4301 *   typename DoFHandler<dim>::active_cell_iterator
4302 *   cell_U=dof_handler_U.begin_active(), endc_U=dof_handler_U.end();
4303 *   typename DoFHandler<dim>::active_cell_iterator cell_P=dof_handler_P.begin_active();
4304 *   typename DoFHandler<dim>::active_cell_iterator cell_LS=dof_handler_LS.begin_active();
4305 *  
4306 *   for (; cell_U!=endc_U; ++cell_U,++cell_P,++cell_LS)
4307 *   if (cell_U->is_locally_owned())
4308 *   {
4309 *   cell_A_u=0;
4310 *   cell_rhs_u=0;
4311 *   cell_rhs_v=0;
4312 *   cell_rhs_w=0;
4313 *  
4314 *   fe_values_LS.reinit(cell_LS);
4315 *   fe_values_U.reinit(cell_U);
4316 *   fe_values_P.reinit(cell_P);
4317 *  
4318 * @endcode
4319 *
4320 * get function values for LS
4321 *
4322 * @code
4323 *   fe_values_LS.get_function_values(locally_relevant_solution_phi,phiqnp1);
4324 * @endcode
4325 *
4326 * get function values for U
4327 *
4328 * @code
4329 *   fe_values_U.get_function_values(locally_relevant_solution_u,uqn);
4330 *   fe_values_U.get_function_values(locally_relevant_solution_u_old,uqnm1);
4331 *   fe_values_U.get_function_values(locally_relevant_solution_v,vqn);
4332 *   fe_values_U.get_function_values(locally_relevant_solution_v_old,vqnm1);
4333 *   if (dim==3)
4334 *   {
4335 *   fe_values_U.get_function_values(locally_relevant_solution_w,wqn);
4336 *   fe_values_U.get_function_values(locally_relevant_solution_w_old,wqnm1);
4337 *   }
4338 * @endcode
4339 *
4340 * For explicit nonlinearity
4341 * get gradient values for U
4342 * fe_values_U.get_function_gradients(locally_relevant_solution_u,grad_un);
4343 * fe_values_U.get_function_gradients(locally_relevant_solution_v,grad_vn);
4344 * if (dim==3)
4345 * fe_values_U.get_function_gradients(locally_relevant_solution_w,grad_wn);
4346 *
4347
4348 *
4349 * get values and gradients for p and dpsi
4350 *
4351 * @code
4352 *   fe_values_P.get_function_gradients(locally_relevant_solution_p,grad_pqn);
4353 *   fe_values_P.get_function_gradients(locally_relevant_solution_psi,grad_psiqn);
4354 *   fe_values_P.get_function_gradients(locally_relevant_solution_psi_old,grad_psiqnm1);
4355 *  
4356 *   for (unsigned int q_point=0; q_point<n_q_points; ++q_point)
4357 *   {
4358 *   const double JxW=fe_values_U.JxW(q_point);
4359 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
4360 *   {
4361 *   shape_grad[i]=fe_values_U.shape_grad(i,q_point);
4362 *   shape_value[i]=fe_values_U.shape_value(i,q_point);
4363 *   }
4364 *  
4365 *   pressure_grad_u=(grad_pqn[q_point][0]+4./3*grad_psiqn[q_point][0]-1./3*grad_psiqnm1[q_point][0]);
4366 *   pressure_grad_v=(grad_pqn[q_point][1]+4./3*grad_psiqn[q_point][1]-1./3*grad_psiqnm1[q_point][1]);
4367 *   if (dim==3)
4368 *   pressure_grad_w=(grad_pqn[q_point][2]+4./3*grad_psiqn[q_point][2]-1./3*grad_psiqnm1[q_point][2]);
4369 *  
4370 *   if (LEVEL_SET==1) // use level set to define rho and nu
4371 *   get_rho_and_nu(phiqnp1[q_point]);
4372 *   else // rho and nu are defined through functions
4373 *   {
4374 *   rho_value=rho_function.value(fe_values_U.quadrature_point(q_point));
4375 *   nu_value=nu_function.value(fe_values_U.quadrature_point(q_point));
4376 *   }
4377 *  
4378 * @endcode
4379 *
4380 * Non-linearity: for semi-implicit
4381 *
4382 * @code
4383 *   u_star=2*uqn[q_point]-uqnm1[q_point];
4384 *   v_star=2*vqn[q_point]-vqnm1[q_point];
4385 *   if (dim==3)
4386 *   w_star=2*wqn[q_point]-wqnm1[q_point];
4387 *  
4388 * @endcode
4389 *
4390 * for explicit nonlinearity
4391 * Un[0] = uqn[q_point];
4392 * Un[1] = vqn[q_point];
4393 * if (dim==3)
4394 * Un[2] = wqn[q_point];
4395 *
4396
4397 *
4398 * double nonlinearity_u = Un*grad_un[q_point];
4399 * double nonlinearity_v = Un*grad_vn[q_point];
4400 * double nonlinearity_w = 0;
4401 * if (dim==3)
4402 * nonlinearity_w = Un*grad_wn[q_point];
4403 *
4404
4405 *
4406 *
4407 * @code
4408 *   rho_star=rho_value; // This is because we consider rho*u_t instead of (rho*u)_t
4409 *   rho=rho_value;
4410 *  
4411 * @endcode
4412 *
4413 * FORCE TERMS
4414 *
4415 * @code
4416 *   force_function.vector_value(fe_values_U.quadrature_point(q_point),force_terms);
4417 *   force_u=force_terms[0];
4418 *   force_v=force_terms[1];
4419 *   if (dim==3)
4420 *   force_w=force_terms[2];
4421 *   if (RHO_TIMES_RHS==1)
4422 *   {
4423 *   force_u*=rho;
4424 *   force_v*=rho;
4425 *   if (dim==3)
4426 *   force_w*=rho;
4427 *   }
4428 *  
4429 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
4430 *   {
4431 *   cell_rhs_u(i)+=((4./3*rho*uqn[q_point]-1./3*rho*uqnm1[q_point]
4432 *   +2./3*time_step*(force_u-pressure_grad_u)
4433 * @endcode
4434 *
4435 * -2./3*time_step*rho*nonlinearity_u
4436 *
4437 * @code
4438 *   )*shape_value[i])*JxW;
4439 *   cell_rhs_v(i)+=((4./3*rho*vqn[q_point]-1./3*rho*vqnm1[q_point]
4440 *   +2./3*time_step*(force_v-pressure_grad_v)
4441 * @endcode
4442 *
4443 * -2./3*time_step*rho*nonlinearity_v
4444 *
4445 * @code
4446 *   )*shape_value[i])*JxW;
4447 *   if (dim==3)
4448 *   cell_rhs_w(i)+=((4./3*rho*wqn[q_point]-1./3*rho*wqnm1[q_point]
4449 *   +2./3*time_step*(force_w-pressure_grad_w)
4450 * @endcode
4451 *
4452 * -2./3*time_step*rho*nonlinearity_w
4453 *
4454 * @code
4455 *   )*shape_value[i])*JxW;
4456 *   if (rebuild_Matrix_U==true)
4457 *   for (unsigned int j=0; j<dofs_per_cell; ++j)
4458 *   {
4459 *   if (dim==2)
4460 *   cell_A_u(i,j)+=(rho_star*shape_value[i]*shape_value[j]
4461 *   +2./3*time_step*nu_value*(shape_grad[i]*shape_grad[j])
4462 *   +2./3*time_step*rho*shape_value[i]
4463 *   *(u_star*shape_grad[j][0]+v_star*shape_grad[j][1]) // semi-implicit NL
4464 *   )*JxW;
4465 *   else //dim==3
4466 *   cell_A_u(i,j)+=(rho_star*shape_value[i]*shape_value[j]
4467 *   +2./3*time_step*nu_value*(shape_grad[i]*shape_grad[j])
4468 *   +2./3*time_step*rho*shape_value[i]
4469 *   *(u_star*shape_grad[j][0]+v_star*shape_grad[j][1]+w_star*shape_grad[j][2]) // semi-implicit NL
4470 *   )*JxW;
4471 *   }
4472 *   }
4473 *   }
4474 *   cell_U->get_dof_indices(local_dof_indices);
4475 * @endcode
4476 *
4477 * distribute
4478 *
4479 * @code
4480 *   if (rebuild_Matrix_U==true)
4481 *   constraints.distribute_local_to_global(cell_A_u,local_dof_indices,system_Matrix_u);
4482 *   constraints.distribute_local_to_global(cell_rhs_u,local_dof_indices,system_rhs_u);
4483 *   constraints.distribute_local_to_global(cell_rhs_v,local_dof_indices,system_rhs_v);
4484 *   if (dim==3)
4485 *   constraints.distribute_local_to_global(cell_rhs_w,local_dof_indices,system_rhs_w);
4486 *   }
4487 *   system_rhs_u.compress(VectorOperation::add);
4488 *   system_rhs_v.compress(VectorOperation::add);
4489 *   if (dim==3) system_rhs_w.compress(VectorOperation::add);
4490 *   if (rebuild_Matrix_U==true)
4491 *   {
4492 *   system_Matrix_u.compress(VectorOperation::add);
4493 *   system_Matrix_v.copy_from(system_Matrix_u);
4494 *   if (dim==3)
4495 *   system_Matrix_w.copy_from(system_Matrix_u);
4496 *   }
4497 * @endcode
4498 *
4499 * BOUNDARY CONDITIONS
4500 *
4501 * @code
4502 *   system_rhs_u.set(boundary_values_id_u,boundary_values_u);
4503 *   system_rhs_u.compress(VectorOperation::insert);
4504 *   system_rhs_v.set(boundary_values_id_v,boundary_values_v);
4505 *   system_rhs_v.compress(VectorOperation::insert);
4506 *   if (dim==3)
4507 *   {
4508 *   system_rhs_w.set(boundary_values_id_w,boundary_values_w);
4509 *   system_rhs_w.compress(VectorOperation::insert);
4510 *   }
4511 *   if (rebuild_Matrix_U)
4512 *   {
4513 *   system_Matrix_u.clear_rows(boundary_values_id_u,1);
4514 *   system_Matrix_v.clear_rows(boundary_values_id_v,1);
4515 *   if (dim==3)
4516 *   system_Matrix_w.clear_rows(boundary_values_id_w,1);
4517 *   if (rebuild_Matrix_U_preconditioners)
4518 *   {
4519 * @endcode
4520 *
4521 * PRECONDITIONERS
4522 *
4523 * @code
4524 *   rebuild_Matrix_U_preconditioners=false;
4525 *   preconditioner_Matrix_u.reset(new PETScWrappers::PreconditionBoomerAMG
4526 *   (system_Matrix_u,PETScWrappers::PreconditionBoomerAMG::AdditionalData(false)));
4527 *   preconditioner_Matrix_v.reset( new PETScWrappers::PreconditionBoomerAMG
4528 *   (system_Matrix_v,PETScWrappers::PreconditionBoomerAMG::AdditionalData(false)));
4529 *   if (dim==3)
4530 *   preconditioner_Matrix_w.reset(new PETScWrappers::PreconditionBoomerAMG
4531 *   (system_Matrix_w,PETScWrappers::PreconditionBoomerAMG::AdditionalData(false)));
4532 *   }
4533 *   }
4534 *   rebuild_Matrix_U=true;
4535 *   }
4536 *  
4537 *   template<int dim>
4538 *   void NavierStokesSolver<dim>::assemble_system_dpsi_q()
4539 *   {
4540 *   if (rebuild_S_M==true)
4541 *   {
4542 *   system_S=0;
4543 *   system_M=0;
4544 *   }
4545 *   system_rhs_psi=0;
4546 *   system_rhs_q=0;
4547 *  
4548 *   const QGauss<dim> quadrature_formula(degree_MAX+1);
4549 *  
4550 *   FEValues<dim> fe_values_U(fe_U,quadrature_formula,
4551 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4552 *   FEValues<dim> fe_values_P(fe_P,quadrature_formula,
4553 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4554 *   FEValues<dim> fe_values_LS(fe_LS,quadrature_formula,
4555 *   update_values|update_gradients|update_quadrature_points|update_JxW_values);
4556 *  
4557 *   const unsigned int dofs_per_cell=fe_P.dofs_per_cell;
4558 *   const unsigned int n_q_points=quadrature_formula.size();
4559 *  
4560 *   FullMatrix<double> cell_S(dofs_per_cell,dofs_per_cell);
4561 *   FullMatrix<double> cell_M(dofs_per_cell,dofs_per_cell);
4562 *   Vector<double> cell_rhs_psi(dofs_per_cell);
4563 *   Vector<double> cell_rhs_q(dofs_per_cell);
4564 *  
4565 *   std::vector<double> phiqnp1(n_q_points);
4566 *   std::vector<Tensor<1, dim> > gunp1(n_q_points);
4567 *   std::vector<Tensor<1, dim> > gvnp1(n_q_points);
4568 *   std::vector<Tensor<1, dim> > gwnp1(n_q_points);
4569 *  
4570 *   std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
4571 *   std::vector<double> shape_value(dofs_per_cell);
4572 *   std::vector<Tensor<1, dim> > shape_grad(dofs_per_cell);
4573 *  
4574 *   typename DoFHandler<dim>::active_cell_iterator
4575 *   cell_P=dof_handler_P.begin_active(), endc_P=dof_handler_P.end();
4576 *   typename DoFHandler<dim>::active_cell_iterator cell_U=dof_handler_U.begin_active();
4577 *   typename DoFHandler<dim>::active_cell_iterator cell_LS=dof_handler_LS.begin_active();
4578 *  
4579 *   for (; cell_P!=endc_P; ++cell_P,++cell_U,++cell_LS)
4580 *   if (cell_P->is_locally_owned())
4581 *   {
4582 *   cell_S=0;
4583 *   cell_M=0;
4584 *   cell_rhs_psi=0;
4585 *   cell_rhs_q=0;
4586 *  
4587 *   fe_values_P.reinit(cell_P);
4588 *   fe_values_U.reinit(cell_U);
4589 *   fe_values_LS.reinit(cell_LS);
4590 *  
4591 * @endcode
4592 *
4593 * get function values for LS
4594 *
4595 * @code
4596 *   fe_values_LS.get_function_values(locally_relevant_solution_phi,phiqnp1);
4597 *  
4598 * @endcode
4599 *
4600 * get function grads for u and v
4601 *
4602 * @code
4603 *   fe_values_U.get_function_gradients(locally_relevant_solution_u,gunp1);
4604 *   fe_values_U.get_function_gradients(locally_relevant_solution_v,gvnp1);
4605 *   if (dim==3)
4606 *   fe_values_U.get_function_gradients(locally_relevant_solution_w,gwnp1);
4607 *  
4608 *   for (unsigned int q_point=0; q_point<n_q_points; ++q_point)
4609 *   {
4610 *   const double JxW=fe_values_P.JxW(q_point);
4611 *   double divU = gunp1[q_point][0]+gvnp1[q_point][1];
4612 *   if (dim==3) divU += gwnp1[q_point][2];
4613 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
4614 *   {
4615 *   shape_value[i]=fe_values_P.shape_value(i,q_point);
4616 *   shape_grad[i]=fe_values_P.shape_grad(i,q_point);
4617 *   }
4618 *   if (LEVEL_SET==1) // use level set to define rho and nu
4619 *   get_rho_and_nu (phiqnp1[q_point]);
4620 *   else // rho and nu are defined through functions
4621 *   nu_value=nu_function.value(fe_values_U.quadrature_point(q_point));
4622 *  
4623 *   for (unsigned int i=0; i<dofs_per_cell; ++i)
4624 *   {
4625 *   cell_rhs_psi(i)+=-3./2./time_step*rho_min*divU*shape_value[i]*JxW;
4626 *   cell_rhs_q(i)-=nu_value*divU*shape_value[i]*JxW;
4627 *   if (rebuild_S_M==true)
4628 *   {
4629 *   for (unsigned int j=0; j<dofs_per_cell; ++j)
4630 *   if (i==j)
4631 *   {
4632 *   cell_S(i,j)+=shape_grad[i]*shape_grad[j]*JxW+1E-10;
4633 *   cell_M(i,j)+=shape_value[i]*shape_value[j]*JxW;
4634 *   }
4635 *   else
4636 *   {
4637 *   cell_S(i,j)+=shape_grad[i]*shape_grad[j]*JxW;
4638 *   cell_M(i,j)+=shape_value[i]*shape_value[j]*JxW;
4639 *   }
4640 *   }
4641 *   }
4642 *   }
4643 *   cell_P->get_dof_indices(local_dof_indices);
4644 * @endcode
4645 *
4646 * Distribute
4647 *
4648 * @code
4649 *   if (rebuild_S_M==true)
4650 *   {
4651 *   constraints_psi.distribute_local_to_global(cell_S,local_dof_indices,system_S);
4652 *   constraints_psi.distribute_local_to_global(cell_M,local_dof_indices,system_M);
4653 *   }
4654 *   constraints_psi.distribute_local_to_global(cell_rhs_q,local_dof_indices,system_rhs_q);
4655 *   constraints_psi.distribute_local_to_global(cell_rhs_psi,local_dof_indices,system_rhs_psi);
4656 *   }
4657 *   if (rebuild_S_M==true)
4658 *   {
4659 *   system_M.compress(VectorOperation::add);
4660 *   system_S.compress(VectorOperation::add);
4661 *   if (rebuild_S_M_preconditioners)
4662 *   {
4663 *   rebuild_S_M_preconditioners=false;
4664 *   preconditioner_S.reset(new PETScWrappers::PreconditionBoomerAMG
4665 *   (system_S,PETScWrappers::PreconditionBoomerAMG::AdditionalData(true)));
4666 *   preconditioner_M.reset(new PETScWrappers::PreconditionBoomerAMG
4667 *   (system_M,PETScWrappers::PreconditionBoomerAMG::AdditionalData(true)));
4668 *   }
4669 *   }
4670 *   system_rhs_psi.compress(VectorOperation::add);
4671 *   system_rhs_q.compress(VectorOperation::add);
4672 *   rebuild_S_M=false;
4673 *   }
4674 *  
4675 * @endcode
4676 *
4677 * ///////////////////////////////////////////////////
4678 * ///////////////////// SOLVERS /////////////////////
4679 * ///////////////////////////////////////////////////
4680 *
4681 * @code
4682 *   template<int dim>
4683 *   void NavierStokesSolver<dim>::solve_U(const AffineConstraints<double> &constraints,
4684 *   PETScWrappers::MPI::SparseMatrix &Matrix,
4685 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner,
4686 *   PETScWrappers::MPI::Vector &completely_distributed_solution,
4687 *   const PETScWrappers::MPI::Vector &rhs)
4688 *   {
4689 *   SolverControl solver_control(dof_handler_U.n_dofs(),1e-6);
4690 * @endcode
4691 *
4692 * PETScWrappers::SolverCG solver(solver_control, mpi_communicator);
4693 * PETScWrappers::SolverGMRES solver(solver_control, mpi_communicator);
4694 * PETScWrappers::SolverChebychev solver(solver_control, mpi_communicator);
4695 *
4696 * @code
4697 *   PETScWrappers::SolverBicgstab solver(solver_control,mpi_communicator);
4698 *   constraints.distribute(completely_distributed_solution);
4699 *   solver.solve(Matrix,completely_distributed_solution,rhs,*preconditioner);
4700 *   constraints.distribute(completely_distributed_solution);
4701 *   if (solver_control.last_step() > MAX_NUM_ITER_TO_RECOMPUTE_PRECONDITIONER)
4702 *   rebuild_Matrix_U_preconditioners=true;
4703 *   if (verbose==true)
4704 *   pcout<<" Solved U in "<<solver_control.last_step()<<" iterations."<<std::endl;
4705 *   }
4706 *  
4707 *   template<int dim>
4708 *   void NavierStokesSolver<dim>::solve_P(const AffineConstraints<double> &constraints,
4709 *   PETScWrappers::MPI::SparseMatrix &Matrix,
4710 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner,
4711 *   PETScWrappers::MPI::Vector &completely_distributed_solution,
4712 *   const PETScWrappers::MPI::Vector &rhs)
4713 *   {
4714 *   SolverControl solver_control(dof_handler_P.n_dofs(),1e-6);
4715 *   PETScWrappers::SolverCG solver(solver_control,mpi_communicator);
4716 * @endcode
4717 *
4718 * PETScWrappers::SolverGMRES solver(solver_control, mpi_communicator);
4719 *
4720 * @code
4721 *   constraints.distribute(completely_distributed_solution);
4722 *   solver.solve(Matrix,completely_distributed_solution,rhs,*preconditioner);
4723 *   constraints.distribute(completely_distributed_solution);
4724 *   if (solver_control.last_step() > MAX_NUM_ITER_TO_RECOMPUTE_PRECONDITIONER)
4725 *   rebuild_S_M_preconditioners=true;
4726 *   if (verbose==true)
4727 *   pcout<<" Solved P in "<<solver_control.last_step()<<" iterations."<<std::endl;
4728 *   }
4729 *  
4730 * @endcode
4731 *
4732 * ///////////////////////////////////////////////////
4733 * ////////////// get different fields ///////////////
4734 * ///////////////////////////////////////////////////
4735 *
4736 * @code
4737 *   template<int dim>
4738 *   void NavierStokesSolver<dim>::get_velocity()
4739 *   {
4740 *   assemble_system_U();
4741 *   save_old_solution();
4742 *   solve_U(constraints,system_Matrix_u,preconditioner_Matrix_u,completely_distributed_solution_u,system_rhs_u);
4743 *   locally_relevant_solution_u=completely_distributed_solution_u;
4744 *   solve_U(constraints,system_Matrix_v,preconditioner_Matrix_v,completely_distributed_solution_v,system_rhs_v);
4745 *   locally_relevant_solution_v=completely_distributed_solution_v;
4746 *   if (dim==3)
4747 *   {
4748 *   solve_U(constraints,system_Matrix_w,preconditioner_Matrix_w,completely_distributed_solution_w,system_rhs_w);
4749 *   locally_relevant_solution_w=completely_distributed_solution_w;
4750 *   }
4751 *   }
4752 *  
4753 *   template<int dim>
4754 *   void NavierStokesSolver<dim>::get_pressure()
4755 *   {
4756 * @endcode
4757 *
4758 * GET DPSI
4759 *
4760 * @code
4761 *   assemble_system_dpsi_q();
4762 *   solve_P(constraints_psi,system_S,preconditioner_S,completely_distributed_solution_psi,system_rhs_psi);
4763 *   locally_relevant_solution_psi=completely_distributed_solution_psi;
4764 * @endcode
4765 *
4766 * SOLVE Q
4767 *
4768 * @code
4769 *   solve_P(constraints,system_M,preconditioner_M,completely_distributed_solution_q,system_rhs_q);
4770 * @endcode
4771 *
4772 * UPDATE THE PRESSURE
4773 *
4774 * @code
4775 *   completely_distributed_solution_p.add(1,completely_distributed_solution_psi);
4776 *   completely_distributed_solution_p.add(1,completely_distributed_solution_q);
4777 *   locally_relevant_solution_p = completely_distributed_solution_p;
4778 *   }
4779 *  
4780 * @endcode
4781 *
4782 * ///////////////////////////////////////////////////
4783 * ///////////////////// DO STEPS ////////////////////
4784 * ///////////////////////////////////////////////////
4785 *
4786 * @code
4787 *   template<int dim>
4788 *   void NavierStokesSolver<dim>::nth_time_step()
4789 *   {
4790 *   get_velocity();
4791 *   get_pressure();
4792 *   }
4793 *  
4794 * @endcode
4795 *
4796 * ///////////////////////////////////////////////////
4797 * ////////////////////// OTHERS /////////////////////
4798 * ///////////////////////////////////////////////////
4799 *
4800 * @code
4801 *   template<int dim>
4802 *   void NavierStokesSolver<dim>::save_old_solution()
4803 *   {
4804 *   locally_relevant_solution_u_old=locally_relevant_solution_u;
4805 *   locally_relevant_solution_v_old=locally_relevant_solution_v;
4806 *   locally_relevant_solution_w_old=locally_relevant_solution_w;
4807 *   locally_relevant_solution_psi_old=locally_relevant_solution_psi;
4808 *   }
4809 *  
4810 * @endcode
4811
4812
4813<a name="ann-TestLevelSet.cc"></a>
4814<h1>Annotated version of TestLevelSet.cc</h1>
4815 *
4816 *
4817 *
4818 *
4819 * @code
4820 *   /* -----------------------------------------------------------------------------
4821 *   *
4822 *   * SPDX-License-Identifier: LGPL-2.1-or-later
4823 *   * Copyright (C) 2016 Manuel Quezada de Luna
4824 *   *
4825 *   * This file is part of the deal.II code gallery.
4826 *   *
4827 *   * -----------------------------------------------------------------------------
4828 *   */
4829 *  
4830 *   #include <deal.II/base/quadrature_lib.h>
4831 *   #include <deal.II/base/function.h>
4832 *   #include <deal.II/lac/affine_constraints.h>
4833 *   #include <deal.II/lac/vector.h>
4834 *   #include <deal.II/lac/full_matrix.h>
4835 *   #include <deal.II/lac/solver_cg.h>
4836 *   #include <deal.II/lac/petsc_sparse_matrix.h>
4837 *   #include <deal.II/lac/petsc_vector.h>
4838 *   #include <deal.II/lac/petsc_solver.h>
4839 *   #include <deal.II/lac/petsc_precondition.h>
4840 *   #include <deal.II/grid/grid_generator.h>
4841 *   #include <deal.II/grid/tria_accessor.h>
4842 *   #include <deal.II/grid/tria_iterator.h>
4843 *   #include <deal.II/dofs/dof_handler.h>
4844 *   #include <deal.II/dofs/dof_accessor.h>
4845 *   #include <deal.II/dofs/dof_tools.h>
4846 *   #include <deal.II/fe/fe_values.h>
4847 *   #include <deal.II/fe/fe_q.h>
4848 *   #include <deal.II/numerics/vector_tools.h>
4849 *   #include <deal.II/numerics/data_out.h>
4850 *   #include <deal.II/numerics/error_estimator.h>
4851 *   #include <deal.II/base/utilities.h>
4852 *   #include <deal.II/base/conditional_ostream.h>
4853 *   #include <deal.II/base/index_set.h>
4854 *   #include <deal.II/lac/sparsity_tools.h>
4855 *   #include <deal.II/distributed/tria.h>
4856 *   #include <deal.II/distributed/grid_refinement.h>
4857 *   #include <deal.II/lac/petsc_vector.h>
4858 *   #include <deal.II/base/convergence_table.h>
4859 *   #include <deal.II/base/timer.h>
4860 *   #include <deal.II/base/parameter_handler.h>
4861 *   #include <deal.II/grid/grid_tools.h>
4862 *   #include <deal.II/fe/mapping_q.h>
4863 *   #include <deal.II/fe/fe_system.h>
4864 *  
4865 *   #include <fstream>
4866 *   #include <iostream>
4867 *   #include <memory>
4868 *  
4869 *   using namespace dealii;
4870 *  
4871 * @endcode
4872 *
4873 * ///////////////////////
4874 * FOR TRANSPORT PROBLEM
4875 * ///////////////////////
4876 * TIME_INTEGRATION
4877 *
4878 * @code
4879 *   #define FORWARD_EULER 0
4880 *   #define SSP33 1
4881 * @endcode
4882 *
4883 * PROBLEM
4884 *
4885 * @code
4886 *   #define CIRCULAR_ROTATION 0
4887 *   #define DIAGONAL_ADVECTION 1
4888 * @endcode
4889 *
4890 * OTHER FLAGS
4891 *
4892 * @code
4893 *   #define VARIABLE_VELOCITY 0
4894 *  
4895 *   #include "utilities_test_LS.cc"
4896 *   #include "LevelSetSolver.cc"
4897 *  
4898 * @endcode
4899 *
4900 * ///////////////////////////////////////////////////
4901 * /////////////////// MAIN CLASS ////////////////////
4902 * ///////////////////////////////////////////////////
4903 *
4904 * @code
4905 *   template <int dim>
4906 *   class TestLevelSet
4907 *   {
4908 *   public:
4909 *   TestLevelSet (const unsigned int degree_LS,
4910 *   const unsigned int degree_U);
4911 *   ~TestLevelSet ();
4912 *   void run ();
4913 *  
4914 *   private:
4915 * @endcode
4916 *
4917 * BOUNDARY
4918 *
4919 * @code
4920 *   void set_boundary_inlet();
4921 *   void get_boundary_values_phi(std::vector<unsigned int> &boundary_values_id_phi,
4922 *   std::vector<double> &boundary_values_phi);
4923 * @endcode
4924 *
4925 * VELOCITY
4926 *
4927 * @code
4928 *   void get_interpolated_velocity();
4929 * @endcode
4930 *
4931 * SETUP AND INIT CONDITIONS
4932 *
4933 * @code
4934 *   void setup();
4935 *   void initial_condition();
4936 *   void init_constraints();
4937 * @endcode
4938 *
4939 * POST PROCESSING
4940 *
4941 * @code
4942 *   void process_solution(parallel::distributed::Triangulation<dim> &triangulation,
4943 *   DoFHandler<dim> &dof_handler_LS,
4944 *   PETScWrappers::MPI::Vector &solution);
4945 *   void output_results();
4946 *   void output_solution();
4947 *  
4948 * @endcode
4949 *
4950 * SOLUTION VECTORS
4951 *
4952 * @code
4953 *   PETScWrappers::MPI::Vector locally_relevant_solution_phi;
4954 *   PETScWrappers::MPI::Vector locally_relevant_solution_u;
4955 *   PETScWrappers::MPI::Vector locally_relevant_solution_v;
4956 *   PETScWrappers::MPI::Vector locally_relevant_solution_w;
4957 *   PETScWrappers::MPI::Vector completely_distributed_solution_phi;
4958 *   PETScWrappers::MPI::Vector completely_distributed_solution_u;
4959 *   PETScWrappers::MPI::Vector completely_distributed_solution_v;
4960 *   PETScWrappers::MPI::Vector completely_distributed_solution_w;
4961 * @endcode
4962 *
4963 * BOUNDARY VECTORS
4964 *
4965 * @code
4966 *   std::vector<unsigned int> boundary_values_id_phi;
4967 *   std::vector<double> boundary_values_phi;
4968 *  
4969 * @endcode
4970 *
4971 * GENERAL
4972 *
4973 * @code
4974 *   MPI_Comm mpi_communicator;
4975 *   parallel::distributed::Triangulation<dim> triangulation;
4976 *  
4977 *   int degree;
4978 *   int degree_LS;
4979 *   DoFHandler<dim> dof_handler_LS;
4980 *   FE_Q<dim> fe_LS;
4981 *   IndexSet locally_owned_dofs_LS;
4982 *   IndexSet locally_relevant_dofs_LS;
4983 *  
4984 *   int degree_U;
4985 *   DoFHandler<dim> dof_handler_U;
4986 *   FE_Q<dim> fe_U;
4987 *   IndexSet locally_owned_dofs_U;
4988 *   IndexSet locally_relevant_dofs_U;
4989 *  
4990 *   DoFHandler<dim> dof_handler_U_disp_field;
4991 *   FESystem<dim> fe_U_disp_field;
4992 *   IndexSet locally_owned_dofs_U_disp_field;
4993 *   IndexSet locally_relevant_dofs_U_disp_field;
4994 *  
4995 *   AffineConstraints<double> constraints;
4996 *   AffineConstraints<double> constraints_disp_field;
4997 *  
4998 *   double time;
4999 *   double time_step;
5000 *   double final_time;
5001 *   unsigned int timestep_number;
5002 *   double cfl;
5003 *   double min_h;
5004 *  
5005 *   double sharpness;
5006 *   int sharpness_integer;
5007 *  
5008 *   unsigned int n_refinement;
5009 *   unsigned int output_number;
5010 *   double output_time;
5011 *   bool get_output;
5012 *  
5013 *   bool verbose;
5014 *   ConditionalOStream pcout;
5015 *  
5016 * @endcode
5017 *
5018 * FOR TRANSPORT
5019 *
5020 * @code
5021 *   double cK; //compression coeff
5022 *   double cE; //entropy-visc coeff
5023 *   unsigned int TRANSPORT_TIME_INTEGRATION;
5024 *   std::string ALGORITHM;
5025 *   unsigned int PROBLEM;
5026 *  
5027 * @endcode
5028 *
5029 * FOR RECONSTRUCTION OF MATERIAL FIELDS
5030 *
5031 * @code
5032 *   double eps, rho_air, rho_fluid;
5033 *  
5034 * @endcode
5035 *
5036 * MASS MATRIX
5037 *
5038 * @code
5039 *   PETScWrappers::MPI::SparseMatrix matrix_MC, matrix_MC_tnm1;
5040 *   std::shared_ptr<PETScWrappers::PreconditionBoomerAMG> preconditioner_MC;
5041 *  
5042 *   };
5043 *  
5044 *   template <int dim>
5045 *   TestLevelSet<dim>::TestLevelSet (const unsigned int degree_LS,
5046 *   const unsigned int degree_U)
5047 *   :
5048 *   mpi_communicator (MPI_COMM_WORLD),
5049 *   triangulation (mpi_communicator,
5050 *   typename Triangulation<dim>::MeshSmoothing
5051 *   (Triangulation<dim>::smoothing_on_refinement |
5052 *   Triangulation<dim>::smoothing_on_coarsening)),
5053 *   degree_LS(degree_LS),
5054 *   dof_handler_LS (triangulation),
5055 *   fe_LS (degree_LS),
5056 *   degree_U(degree_U),
5057 *   dof_handler_U (triangulation),
5058 *   fe_U (degree_U),
5059 *   dof_handler_U_disp_field(triangulation),
5060 *   fe_U_disp_field(FE_Q<dim>(degree_U),dim),
5061 *   pcout (std::cout,(Utilities::MPI::this_mpi_process(mpi_communicator)== 0))
5062 *   {}
5063 *  
5064 *   template <int dim>
5065 *   TestLevelSet<dim>::~TestLevelSet ()
5066 *   {
5067 *   dof_handler_U_disp_field.clear();
5068 *   dof_handler_LS.clear ();
5069 *   dof_handler_U.clear ();
5070 *   }
5071 *  
5072 * @endcode
5073 *
5074 * VELOCITY
5075 * //////////
5076 *
5077 * @code
5078 *   template <int dim>
5079 *   void TestLevelSet<dim>::get_interpolated_velocity()
5080 *   {
5081 * @endcode
5082 *
5083 * velocity in x
5084 *
5085 * @code
5086 *   completely_distributed_solution_u = 0;
5087 *   VectorTools::interpolate(dof_handler_U,
5088 *   ExactU<dim>(PROBLEM,time),
5089 *   completely_distributed_solution_u);
5090 *   constraints.distribute (completely_distributed_solution_u);
5091 *   locally_relevant_solution_u = completely_distributed_solution_u;
5092 * @endcode
5093 *
5094 * velocity in y
5095 *
5096 * @code
5097 *   completely_distributed_solution_v = 0;
5098 *   VectorTools::interpolate(dof_handler_U,
5099 *   ExactV<dim>(PROBLEM,time),
5100 *   completely_distributed_solution_v);
5101 *   constraints.distribute (completely_distributed_solution_v);
5102 *   locally_relevant_solution_v = completely_distributed_solution_v;
5103 *   if (dim==3)
5104 *   {
5105 *   completely_distributed_solution_w = 0;
5106 *   VectorTools::interpolate(dof_handler_U,
5107 *   ExactW<dim>(PROBLEM,time),
5108 *   completely_distributed_solution_w);
5109 *   constraints.distribute (completely_distributed_solution_w);
5110 *   locally_relevant_solution_w = completely_distributed_solution_w;
5111 *   }
5112 *   }
5113 *  
5114 * @endcode
5115 *
5116 * //////////
5117 * BOUNDARY
5118 * //////////
5119 *
5120 * @code
5121 *   template <int dim>
5122 *   void TestLevelSet<dim>::set_boundary_inlet()
5123 *   {
5124 *   const QGauss<dim-1> face_quadrature_formula(1); // center of the face
5125 *   FEFaceValues<dim> fe_face_values (fe_U,face_quadrature_formula,
5126 *   update_values | update_quadrature_points |
5127 *   update_normal_vectors);
5128 *   const unsigned int n_face_q_points = face_quadrature_formula.size();
5129 *   std::vector<double> u_value (n_face_q_points);
5130 *   std::vector<double> v_value (n_face_q_points);
5131 *   std::vector<double> w_value (n_face_q_points);
5132 *  
5133 *   typename DoFHandler<dim>::active_cell_iterator
5134 *   cell_U = dof_handler_U.begin_active(),
5135 *   endc_U = dof_handler_U.end();
5136 *   Tensor<1,dim> u;
5137 *  
5138 *   for (; cell_U!=endc_U; ++cell_U)
5139 *   if (cell_U->is_locally_owned())
5140 *   for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
5141 *   if (cell_U->face(face)->at_boundary())
5142 *   {
5143 *   fe_face_values.reinit(cell_U,face);
5144 *   fe_face_values.get_function_values(locally_relevant_solution_u,u_value);
5145 *   fe_face_values.get_function_values(locally_relevant_solution_v,v_value);
5146 *   if (dim==3)
5147 *   fe_face_values.get_function_values(locally_relevant_solution_w,w_value);
5148 *   u[0]=u_value[0];
5149 *   u[1]=v_value[0];
5150 *   if (dim==3)
5151 *   u[2]=w_value[0];
5152 *   if (fe_face_values.normal_vector(0)*u < -1e-14)
5153 *   cell_U->face(face)->set_boundary_id(10);
5154 *   }
5155 *   }
5156 *  
5157 *   template <int dim>
5158 *   void TestLevelSet<dim>::get_boundary_values_phi(std::vector<unsigned int> &boundary_values_id_phi,
5159 *   std::vector<double> &boundary_values_phi)
5160 *   {
5161 *   std::map<unsigned int, double> map_boundary_values_phi;
5162 *   unsigned int boundary_id=0;
5163 *  
5164 *   set_boundary_inlet();
5165 *   boundary_id=10; // inlet
5166 *   VectorTools::interpolate_boundary_values (dof_handler_LS,
5167 *   boundary_id,BoundaryPhi<dim>(),
5168 *   map_boundary_values_phi);
5169 *  
5170 *   boundary_values_id_phi.resize(map_boundary_values_phi.size());
5171 *   boundary_values_phi.resize(map_boundary_values_phi.size());
5172 *   std::map<unsigned int,double>::const_iterator boundary_value_phi = map_boundary_values_phi.begin();
5173 *   for (int i=0; boundary_value_phi !=map_boundary_values_phi.end(); ++boundary_value_phi, ++i)
5174 *   {
5175 *   boundary_values_id_phi[i]=boundary_value_phi->first;
5176 *   boundary_values_phi[i]=boundary_value_phi->second;
5177 *   }
5178 *   }
5179 *  
5180 * @endcode
5181 *
5182 * ///////////////////////////////
5183 * SETUP AND INITIAL CONDITIONS
5184 * //////////////////////////////
5185 *
5186 * @code
5187 *   template <int dim>
5188 *   void TestLevelSet<dim>::setup()
5189 *   {
5190 *   degree = std::max(degree_LS,degree_U);
5191 * @endcode
5192 *
5193 * setup system LS
5194 *
5195 * @code
5196 *   dof_handler_LS.distribute_dofs (fe_LS);
5197 *   locally_owned_dofs_LS = dof_handler_LS.locally_owned_dofs ();
5198 *   locally_relevant_dofs_LS = DoFTools::extract_locally_relevant_dofs (dof_handler_LS);
5199 * @endcode
5200 *
5201 * setup system U
5202 *
5203 * @code
5204 *   dof_handler_U.distribute_dofs (fe_U);
5205 *   locally_owned_dofs_U = dof_handler_U.locally_owned_dofs ();
5206 *   locally_relevant_dofs_U = DoFTools::extract_locally_relevant_dofs (dof_handler_U);
5207 * @endcode
5208 *
5209 * setup system U for disp field
5210 *
5211 * @code
5212 *   dof_handler_U_disp_field.distribute_dofs (fe_U_disp_field);
5213 *   locally_owned_dofs_U_disp_field = dof_handler_U_disp_field.locally_owned_dofs ();
5214 *   locally_relevant_dofs_U_disp_field = DoFTools::extract_locally_relevant_dofs (dof_handler_U_disp_field);
5215 * @endcode
5216 *
5217 * init vectors for phi
5218 *
5219 * @code
5220 *   locally_relevant_solution_phi.reinit(locally_owned_dofs_LS,
5221 *   locally_relevant_dofs_LS,
5222 *   mpi_communicator);
5223 *   locally_relevant_solution_phi = 0;
5224 *   completely_distributed_solution_phi.reinit(mpi_communicator,
5225 *   dof_handler_LS.n_dofs(),
5226 *   dof_handler_LS.n_locally_owned_dofs());
5227 * @endcode
5228 *
5229 * init vectors for u
5230 *
5231 * @code
5232 *   locally_relevant_solution_u.reinit(locally_owned_dofs_U,
5233 *   locally_relevant_dofs_U,
5234 *   mpi_communicator);
5235 *   locally_relevant_solution_u = 0;
5236 *   completely_distributed_solution_u.reinit(mpi_communicator,
5237 *   dof_handler_U.n_dofs(),
5238 *   dof_handler_U.n_locally_owned_dofs());
5239 * @endcode
5240 *
5241 * init vectors for v
5242 *
5243 * @code
5244 *   locally_relevant_solution_v.reinit(locally_owned_dofs_U,
5245 *   locally_relevant_dofs_U,
5246 *   mpi_communicator);
5247 *   locally_relevant_solution_v = 0;
5248 *   completely_distributed_solution_v.reinit(mpi_communicator,
5249 *   dof_handler_U.n_dofs(),
5250 *   dof_handler_U.n_locally_owned_dofs());
5251 * @endcode
5252 *
5253 * init vectors for w
5254 *
5255 * @code
5256 *   locally_relevant_solution_w.reinit(locally_owned_dofs_U,
5257 *   locally_relevant_dofs_U,
5258 *   mpi_communicator);
5259 *   locally_relevant_solution_w = 0;
5260 *   completely_distributed_solution_w.reinit(mpi_communicator,
5261 *   dof_handler_U.n_dofs(),
5262 *   dof_handler_U.n_locally_owned_dofs());
5263 *   init_constraints();
5264 * @endcode
5265 *
5266 * MASS MATRIX
5267 *
5268 * @code
5269 *   DynamicSparsityPattern dsp (locally_relevant_dofs_LS);
5270 *   DoFTools::make_sparsity_pattern (dof_handler_LS,dsp,constraints,false);
5271 *   SparsityTools::distribute_sparsity_pattern (dsp,
5272 *   dof_handler_LS.n_locally_owned_dofs_per_processor(),
5273 *   mpi_communicator,
5274 *   locally_relevant_dofs_LS);
5275 *   matrix_MC.reinit (mpi_communicator,
5276 *   dsp,
5277 *   dof_handler_LS.n_locally_owned_dofs_per_processor(),
5278 *   dof_handler_LS.n_locally_owned_dofs_per_processor(),
5279 *   Utilities::MPI::this_mpi_process(mpi_communicator));
5280 *   matrix_MC_tnm1.reinit (mpi_communicator,
5281 *   dsp,
5282 *   dof_handler_LS.n_locally_owned_dofs_per_processor(),
5283 *   dof_handler_LS.n_locally_owned_dofs_per_processor(),
5284 *   Utilities::MPI::this_mpi_process(mpi_communicator));
5285 *   }
5286 *  
5287 *   template <int dim>
5288 *   void TestLevelSet<dim>::initial_condition()
5289 *   {
5290 *   time=0;
5291 * @endcode
5292 *
5293 * Initial conditions
5294 * init condition for phi
5295 *
5296 * @code
5297 *   completely_distributed_solution_phi = 0;
5298 *   VectorTools::interpolate(dof_handler_LS,
5299 *   InitialPhi<dim>(PROBLEM, sharpness),
5300 * @endcode
5301 *
5302 * Functions::ZeroFunction<dim>(),
5303 *
5304 * @code
5305 *   completely_distributed_solution_phi);
5306 *   constraints.distribute (completely_distributed_solution_phi);
5307 *   locally_relevant_solution_phi = completely_distributed_solution_phi;
5308 * @endcode
5309 *
5310 * init condition for u=0
5311 *
5312 * @code
5313 *   completely_distributed_solution_u = 0;
5314 *   VectorTools::interpolate(dof_handler_U,
5315 *   ExactU<dim>(PROBLEM,time),
5316 *   completely_distributed_solution_u);
5317 *   constraints.distribute (completely_distributed_solution_u);
5318 *   locally_relevant_solution_u = completely_distributed_solution_u;
5319 * @endcode
5320 *
5321 * init condition for v
5322 *
5323 * @code
5324 *   completely_distributed_solution_v = 0;
5325 *   VectorTools::interpolate(dof_handler_U,
5326 *   ExactV<dim>(PROBLEM,time),
5327 *   completely_distributed_solution_v);
5328 *   constraints.distribute (completely_distributed_solution_v);
5329 *   locally_relevant_solution_v = completely_distributed_solution_v;
5330 *   }
5331 *  
5332 *   template <int dim>
5333 *   void TestLevelSet<dim>::init_constraints()
5334 *   {
5335 *   constraints.clear ();
5336 *   constraints.reinit (locally_relevant_dofs_LS);
5337 *   DoFTools::make_hanging_node_constraints (dof_handler_LS, constraints);
5338 *   constraints.close ();
5339 *   constraints_disp_field.clear ();
5340 *   constraints_disp_field.reinit (locally_relevant_dofs_LS);
5341 *   DoFTools::make_hanging_node_constraints (dof_handler_LS, constraints_disp_field);
5342 *   constraints_disp_field.close ();
5343 *   }
5344 *  
5345 * @endcode
5346 *
5347 * /////////////////
5348 * POST PROCESSING
5349 * /////////////////
5350 *
5351 * @code
5352 *   template <int dim>
5353 *   void TestLevelSet<dim>::process_solution(parallel::distributed::Triangulation<dim> &triangulation,
5354 *   DoFHandler<dim> &dof_handler_LS,
5355 *   PETScWrappers::MPI::Vector &solution)
5356 *   {
5357 *   Vector<double> difference_per_cell (triangulation.n_active_cells());
5358 * @endcode
5359 *
5360 * error for phi
5361 *
5362 * @code
5363 *   VectorTools::integrate_difference (dof_handler_LS,
5364 *   solution,
5365 *   InitialPhi<dim>(PROBLEM,sharpness),
5366 *   difference_per_cell,
5367 *   QGauss<dim>(degree_LS+3),
5368 *   VectorTools::L1_norm);
5369 *  
5370 *   double u_L1_error = difference_per_cell.l1_norm();
5371 *   u_L1_error = std::sqrt(Utilities::MPI::sum(u_L1_error * u_L1_error, mpi_communicator));
5372 *  
5373 *   VectorTools::integrate_difference (dof_handler_LS,
5374 *   solution,
5375 *   InitialPhi<dim>(PROBLEM,sharpness),
5376 *   difference_per_cell,
5377 *   QGauss<dim>(degree_LS+3),
5378 *   VectorTools::L2_norm);
5379 *   double u_L2_error = difference_per_cell.l2_norm();
5380 *   u_L2_error = std::sqrt(Utilities::MPI::sum(u_L2_error * u_L2_error, mpi_communicator));
5381 *  
5382 *   pcout << "L1 error: " << u_L1_error << std::endl;
5383 *   pcout << "L2 error: " << u_L2_error << std::endl;
5384 *   }
5385 *  
5386 *   template<int dim>
5387 *   void TestLevelSet<dim>::output_results()
5388 *   {
5389 *   output_solution();
5390 *   output_number++;
5391 *   }
5392 *  
5393 *   template <int dim>
5394 *   void TestLevelSet<dim>::output_solution()
5395 *   {
5396 *   DataOut<dim> data_out;
5397 *   data_out.attach_dof_handler(dof_handler_LS);
5398 *   data_out.add_data_vector (locally_relevant_solution_phi, "phi");
5399 *   data_out.build_patches();
5400 *  
5401 *   const std::string filename = ("solution-" +
5402 *   Utilities::int_to_string (output_number, 3) +
5403 *   "." +
5404 *   Utilities::int_to_string
5405 *   (triangulation.locally_owned_subdomain(), 4));
5406 *   std::ofstream output ((filename + ".vtu").c_str());
5407 *   data_out.write_vtu (output);
5408 *  
5409 *   if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
5410 *   {
5411 *   std::vector<std::string> filenames;
5412 *   for (unsigned int i=0;
5413 *   i<Utilities::MPI::n_mpi_processes(mpi_communicator);
5414 *   ++i)
5415 *   filenames.push_back ("solution-" +
5416 *   Utilities::int_to_string (output_number, 3) +
5417 *   "." +
5418 *   Utilities::int_to_string (i, 4) +
5419 *   ".vtu");
5420 *  
5421 *   std::ofstream master_output ((filename + ".pvtu").c_str());
5422 *   data_out.write_pvtu_record (master_output, filenames);
5423 *   }
5424 *   }
5425 *  
5426 *   template <int dim>
5427 *   void TestLevelSet<dim>::run()
5428 *   {
5429 * @endcode
5430 *
5431 * ////////////////////
5432 * GENERAL PARAMETERS
5433 * ////////////////////
5434 *
5435 * @code
5436 *   cfl=0.1;
5437 *   verbose = false;
5438 *   get_output = true;
5439 *   output_number = 0;
5440 *   Timer t;
5441 *   n_refinement=6;
5442 *   output_time = 0.1;
5443 *   final_time = 1.0;
5444 *   PROBLEM=CIRCULAR_ROTATION;
5445 * @endcode
5446 *
5447 * PROBLEM=DIAGONAL_ADVECTION;
5448 *
5449 * @code
5450 *   double umax = 0;
5451 *   if (PROBLEM==CIRCULAR_ROTATION)
5452 *   umax = std::sqrt(2)*numbers::PI;
5453 *   else
5454 *   umax = std::sqrt(2);
5455 *  
5456 * @endcode
5457 *
5458 * //////////////////////////////////
5459 * PARAMETERS FOR TRANSPORT PROBLEM
5460 * //////////////////////////////////
5461 *
5462 * @code
5463 *   cK = 1.0; // compression constant
5464 *   cE = 1.0; // entropy viscosity constant
5465 *   sharpness_integer=1; //this will be multiplied by min_h
5466 * @endcode
5467 *
5468 * TRANSPORT_TIME_INTEGRATION=FORWARD_EULER;
5469 *
5470 * @code
5471 *   TRANSPORT_TIME_INTEGRATION=SSP33;
5472 * @endcode
5473 *
5474 * ALGORITHM = "MPP_u1";
5475 *
5476 * @code
5477 *   ALGORITHM = "NMPP_uH";
5478 * @endcode
5479 *
5480 * ALGORITHM = "MPP_uH";
5481 *
5482
5483 *
5484 * //////////
5485 * GEOMETRY
5486 * //////////
5487 *
5488 * @code
5489 *   if (PROBLEM==CIRCULAR_ROTATION || PROBLEM==DIAGONAL_ADVECTION)
5490 *   GridGenerator::hyper_cube(triangulation);
5491 * @endcode
5492 *
5493 * GridGenerator::hyper_rectangle(triangulation, Point<dim>(0.0,0.0), Point<dim>(1.0,1.0), true);
5494 *
5495 * @code
5496 *   triangulation.refine_global (n_refinement);
5497 *  
5498 * @endcode
5499 *
5500 * ///////
5501 * SETUP
5502 * ///////
5503 *
5504 * @code
5505 *   setup();
5506 *  
5507 * @endcode
5508 *
5509 * for Reconstruction of MATERIAL FIELDS
5510 *
5511 * @code
5512 *   min_h = GridTools::minimal_cell_diameter(triangulation)/std::sqrt(dim)/degree;
5513 *   eps=1*min_h; //For reconstruction of density in Navier Stokes
5514 *   sharpness=sharpness_integer*min_h; //adjust value of sharpness (for init cond of phi)
5515 *   rho_fluid = 1000;
5516 *   rho_air = 1;
5517 *  
5518 * @endcode
5519 *
5520 * GET TIME STEP
5521 *
5522 * @code
5523 *   time_step = cfl*min_h/umax;
5524 *  
5525 * @endcode
5526 *
5527 * //////////////////
5528 * TRANSPORT SOLVER
5529 * //////////////////
5530 *
5531 * @code
5532 *   LevelSetSolver<dim> level_set (degree_LS,degree_U,
5533 *   time_step,cK,cE,
5534 *   verbose,
5535 *   ALGORITHM,
5536 *   TRANSPORT_TIME_INTEGRATION,
5537 *   triangulation,
5538 *   mpi_communicator);
5539 *  
5540 * @endcode
5541 *
5542 * ///////////////////
5543 * INITIAL CONDITION
5544 * ///////////////////
5545 *
5546 * @code
5547 *   initial_condition();
5548 *   output_results();
5549 *   if (dim==2)
5550 *   level_set.initial_condition(locally_relevant_solution_phi,
5551 *   locally_relevant_solution_u,locally_relevant_solution_v);
5552 *   else //dim=3
5553 *   level_set.initial_condition(locally_relevant_solution_phi,
5554 *   locally_relevant_solution_u,locally_relevant_solution_v,locally_relevant_solution_w);
5555 *  
5556 * @endcode
5557 *
5558 * /////////////////////////////
5559 * BOUNDARY CONDITIONS FOR PHI
5560 * /////////////////////////////
5561 *
5562 * @code
5563 *   get_boundary_values_phi(boundary_values_id_phi,boundary_values_phi);
5564 *   level_set.set_boundary_conditions(boundary_values_id_phi,boundary_values_phi);
5565 *  
5566 * @endcode
5567 *
5568 * OUTPUT DATA REGARDING TIME STEPPING AND MESH
5569 *
5570 * @code
5571 *   int dofs_LS = dof_handler_LS.n_dofs();
5572 *   pcout << "Cfl: " << cfl << std::endl;
5573 *   pcout << " Number of active cells: "
5574 *   << triangulation.n_global_active_cells() << std::endl
5575 *   << " Number of degrees of freedom: " << std::endl
5576 *   << " LS: " << dofs_LS << std::endl;
5577 *  
5578 * @endcode
5579 *
5580 * TIME STEPPING
5581 *
5582 * @code
5583 *   timestep_number=0;
5584 *   time=0;
5585 *   while (time<final_time)
5586 *   {
5587 *   timestep_number++;
5588 *   if (time+time_step > final_time)
5589 *   {
5590 *   pcout << "FINAL TIME STEP... " << std::endl;
5591 *   time_step = final_time-time;
5592 *   }
5593 *   pcout << "Time step " << timestep_number
5594 *   << "\twith dt=" << time_step
5595 *   << "\tat tn=" << time << std::endl;
5596 *  
5597 * @endcode
5598 *
5599 * //////////////
5600 * GET VELOCITY // (NS or interpolate from a function) at current time tn
5601 * //////////////
5602 *
5603 * @code
5604 *   if (VARIABLE_VELOCITY)
5605 *   {
5606 *   get_interpolated_velocity();
5607 * @endcode
5608 *
5609 * SET VELOCITY TO LEVEL SET SOLVER
5610 *
5611 * @code
5612 *   level_set.set_velocity(locally_relevant_solution_u,locally_relevant_solution_v);
5613 *   }
5614 * @endcode
5615 *
5616 * ////////////////////////
5617 * GET LEVEL SET SOLUTION // (at tnp1)
5618 * ////////////////////////
5619 *
5620 * @code
5621 *   level_set.nth_time_step();
5622 *  
5623 * @endcode
5624 *
5625 * /////////////
5626 * UPDATE TIME
5627 * /////////////
5628 *
5629 * @code
5630 *   time+=time_step; // time tnp1
5631 *  
5632 * @endcode
5633 *
5634 * ////////
5635 * OUTPUT
5636 * ////////
5637 *
5638 * @code
5639 *   if (get_output && time-(output_number)*output_time>=0)
5640 *   {
5641 *   level_set.get_unp1(locally_relevant_solution_phi);
5642 *   output_results();
5643 *   }
5644 *   }
5645 *   pcout << "FINAL TIME T=" << time << std::endl;
5646 *   }
5647 *  
5648 *   int main(int argc, char *argv[])
5649 *   {
5650 *   try
5651 *   {
5652 *   using namespace dealii;
5653 *   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
5654 *   PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
5655 *   deallog.depth_console (0);
5656 *   {
5657 *   unsigned int degree = 1;
5658 *   TestLevelSet<2> multiphase(degree, degree);
5659 *   multiphase.run();
5660 *   }
5661 *   PetscFinalize();
5662 *   }
5663 *   catch (std::exception &exc)
5664 *   {
5665 *   std::cerr << std::endl << std::endl
5666 *   << "----------------------------------------------------"
5667 *   << std::endl;
5668 *   std::cerr << "Exception on processing: " << std::endl
5669 *   << exc.what() << std::endl
5670 *   << "Aborting!" << std::endl
5671 *   << "----------------------------------------------------"
5672 *   << std::endl;
5673 *   return 1;
5674 *   }
5675 *   catch (...)
5676 *   {
5677 *   std::cerr << std::endl << std::endl
5678 *   << "----------------------------------------------------"
5679 *   << std::endl;
5680 *   std::cerr << "Unknown exception!" << std::endl
5681 *   << "Aborting!" << std::endl
5682 *   << "----------------------------------------------------"
5683 *   << std::endl;
5684 *   return 1;
5685 *   }
5686 *   return 0;
5687 *   }
5688 *  
5689 *  
5690 * @endcode
5691
5692
5693<a name="ann-TestNavierStokes.cc"></a>
5694<h1>Annotated version of TestNavierStokes.cc</h1>
5695 *
5696 *
5697 *
5698 *
5699 * @code
5700 *   /* -----------------------------------------------------------------------------
5701 *   *
5702 *   * SPDX-License-Identifier: LGPL-2.1-or-later
5703 *   * Copyright (C) 2016 Manuel Quezada de Luna
5704 *   *
5705 *   * This file is part of the deal.II code gallery.
5706 *   *
5707 *   * -----------------------------------------------------------------------------
5708 *   */
5709 *  
5710 *   #include <deal.II/base/quadrature_lib.h>
5711 *   #include <deal.II/base/function.h>
5712 *   #include <deal.II/lac/affine_constraints.h>
5713 *   #include <deal.II/lac/vector.h>
5714 *   #include <deal.II/lac/full_matrix.h>
5715 *   #include <deal.II/lac/solver_cg.h>
5716 *   #include <deal.II/lac/petsc_sparse_matrix.h>
5717 *   #include <deal.II/lac/petsc_vector.h>
5718 *   #include <deal.II/lac/petsc_solver.h>
5719 *   #include <deal.II/lac/petsc_precondition.h>
5720 *   #include <deal.II/grid/grid_generator.h>
5721 *   #include <deal.II/grid/tria_accessor.h>
5722 *   #include <deal.II/grid/tria_iterator.h>
5723 *   #include <deal.II/dofs/dof_handler.h>
5724 *   #include <deal.II/dofs/dof_accessor.h>
5725 *   #include <deal.II/dofs/dof_tools.h>
5726 *   #include <deal.II/fe/fe_values.h>
5727 *   #include <deal.II/fe/fe_q.h>
5728 *   #include <deal.II/numerics/vector_tools.h>
5729 *   #include <deal.II/numerics/data_out.h>
5730 *   #include <deal.II/numerics/error_estimator.h>
5731 *   #include <deal.II/base/utilities.h>
5732 *   #include <deal.II/base/conditional_ostream.h>
5733 *   #include <deal.II/base/index_set.h>
5734 *   #include <deal.II/lac/sparsity_tools.h>
5735 *   #include <deal.II/distributed/tria.h>
5736 *   #include <deal.II/distributed/grid_refinement.h>
5737 *   #include <deal.II/lac/petsc_vector.h>
5738 *   #include <deal.II/base/convergence_table.h>
5739 *   #include <deal.II/base/timer.h>
5740 *   #include <deal.II/base/parameter_handler.h>
5741 *   #include <fstream>
5742 *   #include <iostream>
5743 *   #include <deal.II/grid/grid_tools.h>
5744 *   #include <deal.II/fe/mapping_q.h>
5745 *   #include <deal.II/base/function.h>
5746 *  
5747 *   using namespace dealii;
5748 *  
5749 *   #include "utilities_test_NS.cc"
5750 *   #include "NavierStokesSolver.cc"
5751 *  
5752 * @endcode
5753 *
5754 * ///////////////////////////////////////////////////
5755 * /////////////////// MAIN CLASS ////////////////////
5756 * ///////////////////////////////////////////////////
5757 *
5758 * @code
5759 *   template <int dim>
5760 *   class TestNavierStokes
5761 *   {
5762 *   public:
5763 *   TestNavierStokes (const unsigned int degree_LS,
5764 *   const unsigned int degree_U);
5765 *   ~TestNavierStokes ();
5766 *   void run ();
5767 *  
5768 *   private:
5769 *   void get_boundary_values_U(double t);
5770 *   void fix_pressure();
5771 *   void output_results();
5772 *   void process_solution(const unsigned int cycle);
5773 *   void setup();
5774 *   void initial_condition();
5775 *   void init_constraints();
5776 *  
5777 *   PETScWrappers::MPI::Vector locally_relevant_solution_rho;
5778 *   PETScWrappers::MPI::Vector locally_relevant_solution_u;
5779 *   PETScWrappers::MPI::Vector locally_relevant_solution_v;
5780 *   PETScWrappers::MPI::Vector locally_relevant_solution_w;
5781 *   PETScWrappers::MPI::Vector locally_relevant_solution_p;
5782 *   PETScWrappers::MPI::Vector completely_distributed_solution_rho;
5783 *   PETScWrappers::MPI::Vector completely_distributed_solution_u;
5784 *   PETScWrappers::MPI::Vector completely_distributed_solution_v;
5785 *   PETScWrappers::MPI::Vector completely_distributed_solution_w;
5786 *   PETScWrappers::MPI::Vector completely_distributed_solution_p;
5787 *  
5788 *   std::vector<unsigned int> boundary_values_id_u;
5789 *   std::vector<unsigned int> boundary_values_id_v;
5790 *   std::vector<unsigned int> boundary_values_id_w;
5791 *   std::vector<double> boundary_values_u;
5792 *   std::vector<double> boundary_values_v;
5793 *   std::vector<double> boundary_values_w;
5794 *  
5795 *   double rho_fluid;
5796 *   double nu_fluid;
5797 *   double rho_air;
5798 *   double nu_air;
5799 *  
5800 *   MPI_Comm mpi_communicator;
5801 *   parallel::distributed::Triangulation<dim> triangulation;
5802 *  
5803 *   int degree_LS;
5804 *   DoFHandler<dim> dof_handler_LS;
5805 *   FE_Q<dim> fe_LS;
5806 *   IndexSet locally_owned_dofs_LS;
5807 *   IndexSet locally_relevant_dofs_LS;
5808 *  
5809 *   int degree_U;
5810 *   DoFHandler<dim> dof_handler_U;
5811 *   FE_Q<dim> fe_U;
5812 *   IndexSet locally_owned_dofs_U;
5813 *   IndexSet locally_relevant_dofs_U;
5814 *  
5815 *   DoFHandler<dim> dof_handler_P;
5816 *   FE_Q<dim> fe_P;
5817 *   IndexSet locally_owned_dofs_P;
5818 *   IndexSet locally_relevant_dofs_P;
5819 *  
5820 *   AffineConstraints<double> constraints;
5821 *  
5822 * @endcode
5823 *
5824 * TimerOutput timer;
5825 *
5826
5827 *
5828 *
5829 * @code
5830 *   double time;
5831 *   double time_step;
5832 *   double final_time;
5833 *   unsigned int timestep_number;
5834 *   double cfl;
5835 *  
5836 *   double min_h;
5837 *  
5838 *   unsigned int n_cycles;
5839 *   unsigned int n_refinement;
5840 *   unsigned int output_number;
5841 *   double output_time;
5842 *   bool get_output;
5843 *  
5844 *   double h;
5845 *   double umax;
5846 *  
5847 *   bool verbose;
5848 *  
5849 *   ConditionalOStream pcout;
5850 *   ConvergenceTable convergence_table;
5851 *  
5852 *   double nu;
5853 *   };
5854 *  
5855 *   template <int dim>
5856 *   TestNavierStokes<dim>::TestNavierStokes (const unsigned int degree_LS,
5857 *   const unsigned int degree_U)
5858 *   :
5859 *   mpi_communicator (MPI_COMM_WORLD),
5860 *   triangulation (mpi_communicator,
5861 *   typename Triangulation<dim>::MeshSmoothing
5862 *   (Triangulation<dim>::smoothing_on_refinement |
5863 *   Triangulation<dim>::smoothing_on_coarsening)),
5864 *   degree_LS(degree_LS),
5865 *   dof_handler_LS (triangulation),
5866 *   fe_LS (degree_LS),
5867 *   degree_U(degree_U),
5868 *   dof_handler_U (triangulation),
5869 *   fe_U (degree_U),
5870 *   dof_handler_P (triangulation),
5871 *   fe_P (degree_U-1), //TODO: change this to be degree_Q-1
5872 * @endcode
5873 *
5874 * timer(std::cout, TimerOutput::summary, TimerOutput::wall_times),
5875 *
5876 * @code
5877 *   pcout (std::cout,(Utilities::MPI::this_mpi_process(mpi_communicator)== 0))
5878 *   {}
5879 *  
5880 *   template <int dim>
5881 *   TestNavierStokes<dim>::~TestNavierStokes ()
5882 *   {
5883 *   dof_handler_LS.clear ();
5884 *   dof_handler_U.clear ();
5885 *   dof_handler_P.clear ();
5886 *   }
5887 *  
5888 * @endcode
5889 *
5890 * /////////////////////////////////////
5891 * /////////////// SETUP ///////////////
5892 * /////////////////////////////////////
5893 *
5894 * @code
5895 *   template <int dim>
5896 *   void TestNavierStokes<dim>::setup()
5897 *   {
5898 * @endcode
5899 *
5900 * setup system LS
5901 *
5902 * @code
5903 *   dof_handler_LS.distribute_dofs (fe_LS);
5904 *   locally_owned_dofs_LS = dof_handler_LS.locally_owned_dofs ();
5905 *   locally_relevant_dofs_LS = DoFTools::extract_locally_relevant_dofs (dof_handler_LS);
5906 * @endcode
5907 *
5908 * setup system U
5909 *
5910 * @code
5911 *   dof_handler_U.distribute_dofs (fe_U);
5912 *   locally_owned_dofs_U = dof_handler_U.locally_owned_dofs ();
5913 *   locally_relevant_dofs_U = DoFTools::extract_locally_relevant_dofs (dof_handler_U);
5914 * @endcode
5915 *
5916 * setup system P
5917 *
5918 * @code
5919 *   dof_handler_P.distribute_dofs (fe_P);
5920 *   locally_owned_dofs_P = dof_handler_P.locally_owned_dofs ();
5921 *   locally_relevant_dofs_P = DoFTools::extract_locally_relevant_dofs (dof_handler_P);
5922 *   init_constraints();
5923 * @endcode
5924 *
5925 * init vectors for rho
5926 *
5927 * @code
5928 *   locally_relevant_solution_rho.reinit (locally_owned_dofs_LS,locally_relevant_dofs_LS,mpi_communicator);
5929 *   locally_relevant_solution_rho = 0;
5930 *   completely_distributed_solution_rho.reinit(locally_owned_dofs_LS,mpi_communicator);
5931 * @endcode
5932 *
5933 * init vectors for u
5934 *
5935 * @code
5936 *   locally_relevant_solution_u.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
5937 *   locally_relevant_solution_u = 0;
5938 *   completely_distributed_solution_u.reinit(locally_owned_dofs_U,mpi_communicator);
5939 * @endcode
5940 *
5941 * init vectors for v
5942 *
5943 * @code
5944 *   locally_relevant_solution_v.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
5945 *   locally_relevant_solution_v = 0;
5946 *   completely_distributed_solution_v.reinit(locally_owned_dofs_U,mpi_communicator);
5947 * @endcode
5948 *
5949 * init vectors for w
5950 *
5951 * @code
5952 *   locally_relevant_solution_w.reinit (locally_owned_dofs_U,locally_relevant_dofs_U,mpi_communicator);
5953 *   locally_relevant_solution_w = 0;
5954 *   completely_distributed_solution_w.reinit(locally_owned_dofs_U,mpi_communicator);
5955 * @endcode
5956 *
5957 * init vectors for p
5958 *
5959 * @code
5960 *   locally_relevant_solution_p.reinit(locally_owned_dofs_P,locally_relevant_dofs_P,mpi_communicator);
5961 *   locally_relevant_solution_p = 0;
5962 *   completely_distributed_solution_p.reinit(locally_owned_dofs_P,mpi_communicator);
5963 *   }
5964 *  
5965 *   template <int dim>
5966 *   void TestNavierStokes<dim>::initial_condition()
5967 *   {
5968 *   time=0;
5969 * @endcode
5970 *
5971 * Initial conditions
5972 * init condition for rho
5973 *
5974 * @code
5975 *   completely_distributed_solution_rho = 0;
5976 *   VectorTools::interpolate(dof_handler_LS,
5977 *   RhoFunction<dim>(0),
5978 *   completely_distributed_solution_rho);
5979 *   constraints.distribute (completely_distributed_solution_rho);
5980 *   locally_relevant_solution_rho = completely_distributed_solution_rho;
5981 * @endcode
5982 *
5983 * init condition for u
5984 *
5985 * @code
5986 *   completely_distributed_solution_u = 0;
5987 *   VectorTools::interpolate(dof_handler_U,
5988 *   ExactSolution_and_BC_U<dim>(0,0),
5989 *   completely_distributed_solution_u);
5990 *   constraints.distribute (completely_distributed_solution_u);
5991 *   locally_relevant_solution_u = completely_distributed_solution_u;
5992 * @endcode
5993 *
5994 * init condition for v
5995 *
5996 * @code
5997 *   completely_distributed_solution_v = 0;
5998 *   VectorTools::interpolate(dof_handler_U,
5999 *   ExactSolution_and_BC_U<dim>(0,1),
6000 *   completely_distributed_solution_v);
6001 *   constraints.distribute (completely_distributed_solution_v);
6002 *   locally_relevant_solution_v = completely_distributed_solution_v;
6003 * @endcode
6004 *
6005 * init condition for w
6006 *
6007 * @code
6008 *   if (dim == 3)
6009 *   {
6010 *   completely_distributed_solution_w = 0;
6011 *   VectorTools::interpolate(dof_handler_U,
6012 *   ExactSolution_and_BC_U<dim>(0,2),
6013 *   completely_distributed_solution_w);
6014 *   constraints.distribute (completely_distributed_solution_w);
6015 *   locally_relevant_solution_w = completely_distributed_solution_w;
6016 *   }
6017 * @endcode
6018 *
6019 * init condition for p
6020 *
6021 * @code
6022 *   completely_distributed_solution_p = 0;
6023 *   VectorTools::interpolate(dof_handler_P,
6024 *   ExactSolution_p<dim>(0),
6025 *   completely_distributed_solution_p);
6026 *   constraints.distribute (completely_distributed_solution_p);
6027 *   locally_relevant_solution_p = completely_distributed_solution_p;
6028 *   }
6029 *  
6030 *   template <int dim>
6031 *   void TestNavierStokes<dim>::init_constraints()
6032 *   {
6033 *   constraints.clear ();
6034 *   constraints.reinit (locally_relevant_dofs_LS);
6035 *   DoFTools::make_hanging_node_constraints (dof_handler_LS, constraints);
6036 *   constraints.close ();
6037 *   }
6038 *  
6039 *   template<int dim>
6040 *   void TestNavierStokes<dim>::fix_pressure()
6041 *   {
6042 * @endcode
6043 *
6044 * fix the constant in the pressure
6045 *
6046 * @code
6047 *   completely_distributed_solution_p = locally_relevant_solution_p;
6048 *   double mean_value = VectorTools::compute_mean_value(dof_handler_P,
6049 *   QGauss<dim>(3),
6050 *   locally_relevant_solution_p,
6051 *   0);
6052 *   if (dim==2)
6053 *   completely_distributed_solution_p.add(-mean_value+std::sin(1)*(std::cos(time)-cos(1+time)));
6054 *   else
6055 *   completely_distributed_solution_p.add(-mean_value+8*std::pow(std::sin(0.5),3)*std::sin(1.5+time));
6056 *   locally_relevant_solution_p = completely_distributed_solution_p;
6057 *   }
6058 *  
6059 *   template <int dim>
6060 *   void TestNavierStokes<dim>::output_results ()
6061 *   {
6062 *   DataOut<dim> data_out;
6063 *   data_out.attach_dof_handler (dof_handler_U);
6064 *   data_out.add_data_vector (locally_relevant_solution_u, "u");
6065 *   data_out.add_data_vector (locally_relevant_solution_v, "v");
6066 *   if (dim==3) data_out.add_data_vector (locally_relevant_solution_w, "w");
6067 *  
6068 *   Vector<float> subdomain (triangulation.n_active_cells());
6069 *   for (unsigned int i=0; i<subdomain.size(); ++i)
6070 *   subdomain(i) = triangulation.locally_owned_subdomain();
6071 *   data_out.add_data_vector (subdomain, "subdomain");
6072 *  
6073 *   data_out.build_patches ();
6074 *  
6075 *   const std::string filename = ("solution-" +
6076 *   Utilities::int_to_string (output_number, 3) +
6077 *   "." +
6078 *   Utilities::int_to_string
6079 *   (triangulation.locally_owned_subdomain(), 4));
6080 *   std::ofstream output ((filename + ".vtu").c_str());
6081 *   data_out.write_vtu (output);
6082 *  
6083 *   if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
6084 *   {
6085 *   std::vector<std::string> filenames;
6086 *   for (unsigned int i=0;
6087 *   i<Utilities::MPI::n_mpi_processes(mpi_communicator);
6088 *   ++i)
6089 *   filenames.push_back ("solution-" +
6090 *   Utilities::int_to_string (output_number, 3) +
6091 *   "." +
6092 *   Utilities::int_to_string (i, 4) +
6093 *   ".vtu");
6094 *  
6095 *   std::ofstream master_output ((filename + ".pvtu").c_str());
6096 *   data_out.write_pvtu_record (master_output, filenames);
6097 *   }
6098 *   output_number++;
6099 *   }
6100 *  
6101 *   template <int dim>
6102 *   void TestNavierStokes<dim>::process_solution(const unsigned int cycle)
6103 *   {
6104 *   Vector<double> difference_per_cell (triangulation.n_active_cells());
6105 * @endcode
6106 *
6107 * error for u
6108 *
6109 * @code
6110 *   VectorTools::integrate_difference (dof_handler_U,
6111 *   locally_relevant_solution_u,
6112 *   ExactSolution_and_BC_U<dim>(time,0),
6113 *   difference_per_cell,
6114 *   QGauss<dim>(degree_U+1),
6115 *   VectorTools::L2_norm);
6116 *   double u_L2_error = difference_per_cell.l2_norm();
6117 *   u_L2_error =
6118 *   std::sqrt(Utilities::MPI::sum(u_L2_error * u_L2_error, mpi_communicator));
6119 *   VectorTools::integrate_difference (dof_handler_U,
6120 *   locally_relevant_solution_u,
6121 *   ExactSolution_and_BC_U<dim>(time,0),
6122 *   difference_per_cell,
6123 *   QGauss<dim>(degree_U+1),
6124 *   VectorTools::H1_norm);
6125 *   double u_H1_error = difference_per_cell.l2_norm();
6126 *   u_H1_error =
6127 *   std::sqrt(Utilities::MPI::sum(u_H1_error * u_H1_error, mpi_communicator));
6128 * @endcode
6129 *
6130 * error for v
6131 *
6132 * @code
6133 *   VectorTools::integrate_difference (dof_handler_U,
6134 *   locally_relevant_solution_v,
6135 *   ExactSolution_and_BC_U<dim>(time,1),
6136 *   difference_per_cell,
6137 *   QGauss<dim>(degree_U+1),
6138 *   VectorTools::L2_norm);
6139 *   double v_L2_error = difference_per_cell.l2_norm();
6140 *   v_L2_error =
6141 *   std::sqrt(Utilities::MPI::sum(v_L2_error * v_L2_error,
6142 *   mpi_communicator));
6143 *   VectorTools::integrate_difference (dof_handler_U,
6144 *   locally_relevant_solution_v,
6145 *   ExactSolution_and_BC_U<dim>(time,1),
6146 *   difference_per_cell,
6147 *   QGauss<dim>(degree_U+1),
6148 *   VectorTools::H1_norm);
6149 *   double v_H1_error = difference_per_cell.l2_norm();
6150 *   v_H1_error =
6151 *   std::sqrt(Utilities::MPI::sum(v_H1_error *
6152 *   v_H1_error, mpi_communicator));
6153 * @endcode
6154 *
6155 * error for w
6156 *
6157 * @code
6158 *   double w_L2_error = 0;
6159 *   double w_H1_error = 0;
6160 *   if (dim == 3)
6161 *   {
6162 *   VectorTools::integrate_difference (dof_handler_U,
6163 *   locally_relevant_solution_w,
6164 *   ExactSolution_and_BC_U<dim>(time,2),
6165 *   difference_per_cell,
6166 *   QGauss<dim>(degree_U+1),
6167 *   VectorTools::L2_norm);
6168 *   w_L2_error = difference_per_cell.l2_norm();
6169 *   w_L2_error =
6170 *   std::sqrt(Utilities::MPI::sum(w_L2_error * w_L2_error,
6171 *   mpi_communicator));
6172 *   VectorTools::integrate_difference (dof_handler_U,
6173 *   locally_relevant_solution_w,
6174 *   ExactSolution_and_BC_U<dim>(time,2),
6175 *   difference_per_cell,
6176 *   QGauss<dim>(degree_U+1),
6177 *   VectorTools::H1_norm);
6178 *   w_H1_error = difference_per_cell.l2_norm();
6179 *   w_H1_error =
6180 *   std::sqrt(Utilities::MPI::sum(w_H1_error *
6181 *   w_H1_error, mpi_communicator));
6182 *   }
6183 * @endcode
6184 *
6185 * error for p
6186 *
6187 * @code
6188 *   VectorTools::integrate_difference (dof_handler_P,
6189 *   locally_relevant_solution_p,
6190 *   ExactSolution_p<dim>(time),
6191 *   difference_per_cell,
6192 *   QGauss<dim>(degree_U+1),
6193 *   VectorTools::L2_norm);
6194 *   double p_L2_error = difference_per_cell.l2_norm();
6195 *   p_L2_error =
6196 *   std::sqrt(Utilities::MPI::sum(p_L2_error * p_L2_error,
6197 *   mpi_communicator));
6198 *   VectorTools::integrate_difference (dof_handler_P,
6199 *   locally_relevant_solution_p,
6200 *   ExactSolution_p<dim>(time),
6201 *   difference_per_cell,
6202 *   QGauss<dim>(degree_U+1),
6203 *   VectorTools::H1_norm);
6204 *   double p_H1_error = difference_per_cell.l2_norm();
6205 *   p_H1_error =
6206 *   std::sqrt(Utilities::MPI::sum(p_H1_error * p_H1_error,
6207 *   mpi_communicator));
6208 *  
6209 *   const unsigned int n_active_cells=triangulation.n_active_cells();
6210 *   const unsigned int n_dofs_U=dof_handler_U.n_dofs();
6211 *   const unsigned int n_dofs_P=dof_handler_P.n_dofs();
6212 *  
6213 *   convergence_table.add_value("cycle", cycle);
6214 *   convergence_table.add_value("cells", n_active_cells);
6215 *   convergence_table.add_value("dofs_U", n_dofs_U);
6216 *   convergence_table.add_value("dofs_P", n_dofs_P);
6217 *   convergence_table.add_value("dt", time_step);
6218 *   convergence_table.add_value("u L2", u_L2_error);
6219 *   convergence_table.add_value("u H1", u_H1_error);
6220 *   convergence_table.add_value("v L2", v_L2_error);
6221 *   convergence_table.add_value("v H1", v_H1_error);
6222 *   if (dim==3)
6223 *   {
6224 *   convergence_table.add_value("w L2", w_L2_error);
6225 *   convergence_table.add_value("w H1", w_H1_error);
6226 *   }
6227 *   convergence_table.add_value("p L2", p_L2_error);
6228 *   convergence_table.add_value("p H1", p_H1_error);
6229 *   }
6230 *  
6231 *   template <int dim>
6232 *   void TestNavierStokes<dim>::get_boundary_values_U(double t)
6233 *   {
6234 *   std::map<unsigned int, double> map_boundary_values_u;
6235 *   std::map<unsigned int, double> map_boundary_values_v;
6236 *  
6237 *   VectorTools::interpolate_boundary_values (dof_handler_U,0,ExactSolution_and_BC_U<dim>(t,0),map_boundary_values_u);
6238 *   VectorTools::interpolate_boundary_values (dof_handler_U,0,ExactSolution_and_BC_U<dim>(t,1),map_boundary_values_v);
6239 *  
6240 *   boundary_values_id_u.resize(map_boundary_values_u.size());
6241 *   boundary_values_id_v.resize(map_boundary_values_v.size());
6242 *   boundary_values_u.resize(map_boundary_values_u.size());
6243 *   boundary_values_v.resize(map_boundary_values_v.size());
6244 *   std::map<unsigned int,double>::const_iterator boundary_value_u =map_boundary_values_u.begin();
6245 *   std::map<unsigned int,double>::const_iterator boundary_value_v =map_boundary_values_v.begin();
6246 *   if (dim==3)
6247 *   {
6248 *   std::map<unsigned int, double> map_boundary_values_w;
6249 *   VectorTools::interpolate_boundary_values (dof_handler_U,0,ExactSolution_and_BC_U<dim>(t,2),map_boundary_values_w);
6250 *   boundary_values_id_w.resize(map_boundary_values_w.size());
6251 *   boundary_values_w.resize(map_boundary_values_w.size());
6252 *   std::map<unsigned int,double>::const_iterator boundary_value_w =map_boundary_values_w.begin();
6253 *   for (int i=0; boundary_value_w !=map_boundary_values_w.end(); ++boundary_value_w, ++i)
6254 *   {
6255 *   boundary_values_id_w[i]=boundary_value_w->first;
6256 *   boundary_values_w[i]=boundary_value_w->second;
6257 *   }
6258 *   }
6259 *   for (int i=0; boundary_value_u !=map_boundary_values_u.end(); ++boundary_value_u, ++i)
6260 *   {
6261 *   boundary_values_id_u[i]=boundary_value_u->first;
6262 *   boundary_values_u[i]=boundary_value_u->second;
6263 *   }
6264 *   for (int i=0; boundary_value_v !=map_boundary_values_v.end(); ++boundary_value_v, ++i)
6265 *   {
6266 *   boundary_values_id_v[i]=boundary_value_v->first;
6267 *   boundary_values_v[i]=boundary_value_v->second;
6268 *   }
6269 *   }
6270 *  
6271 *   template <int dim>
6272 *   void TestNavierStokes<dim>::run()
6273 *   {
6274 *   if (Utilities::MPI::this_mpi_process(mpi_communicator)== 0)
6275 *   {
6276 *   std::cout << "***** CONVERGENCE TEST FOR NS *****" << std::endl;
6277 *   std::cout << "DEGREE LS: " << degree_LS << std::endl;
6278 *   std::cout << "DEGREE U: " << degree_U << std::endl;
6279 *   }
6280 * @endcode
6281 *
6282 * PARAMETERS FOR THE NAVIER STOKES PROBLEM
6283 *
6284 * @code
6285 *   final_time = 1.0;
6286 *   time_step=0.1;
6287 *   n_cycles=6;
6288 *   n_refinement=6;
6289 *   ForceTerms<dim> force_function;
6290 *   RhoFunction<dim> rho_function;
6291 *   NuFunction<dim> nu_function;
6292 *  
6293 *   output_time=0.1;
6294 *   output_number=0;
6295 *   bool get_output = false;
6296 *   bool get_error = true;
6297 *   verbose = true;
6298 *  
6299 *   for (unsigned int cycle=0; cycle<n_cycles; ++cycle)
6300 *   {
6301 *   if (cycle == 0)
6302 *   {
6303 *   GridGenerator::hyper_cube (triangulation);
6304 *   triangulation.refine_global (n_refinement);
6305 *   setup();
6306 *   initial_condition();
6307 *   }
6308 *   else
6309 *   {
6310 *   triangulation.refine_global(1);
6311 *   setup();
6312 *   initial_condition();
6313 *   time_step*=0.5;
6314 *   }
6315 *  
6316 *   output_results();
6317 * @endcode
6318 *
6319 * if (cycle==0)
6320 *
6321 * @code
6322 *   NavierStokesSolver<dim> navier_stokes (degree_LS,
6323 *   degree_U,
6324 *   time_step,
6325 *   force_function,
6326 *   rho_function,
6327 *   nu_function,
6328 *   verbose,
6329 *   triangulation,
6330 *   mpi_communicator);
6331 * @endcode
6332 *
6333 * set INITIAL CONDITION within TRANSPORT PROBLEM
6334 *
6335 * @code
6336 *   if (dim==2)
6337 *   navier_stokes.initial_condition(locally_relevant_solution_rho,
6338 *   locally_relevant_solution_u,
6339 *   locally_relevant_solution_v,
6340 *   locally_relevant_solution_p);
6341 *   else //dim=3
6342 *   navier_stokes.initial_condition(locally_relevant_solution_rho,
6343 *   locally_relevant_solution_u,
6344 *   locally_relevant_solution_v,
6345 *   locally_relevant_solution_w,
6346 *   locally_relevant_solution_p);
6347 *  
6348 *   pcout << "Cycle " << cycle << ':' << std::endl;
6349 *   pcout << " Cycle " << cycle
6350 *   << " Number of active cells: "
6351 *   << triangulation.n_global_active_cells() << std::endl
6352 *   << " Number of degrees of freedom (velocity): "
6353 *   << dof_handler_U.n_dofs() << std::endl
6354 *   << " min h=" << GridTools::minimal_cell_diameter(triangulation)/std::sqrt(2)/degree_U
6355 *   << std::endl;
6356 *  
6357 * @endcode
6358 *
6359 * TIME STEPPING
6360 *
6361 * @code
6362 *   timestep_number=0;
6363 *   time=0;
6364 *   double time_step_backup=time_step;
6365 *   while (time<final_time)
6366 *   {
6367 *   timestep_number++;
6368 * @endcode
6369 *
6370 * ///////////////
6371 * GET TIME_STEP
6372 * ///////////////
6373 *
6374 * @code
6375 *   if (time+time_step > final_time-1E-10)
6376 *   {
6377 *   pcout << "FINAL TIME STEP..." << std::endl;
6378 *   time_step_backup=time_step;
6379 *   time_step=final_time-time;
6380 *   }
6381 *   pcout << "Time step " << timestep_number
6382 *   << "\twith dt=" << time_step
6383 *   << "\tat tn=" << time
6384 *   << std::endl;
6385 * @endcode
6386 *
6387 * /////////////
6388 * FORCE TERMS
6389 * /////////////
6390 *
6391 * @code
6392 *   force_function.set_time(time+time_step);
6393 * @endcode
6394 *
6395 * /////////////////////////////
6396 * DENSITY AND VISCOSITY FIELD
6397 * /////////////////////////////
6398 *
6399 * @code
6400 *   rho_function.set_time(time+time_step);
6401 *   nu_function.set_time(time+time_step);
6402 * @endcode
6403 *
6404 * /////////////////////
6405 * BOUNDARY CONDITIONS
6406 * /////////////////////
6407 *
6408 * @code
6409 *   get_boundary_values_U(time+time_step);
6410 *   if (dim==2) navier_stokes.set_boundary_conditions(boundary_values_id_u, boundary_values_id_v,
6411 *   boundary_values_u, boundary_values_v);
6412 *   else navier_stokes.set_boundary_conditions(boundary_values_id_u,
6413 *   boundary_values_id_v,
6414 *   boundary_values_id_w,
6415 *   boundary_values_u, boundary_values_v, boundary_values_w);
6416 * @endcode
6417 *
6418 * //////////////
6419 * GET SOLUTION
6420 * //////////////
6421 *
6422 * @code
6423 *   navier_stokes.nth_time_step();
6424 *   if (dim==2)
6425 *   navier_stokes.get_velocity(locally_relevant_solution_u,locally_relevant_solution_v);
6426 *   else
6427 *   navier_stokes.get_velocity(locally_relevant_solution_u,
6428 *   locally_relevant_solution_v,
6429 *   locally_relevant_solution_w);
6430 *   navier_stokes.get_pressure(locally_relevant_solution_p);
6431 *  
6432 * @endcode
6433 *
6434 * //////////////
6435 * FIX PRESSURE
6436 * //////////////
6437 *
6438 * @code
6439 *   fix_pressure();
6440 *  
6441 * @endcode
6442 *
6443 * /////////////
6444 * UPDATE TIME
6445 * /////////////
6446 *
6447 * @code
6448 *   time+=time_step;
6449 *  
6450 * @endcode
6451 *
6452 * ////////
6453 * OUTPUT
6454 * ////////
6455 *
6456 * @code
6457 *   if (get_output && time-(output_number)*output_time>=1E-10)
6458 *   output_results();
6459 *   }
6460 *   pcout << "FINAL TIME: " << time << std::endl;
6461 *   time_step=time_step_backup;
6462 *   if (get_error)
6463 *   process_solution(cycle);
6464 *  
6465 *   if (get_error)
6466 *   {
6467 *   convergence_table.set_precision("u L2", 2);
6468 *   convergence_table.set_precision("u H1", 2);
6469 *   convergence_table.set_scientific("u L2",true);
6470 *   convergence_table.set_scientific("u H1",true);
6471 *  
6472 *   convergence_table.set_precision("v L2", 2);
6473 *   convergence_table.set_precision("v H1", 2);
6474 *   convergence_table.set_scientific("v L2",true);
6475 *   convergence_table.set_scientific("v H1",true);
6476 *  
6477 *   if (dim==3)
6478 *   {
6479 *   convergence_table.set_precision("w L2", 2);
6480 *   convergence_table.set_precision("w H1", 2);
6481 *   convergence_table.set_scientific("w L2",true);
6482 *   convergence_table.set_scientific("w H1",true);
6483 *   }
6484 *  
6485 *   convergence_table.set_precision("p L2", 2);
6486 *   convergence_table.set_precision("p H1", 2);
6487 *   convergence_table.set_scientific("p L2",true);
6488 *   convergence_table.set_scientific("p H1",true);
6489 *  
6490 *   convergence_table.set_tex_format("cells","r");
6491 *   convergence_table.set_tex_format("dofs_U","r");
6492 *   convergence_table.set_tex_format("dofs_P","r");
6493 *   convergence_table.set_tex_format("dt","r");
6494 *  
6495 *   if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
6496 *   {
6497 *   std::cout << std::endl;
6498 *   convergence_table.write_text(std::cout);
6499 *   }
6500 *   }
6501 *   }
6502 *   }
6503 *  
6504 *   int main(int argc, char *argv[])
6505 *   {
6506 *   try
6507 *   {
6508 *   using namespace dealii;
6509 *   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
6510 *   PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
6511 *   deallog.depth_console (0);
6512 *  
6513 *   {
6514 *   unsigned int degree_LS = 1;
6515 *   unsigned int degree_U = 2;
6516 *   TestNavierStokes<2> test_navier_stokes(degree_LS, degree_U);
6517 *   test_navier_stokes.run();
6518 *   }
6519 *  
6520 *   PetscFinalize();
6521 *  
6522 *   }
6523 *  
6524 *   catch (std::exception &exc)
6525 *   {
6526 *   std::cerr << std::endl << std::endl
6527 *   << "----------------------------------------------------"
6528 *   << std::endl;
6529 *   std::cerr << "Exception on processing: " << std::endl
6530 *   << exc.what() << std::endl
6531 *   << "Aborting!" << std::endl
6532 *   << "----------------------------------------------------"
6533 *   << std::endl;
6534 *  
6535 *   return 1;
6536 *   }
6537 *   catch (...)
6538 *   {
6539 *   std::cerr << std::endl << std::endl
6540 *   << "----------------------------------------------------"
6541 *   << std::endl;
6542 *   std::cerr << "Unknown exception!" << std::endl
6543 *   << "Aborting!" << std::endl
6544 *   << "----------------------------------------------------"
6545 *   << std::endl;
6546 *   return 1;
6547 *   }
6548 *  
6549 *   return 0;
6550 *   }
6551 * @endcode
6552
6553
6554<a name="ann-clean.sh"></a>
6555<h1>Annotated version of clean.sh</h1>
6556@code{.sh}
6557rm -rf CMakeFiles CMakeCache.txt Makefile cmake_install.cmake *~
6558rm -f MultiPhase TestLevelSet TestNavierStokes
6559rm -f sol*
6560rm -f *#*
6561rm -f *.visit
6562@endcode
6563
6564
6565<a name="ann-utilities.cc"></a>
6566<h1>Annotated version of utilities.cc</h1>
6567 *
6568 *
6569 *
6570 *
6571 * @code
6572 *   /* -----------------------------------------------------------------------------
6573 *   *
6574 *   * SPDX-License-Identifier: LGPL-2.1-or-later
6575 *   * Copyright (C) 2016 Manuel Quezada de Luna
6576 *   *
6577 *   * This file is part of the deal.II code gallery.
6578 *   *
6579 *   * -----------------------------------------------------------------------------
6580 *   */
6581 *  
6582 * @endcode
6583 *
6584 * /////////////////////////////////////////////////
6585 * ////////////////// INITIAL PHI //////////////////
6586 * /////////////////////////////////////////////////
6587 *
6588 * @code
6589 *   template <int dim>
6590 *   class InitialPhi : public Function <dim>
6591 *   {
6592 *   public:
6593 *   InitialPhi (unsigned int PROBLEM, double sharpness=0.005) : Function<dim>(),
6594 *   sharpness(sharpness),
6595 *   PROBLEM(PROBLEM) {}
6596 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const override;
6597 *   double sharpness;
6598 *   unsigned int PROBLEM;
6599 *   };
6600 *   template <int dim>
6601 *   double InitialPhi<dim>::value (const Point<dim> &p,
6602 *   const unsigned int) const
6603 *   {
6604 *   double x = p[0];
6605 *   double y = p[1];
6606 *   double pi=numbers::PI;
6607 *  
6608 *   if (PROBLEM==FILLING_TANK)
6609 *   return 0.5*(-std::tanh((y-0.3)/sharpness)*std::tanh((y-0.35)/sharpness)+1)
6610 *   *(-std::tanh((x-0.02)/sharpness)+1)-1;
6611 *   else if (PROBLEM==BREAKING_DAM)
6612 *   return 0.5*(-std::tanh((x-0.35)/sharpness)*std::tanh((x-0.65)/sharpness)+1)
6613 *   *(1-std::tanh((y-0.35)/sharpness))-1;
6614 *   else if (PROBLEM==FALLING_DROP)
6615 *   {
6616 *   double x0=0.15;
6617 *   double y0=0.75;
6618 *   double r0=0.1;
6619 *   double r = std::sqrt(std::pow(x-x0,2)+std::pow(y-y0,2));
6620 *   return 1-(std::tanh((r-r0)/sharpness)+std::tanh((y-0.3)/sharpness));
6621 *   }
6622 *   else if (PROBLEM==SMALL_WAVE_PERTURBATION)
6623 *   {
6624 *   double wave = 0.1*std::sin(pi*x)+0.25;
6625 *   return -std::tanh((y-wave)/sharpness);
6626 *   }
6627 *   else
6628 *   {
6629 *   std::cout << "Error in type of PROBLEM" << std::endl;
6630 *   abort();
6631 *   }
6632 *   }
6633 *  
6634 * @endcode
6635 *
6636 * ///////////////////////////////////////////////////
6637 * ////////////////// FORCE TERMS ///// //////////////
6638 * ///////////////////////////////////////////////////
6639 *
6640 * @code
6641 *   template <int dim>
6642 *   class ForceTerms : public Functions::ConstantFunction <dim>
6643 *   {
6644 *   public:
6645 *   ForceTerms (const std::vector<double> values) : Functions::ConstantFunction<dim>(values) {}
6646 *   };
6647 *  
6648 * @endcode
6649 *
6650 * /////////////////////////////////////////////////
6651 * ////////////////// BOUNDARY PHI /////////////////
6652 * /////////////////////////////////////////////////
6653 *
6654 * @code
6655 *   template <int dim>
6656 *   class BoundaryPhi : public Functions::ConstantFunction <dim>
6657 *   {
6658 *   public:
6659 *   BoundaryPhi (const double value, const unsigned int n_components=1) : Functions::ConstantFunction<dim>(value,n_components) {}
6660 *   };
6661 *  
6662 * @endcode
6663 *
6664 * //////////////////////////////////////////////////////
6665 * ////////////////// BOUNDARY VELOCITY /////////////////
6666 * //////////////////////////////////////////////////////
6667 *
6668 * @code
6669 *   template <int dim>
6670 *   class BoundaryU : public Function <dim>
6671 *   {
6672 *   public:
6673 *   BoundaryU (unsigned int PROBLEM, double t=0) : Function<dim>(), PROBLEM(PROBLEM) {this->set_time(t);}
6674 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const override;
6675 *   unsigned PROBLEM;
6676 *   };
6677 *   template <int dim>
6678 *   double BoundaryU<dim>::value (const Point<dim> &p, const unsigned int) const
6679 *   {
6680 * @endcode
6681 *
6682 * //////////////////
6683 * FILLING THE TANK
6684 * //////////////////
6685 * boundary for filling the tank (inlet)
6686 *
6687 * @code
6688 *   double x = p[0];
6689 *   double y = p[1];
6690 *  
6691 *   if (PROBLEM==FILLING_TANK)
6692 *   {
6693 *   if (x==0 && y>=0.3 && y<=0.35)
6694 *   return 0.25;
6695 *   else
6696 *   return 0.0;
6697 *   }
6698 *   else
6699 *   {
6700 *   std::cout << "Error in PROBLEM definition" << std::endl;
6701 *   abort();
6702 *   }
6703 *   }
6704 *  
6705 *   template <int dim>
6706 *   class BoundaryV : public Function <dim>
6707 *   {
6708 *   public:
6709 *   BoundaryV (unsigned int PROBLEM, double t=0) : Function<dim>(), PROBLEM(PROBLEM) {this->set_time(t);}
6710 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const override;
6711 *   unsigned int PROBLEM;
6712 *   };
6713 *   template <int dim>
6714 *   double BoundaryV<dim>::value (const Point<dim> &p, const unsigned int) const
6715 *   {
6716 * @endcode
6717 *
6718 * boundary for filling the tank (outlet)
6719 *
6720 * @code
6721 *   double x = p[0];
6722 *   double y = p[1];
6723 *   double return_value = 0;
6724 *  
6725 *   if (PROBLEM==FILLING_TANK)
6726 *   {
6727 *   if (y==0.4 && x>=0.3 && x<=0.35)
6728 *   return_value = 0.25;
6729 *   }
6730 *   return return_value;
6731 *   }
6732 *  
6733 * @endcode
6734 *
6735 * ///////////////////////////////////////////////////
6736 * ///////////////// POST-PROCESSING /////////////////
6737 * ///////////////////////////////////////////////////
6738 *
6739 * @code
6740 *   template <int dim>
6741 *   class Postprocessor : public DataPostprocessorScalar <dim>
6742 *   {
6743 *   public:
6744 *   Postprocessor(double eps, double rho_air, double rho_fluid)
6745 *   :
6746 *   DataPostprocessorScalar<dim>("Density",update_values)
6747 *   {
6748 *   this->eps=eps;
6749 *   this->rho_air=rho_air;
6750 *   this->rho_fluid=rho_fluid;
6751 *   }
6752 *  
6753 *   virtual
6754 *   void
6755 *   evaluate_scalar_field (const DataPostprocessorInputs::Scalar<dim> &input_data,
6756 *   std::vector<Vector<double> > &computed_quantities) const override;
6757 *  
6758 *   double eps;
6759 *   double rho_air;
6760 *   double rho_fluid;
6761 *   };
6762 *  
6763 *  
6764 *   template <int dim>
6765 *   void
6766 *   Postprocessor<dim>::
6767 *   evaluate_scalar_field (const DataPostprocessorInputs::Scalar<dim> &input_data,
6768 *   std::vector<Vector<double> > &computed_quantities) const
6769 *   {
6770 *   const unsigned int n_quadrature_points = input_data.solution_values.size();
6771 *   for (unsigned int q=0; q<n_quadrature_points; ++q)
6772 *   {
6773 *   double H;
6774 *   double rho_value;
6775 *   double phi_value=input_data.solution_values[q];
6776 *   if (phi_value > eps)
6777 *   H=1;
6778 *   else if (phi_value < -eps)
6779 *   H=-1;
6780 *   else
6781 *   H=phi_value/eps;
6782 *   rho_value = rho_fluid*(1+H)/2. + rho_air*(1-H)/2.;
6783 *   computed_quantities[q] = rho_value;
6784 *   }
6785 *   }
6786 *  
6787 * @endcode
6788
6789
6790<a name="ann-utilities_test_LS.cc"></a>
6791<h1>Annotated version of utilities_test_LS.cc</h1>
6792 *
6793 *
6794 *
6795 *
6796 * @code
6797 *   /* -----------------------------------------------------------------------------
6798 *   *
6799 *   * SPDX-License-Identifier: LGPL-2.1-or-later
6800 *   * Copyright (C) 2016 Manuel Quezada de Luna
6801 *   *
6802 *   * This file is part of the deal.II code gallery.
6803 *   *
6804 *   * -----------------------------------------------------------------------------
6805 *   */
6806 *  
6807 * @endcode
6808 *
6809 * ///////////////////////////////////////////////////
6810 * ////////////////// INITIAL PHI //////////////////
6811 * ///////////////////////////////////////////////////
6812 *
6813 * @code
6814 *   template <int dim>
6815 *   class InitialPhi : public Function <dim>
6816 *   {
6817 *   public:
6818 *   InitialPhi (unsigned int PROBLEM, double sharpness=0.005) : Function<dim>(),
6819 *   sharpness(sharpness),
6820 *   PROBLEM(PROBLEM) {}
6821 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
6822 *   double sharpness;
6823 *   unsigned int PROBLEM;
6824 *   };
6825 *   template <int dim>
6826 *   double InitialPhi<dim>::value (const Point<dim> &p,
6827 *   const unsigned int) const
6828 *   {
6829 *   double x = p[0];
6830 *   double y = p[1];
6831 *   double return_value = -1.;
6832 *  
6833 *   if (PROBLEM==CIRCULAR_ROTATION)
6834 *   {
6835 *   double x0=0.5;
6836 *   double y0=0.75;
6837 *   double r0=0.15;
6838 *   double r = std::sqrt(std::pow(x-x0,2)+std::pow(y-y0,2));
6839 *   return_value = -std::tanh((r-r0)/sharpness);
6840 *   }
6841 *   else // (PROBLEM==DIAGONAL_ADVECTION)
6842 *   {
6843 *   double x0=0.25;
6844 *   double y0=0.25;
6845 *   double r0=0.15;
6846 *   double r=0;
6847 *   if (dim==2)
6848 *   r = std::sqrt(std::pow(x-x0,2)+std::pow(y-y0,2));
6849 *   else
6850 *   {
6851 *   double z0=0.25;
6852 *   double z=p[2];
6853 *   r = std::sqrt(std::pow(x-x0,2)+std::pow(y-y0,2)+std::pow(z-z0,2));
6854 *   }
6855 *   return_value = -std::tanh((r-r0)/sharpness);
6856 *   }
6857 *   return return_value;
6858 *   }
6859 *  
6860 * @endcode
6861 *
6862 * /////////////////////////////////////////////////
6863 * ////////////////// BOUNDARY PHI /////////////////
6864 * /////////////////////////////////////////////////
6865 *
6866 * @code
6867 *   template <int dim>
6868 *   class BoundaryPhi : public Function <dim>
6869 *   {
6870 *   public:
6871 *   BoundaryPhi (double t=0)
6872 *   :
6873 *   Function<dim>()
6874 *   {this->set_time(t);}
6875 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
6876 *   };
6877 *  
6878 *   template <int dim>
6879 *   double BoundaryPhi<dim>::value (const Point<dim> &, const unsigned int) const
6880 *   {
6881 *   return -1.0;
6882 *   }
6883 *  
6884 * @endcode
6885 *
6886 * ///////////////////////////////////////////////////
6887 * ////////////////// EXACT VELOCITY /////////////////
6888 * ///////////////////////////////////////////////////
6889 *
6890 * @code
6891 *   template <int dim>
6892 *   class ExactU : public Function <dim>
6893 *   {
6894 *   public:
6895 *   ExactU (unsigned int PROBLEM, double time=0) : Function<dim>(), PROBLEM(PROBLEM), time(time) {}
6896 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
6897 *   void set_time(double time) {this->time=time;};
6898 *   unsigned PROBLEM;
6899 *   double time;
6900 *   };
6901 *  
6902 *   template <int dim>
6903 *   double ExactU<dim>::value (const Point<dim> &p, const unsigned int) const
6904 *   {
6905 *   if (PROBLEM==CIRCULAR_ROTATION)
6906 *   return -2*numbers::PI*(p[1]-0.5);
6907 *   else // (PROBLEM==DIAGONAL_ADVECTION)
6908 *   return 1.0;
6909 *   }
6910 *  
6911 *   template <int dim>
6912 *   class ExactV : public Function <dim>
6913 *   {
6914 *   public:
6915 *   ExactV (unsigned int PROBLEM, double time=0) : Function<dim>(), PROBLEM(PROBLEM), time(time) {}
6916 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
6917 *   void set_time(double time) {this->time=time;};
6918 *   unsigned int PROBLEM;
6919 *   double time;
6920 *   };
6921 *  
6922 *   template <int dim>
6923 *   double ExactV<dim>::value (const Point<dim> &p, const unsigned int) const
6924 *   {
6925 *   if (PROBLEM==CIRCULAR_ROTATION)
6926 *   return 2*numbers::PI*(p[0]-0.5);
6927 *   else // (PROBLEM==DIAGONAL_ADVECTION)
6928 *   return 1.0;
6929 *   }
6930 *  
6931 *   template <int dim>
6932 *   class ExactW : public Function <dim>
6933 *   {
6934 *   public:
6935 *   ExactW (unsigned int PROBLEM, double time=0) : Function<dim>(), PROBLEM(PROBLEM), time(time) {}
6936 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
6937 *   void set_time(double time) {this->time=time;};
6938 *   unsigned int PROBLEM;
6939 *   double time;
6940 *   };
6941 *  
6942 *   template <int dim>
6943 *   double ExactW<dim>::value (const Point<dim> &, const unsigned int) const
6944 *   {
6945 * @endcode
6946 *
6947 * PROBLEM = 3D_DIAGONAL_ADVECTION
6948 *
6949 * @code
6950 *   return 1.0;
6951 *   }
6952 *  
6953 * @endcode
6954
6955
6956<a name="ann-utilities_test_NS.cc"></a>
6957<h1>Annotated version of utilities_test_NS.cc</h1>
6958 *
6959 *
6960 *
6961 *
6962 * @code
6963 *   /* -----------------------------------------------------------------------------
6964 *   *
6965 *   * SPDX-License-Identifier: LGPL-2.1-or-later
6966 *   * Copyright (C) 2016 Manuel Quezada de Luna
6967 *   *
6968 *   * This file is part of the deal.II code gallery.
6969 *   *
6970 *   * -----------------------------------------------------------------------------
6971 *   */
6972 *  
6973 * @endcode
6974 *
6975 * ///////////////////////////////////////////////////
6976 * ////////// EXACT SOLUTION RHO TO TEST NS //////////
6977 * ///////////////////////////////////////////////////
6978 *
6979 * @code
6980 *   template <int dim>
6981 *   class RhoFunction : public Function <dim>
6982 *   {
6983 *   public:
6984 *   RhoFunction (double t=0) : Function<dim>() {this->set_time(t);}
6985 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
6986 *   };
6987 *   template <int dim>
6988 *   double RhoFunction<dim>::value (const Point<dim> &p,
6989 *   const unsigned int) const
6990 *   {
6991 *   double t = this->get_time();
6992 *   double return_value = 0;
6993 *   if (dim==2)
6994 *   return_value = std::pow(std::sin(p[0]+p[1]+t),2)+1;
6995 *   else //dim=3
6996 *   return_value = std::pow(std::sin(p[0]+p[1]+p[2]+t),2)+1;
6997 *   return return_value;
6998 *   }
6999 *  
7000 *   template <int dim>
7001 *   class NuFunction : public Function <dim>
7002 *   {
7003 *   public:
7004 *   NuFunction (double t=0) : Function<dim>() {this->set_time(t);}
7005 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
7006 *   };
7007 *   template <int dim>
7008 *   double NuFunction<dim>::value (const Point<dim> &, const unsigned int) const
7009 *   {
7010 *   return 1.;
7011 *   }
7012 *  
7013 * @endcode
7014 *
7015 * //////////////////////////////////////////////////////////////
7016 * ///////////////// EXACT SOLUTION U to TEST NS ////////////////
7017 * //////////////////////////////////////////////////////////////
7018 *
7019 * @code
7020 *   template <int dim>
7021 *   class ExactSolution_and_BC_U : public Function <dim>
7022 *   {
7023 *   public:
7024 *   ExactSolution_and_BC_U (double t=0, int field=0)
7025 *   :
7026 *   Function<dim>(),
7027 *   field(field)
7028 *   {
7029 *   this->set_time(t);
7030 *   }
7031 *   virtual double value (const Point<dim> &p, const unsigned int component=1) const;
7032 *   virtual Tensor<1,dim> gradient (const Point<dim> &p, const unsigned int component=1) const;
7033 *   virtual void set_field(int field) {this->field=field;}
7034 *   int field;
7035 *   unsigned int type_simulation;
7036 *   };
7037 *   template <int dim>
7038 *   double ExactSolution_and_BC_U<dim>::value (const Point<dim> &p,
7039 *   const unsigned int) const
7040 *   {
7041 *   double t = this->get_time();
7042 *   double return_value = 0;
7043 *   double Pi = numbers::PI;
7044 *   double x = p[0];
7045 *   double y = p[1];
7046 *   double z = 0;
7047 *  
7048 *   if (dim == 2)
7049 *   if (field == 0)
7050 *   return_value = std::sin(x)*std::sin(y+t);
7051 *   else
7052 *   return_value = std::cos(x)*std::cos(y+t);
7053 *   else //dim=3
7054 *   {
7055 *   z = p[2];
7056 *   if (field == 0)
7057 *   return_value = std::cos(t)*std::cos(Pi*y)*std::cos(Pi*z)*std::sin(Pi*x);
7058 *   else if (field == 1)
7059 *   return_value = std::cos(t)*std::cos(Pi*x)*std::cos(Pi*z)*std::sin(Pi*y);
7060 *   else
7061 *   return_value = -2*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*y)*std::sin(Pi*z);
7062 *   }
7063 *   return return_value;
7064 *   }
7065 *   template <int dim>
7066 *   Tensor<1,dim> ExactSolution_and_BC_U<dim>::gradient (const Point<dim> &p,
7067 *   const unsigned int) const
7068 *   {
7069 * @endcode
7070 *
7071 * THIS IS USED JUST FOR TESTING NS
7072 *
7073 * @code
7074 *   Tensor<1,dim> return_value;
7075 *   double t = this->get_time();
7076 *   double Pi = numbers::PI;
7077 *   double x = p[0];
7078 *   double y = p[1];
7079 *   double z = 0;
7080 *   if (dim == 2)
7081 *   if (field == 0)
7082 *   {
7083 *   return_value[0] = std::cos(x)*std::sin(y+t);
7084 *   return_value[1] = std::sin(x)*std::cos(y+t);
7085 *   }
7086 *   else
7087 *   {
7088 *   return_value[0] = -std::sin(x)*std::cos(y+t);
7089 *   return_value[1] = -std::cos(x)*std::sin(y+t);
7090 *   }
7091 *   else //dim=3
7092 *   {
7093 *   z=p[2];
7094 *   if (field == 0)
7095 *   {
7096 *   return_value[0] = Pi*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*y)*std::cos(Pi*z);
7097 *   return_value[1] = -(Pi*std::cos(t)*std::cos(Pi*z)*std::sin(Pi*x)*std::sin(Pi*y));
7098 *   return_value[2] = -(Pi*std::cos(t)*std::cos(Pi*y)*std::sin(Pi*x)*std::sin(Pi*z));
7099 *   }
7100 *   else if (field == 1)
7101 *   {
7102 *   return_value[0] = -(Pi*std::cos(t)*std::cos(Pi*z)*std::sin(Pi*x)*std::sin(Pi*y));
7103 *   return_value[1] = Pi*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*y)*std::cos(Pi*z);
7104 *   return_value[2] = -(Pi*std::cos(t)*std::cos(Pi*x)*std::sin(Pi*y)*std::sin(Pi*z));
7105 *   }
7106 *   else
7107 *   {
7108 *   return_value[0] = 2*Pi*std::cos(t)*std::cos(Pi*y)*std::sin(Pi*x)*std::sin(Pi*z);
7109 *   return_value[1] = 2*Pi*std::cos(t)*std::cos(Pi*x)*std::sin(Pi*y)*std::sin(Pi*z);
7110 *   return_value[2] = -2*Pi*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*y)*std::cos(Pi*z);
7111 *   }
7112 *   }
7113 *   return return_value;
7114 *   }
7115 *  
7116 * @endcode
7117 *
7118 * ///////////////////////////////////////////////////
7119 * ///////// EXACT SOLUTION FOR p TO TEST NS /////////
7120 * ///////////////////////////////////////////////////
7121 *
7122 * @code
7123 *   template <int dim>
7124 *   class ExactSolution_p : public Function <dim>
7125 *   {
7126 *   public:
7127 *   ExactSolution_p (double t=0) : Function<dim>() {this->set_time(t);}
7128 *   virtual double value (const Point<dim> &p, const unsigned int component=0) const;
7129 *   virtual Tensor<1,dim> gradient (const Point<dim> &p, const unsigned int component = 0) const;
7130 *   };
7131 *  
7132 *   template <int dim>
7133 *   double ExactSolution_p<dim>::value (const Point<dim> &p, const unsigned int) const
7134 *   {
7135 *   double t = this->get_time();
7136 *   double return_value = 0;
7137 *   if (dim == 2)
7138 *   return_value = std::cos(p[0])*std::sin(p[1]+t);
7139 *   else //dim=3
7140 *   return_value = std::sin(p[0]+p[1]+p[2]+t);
7141 *   return return_value;
7142 *   }
7143 *  
7144 *   template <int dim>
7145 *   Tensor<1,dim> ExactSolution_p<dim>::gradient (const Point<dim> &p, const unsigned int) const
7146 *   {
7147 *   Tensor<1,dim> return_value;
7148 *   double t = this->get_time();
7149 *   if (dim == 2)
7150 *   {
7151 *   return_value[0] = -std::sin(p[0])*std::sin(p[1]+t);
7152 *   return_value[1] = std::cos(p[0])*std::cos(p[1]+t);
7153 *   }
7154 *   else //dim=3
7155 *   {
7156 *   return_value[0] = std::cos(t+p[0]+p[1]+p[2]);
7157 *   return_value[1] = std::cos(t+p[0]+p[1]+p[2]);
7158 *   return_value[2] = std::cos(t+p[0]+p[1]+p[2]);
7159 *   }
7160 *   return return_value;
7161 *   }
7162 *  
7163 * @endcode
7164 *
7165 * //////////////////////////////////////////////////////////////
7166 * ////////////////// FORCE TERMS to TEST NS ////////////////////
7167 * //////////////////////////////////////////////////////////////
7168 *
7169 * @code
7170 *   template <int dim>
7171 *   class ForceTerms : public Function <dim>
7172 *   {
7173 *   public:
7174 *   ForceTerms (double t=0)
7175 *   :
7176 *   Function<dim>()
7177 *   {
7178 *   this->set_time(t);
7179 *   nu = 1.;
7180 *   }
7181 *   virtual void vector_value (const Point<dim> &p, Vector<double> &values) const;
7182 *   double nu;
7183 *   };
7184 *  
7185 *   template <int dim>
7186 *   void ForceTerms<dim>::vector_value (const Point<dim> &p, Vector<double> &values) const
7187 *   {
7188 *   double x = p[0];
7189 *   double y = p[1];
7190 *   double z = 0;
7191 *   double t = this->get_time();
7192 *   double Pi = numbers::PI;
7193 *  
7194 *   if (dim == 2)
7195 *   {
7196 * @endcode
7197 *
7198 * force in x
7199 *
7200 * @code
7201 *   values[0] = std::cos(t+y)*std::sin(x)*(1+std::pow(std::sin(t+x+y),2)) // time derivative
7202 *   +2*nu*std::sin(x)*std::sin(t+y) // viscosity
7203 *   +std::cos(x)*std::sin(x)*(1+std::pow(std::sin(t+x+y),2)) // non-linearity
7204 *   -std::sin(x)*std::sin(y+t); // pressure
7205 * @endcode
7206 *
7207 * force in y
7208 *
7209 * @code
7210 *   values[1] = -(std::cos(x)*std::sin(t+y)*(1+std::pow(std::sin(t+x+y),2))) // time derivative
7211 *   +2*nu*std::cos(x)*std::cos(t+y) // viscosity
7212 *   -(std::sin(2*(t+y))*(1+std::pow(std::sin(t+x+y),2)))/2. // non-linearity
7213 *   +std::cos(x)*std::cos(y+t); // pressure
7214 *   }
7215 *   else //3D
7216 *   {
7217 *   z = p[2];
7218 * @endcode
7219 *
7220 * force in x
7221 *
7222 * @code
7223 *   values[0]=
7224 *   -(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.
7225 *   +3*std::pow(Pi,2)*std::cos(t)*std::cos(Pi*y)*std::cos(Pi*z)*std::sin(Pi*x) //viscosity
7226 *   -(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
7227 *   +std::cos(t+x+y+z); // pressure
7228 *   values[1]=
7229 *   -(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
7230 *   +3*std::pow(Pi,2)*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*z)*std::sin(Pi*y) //viscosity
7231 *   -(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
7232 *   +std::cos(t+x+y+z); // pressure
7233 *   values[2]=
7234 *   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
7235 *   -6*std::pow(Pi,2)*std::cos(t)*std::cos(Pi*x)*std::cos(Pi*y)*std::sin(Pi*z) //viscosity
7236 *   -(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
7237 *   +std::cos(t+x+y+z); // pressure
7238 *   }
7239 *   }
7240 * @endcode
7241
7242
7243*/
void attach_dof_handler(const DoFHandler< dim, spacedim > &)
Definition fe_q.h:554
void subtract_set(const IndexSet &other)
Definition index_set.cc:473
unsigned int depth_console(const unsigned int n)
Definition logstream.cc:349
Definition point.h:111
Point< 2 > first
Definition grid_out.cc:4623
typename ActiveSelector::active_cell_iterator active_cell_iterator
void loop(IteratorType begin, std_cxx20::type_identity_t< IteratorType > end, DOFINFO &dinfo, INFOBOX &info, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, AssemblerType &assembler, const LoopControl &lctrl=LoopControl())
Definition loop.h:564
void make_hanging_node_constraints(const DoFHandler< dim, spacedim > &dof_handler, AffineConstraints< number > &constraints)
void make_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity_pattern, const AffineConstraints< number > &constraints={}, const bool keep_constrained_dofs=true, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id)
@ update_values
Shape function values.
@ update_normal_vectors
Normal vectors.
@ update_JxW_values
Transformed quadrature weights.
@ update_gradients
Shape function gradients.
@ update_quadrature_points
Transformed quadrature points.
LogStream deallog
Definition logstream.cc:36
const Event initial
Definition event.cc:64
CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt K
IndexSet extract_locally_relevant_dofs(const DoFHandler< dim, spacedim > &dof_handler)
void hyper_rectangle(Triangulation< dim, spacedim > &tria, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
void subdivided_hyper_rectangle(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &repetitions, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
double minimal_cell_diameter(const Triangulation< dim, spacedim > &triangulation, const Mapping< dim, spacedim > &mapping=(ReferenceCells::get_hypercube< dim >() .template get_default_linear_mapping< dim, spacedim >()))
double volume(const Triangulation< dim, spacedim > &tria)
@ matrix
Contents is actually a matrix.
SymmetricTensor< 2, dim, Number > C(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > E(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
void distribute_sparsity_pattern(DynamicSparsityPattern &dsp, const IndexSet &locally_owned_rows, const MPI_Comm mpi_comm, const IndexSet &locally_relevant_rows)
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
T sum(const T &t, const MPI_Comm mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
Definition mpi.cc:92
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:107
std::string compress(const std::string &input)
Definition utilities.cc:389
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition utilities.cc:470
void interpolate(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Function< spacedim, typename VectorType::value_type > &function, VectorType &vec, const ComponentMask &component_mask={}, const unsigned int level=numbers::invalid_unsigned_int)
void interpolate_boundary_values(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const std::map< types::boundary_id, const Function< spacedim, number > * > &function_map, std::map< types::global_dof_index, number > &boundary_values, const ComponentMask &component_mask={})
void run(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length, const unsigned int chunk_size)
void abort(const ExceptionBase &exc) noexcept
int(&) functions(const void *v1, const void *v2)
void assemble(const MeshWorker::DoFInfoBox< dim, DOFINFO > &dinfo, A *assembler)
Definition loop.h:70
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:144
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation