|
| 1 | +// The libMesh Finite Element Library. |
| 2 | +// Copyright (C) 2002-2024 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 | +#ifndef SOLUTION_FUNCTION_H |
| 19 | +#define SOLUTION_FUNCTION_H |
| 20 | + |
| 21 | +// libMesh includes |
| 22 | +#include "libmesh/function_base.h" |
| 23 | + |
| 24 | +// Example includes |
| 25 | +#include "grad_div_exact_solution.h" |
| 26 | + |
| 27 | +// C++ includes |
| 28 | +#include <memory> |
| 29 | + |
| 30 | +using namespace libMesh; |
| 31 | + |
| 32 | +class SolutionFunction : public FunctionBase<Number> |
| 33 | +{ |
| 34 | +public: |
| 35 | + |
| 36 | + SolutionFunction() = default; |
| 37 | + ~SolutionFunction() = default; |
| 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 | + output(0) = soln(x, y, z)(0); |
| 50 | + output(1) = soln(x, y, z)(1); |
| 51 | + output(2) = soln(x, y, z)(2); |
| 52 | + } |
| 53 | + |
| 54 | + virtual Number component(unsigned int component_in, |
| 55 | + const Point & p, |
| 56 | + const Real) |
| 57 | + { |
| 58 | + DenseVector<Number> outvec(3); |
| 59 | + (*this)(p, 0, outvec); |
| 60 | + return outvec(component_in); |
| 61 | + } |
| 62 | + |
| 63 | + virtual std::unique_ptr<FunctionBase<Number>> clone() const |
| 64 | + { return std::make_unique<SolutionFunction>(); } |
| 65 | + |
| 66 | +private: |
| 67 | + |
| 68 | + GradDivExactSolution soln; |
| 69 | +}; |
| 70 | + |
| 71 | +class SolutionGradient : public FunctionBase<Gradient> |
| 72 | +{ |
| 73 | +public: |
| 74 | + |
| 75 | + SolutionGradient() = default; |
| 76 | + ~SolutionGradient() = default; |
| 77 | + |
| 78 | + virtual Gradient operator() (const Point &, const Real = 0) |
| 79 | + { libmesh_not_implemented(); } |
| 80 | + |
| 81 | + virtual void operator() (const Point & p, |
| 82 | + const Real, |
| 83 | + DenseVector<Gradient> & output) |
| 84 | + { |
| 85 | + output.zero(); |
| 86 | + const Real x=p(0), y=p(1), z=p(2); |
| 87 | + output(0) = soln.grad(x, y, z).row(0); |
| 88 | + output(1) = soln.grad(x, y, z).row(1); |
| 89 | + output(2) = soln.grad(x, y, z).row(2); |
| 90 | + } |
| 91 | + |
| 92 | + virtual Gradient component(unsigned int component_in, |
| 93 | + const Point & p, |
| 94 | + const Real) |
| 95 | + { |
| 96 | + DenseVector<Gradient> outvec(3); |
| 97 | + (*this)(p, 0, outvec); |
| 98 | + return outvec(component_in); |
| 99 | + } |
| 100 | + |
| 101 | + virtual std::unique_ptr<FunctionBase<Gradient>> clone() const |
| 102 | + { return std::make_unique<SolutionGradient>(); } |
| 103 | + |
| 104 | +private: |
| 105 | + |
| 106 | + GradDivExactSolution soln; |
| 107 | +}; |
| 108 | + |
| 109 | +#endif // SOLUTION_FUNCTION_H |
0 commit comments