From: Wolfgang Bangerth Date: Wed, 8 Apr 1998 13:46:39 +0000 (+0000) Subject: Perfectionize test case, including more reported numbers. X-Git-Tag: v8.0.0~23093 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2db5258dd6ae8d096ba05bf622456cb342992dbe;p=dealii.git Perfectionize test case, including more reported numbers. git-svn-id: https://svn.dealii.org/trunk@161 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/Attic/examples/convergence/convergence.cc b/deal.II/deal.II/Attic/examples/convergence/convergence.cc index 331afc5baf..5b17341eb4 100644 --- a/deal.II/deal.II/Attic/examples/convergence/convergence.cc +++ b/deal.II/deal.II/Attic/examples/convergence/convergence.cc @@ -58,8 +58,9 @@ class PoissonProblem : public ProblemBase { PoissonProblem (); void clear (); - virtual void create_new (); - virtual void run (unsigned int level); + void create_new (); + void run (unsigned int level); + void print_history () const; protected: Triangulation *tria; @@ -67,6 +68,9 @@ class PoissonProblem : public ProblemBase { Function *rhs; Function *boundary_values; + + vector l1_error, l2_error, linfty_error, h1_seminorm_error, h1_error; + vector n_dofs; }; @@ -97,30 +101,32 @@ class Solution : public Function { * at the given point. */ virtual double operator () (const Point &p) const; + /** + * Return the gradient of the function + * at the given point. + */ + virtual Point gradient (const Point &p) const; }; -template -double RHSPoly::operator () (const Point &p) const { - double ret_val = 0; - for (unsigned int i=0; i::operator () (const Point<2> &p) const { + return 2*(p(0)*(1-p(0)) + p(1)*(1-p(1))); }; -template -double Solution::operator () (const Point &p) const { - double ret_val = 1; - for (unsigned int i=0; i::operator () (const Point<2> &p) const { + return p(0)*(1-p(0))*p(1)*(1-p(1)); }; +Point<2> Solution<2>::gradient (const Point<2> &p) const { + return Point<2> ((1-2*p(0))*p(1)*(1-p(1)), (1-2*p(1))*p(0)*(1-p(0))); +}; + @@ -242,6 +248,7 @@ void PoissonProblem::run (const unsigned int level) { cout << " Distributing dofs... "; dof->distribute_dofs (fe); cout << dof->n_dofs() << " degrees of freedom." << endl; + n_dofs.push_back (dof->n_dofs()); cout << " Assembling matrices..." << endl; FEValues::UpdateStruct update_flags; @@ -257,24 +264,41 @@ void PoissonProblem::run (const unsigned int level) { Solution sol; dVector l1_error_per_cell, l2_error_per_cell, linfty_error_per_cell; - QGauss4 q; + dVector h1_seminorm_error_per_cell, h1_error_per_cell; + QGauss3 q; cout << " Calculating L1 error... "; integrate_difference (sol, l1_error_per_cell, q, fe, L1_norm); cout << l1_error_per_cell.l1_norm() << endl; + l1_error.push_back (l1_error_per_cell.l1_norm()); cout << " Calculating L2 error... "; integrate_difference (sol, l2_error_per_cell, q, fe, L2_norm); cout << l2_error_per_cell.l2_norm() << endl; + l2_error.push_back (l2_error_per_cell.l2_norm()); cout << " Calculating L-infinity error... "; integrate_difference (sol, linfty_error_per_cell, q, fe, Linfty_norm); cout << linfty_error_per_cell.linfty_norm() << endl; + linfty_error.push_back (linfty_error_per_cell.linfty_norm()); + + cout << " Calculating H1-seminorm error... "; + integrate_difference (sol, h1_seminorm_error_per_cell, q, fe, H1_seminorm); + cout << h1_seminorm_error_per_cell.l2_norm() << endl; + h1_seminorm_error.push_back (h1_seminorm_error_per_cell.l2_norm()); + + cout << " Calculating H1 error... "; + integrate_difference (sol, h1_error_per_cell, q, fe, H1_norm); + cout << h1_error_per_cell.l2_norm() << endl; + h1_error.push_back (h1_error_per_cell.l2_norm()); dVector l1_error_per_dof, l2_error_per_dof, linfty_error_per_dof; + dVector h1_seminorm_error_per_dof, h1_error_per_dof; dof->distribute_cell_to_dof_vector (l1_error_per_cell, l1_error_per_dof); dof->distribute_cell_to_dof_vector (l2_error_per_cell, l2_error_per_dof); dof->distribute_cell_to_dof_vector (linfty_error_per_cell, linfty_error_per_dof); + dof->distribute_cell_to_dof_vector (h1_seminorm_error_per_cell, h1_seminorm_error_per_dof); + dof->distribute_cell_to_dof_vector (h1_error_per_cell, h1_error_per_dof); string filename = "gnuplot."; filename += ('0'+level); @@ -285,7 +309,9 @@ void PoissonProblem::run (const unsigned int level) { fill_data (out); out.add_data_vector (l1_error_per_dof, "L1-Error"); out.add_data_vector (l2_error_per_dof, "L2-Error"); - out.add_data_vector (linfty_error_per_dof, "L3-Error"); + out.add_data_vector (linfty_error_per_dof, "Linfty-Error"); + out.add_data_vector (h1_seminorm_error_per_dof, "H1-seminorm-Error"); + out.add_data_vector (h1_error_per_dof, "H1-Error"); out.write_gnuplot (gnuplot); gnuplot.close (); @@ -293,14 +319,59 @@ void PoissonProblem::run (const unsigned int level) { }; +template +void PoissonProblem::print_history () const { + ofstream out("gnuplot.history"); + out << "# n_dofs l1_error l2_error linfty_error h1_seminorm_error h1_error" + << endl; + for (unsigned int i=0; ih/2:" << endl; + cout << " L1 error : " << 1./average_l1 << endl + << " L2 error : " << 1./average_l2 << endl + << " Linfty error : " << 1./average_linfty << endl + << " H1 seminorm error: " << 1./average_h1_semi << endl + << " H1 error : " << 1./average_h1 << endl; +}; + int main () { PoissonProblem<2> problem; - for (unsigned int level=1; level<5; ++level) + for (unsigned int level=1; level<8; ++level) problem.run (level); + cout << endl << "Printing convergence history to ..." << endl; + problem.print_history (); + return 0; }; diff --git a/tests/big-tests/convergence/convergence.cc b/tests/big-tests/convergence/convergence.cc index 331afc5baf..5b17341eb4 100644 --- a/tests/big-tests/convergence/convergence.cc +++ b/tests/big-tests/convergence/convergence.cc @@ -58,8 +58,9 @@ class PoissonProblem : public ProblemBase { PoissonProblem (); void clear (); - virtual void create_new (); - virtual void run (unsigned int level); + void create_new (); + void run (unsigned int level); + void print_history () const; protected: Triangulation *tria; @@ -67,6 +68,9 @@ class PoissonProblem : public ProblemBase { Function *rhs; Function *boundary_values; + + vector l1_error, l2_error, linfty_error, h1_seminorm_error, h1_error; + vector n_dofs; }; @@ -97,30 +101,32 @@ class Solution : public Function { * at the given point. */ virtual double operator () (const Point &p) const; + /** + * Return the gradient of the function + * at the given point. + */ + virtual Point gradient (const Point &p) const; }; -template -double RHSPoly::operator () (const Point &p) const { - double ret_val = 0; - for (unsigned int i=0; i::operator () (const Point<2> &p) const { + return 2*(p(0)*(1-p(0)) + p(1)*(1-p(1))); }; -template -double Solution::operator () (const Point &p) const { - double ret_val = 1; - for (unsigned int i=0; i::operator () (const Point<2> &p) const { + return p(0)*(1-p(0))*p(1)*(1-p(1)); }; +Point<2> Solution<2>::gradient (const Point<2> &p) const { + return Point<2> ((1-2*p(0))*p(1)*(1-p(1)), (1-2*p(1))*p(0)*(1-p(0))); +}; + @@ -242,6 +248,7 @@ void PoissonProblem::run (const unsigned int level) { cout << " Distributing dofs... "; dof->distribute_dofs (fe); cout << dof->n_dofs() << " degrees of freedom." << endl; + n_dofs.push_back (dof->n_dofs()); cout << " Assembling matrices..." << endl; FEValues::UpdateStruct update_flags; @@ -257,24 +264,41 @@ void PoissonProblem::run (const unsigned int level) { Solution sol; dVector l1_error_per_cell, l2_error_per_cell, linfty_error_per_cell; - QGauss4 q; + dVector h1_seminorm_error_per_cell, h1_error_per_cell; + QGauss3 q; cout << " Calculating L1 error... "; integrate_difference (sol, l1_error_per_cell, q, fe, L1_norm); cout << l1_error_per_cell.l1_norm() << endl; + l1_error.push_back (l1_error_per_cell.l1_norm()); cout << " Calculating L2 error... "; integrate_difference (sol, l2_error_per_cell, q, fe, L2_norm); cout << l2_error_per_cell.l2_norm() << endl; + l2_error.push_back (l2_error_per_cell.l2_norm()); cout << " Calculating L-infinity error... "; integrate_difference (sol, linfty_error_per_cell, q, fe, Linfty_norm); cout << linfty_error_per_cell.linfty_norm() << endl; + linfty_error.push_back (linfty_error_per_cell.linfty_norm()); + + cout << " Calculating H1-seminorm error... "; + integrate_difference (sol, h1_seminorm_error_per_cell, q, fe, H1_seminorm); + cout << h1_seminorm_error_per_cell.l2_norm() << endl; + h1_seminorm_error.push_back (h1_seminorm_error_per_cell.l2_norm()); + + cout << " Calculating H1 error... "; + integrate_difference (sol, h1_error_per_cell, q, fe, H1_norm); + cout << h1_error_per_cell.l2_norm() << endl; + h1_error.push_back (h1_error_per_cell.l2_norm()); dVector l1_error_per_dof, l2_error_per_dof, linfty_error_per_dof; + dVector h1_seminorm_error_per_dof, h1_error_per_dof; dof->distribute_cell_to_dof_vector (l1_error_per_cell, l1_error_per_dof); dof->distribute_cell_to_dof_vector (l2_error_per_cell, l2_error_per_dof); dof->distribute_cell_to_dof_vector (linfty_error_per_cell, linfty_error_per_dof); + dof->distribute_cell_to_dof_vector (h1_seminorm_error_per_cell, h1_seminorm_error_per_dof); + dof->distribute_cell_to_dof_vector (h1_error_per_cell, h1_error_per_dof); string filename = "gnuplot."; filename += ('0'+level); @@ -285,7 +309,9 @@ void PoissonProblem::run (const unsigned int level) { fill_data (out); out.add_data_vector (l1_error_per_dof, "L1-Error"); out.add_data_vector (l2_error_per_dof, "L2-Error"); - out.add_data_vector (linfty_error_per_dof, "L3-Error"); + out.add_data_vector (linfty_error_per_dof, "Linfty-Error"); + out.add_data_vector (h1_seminorm_error_per_dof, "H1-seminorm-Error"); + out.add_data_vector (h1_error_per_dof, "H1-Error"); out.write_gnuplot (gnuplot); gnuplot.close (); @@ -293,14 +319,59 @@ void PoissonProblem::run (const unsigned int level) { }; +template +void PoissonProblem::print_history () const { + ofstream out("gnuplot.history"); + out << "# n_dofs l1_error l2_error linfty_error h1_seminorm_error h1_error" + << endl; + for (unsigned int i=0; ih/2:" << endl; + cout << " L1 error : " << 1./average_l1 << endl + << " L2 error : " << 1./average_l2 << endl + << " Linfty error : " << 1./average_linfty << endl + << " H1 seminorm error: " << 1./average_h1_semi << endl + << " H1 error : " << 1./average_h1 << endl; +}; + int main () { PoissonProblem<2> problem; - for (unsigned int level=1; level<5; ++level) + for (unsigned int level=1; level<8; ++level) problem.run (level); + cout << endl << "Printing convergence history to ..." << endl; + problem.print_history (); + return 0; };