]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
compare different transfer classes
authorkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 30 Apr 2007 20:27:16 +0000 (20:27 +0000)
committerkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 30 Apr 2007 20:27:16 +0000 (20:27 +0000)
git-svn-id: https://svn.dealii.org/trunk@14649 0785d39b-7218-0410-832d-ea1e28bc413d

tests/multigrid/Makefile
tests/multigrid/transfer_compare_01.cc [new file with mode: 0644]
tests/multigrid/transfer_compare_01/cmp/generic [new file with mode: 0644]

index 5210343b40ceac95c6011485f77b7fbcaaf46078..4cbe75348f8b0e30393aecf1ed1bfe2b60bf18c8 100644 (file)
@@ -22,7 +22,7 @@ default: run-tests
 ############################################################
 
 tests_x = cycles dof_* count_* boundary_* renumbering_* \
-       transfer transfer_select transfer_block_select transfer_block \
+       transfer* \
        smoother_block
 
 # from above list of regular expressions, generate the real set of
diff --git a/tests/multigrid/transfer_compare_01.cc b/tests/multigrid/transfer_compare_01.cc
new file mode 100644 (file)
index 0000000..d1b90fb
--- /dev/null
@@ -0,0 +1,215 @@
+//----------------------------------------------------------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2000 - 2007 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------------------------------------------------------
+
+// Compare MGTransferPrebuilt, MGTransferBlock and MGTransferSelect
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+#include <grid/tria.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_renumbering.h>
+#include <dofs/dof_tools.h>
+#include <fe/fe_dgp.h>
+#include <fe/fe_dgq.h>
+#include <fe/fe_q.h>
+#include <fe/fe_raviart_thomas.h>
+#include <fe/fe_system.h>
+#include <multigrid/mg_dof_handler.h>
+#include <multigrid/mg_transfer.h>
+#include <multigrid/mg_transfer_block.h>
+#include <multigrid/mg_tools.h>
+#include <multigrid/mg_level_object.h>
+
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <algorithm>
+
+using namespace std;
+
+template <int dim>
+void check_block(const FiniteElement<dim>& fe)
+{
+  deallog << fe.get_name() << std::endl;
+  std::vector<bool> selected(fe.n_blocks(), true);
+  
+  Triangulation<dim> tr;
+  GridGenerator::hyper_cube(tr);
+  tr.refine_global(2);
+  
+  MGDoFHandler<dim> mgdof(tr);
+  DoFHandler<dim>& dof=mgdof;
+  mgdof.distribute_dofs(fe);
+  
+                                  // Make sure all orderings are the
+                                  // same
+  Point<dim> direction;
+  for (unsigned int d=0;d<dim;++d)
+    direction[d] = d*d*d;
+  DoFRenumbering::downstream(dof, direction);
+  DoFRenumbering::component_wise(dof);
+  for (unsigned int l=0;l<tr.n_levels();++l)
+    {
+      DoFRenumbering::downstream(mgdof, l, direction);
+      DoFRenumbering::component_wise(mgdof, l);
+    }
+
+                                  // Store sizes
+  vector<unsigned int> ndofs(fe.n_blocks());
+  DoFTools::count_dofs_per_block(mgdof, ndofs);
+  std::vector<std::vector<unsigned int> > mg_ndofs(mgdof.get_tria().n_levels());
+  MGTools::count_dofs_per_block(mgdof, mg_ndofs);
+  
+  MGTransferPrebuilt<BlockVector<double> > transfer;
+  MGTransferBlock<double> transfer_block;
+  MGTransferBlockSelect<double> transfer_select;
+  transfer.build_matrices(mgdof);
+  transfer_block.build_matrices(dof, mgdof, selected);
+  transfer_select.build_matrices(dof, mgdof, 0);
+  
+  BlockVector<double> u2(mg_ndofs[2]);
+  BlockVector<double> u1(mg_ndofs[1]);
+  BlockVector<double> u0(mg_ndofs[0]);
+  BlockVector<double> v2(mg_ndofs[2]);
+  BlockVector<double> v1(mg_ndofs[1]);
+  BlockVector<double> v0(mg_ndofs[0]);
+
+                                  // Prolongate a constant function
+                                  // twice
+  u0 = 1;
+  transfer.prolongate(1,u1,u0);
+  transfer.prolongate(2,u2,u1);
+  v0 = 1;
+  transfer_block.prolongate(1,v1,v0);
+  transfer_block.prolongate(2,v2,v1);
+  v0.add(-1., u0);
+  v1.add(-1., u1);
+  v2.add(-1., u2);
+                                  // These outputs are just the
+                                  // number of dofs on each level
+  deallog << "Prolongate " << v0.l2_norm()
+         << ' ' << v1.l2_norm()
+         << ' ' << v2.l2_norm()
+         << std::endl;
+
+  v0 = 1.;
+  transfer_select.prolongate(1,v1.block(0),v0.block(0));
+  transfer_select.prolongate(2,v2.block(0),v1.block(0));
+  v0.add(-1., u0);
+  v1.add(-1., u1);
+  v2.add(-1., u2);
+  deallog << "Select     " << v0.block(0).l2_norm()
+         << ' ' << v1.block(0).l2_norm()
+         << ' ' << v2.block(0).l2_norm()
+         << std::endl;
+  
+  v2 = u2;
+  u1 = 0.;
+  u0 = 0.;
+  transfer.restrict_and_add(2,u1,u2);
+  transfer.restrict_and_add(1,u0,u1);
+  v1 = 0.;
+  v0 = 0.;
+  transfer_block.restrict_and_add(2,v1,v2);
+  transfer_block.restrict_and_add(1,v0,v1);
+  v0.add(-1., u0);
+  v1.add(-1., u1);
+  deallog << "Restrict " << v0.l2_norm()
+         << ' ' << v1.l2_norm()
+         << std::endl;
+
+  v1 = 0.;
+  v0 = 0.;
+  transfer_select.restrict_and_add(2,v1.block(0),v2.block(0));
+  transfer_select.restrict_and_add(1,v0.block(0),v1.block(0));
+  v0.add(-1., u0);
+  v1.add(-1., u1);
+  deallog << "Select   " << v0.block(0).l2_norm()
+         << ' ' << v1.block(0).l2_norm()
+         << std::endl;
+  
+  
+                                  // Check copy to mg and back
+  BlockVector<double> u;
+  u.reinit (ndofs);
+  for (unsigned int i=0;i<u.size();++i)
+    u(i) = i+1;
+
+  std::vector<std::vector<unsigned int> > cached_sizes;
+  MGLevelObject<BlockVector<double> > v;
+  MGLevelObject<BlockVector<double> > w;
+  v.resize(0, tr.n_levels()-1);
+  w.resize(0, tr.n_levels()-1);
+  MGTools::reinit_vector_by_blocks(mgdof, v, selected, cached_sizes);
+  MGTools::reinit_vector_by_blocks(mgdof, w, selected, cached_sizes);
+
+  deallog << "copy to mg";
+  transfer.copy_to_mg(mgdof, v, u);
+  transfer_block.copy_to_mg(mgdof, w, u);
+
+  for (unsigned int l=0; l<tr.n_levels();++l)
+    {
+      w[l].add(-1., v[l]);
+      deallog << ' ' << w[l].l2_norm();
+    }
+  deallog << std::endl << "copy from mg ";
+                                  // Now do the opposite: fill a
+                                  // multigrid vector counting the
+                                  // dofs and see where the numbers go
+  u = 0.;
+  for (unsigned int i=0;i<v[2].size();++i)
+    {
+      v[2](i) = i+1;
+      w[2](i) = i+1;
+    }
+  
+  BlockVector<double> uu;
+  uu.reinit(u);
+  transfer.copy_from_mg_add(mgdof, u, v);
+  transfer_block.copy_from_mg_add(mgdof, uu, v);
+  u.print(std::cout, 0, false);
+  uu.print(std::cout, 0, false);
+  u.add(-1., uu);
+  deallog << u.l2_norm() << std::endl;
+  
+}
+
+
+int main()
+{
+  std::ofstream logfile("transfer_compare_01/output");
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+  
+  std::vector<double> factors;
+
+  FE_DGQ<2> q0(0);
+  FE_DGQ<2> q1(1);
+  FE_Q<2> cq1(1);
+  FE_RaviartThomasNodal<2> rt0(0);
+  FE_RaviartThomasNodal<2> rt1(1);
+  
+  FESystem<2> fe0(rt1, 1, q1, 1);
+  FESystem<2> fe1(rt0, 2, q0, 2);
+
+  check_block(q0);
+  check_block(cq1);
+  check_block(rt1);
+  
+  check_block(fe0);
+  check_block(fe1);
+}
diff --git a/tests/multigrid/transfer_compare_01/cmp/generic b/tests/multigrid/transfer_compare_01/cmp/generic
new file mode 100644 (file)
index 0000000..b08f070
--- /dev/null
@@ -0,0 +1,56 @@
+
+DEAL::All
+DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(1)-FE_DGQ<2>(1)]
+DEAL::selected  0 1
+DEAL::Global  dofs: 144 64
+DEAL::Level 0 dofs: 12 4
+DEAL::Level 1 dofs: 40 16
+DEAL::Level 2 dofs: 144 64
+DEAL::u0       12      4
+DEAL::u1       40      16
+DEAL::u2       144     64
+DEAL::u1       572     256
+DEAL::u0       2214    1024
+DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
+DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
+DEAL::Velocity
+DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(1)-FE_DGQ<2>(1)]
+DEAL::selected  0
+DEAL::Global  dofs: 144 64
+DEAL::Level 0 dofs: 12 4
+DEAL::Level 1 dofs: 40 16
+DEAL::Level 2 dofs: 144 64
+DEAL::u0       12      4
+DEAL::u1       40      0
+DEAL::u2       144     0
+DEAL::u1       572     0
+DEAL::u0       2214    0
+DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
+DEAL:: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 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 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 0 0 0 0 0 0
+DEAL::Pressure
+DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(1)-FE_DGQ<2>(1)]
+DEAL::selected  1
+DEAL::Global  dofs: 144 64
+DEAL::Level 0 dofs: 12 4
+DEAL::Level 1 dofs: 40 16
+DEAL::Level 2 dofs: 144 64
+DEAL::u0       12      4
+DEAL::u1       0       16
+DEAL::u2       0       64
+DEAL::u1       0       256
+DEAL::u0       0       1024
+DEAL:: 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
+DEAL:: 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 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 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 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 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 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
+DEAL::FESystem<2>[FE_RaviartThomasNodal<2>(0)^2-FE_DGQ<2>(0)^2]
+DEAL::selected  1 3
+DEAL::Global  dofs: 40 40 16 16
+DEAL::Level 0 dofs: 4 4 1 1
+DEAL::Level 1 dofs: 12 12 4 4
+DEAL::Level 2 dofs: 40 40 16 16
+DEAL::u0       4       4       1       1
+DEAL::u1       0       12      0       4
+DEAL::u2       0       40      0       16
+DEAL::u1       0       136     0       64
+DEAL::u0       0       400     0       256
+DEAL:: 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
+DEAL:: 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 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

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.