namespace DoFTools
{
-
+
template <class DH, class SparsityPattern>
void
make_sparsity_pattern (const DH &dof,
return return_value;
}
-
+
namespace internal
{
- namespace
+ namespace
{
-
+
// implementation of the same function in
// namespace DoFTools for non-hp
// DoFHandlers
}
}
}
-
+
// implementation of the same function in
// namespace DoFTools for non-hp
}
}
}
-
+
}
template <class DH, class SparsityPattern>
- void
+ void
make_flux_sparsity_pattern (const DH &dof,
SparsityPattern &sparsity,
const Table<2,Coupling> &int_mask,
Assert (flux_mask.n_cols() == n_comp,
ExcDimensionMismatch (flux_mask.n_cols(), n_comp));
-
+
// Clear user flags because we will
// need them. But first we save
// them and make sure that we
internal::make_flux_sparsity_pattern (dof, sparsity,
int_mask, flux_mask);
-
+
// finally restore the user flags
const_cast<Triangulation<DH::dimension,DH::space_dimension> &>(dof.get_tria()).load_user_flags(user_flags);
}
==
FiniteElementDomination::no_requirements)
continue;
-
+
// Same procedure as for the
// mother cell. Extract the face
// DoFs from the cell DoFs.
// nothing to do here
break;
}
-
+
default:
// we shouldn't get
// here
template <int dim, int spacedim>
void
-
+
extract_hanging_node_dofs (const DoFHandler<dim,spacedim> &dof_handler,
std::vector<bool> &selected_dofs)
{
namespace internal
{
+//TODO: why is this function so complicated? It would be nice to have
+// comments that explain why we can't just loop over all components
+// and count the entries in dofs_by_component that have this
+// component's index
template <int dim, int spacedim>
void
resolve_components (const FiniteElement<dim,spacedim>&fe,
}
}
}
+
+ template <int dim, int spacedim>
+ void
+ resolve_components (const hp::FECollection<dim,spacedim>&fe_collection,
+ const std::vector<unsigned char> &dofs_by_component,
+ const std::vector<unsigned int> &target_component,
+ const bool only_once,
+ std::vector<unsigned int> &dofs_per_component,
+ unsigned int &component)
+ {
+ // assert that all elements in the collection have the same
+ // structure (base elements and multiplicity, components per base
+ // element) and then simply call the function above
+ for (unsigned int fe=1; fe<fe_collection.size(); ++fe)
+ {
+ Assert (fe_collection[fe].n_components() == fe_collection[0].n_components(),
+ ExcNotImplemented());
+ Assert (fe_collection[fe].n_base_elements() == fe_collection[0].n_base_elements(),
+ ExcNotImplemented());
+ for (unsigned int b=0;b<fe_collection[0].n_base_elements();++b)
+ {
+ Assert (fe_collection[fe].base_element(b).n_components() == fe_collection[0].base_element(b).n_components(),
+ ExcNotImplemented());
+ Assert (fe_collection[fe].base_element(b).n_base_elements() == fe_collection[0].base_element(b).n_base_elements(),
+ ExcNotImplemented());
+ }
+ }
+
+ resolve_components (fe_collection[0], dofs_by_component,
+ target_component, only_once, dofs_per_component,
+ component);
+ }
}
- template <int dim, int spacedim>
+ namespace internal
+ {
+ namespace {
+ /**
+ * Return true if the given element is primitive.
+ */
+ template <int dim, int spacedim>
+ bool all_elements_are_primitive (const FiniteElement<dim,spacedim> &fe)
+ {
+ return fe.is_primitive();
+ }
+
+
+ /**
+ * Return true if each element of the given element collection is primitive.
+ */
+ template <int dim, int spacedim>
+ bool all_elements_are_primitive (const dealii::hp::FECollection<dim,spacedim> &fe_collection)
+ {
+ for (unsigned int i=0; i<fe_collection.size(); ++i)
+ if (fe_collection[i].is_primitive() == false)
+ return false;
+
+ return true;
+ }
+ }
+ }
+
+ template <class DH>
void
count_dofs_per_component (
- const DoFHandler<dim,spacedim>& dof_handler,
+ const DH & dof_handler,
std::vector<unsigned int>& dofs_per_component,
bool only_once,
std::vector<unsigned int> target_component)
{
- const FiniteElement<dim,spacedim>& fe = dof_handler.get_fe();
+ const unsigned int n_components = dof_handler.get_fe().n_components();
std::fill (dofs_per_component.begin(), dofs_per_component.end(), 0U);
// vector as identity.
if (target_component.size()==0)
{
- target_component.resize(fe.n_components());
- for (unsigned int i=0; i<fe.n_components(); ++i)
+ target_component.resize(n_components);
+ for (unsigned int i=0; i<n_components; ++i)
target_component[i] = i;
}
else
- Assert (target_component.size()==fe.n_components(),
+ Assert (target_component.size()==n_components,
ExcDimensionMismatch(target_component.size(),
- fe.n_components()));
+ n_components));
const unsigned int max_component
= *std::max_element (target_component.begin(),
target_component.end());
const unsigned int n_target_components = max_component + 1;
- const unsigned int n_components = fe.n_components();
AssertDimension (dofs_per_component.size(), n_target_components);
// next count what we got
unsigned int component = 0;
- internal::resolve_components(fe, dofs_by_component, target_component,
+ internal::resolve_components(dof_handler.get_fe(),
+ dofs_by_component, target_component,
only_once, dofs_per_component, component);
Assert (n_components == component, ExcInternalError());
// only valid if the finite element
// is actually primitive, so
// exclude other elements from this
- Assert (!dof_handler.get_fe().is_primitive()
+ Assert ((internal::all_elements_are_primitive(dof_handler.get_fe()) == false)
||
(std::accumulate (dofs_per_component.begin(),
dofs_per_component.end(), 0U)
// reduce information from all CPUs
#ifdef DEAL_II_USE_P4EST
#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
- if (const parallel::distributed::Triangulation<dim> * tria
- = (dynamic_cast<const parallel::distributed::Triangulation<dim>*>
+ if (const parallel::distributed::Triangulation<dim,spacedim> * tria
+ = (dynamic_cast<const parallel::distributed::Triangulation<dim,spacedim>*>
(&dof_handler.get_tria())))
{
std::vector<unsigned int> local_dof_count = dofs_per_component;
template <int dim, int spacedim>
- void
+ void
count_dofs_per_block (const DoFHandler<dim,spacedim>& dof_handler,
std::vector<unsigned int> &dofs_per_block,
std::vector<unsigned int> target_block)
template
void
-DoFTools::count_dofs_per_component<deal_II_dimension> (
+DoFTools::count_dofs_per_component<DoFHandler<deal_II_dimension> > (
const DoFHandler<deal_II_dimension>&,
std::vector<unsigned int>&, bool, std::vector<unsigned int>);
-#if deal_II_dimension < 3
-template void DoFTools::extract_level_dofs<deal_II_dimension, deal_II_dimension+1>
-(const unsigned int level, const MGDoFHandler<deal_II_dimension, deal_II_dimension+1>&,
- const std::vector<bool>&, std::vector<bool>&, bool);
+template
+void
+DoFTools::count_dofs_per_component<hp::DoFHandler<deal_II_dimension> > (
+ const hp::DoFHandler<deal_II_dimension>&,
+ std::vector<unsigned int>&, bool, std::vector<unsigned int>);
+
+#if deal_II_dimension < 3
template
void
-DoFTools::count_dofs_per_component<deal_II_dimension, deal_II_dimension+1> (
+DoFTools::count_dofs_per_component<DoFHandler<deal_II_dimension, deal_II_dimension+1> > (
const DoFHandler<deal_II_dimension, deal_II_dimension+1>&,
std::vector<unsigned int>&, bool, std::vector<unsigned int>);
+
+template
+void
+DoFTools::count_dofs_per_component<hp::DoFHandler<deal_II_dimension, deal_II_dimension+1> > (
+ const hp::DoFHandler<deal_II_dimension, deal_II_dimension+1>&,
+ std::vector<unsigned int>&, bool, std::vector<unsigned int>);
+
+template
+void
+DoFTools::extract_level_dofs<deal_II_dimension, deal_II_dimension+1>
+(const unsigned int level, const MGDoFHandler<deal_II_dimension, deal_II_dimension+1>&,
+ const std::vector<bool>&, std::vector<bool>&, bool);
+
#endif
template
--- /dev/null
+//----------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2003, 2004, 2005, 2009 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//----------------------------------------------------------------------
+
+#include "../tests.h"
+#include <grid/tria.h>
+#include <grid/grid_generator.h>
+#include <hp/fe_collection.h>
+#include <hp/dof_handler.h>
+#include <dofs/dof_handler.h>
+#include <fe/fe_q.h>
+#include <fe/fe_system.h>
+#include <dofs/dof_tools.h>
+
+// check
+// DoFTools::
+// count_dofs_per_component (...);
+// for the hp case
+
+
+using namespace std;
+
+template <int dim>
+void test ()
+{
+ Triangulation<dim> triangulation;
+ GridGenerator::hyper_cube(triangulation);
+ triangulation.refine_global(3);
+
+ //define DoFhandler and FEs
+ FE_Q<dim> u(2);
+ FE_Q<dim> p(1);
+
+ FESystem<dim> fe_system(u, 2, p, 1);
+
+ hp::FECollection<dim> fe_collection;
+ fe_collection.push_back(fe_system);
+
+ hp::DoFHandler<dim> hp_dof_handler(triangulation);
+ DoFHandler<dim> dof_handler(triangulation);
+
+ //distribute dofs
+ hp_dof_handler.distribute_dofs(fe_collection);
+ dof_handler.distribute_dofs(fe_system);
+
+ //count dofs per component and show them on the screen
+ std::vector<unsigned int> dofs_per_component(3,0);
+ std::vector<unsigned int> dofs_per_component_hp(3,0);
+ DoFTools::count_dofs_per_component(dof_handler, dofs_per_component);
+ DoFTools::count_dofs_per_component(hp_dof_handler, dofs_per_component_hp);
+
+ for (unsigned int i=0; i<3; i++)
+ {
+ deallog <<"DoFs in the " <<i<<". component for classical FE: "<< dofs_per_component.at(i)<< std::endl;
+ deallog <<"DoFs in the " <<i<<". component for hp FE: "<< dofs_per_component_hp.at(i)<< std::endl;
+
+ Assert (dofs_per_component.at(i) == dofs_per_component_hp.at(i),
+ ExcInternalError());
+ }
+
+}
+
+int main ()
+{
+ std::ofstream logfile("count_dofs_per_component_hp/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ test<1> ();
+ test<2> ();
+ test<3> ();
+ return 0;
+}