libMesh
mesh_function.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 #include <memory>
35 
36 namespace libMesh
37 {
38 
39 
40 // Forward Declarations
41 template <typename T> class DenseVector;
42 class EquationSystems;
43 template <typename T> class NumericVector;
44 class DofMap;
45 class PointLocatorBase;
46 
54 class MeshFunction : public FunctionBase<Number>,
55  public ParallelObject
56 {
57 public:
58 
67  MeshFunction (const EquationSystems & eqn_systems,
68  const NumericVector<Number> & vec,
69  const DofMap & dof_map,
70  std::vector<unsigned int> vars,
71  const FunctionBase<Number> * master=nullptr);
72 
81  MeshFunction (const EquationSystems & eqn_systems,
82  const NumericVector<Number> & vec,
83  const DofMap & dof_map,
84  const unsigned int var,
85  const FunctionBase<Number> * master=nullptr);
86 
90  MeshFunction (const MeshFunction & mf);
91 
98  MeshFunction (MeshFunction &&) = default;
99  MeshFunction & operator= (const MeshFunction &) = delete;
100  MeshFunction & operator= (MeshFunction &&) = delete;
101 
105  ~MeshFunction ();
106 
110  virtual void init () override;
111 
112 #ifdef LIBMESH_ENABLE_DEPRECATED
113 
121  void init (const Trees::BuildType point_locator_build_type);
122 #endif // LIBMESH_ENABLE_DEPRECATED
123 
127  virtual void clear () override;
128 
138  virtual std::unique_ptr<FunctionBase<Number>> clone () const override;
139 
144  virtual Number operator() (const Point & p,
145  const Real time=0.) override;
146 
155  std::map<const Elem *, Number> discontinuous_value (const Point & p,
156  const Real time=0.);
157 
162  Gradient gradient (const Point & p,
163  const Real time=0.);
164 
171  std::map<const Elem *, Gradient> discontinuous_gradient (const Point & p,
172  const Real time=0.);
173 
174 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
175 
179  Tensor hessian (const Point & p,
180  const Real time=0.);
181 #endif
182 
189  virtual void operator() (const Point & p,
190  const Real time,
191  DenseVector<Number> & output) override;
192 
198  void operator() (const Point & p,
199  const Real time,
200  DenseVector<Number> & output,
201  const std::set<subdomain_id_type> * subdomain_ids);
202 
208  void discontinuous_value (const Point & p,
209  const Real time,
210  std::map<const Elem *, DenseVector<Number>> & output);
211 
217  void discontinuous_value (const Point & p,
218  const Real time,
219  std::map<const Elem *, DenseVector<Number>> & output,
220  const std::set<subdomain_id_type> * subdomain_ids);
221 
227  void gradient (const Point & p,
228  const Real time,
229  std::vector<Gradient> & output);
230 
237  void gradient (const Point & p,
238  const Real time,
239  std::vector<Gradient> & output,
240  const std::set<subdomain_id_type> * subdomain_ids);
241 
247  void discontinuous_gradient (const Point & p,
248  const Real time,
249  std::map<const Elem *, std::vector<Gradient>> & output);
250 
256  void discontinuous_gradient (const Point & p,
257  const Real time,
258  std::map<const Elem *, std::vector<Gradient>> & output,
259  const std::set<subdomain_id_type> * subdomain_ids);
260 
266  void hessian (const Point & p,
267  const Real time,
268  std::vector<Tensor> & output);
269 
276  void hessian (const Point & p,
277  const Real time,
278  std::vector<Tensor> & output,
279  const std::set<subdomain_id_type> * subdomain_ids);
280 
287  const PointLocatorBase & get_point_locator () const;
289 
301 
312  void enable_out_of_mesh_mode(const Number & value);
313 
318 
326 
331 
339  void set_subdomain_ids(const std::set<subdomain_id_type> * subdomain_ids);
340 
341 protected:
342 
346  const Elem * find_element(const Point & p,
347  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
348 
355  std::set<const Elem *> find_elements(const Point & p,
356  const std::set<subdomain_id_type> * subdomain_ids = nullptr) const;
357 
364  const Elem * check_found_elem(const Elem * element, const Point & p) const;
365 
370  void _gradient_on_elem (const Point & p,
371  const Elem * element,
372  std::vector<Gradient> & output);
373 
379 
385 
389  const DofMap & _dof_map;
390 
395  const std::vector<unsigned int> _system_vars;
396 
401  std::unique_ptr<PointLocatorBase> _point_locator;
402 
406  std::unique_ptr<std::set<subdomain_id_type>> _subdomain_ids;
407 
413 
419 };
420 
421 
422 } // namespace libMesh
423 
424 
425 #endif // LIBMESH_MESH_FUNCTION_H
std::unique_ptr< std::set< subdomain_id_type > > _subdomain_ids
A default set of subdomain ids in which to search for points.
This is the EquationSystems class.
const EquationSystems & _eqn_systems
The equation systems handler, from which the data are gathered.
virtual std::unique_ptr< FunctionBase< Number > > clone() const override
BuildType
enum defining how to build the tree.
Definition: tree_base.h:58
const NumericVector< Number > & _vector
A reference to the vector that holds the data that is to be interpolated.
bool _out_of_mesh_mode
true if out-of-mesh mode is enabled.
MeshFunction & operator=(const MeshFunction &)=delete
const DofMap & _dof_map
Need access to the DofMap of the other system.
const Elem * find_element(const Point &p, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
Helper function to reduce code duplication.
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
Gradient gradient(const Point &p, const Real time=0.)
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
~MeshFunction()
Destructor.
The libMesh namespace provides an interface to certain functionality in the library.
void disable_out_of_mesh_mode()
Disables out-of-mesh mode.
void _gradient_on_elem(const Point &p, const Elem *element, std::vector< Gradient > &output)
Helper function for finding a gradient as evaluated from a specific element.
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:179
DenseVector< Number > _out_of_mesh_value
Value to return outside the mesh if out-of-mesh mode is enabled.
void enable_out_of_mesh_mode(const DenseVector< Number > &value)
Enables out-of-mesh mode.
virtual void clear() override
Clears the function.
std::set< const Elem * > find_elements(const Point &p, const std::set< subdomain_id_type > *subdomain_ids=nullptr) const
std::map< const Elem *, Number > discontinuous_value(const Point &p, const Real time=0.)
void unset_point_locator_tolerance()
Turn off the user-specified PointLocator tolerance.
virtual void init() override
Override the FunctionBase::init() member function.
const PointLocatorBase & get_point_locator() const
This is the base class for point locators.
An object whose state is distributed along a set of processors.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Number operator()(const Point &p, const Real time=0.) override
MeshFunction(const EquationSystems &eqn_systems, const NumericVector< Number > &vec, const DofMap &dof_map, 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
static const bool value
Definition: xdr_io.C:54
This class provides function-like objects for data distributed over a mesh.
Definition: mesh_function.h:54
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...
const Elem * check_found_elem(const Elem *element, const Point &p) const
Helper function that is called by MeshFunction::find_element() and MeshFunction::find_elements() to e...
Base class for functors that can be evaluated at a point and (optionally) time.
std::map< const Elem *, Gradient > discontinuous_gradient(const Point &p, const Real time=0.)
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
Tensor hessian(const Point &p, const Real time=0.)
void set_subdomain_ids(const std::set< subdomain_id_type > *subdomain_ids)
Choose a default list of subdomain ids to be searched for points.
std::unique_ptr< PointLocatorBase > _point_locator
A point locator is needed to locate the points in the mesh.
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
const std::vector< unsigned int > _system_vars
The indices of the variables within the other system for which data are to be gathered.