]> https://gitweb.dealii.org/ - dealii.git/commitdiff
modify the test codes to meet the format requirements
authorYimin Jin <jinym@cea-igp.ac.cn>
Fri, 19 Jan 2024 03:41:23 +0000 (11:41 +0800)
committerYimin Jin <jinym@cea-igp.ac.cn>
Fri, 19 Jan 2024 03:41:23 +0000 (11:41 +0800)
tests/dofs/dof_accessor_04.cc
tests/dofs/dof_accessor_04.output

index 9f88b53f75a83ea18780342a354e23f7c94cdb44..f4b205aa0e41f52f203fa2c5e8fbe79b478e2e7b 100644 (file)
 // ---------------------------------------------------------------------
 
 // Test DoFCellAccessor::distribute_local_to_global(
-// local_matrix, local_vector, global_matrix, global_vector) 
+// local_matrix, local_vector, global_matrix, global_vector)
 
-#include <deal.II/grid/tria.h>
-#include <deal.II/grid/grid_generator.h>
 #include <deal.II/dofs/dof_handler.h>
 #include <deal.II/dofs/dof_tools.h>
+
 #include <deal.II/fe/fe_q.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+
 #include <deal.II/lac/dynamic_sparsity_pattern.h>
-#include <deal.II/lac/sparse_matrix.h>
 #include <deal.II/lac/full_matrix.h>
+#include <deal.II/lac/sparse_matrix.h>
 #include <deal.II/lac/vector.h>
 
-#include <iostream>
+#include "../tests.h"
 
-int main()
+int
+main()
 {
-  using namespace dealii;
+  initlog();
 
   // create the triangulation
   Triangulation<2> tria;
@@ -50,37 +54,48 @@ int main()
   sp.copy_from(dsp);
 
   SparseMatrix<double> global_matrix(sp);
-  Vector<double> global_vector(dof_handler.n_dofs());
+  Vector<double>       global_vector(dof_handler.n_dofs());
 
   // create local matrix and local vector
   FullMatrix<double> local_matrix(fe.dofs_per_cell, fe.dofs_per_cell);
-  Vector<double> local_vector(fe.dofs_per_cell);
+  Vector<double>     local_vector(fe.dofs_per_cell);
   for (unsigned int i = 0; i < fe.dofs_per_cell; ++i)
-  {
-    local_vector(i) = i + 1;
-    for (unsigned int j = 0; j < fe.dofs_per_cell; ++j)
-      local_matrix(i, j) = i * fe.dofs_per_cell + j + 1;
-  }
+    {
+      local_vector(i) = i + 1;
+      for (unsigned int j = 0; j < fe.dofs_per_cell; ++j)
+        local_matrix(i, j) = i * fe.dofs_per_cell + j + 1;
+    }
 
   // call function distribute_local_to_global()
   auto cell = dof_handler.begin_active();
-  cell->distribute_local_to_global(local_matrix, local_vector, global_matrix, global_vector);
-
-  // output the local matrix and local vector
-  std::cout << "local matrix:" << std::endl;
-  local_matrix.print_formatted(std::cout, 0, false);
-
-  std::cout << "local vector:" << std::endl;
-  local_vector.print(std::cout, 0, false);
-  
-  std::cout << std::endl;
-
-  // output the global matrix and global vector
-  std::cout << "global matrix:" << std::endl;
-  global_matrix.print_formatted(std::cout, 0, false);
-
-  std::cout << "global vector:" << std::endl;
-  global_vector.print(std::cout, 0, false);
+  cell->distribute_local_to_global(local_matrix,
+                                   local_vector,
+                                   global_matrix,
+                                   global_vector);
+
+  // check if each entry of the local matrix/vector has
+  // found its position in the global matrix/vector
+  bool passed = true;
+  for (unsigned int i = 0; i < fe.dofs_per_cell; ++i)
+    {
+      if (global_vector(i) != local_vector(i))
+        passed = false;
+
+      for (unsigned int j = 0; j < fe.dofs_per_cell; ++j)
+        if (global_matrix(i, j) != local_matrix(i, j))
+          {
+            passed = false;
+            break;
+          }
+
+      if (passed == false)
+        break;
+    }
+
+  if (passed)
+    deallog << "PASSED" << std::endl;
+  else
+    deallog << "NOT PASSED" << std::endl;
 
   return 0;
 }
index d005b76f3507e41ed3f1fd2f4e9bb54d5d92056b..126825131cf3f311131e269d9a651f8408b02a5b 100644 (file)
@@ -1,20 +1,2 @@
-local matrix:
- 1  2  3  4 
- 5  6  7  8 
- 9 10 11 12 
-13 14 15 16 
-local vector:
-1 2 3 4 
 
-global matrix:
- 1  2  3  4                
- 5  6  7  8  0  0          
- 9 10 11 12        0  0    
-13 14 15 16  0  0  0  0  0 
-    0     0  0  0          
-    0     0  0  0     0  0 
-       0  0        0  0    
-       0  0     0  0  0  0 
-          0     0     0  0 
-global vector:
-1 2 3 4 0 0 0 0 0
+DEAL::PASSED

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.