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 "laplace_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), z=p(2);
49  // libMesh assumes each component of the vector-valued variable is stored
50  // contiguously.
51  output(_u_var) = soln(0, x, y, z);
52  output(_u_var+1) = soln(1, x, y, z);
53  output(_u_var+2) = soln(2, x, y, z);
54  }
55 
56  virtual Number component(unsigned int component_in,
57  const Point & p,
58  const Real)
59  {
60  const Real x=p(0), y=p(1), z=p(2);
61  return soln(component_in, x, y, z);
62  }
63 
64  virtual std::unique_ptr<FunctionBase<Number>> clone() const
65  { return libmesh_make_unique<SolutionFunction>(_u_var); }
66 
67 private:
68 
69  const unsigned int _u_var;
71 };
72 
73 //FIXME: PB: We ought to be able to merge the above class with this one
74 // through templating, but I'm being lazy.
75 class SolutionGradient : public FunctionBase<Gradient>
76 {
77 public:
78 
79  SolutionGradient(const unsigned int u_var)
80  : _u_var(u_var) {}
82 
83  virtual Gradient operator() (const Point &, const Real = 0)
84  { libmesh_not_implemented(); }
85 
86  virtual void operator() (const Point & p,
87  const Real,
88  DenseVector<Gradient>& output)
89  {
90  output.zero();
91  const Real x=p(0), y=p(1), z=p(2);
92  output(_u_var) = soln(0, x, y, z);
93  output(_u_var+1) = soln(1, x, y, z);
94  output(_u_var+2) = soln(2, x, y, z);
95  }
96 
97  virtual Gradient component(unsigned int component_in,
98  const Point & p,
99  const Real)
100  {
101  const Real x=p(0), y=p(1), z=p(2);
102  return soln(component_in, x, y, z);
103  }
104 
105  virtual std::unique_ptr<FunctionBase<Gradient>> clone() const
106  { return libmesh_make_unique<SolutionGradient>(_u_var); }
107 
108 private:
109 
110  const unsigned int _u_var;
112 };
113 
114 #endif // SOLUTION_FUNCTION_H
SolutionGradient::component
virtual Gradient component(unsigned int component_in, const Point &p, const Real)
Definition: solution_function.h:97
SolutionFunction::component
virtual Number component(unsigned int component_in, const Point &p, const Real)
Definition: solution_function.h:56
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:105
SolutionFunction::clone
virtual std::unique_ptr< FunctionBase< Number > > clone() const
Definition: solution_function.h:64
libMesh::VectorValue< Number >
SolutionGradient::SolutionGradient
SolutionGradient(const unsigned int u_var)
Definition: solution_function.h:79
SolutionFunction::soln
LaplaceExactSolution soln
Definition: solution_function.h:70
SolutionFunction
Definition: solution_function.h:30
SolutionGradient::~SolutionGradient
~SolutionGradient()
Definition: solution_function.h:81
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
SolutionFunction::_u_var
const unsigned int _u_var
Definition: solution_function.h:69
LaplaceExactGradient
Definition: laplace_exact_solution.h:57
SolutionFunction::SolutionFunction
SolutionFunction(const unsigned int u_var)
Definition: solution_function.h:34
laplace_exact_solution.h
SolutionFunction::~SolutionFunction
~SolutionFunction()
Definition: solution_function.h:37
SolutionGradient::soln
LaplaceExactGradient soln
Definition: solution_function.h:111
SolutionGradient::_u_var
const unsigned int _u_var
Definition: solution_function.h:110
LaplaceExactSolution
Definition: laplace_exact_solution.h:25
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::DenseVector< Number >