diff --git a/README.md b/README.md index 0f305c8d7bba91d3470f9a652b0da97dd2407b15..2519df97c25d866ee0d9a02ac7d65ecee2ff5a54 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ Dependencies ------------ `dune-mmdg` requires the DUNE core modules, version 2.7 or later, and a current version of the `dune-mmesh` module. - Additionally, for the `dune-mmesh` module, you will need a current version of `CGAL` installed on your system. diff --git a/dune/mmdg/problems/dgproblem3.hh b/dune/mmdg/problems/dgproblem3.hh index 29421380f614ec5941cd579769ca6e409179f5c8..21659d847274b1984e4a126d6f1446e68b896894 100644 --- a/dune/mmdg/problems/dgproblem3.hh +++ b/dune/mmdg/problems/dgproblem3.hh @@ -13,7 +13,9 @@ class DGProblem3 : public DGProblem<Coordinate, Scalar> public: static constexpr int dim = Coordinate::dimension; - //the exact solution at position pos + //the exact solution at position pos, + //in 2D and 3D the exact solution is obtained by a Fourier series expansion + //of the rectangular function Scalar exactSolution (const Coordinate& pos) const { if constexpr (dim == 1) @@ -21,19 +23,42 @@ class DGProblem3 : public DGProblem<Coordinate, Scalar> return 0.5 * pos[0] * (pos[0] - 1); } - if constexpr (dim == 2) //approximate series + if constexpr (dim == 2) //Fourier series with cut-off { - const int cutoff = 21; + constexpr int cutoff = 31; double solution = 0.0; + for (int m = 1; m <= cutoff; m = m + 2) { for (int n = 1; n <= cutoff; n = n + 2) { solution += sin(M_PI * m * pos[0]) * sin(M_PI * n * pos[1]) - / (m * n * (m*m + n*n)); + / (m * n * (m * m + n * n)); } } - solution *= -16 / pow(M_PI, 4); + + solution *= -16.0 / pow(M_PI, 4); + return solution; + } + + if constexpr (dim == 3) //Fourier series with cut-off + { + constexpr int cutoff = 21; + double solution = 0.0; + + for (int k = 1; k <= cutoff; k = k + 2) + { + for (int l = 1; l <= cutoff; l = l + 2) + { + for (int m = 1; m <= cutoff; m = m + 2) + { + solution += sin(M_PI * k * pos[0]) * sin(M_PI * l * pos[1]) + * sin(M_PI * m* pos[2]) / (k * l * m * (k * k + l * l + m * m)); + } + } + } + + solution *= -64.0 / pow(M_PI, 5); return solution; } @@ -42,10 +67,10 @@ class DGProblem3 : public DGProblem<Coordinate, Scalar> std::to_string(dim) + "!"); } - //exact solution is implemented for dim = 1, 2 + //exact solution is implemented bool hasExactSolution() const { - return (dim == 1 || dim == 2); + return true; }; //source term diff --git a/src/dg.cc b/src/dg.cc index 1b2149213438ff800941d6d8554d135a1ad61070..21363da666e4f69b56dccb623948ac5edf716f79 100644 --- a/src/dg.cc +++ b/src/dg.cc @@ -77,7 +77,7 @@ int main(int argc, char** argv) { problem = new DGProblem3<Coordinate>(); - if constexpr (dim == 2) + if constexpr (dim >= 2) { std::cout << "NOTE: The exact solution of your problem is given by " "an infinite series; increase the cut-off if necessary!\n\n";