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