From 6dd166c69099432f9b182b2014f3a4169c45ab1a Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 22 Apr 1999 15:10:57 +0000 Subject: [PATCH] Implement renumbering by component. git-svn-id: https://svn.dealii.org/trunk@1201 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/numerics/dof_renumbering.h | 59 +++++++++- .../deal.II/source/dofs/dof_renumbering.cc | 102 ++++++++++++++++++ 2 files changed, 160 insertions(+), 1 deletion(-) diff --git a/deal.II/deal.II/include/numerics/dof_renumbering.h b/deal.II/deal.II/include/numerics/dof_renumbering.h index 1b8bc3d71d..4e8beacb87 100644 --- a/deal.II/deal.II/include/numerics/dof_renumbering.h +++ b/deal.II/deal.II/include/numerics/dof_renumbering.h @@ -133,7 +133,23 @@ * may be difficult, however, and in many cases will not justify the effort. * * - * \subsection{Multigrid DoF numbering} + * \section{Componentwise numbering} + * + * For finite elements composed of several base elements using the #FESystem# + * class, or for elements which provide several components themselves, it + * may be of interest to sort the DoF indices by component. This will then + * bring out the block matrix structure, since otherwise the degrees of freedom + * are numbered cell-wise without taking into account that they may belong to + * different components. + * + * This kind of numbering may be obtained by calling the #component_wise# function + * of this class. Since it does not touch the order of indices within each, it + * may be worthwhile to first renumber using the Cuthill-McKee or a similar + * algorithm and afterwards renumbering component-wise. This will bring out the + * matrix structure and additionally have a good numbering within each block. + * + * + * \section{Multigrid DoF numbering} * * Most algorithms also work on multigrid degree of freedom numberings. Refer * to the actual function declarations to get more information on this. @@ -185,11 +201,52 @@ class DoFRenumbering const bool reversed_numbering = false, const vector &starting_indices = vector ()); + /** + * Sort the degrees of freedom by + * component. The numbering within + * each component is not touched, + * so a degree of freedom with index + * $i$, belonging to some component, + * and another degree of freedom + * with index $j$ belonging to the same + * component will be assigned new + * indices $n(i)$ and $n(j)$ with + * $n(i)n(j)$ if $i>j$. + * + * You may want to give the order in + * which the components are to be ordered + * (e.g. if the second argument contains + * the numbers #(0, 3, 2, 1)#, then all + * indices of component #0# will be + * before those of component #3#, before + * those of component #2#, ...). The + * length of this list has to be the + * same as the number of components + * in the finite element, and has to + * contain all numbers counted from + * zero onwards. If + * you ommit this argument, the same + * order as given by the finite element + * is used. + * + * For finite elements with only one + * component, this function is the + * identity operation. + */ + template + static void component_wise (DoFHandler &dof_handler, + const vector &component_order = vector()); + /** * Exception */ DeclException0 (ExcRenumberingIncomplete); + /** + * Exception + */ + DeclException0 (ExcInvalidComponentOrder); }; diff --git a/deal.II/deal.II/source/dofs/dof_renumbering.cc b/deal.II/deal.II/source/dofs/dof_renumbering.cc index 8a50499ae9..dfeaf76f94 100644 --- a/deal.II/deal.II/source/dofs/dof_renumbering.cc +++ b/deal.II/deal.II/source/dofs/dof_renumbering.cc @@ -1,8 +1,11 @@ /* $Id$ */ +#include +#include #include #include #include +#include #include #include @@ -361,6 +364,102 @@ void DoFRenumbering::Cuthill_McKee (MGDoFHandler &dof_handler, +template +void DoFRenumbering::component_wise (DoFHandler &dof_handler, + const vector &component_order_arg) +{ + const unsigned int total_dofs = dof_handler.get_fe().total_dofs; + + // do nothing if the FE has only + // one component + if (dof_handler.get_fe().n_components == 1) + return; + + vector component_order (component_order_arg); + if (component_order.size() == 0) + for (unsigned int i=0; i local_dof_indices(total_dofs); + // prebuilt list to which component + // a given dof on a cell belongs + vector component_list (total_dofs); + for (unsigned int i=0; i > component_to_dof_map (dof_handler.get_fe().n_components); + for (typename DoFHandler::active_cell_iterator cell=dof_handler.begin_active(); + cell!=dof_handler.end(); ++cell) + { + // on each cell: get dof indices + // and insert them into the global + // list using their component + cell->get_dof_indices (local_dof_indices); + for (unsigned int i=0; i new_indices (dof_handler.n_dofs(), -1); + for (unsigned int component=0; component::const_iterator + begin_of_component = component_to_dof_map[component].begin(), + end_of_component = component_to_dof_map[component].end(); + + for (typename vector::const_iterator dof_index = begin_of_component; + dof_index != end_of_component; ++dof_index) + new_indices[*dof_index] = next_free_index++; + }; + + Assert (next_free_index == static_cast(dof_handler.n_dofs()), + ExcInternalError()); + + dof_handler.renumber_dofs (new_indices); +}; + + + @@ -377,3 +476,6 @@ void DoFRenumbering::Cuthill_McKee (MGDoFHandler &dof_handler const bool reversed_numbering, const vector &starting_indices); +template +void DoFRenumbering::component_wise (DoFHandler &dof_handler, + const vector &component_order_arg); -- 2.39.5