diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 929cbaf77..0e589313d 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -23,6 +23,7 @@ # originally generated with the command: # find opm -name '*.c*' -printf '\t%p\n' | sort list (APPEND MAIN_SOURCE_FILES + ebos/nncsorter.cpp opm/autodiff/MPIUtilities.cpp opm/autodiff/MissingFeatures.cpp opm/core/props/rock/RockFromDeck.cpp diff --git a/ebos/ecltransmissibility.hh b/ebos/ecltransmissibility.hh index 06b4db3d8..89e04b526 100644 --- a/ebos/ecltransmissibility.hh +++ b/ebos/ecltransmissibility.hh @@ -28,6 +28,8 @@ #ifndef EWOMS_ECL_TRANSMISSIBILITY_HH #define EWOMS_ECL_TRANSMISSIBILITY_HH +#include + #include #include @@ -619,49 +621,7 @@ private: auto nncData = nnc.nncdata(); auto editnncData = vanguard_.eclState().getInputEDITNNC().data(); - auto nncLess = - [](const Opm::NNCdata& d1, const Opm::NNCdata& d2) - { - return - (d1.cell1 < d2.cell1) - || (d1.cell1 == d2.cell1 && d1.cell2 < d2.cell2); - }; - std::sort(nncData.begin(), nncData.end(), nncLess); - auto candidate = nncData.begin(); - for (const auto& edit: editnncData) { - auto printNncWarning = - [](int c1, int c2) - { - std::ostringstream sstr; - sstr << "Cannot edit NNC from " << c1 << " to " << c2 - << " as it does not exist"; - Opm::OpmLog::warning(sstr.str()); - }; - if (candidate == nncData.end()) { - // no more NNCs left - printNncWarning(edit.cell1, edit.cell2); - continue; - } - if (candidate->cell1 != edit.cell1 || candidate->cell2 != edit.cell2) { - candidate = std::lower_bound(candidate, nncData.end(), Opm::NNCdata(edit.cell1, edit.cell2, 0), nncLess); - if (candidate == nncData.end()) { - // no more NNCs left - printNncWarning(edit.cell1, edit.cell2); - continue; - } - } - auto firstCandidate = candidate; - while (candidate != nncData.end() - && candidate->cell1 == edit.cell1 - && candidate->cell2 == edit.cell2) - { - candidate->trans *= edit.trans; - ++candidate; - } - // start with first match in next iteration to catch case where next - // EDITNNC is for same pair. - candidate = firstCandidate; - } + sortNncAndApplyEditnnc(nncData, editnncData); for (const auto& nncEntry : nncData) { auto c1 = nncEntry.cell1; diff --git a/ebos/nncsorter.cpp b/ebos/nncsorter.cpp new file mode 100644 index 000000000..495cb3d33 --- /dev/null +++ b/ebos/nncsorter.cpp @@ -0,0 +1,79 @@ +// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +// vi: set et ts=4 sw=4 sts=4: +/* + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . + + Consult the COPYING file in the top-level source directory of this + module for the precise wording of the license and the list of + copyright holders. +*/ +#include +#include + +#include + +#include +#include +#include +namespace Ewoms +{ +void sortNncAndApplyEditnnc(std::vector& nncData, std::vector& editnncData, + bool log ) +{ + auto nncLess = + [](const Opm::NNCdata& d1, const Opm::NNCdata& d2) { + return + (d1.cell1 < d2.cell1) + || (d1.cell1 == d2.cell1 && d1.cell2 < d2.cell2); + }; + std::sort(nncData.begin(), nncData.end(), nncLess); + auto candidate = nncData.begin(); + + for (const auto& edit: editnncData) { + auto printNncWarning = + [](int c1, int c2) { + std::ostringstream sstr; + sstr << "Cannot edit NNC from " << c1 << " to " << c2 + << " as it does not exist"; + Opm::OpmLog::warning(sstr.str()); + }; + if (candidate == nncData.end() && log) { + // no more NNCs left + printNncWarning(edit.cell1, edit.cell2); + continue; + } + if (candidate->cell1 != edit.cell1 || candidate->cell2 != edit.cell2) { + candidate = std::lower_bound(candidate, nncData.end(), Opm::NNCdata(edit.cell1, edit.cell2, 0), nncLess); + if (candidate == nncData.end() && log) { + // no more NNCs left + printNncWarning(edit.cell1, edit.cell2); + continue; + } + } + auto firstCandidate = candidate; + while (candidate != nncData.end() + && candidate->cell1 == edit.cell1 + && candidate->cell2 == edit.cell2) + { + candidate->trans *= edit.trans; + ++candidate; + } + // start with first match in next iteration to catch case where next + // EDITNNC is for same pair. + candidate = firstCandidate; + } +} +} // end namespace Ewoms diff --git a/ebos/nncsorter.hpp b/ebos/nncsorter.hpp new file mode 100644 index 000000000..2a6e865d0 --- /dev/null +++ b/ebos/nncsorter.hpp @@ -0,0 +1,37 @@ +// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +// vi: set et ts=4 sw=4 sts=4: +/* + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . + + Consult the COPYING file in the top-level source directory of this + module for the precise wording of the license and the list of + copyright holders. +*/ + +#ifndef EWOMS_EBOS_NNCSORTER_HPP +#define EWOMS_EBOS_NNCSORTER_HPP + + +#include + +#include + +namespace Ewoms +{ +void sortNncAndApplyEditnnc(std::vector& nncData, std::vector& editnncData, + bool log = true); +} +#endif