From bd861026cd0e47f44978e4dc54b424dee435d4c7 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 5 Dec 2005 23:11:27 +0000 Subject: [PATCH] Compute some form of error, although the result is presently nonsensical. git-svn-id: https://svn.dealii.org/trunk@11832 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/examples/step-20/step-20.cc | 73 ++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/deal.II/examples/step-20/step-20.cc b/deal.II/examples/step-20/step-20.cc index d090c93bd9..27a3ad8e0c 100644 --- a/deal.II/examples/step-20/step-20.cc +++ b/deal.II/examples/step-20/step-20.cc @@ -86,6 +86,7 @@ class LaplaceProblem void make_grid_and_dofs (); void assemble_system (); void solve (); + void compute_errors () const; void output_results () const; Triangulation triangulation; @@ -175,6 +176,16 @@ class BoundaryValues : public Function }; +template +class ExactSolution : public Function +{ + public: + ExactSolution () : Function(dim+1) {}; + + virtual double value (const Point &p, + const unsigned int component = 0) const; +}; + // We wanted the right hand side @@ -211,6 +222,18 @@ double RightHandSide::value (const Point &p, } +template +double ExactSolution::value (const Point &p, + const unsigned int component) const +{ + double return_value = 1; + for (unsigned int i=0; i void LaplaceProblem::make_grid_and_dofs () { GridGenerator::hyper_cube (triangulation, 0, 1); - triangulation.refine_global (4); + triangulation.refine_global (5); std::cout << " Number of active cells: " << triangulation.n_active_cells() @@ -621,6 +644,53 @@ void LaplaceProblem::solve () +template +void LaplaceProblem::compute_errors () const +{ + Vector tmp (triangulation.n_active_cells()); + ExactSolution exact_solution; + { + const ComponentSelectFunction mask (dim, 1., dim+1); + VectorTools::integrate_difference (dof_handler, solution, exact_solution, + tmp, QGauss(degree+1), + VectorTools::L2_norm, + &mask); + } + const double p_l2_error = tmp.l2_norm(); + + double u_l2_error = 0; + for (unsigned int d=0; d mask(d, 1., dim+1); + VectorTools::integrate_difference (dof_handler, solution, exact_solution, + tmp, QGauss(degree+1), + VectorTools::L2_norm, + &mask); + u_l2_error = std::sqrt (u_l2_error*u_l2_error + + tmp.l2_norm() * tmp.l2_norm()); + } + + double u_h1_error = 0; + for (unsigned int d=0; d mask(d, 1., dim+1); + VectorTools::integrate_difference (dof_handler, solution, exact_solution, + tmp, QGauss(degree+1), + VectorTools::H1_seminorm, + &mask); + u_h1_error = std::sqrt (u_h1_error*u_h1_error + + tmp.l2_norm() * tmp.l2_norm()); + } + + + std::cout << "Errors: ||e_p||_L2 = " << p_l2_error + << ", ||e_u||_L2 = " << u_l2_error + << ", |e_u|_H1 = " << u_h1_error + << std::endl; +} + + + // This function also does what the // respective one did in the previous // example. No changes here for @@ -667,6 +737,7 @@ void LaplaceProblem::run () make_grid_and_dofs(); assemble_system (); solve (); + compute_errors (); output_results (); } -- 2.39.5