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
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 #include "libmesh/function_base.h"
19 #include "laplace_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), z=p(2);
45  // libMesh assumes each component of the vector-valued variable is stored
46  // contiguously.
47  output(_u_var) = soln(0, x, y, z);
48  output(_u_var+1) = soln(1, x, y, z);
49  output(_u_var+2) = soln(2, x, y, z);
50  }
51 
52  virtual Number component(unsigned int component_in,
53  const Point & p,
54  const Real)
55  {
56  const Real x=p(0), y=p(1), z=p(2);
57  return soln(component_in, x, y, z);
58  }
59 
61  { return UniquePtr<FunctionBase<Number>> (new SolutionFunction(_u_var)); }
62 
63 private:
64 
65  const unsigned int _u_var;
67 };
68 
69 //FIXME: PB: We ought to be able to merge the above class with this one
70 // through templating, but I'm being lazy.
71 class SolutionGradient : public FunctionBase<Gradient>
72 {
73 public:
74 
75  SolutionGradient(const unsigned int u_var)
76  : _u_var(u_var) {}
78 
79  virtual Gradient operator() (const Point &, const Real = 0)
80  { libmesh_not_implemented(); }
81 
82  virtual void operator() (const Point & p,
83  const Real,
84  DenseVector<Gradient>& output)
85  {
86  output.zero();
87  const Real x=p(0), y=p(1), z=p(2);
88  output(_u_var) = soln(0, x, y, z);
89  output(_u_var+1) = soln(1, x, y, z);
90  output(_u_var+2) = soln(2, x, y, z);
91  }
92 
93  virtual Gradient component(unsigned int component_in,
94  const Point & p,
95  const Real)
96  {
97  const Real x=p(0), y=p(1), z=p(2);
98  return soln(component_in, x, y, z);
99  }
100 
102  { return UniquePtr<FunctionBase<Gradient>> (new SolutionGradient(_u_var)); }
103 
104 private:
105 
106  const unsigned int _u_var;
108 };
109 
110 #endif // SOLUTION_FUNCTION_H
const unsigned int _u_var
LaplaceExactGradient soln
virtual void zero() libmesh_override
Set every element in the vector to 0.
Definition: dense_vector.h:374
const unsigned int _u_var
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
SolutionGradient(const unsigned int u_var)
This is the base class for functor-like classes.
LaplaceExactSolution soln
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38