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
parallel_in_time.h
Go to the documentation of this file.
1
317 *  
318 *   #include "BraidFuncs.hh"
319 *  
320 * @endcode
321 *
322 * This advances the solution forward by one time step.
323 * First some data is collected from the status struct,
324 * namely the start and stop time and the current timestep
325 * number. The timestep size @f$\Delta t@f$ is calculated,
326 * and the step function from the HeatEquation is used to
327 * advance the solution.
328 *
329 * @code
330 *   int my_Step(braid_App app,
331 *   braid_Vector ustop,
332 *   braid_Vector fstop,
333 *   braid_Vector u,
334 *   braid_StepStatus status)
335 *   {
336 *   UNUSED(ustop);
337 *   UNUSED(fstop);
338 *   double tstart; /* current time */
339 *   double tstop; /* evolve to this time*/
340 *   int level;
341 *   double deltaT;
342 *  
343 *   int index;
344 *   braid_StepStatusGetLevel(status, &level);
345 *   braid_StepStatusGetTstartTstop(status, &tstart, &tstop);
346 *   braid_StepStatusGetTIndex(status, &index);
347 *  
348 *   deltaT = tstop - tstart;
349 *  
350 *   ::Vector<double>& solution = u->data;
351 *  
352 *   HeatEquation<2>& heateq = app->eq;
353 *  
354 *   heateq.step(solution, deltaT, tstart, index);
355 *  
356 *   return 0;
357 *   }
358 *  
359 *  
360 * @endcode
361 *
362 * In this function we initialize a vector at an arbitrary time.
363 * At this point we don't know anything about what the solution
364 * looks like, and we can really initialize to anything, so in
365 * this case use reinit to initialize the memory and set the
366 * values to zero.
367 *
368 * @code
369 *   int
370 *   my_Init(braid_App app,
371 *   double t,
372 *   braid_Vector *u_ptr)
373 *   {
374 *   my_Vector *u = new(my_Vector);
375 *   int size = app->eq.size();
376 *   u->data.reinit(size);
377 *  
378 *   app->eq.initialize(t, u->data);
379 *  
380 *   *u_ptr = u;
381 *  
382 *   return 0;
383 *   }
384 *  
385 * @endcode
386 *
387 * Here we need to copy the vector u into the vector v. We do this
388 * by allocating a new vector, then reinitializing the deal.ii
389 * vector to the correct size. The deal.ii reinitialization sets
390 * every value to zero, so next we need to iterate over the vector
391 * u and copy the values to the new vector v.
392 *
393 * @code
394 *   int
395 *   my_Clone(braid_App app,
396 *   braid_Vector u,
397 *   braid_Vector *v_ptr)
398 *   {
399 *   UNUSED(app);
400 *   my_Vector *v = new(my_Vector);
401 *   int size = u->data.size();
402 *   v->data.reinit(size);
403 *   for(size_t i=0, end=v->data.size(); i != end; ++i)
404 *   {
405 *   v->data[i] = u->data[i];
406 *   }
407 *   *v_ptr = v;
408 *  
409 *   return 0;
410 *   }
411 *  
412 * @endcode
413 *
414 * Here we need to free the memory used by vector u. This is
415 * pretty simple since the deal.ii vector is stored inside the
416 * XBraid vector, so we just delete the XBraid vector u and it
417 * puts the deal.ii vector out of scope and releases its memory.
418 *
419 * @code
420 *   int
421 *   my_Free(braid_App app,
422 *   braid_Vector u)
423 *   {
424 *   UNUSED(app);
425 *   delete u;
426 *  
427 *   return 0;
428 *   }
429 *  
430 * @endcode
431 *
432 * This is to perform an axpy type operation. That is to say we
433 * do @f$y = \alpha x + \beta y@f$. Fortunately deal.ii already has
434 * this operation built in to its vector class, so we get the
435 * reference to the vector y and call the sadd method.
436 *
437 * @code
438 *   int my_Sum(braid_App app,
439 *   double alpha,
440 *   braid_Vector x,
441 *   double beta,
442 *   braid_Vector y)
443 *   {
444 *   UNUSED(app);
445 *   Vector<double>& vec = y->data;
446 *   vec.sadd(beta, alpha, x->data);
447 *  
448 *   return 0;
449 *   }
450 *  
451 * @endcode
452 *
453 * This calculates the spatial norm using the l2 norm. According
454 * to XBraid, this could be just about any spatial norm but we'll
455 * keep it simple and used deal.ii vector's built in l2_norm method.
456 *
457 * @code
458 *   int
459 *   my_SpatialNorm(braid_App app,
460 *   braid_Vector u,
461 *   double *norm_ptr)
462 *   {
463 *   UNUSED(app);
464 *   double dot = 0.0;
465 *   dot = u->data.l2_norm();
466 *   *norm_ptr = dot;
467 *  
468 *   return 0;
469 *   }
470 *  
471 * @endcode
472 *
473 * This function is called at various points depending on the access
474 * level specified when configuring the XBraid struct. This function
475 * is used to print out data during the run time, such as plots of the
476 * data. The status struct contains a ton of information about the
477 * simulation run. Here we get the current time and timestep number.
478 * The output_results function is called to plot the solution data.
479 * If the method of manufactured solutions is being used, then the
480 * error of this time step is computed and processed.
481 *
482 * @code
483 *   int
484 *   my_Access(braid_App app,
485 *   braid_Vector u,
486 *   braid_AccessStatus astatus)
487 *   {
488 *   double t;
489 *   int index;
490 *  
491 *   braid_AccessStatusGetT(astatus, &t);
492 *   braid_AccessStatusGetTIndex(astatus, &index);
493 *  
494 *   app->eq.output_results(index, t, u->data);
495 *  
496 *   #if DO_MFG
497 *   if(index == app->final_step)
498 *   {
499 *   app->eq.process_solution(t, index, u->data);
500 *   }
501 *   #endif
502 *  
503 *   return 0;
504 *   }
505 *  
506 * @endcode
507 *
508 * This calculates the size of buffer needed to pack the solution
509 * data into a linear buffer for transfer to another processor via
510 * MPI. We query the size of the data from the HeatEquation class
511 * and return the buffer size.
512 *
513 * @code
514 *   int
515 *   my_BufSize(braid_App app,
516 *   int *size_ptr,
517 *   braid_BufferStatus bstatus)
518 *   {
519 *   UNUSED(bstatus);
520 *   int size = app->eq.size();
521 *   *size_ptr = (size+1)*sizeof(double);
522 *  
523 *   return 0;
524 *   }
525 *  
526 * @endcode
527 *
528 * This function packs a linear buffer with data so that the buffer
529 * may be sent to another processor via MPI. The buffer is cast to
530 * a type we can work with. The first element of the buffer is the
531 * size of the buffer. Then we iterate over solution vector u and
532 * fill the buffer with our solution data. Finally we tell XBraid
533 * how much data we wrote.
534 *
535 * @code
536 *   int
537 *   my_BufPack(braid_App app,
538 *   braid_Vector u,
539 *   void *buffer,
540 *   braid_BufferStatus bstatus)
541 *   {
542 *  
543 *   UNUSED(app);
544 *   double *dbuffer = (double*)buffer;
545 *   int size = u->data.size();
546 *   dbuffer[0] = size;
547 *   for(int i=0; i != size; ++i)
548 *   {
549 *   dbuffer[i+1] = (u->data)[i];
550 *   }
551 *   braid_BufferStatusSetSize(bstatus, (size+1)*sizeof(double));
552 *  
553 *   return 0;
554 *   }
555 *  
556 * @endcode
557 *
558 * This function unpacks a buffer that was received from a different
559 * processor via MPI. The size of the buffer is read from the first
560 * element, then we iterate over the size of the buffer and fill
561 * the values of solution vector u with the data in the buffer.
562 *
563 * @code
564 *   int
565 *   my_BufUnpack(braid_App app,
566 *   void *buffer,
567 *   braid_Vector *u_ptr,
568 *   braid_BufferStatus bstatus)
569 *   {
570 *   UNUSED(app);
571 *   UNUSED(bstatus);
572 *  
573 *   my_Vector *u = NULL;
574 *   double *dbuffer = (double*)buffer;
575 *   int size = static_cast<int>(dbuffer[0]);
576 *   u = new(my_Vector);
577 *   u->data.reinit(size);
578 *  
579 *   for(int i = 0; i != size; ++i)
580 *   {
581 *   (u->data)[i] = dbuffer[i+1];
582 *   }
583 *   *u_ptr = u;
584 *  
585 *   return 0;
586 *   }
587 * @endcode
588
589
590<a name="ann-src/BraidFuncs.hh"></a>
591<h1>Annotated version of src/BraidFuncs.hh</h1>
592 *
593 *
594 *
595 *
596 * @code
597 *   /* -----------------------------------------------------------------------------
598 *   *
599 *   * SPDX-License-Identifier: LGPL-2.1-or-later
600 *   * Copyright (C) 2018 by Joshua Christopher
601 *   *
602 *   * This file is part of the deal.II code gallery.
603 *   *
604 *   * -----------------------------------------------------------------------------
605 *   */
606 *  
607 *   #ifndef _BRAIDFUNCS_H_
608 *   #define _BRAIDFUNCS_H_
609 *  
610 *   /**
611 *   * \file BraidFuncs.cc
612 *   * \brief Contains the implementation of the mandatory X-Braid functions
613 *   *
614 *   * X-Braid mandates several functions in order to drive the solution.
615 *   * This file contains the implementation of said mandatory functions.
616 *   * See the X-Braid documentation for more information.
617 *   * There are several functions that are optional in X-Braid that may
618 *   * or may not be implemented in here.
619 *   *
620 *   */
621 *  
622 *  
623 *   /*-------- Third Party --------*/
624 *   #include <deal.II/numerics/vector_tools.h>
625 *  
626 *   #include <braid.h>
627 *   #include <braid_test.h>
628 *  
629 *   /*-------- Project --------*/
630 *   #include "HeatEquation.hh"
631 *  
632 * @endcode
633 *
634 * This struct contains all data that changes with time. For now
635 * this is just the solution data. When doing AMR this should
636 * probably include the triangulization, the sparsity pattern,
637 * constraints, etc.
638 *
639 * @code
640 *   /**
641 *   * \brief Struct that contains the deal.ii vector.
642 *   */
643 *   typedef struct _braid_Vector_struct
644 *   {
645 *   ::Vector<double> data;
646 *   } my_Vector;
647 *  
648 * @endcode
649 *
650 * This struct contains all the data that is unchanging with time.
651 *
652 * @code
653 *   /**
654 *   * \brief Struct that contains the HeatEquation and final
655 *   * time step number.
656 *   */
657 *   typedef struct _braid_App_struct
658 *   {
659 *   HeatEquation<2> eq;
660 *   int final_step;
661 *   } my_App;
662 *  
663 *  
664 *   /**
665 *   * @brief my_Step - Takes a step in time, advancing the u vector
666 *   *
667 *   * @param app - The braid app struct
668 *   * @param ustop - The solution data at the end of this time step
669 *   * @param fstop - RHS data (such as forcing function?)
670 *   * @param u - The solution data at the beginning of this time step
671 *   * @param status - Status structure that contains various info of this time
672 *   *
673 *   * @return Success (0) or failure (1)
674 *   **/
675 *   int my_Step(braid_App app,
676 *   braid_Vector ustop,
677 *   braid_Vector fstop,
678 *   braid_Vector u,
679 *   braid_StepStatus status);
680 *  
681 *  
682 *   /**
683 *   * @brief my_Init - Initializes a solution data at the given time
684 *   * For now, initializes the solution to zero no matter what time we are at
685 *   *
686 *   * @param app - The braid app struct containing user data
687 *   * @param t - Time at which the solution is initialized
688 *   * @param u_ptr - The solution data that needs to be filled
689 *   *
690 *   * @return Success (0) or failure (1)
691 *   **/
692 *   int
693 *   my_Init(braid_App app,
694 *   double t,
695 *   braid_Vector *u_ptr);
696 *  
697 *  
698 *   /**
699 *   * @brief my_Clone - Clones a vector into a new vector
700 *   *
701 *   * @param app - The braid app struct containing user data
702 *   * @param u - The existing vector containing data
703 *   * @param v_ptr - The empty vector that needs to be filled
704 *   *
705 *   * @return Success (0) or failure (1)
706 *   **/
707 *   int
708 *   my_Clone(braid_App app,
709 *   braid_Vector u,
710 *   braid_Vector *v_ptr);
711 *  
712 *  
713 *   /**
714 *   * @brief my_Free - Deletes a vector
715 *   *
716 *   * @param app - The braid app struct containing user data
717 *   * @param u - The vector that needs to be deleted
718 *   *
719 *   * @return Success (0) or failure (1)
720 *   **/
721 *   int
722 *   my_Free(braid_App app,
723 *   braid_Vector u);
724 *  
725 *  
726 *   /**
727 *   * @brief my_Sum - Sums two vectors in an AXPY operation
728 *   * The operation is y = alpha*x + beta*y
729 *   *
730 *   * @param app - The braid app struct containing user data
731 *   * @param alpha - The coefficient in front of x
732 *   * @param x - A vector that is multiplied by alpha then added to y
733 *   * @param beta - The coefficient of y
734 *   * @param y - A vector that is multiplied by beta then summed with x
735 *   *
736 *   * @return Success (0) or failure (1)
737 *   **/
738 *   int
739 *   my_Sum(braid_App app,
740 *   double alpha,
741 *   braid_Vector x,
742 *   double beta,
743 *   braid_Vector y);
744 *  
745 *   /**
746 *   * \brief Returns the spatial norm of the provided vector
747 *   *
748 *   * Calculates and returns the spatial norm of the provided vector.
749 *   * Interestingly enough, X-Braid does not specify a particular norm.
750 *   * to keep things simple, we implement the Euclidean norm.
751 *   *
752 *   * \param app - The braid app struct containing user data
753 *   * \param u - The vector we need to take the norm of
754 *   * \param norm_ptr - Pointer to the norm that was calculated, need to modify this
755 *   * \return Success (0) or failure (1)
756 *   */
757 *   int
758 *   my_SpatialNorm(braid_App app,
759 *   braid_Vector u,
760 *   double *norm_ptr);
761 *  
762 *   /**
763 *   * \brief Allows the user to output details
764 *   *
765 *   * The Access function is called at various points to allow the user to output
766 *   * information to the screen or to files.
767 *   * The astatus parameter provides various information about the simulation,
768 *   * see the XBraid documentation for details on what information you can get.
769 *   * Example information is what the current timestep number and current time is.
770 *   * If the access level (in parallel_in_time.cc) is set to 0, this function is
771 *   * never called.
772 *   * If the access level is set to 1, the function is called after the last
773 *   * XBraid cycle.
774 *   * If the access level is set to 2, it is called every XBraid cycle.
775 *   *
776 *   * \param app - The braid app struct containing user data
777 *   * \param u - The vector containing the data at the status provided
778 *   * \param astatus - The Braid status structure
779 *   * \return Success (0) or failure (1)
780 *   */
781 *   int
782 *   my_Access(braid_App app,
783 *   braid_Vector u,
784 *   braid_AccessStatus astatus);
785 *  
786 *   /**
787 *   * \brief Calculates the size of a buffer for MPI data transfer
788 *   *
789 *   * Calculates the size of the buffer that is needed to transfer
790 *   * a solution vector to another processor.
791 *   * The bstatus parameter provides various information on the
792 *   * simulation, see the XBraid documentation for all possible
793 *   * fields.
794 *   *
795 *   * \param app - The braid app struct containing user data
796 *   * \param size_ptr A pointer to the calculated size
797 *   * \param bstatus The XBraid status structure
798 *   * \return Success (0) or failure (1)
799 *   */
800 *   int
801 *   my_BufSize(braid_App app,
802 *   int *size_ptr,
803 *   braid_BufferStatus bstatus);
804 *  
805 *   /**
806 *   * \brief Linearizes a vector to be sent to another processor
807 *   *
808 *   * Linearizes (packs) a data buffer with the contents of
809 *   * some solution state u.
810 *   *
811 *   * \param app - The braid app struct containing user data
812 *   * \param u The vector that must be packed into buffer
813 *   * \param buffer The buffer that must be filled with u
814 *   * \param bstatus The XBraid status structure
815 *   * \return Success (0) or failure (1)
816 *   */
817 *   int
818 *   my_BufPack(braid_App app,
819 *   braid_Vector u,
820 *   void *buffer,
821 *   braid_BufferStatus bstatus);
822 *  
823 *   /**
824 *   * \brief Unpacks a vector that was sent from another processor
825 *   *
826 *   * Unpacks a linear data buffer into the vector pointed to by
827 *   * u_ptr.
828 *   *
829 *   * \param app - The braid app struct containing user data
830 *   * \param buffer The buffer that must be unpacked
831 *   * \param u_ptr The pointer to the vector that is filled
832 *   * \param bstatus The XBraid status structure
833 *   * \return Success (0) or failure (1)
834 *   */
835 *   int
836 *   my_BufUnpack(braid_App app,
837 *   void *buffer,
838 *   braid_Vector *u_ptr,
839 *   braid_BufferStatus bstatus);
840 *  
841 *   #endif // _BRAIDFUNCS_H_
842 * @endcode
843
844
845<a name="ann-src/HeatEquation.hh"></a>
846<h1>Annotated version of src/HeatEquation.hh</h1>
847 *
848 *
849 *
850 *
851 * @code
852 *   /* -----------------------------------------------------------------------------
853 *   *
854 *   * SPDX-License-Identifier: LGPL-2.1-or-later
855 *   * Copyright (C) 2018 by Joshua Christopher
856 *   *
857 *   * This file is part of the deal.II code gallery.
858 *   *
859 *   * -----------------------------------------------------------------------------
860 *   */
861 *  
862 *   #ifndef _HEATEQUATION_H_
863 *   #define _HEATEQUATION_H_
864 *  
865 *   #include <deal.II/base/utilities.h>
866 *   #include <deal.II/base/quadrature_lib.h>
867 *   #include <deal.II/base/function.h>
868 *   #include <deal.II/base/logstream.h>
869 *   #include <deal.II/lac/vector.h>
870 *   #include <deal.II/lac/full_matrix.h>
871 *   #include <deal.II/lac/dynamic_sparsity_pattern.h>
872 *   #include <deal.II/lac/sparse_matrix.h>
873 *   #include <deal.II/lac/solver_cg.h>
874 *   #include <deal.II/lac/precondition.h>
875 *   #include <deal.II/lac/affine_constraints.h>
876 *   #include <deal.II/grid/tria.h>
877 *   #include <deal.II/grid/grid_generator.h>
878 *   #include <deal.II/grid/grid_refinement.h>
879 *   #include <deal.II/grid/grid_out.h>
880 *   #include <deal.II/grid/tria_accessor.h>
881 *   #include <deal.II/grid/tria_iterator.h>
882 *   #include <deal.II/dofs/dof_handler.h>
883 *   #include <deal.II/dofs/dof_accessor.h>
884 *   #include <deal.II/dofs/dof_tools.h>
885 *   #include <deal.II/fe/fe_q.h>
886 *   #include <deal.II/fe/fe_values.h>
887 *   #include <deal.II/numerics/data_out.h>
888 *   #include <deal.II/numerics/vector_tools.h>
889 *   #include <deal.II/numerics/error_estimator.h>
890 *   #include <deal.II/numerics/solution_transfer.h>
891 *   #include <deal.II/numerics/matrix_tools.h>
892 *   #include <deal.II/base/convergence_table.h>
893 *  
894 *   #include <fstream>
895 *  
896 *   using namespace dealii;
897 *  
898 * @endcode
899 *
900 * The HeatEquation class is describes the finite element
901 * solver for the heat equation. It contains all the functions
902 * needed to define the problem domain and advance the solution
903 * in time.
904 *
905 * @code
906 *   template <int dim>
907 *   class HeatEquation
908 *   {
909 *   public:
910 *   HeatEquation();
911 *   void define();
912 *   void step(Vector<double>& braid_data,
913 *   double deltaT,
914 *   double a_time,
915 *   int a_time_idx);
916 *  
917 *   int size() const; /// Returns the size of the solution vector
918 *  
919 *   void output_results(int a_time_idx,
920 *   double a_time,
921 *   Vector<double>& a_solution) const;
922 *  
923 *   void initialize(double a_time,
924 *   Vector<double>& a_vector) const;
925 *  
926 *   void process_solution(double a_time,
927 *   int a_index,
928 *   const Vector<double>& a_vector);
929 *  
930 *   private:
931 *   void setup_system();
932 *   void solve_time_step(Vector<double>& a_solution);
933 *  
934 *   Triangulation<dim> triangulation;
935 *   FE_Q<dim> fe;
936 *   DoFHandler<dim> dof_handler;
937 *  
938 *   AffineConstraints<double> constraints;
939 *  
940 *   SparsityPattern sparsity_pattern;
941 *   SparseMatrix<double> mass_matrix;
942 *   SparseMatrix<double> laplace_matrix;
943 *   SparseMatrix<double> system_matrix;
944 *  
945 *   Vector<double> system_rhs;
946 *  
947 *   std::ofstream myfile;
948 *  
949 *   const double theta;
950 *  
951 * @endcode
952 *
953 * These were originally in the run() function but because
954 * I am splitting the run() function up into define and step
955 * they need to become member data
956 *
957 * @code
958 *   Vector<double> tmp;
959 *   Vector<double> forcing_terms;
960 *  
961 *   ConvergenceTable convergence_table;
962 *   };
963 *  
964 * @endcode
965 *
966 * The RightHandSide class describes the RHS of the governing
967 * equations. In this case, it is the forcing function.
968 *
969 * @code
970 *   template <int dim>
971 *   class RightHandSide : public Function<dim>
972 *   {
973 *   public:
974 *   RightHandSide ()
975 *   :
976 *   Function<dim>(),
977 *   period (0.2)
978 *   {}
979 *  
980 *   virtual double value (const Point<dim> &p,
981 *   const unsigned int component = 0) const override;
982 *  
983 *   private:
984 *   const double period;
985 *   };
986 *  
987 * @endcode
988 *
989 * The BoundaryValues class describes the boundary conditions
990 * of the governing equations.
991 *
992 * @code
993 *   template <int dim>
994 *   class BoundaryValues : public Function<dim>
995 *   {
996 *   public:
997 *   virtual double value (const Point<dim> &p,
998 *   const unsigned int component = 0) const override;
999 *   };
1000 *  
1001 * @endcode
1002 *
1003 * The RightHandSideMFG class describes the right hand side
1004 * function when doing the method of manufactured solutions.
1005 *
1006 * @code
1007 *   template <int dim>
1008 *   class RightHandSideMFG : public Function<dim>
1009 *   {
1010 *   public:
1011 *   virtual double value (const Point<dim> &p,
1012 *   const unsigned int component = 0) const override;
1013 *   };
1014 *  
1015 * @endcode
1016 *
1017 * The InitialValuesMFG class describes the initial values
1018 * when doing the method of manufactured solutions.
1019 *
1020 * @code
1021 *   template <int dim>
1022 *   class InitialValuesMFG : public Function<dim>
1023 *   {
1024 *   public:
1025 *   virtual double value (const Point<dim> &p,
1026 *   const unsigned int component = 0) const override;
1027 *   };
1028 *  
1029 * @endcode
1030 *
1031 * Provides the exact value for the manufactured solution. This
1032 * is used for the boundary conditions as well.
1033 *
1034 * @code
1035 *   template <int dim>
1036 *   class ExactValuesMFG : public Function<dim>
1037 *   {
1038 *   public:
1039 *   /**
1040 *   * \brief Computes the value at the given point and member data time
1041 *   *
1042 *   * Computes the exact value of the manufactured solution at point p and
1043 *   * the member data time. See the class documentation and the design doc
1044 *   * for details on what the exact solution is.
1045 *   *
1046 *   * \param p The point that the exact solution is computed at
1047 *   * \param component The component of the exact solution (always 0 for now)
1048 *   * \return double The exact value that was computed
1049 *   */
1050 *   virtual double value (const Point<dim> &p,
1051 *   const unsigned int component = 0) const override;
1052 *  
1053 *   /**
1054 *   * \brief Computes the gradient of the exact solution at the given point
1055 *   *
1056 *   * Computes the gradient of the exact/manufactured solution value at
1057 *   * point p and member data time. See the design doc for details on
1058 *   * what the gradient of the exact solution is
1059 *   *
1060 *   * \param p The point that the gradient is calculated at
1061 *   * \param component The component of the system of equations this gradient is for
1062 *   * \return Tensor<1,dim> A rank 1 tensor that contains the gradient
1063 *   * in each spatial dimension
1064 *   */
1065 *   virtual Tensor<1,dim> gradient (const Point<dim> &p,
1066 *   const unsigned int component = 0) const override;
1067 *   };
1068 *  
1069 *  
1070 *   #include "HeatEquationImplem.hh"
1071 *  
1072 *   #endif // _HEATEQUATION_H_
1073 * @endcode
1074
1075
1076<a name="ann-src/HeatEquationImplem.hh"></a>
1077<h1>Annotated version of src/HeatEquationImplem.hh</h1>
1078 *
1079 *
1080 *
1081 *
1082 * @code
1083 *   /* -----------------------------------------------------------------------------
1084 *   *
1085 *   * SPDX-License-Identifier: LGPL-2.1-or-later
1086 *   * Copyright (C) 2018 by Joshua Christopher
1087 *   *
1088 *   * This file is part of the deal.II code gallery.
1089 *   *
1090 *   * -----------------------------------------------------------------------------
1091 *   */
1092 *  
1093 *   #include "Utilities.hh"
1094 *  
1095 *   #include <iomanip>
1096 *   #include <math.h>
1097 *  
1098 * @endcode
1099 *
1100 * Calculates the forcing function for the RightHandSide. See the
1101 * documentation for the math.
1102 *
1103 * @code
1104 *   template <int dim>
1105 *   double RightHandSide<dim>::value (const Point<dim> &p,
1106 *   const unsigned int component) const
1107 *   {
1108 *   (void) component;
1109 *   Assert (component == 0, ExcIndexRange(component, 0, 1));
1110 *   Assert (dim == 2, ExcNotImplemented());
1111 *  
1112 *   double time = this->get_time();
1113 *  
1114 *   if ((p[0] > 0.5) && (p[1] > -0.5))
1115 *   {
1116 *   return std::exp(-0.5*(time-0.125)*(time-0.125)/(0.005));
1117 *   }
1118 *   else if ((p[0] > -0.5) && (p[1] > 0.5))
1119 *   {
1120 *   return std::exp(-0.5*(time-0.375)*(time-0.375)/(0.005));
1121 *   }
1122 *   else
1123 *   {
1124 *   return 0;
1125 *   }
1126 *  
1127 *   return 0; // No forcing function
1128 *   }
1129 *  
1130 * @endcode
1131 *
1132 * Calculates the forcing function for the method of manufactured
1133 * solutions. See the documentation for the math.
1134 *
1135 * @code
1136 *   template <int dim>
1137 *   double RightHandSideMFG<dim>::value (const Point<dim> &p,
1138 *   const unsigned int component) const
1139 *   {
1140 *   (void) component;
1141 *   Assert (component == 0, ExcIndexRange(component, 0, 1));
1142 *   Assert (dim == 2, ExcNotImplemented());
1143 *  
1144 *   double time = this->get_time();
1145 *  
1146 *   double pi = numbers::PI;
1147 *   return 4*pi*pi*std::exp(-4*pi*pi*time)*std::cos(2*pi*p[0])*std::cos(2*pi*p[1]);
1148 *   }
1149 *  
1150 * @endcode
1151 *
1152 * Calculates the boundary conditions, essentially zero everywhere.
1153 *
1154 * @code
1155 *   template <int dim>
1156 *   double BoundaryValues<dim>::value (const Point<dim> &p,
1157 *   const unsigned int component) const
1158 *   {
1159 *   UNUSED(p);
1160 *   (void) component;
1161 *   Assert (component == 0, ExcIndexRange(component, 0, 1));
1162 *   return 0;
1163 *   }
1164 *  
1165 * @endcode
1166 *
1167 * Calculates the exact solution (and thus also boundary conditions)
1168 * for the method of manufactured solutions.
1169 *
1170 * @code
1171 *   template <int dim>
1172 *   double ExactValuesMFG<dim>::value (const Point<dim> &p,
1173 *   const unsigned int component) const
1174 *   {
1175 *   (void) component;
1176 *   Assert (component == 0, ExcIndexRange(component, 0, 1));
1177 *  
1178 *   double time = this->get_time();
1179 *   const double pi = numbers::PI;
1180 *  
1181 *   return std::exp(-4*pi*pi*time)*std::cos(2*pi*p[0])*std::cos(2*pi*p[1]);
1182 *   }
1183 *  
1184 * @endcode
1185 *
1186 * Calculates the gradient of the exact solution for the method of manufactured
1187 * solutions. See the documentation for the math.
1188 *
1189 * @code
1190 *   template <int dim>
1191 *   Tensor<1,dim> ExactValuesMFG<dim>::gradient (const Point<dim> &p,
1192 *   const unsigned int) const
1193 *   {
1194 *   Assert (dim == 2, ExcNotImplemented());
1195 *  
1196 *   Tensor<1,dim> return_value;
1197 *   const double pi = numbers::PI;
1198 *   double time = this->get_time();
1199 *   return_value[0] = -2*pi*std::exp(-4*pi*pi*time)*std::cos(2*pi*p[1])*std::sin(2*pi*p[0]);
1200 *   return_value[1] = -2*pi*std::exp(-4*pi*pi*time)*std::cos(2*pi*p[0])*std::sin(2*pi*p[1]);
1201 *   return return_value;
1202 *   }
1203 *  
1204 * @endcode
1205 *
1206 * Calculates the initial values for the method of manufactured solutions.
1207 * See the documentation for the math.
1208 *
1209 * @code
1210 *   template <int dim>
1211 *   double InitialValuesMFG<dim>::value (const Point<dim> &p,
1212 *   const unsigned int component) const
1213 *   {
1214 *   (void) component;
1215 *   Assert (component == 0, ExcIndexRange(component, 0, 1));
1216 *   const double pi = numbers::PI;
1217 *  
1218 *   return std::cos(2*pi*p[0])*std::cos(2*pi*p[1]);
1219 *   }
1220 *  
1221 *   template <int dim>
1222 *   HeatEquation<dim>::HeatEquation ()
1223 *   :
1224 *   fe(1),
1225 *   dof_handler(triangulation),
1226 *   theta(0.5)
1227 *   {
1228 *   }
1229 *  
1230 *   template <int dim>
1231 *   void HeatEquation<dim>::initialize(double a_time,
1232 *   Vector<double>& a_vector) const
1233 *   {
1234 *   #if DO_MFG
1235 * @endcode
1236 *
1237 * We only initialize values in the manufactured solution case
1238 *
1239 * @code
1240 *   InitialValuesMFG<dim> iv_function;
1241 *   iv_function.set_time(a_time);
1242 *   VectorTools::project (dof_handler, constraints,
1243 *   QGauss<dim>(fe.degree+1), iv_function,
1244 *   a_vector);
1245 *   #else
1246 *   UNUSED(a_time);
1247 *   UNUSED(a_vector);
1248 *   #endif // DO_MFG
1249 * @endcode
1250 *
1251 * If not the MFG solution case, a_vector is already zero'd so do nothing
1252 *
1253 * @code
1254 *   }
1255 *  
1256 *   template <int dim>
1257 *   void HeatEquation<dim>::setup_system()
1258 *   {
1259 *   dof_handler.distribute_dofs(fe);
1260 *  
1261 *   constraints.clear ();
1263 *   constraints);
1264 *   constraints.close();
1265 *  
1266 *   DynamicSparsityPattern dsp(dof_handler.n_dofs());
1267 *   DoFTools::make_sparsity_pattern(dof_handler,
1268 *   dsp,
1269 *   constraints,
1270 *   /*keep_constrained_dofs = */ true);
1271 *   sparsity_pattern.copy_from(dsp);
1272 *  
1273 *   mass_matrix.reinit(sparsity_pattern);
1274 *   laplace_matrix.reinit(sparsity_pattern);
1275 *   system_matrix.reinit(sparsity_pattern);
1276 *  
1277 *   MatrixCreator::create_mass_matrix(dof_handler,
1278 *   QGauss<dim>(fe.degree+1),
1279 *   mass_matrix);
1280 *   MatrixCreator::create_laplace_matrix(dof_handler,
1281 *   QGauss<dim>(fe.degree+1),
1282 *   laplace_matrix);
1283 *  
1284 *   system_rhs.reinit(dof_handler.n_dofs());
1285 *   }
1286 *  
1287 *  
1288 *   template <int dim>
1289 *   void HeatEquation<dim>::solve_time_step(Vector<double>& a_solution)
1290 *   {
1291 *   SolverControl solver_control(1000, 1e-8 * system_rhs.l2_norm());
1292 *   SolverCG<> cg(solver_control);
1293 *  
1294 *   PreconditionSSOR<> preconditioner;
1295 *   preconditioner.initialize(system_matrix, 1.0);
1296 *  
1297 *   cg.solve(system_matrix, a_solution, system_rhs,
1298 *   preconditioner);
1299 *  
1300 *   constraints.distribute(a_solution);
1301 *   }
1302 *  
1303 *  
1304 *  
1305 *   template <int dim>
1306 *   void HeatEquation<dim>::output_results(int a_time_idx,
1307 *   double a_time,
1308 *   Vector<double>& a_solution) const
1309 *   {
1310 *  
1311 *   DataOutBase::VtkFlags vtk_flags;
1312 *   vtk_flags.time = a_time;
1313 *   vtk_flags.cycle = a_time_idx;
1314 *  
1315 *   DataOut<dim> data_out;
1316 *   data_out.set_flags(vtk_flags);
1317 *  
1318 *   data_out.attach_dof_handler(dof_handler);
1319 *   data_out.add_data_vector(a_solution, "U");
1320 *  
1321 *   data_out.build_patches();
1322 *  
1323 *   const std::string filename = "solution-"
1324 *   + Utilities::int_to_string(a_time_idx, 3) +
1325 *   ".vtk";
1326 *   std::ofstream output(filename.c_str());
1327 *   data_out.write_vtk(output);
1328 *   }
1329 *  
1330 * @endcode
1331 *
1332 * We define the geometry here, this is called on each processor
1333 * and doesn't change in time. Once doing AMR, this won't need
1334 * to exist anymore.
1335 *
1336 * @code
1337 *   template <int dim>
1338 *   void HeatEquation<dim>::define()
1339 *   {
1340 *   const unsigned int initial_global_refinement = 6;
1341 *  
1343 *   triangulation.refine_global (initial_global_refinement);
1344 *  
1345 *   setup_system();
1346 *  
1347 *   tmp.reinit (dof_handler.n_dofs());
1348 *   forcing_terms.reinit (dof_handler.n_dofs());
1349 *   }
1350 *  
1351 * @endcode
1352 *
1353 * Here we advance the solution forward in time. This is done
1354 * the same way as in the loop in @ref step_26 "step-26"'s run function.
1355 *
1356 * @code
1357 *   template<int dim>
1358 *   void HeatEquation<dim>::step(Vector<double>& braid_data,
1359 *   double deltaT,
1360 *   double a_time,
1361 *   int a_time_idx)
1362 *   {
1363 *   a_time += deltaT;
1364 *   ++a_time_idx;
1365 *  
1366 *   mass_matrix.vmult(system_rhs, braid_data);
1367 *  
1368 *   laplace_matrix.vmult(tmp, braid_data);
1369 *  
1370 *   system_rhs.add(-(1 - theta) * deltaT, tmp);
1371 *  
1372 *   #if DO_MFG
1373 *   RightHandSideMFG<dim> rhs_function;
1374 *   #else
1375 *   RightHandSide<dim> rhs_function;
1376 *   #endif
1377 *   rhs_function.set_time(a_time);
1378 *   VectorTools::create_right_hand_side(dof_handler,
1379 *   QGauss<dim>(fe.degree+1),
1380 *   rhs_function,
1381 *   tmp);
1382 *  
1383 *   forcing_terms = tmp;
1384 *   forcing_terms *= deltaT * theta;
1385 *  
1386 *   rhs_function.set_time(a_time - deltaT);
1387 *   VectorTools::create_right_hand_side(dof_handler,
1388 *   QGauss<dim>(fe.degree+1),
1389 *   rhs_function,
1390 *   tmp);
1391 *  
1392 *   forcing_terms.add(deltaT * (1 - theta), tmp);
1393 *   system_rhs += forcing_terms;
1394 *  
1395 *   system_matrix.copy_from(mass_matrix);
1396 *   system_matrix.add(theta * deltaT, laplace_matrix);
1397 *  
1398 *   constraints.condense (system_matrix, system_rhs);
1399 *  
1400 *   {
1401 *   #if DO_MFG
1402 * @endcode
1403 *
1404 * If we are doing the method of manufactured solutions
1405 * then we set the boundary conditions to the exact solution.
1406 * Otherwise the boundary conditions are zero.
1407 *
1408 * @code
1409 *   ExactValuesMFG<dim> boundary_values_function;
1410 *   #else
1411 *   BoundaryValues<dim> boundary_values_function;
1412 *   #endif
1413 *   boundary_values_function.set_time(a_time);
1414 *  
1415 *   std::map<types::global_dof_index, double> boundary_values;
1416 *   VectorTools::interpolate_boundary_values(dof_handler,
1417 *   0,
1418 *   boundary_values_function,
1419 *   boundary_values);
1420 *  
1421 *   MatrixTools::apply_boundary_values(boundary_values,
1422 *   system_matrix,
1423 *   braid_data,
1424 *   system_rhs);
1425 *   }
1426 *  
1427 *   solve_time_step(braid_data);
1428 *   }
1429 *  
1430 *   template<int dim>
1431 *   int HeatEquation<dim>::size() const
1432 *   {
1433 *   return dof_handler.n_dofs();
1434 *   }
1435 *  
1436 * @endcode
1437 *
1438 * This function computes the error for the time step when doing
1439 * the method of manufactured solutions. First the exact values
1440 * is calculated, then the difference per cell is computed for
1441 * the various norms, and the error is computed. This is written
1442 * out to a pretty table.
1443 *
1444 * @code
1445 *   template<int dim> void
1446 *   HeatEquation<dim>::process_solution(double a_time,
1447 *   int a_index,
1448 *   const Vector<double>& a_vector)
1449 *   {
1450 * @endcode
1451 *
1452 * Compute the exact value for the manufactured solution case
1453 *
1454 * @code
1455 *   ExactValuesMFG<dim> exact_function;
1456 *   exact_function.set_time(a_time);
1457 *  
1458 *   Vector<double> difference_per_cell (triangulation.n_active_cells());
1459 *   VectorTools::integrate_difference(dof_handler,
1460 *   a_vector,
1461 *   exact_function,
1462 *   difference_per_cell,
1463 *   QGauss<dim>(fe.degree+1),
1464 *   VectorTools::L2_norm);
1465 *  
1466 *   const double L2_error = VectorTools::compute_global_error(triangulation,
1467 *   difference_per_cell,
1468 *   VectorTools::L2_norm);
1469 *  
1470 *   VectorTools::integrate_difference(dof_handler,
1471 *   a_vector,
1472 *   exact_function,
1473 *   difference_per_cell,
1474 *   QGauss<dim>(fe.degree+1),
1475 *   VectorTools::H1_seminorm);
1476 *  
1477 *   const double H1_error = VectorTools::compute_global_error(triangulation,
1478 *   difference_per_cell,
1479 *   VectorTools::H1_seminorm);
1480 *  
1481 *   const QTrapezoid<1> q_trapez;
1482 *   const QIterated<dim> q_iterated (q_trapez, 5);
1483 *   VectorTools::integrate_difference (dof_handler,
1484 *   a_vector,
1485 *   exact_function,
1486 *   difference_per_cell,
1487 *   q_iterated,
1488 *   VectorTools::Linfty_norm);
1489 *   const double Linfty_error = VectorTools::compute_global_error(triangulation,
1490 *   difference_per_cell,
1491 *   VectorTools::Linfty_norm);
1492 *  
1493 *   const unsigned int n_active_cells = triangulation.n_active_cells();
1494 *   const unsigned int n_dofs = dof_handler.n_dofs();
1495 *  
1496 *   pout() << "Cycle " << a_index << ':'
1497 *   << std::endl
1498 *   << " Number of active cells: "
1499 *   << n_active_cells
1500 *   << std::endl
1501 *   << " Number of degrees of freedom: "
1502 *   << n_dofs
1503 *   << std::endl;
1504 *  
1505 *   convergence_table.add_value("cycle", a_index);
1506 *   convergence_table.add_value("cells", n_active_cells);
1507 *   convergence_table.add_value("dofs", n_dofs);
1508 *   convergence_table.add_value("L2", L2_error);
1509 *   convergence_table.add_value("H1", H1_error);
1510 *   convergence_table.add_value("Linfty", Linfty_error);
1511 *  
1512 *   convergence_table.set_precision("L2", 3);
1513 *   convergence_table.set_precision("H1", 3);
1514 *   convergence_table.set_precision("Linfty", 3);
1515 *  
1516 *   convergence_table.set_scientific("L2", true);
1517 *   convergence_table.set_scientific("H1", true);
1518 *   convergence_table.set_scientific("Linfty", true);
1519 *  
1520 *   convergence_table.set_tex_caption("cells", "\\# cells");
1521 *   convergence_table.set_tex_caption("dofs", "\\# dofs");
1522 *   convergence_table.set_tex_caption("L2", "@fL^2@f-error");
1523 *   convergence_table.set_tex_caption("H1", "@fH^1@f-error");
1524 *   convergence_table.set_tex_caption("Linfty", "@fL^\\infty@f-error");
1525 *  
1526 *   convergence_table.set_tex_format("cells", "r");
1527 *   convergence_table.set_tex_format("dofs", "r");
1528 *  
1529 *   std::cout << std::endl;
1530 *   convergence_table.write_text(std::cout);
1531 *  
1532 *   std::ofstream error_table_file("tex-conv-table.tex");
1533 *   convergence_table.write_tex(error_table_file);
1534 *   }
1535 * @endcode
1536
1537
1538<a name="ann-src/Utilities.cc"></a>
1539<h1>Annotated version of src/Utilities.cc</h1>
1540 *
1541 *
1542 *
1543 *
1544 * @code
1545 *   /* -----------------------------------------------------------------------------
1546 *   *
1547 *   * SPDX-License-Identifier: LGPL-2.1-or-later
1548 *   * Copyright (C) 2018 by Joshua Christopher
1549 *   *
1550 *   * This file is part of the deal.II code gallery.
1551 *   *
1552 *   * -----------------------------------------------------------------------------
1553 *   */
1554 *  
1555 *   #include "Utilities.hh"
1556 *  
1557 *   #include <string>
1558 *   #include <fstream>
1559 *  
1560 *   #include <mpi.h>
1561 *  
1562 *   int procID = 0;
1563 *  
1564 *   #ifdef USE_MPI
1565 * @endcode
1566 *
1567 * The shared variables
1568 *
1569
1570 *
1571 *
1572 * @code
1573 *   static std::string s_pout_filename ;
1574 *   static std::string s_pout_basename ;
1575 *   static std::ofstream s_pout ;
1576 *  
1577 *   static bool s_pout_init = false ;
1578 *   static bool s_pout_open = false ;
1579 *  
1580 * @endcode
1581 *
1582 * in parallel, compute the filename give the basename
1583 * [NOTE: dont call this before MPI is initialized.]
1584 *
1585 * @code
1586 *   static void setFileName()
1587 *   {
1588 *   static const size_t ProcnumSize = 1 + 10 + 1 ; //'.' + 10digits + '\0'
1589 *   char procnum[ProcnumSize] ;
1590 *   snprintf( procnum ,ProcnumSize ,".%d" ,procID);
1591 *   s_pout_filename = s_pout_basename + procnum ;
1592 *   }
1593 *  
1594 * @endcode
1595 *
1596 * in parallel, close the file if nec., open it and check for success
1597 *
1598 * @code
1599 *   static void openFile()
1600 *   {
1601 *   if ( s_pout_open )
1602 *   {
1603 *   s_pout.close();
1604 *   }
1605 *   s_pout.open( s_pout_filename.c_str() );
1606 * @endcode
1607 *
1608 * if open() fails, we have problems, but it's better
1609 * to try again later than to make believe it succeeded
1610 *
1611 * @code
1612 *   s_pout_open = (bool)s_pout ;
1613 *   }
1614 *   #endif
1615 *  
1616 *   std::ostream& pout()
1617 *   {
1618 *   #ifdef USE_MPI
1619 * @endcode
1620 *
1621 * the common case is _open == true, which just returns s_pout
1622 *
1623 * @code
1624 *   if ( ! s_pout_open )
1625 *   {
1626 * @endcode
1627 *
1628 * the uncommon cae: the file isn't opened, MPI may not be
1629 * initialized, and the basename may not have been set
1630 *
1631 * @code
1632 *   int flag_i, flag_f;
1633 *   MPI_Initialized(&flag_i);
1634 *   MPI_Finalized(&flag_f);
1635 * @endcode
1636 *
1637 * app hasn't set a basename yet, so set the default
1638 *
1639 * @code
1640 *   if ( ! s_pout_init )
1641 *   {
1642 *   s_pout_basename = "pout" ;
1643 *   s_pout_init = true ;
1644 *   }
1645 * @endcode
1646 *
1647 * if MPI not initialized, we can't open the file so return cout
1648 *
1649 * @code
1650 *   if ( ! flag_i || flag_f)
1651 *   {
1652 *   return std::cout; // MPI hasn't been started yet, or has ended....
1653 *   }
1654 * @endcode
1655 *
1656 * MPI is initialized, so file must not be, so open it
1657 *
1658 * @code
1659 *   setFileName() ;
1660 *   openFile() ;
1661 * @endcode
1662 *
1663 * finally, in case the open failed, return cout
1664 *
1665 * @code
1666 *   if ( ! s_pout_open )
1667 *   {
1668 *   return std::cout ;
1669 *   }
1670 *   }
1671 *   return s_pout ;
1672 *   #else
1673 *   return std::cout;
1674 *   #endif
1675 *   }
1676 * @endcode
1677
1678
1679<a name="ann-src/Utilities.hh"></a>
1680<h1>Annotated version of src/Utilities.hh</h1>
1681 *
1682 *
1683 *
1684 *
1685 * @code
1686 *   /* -----------------------------------------------------------------------------
1687 *   *
1688 *   * SPDX-License-Identifier: LGPL-2.1-or-later
1689 *   * Copyright (C) 2018 by Joshua Christopher
1690 *   *
1691 *   * This file is part of the deal.II code gallery.
1692 *   *
1693 *   * -----------------------------------------------------------------------------
1694 *   */
1695 *  
1696 *   #ifndef _UTILITIES_H_
1697 *   #define _UTILITIES_H_
1698 *  
1699 *   #include <iostream>
1700 *  
1701 * @endcode
1702 *
1703 * This preprocessor macro is used on function arguments
1704 * that are not used in the function. It is used to
1705 * suppress compiler warnings.
1706 *
1707 * @code
1708 *   #define UNUSED(x) (void)(x)
1709 *  
1710 * @endcode
1711 *
1712 * Contains the current MPI processor ID.
1713 *
1714 * @code
1715 *   extern int procID;
1716 *  
1717 * @endcode
1718 *
1719 * Function to return the ostream to write out to. In MPI
1720 * mode it returns a stream to a file named pout.<#> where
1721 * <#> is the procID. This allows the user to write output
1722 * from each processor to a separate file. In serial mode
1723 * (no MPI), it returns the standard output.
1724 *
1725 * @code
1726 *   std::ostream& pout();
1727 *   #endif
1728 * @endcode
1729
1730
1731<a name="ann-src/parallel_in_time.cc"></a>
1732<h1>Annotated version of src/parallel_in_time.cc</h1>
1733 *
1734 *
1735 *
1736 *
1737 * @code
1738 *   /* -----------------------------------------------------------------------------
1739 *   *
1740 *   * SPDX-License-Identifier: LGPL-2.1-or-later
1741 *   * Copyright (C) 2018 by Joshua Christopher
1742 *   *
1743 *   * This file is part of the deal.II code gallery.
1744 *   *
1745 *   * -----------------------------------------------------------------------------
1746 *   *
1747 *   * Author: Joshua Christopher, Colorado State University, 2018
1748 *   */
1749 *  
1750 *   #include "BraidFuncs.hh"
1751 *   #include "HeatEquation.hh"
1752 *   #include "Utilities.hh"
1753 *  
1754 *   #include <fstream>
1755 *   #include <iostream>
1756 *  
1757 *   int main(int argc, char *argv[])
1758 *   {
1759 *   try
1760 *   {
1761 *   using namespace dealii;
1762 *  
1763 *   /* Initialize MPI */
1764 *   MPI_Comm comm; //, comm_x, comm_t;
1765 *   int rank;
1766 *   MPI_Init(&argc, &argv);
1767 *   comm = MPI_COMM_WORLD;
1768 *   MPI_Comm_rank(comm, &rank);
1769 *   procID = rank;
1770 *  
1771 * @endcode
1772 *
1773 * Set up X-Braid
1774 *
1775 * @code
1776 *   /* Initialize Braid */
1777 *   braid_Core core;
1778 *   double tstart = 0.0;
1779 *   double tstop = 0.002;
1780 *   int ntime = 10;
1781 *   my_App *app = new(my_App);
1782 *  
1783 *   braid_Init(MPI_COMM_WORLD, comm, tstart, tstop, ntime, app,
1784 *   my_Step, my_Init, my_Clone, my_Free, my_Sum, my_SpatialNorm,
1785 *   my_Access, my_BufSize, my_BufPack, my_BufUnpack, &core);
1786 *  
1787 *   /* Define XBraid parameters
1788 *   * See -help message forf descriptions */
1789 *   int max_levels = 3;
1790 * @endcode
1791 *
1792 * int nrelax = 1;
1793 * int skip = 0;
1794 *
1795 * @code
1796 *   double tol = 1.e-7;
1797 * @endcode
1798 *
1799 * int cfactor = 2;
1800 *
1801 * @code
1802 *   int max_iter = 5;
1803 * @endcode
1804 *
1805 * int min_coarse = 10;
1806 * int fmg = 0;
1807 * int scoarsen = 0;
1808 * int res = 0;
1809 * int wrapper_tests = 0;
1810 *
1811 * @code
1812 *   int print_level = 1;
1813 *   int access_level = 1;
1814 *   int use_sequential= 0;
1815 *  
1816 *   braid_SetPrintLevel( core, print_level);
1817 *   braid_SetAccessLevel( core, access_level);
1818 *   braid_SetMaxLevels(core, max_levels);
1819 * @endcode
1820 *
1821 * braid_SetMinCoarse( core, min_coarse );
1822 * braid_SetSkip(core, skip);
1823 * braid_SetNRelax(core, -1, nrelax);
1824 *
1825 * @code
1826 *   braid_SetAbsTol(core, tol);
1827 * @endcode
1828 *
1829 * braid_SetCFactor(core, -1, cfactor);
1830 *
1831 * @code
1832 *   braid_SetMaxIter(core, max_iter);
1833 *   braid_SetSeqSoln(core, use_sequential);
1834 *  
1835 *   app->eq.define();
1836 *   app->final_step = ntime;
1837 *  
1838 *   braid_Drive(core);
1839 *  
1840 * @endcode
1841 *
1842 * Free the memory now that we are done
1843 *
1844 * @code
1845 *   braid_Destroy(core);
1846 *  
1847 *   delete app;
1848 *  
1849 * @endcode
1850 *
1851 * Clean up MPI
1852 * MPI_Comm_free(&comm);
1853 *
1854 * @code
1855 *   MPI_Finalize();
1856 *   }
1857 *   catch (std::exception &exc)
1858 *   {
1859 *   std::cerr << std::endl << std::endl
1860 *   << "----------------------------------------------------"
1861 *   << std::endl;
1862 *   std::cerr << "Exception on processing: " << std::endl << exc.what()
1863 *   << std::endl << "Aborting!" << std::endl
1864 *   << "----------------------------------------------------"
1865 *   << std::endl;
1866 *  
1867 *   return 1;
1868 *   }
1869 *   catch (...)
1870 *   {
1871 *   std::cerr << std::endl << std::endl
1872 *   << "----------------------------------------------------"
1873 *   << std::endl;
1874 *   std::cerr << "Unknown exception!" << std::endl << "Aborting!"
1875 *   << std::endl
1876 *   << "----------------------------------------------------"
1877 *   << std::endl;
1878 *   return 1;
1879 *   }
1880 *  
1881 *   return 0;
1882 *   }
1883 *  
1884 * @endcode
1885
1886
1887<a name="ann-test/test_braid.cc"></a>
1888<h1>Annotated version of test/test_braid.cc</h1>
1889 *
1890 *
1891 *
1892 *
1893 * @code
1894 *   /* -----------------------------------------------------------------------------
1895 *   *
1896 *   * SPDX-License-Identifier: LGPL-2.1-or-later
1897 *   * Copyright (C) 2018 by Joshua Christopher
1898 *   *
1899 *   * This file is part of the deal.II code gallery.
1900 *   *
1901 *   * -----------------------------------------------------------------------------
1902 *   */
1903 *  
1904 *   #include "BraidFuncs.hh"
1905 *  
1906 *   #include <braid.h>
1907 *   #include <braid_test.h>
1908 *  
1909 *   #include <iostream>
1910 *  
1911 *   int main(int argc, char** argv)
1912 *   {
1913 *   MPI_Comm comm;
1914 *   int rank;
1915 *   MPI_Init(&argc, &argv);
1916 *   comm = MPI_COMM_WORLD;
1917 *   MPI_Comm_rank(comm, &rank);
1918 *  
1919 *   my_App *app = new(my_App);
1920 *   app->eq.define();
1921 *  
1922 *   double time = 0.2;
1923 *  
1924 *   braid_Int init_access_result = braid_TestInitAccess(app,
1925 *   comm,
1926 *   stdout,
1927 *   time,
1928 *   my_Init,
1929 *   my_Access,
1930 *   my_Free);
1931 *   (void)init_access_result;
1932 *  
1933 *   braid_Int clone_result = braid_TestClone(app,
1934 *   comm,
1935 *   stdout,
1936 *   time,
1937 *   my_Init,
1938 *   my_Access,
1939 *   my_Free,
1940 *   my_Clone);
1941 *   (void)clone_result;
1942 *  
1943 *   braid_Int sum_result = braid_TestSum(app,
1944 *   comm,
1945 *   stdout,
1946 *   time,
1947 *   my_Init,
1948 *   my_Access,
1949 *   my_Free,
1950 *   my_Clone,
1951 *   my_Sum);
1952 *   (void)sum_result;
1953 *  
1954 *   braid_Int norm_result = braid_TestSpatialNorm(app,
1955 *   comm,
1956 *   stdout,
1957 *   time,
1958 *   my_Init,
1959 *   my_Free,
1960 *   my_Clone,
1961 *   my_Sum,
1962 *   my_SpatialNorm);
1963 *   (void)norm_result;
1964 *  
1965 *   braid_Int buf_result = braid_TestBuf(app,
1966 *   comm,
1967 *   stdout,
1968 *   time,
1969 *   my_Init,
1970 *   my_Free,
1971 *   my_Sum,
1972 *   my_SpatialNorm,
1973 *   my_BufSize,
1974 *   my_BufPack,
1975 *   my_BufUnpack);
1976 *   (void)buf_result;
1977 *  
1978 * @endcode
1979 *
1980 * /* Create spatial communicator for wrapper-tests */
1981 * braid_SplitCommworld(&comm, 1, &comm_x, &comm_t);
1982 *
1983 *
1984 * braid_TestAll(app, comm_x, stdout, 0.0, (tstop-tstart)/ntime,
1985 * 2*(tstop-tstart)/ntime, my_Init, my_Free, my_Clone,
1986 * my_Sum, my_SpatialNorm, my_BufSize, my_BufPack,
1987 * my_BufUnpack, my_Coarsen, my_Interp, my_Residual, my_Step);
1988 *
1989
1990 *
1991 *
1992 * @code
1993 *   /* Finalize MPI */
1995 *   }
1996 * @endcode
1997
1998
1999*/
void set_flags(const FlagType &flags)
void initialize(const MatrixType &A, const AdditionalData &parameters=AdditionalData())
void refine_global(const unsigned int times=1)
unsigned int level
Definition grid_out.cc:4626
__global__ void set(Number *val, const Number s, const size_type N)
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)
void hyper_L(Triangulation< dim > &tria, const double left=-1., const double right=1., const bool colorize=false)
void mass_matrix(FullMatrix< double > &M, const FEValuesBase< dim > &fe, const double factor=1.)
Definition l2.h:57
void create_mass_matrix(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Quadrature< dim > &q, MatrixType &matrix, const Function< spacedim, typename MatrixType::value_type > *const a=nullptr, const AffineConstraints< typename MatrixType::value_type > &constraints=AffineConstraints< typename MatrixType::value_type >())
void create_laplace_matrix(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Quadrature< dim > &q, MatrixType &matrix, const Function< spacedim, typename MatrixType::value_type > *const a=nullptr, const AffineConstraints< typename MatrixType::value_type > &constraints=AffineConstraints< typename MatrixType::value_type >())
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition utilities.cc:191
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
std::vector< unsigned int > serial(const std::vector< unsigned int > &targets, const std::function< RequestType(const unsigned int)> &create_request, const std::function< AnswerType(const unsigned int, const RequestType &)> &answer_request, const std::function< void(const unsigned int, const AnswerType &)> &process_answer, const MPI_Comm comm)
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition utilities.cc:470
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
*** braid_TestAll(app, comm_x, stdout, 0.0,(tstop-tstart)/ntime, *2 *(tstop-tstart)/ntime, my_Init, my_Free, my_Clone, *my_Sum, my_SpatialNorm, my_BufSize, my_BufPack, *my_BufUnpack, my_Coarsen, my_Interp, my_Residual, my_Step)
****code *  *  MPI_Finalize()
*braid_SplitCommworld & comm
void advance(std::tuple< I1, I2 > &t, const unsigned int n)