Added functionality to build a GroupTree (from GRUPTREE). Only the groups, not any wells in the tree.

This commit is contained in:
Kristian Flikka
2013-11-13 10:17:55 +01:00
parent 0f09746143
commit 3863df9734
5 changed files with 200 additions and 1 deletions

View File

@@ -0,0 +1,67 @@
/*
Copyright 2013 Statoil 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 <opm/parser/eclipse/EclipseState/Schedule/GroupTreeNode.hpp>
#include <stdexcept>
namespace Opm {
GroupTreeNode::GroupTreeNode(const std::string& name) {
m_name = name;
m_parent = NULL;
}
GroupTreeNode::GroupTreeNode(const std::string& name, GroupTreeNode * parent) {
m_name = name;
m_parent = parent;
}
const std::string& GroupTreeNode::name() const {
return m_name;
}
GroupTreeNode * GroupTreeNode::parent() const {
return m_parent;
}
GroupTreeNodePtr GroupTreeNode::addChildGroup(const std::string& childName) {
if (hasChildGroup(childName)) {
throw std::invalid_argument("Child group with name \"" + childName + "\"already exists.");
}
GroupTreeNodePtr child(new GroupTreeNode(childName, this));
m_childGroups[childName] = child;
return child;
}
bool GroupTreeNode::hasChildGroup(const std::string& childName) const {
return m_childGroups.find(childName) != m_childGroups.end();
}
GroupTreeNodeConstPtr GroupTreeNode::getChildGroup(const std::string& childName) {
if (hasChildGroup(childName)) {
return m_childGroups[childName];
}
throw std::invalid_argument("Child group with name \"" + childName + "\" does not exist.");
}
GroupTreeNodePtr GroupTreeNode::createFieldNode() {
return GroupTreeNodePtr(new GroupTreeNode("FIELD"));
}
}

View File

@@ -0,0 +1,55 @@
/*
Copyright 2013 Statoil 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/>.
*/
#ifndef GROUPTREENODE_HPP
#define GROUPTREENODE_HPP
#include <string>
#include <map>
#include <boost/shared_ptr.hpp>
namespace Opm {
/// This Class is currently ONLY keeping track of the actual group nodes,
/// and knows nothing about the wells. The wells will know which group
/// (leaf) node they belong to.
class GroupTreeNode {
public:
const std::string& name() const;
GroupTreeNode * parent() const;
boost::shared_ptr<GroupTreeNode> addChildGroup(const std::string& childName);
bool hasChildGroup(const std::string& childName) const;
boost::shared_ptr<const GroupTreeNode> getChildGroup(const std::string& childName);
void setParent(GroupTreeNode * parent);
static boost::shared_ptr<GroupTreeNode> createFieldNode();
private:
GroupTreeNode(const std::string& name);
GroupTreeNode(const std::string& name, GroupTreeNode * parent);
std::string m_name;
std::map<std::string, boost::shared_ptr<GroupTreeNode> > m_childGroups;
GroupTreeNode * m_parent;
};
typedef boost::shared_ptr<GroupTreeNode> GroupTreeNodePtr;
typedef boost::shared_ptr<const GroupTreeNode> GroupTreeNodeConstPtr;
}
#endif /* GROUPTREENODE_HPP */

View File

@@ -31,3 +31,8 @@ add_test(NAME runCompletionSetTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMM
add_executable(runDynamicStateTests DynamicStateTests.cpp)
target_link_libraries(runDynamicStateTests Parser ${Boost_LIBRARIES})
add_test(NAME runDynamicStateTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runDynamicStateTests )
add_executable(runGroupTreeNodeTests GroupTreeNodeTests.cpp)
target_link_libraries(runGroupTreeNodeTests Parser ${Boost_LIBRARIES})
add_test(NAME runGroupTreeNodeTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runGroupTreeNodeTests )

View File

@@ -0,0 +1,70 @@
/*
Copyright 2013 Statoil 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 <opm/parser/eclipse/EclipseState/Schedule/GroupTreeNode.hpp>
#define BOOST_TEST_MODULE GroupTreeNodeTests
#include <boost/test/unit_test.hpp>
#include <stdexcept>
using namespace Opm;
BOOST_AUTO_TEST_CASE(CreateFieldNode) {
GroupTreeNodePtr node = GroupTreeNode::createFieldNode();
BOOST_CHECK_EQUAL("FIELD", node->name());
}
BOOST_AUTO_TEST_CASE(CreateFieldNode_HasNoParent) {
GroupTreeNodePtr node = GroupTreeNode::createFieldNode();
BOOST_CHECK(!node->parent());
}
BOOST_AUTO_TEST_CASE(CreateChild_WithFieldParent_ParentSet) {
GroupTreeNodePtr fieldNode = GroupTreeNode::createFieldNode();
GroupTreeNodePtr child = fieldNode->addChildGroup("Child");
BOOST_CHECK_EQUAL(fieldNode.get(), child->parent());
}
BOOST_AUTO_TEST_CASE(CreateChild_WithFieldParent_ParentHasChild) {
GroupTreeNodePtr fieldNode = GroupTreeNode::createFieldNode();
BOOST_CHECK(!fieldNode->hasChildGroup("Child"));
GroupTreeNodePtr child = fieldNode->addChildGroup("Child");
BOOST_REQUIRE(fieldNode->hasChildGroup("Child"));
BOOST_CHECK_EQUAL(child, fieldNode->getChildGroup("Child"));
}
BOOST_AUTO_TEST_CASE(CreateChildGroup_ChildExists_Throws) {
GroupTreeNodePtr fieldNode = GroupTreeNode::createFieldNode();
GroupTreeNodePtr child = fieldNode->addChildGroup("Child");
BOOST_CHECK_THROW(fieldNode->addChildGroup("Child"), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(GetChildGroup_ChildNotExisting_Throws) {
GroupTreeNodePtr fieldNode = GroupTreeNode::createFieldNode();
GroupTreeNodePtr child = fieldNode->addChildGroup("Child2");
BOOST_CHECK_THROW(fieldNode->getChildGroup("Child"), std::invalid_argument);
}