1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2020 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15
16
17
18 // Test DoFTools::count_dofs_per_fe_component
19
20
21 #include <deal.II/base/tensor.h>
22 #include <deal.II/base/utilities.h>
23
24 #include <deal.II/distributed/tria.h>
25
26 #include <deal.II/dofs/dof_handler.h>
27 #include <deal.II/dofs/dof_tools.h>
28
29 #include <deal.II/fe/fe_dgq.h>
30 #include <deal.II/fe/fe_q.h>
31 #include <deal.II/fe/fe_system.h>
32
33 #include <deal.II/grid/grid_generator.h>
34 #include <deal.II/grid/intergrid_map.h>
35 #include <deal.II/grid/tria_accessor.h>
36 #include <deal.II/grid/tria_iterator.h>
37
38 #include <numeric>
39
40 using namespace dealii;
41
42 template <int dim>
43 void
test()44 test()
45 {
46 parallel::distributed::Triangulation<dim> triangulation(
47 MPI_COMM_WORLD, Triangulation<dim>::limit_level_difference_at_vertices);
48
49 FESystem<dim> fe(FE_Q<dim>(3), 2, FE_DGQ<dim>(1), 1);
50
51 DoFHandler<dim> dof_handler(triangulation);
52
53 GridGenerator::hyper_cube(triangulation);
54 triangulation.refine_global(2);
55 dof_handler.distribute_dofs(fe);
56
57 const std::vector<types::global_dof_index> dofs_per_component =
58 DoFTools::count_dofs_per_fe_component(dof_handler);
59
60 Assert(std::accumulate(dofs_per_component.begin(),
61 dofs_per_component.end(),
62 0U) == dof_handler.n_dofs(),
63 ExcInternalError());
64
65 const unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
66 if (myid == 0)
67 {
68 deallog << "Total number of dofs: " << dof_handler.n_dofs() << std::endl;
69 for (unsigned int i = 0; i < dofs_per_component.size(); ++i)
70 deallog << "Component " << i << " has " << dofs_per_component[i]
71 << " global dofs" << std::endl;
72 }
73 }
74
75
76 int
main(int argc,char * argv[])77 main(int argc, char *argv[])
78 {
79 Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
80
81 test<2>();
82 test<3>();
83
84 return 0;
85 }
86