DOLFIN
DOLFIN C++ interface
Function.h
1 // Copyright (C) 2003-2012 Anders Logg
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 // Modified by Garth N. Wells, 2005-2010.
19 // Modified by Kristian B. Oelgaard, 2007.
20 // Modified by Martin Sandve Alnes, 2008-2014.
21 // Modified by Andre Massing, 2009.
22 
23 #ifndef __FUNCTION_H
24 #define __FUNCTION_H
25 
26 #include <memory>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 #include <boost/ptr_container/ptr_map.hpp>
31 #include <Eigen/Dense>
32 
33 #include <dolfin/common/types.h>
34 #include <dolfin/common/Hierarchical.h>
35 #include "GenericFunction.h"
36 #include "FunctionAXPY.h"
37 
38 namespace ufc
39 {
40  // Forward declarations
41  class cell;
42 }
43 
44 namespace dolfin
45 {
46 
47  // Forward declarations
48  class Cell;
49  class Expression;
50  class FunctionSpace;
51  class GenericVector;
52  class SubDomain;
53  template<typename T> class Array;
54 
64 
65  class Function : public GenericFunction, public Hierarchical<Function>
66  {
67  public:
68 
69  Function() : Hierarchical<Function>(*this) {}
70 
76  explicit Function(std::shared_ptr<const FunctionSpace> V);
77 
88  Function(std::shared_ptr<const FunctionSpace> V,
89  std::shared_ptr<GenericVector> x);
90 
98  Function(std::shared_ptr<const FunctionSpace> V,
99  std::string filename);
100 
106  Function(const Function& v);
107 
117  Function(const Function& v, std::size_t i);
118 
120  virtual ~Function();
121 
127  const Function& operator= (const Function& v);
128 
134  const Function& operator= (const Expression& v);
135 
141  void operator=(const FunctionAXPY& axpy);
142 
151  Function& operator[] (std::size_t i) const;
152 
158  virtual std::shared_ptr<const FunctionSpace> function_space() const override
159  {
160  dolfin_assert(_function_space);
161  return _function_space;
162  }
163 
169  std::shared_ptr<GenericVector> vector();
170 
176  std::shared_ptr<const GenericVector> vector() const;
177 
187  bool in(const FunctionSpace& V) const;
188 
194  std::size_t geometric_dimension() const;
195 
202  void eval(Array<double>& values, const Array<double>& x) const override;
203 
215  void eval(Array<double>& values, const Array<double>& x,
216  const Cell& dolfin_cell, const ufc::cell& ufc_cell) const;
217 
224  void eval(Eigen::Ref<Eigen::VectorXd> values,
225  Eigen::Ref<const Eigen::VectorXd> x) const override;
226 
238  void eval(Eigen::Ref<Eigen::VectorXd> values,
239  Eigen::Ref<const Eigen::VectorXd> x,
240  const dolfin::Cell& dolfin_cell, const ufc::cell& ufc_cell) const;
241 
246  void interpolate(const GenericFunction& v);
247 
253  void extrapolate(const Function& v);
254 
255  //--- Implementation of GenericFunction interface ---
256 
262  virtual std::size_t value_rank() const override;
263 
273  virtual std::size_t value_dimension(std::size_t i) const override;
274 
280  virtual std::vector<std::size_t> value_shape() const override;
281 
290  virtual void eval(Array<double>& values, const Array<double>& x,
291  const ufc::cell& cell) const override;
292 
301  virtual void eval(Eigen::Ref<Eigen::VectorXd> values,
302  Eigen::Ref<const Eigen::VectorXd> x,
303  const ufc::cell& cell) const override;
304 
317  virtual void restrict(double* w,
318  const FiniteElement& element,
319  const Cell& dolfin_cell,
320  const double* coordinate_dofs,
321  const ufc::cell& ufc_cell) const override;
322 
329  virtual void compute_vertex_values(std::vector<double>& vertex_values,
330  const Mesh& mesh) const override;
331 
336  void compute_vertex_values(std::vector<double>& vertex_values);
337 
342  void set_allow_extrapolation(bool allow_extrapolation)
343  { _allow_extrapolation = allow_extrapolation; }
344 
350  { return _allow_extrapolation; }
351 
352  private:
353 
354  // Friends
355  friend class FunctionSpace;
356  friend class FunctionAssigner;
357 
358  // Collection of sub-functions which share data with the function
359  mutable boost::ptr_map<std::size_t, Function> _sub_functions;
360 
361  // Initialize vector
362  void init_vector();
363 
364  // The function space
365  std::shared_ptr<const FunctionSpace> _function_space;
366 
367  // The vector of expansion coefficients (local)
368  std::shared_ptr<GenericVector> _vector;
369 
370  // True if extrapolation should be allowed
371  bool _allow_extrapolation;
372 
373  };
374 
375 }
376 
377 #endif
virtual std::shared_ptr< const FunctionSpace > function_space() const override
Definition: Function.h:158
Definition: Hierarchical.h:43
Definition: adapt.h:29
Definition: FunctionAXPY.h:35
Definition: FunctionSpace.h:53
Definition: Array.h:41
Definition: Extrapolation.h:34
Definition: Expression.h:49
A Cell is a MeshEntity of topological codimension 0.
Definition: Cell.h:42
bool get_allow_extrapolation() const
Definition: Function.h:349
Definition: Function.h:65
void set_allow_extrapolation(bool allow_extrapolation)
Definition: Function.h:342
Definition: GenericFunction.h:53
This is a wrapper for a UFC finite element (ufc::finite_element).
Definition: FiniteElement.h:35
Definition: Mesh.h:82
Definition: FunctionAssigner.h:40