From: wolf Date: Thu, 25 Feb 1999 14:03:04 +0000 (+0000) Subject: Add adaptive refinement. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afc1ca72289ae152989a92d7d8beda0b350a22fc;p=dealii-svn.git Add adaptive refinement. git-svn-id: https://svn.dealii.org/trunk@907 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/Attic/examples/nonlinear/fixed-point-iteration/Makefile b/deal.II/deal.II/Attic/examples/nonlinear/fixed-point-iteration/Makefile index 949f8f59f3..1572542e20 100644 --- a/deal.II/deal.II/Attic/examples/nonlinear/fixed-point-iteration/Makefile +++ b/deal.II/deal.II/Attic/examples/nonlinear/fixed-point-iteration/Makefile @@ -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: diff --git a/deal.II/deal.II/Attic/examples/nonlinear/fixed-point-iteration/nonlinear.cc b/deal.II/deal.II/Attic/examples/nonlinear/fixed-point-iteration/nonlinear.cc index 62bec30879..429a101ed6 100644 --- a/deal.II/deal.II/Attic/examples/nonlinear/fixed-point-iteration/nonlinear.cc +++ b/deal.II/deal.II/Attic/examples/nonlinear/fixed-point-iteration/nonlinear.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -33,10 +34,12 @@ class RightHandSide : public Function public: double operator () (const Point &p) const { - double x = 6; + double x = 80; for (unsigned int d=0; d::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; in_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; in_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 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 out; + ofstream gnuplot(filename.c_str()); + fill_data (out); + out.write_gnuplot (gnuplot); + gnuplot.close (); + }; + + last_solution = solution; }; - last_solution = solution; + Vector error_indicator; + KellyErrorEstimator ee; + QSimpson eq; + ee.estimate_error (*dof, eq, fe, boundary, + KellyErrorEstimator::FunctionMap(), + solution, + error_indicator); + tria->refine_and_coarsen_fixed_number (error_indicator, 0.3, 0); + tria->execute_coarsening_and_refinement (); }; + delete dof; delete tria; diff --git a/tests/big-tests/nonlinear/fixed-point-iteration/Makefile b/tests/big-tests/nonlinear/fixed-point-iteration/Makefile index 949f8f59f3..1572542e20 100644 --- a/tests/big-tests/nonlinear/fixed-point-iteration/Makefile +++ b/tests/big-tests/nonlinear/fixed-point-iteration/Makefile @@ -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: diff --git a/tests/big-tests/nonlinear/fixed-point-iteration/nonlinear.cc b/tests/big-tests/nonlinear/fixed-point-iteration/nonlinear.cc index 62bec30879..429a101ed6 100644 --- a/tests/big-tests/nonlinear/fixed-point-iteration/nonlinear.cc +++ b/tests/big-tests/nonlinear/fixed-point-iteration/nonlinear.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -33,10 +34,12 @@ class RightHandSide : public Function public: double operator () (const Point &p) const { - double x = 6; + double x = 80; for (unsigned int d=0; d::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; in_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; in_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 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 out; + ofstream gnuplot(filename.c_str()); + fill_data (out); + out.write_gnuplot (gnuplot); + gnuplot.close (); + }; + + last_solution = solution; }; - last_solution = solution; + Vector error_indicator; + KellyErrorEstimator ee; + QSimpson eq; + ee.estimate_error (*dof, eq, fe, boundary, + KellyErrorEstimator::FunctionMap(), + solution, + error_indicator); + tria->refine_and_coarsen_fixed_number (error_indicator, 0.3, 0); + tria->execute_coarsening_and_refinement (); }; + delete dof; delete tria;