libMesh
Loading...
Searching...
No Matches
factoryfunction.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
27using namespace libMesh;
28
29// An example of a hand-coded function
30
31class 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
56namespace 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
62template<>
63std::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 std::unique_ptr< FunctionBase< Number > > clone() const
virtual void init()
The actual initialization process.
virtual void clear()
Clears the function.
virtual Number operator()(const Point &, const Real)
Defines a dense vector for use in Finite Element-type computations.
virtual unsigned int size() const override final
Factory implementation class.
Definition factory.h:89
Factory class definition.
Definition factory.h:47
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:40
The libMesh namespace provides an interface to certain functionality in the library.
FactoryImp< ExampleOneFunction, FunctionBase< Number > > example_one_factory("example_one")
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real