From 98c75b87902cabef2ebbbccdafd033b76994ffde Mon Sep 17 00:00:00 2001 From: mattijs <mattijs> Date: Mon, 9 Sep 2013 15:33:43 +0100 Subject: [PATCH] ENH: instant: quick time comparison --- src/OpenFOAM/db/Time/instant/instant.C | 16 ++++++++++------ src/OpenFOAM/db/Time/instant/instant.H | 9 ++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/OpenFOAM/db/Time/instant/instant.C b/src/OpenFOAM/db/Time/instant/instant.C index 46f6bb73f18..bcbe24e55db 100644 --- a/src/OpenFOAM/db/Time/instant/instant.C +++ b/src/OpenFOAM/db/Time/instant/instant.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -54,15 +54,19 @@ Foam::instant::instant(const word& tname) {} +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::instant::equal(const scalar b) const +{ + return (value_ < b + SMALL && value_ > b - SMALL); +} + + // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // bool Foam::operator==(const instant& a, const instant& b) { - return - ( - a.value_ < b.value_ + SMALL - && a.value_ > b.value_ - SMALL - ); + return a.equal(b.value_); } diff --git a/src/OpenFOAM/db/Time/instant/instant.H b/src/OpenFOAM/db/Time/instant/instant.H index 9682d8e3f7e..be3ea4e0113 100644 --- a/src/OpenFOAM/db/Time/instant/instant.H +++ b/src/OpenFOAM/db/Time/instant/instant.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -99,10 +99,10 @@ public: instant(const scalar, const word&); //- Construct from time value - instant(const scalar); + explicit instant(const scalar); //- Construct from word - instant(const word&); + explicit instant(const word&); // Member Functions @@ -133,6 +133,9 @@ public: return name_; } + //- Comparison used for instants to be equal + bool equal(const scalar) const; + // Friend Operators -- GitLab