DOLFIN
DOLFIN C++ interface
FiniteElement.h
1 // Copyright (C) 2008-2013 Anders Logg and Garth N. Wells
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef __FINITE_ELEMENT_H
19 #define __FINITE_ELEMENT_H
20 
21 #include <memory>
22 #include <vector>
23 #include <ufc.h>
24 #include <boost/multi_array.hpp>
25 #include <dolfin/common/types.h>
26 #include <dolfin/log/log.h>
27 
28 namespace dolfin
29 {
30 
31  class Cell;
32 
34 
36  {
37  public:
38 
42  FiniteElement(std::shared_ptr<const ufc::finite_element> element);
43 
45  virtual ~FiniteElement() {}
46 
47  //--- Direct wrappers for ufc::finite_element ---
48 
51  std::string signature() const
52  {
53  dolfin_assert(_ufc_element);
54  return _ufc_element->signature();
55  }
56 
59  ufc::shape cell_shape() const
60  {
61  dolfin_assert(_ufc_element);
62  return _ufc_element->cell_shape();
63  }
64 
67  std::size_t topological_dimension() const
68  {
69  dolfin_assert(_ufc_element);
70  return _ufc_element->topological_dimension();
71  }
72 
75  virtual unsigned int geometric_dimension() const
76  {
77  dolfin_assert(_ufc_element);
78  return _ufc_element->geometric_dimension();
79  }
80 
83  std::size_t space_dimension() const
84  {
85  dolfin_assert(_ufc_element);
86  return _ufc_element->space_dimension();
87  }
88 
90  std::size_t value_rank() const
91  {
92  dolfin_assert(_ufc_element);
93  return _ufc_element->value_rank();
94  }
95 
97  std::size_t value_dimension(std::size_t i) const
98  {
99  dolfin_assert(_ufc_element);
100  return _ufc_element->value_dimension(i);
101  }
102 
104  void evaluate_basis(std::size_t i, double* values, const double* x,
105  const double* coordinate_dofs,
106  int cell_orientation) const
107  {
108  dolfin_assert(_ufc_element);
109  _ufc_element->evaluate_basis(i, values, x, coordinate_dofs,
110  cell_orientation);
111  }
112 
114  void evaluate_basis_all(double* values,
115  const double* x,
116  const double* coordinate_dofs,
117  int cell_orientation) const
118  {
119  dolfin_assert(_ufc_element);
120  _ufc_element->evaluate_basis_all(values, x, coordinate_dofs,
121  cell_orientation);
122  }
123 
125  void evaluate_basis_derivatives(unsigned int i,
126  unsigned int n,
127  double* values,
128  const double* x,
129  const double* coordinate_dofs,
130  int cell_orientation) const
131  {
132  dolfin_assert(_ufc_element);
133  _ufc_element->evaluate_basis_derivatives(i, n, values, x,
134  coordinate_dofs,
135  cell_orientation);
136  }
137 
140  void evaluate_basis_derivatives_all(unsigned int n,
141  double* values,
142  const double* x,
143  const double* coordinate_dofs,
144  int cell_orientation) const
145  {
146  dolfin_assert(_ufc_element);
147  _ufc_element->evaluate_basis_derivatives_all(n, values, x,
148  coordinate_dofs,
149  cell_orientation);
150  }
151 
153  double evaluate_dof(std::size_t i,
154  const ufc::function& function,
155  const double* coordinate_dofs,
156  int cell_orientation,
157  const ufc::cell& c) const
158  {
159  dolfin_assert(_ufc_element);
160  return _ufc_element->evaluate_dof(i, function, coordinate_dofs,
161  cell_orientation, c);
162  }
163 
165  void evaluate_dofs(double* values,
166  const ufc::function& f,
167  const double* coordinate_dofs,
168  int cell_orientation,
169  const ufc::cell& c) const
170  {
171  dolfin_assert(_ufc_element);
172  _ufc_element->evaluate_dofs(values, f, coordinate_dofs,
173  cell_orientation, c);
174  }
175 
181  void interpolate_vertex_values(double* vertex_values,
182  double* coefficients,
183  const double* coordinate_dofs,
184  int cell_orientation) const
185  {
186  dolfin_assert(_ufc_element);
187  _ufc_element->interpolate_vertex_values(vertex_values, coefficients,
188  coordinate_dofs,
189  cell_orientation);
190  }
191 
200  void tabulate_dof_coordinates(boost::multi_array<double, 2>& coordinates,
201  const std::vector<double>& coordinate_dofs,
202  const Cell& cell) const;
203 
207  std::size_t num_sub_elements() const
208  {
209  dolfin_assert(_ufc_element);
210  return _ufc_element->num_sub_elements();
211  }
212 
213  //--- DOLFIN-specific extensions of the interface ---
214 
216  std::size_t hash() const
217  { return _hash; }
218 
220  std::shared_ptr<const FiniteElement>
221  create_sub_element(std::size_t i) const
222  {
223  dolfin_assert(_ufc_element);
224  std::shared_ptr<const ufc::finite_element>
225  ufc_element(_ufc_element->create_sub_element(i));
226  std::shared_ptr<const FiniteElement>
227  element(new const FiniteElement(ufc_element));
228  return element;
229  }
230 
232  std::shared_ptr<const FiniteElement> create() const
233  {
234  dolfin_assert(_ufc_element);
235  std::shared_ptr<const ufc::finite_element>
236  ufc_element(_ufc_element->create());
237  return std::shared_ptr<const FiniteElement>(new FiniteElement(ufc_element));
238  }
239 
241  std::shared_ptr<const FiniteElement>
242  extract_sub_element(const std::vector<std::size_t>& component) const;
243 
246  std::shared_ptr<const ufc::finite_element> ufc_element() const
247  { return _ufc_element; }
248 
249  private:
250 
251  // UFC finite element
252  std::shared_ptr<const ufc::finite_element> _ufc_element;
253 
254  // Recursively extract sub finite element
255  static std::shared_ptr<const FiniteElement>
256  extract_sub_element(const FiniteElement& finite_element,
257  const std::vector<std::size_t>& component);
258 
259  // Simple hash of the signature string
260  std::size_t _hash;
261 
262  };
263 
264 }
265 #endif
std::size_t num_sub_elements() const
Definition: FiniteElement.h:207
std::shared_ptr< const ufc::finite_element > ufc_element() const
Definition: FiniteElement.h:246
double evaluate_dof(std::size_t i, const ufc::function &function, const double *coordinate_dofs, int cell_orientation, const ufc::cell &c) const
Evaluate linear functional for dof i on the function f.
Definition: FiniteElement.h:153
Definition: adapt.h:29
void evaluate_basis_derivatives_all(unsigned int n, double *values, const double *x, const double *coordinate_dofs, int cell_orientation) const
Definition: FiniteElement.h:140
std::shared_ptr< const FiniteElement > create_sub_element(std::size_t i) const
Create a new finite element for sub element i (for a mixed element)
Definition: FiniteElement.h:221
void interpolate_vertex_values(double *vertex_values, double *coefficients, const double *coordinate_dofs, int cell_orientation) const
Definition: FiniteElement.h:181
virtual ~FiniteElement()
Destructor.
Definition: FiniteElement.h:45
FiniteElement(std::shared_ptr< const ufc::finite_element > element)
Definition: FiniteElement.cpp:29
std::size_t hash() const
Return simple hash of the signature string.
Definition: FiniteElement.h:216
virtual unsigned int geometric_dimension() const
Definition: FiniteElement.h:75
A Cell is a MeshEntity of topological codimension 0.
Definition: Cell.h:42
std::shared_ptr< const FiniteElement > extract_sub_element(const std::vector< std::size_t > &component) const
Extract sub finite element for component.
Definition: FiniteElement.cpp:57
void evaluate_basis(std::size_t i, double *values, const double *x, const double *coordinate_dofs, int cell_orientation) const
Evaluate basis function i at given point in cell.
Definition: FiniteElement.h:104
std::size_t value_rank() const
Return the rank of the value space.
Definition: FiniteElement.h:90
std::shared_ptr< const FiniteElement > create() const
Create a new class instance.
Definition: FiniteElement.h:232
std::size_t space_dimension() const
Definition: FiniteElement.h:83
void evaluate_basis_all(double *values, const double *x, const double *coordinate_dofs, int cell_orientation) const
Evaluate all basis functions at given point in cell.
Definition: FiniteElement.h:114
std::size_t value_dimension(std::size_t i) const
Return the dimension of the value space for axis i.
Definition: FiniteElement.h:97
void evaluate_dofs(double *values, const ufc::function &f, const double *coordinate_dofs, int cell_orientation, const ufc::cell &c) const
Evaluate linear functionals for all dofs on the function f.
Definition: FiniteElement.h:165
std::size_t topological_dimension() const
Definition: FiniteElement.h:67
This is a wrapper for a UFC finite element (ufc::finite_element).
Definition: FiniteElement.h:35
void tabulate_dof_coordinates(boost::multi_array< double, 2 > &coordinates, const std::vector< double > &coordinate_dofs, const Cell &cell) const
Definition: FiniteElement.cpp:35
ufc::shape cell_shape() const
Definition: FiniteElement.h:59
void evaluate_basis_derivatives(unsigned int i, unsigned int n, double *values, const double *x, const double *coordinate_dofs, int cell_orientation) const
Evaluate order n derivatives of basis function i at given point in cell.
Definition: FiniteElement.h:125
std::string signature() const
Definition: FiniteElement.h:51