Flow123d  release_3.0.0-962-g8853c67
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/duplicate_nodes.h"
23 
24 
25 
27 {
28  unsigned int n_dofs = 0;
29  switch (cell->dim())
30  {
31  case 0:
32  for (unsigned int d=0; d<fe0_->n_dofs(); d++)
33  if (fe0_->dof(d).dim == 0)
34  n_dofs++;
35  break;
36  case 1:
37  for (unsigned int d=0; d<fe1_->n_dofs(); d++)
38  if (fe1_->dof(d).dim == 1)
39  n_dofs++;
40  break;
41  case 2:
42  for (unsigned int d=0; d<fe2_->n_dofs(); d++)
43  if (fe2_->dof(d).dim == 2)
44  n_dofs++;
45  break;
46  case 3:
47  for (unsigned int d=0; d<fe3_->n_dofs(); d++)
48  if (fe3_->dof(d).dim == 3)
49  n_dofs++;
50  break;
51  }
52  return n_dofs;
53 }
54 
55 
56 unsigned int EqualOrderDiscreteSpace::n_edge_dofs(const Edge &edge) const
57 {
58  unsigned int n_dofs = 0;
59  unsigned int dim = edge.side(0)->dim();
60  switch (dim+1)
61  {
62  case 0:
63  for (unsigned int d=0; d<fe0_->n_dofs(); d++)
64  if (fe0_->dof(d).dim == dim && fe0_->dof(d).n_face_idx == 0)
65  n_dofs++;
66  break;
67  case 1:
68  for (unsigned int d=0; d<fe1_->n_dofs(); d++)
69  if (fe1_->dof(d).dim == dim && fe1_->dof(d).n_face_idx == 0)
70  n_dofs++;
71  break;
72  case 2:
73  for (unsigned int d=0; d<fe2_->n_dofs(); d++)
74  if (fe2_->dof(d).dim == dim && fe2_->dof(d).n_face_idx == 0)
75  n_dofs++;
76  break;
77  case 3:
78  for (unsigned int d=0; d<fe3_->n_dofs(); d++)
79  if (fe3_->dof(d).dim == dim && fe3_->dof(d).n_face_idx == 0)
80  n_dofs++;
81  break;
82  }
83  return n_dofs;
84 }
85 
86 
87 unsigned int EqualOrderDiscreteSpace::n_node_dofs(unsigned int nid) const
88 {
89  unsigned int n_dofs = 0;
90  unsigned int dim = mesh_->tree->node_dim()[nid];
91  switch (dim)
92  {
93  case 0:
94  for (unsigned int d=0; d<fe0_->n_dofs(); d++)
95  if (fe0_->dof(d).dim == 0 && fe0_->dof(d).n_face_idx == 0)
96  n_dofs++;
97  break;
98  case 1:
99  for (unsigned int d=0; d<fe1_->n_dofs(); d++)
100  if (fe1_->dof(d).dim == 0 && fe1_->dof(d).n_face_idx == 0)
101  n_dofs++;
102  break;
103  case 2:
104  for (unsigned int d=0; d<fe2_->n_dofs(); d++)
105  if (fe2_->dof(d).dim == 0 && fe2_->dof(d).n_face_idx == 0)
106  n_dofs++;
107  break;
108  case 3:
109  for (unsigned int d=0; d<fe3_->n_dofs(); d++)
110  if (fe3_->dof(d).dim == 0 && fe3_->dof(d).n_face_idx == 0)
111  n_dofs++;
112  break;
113  }
114  return n_dofs;
115 }
116 
117 
118 
119 template<> FiniteElement<0> *DiscreteSpace::fe(const ElementAccessor<3> &cell) const { return fe0d(cell); }
120 template<> FiniteElement<1> *DiscreteSpace::fe(const ElementAccessor<3> &cell) const { return fe1d(cell); }
121 template<> FiniteElement<2> *DiscreteSpace::fe(const ElementAccessor<3> &cell) const { return fe2d(cell); }
122 template<> FiniteElement<3> *DiscreteSpace::fe(const ElementAccessor<3> &cell) const { return fe3d(cell); }
123 
124 
125 
126 
127 
const std::vector< unsigned int > & node_dim() const
FiniteElement< 2 > * fe2_
FiniteElement< 1 > * fe1_
DuplicateNodes * tree
Definition: mesh.h:268
unsigned int dim
Association to n-face of given dimension (point, line, triangle, tetrahedron.
Definition: edges.h:26
unsigned int n_face_idx
Index of n-face to which the dof is associated.
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).
FiniteElement< 1 > * fe1d(const ElementAccessor< 3 > &cell) const override
unsigned int dim() const
Definition: elements.h:124
unsigned int dim() const
Definition: side_impl.hh:38
Declaration of class which provides the finite element for every mesh cell.
FiniteElement< 2 > * fe2d(const ElementAccessor< 3 > &cell) const override
FiniteElement< 0 > * fe0d(const ElementAccessor< 3 > &cell) const override
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.
FiniteElement< 3 > * fe3d(const ElementAccessor< 3 > &cell) const override
const Dof & dof(unsigned int i) const
Returns i -th degree of freedom.
const unsigned int n_dofs() const
Returns the number of degrees of freedom needed by the finite element.
Abstract class for description of finite elements.
FiniteElement< 0 > * fe0_
SideIter side(const unsigned int i) const
Definition: edges.h:31