libMesh
factoryfunction.C
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 // libMesh includes
21 #include "libmesh/dense_vector.h"
22 #include "libmesh/factory.h"
23 #include "libmesh/function_base.h"
24 #include "libmesh/auto_ptr.h" // libmesh_make_unique
25 
26 using namespace libMesh;
27 
28 // An example of a hand-coded function
29 
30 class ExampleOneFunction : public FunctionBase<Number>
31 {
32  virtual Number operator() (const Point & /*p*/,
33  const Real /*time*/)
34  {
35  return 1;
36  }
37 
38  virtual void operator() (const Point & /*p*/,
39  const Real /*time*/,
40  DenseVector<Number> & output)
41  {
42  for (unsigned int i=0; i != output.size(); ++i)
43  output(i) = 1;
44  }
45 
46  virtual void init() {}
47  virtual void clear() {}
48  virtual std::unique_ptr<FunctionBase<Number>> clone() const
49  {
50  return libmesh_make_unique<ExampleOneFunction>();
51  }
52 };
53 
54 #ifdef LIBMESH_USE_SEPARATE_NAMESPACE
55 namespace libMesh {
56 #endif
57 
58 //-------------------------------------------------
59 // Full specialization for the Factory<FunctionBase<Number>>
60 // So we can look up hand-coded functions by name string
61 template<>
62 std::map<std::string, Factory<FunctionBase<Number>> *> &
64 {
65  static std::map<std::string, Factory<FunctionBase<Number>> *> _map;
66  return _map;
67 }
68 
70 
71 #ifdef LIBMESH_USE_SEPARATE_NAMESPACE
72 } // namespace libMesh
73 #endif
ExampleOneFunction::init
virtual void init()
The actual initialization process.
Definition: factoryfunction.C:46
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
ExampleOneFunction::clone
virtual std::unique_ptr< FunctionBase< Number > > clone() const
Definition: factoryfunction.C:48
libMesh::example_one_factory
FactoryImp< ExampleOneFunction, FunctionBase< Number > > example_one_factory("example_one")
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::Factory
Factory class definition.
Definition: factory.h:46
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::DenseVector::size
virtual unsigned int size() const override
Definition: dense_vector.h:92
ExampleOneFunction::clear
virtual void clear()
Clears the function.
Definition: factoryfunction.C:47
libMesh::FactoryImp
Factory implementation class.
Definition: factory.h:88
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
ExampleOneFunction
Definition: factoryfunction.C:30
libMesh::DenseVector< Number >