MFEM v4.7.0 Finite element discretization library
Searching...
No Matches
lor_mms.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, Lawrence Livermore National Security, LLC. Produced
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_LOR_MMS_HPP
13#define MFEM_LOR_MMS_HPP
14
15namespace mfem
16{
17
18static constexpr real_t pi = M_PI, pi2 = M_PI*M_PI;
19
20// Exact solution for definite Helmholtz problem with RHS corresponding to f
21// defined below.
22real_t u(const Vector &xvec)
23{
24 const int dim = xvec.Size();
25 const real_t x = pi*xvec[0], y = pi*xvec[1];
26 if (dim == 2) { return sin(x)*sin(y); }
27 else { const real_t z = pi*xvec[2]; return sin(x)*sin(y)*sin(z); }
28}
29
30std::function<real_t(const Vector &)> f(real_t mass_coeff)
31{
32 return [mass_coeff](const Vector &xvec)
33 {
34 const int dim = xvec.Size();
35 const real_t x = pi*xvec[0], y = pi*xvec[1];
36 if (dim == 2)
37 {
38 return mass_coeff*sin(x)*sin(y) + 2*pi2*sin(x)*sin(y);
39 }
40 else // dim == 3
41 {
42 const real_t z = pi*xvec[2];
43 return mass_coeff*sin(x)*sin(y)*sin(z) + 3*pi2*sin(x)*sin(y)*sin(z);
44 }
45 };
46}
47
48// Exact solution for definite Maxwell and grad-div problems with RHS
49// corresponding to f_vec below.
50void u_vec(const Vector &xvec, Vector &u)
51{
52 const int dim = xvec.Size();
53 const real_t x = pi*xvec[0], y = pi*xvec[1];
54 if (dim == 2)
55 {
56 u[0] = cos(x)*sin(y);
57 u[1] = sin(x)*cos(y);
58 }
59 else // dim == 3
60 {
61 const real_t z = pi*xvec[2];
62 u[0] = cos(x)*sin(y)*sin(z);
63 u[1] = sin(x)*cos(y)*sin(z);
64 u[2] = sin(x)*sin(y)*cos(z);
65 }
66}
67
68std::function<void(const Vector &, Vector &)> f_vec(bool grad_div_problem)
69{
70 return [grad_div_problem](const Vector &xvec, Vector &f)
71 {
72 const int dim = xvec.Size();
73 const real_t x = pi*xvec[0], y = pi*xvec[1];
75 {
76 if (dim == 2)
77 {
78 f[0] = (1 + 2*pi2)*cos(x)*sin(y);
79 f[1] = (1 + 2*pi2)*cos(y)*sin(x);
80 }
81 else // dim == 3
82 {
83 const real_t z = pi*xvec[2];
84 f[0] = (1 + 3*pi2)*cos(x)*sin(y)*sin(z);
85 f[1] = (1 + 3*pi2)*cos(y)*sin(x)*sin(z);
86 f[2] = (1 + 3*pi2)*cos(z)*sin(x)*sin(y);
87 }
88 }
89 else
90 {
91 if (dim == 2)
92 {
93 f[0] = cos(x)*sin(y);
94 f[1] = sin(x)*cos(y);
95 }
96 else // dim == 3
97 {
98 const real_t z = pi*xvec[2];
99 f[0] = cos(x)*sin(y)*sin(z);
100 f[1] = sin(x)*cos(y)*sin(z);
101 f[2] = sin(x)*sin(y)*cos(z);
102 }
103 }
104 };
105}
106
107} // namespace mfem
108
109#endif
Vector data type.
Definition vector.hpp:80
int Size() const
Returns the size of the vector.
Definition vector.hpp:218
int dim
Definition ex24.cpp:53
real_t u(const Vector &xvec)
Definition lor_mms.hpp:22
void u_vec(const Vector &xvec, Vector &u)
Definition lor_mms.hpp:50
std::function< void(const Vector &, Vector &)> f_vec(bool grad_div_problem)
Definition lor_mms.hpp:68
float real_t
Definition config.hpp:43
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30
const real_t pi2
Definition polar-nc.cpp:249