From: Wolfgang Bangerth Date: Wed, 7 Mar 2001 09:55:50 +0000 (+0000) Subject: Bring step-7 up to date with mapping branch changes. X-Git-Tag: v8.0.0~19634 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef517a05e0;p=dealii.git Bring step-7 up to date with mapping branch changes. git-svn-id: https://svn.dealii.org/trunk@4136 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/examples/step-7/step-7.cc b/deal.II/examples/step-7/step-7.cc index 0bf34a46ed..a16c466f99 100644 --- a/deal.II/examples/step-7/step-7.cc +++ b/deal.II/examples/step-7/step-7.cc @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -1449,18 +1449,41 @@ void LaplaceProblem::run () // simple here, since we only have // a pointer to the common base // class of all finite elements, - // but we can use a rather new - // feature of C++ to check whether - // the actual type of the object - // pointed to by ``fe'' is an - // ``FEQ1'', ``FEQ2'', or something - // different. - if (typeid(*fe)==typeid(const FEQ1)) - filename += "-q1"; - else - if (typeid(*fe)==typeid(const FEQ2)) - filename += "-q2"; - else + // which does not know anything + // about polynomial + // degrees. However, we actually + // know that we have generated a + // finite element of class + // ``FE_Q'', so we can use some C++ + // feature to actually get a + // reference to the ``FE_Q'' + // element pointed to by the + // reference and ask it for the + // polynomial degree. Note that if + // for whatever reason the object + // referenced behind the pointer to + // the base class should not be of + // type ``FE_Q'', then the C++ + // language lets the + // ``dynamic_cast'' operator + // applied to a reference type + // throw an exception (if it were a + // pointer type, then a null + // pointer would be returned, which + // would then yield a segmentation + // fault when dereferenced in the + // subsequent call to + // ``get_order''). + switch (dynamic_cast&>(*fe).get_degree()) + { + case 1: + filename += "-q1"; + break; + case 2: + filename += "-q2"; + break; + + default: // The finite element is // neither Q1 nor Q2. This // should not have happened, @@ -1471,7 +1494,9 @@ void LaplaceProblem::run () // exception, since we don't // know how to name the // respective output file - Assert (false, ExcInternalError()); + Assert (false, ExcInternalError()); + }; + filename += ".gmv"; @@ -1531,26 +1556,15 @@ void LaplaceProblem::run () // quadratic elements, two // sub-cells per space direction is // obviously the right choice, so - // this is what we choose (note - // that the variable is initialized - // anyway to avoid an error message - // about possible use without - // initialization in optimized - // mode, where the compiler does - // not abort the program in the - // second `else' clause; however, - // the value in the initialization - // is such that it should be - // invalid): - unsigned int n_subcells = static_cast(-1); - if (typeid(*fe) == typeid(const FEQ1)) - n_subcells = 1; - else - if (typeid(*fe) == typeid(const FEQ2)) - n_subcells = 2; - else - Assert (false, ExcInternalError()); - + // this is what we choose. In + // general, for elements of + // polynomial order ``q'', we use + // ``q'' subdivisions, and the + // order of the elements is + // determined in the same way as + // above in the ``run'' function: + const unsigned int + n_subcells = dynamic_cast&>(*fe).get_degree(); data_out.build_patches (n_subcells); // Finally write out the data in @@ -1589,13 +1603,19 @@ void LaplaceProblem::run () default: Assert (false, ExcInternalError()); }; - if (typeid(*fe)==typeid(const FEQ1)) - filename += "-q1"; - else - if (typeid(*fe)==typeid(const FEQ2)) - filename += "-q2"; - else - Assert (false, ExcInternalError()); + + switch (dynamic_cast&>(*fe).get_degree()) + { + case 1: + filename += "-q1"; + break; + case 2: + filename += "-q2"; + break; + default: + Assert (false, ExcInternalError()); + }; + filename += ".tex"; std::ofstream table_file(filename.c_str()); @@ -1685,13 +1705,17 @@ void LaplaceProblem::run () default: Assert (false, ExcInternalError()); }; - if (typeid(*fe)==typeid(const FEQ1)) - filename += "-q1"; - else - if (typeid(*fe)==typeid(const FEQ2)) - filename += "-q2"; - else - Assert (false, ExcInternalError()); + switch (dynamic_cast&>(*fe).get_degree()) + { + case 1: + filename += "-q1"; + break; + case 2: + filename += "-q2"; + break; + default: + Assert (false, ExcInternalError()); + }; filename += ".tex"; std::ofstream table_file(filename.c_str()); @@ -1729,7 +1753,7 @@ int main () << "=============================================" << std::endl << std::endl; - FEQ1<2> fe; + FE_Q<2> fe(1); LaplaceProblem<2> laplace_problem_2d (fe, LaplaceProblem<2>::adaptive_refinement); laplace_problem_2d.run (); @@ -1741,7 +1765,7 @@ int main () << "===========================================" << std::endl << std::endl; - FEQ1<2> fe; + FE_Q<2> fe(1); LaplaceProblem<2> laplace_problem_2d (fe, LaplaceProblem<2>::global_refinement); laplace_problem_2d.run (); @@ -1753,7 +1777,7 @@ int main () << "===========================================" << std::endl << std::endl; - FEQ2<2> fe; + FE_Q<2> fe(2); LaplaceProblem<2> laplace_problem_2d (fe, LaplaceProblem<2>::global_refinement); laplace_problem_2d.run ();