]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add another, now real hp, testcase
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 28 Jul 2006 23:45:55 +0000 (23:45 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 28 Jul 2006 23:45:55 +0000 (23:45 +0000)
git-svn-id: https://svn.dealii.org/trunk@13486 0785d39b-7218-0410-832d-ea1e28bc413d

tests/hp/step-3a.cc [new file with mode: 0644]
tests/hp/step-3a/cmp/generic [new file with mode: 0644]

diff --git a/tests/hp/step-3a.cc b/tests/hp/step-3a.cc
new file mode 100644 (file)
index 0000000..3540cea
--- /dev/null
@@ -0,0 +1,279 @@
+//----------------------------  step-3a.cc  ---------------------------
+//    $Id: step-3a.cc 13000 2006-05-02 23:16:07Z wolf $
+//    Version: $Name$ 
+//
+//    Copyright (C) 2005, 2006 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.
+//
+//----------------------------  step-3a.cc  ---------------------------
+
+
+// a variant of the hp-ified version of step-3a where we assign
+// different fe_indices in a symmetric way. the solution should be
+// symmetric as well, and in fact is
+
+
+#include <base/logstream.h>
+#include <grid/tria.h>
+#include <dofs/dof_handler.h>
+#include <dofs/dof_constraints.h>
+#include <grid/grid_generator.h>
+
+#include <grid/tria_accessor.h>
+#include <grid/tria_iterator.h>
+#include <dofs/dof_accessor.h>
+
+#include <fe/fe_q.h>
+
+#include <dofs/dof_tools.h>
+
+#include <fe/hp_fe_values.h>
+#include <base/quadrature_lib.h>
+
+#include <base/function.h>
+#include <numerics/vectors.h>
+#include <numerics/matrices.h>
+
+#include <lac/vector.h>
+#include <lac/full_matrix.h>
+#include <lac/sparse_matrix.h>
+#include <lac/solver_cg.h>
+#include <lac/precondition.h>
+
+#include <numerics/data_out.h>
+#include <fstream>
+#include <iostream>
+
+std::ofstream logfile("step-3a/output");
+
+
+
+class LaplaceProblem 
+{
+  public:
+    LaplaceProblem ();
+
+    void run ();
+    
+  private:
+    void make_grid_and_dofs ();
+    void assemble_system ();
+    void solve ();
+    void output_results () const;
+
+    Triangulation<2>     triangulation;
+    hp::FECollection<2>              fe;
+    hp::DoFHandler<2>        dof_handler;
+
+    SparsityPattern      sparsity_pattern;
+    SparseMatrix<double> system_matrix;
+
+                                    // Although we do not have h-refinement,
+                                    // hanging nodes will inevitably appear
+                                    // due to different polynomial degrees.
+    ConstraintMatrix     hanging_node_constraints;
+    
+    Vector<double>       solution;
+    Vector<double>       system_rhs;
+};
+
+
+LaplaceProblem::LaplaceProblem () :
+               dof_handler (triangulation)
+{}
+
+
+
+void LaplaceProblem::make_grid_and_dofs ()
+{
+  GridGenerator::hyper_cube (triangulation, -1, 1);
+  triangulation.refine_global (2);
+  deallog << "Number of active cells: "
+         << triangulation.n_active_cells()
+         << std::endl;
+  deallog << "Total number of cells: "
+         << triangulation.n_cells()
+         << std::endl;
+
+  hp::DoFHandler<2>::active_cell_iterator cell = dof_handler.begin_active (),
+                                         endc = dof_handler.end ();
+  
+  unsigned int cell_no = 0;
+  for (; cell != endc; ++cell)
+    {
+      if (cell_no < triangulation.n_active_cells () / 2)
+       cell->set_active_fe_index (1);
+      else
+       cell->set_active_fe_index (0);
+      deallog << "Cell " << cell << " has fe_index=" << cell->active_fe_index()
+             << std::endl;
+      ++cell_no;
+    }  
+      
+  dof_handler.distribute_dofs (fe);
+  deallog << "Number of degrees of freedom: "
+         << dof_handler.n_dofs()
+         << std::endl;
+
+  solution.reinit (dof_handler.n_dofs());
+  system_rhs.reinit (dof_handler.n_dofs());
+
+                                  // Create sparsity pattern.  
+  sparsity_pattern.reinit (dof_handler.n_dofs(),
+                          dof_handler.n_dofs(),
+                          dof_handler.max_couplings_between_dofs());
+  DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern);
+
+                                  // Create constraints which stem from
+                                  // the different polynomial degrees on
+                                  // the different elements.
+  hanging_node_constraints.clear ();
+  DoFTools::make_hanging_node_constraints (dof_handler,
+                                          hanging_node_constraints);
+
+  hanging_node_constraints.print (deallog.get_file_stream());
+
+  hanging_node_constraints.close ();
+  hanging_node_constraints.condense (sparsity_pattern);
+  
+  sparsity_pattern.compress();
+  system_matrix.reinit (sparsity_pattern);
+}
+
+
+
+void LaplaceProblem::assemble_system () 
+{
+  hp::QCollection<2>  quadrature_formula(QGauss<2>(6));
+  hp::FEValues<2> x_fe_values (fe, quadrature_formula, 
+                              update_values | update_gradients | update_JxW_values);
+  
+  const unsigned int   max_dofs_per_cell = fe.max_dofs_per_cell ();
+  const unsigned int   n_q_points    = quadrature_formula[0].n_quadrature_points;
+
+  FullMatrix<double>   cell_matrix (max_dofs_per_cell, max_dofs_per_cell);
+  Vector<double>       cell_rhs (max_dofs_per_cell);
+
+  std::vector<unsigned int> local_dof_indices (max_dofs_per_cell);
+
+  hp::DoFHandler<2>::active_cell_iterator
+    cell = dof_handler.begin_active(),
+    endc = dof_handler.end();
+  for (; cell!=endc; ++cell)
+    {
+      x_fe_values.reinit (cell);
+
+      const FEValues<2> &fe_values = x_fe_values.get_present_fe_values();
+      
+      cell_matrix = 0;
+      cell_rhs = 0;
+
+      const unsigned int dofs_per_cell = cell->get_fe ().dofs_per_cell;
+      
+      for (unsigned int i=0; i<dofs_per_cell; ++i)
+       for (unsigned int j=0; j<dofs_per_cell; ++j)
+         for (unsigned int q_point=0; q_point<n_q_points; ++q_point)
+           cell_matrix(i,j) += (fe_values.shape_grad (i, q_point) *
+                                fe_values.shape_grad (j, q_point) *
+                                fe_values.JxW (q_point));
+
+      for (unsigned int i=0; i<dofs_per_cell; ++i)
+       for (unsigned int q_point=0; q_point<n_q_points; ++q_point)
+         cell_rhs(i) += (fe_values.shape_value (i, q_point) *
+                         1 *
+                         fe_values.JxW (q_point));
+
+      local_dof_indices.resize (dofs_per_cell);
+      cell->get_dof_indices (local_dof_indices);
+
+      for (unsigned int i=0; i<dofs_per_cell; ++i)
+       for (unsigned int j=0; j<dofs_per_cell; ++j)
+         system_matrix.add (local_dof_indices[i],
+                            local_dof_indices[j],
+                            cell_matrix(i,j));
+
+      for (unsigned int i=0; i<dofs_per_cell; ++i)
+       system_rhs(local_dof_indices[i]) += cell_rhs(i);
+    }
+
+                                  // Include hanging nodes.
+  hanging_node_constraints.condense (system_matrix);
+  hanging_node_constraints.condense (system_rhs);
+  
+  std::map<unsigned int,double> boundary_values;
+  VectorTools::interpolate_boundary_values (dof_handler,
+                                           0,
+                                           ZeroFunction<2>(),
+                                           boundary_values);
+  MatrixTools::apply_boundary_values (boundary_values,
+                                     system_matrix,
+                                     solution,
+                                     system_rhs);
+}
+
+
+
+void LaplaceProblem::solve () 
+{
+  SolverControl           solver_control (1000, 1e-12);
+  SolverCG<>              cg (solver_control);
+
+  cg.solve (system_matrix, solution, system_rhs,
+           PreconditionIdentity());
+
+  solution.print (deallog.get_file_stream());
+  
+  hanging_node_constraints.distribute (solution);
+}
+
+
+
+void LaplaceProblem::output_results () const
+{
+  DataOut<2,hp::DoFHandler<2> > data_out;
+  data_out.attach_dof_handler (dof_handler);
+  data_out.add_data_vector (solution, "solution");
+  data_out.build_patches ();
+
+  data_out.write_gnuplot (deallog.get_file_stream());
+}
+
+
+
+void LaplaceProblem::run () 
+{
+  FE_Q<2> fe_1 (1),
+    fe_2 (2),
+    fe_3 (3),
+    fe_4 (4);
+
+  fe.push_back (fe_1);
+  fe.push_back (fe_2);
+  fe.push_back (fe_3);
+  fe.push_back (fe_4);
+
+  make_grid_and_dofs ();
+  assemble_system ();
+  solve ();
+  output_results ();
+}
+
+
+
+int main () 
+{
+  logfile.precision(6);
+  
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);  
+
+  LaplaceProblem laplace_problem;
+  laplace_problem.run ();
+
+  return 0;
+}
diff --git a/tests/hp/step-3a/cmp/generic b/tests/hp/step-3a/cmp/generic
new file mode 100644 (file)
index 0000000..6429376
--- /dev/null
@@ -0,0 +1,150 @@
+
+DEAL::Number of active cells: 16
+DEAL::Total number of cells: 21
+DEAL::Cell 2.0 has fe_index=1
+DEAL::Cell 2.1 has fe_index=1
+DEAL::Cell 2.2 has fe_index=1
+DEAL::Cell 2.3 has fe_index=1
+DEAL::Cell 2.4 has fe_index=1
+DEAL::Cell 2.5 has fe_index=1
+DEAL::Cell 2.6 has fe_index=1
+DEAL::Cell 2.7 has fe_index=1
+DEAL::Cell 2.8 has fe_index=0
+DEAL::Cell 2.9 has fe_index=0
+DEAL::Cell 2.10 has fe_index=0
+DEAL::Cell 2.11 has fe_index=0
+DEAL::Cell 2.12 has fe_index=0
+DEAL::Cell 2.13 has fe_index=0
+DEAL::Cell 2.14 has fe_index=0
+DEAL::Cell 2.15 has fe_index=0
+DEAL::Number of degrees of freedom: 55
+    17 40:  0.500000
+    17 41:  0.500000
+    20 41:  0.500000
+    20 44:  0.500000
+    35 44:  0.500000
+    35 49:  0.500000
+    38 49:  0.500000
+    38 51:  0.500000
+DEAL:cg::Starting value 0.634648
+DEAL:cg::Convergence step 16 value 0
+0.000e+00 0.000e+00 0.000e+00 1.814e-01 0.000e+00 1.122e-01 0.000e+00 1.109e-01 7.270e-02 0.000e+00 2.303e-01 1.395e-01 0.000e+00 2.170e-01 1.331e-01 0.000e+00 2.157e-01 0.000e+00 1.299e-01 2.790e-01 0.000e+00 2.646e-01 0.000e+00 1.814e-01 1.122e-01 0.000e+00 2.170e-01 1.331e-01 0.000e+00 0.000e+00 0.000e+00 0.000e+00 1.109e-01 7.270e-02 2.157e-01 0.000e+00 2.646e-01 0.000e+00 0.000e+00 1.299e-01 0.000e+00 2.421e-01 0.000e+00 1.926e-01 3.080e-01 2.409e-01 0.000e+00 0.000e+00 0.000e+00 2.421e-01 1.926e-01 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
+# This file was generated by the deal.II library.
+
+
+#
+# For a description of the GNUPLOT format see the GNUPLOT manual.
+#
+# <x> <y> <solution> 
+-1.00000 -1.00000 0.00000 
+-0.500000 -1.00000 0.00000 
+
+-1.00000 -0.500000 0.00000 
+-0.500000 -0.500000 0.181364 
+
+
+-0.500000 -1.00000 0.00000 
+0.00000 -1.00000 0.00000 
+
+-0.500000 -0.500000 0.181364 
+0.00000 -0.500000 0.230304 
+
+
+-1.00000 -0.500000 0.00000 
+-0.500000 -0.500000 0.181364 
+
+-1.00000 0.00000 0.00000 
+-0.500000 0.00000 0.242082 
+
+
+-0.500000 -0.500000 0.181364 
+0.00000 -0.500000 0.230304 
+
+-0.500000 0.00000 0.242082 
+0.00000 0.00000 0.307982 
+
+
+0.00000 -1.00000 0.00000 
+0.500000 -1.00000 0.00000 
+
+0.00000 -0.500000 0.230304 
+0.500000 -0.500000 0.181364 
+
+
+0.500000 -1.00000 0.00000 
+1.00000 -1.00000 0.00000 
+
+0.500000 -0.500000 0.181364 
+1.00000 -0.500000 0.00000 
+
+
+0.00000 -0.500000 0.230304 
+0.500000 -0.500000 0.181364 
+
+0.00000 0.00000 0.307982 
+0.500000 0.00000 0.242082 
+
+
+0.500000 -0.500000 0.181364 
+1.00000 -0.500000 0.00000 
+
+0.500000 0.00000 0.242082 
+1.00000 0.00000 0.00000 
+
+
+-1.00000 0.00000 0.00000 
+-0.500000 0.00000 0.242082 
+
+-1.00000 0.500000 0.00000 
+-0.500000 0.500000 0.192624 
+
+
+-0.500000 0.00000 0.242082 
+0.00000 0.00000 0.307982 
+
+-0.500000 0.500000 0.192624 
+0.00000 0.500000 0.240924 
+
+
+-1.00000 0.500000 0.00000 
+-0.500000 0.500000 0.192624 
+
+-1.00000 1.00000 0.00000 
+-0.500000 1.00000 0.00000 
+
+
+-0.500000 0.500000 0.192624 
+0.00000 0.500000 0.240924 
+
+-0.500000 1.00000 0.00000 
+0.00000 1.00000 0.00000 
+
+
+0.00000 0.00000 0.307982 
+0.500000 0.00000 0.242082 
+
+0.00000 0.500000 0.240924 
+0.500000 0.500000 0.192624 
+
+
+0.500000 0.00000 0.242082 
+1.00000 0.00000 0.00000 
+
+0.500000 0.500000 0.192624 
+1.00000 0.500000 0.00000 
+
+
+0.00000 0.500000 0.240924 
+0.500000 0.500000 0.192624 
+
+0.00000 1.00000 0.00000 
+0.500000 1.00000 0.00000 
+
+
+0.500000 0.500000 0.192624 
+1.00000 0.500000 0.00000 
+
+0.500000 1.00000 0.00000 
+1.00000 1.00000 0.00000 
+
+

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.