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 &, const Real = 0)
36  { libmesh_not_implemented(); }
37
38  virtual void operator() (const Point & p,
39  const Real,
40  DenseVector<Number> & output)
41  {
42  output.zero();
43  const Real x=p(0), y=p(1), z=p(2);
44  // libMesh assumes each component of the vector-valued variable is stored
45  // contiguously.
46  output(_u_var) = soln(x, y, z)(0);
47  output(_u_var+1) = soln(x, y, z)(1);
48  output(_u_var+2) = soln(x, y, z)(2);
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), z=p(2);
56  return soln(x, y, z)(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) {}
75
76  virtual Gradient operator() (const Point &,
77  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), z=p(2);
86  output(_u_var) = soln.grad(x, y, z).row(0);
87  output(_u_var+1) = soln.grad(x, y, z).row(1);
88  output(_u_var+2) = soln.grad(x, y, z).row(2);
89  }
90
91  virtual Gradient component(unsigned int component_in,
92  const Point & p,
93  const Real)
94  {
95  const Real x=p(0), y=p(1), z=p(2);
97  }
98
101
102 private:
103
104  const unsigned int _u_var;
106 };
107
108 #endif // SOLUTION_FUNCTION_H
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