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