317 * #include
"BraidFuncs.hh"
321 * This advances the solution forward by one time step.
322 * First some
data is collected from the status
struct,
323 * namely the start and stop time and the current timestep
324 * number. The timestep
size @f$\Delta t@f$ is calculated,
325 * and the step function from the HeatEquation is used to
329 *
int my_Step(braid_App app,
330 * braid_Vector ustop,
331 * braid_Vector fstop,
333 * braid_StepStatus status)
343 * braid_StepStatusGetLevel(status, &
level);
344 * braid_StepStatusGetTstartTstop(status, &tstart, &tstop);
345 * braid_StepStatusGetTIndex(status, &index);
347 * deltaT = tstop - tstart;
349 * ::Vector<double>& solution = u->data;
351 * HeatEquation<2>& heateq = app->eq;
353 * heateq.step(solution, deltaT, tstart, index);
361 * In
this function we initialize a vector at an arbitrary time.
362 * At
this point we don
't know anything about what the solution
363 * looks like, and we can really initialize to anything, so in
364 * this case use reinit to initialize the memory and set the
369 * my_Init(braid_App app,
371 * braid_Vector *u_ptr)
373 * my_Vector *u = new(my_Vector);
374 * int size = app->eq.size();
375 * u->data.reinit(size);
377 * app->eq.initialize(t, u->data);
386 * Here we need to copy the vector u into the vector v. We do this
387 * by allocating a new vector, then reinitializing the deal.ii
388 * vector to the correct size. The deal.ii reinitialization sets
389 * every value to zero, so next we need to iterate over the vector
390 * u and copy the values to the new vector v.
394 * my_Clone(braid_App app,
396 * braid_Vector *v_ptr)
399 * my_Vector *v = new(my_Vector);
400 * int size = u->data.size();
401 * v->data.reinit(size);
402 * for(size_t i=0, end=v->data.size(); i != end; ++i)
404 * v->data[i] = u->data[i];
413 * Here we need to free the memory used by vector u. This is
414 * pretty simple since the deal.ii vector is stored inside the
415 * XBraid vector, so we just delete the XBraid vector u and it
416 * puts the deal.ii vector out of scope and releases its memory.
420 * my_Free(braid_App app,
431 * This is to perform an axpy type operation. That is to say we
432 * do @f$y = \alpha x + \beta y@f$. Fortunately deal.ii already has
433 * this operation built in to its vector class, so we get the
434 * reference to the vector y and call the sadd method.
437 * int my_Sum(braid_App app,
444 * Vector<double>& vec = y->data;
445 * vec.sadd(beta, alpha, x->data);
452 * This calculates the spatial norm using the l2 norm. According
453 * to XBraid, this could be just about any spatial norm but we'll
454 * keep it simple and used deal.ii vector
's built in l2_norm method.
458 * my_SpatialNorm(braid_App app,
464 * dot = u->data.l2_norm();
472 * This function is called at various points depending on the access
473 * level specified when configuring the XBraid struct. This function
474 * is used to print out data during the run time, such as plots of the
475 * data. The status struct contains a ton of information about the
476 * simulation run. Here we get the current time and timestep number.
477 * The output_results function is called to plot the solution data.
478 * If the method of manufactured solutions is being used, then the
479 * error of this time step is computed and processed.
483 * my_Access(braid_App app,
485 * braid_AccessStatus astatus)
490 * braid_AccessStatusGetT(astatus, &t);
491 * braid_AccessStatusGetTIndex(astatus, &index);
493 * app->eq.output_results(index, t, u->data);
496 * if(index == app->final_step)
498 * app->eq.process_solution(t, index, u->data);
507 * This calculates the size of buffer needed to pack the solution
508 * data into a linear buffer for transfer to another processor via
509 * MPI. We query the size of the data from the HeatEquation class
510 * and return the buffer size.
514 * my_BufSize(braid_App app,
516 * braid_BufferStatus bstatus)
519 * int size = app->eq.size();
520 * *size_ptr = (size+1)*sizeof(double);
527 * This function packs a linear buffer with data so that the buffer
528 * may be sent to another processor via MPI. The buffer is cast to
529 * a type we can work with. The first element of the buffer is the
530 * size of the buffer. Then we iterate over solution vector u and
531 * fill the buffer with our solution data. Finally we tell XBraid
532 * how much data we wrote.
536 * my_BufPack(braid_App app,
539 * braid_BufferStatus bstatus)
543 * double *dbuffer = (double*)buffer;
544 * int size = u->data.size();
546 * for(int i=0; i != size; ++i)
548 * dbuffer[i+1] = (u->data)[i];
550 * braid_BufferStatusSetSize(bstatus, (size+1)*sizeof(double));
557 * This function unpacks a buffer that was received from a different
558 * processor via MPI. The size of the buffer is read from the first
559 * element, then we iterate over the size of the buffer and fill
560 * the values of solution vector u with the data in the buffer.
564 * my_BufUnpack(braid_App app,
566 * braid_Vector *u_ptr,
567 * braid_BufferStatus bstatus)
572 * my_Vector *u = NULL;
573 * double *dbuffer = (double*)buffer;
574 * int size = static_cast<int>(dbuffer[0]);
575 * u = new(my_Vector);
576 * u->data.reinit(size);
578 * for(int i = 0; i != size; ++i)
580 * (u->data)[i] = dbuffer[i+1];
589<a name="ann-src/BraidFuncs.hh"></a>
590<h1>Annotated version of src/BraidFuncs.hh</h1>
596 * /* -----------------------------------------------------------------------------
598 * * SPDX-License-Identifier: LGPL-2.1-or-later
599 * * Copyright (C) 2018 by Joshua Christopher
601 * * This file is part of the deal.II code gallery.
603 * * -----------------------------------------------------------------------------
606 * #ifndef _BRAIDFUNCS_H_
607 * #define _BRAIDFUNCS_H_
610 * * \file BraidFuncs.cc
611 * * \brief Contains the implementation of the mandatory X-Braid functions
613 * * X-Braid mandates several functions in order to drive the solution.
614 * * This file contains the implementation of said mandatory functions.
615 * * See the X-Braid documentation for more information.
616 * * There are several functions that are optional in X-Braid that may
617 * * or may not be implemented in here.
622 * /*-------- Third Party --------*/
623 * #include <deal.II/numerics/vector_tools.h>
626 * #include <braid_test.h>
628 * /*-------- Project --------*/
629 * #include "HeatEquation.hh"
633 * This struct contains all data that changes with time. For now
634 * this is just the solution data. When doing AMR this should
635 * probably include the triangulization, the sparsity pattern,
640 * * \brief Struct that contains the deal.ii vector.
642 * typedef struct _braid_Vector_struct
644 * ::Vector<double> data;
649 * This struct contains all the data that is unchanging with time.
653 * * \brief Struct that contains the HeatEquation and final
654 * * time step number.
656 * typedef struct _braid_App_struct
658 * HeatEquation<2> eq;
664 * * @brief my_Step - Takes a step in time, advancing the u vector
666 * * @param app - The braid app struct
667 * * @param ustop - The solution data at the end of this time step
668 * * @param fstop - RHS data (such as forcing function?)
669 * * @param u - The solution data at the beginning of this time step
670 * * @param status - Status structure that contains various info of this time
672 * * @return Success (0) or failure (1)
674 * int my_Step(braid_App app,
675 * braid_Vector ustop,
676 * braid_Vector fstop,
678 * braid_StepStatus status);
682 * * @brief my_Init - Initializes a solution data at the given time
683 * * For now, initializes the solution to zero no matter what time we are at
685 * * @param app - The braid app struct containing user data
686 * * @param t - Time at which the solution is initialized
687 * * @param u_ptr - The solution data that needs to be filled
689 * * @return Success (0) or failure (1)
692 * my_Init(braid_App app,
694 * braid_Vector *u_ptr);
698 * * @brief my_Clone - Clones a vector into a new vector
700 * * @param app - The braid app struct containing user data
701 * * @param u - The existing vector containing data
702 * * @param v_ptr - The empty vector that needs to be filled
704 * * @return Success (0) or failure (1)
707 * my_Clone(braid_App app,
709 * braid_Vector *v_ptr);
713 * * @brief my_Free - Deletes a vector
715 * * @param app - The braid app struct containing user data
716 * * @param u - The vector that needs to be deleted
718 * * @return Success (0) or failure (1)
721 * my_Free(braid_App app,
726 * * @brief my_Sum - Sums two vectors in an AXPY operation
727 * * The operation is y = alpha*x + beta*y
729 * * @param app - The braid app struct containing user data
730 * * @param alpha - The coefficient in front of x
731 * * @param x - A vector that is multiplied by alpha then added to y
732 * * @param beta - The coefficient of y
733 * * @param y - A vector that is multiplied by beta then summed with x
735 * * @return Success (0) or failure (1)
738 * my_Sum(braid_App app,
745 * * \brief Returns the spatial norm of the provided vector
747 * * Calculates and returns the spatial norm of the provided vector.
748 * * Interestingly enough, X-Braid does not specify a particular norm.
749 * * to keep things simple, we implement the Euclidean norm.
751 * * \param app - The braid app struct containing user data
752 * * \param u - The vector we need to take the norm of
753 * * \param norm_ptr - Pointer to the norm that was calculated, need to modify this
754 * * \return Success (0) or failure (1)
757 * my_SpatialNorm(braid_App app,
762 * * \brief Allows the user to output details
764 * * The Access function is called at various points to allow the user to output
765 * * information to the screen or to files.
766 * * The astatus parameter provides various information about the simulation,
767 * * see the XBraid documentation for details on what information you can get.
768 * * Example information is what the current timestep number and current time is.
769 * * If the access level (in parallel_in_time.cc) is set to 0, this function is
771 * * If the access level is set to 1, the function is called after the last
773 * * If the access level is set to 2, it is called every XBraid cycle.
775 * * \param app - The braid app struct containing user data
776 * * \param u - The vector containing the data at the status provided
777 * * \param astatus - The Braid status structure
778 * * \return Success (0) or failure (1)
781 * my_Access(braid_App app,
783 * braid_AccessStatus astatus);
786 * * \brief Calculates the size of a buffer for MPI data transfer
788 * * Calculates the size of the buffer that is needed to transfer
789 * * a solution vector to another processor.
790 * * The bstatus parameter provides various information on the
791 * * simulation, see the XBraid documentation for all possible
794 * * \param app - The braid app struct containing user data
795 * * \param size_ptr A pointer to the calculated size
796 * * \param bstatus The XBraid status structure
797 * * \return Success (0) or failure (1)
800 * my_BufSize(braid_App app,
802 * braid_BufferStatus bstatus);
805 * * \brief Linearizes a vector to be sent to another processor
807 * * Linearizes (packs) a data buffer with the contents of
808 * * some solution state u.
810 * * \param app - The braid app struct containing user data
811 * * \param u The vector that must be packed into buffer
812 * * \param buffer The buffer that must be filled with u
813 * * \param bstatus The XBraid status structure
814 * * \return Success (0) or failure (1)
817 * my_BufPack(braid_App app,
820 * braid_BufferStatus bstatus);
823 * * \brief Unpacks a vector that was sent from another processor
825 * * Unpacks a linear data buffer into the vector pointed to by
828 * * \param app - The braid app struct containing user data
829 * * \param buffer The buffer that must be unpacked
830 * * \param u_ptr The pointer to the vector that is filled
831 * * \param bstatus The XBraid status structure
832 * * \return Success (0) or failure (1)
835 * my_BufUnpack(braid_App app,
837 * braid_Vector *u_ptr,
838 * braid_BufferStatus bstatus);
840 * #endif // _BRAIDFUNCS_H_
844<a name="ann-src/HeatEquation.hh"></a>
845<h1>Annotated version of src/HeatEquation.hh</h1>
851 * /* -----------------------------------------------------------------------------
853 * * SPDX-License-Identifier: LGPL-2.1-or-later
854 * * Copyright (C) 2018 by Joshua Christopher
856 * * This file is part of the deal.II code gallery.
858 * * -----------------------------------------------------------------------------
861 * #ifndef _HEATEQUATION_H_
862 * #define _HEATEQUATION_H_
864 * #include <deal.II/base/utilities.h>
865 * #include <deal.II/base/quadrature_lib.h>
866 * #include <deal.II/base/function.h>
867 * #include <deal.II/base/logstream.h>
868 * #include <deal.II/lac/vector.h>
869 * #include <deal.II/lac/full_matrix.h>
870 * #include <deal.II/lac/dynamic_sparsity_pattern.h>
871 * #include <deal.II/lac/sparse_matrix.h>
872 * #include <deal.II/lac/solver_cg.h>
873 * #include <deal.II/lac/precondition.h>
874 * #include <deal.II/lac/affine_constraints.h>
875 * #include <deal.II/grid/tria.h>
876 * #include <deal.II/grid/grid_generator.h>
877 * #include <deal.II/grid/grid_refinement.h>
878 * #include <deal.II/grid/grid_out.h>
879 * #include <deal.II/grid/tria_accessor.h>
880 * #include <deal.II/grid/tria_iterator.h>
881 * #include <deal.II/dofs/dof_handler.h>
882 * #include <deal.II/dofs/dof_accessor.h>
883 * #include <deal.II/dofs/dof_tools.h>
884 * #include <deal.II/fe/fe_q.h>
885 * #include <deal.II/fe/fe_values.h>
886 * #include <deal.II/numerics/data_out.h>
887 * #include <deal.II/numerics/vector_tools.h>
888 * #include <deal.II/numerics/error_estimator.h>
889 * #include <deal.II/numerics/solution_transfer.h>
890 * #include <deal.II/numerics/matrix_tools.h>
891 * #include <deal.II/base/convergence_table.h>
895 * using namespace dealii;
899 * The HeatEquation class is describes the finite element
900 * solver for the heat equation. It contains all the functions
901 * needed to define the problem domain and advance the solution
911 * void step(Vector<double>& braid_data,
916 * int size() const; /// Returns the size of the solution vector
918 * void output_results(int a_time_idx,
920 * Vector<double>& a_solution) const;
922 * void initialize(double a_time,
923 * Vector<double>& a_vector) const;
925 * void process_solution(double a_time,
927 * const Vector<double>& a_vector);
930 * void setup_system();
931 * void solve_time_step(Vector<double>& a_solution);
933 * Triangulation<dim> triangulation;
935 * DoFHandler<dim> dof_handler;
937 * AffineConstraints<double> constraints;
939 * SparsityPattern sparsity_pattern;
940 * SparseMatrix<double> mass_matrix;
941 * SparseMatrix<double> laplace_matrix;
942 * SparseMatrix<double> system_matrix;
944 * Vector<double> system_rhs;
946 * std::ofstream myfile;
948 * const double theta;
952 * These were originally in the run() function but because
953 * I am splitting the run() function up into define and step
954 * they need to become member data
957 * Vector<double> tmp;
958 * Vector<double> forcing_terms;
960 * ConvergenceTable convergence_table;
965 * The RightHandSide class describes the RHS of the governing
966 * equations. In this case, it is the forcing function.
970 * class RightHandSide : public Function<dim>
979 * virtual double value (const Point<dim> &p,
980 * const unsigned int component = 0) const override;
983 * const double period;
988 * The BoundaryValues class describes the boundary conditions
989 * of the governing equations.
993 * class BoundaryValues : public Function<dim>
996 * virtual double value (const Point<dim> &p,
997 * const unsigned int component = 0) const override;
1002 * The RightHandSideMFG class describes the right hand side
1003 * function when doing the method of manufactured solutions.
1006 * template <int dim>
1007 * class RightHandSideMFG : public Function<dim>
1010 * virtual double value (const Point<dim> &p,
1011 * const unsigned int component = 0) const override;
1016 * The InitialValuesMFG class describes the initial values
1017 * when doing the method of manufactured solutions.
1020 * template <int dim>
1021 * class InitialValuesMFG : public Function<dim>
1024 * virtual double value (const Point<dim> &p,
1025 * const unsigned int component = 0) const override;
1030 * Provides the exact value for the manufactured solution. This
1031 * is used for the boundary conditions as well.
1034 * template <int dim>
1035 * class ExactValuesMFG : public Function<dim>
1039 * * \brief Computes the value at the given point and member data time
1041 * * Computes the exact value of the manufactured solution at point p and
1042 * * the member data time. See the class documentation and the design doc
1043 * * for details on what the exact solution is.
1045 * * \param p The point that the exact solution is computed at
1046 * * \param component The component of the exact solution (always 0 for now)
1047 * * \return double The exact value that was computed
1049 * virtual double value (const Point<dim> &p,
1050 * const unsigned int component = 0) const override;
1053 * * \brief Computes the gradient of the exact solution at the given point
1055 * * Computes the gradient of the exact/manufactured solution value at
1056 * * point p and member data time. See the design doc for details on
1057 * * what the gradient of the exact solution is
1059 * * \param p The point that the gradient is calculated at
1060 * * \param component The component of the system of equations this gradient is for
1061 * * \return Tensor<1,dim> A rank 1 tensor that contains the gradient
1062 * * in each spatial dimension
1064 * virtual Tensor<1,dim> gradient (const Point<dim> &p,
1065 * const unsigned int component = 0) const override;
1069 * #include "HeatEquationImplem.hh"
1071 * #endif // _HEATEQUATION_H_
1075<a name="ann-src/HeatEquationImplem.hh"></a>
1076<h1>Annotated version of src/HeatEquationImplem.hh</h1>
1082 * /* -----------------------------------------------------------------------------
1084 * * SPDX-License-Identifier: LGPL-2.1-or-later
1085 * * Copyright (C) 2018 by Joshua Christopher
1087 * * This file is part of the deal.II code gallery.
1089 * * -----------------------------------------------------------------------------
1092 * #include "Utilities.hh"
1094 * #include <iomanip>
1099 * Calculates the forcing function for the RightHandSide. See the
1100 * documentation for the math.
1103 * template <int dim>
1104 * double RightHandSide<dim>::value (const Point<dim> &p,
1105 * const unsigned int component) const
1108 * Assert (component == 0, ExcIndexRange(component, 0, 1));
1109 * Assert (dim == 2, ExcNotImplemented());
1111 * double time = this->get_time();
1113 * if ((p[0] > 0.5) && (p[1] > -0.5))
1115 * return std::exp(-0.5*(time-0.125)*(time-0.125)/(0.005));
1117 * else if ((p[0] > -0.5) && (p[1] > 0.5))
1119 * return std::exp(-0.5*(time-0.375)*(time-0.375)/(0.005));
1126 * return 0; // No forcing function
1131 * Calculates the forcing function for the method of manufactured
1132 * solutions. See the documentation for the math.
1135 * template <int dim>
1136 * double RightHandSideMFG<dim>::value (const Point<dim> &p,
1137 * const unsigned int component) const
1140 * Assert (component == 0, ExcIndexRange(component, 0, 1));
1141 * Assert (dim == 2, ExcNotImplemented());
1143 * double time = this->get_time();
1145 * double pi = numbers::PI;
1146 * return 4*pi*pi*std::exp(-4*pi*pi*time)*std::cos(2*pi*p[0])*std::cos(2*pi*p[1]);
1151 * Calculates the boundary conditions, essentially zero everywhere.
1154 * template <int dim>
1155 * double BoundaryValues<dim>::value (const Point<dim> &p,
1156 * const unsigned int component) const
1160 * Assert (component == 0, ExcIndexRange(component, 0, 1));
1166 * Calculates the exact solution (and thus also boundary conditions)
1167 * for the method of manufactured solutions.
1170 * template <int dim>
1171 * double ExactValuesMFG<dim>::value (const Point<dim> &p,
1172 * const unsigned int component) const
1175 * Assert (component == 0, ExcIndexRange(component, 0, 1));
1177 * double time = this->get_time();
1178 * const double pi = numbers::PI;
1180 * return std::exp(-4*pi*pi*time)*std::cos(2*pi*p[0])*std::cos(2*pi*p[1]);
1185 * Calculates the gradient of the exact solution for the method of manufactured
1186 * solutions. See the documentation for the math.
1189 * template <int dim>
1190 * Tensor<1,dim> ExactValuesMFG<dim>::gradient (const Point<dim> &p,
1191 * const unsigned int) const
1193 * Assert (dim == 2, ExcNotImplemented());
1195 * Tensor<1,dim> return_value;
1196 * const double pi = numbers::PI;
1197 * double time = this->get_time();
1198 * return_value[0] = -2*pi*std::exp(-4*pi*pi*time)*std::cos(2*pi*p[1])*std::sin(2*pi*p[0]);
1199 * return_value[1] = -2*pi*std::exp(-4*pi*pi*time)*std::cos(2*pi*p[0])*std::sin(2*pi*p[1]);
1200 * return return_value;
1205 * Calculates the initial values for the method of manufactured solutions.
1206 * See the documentation for the math.
1209 * template <int dim>
1210 * double InitialValuesMFG<dim>::value (const Point<dim> &p,
1211 * const unsigned int component) const
1214 * Assert (component == 0, ExcIndexRange(component, 0, 1));
1215 * const double pi = numbers::PI;
1217 * return std::cos(2*pi*p[0])*std::cos(2*pi*p[1]);
1220 * template <int dim>
1221 * HeatEquation<dim>::HeatEquation ()
1224 * dof_handler(triangulation),
1229 * template <int dim>
1230 * void HeatEquation<dim>::initialize(double a_time,
1231 * Vector<double>& a_vector) const
1236 * We only initialize values in the manufactured solution case
1239 * InitialValuesMFG<dim> iv_function;
1240 * iv_function.set_time(a_time);
1241 * VectorTools::project (dof_handler, constraints,
1242 * QGauss<dim>(fe.degree+1), iv_function,
1250 * If not the MFG solution case, a_vector is already zero'd so
do nothing
1255 *
template <
int dim>
1256 *
void HeatEquation<dim>::setup_system()
1258 * dof_handler.distribute_dofs(fe);
1260 * constraints.clear ();
1263 * constraints.close();
1270 * sparsity_pattern.copy_from(dsp);
1273 * laplace_matrix.reinit(sparsity_pattern);
1274 * system_matrix.reinit(sparsity_pattern);
1283 * system_rhs.reinit(dof_handler.n_dofs());
1287 *
template <
int dim>
1288 *
void HeatEquation<dim>::solve_time_step(
Vector<double>& a_solution)
1290 *
SolverControl solver_control(1000, 1e-8 * system_rhs.l2_norm());
1294 * preconditioner.
initialize(system_matrix, 1.0);
1296 * cg.solve(system_matrix, a_solution, system_rhs,
1299 * constraints.distribute(a_solution);
1304 *
template <
int dim>
1305 *
void HeatEquation<dim>::output_results(
int a_time_idx,
1311 * vtk_flags.
time = a_time;
1312 * vtk_flags.cycle = a_time_idx;
1317 * data_out.attach_dof_handler(dof_handler);
1318 * data_out.add_data_vector(a_solution,
"U");
1320 * data_out.build_patches();
1322 *
const std::string filename =
"solution-"
1325 * std::ofstream output(filename.c_str());
1326 * data_out.write_vtk(output);
1331 * We define the geometry here,
this is called on each processor
1332 * and doesn
't change in time. Once doing AMR, this won't need
1336 *
template <
int dim>
1337 *
void HeatEquation<dim>::define()
1339 *
const unsigned int initial_global_refinement = 6;
1346 * tmp.reinit (dof_handler.n_dofs());
1347 * forcing_terms.reinit (dof_handler.n_dofs());
1352 * Here we
advance the solution forward in time. This is done
1353 * the same way as in the
loop in @ref step_26
"step-26"'s run function.
1357 * void HeatEquation<dim>::step(Vector<double>& braid_data,
1365 * mass_matrix.vmult(system_rhs, braid_data);
1367 * laplace_matrix.vmult(tmp, braid_data);
1369 * system_rhs.add(-(1 - theta) * deltaT, tmp);
1372 * RightHandSideMFG<dim> rhs_function;
1374 * RightHandSide<dim> rhs_function;
1376 * rhs_function.set_time(a_time);
1377 * VectorTools::create_right_hand_side(dof_handler,
1378 * QGauss<dim>(fe.degree+1),
1382 * forcing_terms = tmp;
1383 * forcing_terms *= deltaT * theta;
1385 * rhs_function.set_time(a_time - deltaT);
1386 * VectorTools::create_right_hand_side(dof_handler,
1387 * QGauss<dim>(fe.degree+1),
1391 * forcing_terms.add(deltaT * (1 - theta), tmp);
1392 * system_rhs += forcing_terms;
1394 * system_matrix.copy_from(mass_matrix);
1395 * system_matrix.add(theta * deltaT, laplace_matrix);
1397 * constraints.condense (system_matrix, system_rhs);
1403 * If we are doing the method of manufactured solutions
1404 * then we set the boundary conditions to the exact solution.
1405 * Otherwise the boundary conditions are zero.
1408 * ExactValuesMFG<dim> boundary_values_function;
1410 * BoundaryValues<dim> boundary_values_function;
1412 * boundary_values_function.set_time(a_time);
1414 * std::map<types::global_dof_index, double> boundary_values;
1415 * VectorTools::interpolate_boundary_values(dof_handler,
1417 * boundary_values_function,
1420 * MatrixTools::apply_boundary_values(boundary_values,
1426 * solve_time_step(braid_data);
1430 * int HeatEquation<dim>::size() const
1432 * return dof_handler.n_dofs();
1437 * This function computes the error for the time step when doing
1438 * the method of manufactured solutions. First the exact values
1439 * is calculated, then the difference per cell is computed for
1440 * the various norms, and the error is computed. This is written
1441 * out to a pretty table.
1444 * template<int dim> void
1445 * HeatEquation<dim>::process_solution(double a_time,
1447 * const Vector<double>& a_vector)
1451 * Compute the exact value for the manufactured solution case
1454 * ExactValuesMFG<dim> exact_function;
1455 * exact_function.set_time(a_time);
1457 * Vector<double> difference_per_cell (triangulation.n_active_cells());
1458 * VectorTools::integrate_difference(dof_handler,
1461 * difference_per_cell,
1462 * QGauss<dim>(fe.degree+1),
1463 * VectorTools::L2_norm);
1465 * const double L2_error = VectorTools::compute_global_error(triangulation,
1466 * difference_per_cell,
1467 * VectorTools::L2_norm);
1469 * VectorTools::integrate_difference(dof_handler,
1472 * difference_per_cell,
1473 * QGauss<dim>(fe.degree+1),
1474 * VectorTools::H1_seminorm);
1476 * const double H1_error = VectorTools::compute_global_error(triangulation,
1477 * difference_per_cell,
1478 * VectorTools::H1_seminorm);
1480 * const QTrapezoid<1> q_trapez;
1481 * const QIterated<dim> q_iterated (q_trapez, 5);
1482 * VectorTools::integrate_difference (dof_handler,
1485 * difference_per_cell,
1487 * VectorTools::Linfty_norm);
1488 * const double Linfty_error = VectorTools::compute_global_error(triangulation,
1489 * difference_per_cell,
1490 * VectorTools::Linfty_norm);
1492 * const unsigned int n_active_cells = triangulation.n_active_cells();
1493 * const unsigned int n_dofs = dof_handler.n_dofs();
1495 * pout() << "Cycle " << a_index << ':
'
1497 * << " Number of active cells: "
1500 * << " Number of degrees of freedom: "
1504 * convergence_table.add_value("cycle", a_index);
1505 * convergence_table.add_value("cells", n_active_cells);
1506 * convergence_table.add_value("dofs", n_dofs);
1507 * convergence_table.add_value("L2", L2_error);
1508 * convergence_table.add_value("H1", H1_error);
1509 * convergence_table.add_value("Linfty", Linfty_error);
1511 * convergence_table.set_precision("L2", 3);
1512 * convergence_table.set_precision("H1", 3);
1513 * convergence_table.set_precision("Linfty", 3);
1515 * convergence_table.set_scientific("L2", true);
1516 * convergence_table.set_scientific("H1", true);
1517 * convergence_table.set_scientific("Linfty", true);
1519 * convergence_table.set_tex_caption("cells", "\\# cells");
1520 * convergence_table.set_tex_caption("dofs", "\\# dofs");
1521 * convergence_table.set_tex_caption("L2", "@fL^2@f-error");
1522 * convergence_table.set_tex_caption("H1", "@fH^1@f-error");
1523 * convergence_table.set_tex_caption("Linfty", "@fL^\\infty@f-error");
1525 * convergence_table.set_tex_format("cells", "r");
1526 * convergence_table.set_tex_format("dofs", "r");
1528 * std::cout << std::endl;
1529 * convergence_table.write_text(std::cout);
1531 * std::ofstream error_table_file("tex-conv-table.tex");
1532 * convergence_table.write_tex(error_table_file);
1537<a name="ann-src/Utilities.cc"></a>
1538<h1>Annotated version of src/Utilities.cc</h1>
1544 * /* -----------------------------------------------------------------------------
1546 * * SPDX-License-Identifier: LGPL-2.1-or-later
1547 * * Copyright (C) 2018 by Joshua Christopher
1549 * * This file is part of the deal.II code gallery.
1551 * * -----------------------------------------------------------------------------
1554 * #include "Utilities.hh"
1557 * #include <fstream>
1566 * The shared variables
1572 * static std::string s_pout_filename ;
1573 * static std::string s_pout_basename ;
1574 * static std::ofstream s_pout ;
1576 * static bool s_pout_init = false ;
1577 * static bool s_pout_open = false ;
1581 * in parallel, compute the filename give the basename
1582 * [NOTE: dont call this before MPI is initialized.]
1585 * static void setFileName()
1587 * static const size_t ProcnumSize = 1 + 10 + 1 ; //'.
' + 10digits + '\0
'
1588 * char procnum[ProcnumSize] ;
1589 * snprintf( procnum ,ProcnumSize ,".%d" ,procID);
1590 * s_pout_filename = s_pout_basename + procnum ;
1595 * in parallel, close the file if nec., open it and check for success
1598 * static void openFile()
1600 * if ( s_pout_open )
1604 * s_pout.open( s_pout_filename.c_str() );
1607 * if open() fails, we have problems, but it's better
1608 * to
try again later than to make believe it succeeded
1611 * s_pout_open = (
bool)s_pout ;
1615 * std::ostream& pout()
1620 * the common
case is _open ==
true, which just returns s_pout
1623 *
if ( ! s_pout_open )
1627 * the uncommon cae: the file isn
't opened, MPI may not be
1628 * initialized, and the basename may not have been set
1631 * int flag_i, flag_f;
1632 * MPI_Initialized(&flag_i);
1633 * MPI_Finalized(&flag_f);
1636 * app hasn't set a basename yet, so set the
default
1639 *
if ( ! s_pout_init )
1641 * s_pout_basename =
"pout" ;
1642 * s_pout_init = true ;
1646 *
if MPI not initialized, we can
't open the file so return cout
1649 * if ( ! flag_i || flag_f)
1651 * return std::cout; // MPI hasn't been started yet, or has ended....
1655 *
MPI is initialized, so file must not be, so open it
1662 *
finally, in
case the open failed,
return cout
1665 *
if ( ! s_pout_open )
1667 *
return std::cout ;
1678<a name=
"ann-src/Utilities.hh"></a>
1679<h1>Annotated version of src/
Utilities.hh</h1>
1695 * #ifndef _UTILITIES_H_
1696 * #define _UTILITIES_H_
1698 * #include <iostream>
1702 * This preprocessor macro is used on function arguments
1703 * that are not used in the function. It is used to
1704 * suppress compiler warnings.
1707 * #define UNUSED(x) (void)(x)
1711 * Contains the current
MPI processor ID.
1714 *
extern int procID;
1718 *
Function to
return the ostream to write out to. In
MPI
1719 * mode it returns a stream to a file named pout.<#> where
1720 * <#> is the procID. This allows the user to write output
1721 * from each processor to a separate file. In
serial mode
1722 * (no
MPI), it returns the standard output.
1725 * std::ostream& pout();
1730<a name=
"ann-src/parallel_in_time.cc"></a>
1731<h1>Annotated version of src/parallel_in_time.cc</h1>
1749 * #include
"BraidFuncs.hh"
1750 * #include
"HeatEquation.hh"
1751 * #include
"Utilities.hh"
1753 * #include <fstream>
1754 * #include <iostream>
1756 *
int main(
int argc,
char *argv[])
1760 *
using namespace dealii;
1765 * MPI_Init(&argc, &argv);
1766 *
comm = MPI_COMM_WORLD;
1767 * MPI_Comm_rank(
comm, &rank);
1777 *
double tstart = 0.0;
1778 *
double tstop = 0.002;
1780 * my_App *app =
new(my_App);
1782 * braid_Init(MPI_COMM_WORLD,
comm, tstart, tstop, ntime, app,
1783 * my_Step, my_Init, my_Clone, my_Free, my_Sum, my_SpatialNorm,
1784 * my_Access, my_BufSize, my_BufPack, my_BufUnpack, &core);
1788 *
int max_levels = 3;
1795 *
double tol = 1.e-7;
1804 *
int min_coarse = 10;
1808 *
int wrapper_tests = 0;
1811 *
int print_level = 1;
1812 *
int access_level = 1;
1813 *
int use_sequential= 0;
1815 * braid_SetPrintLevel( core, print_level);
1816 * braid_SetAccessLevel( core, access_level);
1817 * braid_SetMaxLevels(core, max_levels);
1820 * braid_SetMinCoarse( core, min_coarse );
1821 * braid_SetSkip(core, skip);
1822 * braid_SetNRelax(core, -1, nrelax);
1825 * braid_SetAbsTol(core, tol);
1828 * braid_SetCFactor(core, -1, cfactor);
1831 * braid_SetMaxIter(core, max_iter);
1832 * braid_SetSeqSoln(core, use_sequential);
1835 * app->final_step = ntime;
1837 * braid_Drive(core);
1841 * Free the memory now that we are done
1844 * braid_Destroy(core);
1851 * MPI_Comm_free(&
comm);
1856 *
catch (std::exception &exc)
1858 * std::cerr << std::endl << std::endl
1859 * <<
"----------------------------------------------------"
1861 * std::cerr <<
"Exception on processing: " << std::endl << exc.what()
1862 * << std::endl <<
"Aborting!" << std::endl
1863 * <<
"----------------------------------------------------"
1870 * std::cerr << std::endl << std::endl
1871 * <<
"----------------------------------------------------"
1873 * std::cerr <<
"Unknown exception!" << std::endl <<
"Aborting!"
1875 * <<
"----------------------------------------------------"
1886<a name=
"ann-test/test_braid.cc"></a>
1887<h1>Annotated version of test/test_braid.cc</h1>
1903 * #include
"BraidFuncs.hh"
1905 * #include <braid.h>
1906 * #include <braid_test.h>
1908 * #include <iostream>
1910 *
int main(
int argc,
char** argv)
1914 * MPI_Init(&argc, &argv);
1915 *
comm = MPI_COMM_WORLD;
1916 * MPI_Comm_rank(
comm, &rank);
1918 * my_App *app =
new(my_App);
1921 *
double time = 0.2;
1923 * braid_Int init_access_result = braid_TestInitAccess(app,
1930 * (
void)init_access_result;
1932 * braid_Int clone_result = braid_TestClone(app,
1940 * (
void)clone_result;
1942 * braid_Int sum_result = braid_TestSum(app,
1953 * braid_Int norm_result = braid_TestSpatialNorm(app,
1962 * (
void)norm_result;
1964 * braid_Int buf_result = braid_TestBuf(app,
1980 * braid_SplitCommworld(&
comm, 1, &comm_x, &comm_t);
1984 * 2*(tstop-tstart)/ntime, my_Init, my_Free, my_Clone,
1985 * my_Sum, my_SpatialNorm, my_BufSize, my_BufPack,
1986 * my_BufUnpack, my_Coarsen, my_Interp, my_Residual, my_Step);
void set_flags(const FlagType &flags)
void initialize(const MatrixType &A, const AdditionalData ¶meters=AdditionalData())
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())
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)
std::vector< index_type > data
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.)
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)
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)
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)