libMesh
solution_function.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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
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 #include "libmesh/function_base.h"
19 #include "curl_curl_exact_solution.h"
20
21 using namespace libMesh;
22
23 #ifndef SOLUTION_FUNCTION_H
24 #define SOLUTION_FUNCTION_H
25
26 class SolutionFunction : public FunctionBase<Number>
27 {
28 public:
29
30  SolutionFunction(const unsigned int u_var)
31  : _u_var(u_var) {}
32
34
35  virtual Number operator() (const Point &,
36  const Real = 0)
37  { libmesh_not_implemented(); }
38
39  virtual void operator() (const Point & p,
40  const Real,
41  DenseVector<Number> & output)
42  {
43  output.zero();
44  const Real x=p(0), y=p(1);
45  // libMesh assumes each component of the vector-valued variable is stored
46  // contiguously.
47  output(_u_var) = soln(x, y)(0);
48  output(_u_var+1) = soln(x, y)(1);
49  }
50
51  virtual Number component(unsigned int component_in,
52  const Point & p,
53  const Real)
54  {
55  const Real x=p(0), y=p(1);
56  return soln(x, y)(component_in);
57  }
58
60  { return UniquePtr<FunctionBase<Number>> (new SolutionFunction(_u_var)); }
61
62 private:
63
64  const unsigned int _u_var;
66 };
67
69 {
70 public:
71
73  : _u_var(u_var) {}
74
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,
83  {
84  output.zero();
85  const Real x=p(0), y=p(1);
88  }
89
90  virtual Gradient component(unsigned int component_in, const Point & p,
91  const Real)
92  {
93  const Real x=p(0), y=p(1);
95  }
96
99
100 private:
101
102  const unsigned int _u_var;
104 };
105
106 #endif // SOLUTION_FUNCTION_H
CurlCurlExactSolution soln
virtual void zero() libmesh_override
Set every element in the vector to 0.
Definition: dense_vector.h:374
virtual UniquePtr< FunctionBase< Number > > clone() const
SolutionFunction(const unsigned int u_var)
The libMesh namespace provides an interface to certain functionality in the library.
virtual Gradient component(unsigned int component_in, const Point &p, const Real)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual UniquePtr< FunctionBase< Gradient > > clone() const
PetscErrorCode Vec x
virtual Number component(unsigned int component_in, const Point &p, const Real)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real