From: Wolfgang Bangerth Date: Fri, 3 Apr 1998 17:43:11 +0000 (+0000) Subject: Example update. X-Git-Tag: v8.0.0~23121 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=386c0032799e371ac9be6287b6e3fc3a21974ef6;p=dealii.git Example update. git-svn-id: https://svn.dealii.org/trunk@133 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/Attic/examples/poisson/equation.cc b/deal.II/deal.II/Attic/examples/poisson/equation.cc index c995c110e0..405d59704f 100644 --- a/deal.II/deal.II/Attic/examples/poisson/equation.cc +++ b/deal.II/deal.II/Attic/examples/poisson/equation.cc @@ -4,24 +4,6 @@ -template -double RightHandSide::operator () (const Point &p) const { - const double pi = 3.1415926536; - switch (dim) - { - case 1: - return p(0)*p(0)*p(0)-3./2.*p(0)*p(0)-6*p(0)+3; - case 2: - return (-2.0*cos(pi*p(0)/2)*p(1)*sin(pi*p(1)) + - 2.0*p(0)*sin(pi*p(0)/2)*pi*p(1)*sin(pi*p(1)) + - 5.0/4.0*p(0)*p(0)*cos(pi*p(0)/2)*pi*pi*p(1)*sin(pi*p(1)) - - 2.0*p(0)*p(0)*cos(pi*p(0)/2)*cos(pi*p(1))*pi); - default: - return 0; - }; -}; - - @@ -83,9 +65,6 @@ void PoissonEquation::assemble (dVector &, -template class RightHandSide<1>; -template class RightHandSide<2>; - template class PoissonEquation<1>; template class PoissonEquation<2>; diff --git a/deal.II/deal.II/Attic/examples/poisson/poisson.h b/deal.II/deal.II/Attic/examples/poisson/poisson.h index d41e6bf432..74224e3837 100644 --- a/deal.II/deal.II/Attic/examples/poisson/poisson.h +++ b/deal.II/deal.II/Attic/examples/poisson/poisson.h @@ -34,21 +34,6 @@ extern "C" { -template -class RightHandSide : public Function { - public: - /** - * Return the value of the function - * at the given point. - */ - virtual double operator () (const Point &p) const; -}; - - - - - - template class PoissonEquation : public Equation { public: @@ -89,14 +74,18 @@ class PoissonProblem : public ProblemBase, bool make_grid (ParameterHandler &prm); - void make_ball_grid (); - void make_curved_line_grid (); void make_zoom_in_grid (); void make_random_grid (); + bool set_right_hand_side (ParameterHandler &prm); + bool set_boundary_values (ParameterHandler &prm); + protected: Triangulation *tria; DoFHandler *dof; + + Function *rhs; + Function *boundary_values; }; diff --git a/deal.II/deal.II/Attic/examples/poisson/poisson.prm b/deal.II/deal.II/Attic/examples/poisson/poisson.prm index fb9f151be9..2bebf9b6d4 100644 --- a/deal.II/deal.II/Attic/examples/poisson/poisson.prm +++ b/deal.II/deal.II/Attic/examples/poisson/poisson.prm @@ -1,3 +1,5 @@ set Test run = { zoom in | ball | curved line | random } -set Global refinement = {{ 2 | 4 | 6 | 0 }} +set Global refinement = {{ 2 | 5 | 6 | 0 }} +set Right hand side = {{ zero | zero | trigpoly | constant }} +set Boundary values = {{ sine | sine | zero | zero }} set Output file = gnuplot.{{ zoom_in | ball | curved_line | random }} diff --git a/deal.II/deal.II/Attic/examples/poisson/problem.cc b/deal.II/deal.II/Attic/examples/poisson/problem.cc index 77fcbcf35d..fcc3a74ee3 100644 --- a/deal.II/deal.II/Attic/examples/poisson/problem.cc +++ b/deal.II/deal.II/Attic/examples/poisson/problem.cc @@ -5,6 +5,52 @@ +template +class BoundaryValuesSine : public Function { + public: + /** + * Return the value of the function + * at the given point. + */ + virtual double operator () (const Point &p) const { + return cos(2*3.1415926536*p(0))*cos(2*3.1415926536*p(1)); + }; + + + /** + * Set #values# to the point values + * of the function at the #points#. + * It is assumed that #values# be + * empty. + */ + virtual void value_list (const vector > &points, + vector &values) const { + for (unsigned int i=0; i +class RHSTrigPoly : public Function { + public: + /** + * Return the value of the function + * at the given point. + */ + virtual double operator () (const Point &p) const; +}; + + + + + + + + template class CurvedLine : @@ -34,17 +80,57 @@ class CurvedLine : +template +double RHSTrigPoly::operator () (const Point &p) const { + const double pi = 3.1415926536; + switch (dim) + { + case 1: + return p(0)*p(0)*cos(2*pi*p(0)); + case 2: + return (-2.0*cos(pi*p(0)/2)*p(1)*sin(pi*p(1)) + + 2.0*p(0)*sin(pi*p(0)/2)*pi*p(1)*sin(pi*p(1)) + + 5.0/4.0*p(0)*p(0)*cos(pi*p(0)/2)*pi*pi*p(1)*sin(pi*p(1)) - + 2.0*p(0)*p(0)*cos(pi*p(0)/2)*cos(pi*p(1))*pi); + default: + return 0; + }; +}; + + + + + template PoissonProblem::PoissonProblem () : - tria(0), dof(0) {}; + tria(0), dof(0), rhs(0), boundary_values(0) {}; template void PoissonProblem::clear () { - if (tria != 0) delete tria; - if (dof != 0) delete dof; + if (tria != 0) { + delete tria; + tria = 0; + }; + + if (dof != 0) { + delete dof; + dof = 0; + }; + + if (rhs != 0) + { + delete rhs; + rhs = 0; + }; + + if (boundary_values != 0) + { + delete boundary_values; + boundary_values = 0; + }; ProblemBase::clear (); }; @@ -67,12 +153,17 @@ void PoissonProblem::create_new (const unsigned int) { template void PoissonProblem::declare_parameters (ParameterHandler &prm) { if (dim>=2) - prm.declare_entry ("Test run", "zoom in", "zoom in\\|ball\\|curved line\\|random"); + prm.declare_entry ("Test run", "zoom in", + "tensor\\|zoom in\\|ball\\|curved line\\|random"); else - prm.declare_entry ("Test run", "zoom in", "zoom in\\|random"); + prm.declare_entry ("Test run", "zoom in", "tensor\\|zoom in\\|random"); prm.declare_entry ("Global refinement", "0", ParameterHandler::RegularExpressions::Integer); + prm.declare_entry ("Right hand side", "zero", + "zero\\|constant\\|trigpoly"); + prm.declare_entry ("Boundary values", "zero", + "zero\\|sine"); prm.declare_entry ("Output file", "gnuplot.1"); }; @@ -90,11 +181,13 @@ bool PoissonProblem::make_grid (ParameterHandler &prm) { if (test=="curved line") test_case = 3; else if (test=="random") test_case = 4; - else - { - cerr << "This test seems not to be implemented!" << endl; - return false; - }; + else + if (test=="tensor") test_case = 5; + else + { + cerr << "This test seems not to be implemented!" << endl; + return false; + }; switch (test_case) { @@ -102,14 +195,29 @@ bool PoissonProblem::make_grid (ParameterHandler &prm) { make_zoom_in_grid (); break; case 2: - make_ball_grid (); + // make ball grid around origin with + // unit radius + { + static const Point origin; + static const HyperBallBoundary boundary(origin, 1.); + tria->create_hyper_ball (origin, 1.); + tria->set_boundary (&boundary); break; + }; case 3: - make_curved_line_grid (); + // set the boundary function + { + static const CurvedLine boundary; + tria->create_hypercube (); + tria->set_boundary (&boundary); break; + }; case 4: make_random_grid (); break; + case 5: + tria->create_hypercube (); + break; default: return false; }; @@ -152,30 +260,6 @@ void PoissonProblem::make_zoom_in_grid () { -template -void PoissonProblem::make_ball_grid () { - // make ball grid around origin with - // unit radius - const Point origin; - static const HyperBallBoundary boundary(origin, 1.); - - tria->create_hyper_ball (origin, 1.); - tria->set_boundary (&boundary); -}; - - - - -template -void PoissonProblem::make_curved_line_grid () { - // set the boundary function - static const CurvedLine boundary; - - tria->create_hypercube (); - tria->set_boundary (&boundary); -}; - - template void PoissonProblem::make_random_grid () { @@ -203,9 +287,52 @@ void PoissonProblem::make_random_grid () { tria->execute_refinement (); }; }; + + + + +template +bool PoissonProblem::set_right_hand_side (ParameterHandler &prm) { + String rhs_name = prm.get ("Right hand side"); + + if (rhs_name == "zero") + rhs = new ZeroFunction(); + else + if (rhs_name == "constant") + rhs = new ConstantFunction(1.); + else + if (rhs_name == "trigpoly") + rhs = new RHSTrigPoly(); + else + return false; + + if (rhs != 0) + return true; + else + return false; +}; +template +bool PoissonProblem::set_boundary_values (ParameterHandler &prm) { + String bv_name = prm.get ("Boundary values"); + + if (bv_name == "zero") + boundary_values = new ZeroFunction (); + else + if (bv_name == "sine") + boundary_values = new BoundaryValuesSine (); + else + return false; + + if (boundary_values != 0) + return true; + else + return false; +}; + + template @@ -217,10 +344,14 @@ void PoissonProblem::run (ParameterHandler &prm) { if (!make_grid (prm)) return; + if (!set_right_hand_side (prm)) + return; + if (!set_boundary_values (prm)) + return; + FELinear fe; - static const RightHandSide rhs; - PoissonEquation equation (rhs); + PoissonEquation equation (*rhs); QGauss4 quadrature; cout << " Distributing dofs... "; @@ -233,8 +364,7 @@ void PoissonProblem::run (ParameterHandler &prm) { update_flags.jacobians = update_flags.JxW_values = true; ProblemBase::DirichletBC dirichlet_bc; - ZeroFunction zero; - dirichlet_bc[0] = &zero; + dirichlet_bc[0] = boundary_values; assemble (equation, quadrature, fe, update_flags, dirichlet_bc); cout << " Solving..." << endl; diff --git a/tests/big-tests/poisson/equation.cc b/tests/big-tests/poisson/equation.cc index c995c110e0..405d59704f 100644 --- a/tests/big-tests/poisson/equation.cc +++ b/tests/big-tests/poisson/equation.cc @@ -4,24 +4,6 @@ -template -double RightHandSide::operator () (const Point &p) const { - const double pi = 3.1415926536; - switch (dim) - { - case 1: - return p(0)*p(0)*p(0)-3./2.*p(0)*p(0)-6*p(0)+3; - case 2: - return (-2.0*cos(pi*p(0)/2)*p(1)*sin(pi*p(1)) + - 2.0*p(0)*sin(pi*p(0)/2)*pi*p(1)*sin(pi*p(1)) + - 5.0/4.0*p(0)*p(0)*cos(pi*p(0)/2)*pi*pi*p(1)*sin(pi*p(1)) - - 2.0*p(0)*p(0)*cos(pi*p(0)/2)*cos(pi*p(1))*pi); - default: - return 0; - }; -}; - - @@ -83,9 +65,6 @@ void PoissonEquation::assemble (dVector &, -template class RightHandSide<1>; -template class RightHandSide<2>; - template class PoissonEquation<1>; template class PoissonEquation<2>; diff --git a/tests/big-tests/poisson/poisson.h b/tests/big-tests/poisson/poisson.h index d41e6bf432..74224e3837 100644 --- a/tests/big-tests/poisson/poisson.h +++ b/tests/big-tests/poisson/poisson.h @@ -34,21 +34,6 @@ extern "C" { -template -class RightHandSide : public Function { - public: - /** - * Return the value of the function - * at the given point. - */ - virtual double operator () (const Point &p) const; -}; - - - - - - template class PoissonEquation : public Equation { public: @@ -89,14 +74,18 @@ class PoissonProblem : public ProblemBase, bool make_grid (ParameterHandler &prm); - void make_ball_grid (); - void make_curved_line_grid (); void make_zoom_in_grid (); void make_random_grid (); + bool set_right_hand_side (ParameterHandler &prm); + bool set_boundary_values (ParameterHandler &prm); + protected: Triangulation *tria; DoFHandler *dof; + + Function *rhs; + Function *boundary_values; }; diff --git a/tests/big-tests/poisson/poisson.prm b/tests/big-tests/poisson/poisson.prm index fb9f151be9..2bebf9b6d4 100644 --- a/tests/big-tests/poisson/poisson.prm +++ b/tests/big-tests/poisson/poisson.prm @@ -1,3 +1,5 @@ set Test run = { zoom in | ball | curved line | random } -set Global refinement = {{ 2 | 4 | 6 | 0 }} +set Global refinement = {{ 2 | 5 | 6 | 0 }} +set Right hand side = {{ zero | zero | trigpoly | constant }} +set Boundary values = {{ sine | sine | zero | zero }} set Output file = gnuplot.{{ zoom_in | ball | curved_line | random }} diff --git a/tests/big-tests/poisson/problem.cc b/tests/big-tests/poisson/problem.cc index 77fcbcf35d..fcc3a74ee3 100644 --- a/tests/big-tests/poisson/problem.cc +++ b/tests/big-tests/poisson/problem.cc @@ -5,6 +5,52 @@ +template +class BoundaryValuesSine : public Function { + public: + /** + * Return the value of the function + * at the given point. + */ + virtual double operator () (const Point &p) const { + return cos(2*3.1415926536*p(0))*cos(2*3.1415926536*p(1)); + }; + + + /** + * Set #values# to the point values + * of the function at the #points#. + * It is assumed that #values# be + * empty. + */ + virtual void value_list (const vector > &points, + vector &values) const { + for (unsigned int i=0; i +class RHSTrigPoly : public Function { + public: + /** + * Return the value of the function + * at the given point. + */ + virtual double operator () (const Point &p) const; +}; + + + + + + + + template class CurvedLine : @@ -34,17 +80,57 @@ class CurvedLine : +template +double RHSTrigPoly::operator () (const Point &p) const { + const double pi = 3.1415926536; + switch (dim) + { + case 1: + return p(0)*p(0)*cos(2*pi*p(0)); + case 2: + return (-2.0*cos(pi*p(0)/2)*p(1)*sin(pi*p(1)) + + 2.0*p(0)*sin(pi*p(0)/2)*pi*p(1)*sin(pi*p(1)) + + 5.0/4.0*p(0)*p(0)*cos(pi*p(0)/2)*pi*pi*p(1)*sin(pi*p(1)) - + 2.0*p(0)*p(0)*cos(pi*p(0)/2)*cos(pi*p(1))*pi); + default: + return 0; + }; +}; + + + + + template PoissonProblem::PoissonProblem () : - tria(0), dof(0) {}; + tria(0), dof(0), rhs(0), boundary_values(0) {}; template void PoissonProblem::clear () { - if (tria != 0) delete tria; - if (dof != 0) delete dof; + if (tria != 0) { + delete tria; + tria = 0; + }; + + if (dof != 0) { + delete dof; + dof = 0; + }; + + if (rhs != 0) + { + delete rhs; + rhs = 0; + }; + + if (boundary_values != 0) + { + delete boundary_values; + boundary_values = 0; + }; ProblemBase::clear (); }; @@ -67,12 +153,17 @@ void PoissonProblem::create_new (const unsigned int) { template void PoissonProblem::declare_parameters (ParameterHandler &prm) { if (dim>=2) - prm.declare_entry ("Test run", "zoom in", "zoom in\\|ball\\|curved line\\|random"); + prm.declare_entry ("Test run", "zoom in", + "tensor\\|zoom in\\|ball\\|curved line\\|random"); else - prm.declare_entry ("Test run", "zoom in", "zoom in\\|random"); + prm.declare_entry ("Test run", "zoom in", "tensor\\|zoom in\\|random"); prm.declare_entry ("Global refinement", "0", ParameterHandler::RegularExpressions::Integer); + prm.declare_entry ("Right hand side", "zero", + "zero\\|constant\\|trigpoly"); + prm.declare_entry ("Boundary values", "zero", + "zero\\|sine"); prm.declare_entry ("Output file", "gnuplot.1"); }; @@ -90,11 +181,13 @@ bool PoissonProblem::make_grid (ParameterHandler &prm) { if (test=="curved line") test_case = 3; else if (test=="random") test_case = 4; - else - { - cerr << "This test seems not to be implemented!" << endl; - return false; - }; + else + if (test=="tensor") test_case = 5; + else + { + cerr << "This test seems not to be implemented!" << endl; + return false; + }; switch (test_case) { @@ -102,14 +195,29 @@ bool PoissonProblem::make_grid (ParameterHandler &prm) { make_zoom_in_grid (); break; case 2: - make_ball_grid (); + // make ball grid around origin with + // unit radius + { + static const Point origin; + static const HyperBallBoundary boundary(origin, 1.); + tria->create_hyper_ball (origin, 1.); + tria->set_boundary (&boundary); break; + }; case 3: - make_curved_line_grid (); + // set the boundary function + { + static const CurvedLine boundary; + tria->create_hypercube (); + tria->set_boundary (&boundary); break; + }; case 4: make_random_grid (); break; + case 5: + tria->create_hypercube (); + break; default: return false; }; @@ -152,30 +260,6 @@ void PoissonProblem::make_zoom_in_grid () { -template -void PoissonProblem::make_ball_grid () { - // make ball grid around origin with - // unit radius - const Point origin; - static const HyperBallBoundary boundary(origin, 1.); - - tria->create_hyper_ball (origin, 1.); - tria->set_boundary (&boundary); -}; - - - - -template -void PoissonProblem::make_curved_line_grid () { - // set the boundary function - static const CurvedLine boundary; - - tria->create_hypercube (); - tria->set_boundary (&boundary); -}; - - template void PoissonProblem::make_random_grid () { @@ -203,9 +287,52 @@ void PoissonProblem::make_random_grid () { tria->execute_refinement (); }; }; + + + + +template +bool PoissonProblem::set_right_hand_side (ParameterHandler &prm) { + String rhs_name = prm.get ("Right hand side"); + + if (rhs_name == "zero") + rhs = new ZeroFunction(); + else + if (rhs_name == "constant") + rhs = new ConstantFunction(1.); + else + if (rhs_name == "trigpoly") + rhs = new RHSTrigPoly(); + else + return false; + + if (rhs != 0) + return true; + else + return false; +}; +template +bool PoissonProblem::set_boundary_values (ParameterHandler &prm) { + String bv_name = prm.get ("Boundary values"); + + if (bv_name == "zero") + boundary_values = new ZeroFunction (); + else + if (bv_name == "sine") + boundary_values = new BoundaryValuesSine (); + else + return false; + + if (boundary_values != 0) + return true; + else + return false; +}; + + template @@ -217,10 +344,14 @@ void PoissonProblem::run (ParameterHandler &prm) { if (!make_grid (prm)) return; + if (!set_right_hand_side (prm)) + return; + if (!set_boundary_values (prm)) + return; + FELinear fe; - static const RightHandSide rhs; - PoissonEquation equation (rhs); + PoissonEquation equation (*rhs); QGauss4 quadrature; cout << " Distributing dofs... "; @@ -233,8 +364,7 @@ void PoissonProblem::run (ParameterHandler &prm) { update_flags.jacobians = update_flags.JxW_values = true; ProblemBase::DirichletBC dirichlet_bc; - ZeroFunction zero; - dirichlet_bc[0] = &zero; + dirichlet_bc[0] = boundary_values; assemble (equation, quadrature, fe, update_flags, dirichlet_bc); cout << " Solving..." << endl;