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
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 const Real x=p(0), y=p(1), z=p(2);
51 // libMesh assumes each component of the vector-valued variable is stored
52 // contiguously.
53 output(_u_var) = soln(0, x, y, z);
54 output(_u_var+1) = soln(1, x, y, z);
55 output(_u_var+2) = soln(2, x, y, z);
56 }
57
58 virtual Number component(unsigned int component_in,
59 const Point & p,
60 const Real)
61 {
62 const Real x=p(0), y=p(1), z=p(2);
63 return soln(component_in, x, y, z);
64 }
65
66 virtual std::unique_ptr<FunctionBase<Number>> clone() const
67 { return std::make_unique<SolutionFunction>(_u_var); }
68
69private:
70
71 const unsigned int _u_var;
73};
74
75//FIXME: PB: We ought to be able to merge the above class with this one
76// through templating, but I'm being lazy.
77class SolutionGradient : public FunctionBase<Gradient>
78{
79public:
80
81 SolutionGradient(const unsigned int u_var)
82 : _u_var(u_var) {}
83 ~SolutionGradient() = default;
84
85 virtual Gradient operator() (const Point &, const Real = 0)
86 { libmesh_not_implemented(); }
87
88 virtual void operator() (const Point & p,
89 const Real,
91 {
92 output.zero();
93 const Real x=p(0), y=p(1), z=p(2);
94 output(_u_var) = soln(0, x, y, z);
95 output(_u_var+1) = soln(1, x, y, z);
96 output(_u_var+2) = soln(2, x, y, z);
97 }
98
99 virtual Gradient component(unsigned int component_in,
100 const Point & p,
101 const Real)
102 {
103 const Real x=p(0), y=p(1), z=p(2);
104 return soln(component_in, x, y, z);
105 }
106
107 virtual std::unique_ptr<FunctionBase<Gradient>> clone() const
108 { return std::make_unique<SolutionGradient>(_u_var); }
109
110private:
111
112 const unsigned int _u_var;
114};
115
116#endif // SOLUTION_FUNCTION_H
virtual Number operator()(const Point &, const Real=0)
virtual std::unique_ptr< FunctionBase< Number > > clone() const
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)
LaplaceExactSolution soln
~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
LaplaceExactGradient 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
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