libMesh
factoryfunction.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 
25 using namespace libMesh;
26 
27 // An example of a hand-coded function
28 
29 class ExampleOneFunction : public FunctionBase<Number>
30 {
31  virtual Number operator() (const Point & /*p*/,
32  const Real /*time*/)
33  {
34  return 1;
35  }
36 
37  virtual void operator() (const Point & /*p*/,
38  const Real /*time*/,
39  DenseVector<Number> & output)
40  {
41  for (unsigned int i=0; i != output.size(); ++i)
42  output(i) = 1;
43  }
44 
45  virtual void init() {}
46  virtual void clear() {}
48  {
50  }
51 };
52 
53 #ifdef LIBMESH_USE_SEPARATE_NAMESPACE
54 namespace libMesh {
55 #endif
56 
57 //-------------------------------------------------
58 // Full specialization for the Factory<FunctionBase<Number>>
59 // So we can look up hand-coded functions by name string
60 template<>
61 std::map<std::string, Factory<FunctionBase<Number>> *> &
63 {
64  static std::map<std::string, Factory<FunctionBase<Number>> *> _map;
65  return _map;
66 }
67 
69 
70 #ifdef LIBMESH_USE_SEPARATE_NAMESPACE
71 } // namespace libMesh
72 #endif
virtual UniquePtr< FunctionBase< Number > > clone() const
virtual void init()
The actual initialization process.
The libMesh namespace provides an interface to certain functionality in the library.
virtual unsigned int size() const libmesh_override
Definition: dense_vector.h:87
Factory implementation class.
Definition: factory.h:88
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
Factory class definition.
Definition: factory.h:46
virtual void clear()
Clears the function.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This is the base class for functor-like classes.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
FactoryImp< ExampleOneFunction, FunctionBase< Number > > example_one_factory("example_one")