MFEM  v4.6.0 Finite element discretization library
lor_mms.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
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
15 namespace mfem
16 {
17
18 static constexpr double pi = M_PI, pi2 = M_PI*M_PI;
19
20 // Exact solution for definite Helmholtz problem with RHS corresponding to f
21 // defined below.
22 double u(const Vector &xvec)
23 {
24  const int dim = xvec.Size();
25  const double x = pi*xvec[0], y = pi*xvec[1];
26  if (dim == 2) { return sin(x)*sin(y); }
27  else { const double z = pi*xvec[2]; return sin(x)*sin(y)*sin(z); }
28 }
29
30 std::function<double(const Vector &)> f(double mass_coeff)
31 {
32  return [mass_coeff](const Vector &xvec)
33  {
34  const int dim = xvec.Size();
35  const double 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 double 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.
50 void u_vec(const Vector &xvec, Vector &u)
51 {
52  const int dim = xvec.Size();
53  const double 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 double 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
68 std::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 double x = pi*xvec[0], y = pi*xvec[1];
74  if (grad_div_problem)
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 double 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 double 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
int Size() const
Returns the size of the vector.
Definition: vector.hpp:197
std::function< double(const Vector &)> f(double mass_coeff)
Definition: lor_mms.hpp:30
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
int dim
Definition: ex24.cpp:53
const double pi2
Definition: polar-nc.cpp:249
Vector data type.
Definition: vector.hpp:58
double u(const Vector &xvec)
Definition: lor_mms.hpp:22