Flow123d  JS_before_hm-2-g912b55d
discrete_space.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file discrete_space.cc
15  * @brief Implementation of class which provides the finite element for every mesh cell.
16  * @author Jan Stebel
17  */
18 
19 #include "fem/discrete_space.hh"
20 #include "fem/finite_element.hh"
21 #include "mesh/mesh.h"
22 #include "mesh/accessors.hh"
23 #include "mesh/duplicate_nodes.h"
24 
25 
26 
28 {
29  unsigned int n_dofs = 0;
30  switch (cell->dim())
31  {
32  case 0:
33  for (unsigned int d=0; d<fe0_->n_dofs(); d++)
34  if (fe0_->dof(d).dim == 0)
35  n_dofs++;
36  break;
37  case 1:
38  for (unsigned int d=0; d<fe1_->n_dofs(); d++)
39  if (fe1_->dof(d).dim == 1)
40  n_dofs++;
41  break;
42  case 2:
43  for (unsigned int d=0; d<fe2_->n_dofs(); d++)
44  if (fe2_->dof(d).dim == 2)
45  n_dofs++;
46  break;
47  case 3:
48  for (unsigned int d=0; d<fe3_->n_dofs(); d++)
49  if (fe3_->dof(d).dim == 3)
50  n_dofs++;
51  break;
52  }
53  return n_dofs;
54 }
55 
56 
57 unsigned int EqualOrderDiscreteSpace::n_edge_dofs(const Edge &edge) const
58 {
59  unsigned int n_dofs = 0;
60  unsigned int dim = edge.side(0)->dim();
61  switch (dim+1)
62  {
63  case 0:
64  for (unsigned int d=0; d<fe0_->n_dofs(); d++)
65  if (fe0_->dof(d).dim == dim && fe0_->dof(d).n_face_idx == 0)
66  n_dofs++;
67  break;
68  case 1:
69  for (unsigned int d=0; d<fe1_->n_dofs(); d++)
70  if (fe1_->dof(d).dim == dim && fe1_->dof(d).n_face_idx == 0)
71  n_dofs++;
72  break;
73  case 2:
74  for (unsigned int d=0; d<fe2_->n_dofs(); d++)
75  if (fe2_->dof(d).dim == dim && fe2_->dof(d).n_face_idx == 0)
76  n_dofs++;
77  break;
78  case 3:
79  for (unsigned int d=0; d<fe3_->n_dofs(); d++)
80  if (fe3_->dof(d).dim == dim && fe3_->dof(d).n_face_idx == 0)
81  n_dofs++;
82  break;
83  }
84  return n_dofs;
85 }
86 
87 
88 unsigned int EqualOrderDiscreteSpace::n_node_dofs(unsigned int nid) const
89 {
90  unsigned int n_dofs = 0;
91  unsigned int dim = mesh_->tree->node_dim()[nid];
92  switch (dim)
93  {
94  case 0:
95  for (unsigned int d=0; d<fe0_->n_dofs(); d++)
96  if (fe0_->dof(d).dim == 0 && fe0_->dof(d).n_face_idx == 0)
97  n_dofs++;
98  break;
99  case 1:
100  for (unsigned int d=0; d<fe1_->n_dofs(); d++)
101  if (fe1_->dof(d).dim == 0 && fe1_->dof(d).n_face_idx == 0)
102  n_dofs++;
103  break;
104  case 2:
105  for (unsigned int d=0; d<fe2_->n_dofs(); d++)
106  if (fe2_->dof(d).dim == 0 && fe2_->dof(d).n_face_idx == 0)
107  n_dofs++;
108  break;
109  case 3:
110  for (unsigned int d=0; d<fe3_->n_dofs(); d++)
111  if (fe3_->dof(d).dim == 0 && fe3_->dof(d).n_face_idx == 0)
112  n_dofs++;
113  break;
114  }
115  return n_dofs;
116 }
117 
118 
119 
120 template<> FiniteElement<0> *DiscreteSpace::fe(const ElementAccessor<3> &cell) const { return fe0d(cell); }
121 template<> FiniteElement<1> *DiscreteSpace::fe(const ElementAccessor<3> &cell) const { return fe1d(cell); }
122 template<> FiniteElement<2> *DiscreteSpace::fe(const ElementAccessor<3> &cell) const { return fe2d(cell); }
123 template<> FiniteElement<3> *DiscreteSpace::fe(const ElementAccessor<3> &cell) const { return fe3d(cell); }
124 
125 
126 
127 
128 
unsigned int n_dofs() const
Returns the number of degrees of freedom needed by the finite element.
const std::vector< unsigned int > & node_dim() const
FiniteElement< 2 > * fe2_
FiniteElement< 1 > * fe1_
DuplicateNodes * tree
Definition: mesh.h:263
unsigned int dim
Association to n-face of given dimension (point, line, triangle, tetrahedron.
unsigned int n_face_idx
Index of n-face to which the dof is associated.
FiniteElement< 2 > * fe2d(const ElementAccessor< 3 > &) const override
FiniteElement< dim > * fe(const ElementAccessor< 3 > &) const
Return finite element object for given element.
unsigned int n_elem_dofs(const ElementAccessor< 3 > &cell) const override
Number of dofs associated to element (not shared by adjacent elements).
unsigned int dim() const
Definition: elements.h:123
unsigned int dim() const
Returns dimension of the side, that is dimension of the element minus one.
Declaration of class which provides the finite element for every mesh cell.
unsigned int n_node_dofs(unsigned int nid) const override
Number of dofs associated to node. nid is the node index in the mesh tree.
FiniteElement< 3 > * fe3_
unsigned int n_edge_dofs(const Edge &edge) const override
Number of dofs associated to edge.
const Dof & dof(unsigned int i) const
Returns i -th degree of freedom.
Abstract class for description of finite elements.
FiniteElement< 0 > * fe0_
FiniteElement< 1 > * fe1d(const ElementAccessor< 3 > &) const override
SideIter side(const unsigned int i) const
Gets side iterator of the i -th side.
FiniteElement< 3 > * fe3d(const ElementAccessor< 3 > &) const override
FiniteElement< 0 > * fe0d(const ElementAccessor< 3 > &) const override