libMesh
solution_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 #ifndef SOLUTION_FUNCTION_H
19 #define SOLUTION_FUNCTION_H
20 
21 // libMesh includes
22 #include "libmesh/function_base.h"
23 
24 // Example includes
26 
27 // C++ includes
28 #include <memory>
29 
30 using namespace libMesh;
31 
32 class SolutionFunction : public FunctionBase<Number>
33 {
34 public:
35 
36  SolutionFunction() = default;
37  ~SolutionFunction() = default;
38 
39  virtual Number operator() (const Point &,
40  const Real = 0)
41  { libmesh_not_implemented(); }
42 
43  virtual void operator() (const Point & p,
44  const Real,
45  DenseVector<Number> & output)
46  {
47  output.zero();
48  output(0) = soln(p)(0);
49  output(1) = soln(p)(1);
50  output(2) = soln(p)(2);
51  }
52 
53  virtual Number component(unsigned int component_in,
54  const Point & p,
55  const Real)
56  {
57  DenseVector<Number> outvec(3);
58  (*this)(p, 0, outvec);
59  return outvec(component_in);
60  }
61 
62  virtual std::unique_ptr<FunctionBase<Number>> clone() const
63  { return std::make_unique<SolutionFunction>(); }
64 
65 private:
66 
68 };
69 
70 class SolutionGradient : public FunctionBase<Gradient>
71 {
72 public:
73 
74  SolutionGradient() = default;
75  ~SolutionGradient() = default;
76 
77  virtual Gradient operator() (const Point &, const Real = 0)
78  { libmesh_not_implemented(); }
79 
80  virtual void operator() (const Point & p,
81  const Real,
82  DenseVector<Gradient> & output)
83  {
84  output.zero();
85  output(0) = soln.grad(p).row(0);
86  output(1) = soln.grad(p).row(1);
87  output(2) = soln.grad(p).row(2);
88  }
89 
90  virtual Gradient component(unsigned int component_in,
91  const Point & p,
92  const Real)
93  {
94  DenseVector<Gradient> outvec(3);
95  (*this)(p, 0, outvec);
96  return outvec(component_in);
97  }
98 
99  virtual std::unique_ptr<FunctionBase<Gradient>> clone() const
100  { return std::make_unique<SolutionGradient>(); }
101 
102 private:
103 
105 };
106 
107 #endif // SOLUTION_FUNCTION_H
virtual Number component(unsigned int component_in, const Point &p, const Real)
virtual std::unique_ptr< FunctionBase< Gradient > > clone() const
virtual void zero() override final
Set every element in the vector to 0.
Definition: dense_vector.h:420
virtual std::unique_ptr< FunctionBase< Number > > clone() const
virtual Gradient component(unsigned int component_in, const Point &p, const Real)
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
The libMesh namespace provides an interface to certain functionality in the library.
GradDivExactSolution soln
GradDivExactSolution soln
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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