]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add adaptive refinement.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 25 Feb 1999 14:03:04 +0000 (14:03 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 25 Feb 1999 14:03:04 +0000 (14:03 +0000)
git-svn-id: https://svn.dealii.org/trunk@907 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/Attic/examples/nonlinear/fixed-point-iteration/Makefile
deal.II/deal.II/Attic/examples/nonlinear/fixed-point-iteration/nonlinear.cc
tests/big-tests/nonlinear/fixed-point-iteration/Makefile
tests/big-tests/nonlinear/fixed-point-iteration/nonlinear.cc

index 949f8f59f34c434166bc5f711ebe342c13f170eb..1572542e202f721afa56078c522bef8db73291a7 100644 (file)
@@ -11,7 +11,7 @@ target   = nonlinear
 # the archives ./Obj.a and ./Obj.g.a. By default, the debug version
 # is used to link. It you don't like that, change the following
 # variable to "off"
-debug-mode = on
+debug-mode = off
 
 # If you want your program to be linked with extra object or library
 # files, specify them here:
index 62bec3087965aff14880af4faa703d6f20a98789..429a101ed660412154181c91302d4a658726b3b6 100644 (file)
@@ -17,6 +17,7 @@
 #include <base/quadrature_lib.h>
 #include <numerics/base.h>
 #include <numerics/assembler.h>
+#include <numerics/error_estimator.h>
 
 #include <map>
 #include <fstream>
@@ -33,10 +34,12 @@ class RightHandSide :  public Function<dim>
   public:
     double operator () (const Point<dim> &p) const 
       {
-       double x = 6;
+       double x = 80;
        for (unsigned int d=0; d<dim; ++d)
          if (p(d) < 0.5)
-           x *= -1;
+           x *= -p(d);
+         else
+           x *= (1-p(d));
        
        return x;
       };
@@ -170,52 +173,69 @@ void NonlinearProblem<dim>::run () {
   dirichlet_bc[0] = &boundary_values;
 
 
-  cout << "    Making grid... ";
   tria->create_hypercube ();
-  tria->refine_global (6);
-  cout << tria->n_active_cells() << " active cells." << endl;
-  
-  cout << "    Distributing dofs... "; 
-  dof->distribute_dofs (fe);
-  cout << dof->n_dofs() << " degrees of freedom." << endl;
-
-                                  // set the starting values for the iteration
-                                  // to a constant value of 1
-  last_solution.reinit (dof->n_dofs());
-  for (unsigned int i=0; i<dof->n_dofs(); ++i)
-    last_solution(i) = 1;
-  
+  tria->refine_global (4);
 
-                                  // here comes the fixed point iteration
-  for (unsigned int nonlinear_step=0; nonlinear_step<40; ++nonlinear_step)
+  for (unsigned int refinement_step=0; refinement_step<10; ++refinement_step)
     {
-      cout << "    Nonlinear step " << nonlinear_step << endl;
-      cout << "        Assembling matrices..." << endl;
-      assemble (equation, quadrature, fe,
-               UpdateFlags(update_gradients | update_JxW_values |
-                           update_q_points),
-               dirichlet_bc, boundary);
-
-      cout << "        Solving..." << endl;
-      solve ();
+      cout << "Refinement step " << refinement_step << endl
+          << "  Grid has " << tria->n_active_cells() << " active cells." << endl;
+  
+      cout << "    Distributing dofs... "; 
+      dof->distribute_dofs (fe);
+      cout << dof->n_dofs() << " degrees of freedom." << endl;
+      
+                                      // set the starting values for the iteration
+                                      // to a constant value of 1
+      last_solution.reinit (dof->n_dofs());
+      for (unsigned int i=0; i<dof->n_dofs(); ++i)
+       last_solution(i) = 1;
+  
 
-      if (nonlinear_step % 4 == 0)
+                                      // here comes the fixed point iteration
+      for (unsigned int nonlinear_step=0; nonlinear_step<10; ++nonlinear_step)
        {
-         string filename = "nonlinear.";
-         filename += ('0' + (nonlinear_step/4));
-         filename += ".gnuplot";
-         cout << "        Writing to file <" << filename << ">..." << endl;
+         cout << "    Nonlinear step " << nonlinear_step << endl;
+         cout << "        Assembling matrices..." << endl;
+         assemble (equation, quadrature, fe,
+                   UpdateFlags(update_gradients | update_JxW_values |
+                               update_q_points),
+                   dirichlet_bc, boundary);
+         
+         cout << "        Solving..." << endl;
+         solve ();
          
-         DataOut<dim> out;
-         ofstream gnuplot(filename.c_str());
-         fill_data (out);
-         out.write_gnuplot (gnuplot);
-         gnuplot.close ();
+         if (nonlinear_step % 2 == 0)
+           {
+             string filename = "nonlinear.";
+             filename += ('0' + refinement_step);
+             filename += '.';
+             filename += ('0' + (nonlinear_step/2));
+             filename += ".gnuplot";
+             cout << "        Writing to file <" << filename << ">..." << endl;
+             
+             DataOut<dim> out;
+             ofstream gnuplot(filename.c_str());
+             fill_data (out);
+             out.write_gnuplot (gnuplot);
+             gnuplot.close ();
+           };
+         
+         last_solution = solution;
        };
 
-      last_solution = solution;
+      Vector<float> error_indicator;
+      KellyErrorEstimator<dim> ee;
+      QSimpson<dim-1> eq;
+      ee.estimate_error (*dof, eq, fe, boundary,
+                        KellyErrorEstimator<dim>::FunctionMap(),
+                        solution,
+                        error_indicator);
+      tria->refine_and_coarsen_fixed_number (error_indicator, 0.3, 0);
+      tria->execute_coarsening_and_refinement ();
     };
   
+  
   delete dof;
   delete tria;
   
index 949f8f59f34c434166bc5f711ebe342c13f170eb..1572542e202f721afa56078c522bef8db73291a7 100644 (file)
@@ -11,7 +11,7 @@ target   = nonlinear
 # the archives ./Obj.a and ./Obj.g.a. By default, the debug version
 # is used to link. It you don't like that, change the following
 # variable to "off"
-debug-mode = on
+debug-mode = off
 
 # If you want your program to be linked with extra object or library
 # files, specify them here:
index 62bec3087965aff14880af4faa703d6f20a98789..429a101ed660412154181c91302d4a658726b3b6 100644 (file)
@@ -17,6 +17,7 @@
 #include <base/quadrature_lib.h>
 #include <numerics/base.h>
 #include <numerics/assembler.h>
+#include <numerics/error_estimator.h>
 
 #include <map>
 #include <fstream>
@@ -33,10 +34,12 @@ class RightHandSide :  public Function<dim>
   public:
     double operator () (const Point<dim> &p) const 
       {
-       double x = 6;
+       double x = 80;
        for (unsigned int d=0; d<dim; ++d)
          if (p(d) < 0.5)
-           x *= -1;
+           x *= -p(d);
+         else
+           x *= (1-p(d));
        
        return x;
       };
@@ -170,52 +173,69 @@ void NonlinearProblem<dim>::run () {
   dirichlet_bc[0] = &boundary_values;
 
 
-  cout << "    Making grid... ";
   tria->create_hypercube ();
-  tria->refine_global (6);
-  cout << tria->n_active_cells() << " active cells." << endl;
-  
-  cout << "    Distributing dofs... "; 
-  dof->distribute_dofs (fe);
-  cout << dof->n_dofs() << " degrees of freedom." << endl;
-
-                                  // set the starting values for the iteration
-                                  // to a constant value of 1
-  last_solution.reinit (dof->n_dofs());
-  for (unsigned int i=0; i<dof->n_dofs(); ++i)
-    last_solution(i) = 1;
-  
+  tria->refine_global (4);
 
-                                  // here comes the fixed point iteration
-  for (unsigned int nonlinear_step=0; nonlinear_step<40; ++nonlinear_step)
+  for (unsigned int refinement_step=0; refinement_step<10; ++refinement_step)
     {
-      cout << "    Nonlinear step " << nonlinear_step << endl;
-      cout << "        Assembling matrices..." << endl;
-      assemble (equation, quadrature, fe,
-               UpdateFlags(update_gradients | update_JxW_values |
-                           update_q_points),
-               dirichlet_bc, boundary);
-
-      cout << "        Solving..." << endl;
-      solve ();
+      cout << "Refinement step " << refinement_step << endl
+          << "  Grid has " << tria->n_active_cells() << " active cells." << endl;
+  
+      cout << "    Distributing dofs... "; 
+      dof->distribute_dofs (fe);
+      cout << dof->n_dofs() << " degrees of freedom." << endl;
+      
+                                      // set the starting values for the iteration
+                                      // to a constant value of 1
+      last_solution.reinit (dof->n_dofs());
+      for (unsigned int i=0; i<dof->n_dofs(); ++i)
+       last_solution(i) = 1;
+  
 
-      if (nonlinear_step % 4 == 0)
+                                      // here comes the fixed point iteration
+      for (unsigned int nonlinear_step=0; nonlinear_step<10; ++nonlinear_step)
        {
-         string filename = "nonlinear.";
-         filename += ('0' + (nonlinear_step/4));
-         filename += ".gnuplot";
-         cout << "        Writing to file <" << filename << ">..." << endl;
+         cout << "    Nonlinear step " << nonlinear_step << endl;
+         cout << "        Assembling matrices..." << endl;
+         assemble (equation, quadrature, fe,
+                   UpdateFlags(update_gradients | update_JxW_values |
+                               update_q_points),
+                   dirichlet_bc, boundary);
+         
+         cout << "        Solving..." << endl;
+         solve ();
          
-         DataOut<dim> out;
-         ofstream gnuplot(filename.c_str());
-         fill_data (out);
-         out.write_gnuplot (gnuplot);
-         gnuplot.close ();
+         if (nonlinear_step % 2 == 0)
+           {
+             string filename = "nonlinear.";
+             filename += ('0' + refinement_step);
+             filename += '.';
+             filename += ('0' + (nonlinear_step/2));
+             filename += ".gnuplot";
+             cout << "        Writing to file <" << filename << ">..." << endl;
+             
+             DataOut<dim> out;
+             ofstream gnuplot(filename.c_str());
+             fill_data (out);
+             out.write_gnuplot (gnuplot);
+             gnuplot.close ();
+           };
+         
+         last_solution = solution;
        };
 
-      last_solution = solution;
+      Vector<float> error_indicator;
+      KellyErrorEstimator<dim> ee;
+      QSimpson<dim-1> eq;
+      ee.estimate_error (*dof, eq, fe, boundary,
+                        KellyErrorEstimator<dim>::FunctionMap(),
+                        solution,
+                        error_indicator);
+      tria->refine_and_coarsen_fixed_number (error_indicator, 0.3, 0);
+      tria->execute_coarsening_and_refinement ();
     };
   
+  
   delete dof;
   delete tria;
   

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.