Flow123d  release_3.0.0-1264-g45bfb2a
fe_rt.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 fe_rt.cc
15  * @brief Definitions of Raviart-Thomas finite elements.
16  * @author Jan Stebel
17  */
18 
19 #include "mesh/accessors.hh"
20 #include "fem/fe_rt.hh"
21 #include "fem/fe_values.hh"
22 #include "mesh/ref_element.hh"
24 #include "system/fmt/posix.h" // for FMT_UNUSED
25 
26 
27 RT0_space::RT0_space(unsigned int dim)
28  : FunctionSpace(dim, dim)
29 {}
30 
31 
32 double RT0_space::basis_value(unsigned int basis_index,
33  const arma::vec &point,
34  unsigned int comp_index) const
35 {
36  OLD_ASSERT(basis_index < this->dim(), "Index of basis function is out of range.");
37  OLD_ASSERT(comp_index < this->n_components_, "Index of component is out of range.");
38 
39  if (basis_index>0 && comp_index==basis_index-1)
40  return point[comp_index]-1;
41  else
42  return point[comp_index];
43 }
44 
45 
46 const arma::vec RT0_space::basis_grad(FMT_UNUSED unsigned int basis_index,
47  FMT_UNUSED const arma::vec &point,
48  unsigned int comp_index) const
49 {
50  OLD_ASSERT(basis_index < this->dim(), "Index of basis function is out of range.");
51  OLD_ASSERT(comp_index < this->n_components_, "Index of component is out of range.");
52 
53  arma::vec g(this->space_dim_);
54  g.zeros();
55  g[comp_index] = 1;
56 
57  return g;
58 }
59 
60 
61 template<> FE_RT0<0>::FE_RT0()
62 {
63 }
64 
65 
66 
67 template<unsigned int dim>
69 {
70  arma::vec::fixed<dim> sp;
71 
72  this->init(false, FEVectorPiola);
73  this->function_space_ = make_shared<RT0_space>(dim);
74 
75  for (unsigned int sid=0; sid<RefElement<dim>::n_sides; ++sid)
76  {
77  sp.fill(0);
78  for (unsigned int i=0; i<RefElement<dim>::n_nodes_per_side; ++i)
81  // barycentric coordinates
82  arma::vec::fixed<dim+1> bsp;
83  bsp.subvec(1,dim) = sp;
84  bsp[0] = 1. - arma::sum(sp);
85  // The dof (flux through side) is computed as scalar product of the value with normal vector times side measure.
86  this->dofs_.push_back(Dof(dim-1, sid, bsp, RefElement<dim>::normal_vector(sid)*RefElement<dim>::side_measure(sid), Value));
87  }
88  this->component_indices_.clear();
89  this->nonzero_components_.resize(this->dofs_.size(), std::vector<bool>(this->n_components(), true));
90 
91  this->compute_node_matrix();
92 }
93 
94 
95 
96 
97 template class FE_RT0<0>;
98 template class FE_RT0<1>;
99 template class FE_RT0<2>;
100 template class FE_RT0<3>;
101 
102 
104 {
105 }
106 
107 
108 template<unsigned int dim>
110 {
111  arma::vec::fixed<dim> sp;
112 
113  this->init(false, FEVectorPiola);
114  this->function_space_ = make_shared<RT0_space>(dim);
115 
116  for (unsigned int sid=0; sid<RefElement<dim>::n_sides; ++sid)
117  {
118  sp.fill(0);
119  for (unsigned int i=0; i<RefElement<dim>::n_nodes_per_side; ++i)
122  // barycentric coordinates
123  arma::vec::fixed<dim+1> bsp;
124  bsp.subvec(1,dim) = sp;
125  bsp[0] = 1. - arma::sum(sp);
126  // The dof (flux through side) is computed as scalar product of the value with normal vector times side measure.
127  this->dofs_.push_back(Dof(dim, 0, bsp, RefElement<dim>::normal_vector(sid)*RefElement<dim>::side_measure(sid), Value));
128  }
129  this->component_indices_.clear();
130  this->nonzero_components_.resize(this->dofs_.size(), std::vector<bool>(this->n_components(), true));
131 
132  this->compute_node_matrix();
133 }
134 
135 
136 
137 
138 template class FE_RT0_disc<0>;
139 template class FE_RT0_disc<1>;
140 template class FE_RT0_disc<2>;
141 template class FE_RT0_disc<3>;
142 
FE_RT0_disc()
Constructor.
Definition: fe_rt.cc:109
RT0_space(unsigned int dim)
Definition: fe_rt.cc:27
unsigned int n_components_
Number of components of function values.
Class FEValues calculates finite element data on the actual cells such as shape function values...
Mat< double, N, 1 > vec
Definition: armor.hh:211
double basis_value(unsigned int basis_index, const arma::vec &point, unsigned int comp_index) const override
Value of the i th basis function at point point.
Definition: fe_rt.cc:32
const arma::vec basis_grad(unsigned int basis_index, const arma::vec &point, unsigned int comp_index) const override
Gradient of the i th basis function at point point.
Definition: fe_rt.cc:46
#define OLD_ASSERT(...)
Definition: global_defs.h:131
#define FMT_UNUSED
Definition: posix.h:75
Raviart-Thomas element of order 0.
Definition: fe_rt.hh:60
unsigned int n_components() const
Getter for number of components.
FE_RT0()
Constructor.
Definition: fe_rt.cc:68
Discontinuous Raviart-Thomas element of order 0.
Definition: fe_rt.hh:81
unsigned int dim() const override
Dimension of function space (number of basis functions).
Definition: fe_rt.hh:49
Definitions of particular quadrature rules on simplices.
Class RefElement defines numbering of vertices, sides, calculation of normal vectors etc...
unsigned int space_dim_
Space dimension of function arguments (i.e. 1, 2 or 3).
Definitions of Raviart-Thomas finite elements.