From 4a60cae2e379074c0e7d1a2e8100804e9c0aaaaf Mon Sep 17 00:00:00 2001 From: Fanny CHOPOT <fanny.chopot.ocre@cea.fr> Date: Wed, 2 May 2018 10:45:00 +0200 Subject: [PATCH] ajout fonction calcul erreur L2 --- src/main.cpp | 10 ++++++++-- src/scheme/FiniteVolumesDiffusion.hpp | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1cfa843fe..2bdfa752b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -171,10 +171,17 @@ int main(int argc, char *argv[]) t += dt; ++iteration; } + - std::cout << "* " << rang::style::underline << "Final time" << rang::style::reset + std::cout << "* " << rang::style::underline << "Final time" << rang::style::reset << ": " << rang::fgB::green << t << rang::fg::reset << " (" << iteration << " iterations)\n"; + double error = 0.; + error = finite_volumes_diffusion.error_L2(unknowns); + + std::cout << "* " << rang::style::underline << "Erreur L2" << rang::style::reset + << ": " << rang::fgB::green << error << rang::fg::reset << " \n"; + //method_cost_map["AcousticSolverWithMesh"] = timer.seconds(); method_cost_map["FiniteVolumesDiffusionWithMesh"] = timer.seconds(); @@ -189,7 +196,6 @@ int main(int argc, char *argv[]) } } - } diff --git a/src/scheme/FiniteVolumesDiffusion.hpp b/src/scheme/FiniteVolumesDiffusion.hpp index 67774fc98..5a60de696 100644 --- a/src/scheme/FiniteVolumesDiffusion.hpp +++ b/src/scheme/FiniteVolumesDiffusion.hpp @@ -299,6 +299,27 @@ public: }); } + + // Calcul erreur entre solution analytique et solution numerique en norme L2 + + double error_L2(UnknownsType& unknowns) { + + Kokkos::View<Rd*> uj = unknowns.uj(); + + const Kokkos::View<const Rd*> xj = m_mesh_data.xj(); + + double pi = 4.*std::atan(1.); + double erreur = 0.; + double exacte = 0.; + for (size_t j=0; j<m_mesh.numberOfCells(); ++j) { + exacte = std::sin(pi*xj[j][0])*std::exp(-0.2); + erreur += (exacte - uj[j][0])*(exacte - uj[j][0]); + } + erreur = std::sqrt(erreur); + return erreur; + } + + }; #endif // FINITE_VOLUMES_DIFFUSION_HPP -- GitLab