From 4dcf8ffb94e2961ec248b3007ed782c360aa6c24 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 6 Apr 1998 09:06:58 +0000 Subject: [PATCH] Example update. git-svn-id: https://svn.dealii.org/trunk@144 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/Attic/examples/Makefile | 24 ++-- .../deal.II/Attic/examples/poisson/Makefile | 18 ++- .../Attic/examples/poisson/poisson.prm | 10 +- .../deal.II/Attic/examples/poisson/problem.cc | 132 ++++++++++++++++-- tests/big-tests/Makefile | 24 ++-- tests/big-tests/poisson/Makefile | 18 ++- tests/big-tests/poisson/make_ps | 7 + tests/big-tests/poisson/poisson.prm | 10 +- tests/big-tests/poisson/problem.cc | 132 ++++++++++++++++-- 9 files changed, 309 insertions(+), 66 deletions(-) diff --git a/deal.II/deal.II/Attic/examples/Makefile b/deal.II/deal.II/Attic/examples/Makefile index 3bfb65efb9..a8c6a1a107 100644 --- a/deal.II/deal.II/Attic/examples/Makefile +++ b/deal.II/deal.II/Attic/examples/Makefile @@ -1,9 +1,13 @@ # $Id$ CXX=c++ -INCPATH = -I../include -I../../lac/include -I../../base/include -CXXFLAGS.g= -DDEBUG -g -Wall $(INCPATH) -CXXFLAGS = -O3 $(INCPATH) +INCLUDE = -I../include -I../../lac/include -I../../base/include +CXXFLAGS.g= -DDEBUG -g -Wall -W -pedantic -Wconversion \ + -Winline -Woverloaded-virtual -fno-rtti -fno-exceptions \ + $(INCLUDE) +CXXFLAGS =-O3 -Wuninitialized -finline-functions -ffast-math \ + -funroll-loops -felide-constructors -fnonnull-objects \ + -fno-rtti -fno-exceptions $(INCLUDE) LIBPATH = -L../lib -L../../lac/lib LIBFILES.g= ../lib/libbasic.g.a ../lib/libgrid.g.a \ @@ -13,14 +17,18 @@ LIBFILES = $(LIBFILES.g:.g.a=.a) LIBS.g = $(LIBPATH) -lbasic.g -lgrid.g -lfe.g -lnumerics.g -llac.g LIBS = $(LIBS.g:.g=) + +ifeq ($(shell uname),Linux) +CXX = /home/wolf/bin/gcc-2.8.1/bin/c++ +endif + + ifeq ($(shell uname),SunOS) -#CXXFLAGS := -V2.7.2.3 $(CXXFLAGS) -#CXXFLAGS.g:= -V2.7.2.3 $(CXXFLAGS.g) INCLUDE2.8 = -I/usr/local/source/libstdc++-2.8.0/libstdc++ \ -I/usr/local/source/libstdc++-2.8.0/libstdc++/stl \ -I/usr/local/source/libstdc++-2.8.0/libio -CXXFLAGS := $(CXXFLAGS) -fno-rtti -fno-exceptions $(INCLUDE2.8) -CXXFLAGS.g:= $(CXXFLAGS.g) -W -fno-rtti -fno-exceptions $(INCLUDE2.8) +CXXFLAGS := $(CXXFLAGS) $(INCLUDE2.8) +CXXFLAGS.g:= $(CXXFLAGS.g) $(INCLUDE2.8) endif @@ -78,6 +86,6 @@ clean: #of this file. Makefile.dep: $(cc-files) $(h-files) @echo ================= Making $@ - @$(CXX) $(INCPATH) -M $(cc-files) > Makefile.dep + @$(CXX) $(INCLUDE) -M $(cc-files) > Makefile.dep include Makefile.dep diff --git a/deal.II/deal.II/Attic/examples/poisson/Makefile b/deal.II/deal.II/Attic/examples/poisson/Makefile index 3e2c9bc71a..9e55405fbe 100644 --- a/deal.II/deal.II/Attic/examples/poisson/Makefile +++ b/deal.II/deal.II/Attic/examples/poisson/Makefile @@ -3,19 +3,23 @@ CXX = c++ INCLUDE = -I../../include -I../../../lac/include \ -I../../../base/include -I../../../mia/include -CXXFLAGS.g= -DDEBUG -g -Wall -pedantic -Wconversion \ - -Winline -Woverloaded-virtual $(INCLUDE) +CXXFLAGS.g= -DDEBUG -g -Wall -W -pedantic -Wconversion \ + -Winline -Woverloaded-virtual -fno-rtti -fno-exceptions \ + $(INCLUDE) CXXFLAGS =-O3 -Wuninitialized -finline-functions -ffast-math \ - -funroll-loops -felide-constructors -fnonnull-objects $(INCLUDE) + -funroll-loops -felide-constructors -fnonnull-objects \ + -fno-rtti -fno-exceptions $(INCLUDE) + +ifeq ($(shell uname),Linux) +CXX = /home/wolf/bin/gcc-2.8.1/bin/c++ +endif ifeq ($(shell uname),SunOS) -#CXXFLAGS := -V2.7.2.3 $(CXXFLAGS) -#CXXFLAGS.g:= -V2.7.2.3 $(CXXFLAGS.g) INCLUDE2.8 = -I/usr/local/source/libstdc++-2.8.0/libstdc++ \ -I/usr/local/source/libstdc++-2.8.0/libstdc++/stl \ -I/usr/local/source/libstdc++-2.8.0/libio -CXXFLAGS := $(CXXFLAGS) -fno-rtti -fno-exceptions $(INCLUDE2.8) -CXXFLAGS.g:= $(CXXFLAGS.g) -W -fno-rtti -fno-exceptions $(INCLUDE2.8) +CXXFLAGS := $(CXXFLAGS) $(INCLUDE2.8) +CXXFLAGS.g:= $(CXXFLAGS.g) $(INCLUDE2.8) endif LIBPATH = -L../../lib -L../../../lac/lib diff --git a/deal.II/deal.II/Attic/examples/poisson/poisson.prm b/deal.II/deal.II/Attic/examples/poisson/poisson.prm index 2bebf9b6d4..9d94d10703 100644 --- a/deal.II/deal.II/Attic/examples/poisson/poisson.prm +++ b/deal.II/deal.II/Attic/examples/poisson/poisson.prm @@ -1,5 +1,5 @@ -set Test run = { zoom in | ball | curved line | random } -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 }} +set Test run = { zoom in | ball | curved line | random | jump | L-region} +set Global refinement = {{ 2 | 5 | 6 | 0 | 2 | 5 }} +set Right hand side = {{ zero | zero | trigpoly | constant | zero | zero }} +set Boundary values = {{ sine | sine | zero | zero | jump | sine }} +set Output file = gnuplot.{{ zoom_in | ball | curved_line | random | jump | L-region }} diff --git a/deal.II/deal.II/Attic/examples/poisson/problem.cc b/deal.II/deal.II/Attic/examples/poisson/problem.cc index fcc3a74ee3..b33cf6f708 100644 --- a/deal.II/deal.II/Attic/examples/poisson/problem.cc +++ b/deal.II/deal.II/Attic/examples/poisson/problem.cc @@ -33,6 +33,29 @@ class BoundaryValuesSine : public Function { +template +class BoundaryValuesJump : public Function { + public: + /** + * Return the value of the function + * at the given point. + */ + virtual double operator () (const Point &p) const { + switch (dim) + { + case 1: + return 0; + default: + if (p(0) == p(1)) + return 0.5; + else + return (p(0)>p(1) ? 0. : 1.); + }; + }; +}; + + + template class RHSTrigPoly : public Function { @@ -46,6 +69,34 @@ class RHSTrigPoly : public Function { +/** + Right hand side constructed such that the exact solution is + $x(1-x)$ in 1d, $x(1-x)*y(1-y)$ in 2d, etc. + */ +template +class RHSPoly : public Function { + public: + /** + * Return the value of the function + * at the given point. + */ + virtual double operator () (const Point &p) const; +}; + + + +template +class Solution : public Function { + public: + /** + * Return the value of the function + * at the given point. + */ + virtual double operator () (const Point &p) const; +}; + + + @@ -99,6 +150,25 @@ double RHSTrigPoly::operator () (const Point &p) const { +template +double RHSPoly::operator () (const Point &p) const { + double ret_val = 0; + for (unsigned int i=0; i +double Solution::operator () (const Point &p) const { + double ret_val = 0; + for (unsigned int i=0; i @@ -154,16 +224,16 @@ template void PoissonProblem::declare_parameters (ParameterHandler &prm) { if (dim>=2) prm.declare_entry ("Test run", "zoom in", - "tensor\\|zoom in\\|ball\\|curved line\\|random"); + "tensor\\|zoom in\\|ball\\|curved line\\|random\\|jump\\|L-region"); else 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"); + "zero\\|constant\\|trigpoly\\|poly"); prm.declare_entry ("Boundary values", "zero", - "zero\\|sine"); + "zero\\|sine\\|jump"); prm.declare_entry ("Output file", "gnuplot.1"); }; @@ -184,10 +254,14 @@ bool PoissonProblem::make_grid (ParameterHandler &prm) { else if (test=="tensor") test_case = 5; else - { - cerr << "This test seems not to be implemented!" << endl; - return false; - }; + if (test=="jump") test_case = 6; + else + if (test=="L-region") test_case = 7; + else + { + cerr << "This test seems not to be implemented!" << endl; + return false; + }; switch (test_case) { @@ -218,6 +292,19 @@ bool PoissonProblem::make_grid (ParameterHandler &prm) { case 5: tria->create_hypercube (); break; + case 6: + tria->create_hypercube (); + tria->refine_global (1); + for (unsigned int i=0; i<5; ++i) + { + tria->begin_active(tria->n_levels()-1)->set_refine_flag(); + (--(tria->last_active()))->set_refine_flag(); + tria->execute_refinement (); + }; + break; + case 7: + tria->create_hyper_L (); + break; default: return false; }; @@ -304,7 +391,10 @@ bool PoissonProblem::set_right_hand_side (ParameterHandler &prm) { if (rhs_name == "trigpoly") rhs = new RHSTrigPoly(); else - return false; + if (rhs_name == "poly") + rhs = new RHSPoly (); + else + return false; if (rhs != 0) return true; @@ -324,7 +414,10 @@ bool PoissonProblem::set_boundary_values (ParameterHandler &prm) { if (bv_name == "sine") boundary_values = new BoundaryValuesSine (); else - return false; + if (bv_name == "jump") + boundary_values = new BoundaryValuesJump (); + else + return false; if (boundary_values != 0) return true; @@ -340,9 +433,10 @@ void PoissonProblem::run (ParameterHandler &prm) { cout << "Test case = " << prm.get ("Test run") << endl; - cout << " Making grid..." << endl; + cout << " Making grid... "; if (!make_grid (prm)) return; + cout << tria->n_active_cells() << " active cells." << endl; if (!set_right_hand_side (prm)) return; @@ -352,7 +446,7 @@ void PoissonProblem::run (ParameterHandler &prm) { FELinear fe; PoissonEquation equation (*rhs); - QGauss4 quadrature; + QGauss3 quadrature; cout << " Distributing dofs... "; dof->distribute_dofs (fe); @@ -371,14 +465,26 @@ void PoissonProblem::run (ParameterHandler &prm) { solve (); cout << " Writing to file <" << prm.get("Output file") << ">..." - << endl << endl; DataOut out; - ofstream gnuplot(prm.get("Output file")); + String o_filename = prm.get ("Output file"); + ofstream gnuplot(o_filename); fill_data (out); out.write_gnuplot (gnuplot); gnuplot.close (); + + cout << " Calculation L2 error... "; + Solution sol; + vector difference; + QGauss3 q; + integrate_difference (sol, difference, q, fe, L2_norm); + double error = 0; + for (unsigned int i=0; i Makefile.dep + @$(CXX) $(INCLUDE) -M $(cc-files) > Makefile.dep include Makefile.dep diff --git a/tests/big-tests/poisson/Makefile b/tests/big-tests/poisson/Makefile index 3e2c9bc71a..9e55405fbe 100644 --- a/tests/big-tests/poisson/Makefile +++ b/tests/big-tests/poisson/Makefile @@ -3,19 +3,23 @@ CXX = c++ INCLUDE = -I../../include -I../../../lac/include \ -I../../../base/include -I../../../mia/include -CXXFLAGS.g= -DDEBUG -g -Wall -pedantic -Wconversion \ - -Winline -Woverloaded-virtual $(INCLUDE) +CXXFLAGS.g= -DDEBUG -g -Wall -W -pedantic -Wconversion \ + -Winline -Woverloaded-virtual -fno-rtti -fno-exceptions \ + $(INCLUDE) CXXFLAGS =-O3 -Wuninitialized -finline-functions -ffast-math \ - -funroll-loops -felide-constructors -fnonnull-objects $(INCLUDE) + -funroll-loops -felide-constructors -fnonnull-objects \ + -fno-rtti -fno-exceptions $(INCLUDE) + +ifeq ($(shell uname),Linux) +CXX = /home/wolf/bin/gcc-2.8.1/bin/c++ +endif ifeq ($(shell uname),SunOS) -#CXXFLAGS := -V2.7.2.3 $(CXXFLAGS) -#CXXFLAGS.g:= -V2.7.2.3 $(CXXFLAGS.g) INCLUDE2.8 = -I/usr/local/source/libstdc++-2.8.0/libstdc++ \ -I/usr/local/source/libstdc++-2.8.0/libstdc++/stl \ -I/usr/local/source/libstdc++-2.8.0/libio -CXXFLAGS := $(CXXFLAGS) -fno-rtti -fno-exceptions $(INCLUDE2.8) -CXXFLAGS.g:= $(CXXFLAGS.g) -W -fno-rtti -fno-exceptions $(INCLUDE2.8) +CXXFLAGS := $(CXXFLAGS) $(INCLUDE2.8) +CXXFLAGS.g:= $(CXXFLAGS.g) $(INCLUDE2.8) endif LIBPATH = -L../../lib -L../../../lac/lib diff --git a/tests/big-tests/poisson/make_ps b/tests/big-tests/poisson/make_ps index ebe72be4af..3d202fe484 100644 --- a/tests/big-tests/poisson/make_ps +++ b/tests/big-tests/poisson/make_ps @@ -22,4 +22,11 @@ splot "gnuplot.curved_line" set output "fig.random.eps" splot "gnuplot.random" +!echo " Making " +set output "fig.jump.eps" +splot "gnuplot.jump" +!echo " Making " +set view 52,115 +set output "fig.L-region.eps" +splot "gnuplot.L-region" diff --git a/tests/big-tests/poisson/poisson.prm b/tests/big-tests/poisson/poisson.prm index 2bebf9b6d4..9d94d10703 100644 --- a/tests/big-tests/poisson/poisson.prm +++ b/tests/big-tests/poisson/poisson.prm @@ -1,5 +1,5 @@ -set Test run = { zoom in | ball | curved line | random } -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 }} +set Test run = { zoom in | ball | curved line | random | jump | L-region} +set Global refinement = {{ 2 | 5 | 6 | 0 | 2 | 5 }} +set Right hand side = {{ zero | zero | trigpoly | constant | zero | zero }} +set Boundary values = {{ sine | sine | zero | zero | jump | sine }} +set Output file = gnuplot.{{ zoom_in | ball | curved_line | random | jump | L-region }} diff --git a/tests/big-tests/poisson/problem.cc b/tests/big-tests/poisson/problem.cc index fcc3a74ee3..b33cf6f708 100644 --- a/tests/big-tests/poisson/problem.cc +++ b/tests/big-tests/poisson/problem.cc @@ -33,6 +33,29 @@ class BoundaryValuesSine : public Function { +template +class BoundaryValuesJump : public Function { + public: + /** + * Return the value of the function + * at the given point. + */ + virtual double operator () (const Point &p) const { + switch (dim) + { + case 1: + return 0; + default: + if (p(0) == p(1)) + return 0.5; + else + return (p(0)>p(1) ? 0. : 1.); + }; + }; +}; + + + template class RHSTrigPoly : public Function { @@ -46,6 +69,34 @@ class RHSTrigPoly : public Function { +/** + Right hand side constructed such that the exact solution is + $x(1-x)$ in 1d, $x(1-x)*y(1-y)$ in 2d, etc. + */ +template +class RHSPoly : public Function { + public: + /** + * Return the value of the function + * at the given point. + */ + virtual double operator () (const Point &p) const; +}; + + + +template +class Solution : public Function { + public: + /** + * Return the value of the function + * at the given point. + */ + virtual double operator () (const Point &p) const; +}; + + + @@ -99,6 +150,25 @@ double RHSTrigPoly::operator () (const Point &p) const { +template +double RHSPoly::operator () (const Point &p) const { + double ret_val = 0; + for (unsigned int i=0; i +double Solution::operator () (const Point &p) const { + double ret_val = 0; + for (unsigned int i=0; i @@ -154,16 +224,16 @@ template void PoissonProblem::declare_parameters (ParameterHandler &prm) { if (dim>=2) prm.declare_entry ("Test run", "zoom in", - "tensor\\|zoom in\\|ball\\|curved line\\|random"); + "tensor\\|zoom in\\|ball\\|curved line\\|random\\|jump\\|L-region"); else 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"); + "zero\\|constant\\|trigpoly\\|poly"); prm.declare_entry ("Boundary values", "zero", - "zero\\|sine"); + "zero\\|sine\\|jump"); prm.declare_entry ("Output file", "gnuplot.1"); }; @@ -184,10 +254,14 @@ bool PoissonProblem::make_grid (ParameterHandler &prm) { else if (test=="tensor") test_case = 5; else - { - cerr << "This test seems not to be implemented!" << endl; - return false; - }; + if (test=="jump") test_case = 6; + else + if (test=="L-region") test_case = 7; + else + { + cerr << "This test seems not to be implemented!" << endl; + return false; + }; switch (test_case) { @@ -218,6 +292,19 @@ bool PoissonProblem::make_grid (ParameterHandler &prm) { case 5: tria->create_hypercube (); break; + case 6: + tria->create_hypercube (); + tria->refine_global (1); + for (unsigned int i=0; i<5; ++i) + { + tria->begin_active(tria->n_levels()-1)->set_refine_flag(); + (--(tria->last_active()))->set_refine_flag(); + tria->execute_refinement (); + }; + break; + case 7: + tria->create_hyper_L (); + break; default: return false; }; @@ -304,7 +391,10 @@ bool PoissonProblem::set_right_hand_side (ParameterHandler &prm) { if (rhs_name == "trigpoly") rhs = new RHSTrigPoly(); else - return false; + if (rhs_name == "poly") + rhs = new RHSPoly (); + else + return false; if (rhs != 0) return true; @@ -324,7 +414,10 @@ bool PoissonProblem::set_boundary_values (ParameterHandler &prm) { if (bv_name == "sine") boundary_values = new BoundaryValuesSine (); else - return false; + if (bv_name == "jump") + boundary_values = new BoundaryValuesJump (); + else + return false; if (boundary_values != 0) return true; @@ -340,9 +433,10 @@ void PoissonProblem::run (ParameterHandler &prm) { cout << "Test case = " << prm.get ("Test run") << endl; - cout << " Making grid..." << endl; + cout << " Making grid... "; if (!make_grid (prm)) return; + cout << tria->n_active_cells() << " active cells." << endl; if (!set_right_hand_side (prm)) return; @@ -352,7 +446,7 @@ void PoissonProblem::run (ParameterHandler &prm) { FELinear fe; PoissonEquation equation (*rhs); - QGauss4 quadrature; + QGauss3 quadrature; cout << " Distributing dofs... "; dof->distribute_dofs (fe); @@ -371,14 +465,26 @@ void PoissonProblem::run (ParameterHandler &prm) { solve (); cout << " Writing to file <" << prm.get("Output file") << ">..." - << endl << endl; DataOut out; - ofstream gnuplot(prm.get("Output file")); + String o_filename = prm.get ("Output file"); + ofstream gnuplot(o_filename); fill_data (out); out.write_gnuplot (gnuplot); gnuplot.close (); + + cout << " Calculation L2 error... "; + Solution sol; + vector difference; + QGauss3 q; + integrate_difference (sol, difference, q, fe, L2_norm); + double error = 0; + for (unsigned int i=0; i