libMesh
Loading...
Searching...
No Matches
solution_function.h
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#ifndef SOLUTION_FUNCTION_H
19#define SOLUTION_FUNCTION_H
20
21// libMesh includes
22#include "libmesh/function_base.h"
23
24// Example includes
25#include "curl_curl_exact_solution.h"
26
27// C++ includes
28#include <memory>
29
30using namespace libMesh;
31
32class SolutionFunction : public FunctionBase<Number>
33{
34public:
35
36 SolutionFunction(const unsigned int u_var)
37 : _u_var(u_var) {}
38
39 ~SolutionFunction() = default;
40
41 virtual Number operator() (const Point &,
42 const Real = 0)
43 { libmesh_not_implemented(); }
44
45 virtual void operator() (const Point & p,
46 const Real,
47 DenseVector<Number> & output)
48 {
49 output.zero();
50 // libMesh assumes each component of the vector-valued variable is stored
51 // contiguously.
52 output(_u_var) = soln(p)(0);
53 output(_u_var+1) = soln(p)(1);
54 output(_u_var+2) = soln(p)(2);
55 }
56
57 virtual Number component(unsigned int component_in,
58 const Point & p,
59 const Real)
60 {
61 return soln(p)(component_in);
62 }
63
64 virtual std::unique_ptr<FunctionBase<Number>> clone() const
65 { return std::make_unique<SolutionFunction>(_u_var); }
66
67private:
68
69 const unsigned int _u_var;
71};
72
73class SolutionGradient : public FunctionBase<Gradient>
74{
75public:
76
77 SolutionGradient(const unsigned int u_var)
78 : _u_var(u_var) {}
79
80 ~SolutionGradient() = default;
81
82 virtual Gradient operator() (const Point &, const Real = 0)
83 { libmesh_not_implemented(); }
84
85 virtual void operator() (const Point & p,
86 const Real,
87 DenseVector<Gradient> & output)
88 {
89 output.zero();
90 output(_u_var) = soln.grad(p).row(0);
91 output(_u_var+1) = soln.grad(p).row(1);
92 output(_u_var+2) = soln.grad(p).row(2);
93 }
94
95 virtual Gradient component(unsigned int component_in, const Point & p,
96 const Real)
97 {
98 return soln.grad(p).row(component_in);
99 }
100
101 virtual std::unique_ptr<FunctionBase<Gradient>> clone() const
102 { return std::make_unique<SolutionGradient>(_u_var); }
103
104private:
105
106 const unsigned int _u_var;
108};
109
110#endif // SOLUTION_FUNCTION_H
virtual Number operator()(const Point &, const Real=0)
virtual std::unique_ptr< FunctionBase< Number > > clone() const
CurlCurlExactSolution soln
const unsigned int _u_var
SolutionFunction(const unsigned int u_var)
GradDivExactSolution soln
virtual Number component(unsigned int component_in, const Point &p, const Real)
~SolutionFunction()=default
const unsigned int _u_var
~SolutionGradient()=default
GradDivExactSolution soln
SolutionGradient(const unsigned int u_var)
virtual Gradient component(unsigned int component_in, const Point &p, const Real)
virtual Gradient operator()(const Point &, const Real=0)
virtual std::unique_ptr< FunctionBase< Gradient > > clone() const
CurlCurlExactSolution soln
Defines a dense vector for use in Finite Element-type computations.
virtual void zero() override final
Set every element in the vector to 0.
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
TypeVector< T > row(const unsigned int r) const
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.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real