From 02e715fe14ddb448f38598d7623794a0a3932347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Mon, 2 Jul 2012 19:09:58 +0200 Subject: [PATCH] makefhfQPeriodic(): Use less branch'y implementation. --- .../transport/SinglePointUpwindTwoPhase.hpp | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/opm/core/transport/SinglePointUpwindTwoPhase.hpp b/opm/core/transport/SinglePointUpwindTwoPhase.hpp index 83261d48..87ea6c2f 100644 --- a/opm/core/transport/SinglePointUpwindTwoPhase.hpp +++ b/opm/core/transport/SinglePointUpwindTwoPhase.hpp @@ -306,42 +306,42 @@ namespace Opm { std::copy(porevol.begin(), porevol.end(), store_.porevol()); } - void makefhfQPeriodic( const std::vector& p_faces,const std::vector& hf_faces, - const std::vector& nb_faces) + + void + makefhfQPeriodic(const std::vector& p_faces , + const std::vector& hf_faces, + const std::vector& nb_faces) { + assert (! p_faces.empty()); + assert (p_faces.size() == hf_faces.size()); + assert (hf_faces.size() == nb_faces.size()); + std::vector nbhf(hf_faces.size()); - for(unsigned int i=0; i::size_type i = 0; i < p_faces.size(); ++i) { + const int nbf = nb_faces[i]; + + assert (2*std::vector::size_type(nbf) + 1 < f2hf_.size()); + assert ((f2hf_[2*nbf + 0] < 0) ^ (f2hf_[2*nbf + 1] < 0)); + + const int p = (f2hf_[2*nbf + 0] < 0) ? 1 : 0; // "Self" + nbhf[ i ] = f2hf_[2*nbf + p]; } - for(unsigned int i=0; i::size_type i = 0; i < p_faces.size(); ++i) { + const int f = p_faces [i]; + const int hf = hf_faces[i]; - if(f2hf_[2*f] == hf){ - assert(f2hf_[2*f+1]==-1); - }else{ - assert(f2hf_[2*f]==-1); - f2hf_[2*f]=nbhf[i]; - changed=true; - } - if(!changed){ - if(f2hf_[2*f+1]== hf){ - assert(f2hf_[2*f]==-1); - }else{ - assert(f2hf_[2*f+1]==-1); - f2hf_[2*f+1]=nbhf[i]; - changed=true; - } - } - assert(changed); + assert (0 <= f); + assert (0 <= hf); + assert (2*std::vector::size_type(f) + 1 < f2hf_.size()); + + assert ((f2hf_[2*f + 0] < 0 ) ^ (f2hf_[2*f + 1] < 0 )); + assert ((f2hf_[2*f + 0] == hf) ^ (f2hf_[2*f + 1] == hf)); + + const int p = (f2hf_[2*f + 0] == hf) ? 1 : 0; // "Other" + + f2hf_[2*f + p] = nbhf[ i ]; } }