libMesh
solution_function.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 // libMesh includes
19 #include "libmesh/function_base.h"
20 #include "libmesh/auto_ptr.h" // libmesh_make_unique
21 
22 // Example includes
23 #include "curl_curl_exact_solution.h"
24 
25 using namespace libMesh;
26 
27 #ifndef SOLUTION_FUNCTION_H
28 #define SOLUTION_FUNCTION_H
29 
30 class SolutionFunction : public FunctionBase<Number>
31 {
32 public:
33 
34  SolutionFunction(const unsigned int u_var)
35  : _u_var(u_var) {}
36 
38 
39  virtual Number operator() (const Point &,
40  const Real = 0)
41  { libmesh_not_implemented(); }
42 
43  virtual void operator() (const Point & p,
44  const Real,
45  DenseVector<Number> & output)
46  {
47  output.zero();
48  const Real x=p(0), y=p(1);
49  // libMesh assumes each component of the vector-valued variable is stored
50  // contiguously.
51  output(_u_var) = soln(x, y)(0);
52  output(_u_var+1) = soln(x, y)(1);
53  }
54 
55  virtual Number component(unsigned int component_in,
56  const Point & p,
57  const Real)
58  {
59  const Real x=p(0), y=p(1);
60  return soln(x, y)(component_in);
61  }
62 
63  virtual std::unique_ptr<FunctionBase<Number>> clone() const
64  { return libmesh_make_unique<SolutionFunction>(_u_var); }
65 
66 private:
67 
68  const unsigned int _u_var;
70 };
71 
72 class SolutionGradient : public FunctionBase<Gradient>
73 {
74 public:
75 
76  SolutionGradient(const unsigned int u_var)
77  : _u_var(u_var) {}
78 
80 
81  virtual Gradient operator() (const Point &, const Real = 0)
82  { libmesh_not_implemented(); }
83 
84  virtual void operator() (const Point & p,
85  const Real,
86  DenseVector<Gradient> & output)
87  {
88  output.zero();
89  const Real x=p(0), y=p(1);
90  output(_u_var) = soln.grad(x, y).row(0);
91  output(_u_var+1) = soln.grad(x, y).row(1);
92  }
93 
94  virtual Gradient component(unsigned int component_in, const Point & p,
95  const Real)
96  {
97  const Real x=p(0), y=p(1);
98  return soln.grad(x, y).row(component_in);
99  }
100 
101  virtual std::unique_ptr<FunctionBase<Gradient>> clone() const
102  { return libmesh_make_unique<SolutionGradient>(_u_var); }
103 
104 private:
105 
106  const unsigned int _u_var;
108 };
109 
110 #endif // SOLUTION_FUNCTION_H
SolutionGradient::component
virtual Gradient component(unsigned int component_in, const Point &p, const Real)
Definition: solution_function.h:94
SolutionFunction::component
virtual Number component(unsigned int component_in, const Point &p, const Real)
Definition: solution_function.h:55
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::FunctionBase
Base class for functors that can be evaluated at a point and (optionally) time.
Definition: dirichlet_boundaries.h:44
SolutionGradient
Definition: solution_function.h:75
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::DenseVector::zero
virtual void zero() override
Set every element in the vector to 0.
Definition: dense_vector.h:379
SolutionGradient::clone
virtual std::unique_ptr< FunctionBase< Gradient > > clone() const
Definition: solution_function.h:101
SolutionFunction::clone
virtual std::unique_ptr< FunctionBase< Number > > clone() const
Definition: solution_function.h:63
libMesh::VectorValue< Number >
SolutionGradient::SolutionGradient
SolutionGradient(const unsigned int u_var)
Definition: solution_function.h:76
SolutionFunction::soln
CurlCurlExactSolution soln
Definition: solution_function.h:69
SolutionFunction
Definition: solution_function.h:30
SolutionGradient::~SolutionGradient
~SolutionGradient()
Definition: solution_function.h:79
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
SolutionFunction::SolutionFunction
SolutionFunction(const unsigned int u_var)
Definition: solution_function.h:34
SolutionFunction::~SolutionFunction
~SolutionFunction()
Definition: solution_function.h:37
SolutionGradient::soln
CurlCurlExactSolution soln
Definition: solution_function.h:107
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
CurlCurlExactSolution
Definition: curl_curl_exact_solution.h:26
libMesh::DenseVector< Number >