MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
lor_mms.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, 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 extern bool grad_div_problem;
16 
17 namespace mfem
18 {
19 
20 static constexpr double pi = M_PI, pi2 = M_PI*M_PI;
21 
22 // Exact solution for definite Helmholtz problem with RHS corresponding to f
23 // defined below.
24 double u(const Vector &xvec)
25 {
26  int dim = xvec.Size();
27  double x = pi*xvec[0], y = pi*xvec[1];
28  if (dim == 2) { return sin(x)*sin(y); }
29  else { double z = pi*xvec[2]; return sin(x)*sin(y)*sin(z); }
30 }
31 
32 double f(const Vector &xvec)
33 {
34  int dim = xvec.Size();
35  double x = pi*xvec[0], y = pi*xvec[1];
36 
37  if (dim == 2)
38  {
39  return sin(x)*sin(y) + 2*pi2*sin(x)*sin(y);
40  }
41  else // dim == 3
42  {
43  double z = pi*xvec[2];
44  return sin(x)*sin(y)*sin(z) + 3*pi2*sin(x)*sin(y)*sin(z);
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  int dim = xvec.Size();
53  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  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 void f_vec(const Vector &xvec, Vector &f)
69 {
70  int dim = xvec.Size();
71  double x = pi*xvec[0], y = pi*xvec[1];
72  if (grad_div_problem)
73  {
74  if (dim == 2)
75  {
76  f[0] = (1 + 2*pi2)*cos(x)*sin(y);
77  f[1] = (1 + 2*pi2)*cos(y)*sin(x);
78  }
79  else // dim == 3
80  {
81  double z = pi*xvec[2];
82  f[0] = (1 + 3*pi2)*cos(x)*sin(y)*sin(z);
83  f[1] = (1 + 3*pi2)*cos(y)*sin(x)*sin(z);
84  f[2] = (1 + 3*pi2)*cos(z)*sin(x)*sin(y);
85  }
86  }
87  else
88  {
89  if (dim == 2)
90  {
91  f[0] = cos(x)*sin(y);
92  f[1] = sin(x)*cos(y);
93  }
94  else // dim == 3
95  {
96  double z = pi*xvec[2];
97  f[0] = cos(x)*sin(y)*sin(z);
98  f[1] = sin(x)*cos(y)*sin(z);
99  f[2] = sin(x)*sin(y)*cos(z);
100  }
101  }
102 }
103 
104 } // namespace mfem
105 
106 #endif
int Size() const
Returns the size of the vector.
Definition: vector.hpp:200
bool grad_div_problem
Definition: lor_solvers.cpp:77
double f(const Vector &xvec)
Definition: lor_mms.hpp:32
void u_vec(const Vector &xvec, Vector &u)
Definition: lor_mms.hpp:50
int dim
Definition: ex24.cpp:53
const double pi2
Definition: polar-nc.cpp:249
Vector data type.
Definition: vector.hpp:60
void f_vec(const Vector &xvec, Vector &f)
Definition: lor_mms.hpp:68
double u(const Vector &xvec)
Definition: lor_mms.hpp:24