libMesh
Loading...
Searching...
No Matches
exact_soln.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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 EXACT_SOLN_H
19#define EXACT_SOLN_H
20
21#include "libmesh/parameters.h"
22#include "libmesh/libmesh_common.h"
23
24namespace libMesh
25{
26class Point;
27
29{
30public:
31 virtual Real operator()(const Point & p) const = 0;
32 virtual Real forcing(const Point & p) const = 0;
33};
34
35inline Number
37 const Parameters & params,
38 const std::string & /*sys_name*/,
39 const std::string & unknown_name)
40{
41 const auto * const error_obj = params.get<const ExactSoln *>(unknown_name + "_exact_sol");
42 return (*error_obj)(p);
43}
44
45class USoln : public ExactSoln
46{
47public:
48 USoln(const Real nu_in, const bool cavity_in) : nu(nu_in), cavity(cavity_in) {}
49
50 Real operator()(const Point & p) const override
51 {
52 const auto x = p(0);
53 const auto y = p(1);
54 if (cavity)
55 return sin(y) * cos((1. / 2) * x * pi);
56 else
57 return sin(1. / 2 * y * pi) * cos(1. / 2 * x * pi);
58 }
59
60 Real forcing(const Point & p) const override
61 {
62 const auto x = p(0);
63 const auto y = p(1);
64 if (cavity)
65 {
66 return nu * sin(y) * cos((1. / 2) * x * pi) +
67 (1. / 4) * pi * pi * nu * sin(y) * cos((1. / 2) * x * pi) -
68 1. / 2 * pi * sin(x) * sin(y) * sin((1. / 2) * y * pi) * cos((1. / 2) * x * pi) +
69 sin(x) * cos(y) * cos((1. / 2) * x * pi) * cos((1. / 2) * y * pi) -
70 pi * sin(y) * sin(y) * sin((1. / 2) * x * pi) * cos((1. / 2) * x * pi) +
71 sin(y) * cos(x);
72 }
73 else
74 {
75 const auto quant1 = sin((1. / 2) * y * pi);
76 const auto quant2 = cos((1. / 2) * y * pi);
77 return (1. / 2) * pi * pi * nu * sin((1. / 2) * y * pi) * cos((1. / 2) * x * pi) -
78 1. / 2 * pi * sin((1. / 4) * x * pi) * quant1 * quant1 * cos((1. / 2) * x * pi) -
79 1. / 4 * pi * sin((1. / 4) * x * pi) * sin((3. / 2) * y * pi) +
80 (1. / 2) * pi * sin((1. / 4) * x * pi) * cos((1. / 2) * x * pi) * quant2 * quant2 -
81 pi * sin((1. / 2) * x * pi) * quant1 * quant1 * cos((1. / 2) * x * pi);
82 }
83 }
84
85private:
86 const Real nu;
87 const bool cavity;
88};
89
90class VSoln : public ExactSoln
91{
92public:
93 VSoln(const Real nu_in, const bool cavity_in) : nu(nu_in), cavity(cavity_in) {}
94
95 Real operator()(const Point & p) const override
96 {
97 const auto x = p(0);
98 const auto y = p(1);
99 if (cavity)
100 return sin(x) * cos((1. / 2) * y * pi);
101 else
102 return sin((1. / 4) * x * pi) * cos((1. / 2) * y * pi);
103 }
104
105 Real forcing(const Point & p) const override
106 {
107 const auto x = p(0);
108 const auto y = p(1);
109 if (cavity)
110 return nu * sin(x) * cos((1. / 2) * y * pi) +
111 (1. / 4) * pi * pi * nu * sin(x) * cos((1. / 2) * y * pi) -
112 pi * sin(x) * sin(x) * sin((1. / 2) * y * pi) * cos((1. / 2) * y * pi) -
113 1. / 2 * pi * sin(x) * sin(y) * sin((1. / 2) * x * pi) * cos((1. / 2) * y * pi) +
114 sin(y) * cos(x) * cos((1. / 2) * x * pi) * cos((1. / 2) * y * pi) + sin(x) * cos(y);
115 else
116 {
117 const auto quant1 = sin((1. / 4) * x * pi);
118 return (5. / 16) * pi * pi * nu * sin((1. / 4) * x * pi) * cos((1. / 2) * y * pi) -
119 pi * quant1 * quant1 * sin((1. / 2) * y * pi) * cos((1. / 2) * y * pi) -
120 1. / 2 * pi * sin((1. / 4) * x * pi) * sin((1. / 2) * x * pi) *
121 sin((1. / 2) * y * pi) * cos((1. / 2) * y * pi) +
122 (1. / 4) * pi * sin((1. / 2) * y * pi) * cos((1. / 4) * x * pi) *
123 cos((1. / 2) * x * pi) * cos((1. / 2) * y * pi) +
124 (3. / 2) * pi * cos((1. / 4) * x * pi) * cos((3. / 2) * y * pi);
125 }
126 }
127
128private:
129 const Real nu;
130 const bool cavity;
131};
132
133class PSoln : public ExactSoln
134{
135public:
136 PSoln(const bool cavity_in) : cavity(cavity_in) {}
137
138 Real operator()(const Point & p) const override
139 {
140 const auto x = p(0);
141 const auto y = p(1);
142 if (cavity)
143 return sin(x) * sin(y);
144 else
145 return sin((3. / 2) * y * pi) * cos((1. / 4) * x * pi);
146 }
147
148 Real forcing(const Point & p) const override
149 {
150 const auto x = p(0);
151 const auto y = p(1);
152 if (cavity)
153 return -1. / 2 * pi * sin(x) * sin((1. / 2) * y * pi) -
154 1. / 2 * pi * sin(y) * sin((1. / 2) * x * pi);
155 else
156 return -1. / 2 * pi * sin((1. / 4) * x * pi) * sin((1. / 2) * y * pi) -
157 1. / 2 * pi * sin((1. / 2) * x * pi) * sin((1. / 2) * y * pi);
158 }
159
160private:
161 const bool cavity;
162};
163}
164
165#endif // EXACT_SOLN_H
virtual Real forcing(const Point &p) const =0
virtual Real operator()(const Point &p) const =0
const bool cavity
Definition exact_soln.h:161
PSoln(const bool cavity_in)
Definition exact_soln.h:136
Real operator()(const Point &p) const override
Definition exact_soln.h:138
Real forcing(const Point &p) const override
Definition exact_soln.h:148
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition parameters.h:75
const T & get(std::string_view) const
Definition parameters.h:451
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
USoln(const Real nu_in, const bool cavity_in)
Definition exact_soln.h:48
const bool cavity
Definition exact_soln.h:87
Real forcing(const Point &p) const override
Definition exact_soln.h:60
const Real nu
Definition exact_soln.h:86
Real operator()(const Point &p) const override
Definition exact_soln.h:50
const Real nu
Definition exact_soln.h:129
VSoln(const Real nu_in, const bool cavity_in)
Definition exact_soln.h:93
Real operator()(const Point &p) const override
Definition exact_soln.h:95
const bool cavity
Definition exact_soln.h:130
Real forcing(const Point &p) const override
Definition exact_soln.h:105
The libMesh namespace provides an interface to certain functionality in the library.
const Real pi
.
Definition libmesh.h:292
Number compute_error(const Point &p, const Parameters &params, const std::string &, const std::string &unknown_name)
Definition exact_soln.h:36
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real