-
Notifications
You must be signed in to change notification settings - Fork 119
New SummaryNode implementation #1609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 37 commits
402f28f
3af0bbf
e5e0a49
e317b96
90a2eeb
0265b7f
861c098
dbf17af
c3de96b
d9e1d39
4bb453d
84c57ff
001877d
b940d81
cb0f27c
b12397c
e500fbb
855b23a
bb114b6
701175c
6970158
0174a16
fda69e9
318ca70
a6a144a
21e9c1b
35afdd5
99375eb
62983db
327fe79
89fe3c3
eba0f3d
06eeae8
f884c90
fb4f026
ab71b43
2c74b09
06d317d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| Copyright 2020 Equinor ASA. | ||
|
|
||
| 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 3 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 <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace Opm::EclIO { | ||
|
|
||
| struct SummaryNode { | ||
| enum class Category { | ||
| Well, | ||
| Group, | ||
| Field, | ||
| Region, | ||
| Block, | ||
| Connection, | ||
| Segment, | ||
| Miscellaneous, | ||
| }; | ||
|
|
||
| enum class Type { | ||
| Rate, | ||
| Total, | ||
| Ratio, | ||
| Pressure, | ||
| Count, | ||
| Mode, | ||
| Undefined, | ||
| }; | ||
|
|
||
| const std::string keyword; | ||
| const Category category; | ||
| const Type type; | ||
| const std::string wgname; | ||
| const int number; | ||
|
|
||
| constexpr static int default_number { std::numeric_limits<int>::min() }; | ||
|
|
||
| std::string unique_key() const; | ||
| bool is_user_defined() const; | ||
| }; | ||
|
|
||
| } // namespace Opm::EclIO | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| Copyright 2020 Equinor ASA. | ||
|
|
||
| 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 3 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 <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include <numeric> | ||
| #include <regex> | ||
| #include <string> | ||
| #include <unordered_set> | ||
| #include <vector> | ||
|
|
||
| #include <opm/io/eclipse/SummaryNode.hpp> | ||
|
|
||
| namespace { | ||
|
|
||
| constexpr bool use_number(Opm::EclIO::SummaryNode::Category category) { | ||
| switch (category) { | ||
| case Opm::EclIO::SummaryNode::Category::Block: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Connection: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Region: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Segment: | ||
| return true; | ||
| case Opm::EclIO::SummaryNode::Category::Field: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Group: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Miscellaneous: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Well: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| constexpr bool use_name(Opm::EclIO::SummaryNode::Category category) { | ||
| switch (category) { | ||
| case Opm::EclIO::SummaryNode::Category::Connection: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Group: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Segment: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Well: | ||
| return true; | ||
| case Opm::EclIO::SummaryNode::Category::Block: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Field: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Miscellaneous: [[fallthrough]]; | ||
| case Opm::EclIO::SummaryNode::Category::Region: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| std::string Opm::EclIO::SummaryNode::unique_key() const { | ||
| std::vector<std::string> key_parts { keyword } ; | ||
|
|
||
| if (use_name(category)) | ||
| key_parts.emplace_back(wgname); | ||
|
|
||
| if (use_number(category)) | ||
| key_parts.emplace_back(std::to_string(number)); | ||
|
|
||
| auto compose_key = [](std::string& key, const std::string& key_part) -> std::string { | ||
| constexpr auto delimiter { ':' } ; | ||
| return key.empty() ? key_part : key + delimiter + key_part; | ||
| }; | ||
|
|
||
| return std::accumulate(std::begin(key_parts), std::end(key_parts), std::string(), compose_key); | ||
| } | ||
|
|
||
| bool Opm::EclIO::SummaryNode::is_user_defined() const { | ||
| static const std::unordered_set<std::string> udq_blacklist { | ||
| "AUTOCOAR", | ||
| "AUTOREF", | ||
| "FULLIMP", | ||
| "GUIDECAL", | ||
| "GUIDERAT", | ||
| "GUPFREQ", | ||
| "RUNSPEC", | ||
| "RUNSUM", | ||
| "SUMMARY", | ||
| "SUMTHIN", | ||
| "SURF", | ||
| "SURFACT", | ||
| "SURFACTW", | ||
| "SURFADDW", | ||
| "SURFADS", | ||
| "SURFCAPD", | ||
| "SURFESAL", | ||
| "SURFNUM", | ||
| "SURFOPTS", | ||
| "SURFROCK", | ||
| "SURFST", | ||
| "SURFSTES", | ||
| "SURFVISC", | ||
| "SURFWNUM", | ||
| } ; | ||
|
|
||
| static const std::regex user_defined_regex { "[ABCFGRSW]U[A-Z]+" } ; | ||
|
|
||
| const bool matched { std::regex_match(keyword, user_defined_regex) } ; | ||
| const bool blacklisted { udq_blacklist.find(keyword) != udq_blacklist.end() } ; | ||
|
|
||
| return matched && !blacklisted; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you consider writing this as return !blacklisted && std::regex_match(keyword, user_defined_regex);? That way, you don't incur the cost of regular expression matching for blacklisted keywords.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, in this case, if that's worth it, given the domain of the function and the relative simplicity of the regular expression. |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.