From 877829f43ac9e1789c4a0ebbe42421a38370bdf2 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Mon, 28 Oct 2013 17:42:32 +0100 Subject: [PATCH] Added method equals in BlackoilState.hpp --- opm/core/simulator/BlackoilState.hpp | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/opm/core/simulator/BlackoilState.hpp b/opm/core/simulator/BlackoilState.hpp index d20fc6dde..c788d9495 100644 --- a/opm/core/simulator/BlackoilState.hpp +++ b/opm/core/simulator/BlackoilState.hpp @@ -19,6 +19,7 @@ #ifndef OPM_BLACKOILSTATE_HEADER_INCLUDED #define OPM_BLACKOILSTATE_HEADER_INCLUDED +#include #include #include @@ -82,6 +83,22 @@ namespace Opm return num_phases_; } + + + bool equals(const BlackoilState& other, double epsilon = 1e-8) const { + bool equal = (num_phases_ == other.num_phases_); + + equal = equal && (vectorApproxEqual( pressure() , other.pressure() , epsilon)); + equal = equal && (vectorApproxEqual( facepressure() , other.facepressure() , epsilon)); + equal = equal && (vectorApproxEqual( faceflux() , other.faceflux() , epsilon)); + equal = equal && (vectorApproxEqual( surfacevol() , other.surfacevol() , epsilon)); + equal = equal && (vectorApproxEqual( saturation() , other.saturation() , epsilon)); + equal = equal && (vectorApproxEqual( gasoilratio() , other.gasoilratio() , epsilon)); + + return equal; + } + + std::vector& pressure () { return press_ ; } std::vector& facepressure() { return fpress_; } std::vector& faceflux () { return flux_ ; } @@ -104,6 +121,19 @@ namespace Opm std::vector surfvol_; std::vector sat_ ; std::vector gor_ ; + + + static bool vectorApproxEqual(const std::vector& v1, const std::vector& v2 , double epsilon) { + if (v1.size() != v2.size()) + return false; + + for (size_t i = 0; i < v1.size(); i++) + if (fabs(v1[i] - v2[i]) > epsilon * (fabs(v1[i]) + fabs(v2[i]))) + return false; + + return true; + } + }; } // namespace Opm