Skip to content

Commit

Permalink
Use string based parent *name* in GTNode instead of pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
joakim-hove committed May 8, 2020
1 parent 2bae3b2 commit ad74644
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
9 changes: 6 additions & 3 deletions opm/parser/eclipse/EclipseState/Schedule/Group/GTNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/

#include <optional>
#include <vector>

#include <opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp>
Expand All @@ -29,19 +30,21 @@ namespace Opm {

class GTNode {
public:
GTNode(const Group& group, const GTNode* parent);
GTNode(const Group& group, std::size_t level, const std::optional<std::string>& parent_name);

void add_group(const GTNode& child_group);
void add_well(const Well& well);

const std::vector<Well>& wells() const;
const std::vector<GTNode>& groups() const;
const std::string& name() const;
const GTNode& parent() const;
const std::string& parent_name() const;

const Group& group() const;
private:
const Group m_group;
const GTNode * m_parent;
std::size_t m_level;
std::optional<std::string> m_parent_name;
/*
Class T with a stl container <T> - supposedly undefined behavior before
C++17 - but it compiles without warnings.
Expand Down
3 changes: 1 addition & 2 deletions opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ namespace Opm
const UnitSystem& unit_system);

DynamicState<std::shared_ptr<RPTConfig>> rpt_config;

GTNode groupTree(const std::string& root_node, std::size_t report_step, const GTNode * parent) const;
GTNode groupTree(const std::string& root_node, std::size_t report_step, std::size_t level, const std::optional<std::string>& parent_name) const;
void updateGroup(std::shared_ptr<Group> group, size_t reportStep);
bool checkGroups(const ParseContext& parseContext, ErrorGuard& errors);
void updateUDQActive( std::size_t timeStep, std::shared_ptr<UDQActive> udq );
Expand Down
14 changes: 8 additions & 6 deletions src/opm/parser/eclipse/EclipseState/Schedule/Group/GTNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

namespace Opm {

GTNode::GTNode(const Group& group_arg, const GTNode * parent_arg) :
GTNode::GTNode(const Group& group_arg, std::size_t level, const std::optional<std::string>& parent_name) :
m_group(group_arg),
m_parent(parent_arg)
{}
m_level(level),
m_parent_name(parent_name)
{
}

const std::string& GTNode::name() const {
return this->m_group.name();
Expand All @@ -34,9 +36,9 @@ const Group& GTNode::group() const {
return this->m_group;
}

const GTNode& GTNode::parent() const {
if (this->m_parent)
return *this->m_parent;
const std::string& GTNode::parent_name() const {
if (this->m_parent_name.has_value())
return *this->m_parent_name;

throw std::invalid_argument("Tried to access parent of root in GroupTree. Root: " + this->name());
}
Expand Down
8 changes: 4 additions & 4 deletions src/opm/parser/eclipse/EclipseState/Schedule/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2218,25 +2218,25 @@ void Schedule::invalidNamePattern( const std::string& namePattern, std::size_t
}


GTNode Schedule::groupTree(const std::string& root_node, std::size_t report_step, const GTNode * parent) const {
GTNode Schedule::groupTree(const std::string& root_node, std::size_t report_step, std::size_t level, const std::optional<std::string>& parent_name) const {
auto root_group = this->getGroup(root_node, report_step);
GTNode tree(root_group, parent);
GTNode tree(root_group, level, parent_name);

for (const auto& wname : root_group.wells()) {
const auto& well = this->getWell(wname, report_step);
tree.add_well(well);
}

for (const auto& gname : root_group.groups()) {
auto child_group = this->groupTree(gname, report_step, std::addressof(tree));
auto child_group = this->groupTree(gname, report_step, level + 1, root_node);
tree.add_group(child_group);
}

return tree;
}

GTNode Schedule::groupTree(const std::string& root_node, std::size_t report_step) const {
return this->groupTree(root_node, report_step, nullptr);
return this->groupTree(root_node, report_step, 0, {});
}


Expand Down
4 changes: 2 additions & 2 deletions tests/parser/ScheduleTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,13 @@ BOOST_AUTO_TEST_CASE(GroupTree2TEST) {
auto gt = schedule.groupTree(0);
BOOST_CHECK_EQUAL(gt.wells().size(), 0);
BOOST_CHECK_EQUAL(gt.group().name(), "FIELD");
BOOST_CHECK_THROW(gt.parent(), std::invalid_argument);
BOOST_CHECK_THROW(gt.parent_name(), std::invalid_argument);

auto cg = gt.groups();
auto pg = cg[0];
BOOST_CHECK_EQUAL(cg.size(), 1);
BOOST_CHECK_EQUAL(pg.group().name(), "PLATFORM");
BOOST_CHECK_EQUAL(pg.parent().name(), "FIELD");
BOOST_CHECK_EQUAL(pg.parent_name(), "FIELD");
}


Expand Down

0 comments on commit ad74644

Please sign in to comment.