libMesh
mesh_function.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_MESH_FUNCTION_H
21 #define LIBMESH_MESH_FUNCTION_H
22 
23 // Local Includes
24 #include "libmesh/function_base.h"
25 #include "libmesh/dense_vector.h"
26 #include "libmesh/vector_value.h"
27 #include "libmesh/tensor_value.h"
28 #include "libmesh/tree_base.h"
29 #include "libmesh/parallel_object.h"
30 
31 // C++ includes
32 #include <cstddef>
33 #include <vector>
34 
35 namespace libMesh
36 {
37 
38 
39 // Forward Declarations
40 template <typename T> class DenseVector;
41 class EquationSystems;
42 template <typename T> class NumericVector;
43 class DofMap;
44 class PointLocatorBase;
45 
53 class MeshFunction : public FunctionBase<Number>,
54  public ParallelObject
55 {
56 public:
57 
66  MeshFunction (const EquationSystems & eqn_systems,
67  const NumericVector<Number> & vec,
68  const DofMap & dof_map,
69  const std::vector<unsigned int> & vars,
70  const FunctionBase<Number> * master=nullptr);
71 
80  MeshFunction (const EquationSystems & eqn_systems,
81  const NumericVector<Number> & vec,
82  const DofMap & dof_map,
83  const unsigned int var,
84  const FunctionBase<Number> * master=nullptr);
85 
91  MeshFunction (MeshFunction &&) = delete;
92  MeshFunction (const MeshFunction &) = delete;
93 
97  MeshFunction & operator= (const MeshFunction &) = delete;
98  MeshFunction & operator= (MeshFunction &&) = delete;
99 
103  ~MeshFunction ();
104 
110  virtual void init () override { this->init(Trees::NODES); }
111 
116  void init (const Trees::BuildType point_locator_build_type);
117 
121  virtual void clear () override;
122 
132  virtual std::unique_ptr<FunctionBase<Number>> clone () const override;
133 
138  Number operator() (const Point & p,
139  const Real time=0.) override;
140 
149  std::map<const Elem *, Number> discontinuous_value (const Point & p,
150  const Real time=0.);
151 
156  Gradient gradient (const Point & p,
157  const Real time=0.);
158 
165  std::map<const Elem *, Gradient> discontinuous_gradient (const Point & p,
166  const Real time=0.);
167 
168 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
169 
173  Tensor hessian (const Point & p,
174  const Real time=0.);
175 #endif
176 
183  void operator() (const Point & p,
184  const Real time,
185  DenseVector<Number> & output) override;
186 
192  void operator() (const Point & p,
193  const Real time,
194  DenseVector<Number> & output,
195  const std::set<subdomain_id_type> * subdomain_ids);
196 
202  void discontinuous_value (const Point & p,
203  const Real time,
204  std::map<const Elem *, DenseVector<Number>> & output);
205 
211  void discontinuous_value (const Point & p,
212  const Real time,
213  std::map<const Elem *, DenseVector<Number>> & output,
214  const std::set<subdomain_id_type> * subdomain_ids);
215 
222  void gradient (const Point & p,
223  const Real time,
224  std::vector<Gradient> & output,
225  const std::set<subdomain_id_type> * subdomain_ids = nullptr);
226 
232  void discontinuous_gradient (const Point & p,
233  const Real time,
234  std::map<const Elem *, std::vector<Gradient>> & output);
235 
241  void discontinuous_gradient (const Point & p,
242  const Real time,
243  std::map<const Elem *, std::vector<Gradient>> & output,
244  const std::set<subdomain_id_type> * subdomain_ids);
245 
252  void hessian (const Point & p,
253  const Real time,
254  std::vector<Tensor> & output,
255  const std::set<subdomain_id_type> * subdomain_ids = nullptr);
256 
263  const PointLocatorBase & get_point_locator (void) const;
264 
276 
287  void enable_out_of_mesh_mode(const Number & value);
288 
292  void disable_out_of_mesh_mode(void);
293 
301 
306 
307 protected:
308 
312  const Elem * find_element(const Point & p,
313  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
314 
321  std::set<const Elem *> find_elements(const Point & p,
322  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
323 
329 
335 
339  const DofMap & _dof_map;
340 
345  const std::vector<unsigned int> _system_vars;
346 
352 
358 
364 };
365 
366 
367 
368 
369 // ------------------------------------------------------------
370 // MeshFunction inline methods
371 
372 
373 } // namespace libMesh
374 
375 
376 #endif // LIBMESH_MESH_FUNCTION_H
libMesh::MeshFunction::find_element
const Elem * find_element(const Point &p, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
Helper function to reduce code duplication.
Definition: mesh_function.C:700
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::FunctionBase
Base class for functors that can be evaluated at a point and (optionally) time.
Definition: dirichlet_boundaries.h:44
libMesh::MeshFunction::_out_of_mesh_value
DenseVector< Number > _out_of_mesh_value
Value to return outside the mesh if out-of-mesh mode is enabled.
Definition: mesh_function.h:363
libMesh::MeshFunction::init
virtual void init() override
Override the FunctionBase::init() member function by calling our own and specifying the Trees::NODES ...
Definition: mesh_function.h:110
libMesh::MeshFunction::operator()
Number operator()(const Point &p, const Real time=0.) override
Definition: mesh_function.C:149
libMesh::MeshFunction
This class provides function-like objects for data distributed over a mesh.
Definition: mesh_function.h:53
libMesh::MeshFunction::find_elements
std::set< const Elem * > find_elements(const Point &p, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
Definition: mesh_function.C:744
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::MeshFunction::discontinuous_gradient
std::map< const Elem *, Gradient > discontinuous_gradient(const Point &p, const Real time=0.)
Definition: mesh_function.C:184
libMesh::MeshFunction::clone
virtual std::unique_ptr< FunctionBase< Number > > clone() const override
Definition: mesh_function.C:134
libMesh::MeshFunction::discontinuous_value
std::map< const Elem *, Number > discontinuous_value(const Point &p, const Real time=0.)
Definition: mesh_function.C:159
libMesh::MeshFunction::operator=
MeshFunction & operator=(const MeshFunction &)=delete
This class contains const references so it can't be assigned.
libMesh::Trees::BuildType
BuildType
enum defining how to build the tree.
Definition: tree_base.h:55
libMesh::MeshFunction::hessian
Tensor hessian(const Point &p, const Real time=0.)
Definition: mesh_function.C:200
libMesh::MeshFunction::get_point_locator
const PointLocatorBase & get_point_locator(void) const
Definition: mesh_function.C:793
libMesh::VectorValue
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
Definition: exact_solution.h:54
libMesh::NumericVector< Number >
libMesh::MeshFunction::set_point_locator_tolerance
void set_point_locator_tolerance(Real tol)
We may want to specify a tolerance for the PointLocator to use, since in some cases the point we want...
Definition: mesh_function.C:821
libMesh::MeshFunction::enable_out_of_mesh_mode
void enable_out_of_mesh_mode(const DenseVector< Number > &value)
Enables out-of-mesh mode.
Definition: mesh_function.C:799
libMesh::TensorValue
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
Definition: exact_solution.h:53
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::MeshFunction::_point_locator
PointLocatorBase * _point_locator
A point locator is needed to locate the points in the mesh.
Definition: mesh_function.h:351
libMesh::MeshFunction::_eqn_systems
const EquationSystems & _eqn_systems
The equation systems handler, from which the data are gathered.
Definition: mesh_function.h:328
libMesh::MeshFunction::~MeshFunction
~MeshFunction()
Destructor.
Definition: mesh_function.C:87
libMesh::MeshFunction::unset_point_locator_tolerance
void unset_point_locator_tolerance()
Turn off the user-specified PointLocator tolerance.
Definition: mesh_function.C:826
libMesh::MeshFunction::_dof_map
const DofMap & _dof_map
Need access to the DofMap of the other system.
Definition: mesh_function.h:339
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::MeshFunction::_vector
const NumericVector< Number > & _vector
A reference to the vector that holds the data that is to be interpolated.
Definition: mesh_function.h:334
value
static const bool value
Definition: xdr_io.C:56
libMesh::MeshFunction::_out_of_mesh_mode
bool _out_of_mesh_mode
true if out-of-mesh mode is enabled.
Definition: mesh_function.h:357
libMesh::DofMap
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:176
libMesh::MeshFunction::disable_out_of_mesh_mode
void disable_out_of_mesh_mode(void)
Disables out-of-mesh mode.
Definition: mesh_function.C:814
libMesh::MeshFunction::_system_vars
const std::vector< unsigned int > _system_vars
The indices of the variables within the other system for which data are to be gathered.
Definition: mesh_function.h:345
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::Trees::NODES
Definition: tree_base.h:55
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::ParallelObject
An object whose state is distributed along a set of processors.
Definition: parallel_object.h:55
libMesh::PointLocatorBase
This is the base class for point locators.
Definition: point_locator_base.h:62
libMesh::MeshFunction::clear
virtual void clear() override
Clears the function.
Definition: mesh_function.C:121
libMesh::MeshFunction::MeshFunction
MeshFunction(const EquationSystems &eqn_systems, const NumericVector< Number > &vec, const DofMap &dof_map, const std::vector< unsigned int > &vars, const FunctionBase< Number > *master=nullptr)
Constructor for mesh based functions with vectors as return value.
Definition: mesh_function.C:42
libMesh::MeshFunction::gradient
Gradient gradient(const Point &p, const Real time=0.)
Definition: mesh_function.C:174
libMesh::DenseVector< Number >