]> https://gitweb.dealii.org/ - code-gallery.git/commitdiff
Add annotations to the source to explain choices.
authorDavid Wells <wellsd2@rpi.edu>
Sat, 9 Jan 2016 19:18:10 +0000 (14:18 -0500)
committerDavid Wells <wellsd2@rpi.edu>
Sat, 9 Jan 2016 21:46:35 +0000 (16:46 -0500)
cdr/common/include/deal.II-cdr/parameters.h
cdr/common/include/deal.II-cdr/system_matrix.h
cdr/common/include/deal.II-cdr/system_matrix.templates.h
cdr/common/include/deal.II-cdr/system_rhs.h
cdr/common/include/deal.II-cdr/system_rhs.templates.h
cdr/common/include/deal.II-cdr/write_pvtu_output.h
cdr/common/include/deal.II-cdr/write_pvtu_output.templates.h
cdr/common/source/system_matrix.cc
cdr/common/source/system_rhs.cc
cdr/common/source/write_pvtu_output.cc
cdr/solver/cdr.cc

index 525c9ff2e06601051d52f5646bdb734a17199bd1..ddf2d15323c9b0d9911087d74eb9c863a818d534 100644 (file)
@@ -5,6 +5,12 @@
 
 #include <string>
 
+// I prefer to use the ParameterHandler class in a slightly different way than
+// usual: The class Parameters creates, uses, and then destroys a
+// ParameterHandler inside the <code>read_parameter_file</code> method instead
+// of keeping it around. This is nice because now all of the run time
+// parameters are contained in a simple class and it can be copied or passed
+// around very easily.
 namespace CDR
 {
   using namespace dealii;
index 4697587fda1d0e590bdabb9466e9e31ec4b2a47c..348f419cff52f6304575377e0cd277ba2ac62924 100644 (file)
 
 #include <functional>
 
+// One of the goals I had in writing this entry was to split up functions into
+// different compilation units instead of using one large file. This is the
+// header file for a pair of functions (only one of which I ultimately use)
+// which build the system matrix.
 namespace CDR
 {
   using namespace dealii;
index 41f7c4c381e0c4bfdc8e0edef7be8eedf6b0b880..7cafd467781eb34d2bae78ebcc5a52eed1f4c5b1 100644 (file)
@@ -19,6 +19,9 @@ namespace CDR
 {
   using namespace dealii;
 
+  // This is the actual implementation of the <code>create_system_matrix</code>
+  // function described in the header file. It is similar to the system matrix
+  // assembly routine in step-40.
   template<int dim, typename UpdateFunction>
   void internal_create_system_matrix
   (const DoFHandler<dim>                                 &dof_handler,
@@ -55,13 +58,13 @@ namespace CDR
                         const auto convection_contribution = current_convection
                           *fe_values.shape_grad(j, q);
                         cell_matrix(i, j) += fe_values.JxW(q)*
-                          // mass and reaction part
+                          // Here are the time step, mass, and reaction parts:
                           ((1.0 + time_step/2.0*parameters.reaction_coefficient)
                            *fe_values.shape_value(i, q)*fe_values.shape_value(j, q)
                            + time_step/2.0*
-                           // convection part
+                           // and the convection part:
                            (fe_values.shape_value(i, q)*convection_contribution
-                            // Laplacian part
+                            // and, finally, the diffusion part:
                             + parameters.diffusion_coefficient
                             *(fe_values.shape_grad(i, q)*fe_values.shape_grad(j, q)))
                            );
index 96c8cb4db533abd732525c4a443bc8a9bcf20586..966542da249365f2728595f6d8664018874bc068 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <functional>
 
+// Similarly to <code>create_system_matrix</code>, I wrote a separate function
+// to compute the right hand side.
 namespace CDR
 {
   using namespace dealii;
index efbac5c4bba145e28750aee3c454575c9f5a84a9..9e49a5e88aa9a80174d30834a48a8a6550b64dac 100644 (file)
@@ -78,17 +78,17 @@ namespace CDR
                           *fe_values.shape_grad(j, q);
 
                         cell_rhs(i) += fe_values.JxW(q)*
-                          // mass and reaction part
+                          // Here are the mass and reaction part:
                           (((1.0 - time_step/2.0*parameters.reaction_coefficient)
                             *fe_values.shape_value(i, q)*fe_values.shape_value(j, q)
                             - time_step/2.0*
-                            // convection part
+                            // the convection part:
                             (fe_values.shape_value(i, q)*convection_contribution
-                             // Laplacian part
+                             // the diffusion part:
                              + parameters.diffusion_coefficient
                              *(fe_values.shape_grad(i, q)*fe_values.shape_grad(j, q))))
                            *current_fe_coefficients[j]
-                           // forcing parts
+                           // and, finally, the forcing function part:
                            + time_step/2.0*
                            (current_forcing + previous_forcing)
                            *fe_values.shape_value(i, q));
index 92e793eed5dbe0ea0499bbef8123cd671da73b86..5b0b1c277d7157bacf2ee17ef5d16c411911f7df 100644 (file)
@@ -2,6 +2,7 @@
 #define dealii__cdr_write_pvtu_output_h
 #include <deal.II/dofs/dof_handler.h>
 
+// This is a small class which handles PVTU output.
 namespace CDR
 {
   using namespace dealii;
index 5f2f63dcbe3ea0feb87bc51da7b5548cc785410e..ec479a5e75f2f67b600ab565b24b8fb29ea04be9 100644 (file)
@@ -15,6 +15,8 @@
 #include <fstream>
 #include <vector>
 
+// Here is the implementation of the important function. This is similar to
+// what is presented in step-40.
 namespace CDR
 {
   using namespace dealii;
@@ -39,6 +41,8 @@ namespace CDR
 
     DataOutBase::VtkFlags flags;
     flags.time = current_time;
+    // While the default flag is for the best compression level, using
+    // <code>best_speed</code> makes this function much faster.
     flags.compression_level = DataOutBase::VtkFlags::ZlibCompressionLevel::best_speed;
     data_out.set_flags(flags);
 
index ae90c0b58044ef873df6defac71d23ba25d1488c..ae14c4e780008f527f1bf9bf5be171f78e348f26 100644 (file)
@@ -5,6 +5,10 @@
 #include <deal.II-cdr/system_matrix.h>
 #include <deal.II-cdr/system_matrix.templates.h>
 
+// This file exists just to build template specializations of
+// <code>create_system_matrix</code>. Even though the solver is run in
+// parallel with Trilinos objects, other serial solvers can use the same
+// function without recompilation by compiling everything here just one time.
 namespace CDR
 {
   using namespace dealii;
index 4374d734634bf195e9e727ffb06d26c3e6fd89e6..609e82416b4e4a27cb1d6db00283237ca9021014 100644 (file)
@@ -5,6 +5,8 @@
 
 #include <deal.II-cdr/system_rhs.templates.h>
 
+// Like <code>system_matrix.cc</code>, this file just compiles template
+// specializations.
 namespace CDR
 {
   using namespace dealii;
index 4e27847d9f3d45ab85e2e6aa16ab64573ce17bbd..f74f2c21e94444a0f044bd41cd9ea5392b96bb20 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <deal.II-cdr/write_pvtu_output.templates.h>
 
+// Again, this file just compiles the constructor and also the templated
+// functions.
 namespace CDR
 {
   using namespace dealii;
index fffb44275d934a183c051eb1c5ed09f7eb95bfec..2cfa7336432c0909662155929b33f665033a79d8 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <deal.II/numerics/error_estimator.h>
 
-// for distributed computations
+// These headers are for distributed computations:
 #include <deal.II/base/utilities.h>
 #include <deal.II/base/index_set.h>
 #include <deal.II/distributed/tria.h>
@@ -40,7 +40,8 @@ using namespace dealii;
 
 constexpr int manifold_id {0};
 
-
+// This is the actual solver class which performs time iteration and calls the
+// appropriate library functions to do it.
 template<int dim>
 class CDRProblem
 {
@@ -70,6 +71,13 @@ private:
 
   ConstraintMatrix constraints;
   bool first_run;
+
+  // As is usual in parallel programs, I keep two copies of parts of the
+  // complete solution: <code>locally_relevant_solution</code> contains both
+  // the locally calculated solution as well as the layer of cells at its
+  // boundary (the @ref GlossGhostCells "ghost cells") while
+  // <code>completely_distributed_solution</code> only contains the parts of
+  // the solution computed on the current @ref GlossMPIProcess "MPI process".
   TrilinosWrappers::MPI::Vector locally_relevant_solution;
   TrilinosWrappers::MPI::Vector completely_distributed_solution;
   TrilinosWrappers::MPI::Vector system_rhs;
@@ -284,6 +292,8 @@ constexpr int dim {2};
 
 int main(int argc, char *argv[])
 {
+  // One of the new features in C++11 is the <code>chrono</code> component of
+  // the standard library. This gives us an easy way to time the output.
   auto t0 = std::chrono::high_resolution_clock::now();
 
   Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.