Added code to finalize writing of group data to restart file

This commit is contained in:
Jostein Alvestad
2018-06-12 13:56:44 +02:00
parent cedadaf649
commit c5a1b30dc1
6 changed files with 159 additions and 44 deletions

View File

@@ -34,6 +34,21 @@ namespace Opm {
namespace Opm { namespace RestartIO { namespace Helpers {
class groupMaps {
public:
const std::map <size_t, const Opm::Group*>& indexGroupMap() const;
const std::map <const std::string, size_t>& groupNameIndexMap() const;
void currentGrpTreeNameSeqIndMap(const Opm::Schedule& sched,
const size_t simStep,
const std::map<const std::string , size_t>& GnIMap,
const std::map<size_t, const Opm::Group*>& IGMap);
private:
std::map <size_t, const Opm::Group*> m_indexGroupMap;
std::map <const std::string, size_t> m_groupNameIndexMap;
};
class AggregateGroupData
{
public:
@@ -51,7 +66,7 @@ namespace Opm { namespace RestartIO { namespace Helpers {
#if 0
void captureDynamicGroupData(const Opm::Phases& phases,
const Opm::Schedule& sched,
const std::size_t rptStep,
const std::size_t simStep,
const Opm::data::WellRates& wRates);
#endif
@@ -79,13 +94,13 @@ namespace Opm { namespace RestartIO { namespace Helpers {
return this->zGroup_.data();
}
const std::vector<std::string> restart_group_keys = {"GOPP", "GWPP", "GOPR", "GWPR", "GGPR",
"GVPR", "GWIR", "GGIR", "GWCT", "GGOR",
const std::vector<std::string> restart_group_keys = {"GOPP", "GWPP", "GOPR", "GWPR", "GGPR",
"GVPR", "GWIR", "GGIR", "GWCT", "GGOR",
"GOPT", "GWPT", "GGPT", "GVPT", "GWIT",
"GGIT"};
const std::vector<std::string> restart_field_keys = {"FOPP", "FWPP", "FOPR", "FWPR", "FGPR",
"FVPR", "FWIR", "FGIR", "FWCT", "FGOR",
const std::vector<std::string> restart_field_keys = {"FOPP", "FWPP", "FOPR", "FWPR", "FGPR",
"FVPR", "FWIR", "FGIR", "FWCT", "FGOR",
"FOPT", "FWPT", "FGPT", "FVPT", "FWIT",
"FGIT"};
@@ -97,7 +112,7 @@ namespace Opm { namespace RestartIO { namespace Helpers {
{"GWIR", 5},
{"GGIR", 6},
{"GWCT", 8},
{"GGOR", 8},
{"GGOR", 9},
{"GOPT", 10},
{"GWPT", 11},
{"GGPT", 12},
@@ -116,7 +131,7 @@ namespace Opm { namespace RestartIO { namespace Helpers {
{"FWIR", 5},
{"FGIR", 6},
{"FWCT", 8},
{"FGOR", 8},
{"FGOR", 9},
{"FOPT", 10},
{"FWPT", 11},
{"FGPT", 12},

View File

@@ -22,17 +22,21 @@
#include <string>
#include <vector>
#include <map>
namespace Opm {
class GroupTree {
public:
void update( const std::string& name );
void update( const std::string& name, const std::string& parent );
void update( const std::string& name);
void update( const std::string& name, const std::string& parent);
void updateSeqIndex( const std::string& name, const std::string& other_parent);
bool exists( const std::string& group ) const;
const std::string& parent( const std::string& name ) const;
std::vector< std::string > children( const std::string& parent ) const;
const std::map<const std::string , size_t>& nameSeqIndMap() const;
const std::map<size_t, const std::string >& seqIndNameMap() const;
size_t groupTreeSize();
bool operator==( const GroupTree& ) const;
bool operator!=( const GroupTree& ) const;
@@ -53,6 +57,8 @@ class GroupTree {
std::vector< group > groups = { group { "FIELD", "" } };
friend bool operator<( const std::string&, const group& );
std::vector< group >::iterator find( const std::string& );
std::map<const std::string , size_t> m_nameSeqIndMap;
std::map<size_t, const std::string > m_seqIndNameMap;
};
}

View File

@@ -145,7 +145,6 @@ namespace {
std::map <size_t, const Opm::Group*> currentGroupMapIndexGroup(const Opm::Schedule& sched, const size_t simStep, const std::vector<int>& inteHead)
{
//const std::vector< const Opm::Group* > groups = sched.getGroups(simStep);
const auto& groups = sched.getGroups(simStep);
// make group index for current report step
std::map <size_t, const Opm::Group*> indexGroupMap;
@@ -160,14 +159,13 @@ namespace {
std::map <std::string, size_t> currentGroupMapNameIndex(const Opm::Schedule& sched, const size_t simStep, const std::vector<int>& inteHead)
{
//const std::vector< const Opm::Group* > groups = sched.getGroups(simStep);
const auto& groups = sched.getGroups(simStep);
// make group index for current report step
std::map <std::string, size_t> groupIndexMap;
// make group name to index map for the current time step
std::map <const std::string, size_t> groupIndexMap;
for (const auto* group : groups) {
int ind = (group->name() == "FIELD")
? ngmaxz(inteHead)-1 : group->seqIndex()-1;
std::pair<std::string, size_t> groupPair = std::make_pair(group->name(), ind);
std::pair<const std::string, size_t> groupPair = std::make_pair(group->name(), ind);
groupIndexMap.insert(groupPair);
}
return groupIndexMap;
@@ -363,42 +361,61 @@ namespace {
const auto childGroups = sched.getChildGroups(group.name(), simStep);
const auto childWells = sched.getChildWells(group.name(), simStep);
//std::cout << "IGrpArray - staticContrib - before currentGroupMapIndexGroup(sched, simStep, inteHead)" << std::endl;
//const auto& groupMapIndexGroup = currentGroupMapIndexGroup(sched, simStep, inteHead);
//std::cout << "IGrpArray - staticContrib - before currentGroupMapNameIndex(sched, simStep, inteHead)" << std::endl;
const auto groupMapNameIndex = currentGroupMapNameIndex(sched, simStep, inteHead);
const auto groupMapNameIndex = currentMapGroup_nameIndex(sched, simStep, inteHead);
const auto mapIndexGroup = currentMapIndexGroup(sched, simStep, inteHead);
if ((childGroups.size() != 0) && (childWells.size()!=0))
throw std::invalid_argument("group has both wells and child groups" + group.name());
int igrpCount = 0;
if (childWells.size() != 0) {
//group has child wells
//std::cout << "IGrpArray - staticContrib: childwells for group.name(): " << group.name() << "childWells - size: " << childWells.size() << std::endl;
//for (const auto well : childWells ) {
for ( auto it = childWells.begin() ; it != childWells.end(); it++) {
//std::cout << "Child well name: " << it->name() << " Well seqIndex(): " << it->seqIndex() << std::endl;
iGrp[igrpCount] = (*it)->seqIndex()+1;
igrpCount+=1;
//std::cout << "childWells: igrpCount after increment: " << igrpCount << std::endl;
}
}
else if (childGroups.size() != 0) {
//group has child groups
//The field group always has seqIndex = 0 because it is always defined first
//Hence the all groups except the Field group uses the seqIndex assigned
//std::cout << "IGrpArray - staticContrib: childGroups for group.name(): " << group.name() << "childGroups - size: " << childGroups.size() << std::endl;
//for (const auto grp : childGroups ) {
for ( auto it = childGroups.begin() ; it != childGroups.end(); it++) {
//std::cout << "Child Group name: " << it->name() << " Group seqIndex(): " << it->seqIndex()-1 << std::endl;
iGrp[igrpCount] = (*it)->seqIndex();
igrpCount+=1;
//std::cout << "childGroups: igrpCount after increment: " << igrpCount << std::endl;
std::vector<size_t> childGroupIndex;
Opm::RestartIO::Helpers::groupMaps groupMap;
groupMap.currentGrpTreeNameSeqIndMap(sched, simStep, groupMapNameIndex,mapIndexGroup);
const auto indGroupMap = groupMap.indexGroupMap();
const auto gNameIndMap = groupMap.groupNameIndexMap();
for (auto* grp : childGroups) {
auto groupName = grp->name();
auto searchGTName = gNameIndMap.find(groupName);
if (searchGTName != gNameIndMap.end()) {
childGroupIndex.push_back(searchGTName->second);
}
else {
throw std::invalid_argument( "Invalid group name" );
}
}
std::sort(childGroupIndex.begin(), childGroupIndex.end());
for (auto groupTreeIndex : childGroupIndex) {
auto searchGTIterator = indGroupMap.find(groupTreeIndex);
if (searchGTIterator != indGroupMap.end()) {
auto gname = (searchGTIterator->second)->name();
auto gSeqNoItr = groupMapNameIndex.find(gname);
if (gSeqNoItr != groupMapNameIndex.end()) {
iGrp[igrpCount] = (gSeqNoItr->second) + 1;
igrpCount+=1;
}
else {
std::cout << "AggregateGroupData, ChildGroups - Group name: groupMapNameIndex: " << gSeqNoItr->first << std::endl;
throw std::invalid_argument( "Invalid group name" );
}
}
else {
std::cout << "AggregateGroupData, ChildGroups - GroupTreeIndex: " << groupTreeIndex << std::endl;
throw std::invalid_argument( "Invalid GroupTree index" );
}
}
}
//assign the number of child wells or child groups to
// location nwgmax
//std::cout << "IGrpArray - staticContrib: childGroups.size() " << childGroups.size() << "childWells.size(): " << childWells.size() << std::endl;
//std::cout << "IGrpArray - staticContrib: nwgmax: " << nwgmax << std::endl;
iGrp[nwgmax] = (childGroups.size() == 0)
? childWells.size() : childGroups.size();
@@ -438,7 +455,6 @@ namespace {
//location nwgmax + 28
const auto& groupTree = sched.getGroupTree( simStep );
const std::string& parent = groupTree.parent(group.name());
//std::cout << "IGrpArray - staticContrib - before groupMapNameIndex.find(parent)" << std::endl;
if (group.name() == "FIELD")
iGrp[nwgmax+28] = 0;
else {
@@ -547,17 +563,18 @@ namespace {
? restart_field_keys : restart_group_keys;
const std::map<std::string, size_t>& keyToIndex = (groupName == "FIELD")
? fieldKeyToIndex : groupKeyToIndex;
for (const auto key : keys) {
std::string compKey = (groupName == "FIELD")
? key : key + ":" + groupName;
std::cout << "AggregateGroupData compKey: " << compKey << std::endl;
if (sumState.has(compKey)) {
double keyValue = sumState.get(compKey);
std::cout << "AggregateGroupData_compkey: " << compKey << std::endl;
const auto itr = keyToIndex.find(key);
xGrp[itr->second] = keyValue;
}
else {
std::cout << "AggregateGroupData_compkey: " << compKey << std::endl;
std::cout << "AggregateGroupData, empty " << std::endl;
//throw std::invalid_argument("No such keyword: " + compKey);
}
@@ -589,6 +606,45 @@ namespace {
}
} // Anonymous
void
Opm::RestartIO::Helpers::groupMaps::
currentGrpTreeNameSeqIndMap(const Opm::Schedule& sched,
const size_t simStep,
const std::map<const std::string , size_t>& GnIMap,
const std::map<size_t, const Opm::Group*>& IGMap)
{
const auto& grpTreeNSIMap = (sched.getGroupTree(simStep)).nameSeqIndMap();
const auto& grpTreeSINMap = (sched.getGroupTree(simStep)).seqIndNameMap();
// make group index for current report step
size_t index = 0;
for (auto itr = IGMap.begin(); itr != IGMap.end(); itr++) {
auto name = (itr->second)->name();
auto srchGN = grpTreeNSIMap.find(name);
if (srchGN != grpTreeNSIMap.end()) {
//come here if group is in gruptree
this->m_indexGroupMap.insert(std::make_pair(srchGN->second, itr->second));
this->m_groupNameIndexMap.insert(std::make_pair(srchGN->first, srchGN->second));
}
else {
//come here if group is not in gruptree to put in from global group list
this->m_indexGroupMap.insert(std::make_pair(itr->first, itr->second));
this->m_groupNameIndexMap.insert(std::make_pair(name, itr->first));
}
}
}
const std::map <size_t, const Opm::Group*>&
Opm::RestartIO::Helpers::groupMaps::indexGroupMap() const
{
return this->m_indexGroupMap;
}
const std::map <const std::string, size_t>&
Opm::RestartIO::Helpers::groupMaps::groupNameIndexMap() const
{
return this->m_groupNameIndexMap;
}
// =====================================================================
Opm::RestartIO::Helpers::AggregateGroupData::
@@ -614,15 +670,18 @@ captureDeclaredGroupData(const Opm::Schedule& sched,
const Opm::SummaryState& sumState,
const std::vector<int>& inteHead)
{
std::map <size_t, const Opm::Group*> indexGroupMap = currentGroupMapIndexGroup(sched, simStep, inteHead);
std::map <std::string, size_t> nameIndexMap = currentGroupMapNameIndex(sched, simStep, inteHead);
const auto indexGroupMap = currentMapIndexGroup(sched, simStep, inteHead);
const auto nameIndexMap = currentMapGroup_nameIndex(sched, simStep, inteHead);
//Opm::RestartIO::Helpers::groupMaps grpMaps;
//grpMaps.currentGrpTreeNameSeqIndMap(sched, simStep, nameIndexMap,indexGroupMap);
std::vector<const Opm::Group*> curGroups;
curGroups.resize(ngmaxz(inteHead));
//
//initialize curgroups
for (auto* cg : curGroups) cg = nullptr;
std::map <size_t, const Opm::Group*>::iterator it = indexGroupMap.begin();
auto it = indexGroupMap.begin();
while (it != indexGroupMap.end())
{
curGroups[static_cast<int>(it->first)] = it->second;

View File

@@ -630,6 +630,7 @@ void writeGroup(::Opm::RestartIO::ecl_rst_file_type * rst_file,
groupData.captureDeclaredGroupData(schedule, rst_g_keys, rst_f_keys, grpKeyToInd, fldKeyToInd, simStep, sumState, ih);
write_kw(rst_file, EclKW<int> ("IGRP", groupData.getIGroup()));
write_kw(rst_file, EclKW<float>("SGRP", groupData.getSGroup()));
write_kw(rst_file, EclKW<double>("XGRP", groupData.getXGroup()));
}

View File

@@ -19,13 +19,14 @@
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <opm/parser/eclipse/EclipseState/Schedule/GroupTree.hpp>
namespace Opm {
void GroupTree::update( const std::string& name ) {
this->update( name, "FIELD" );
void GroupTree::update( const std::string& name) {
this->update( name, "FIELD");
}
/*
@@ -35,8 +36,16 @@ void GroupTree::update( const std::string& name ) {
* this grouptree class is just meta data for the actual group objects (stored
* and represented elsewhere)
*/
const std::map<const std::string , size_t>& GroupTree::nameSeqIndMap() const {
return m_nameSeqIndMap;
}
void GroupTree::update( const std::string& name, const std::string& other_parent ) {
const std::map<size_t, const std::string >& GroupTree::seqIndNameMap() const {
return m_seqIndNameMap;
}
void GroupTree::update( const std::string& name, const std::string& other_parent) {
if( name == "FIELD" )
throw std::invalid_argument( "The FIELD group name is reserved." );
@@ -44,12 +53,10 @@ void GroupTree::update( const std::string& name, const std::string& other_parent
throw std::invalid_argument( "Parent group must have a name." );
auto root = this->find( other_parent );
if( root == this->groups.end() || root->name != other_parent )
if( root == this->groups.end() || root->name != other_parent )
this->groups.insert( root, 1, group { other_parent, "FIELD" } );
auto node = this->find( name );
if( node == this->groups.end() || node->name != name ) {
this->groups.insert( node, 1, group { name, other_parent } );
return;
@@ -58,6 +65,31 @@ void GroupTree::update( const std::string& name, const std::string& other_parent
node->parent = other_parent;
}
void GroupTree::updateSeqIndex( const std::string& name, const std::string& other_parent) {
if( name == "FIELD" )
throw std::invalid_argument( "The FIELD group name is reserved." );
if( other_parent.empty() )
throw std::invalid_argument( "Parent group must have a name." );
// add code to set an index that determine the sequence of the groups
// defined in the group tree
size_t index = this->m_nameSeqIndMap.size();
std::cout << "GroupTree::update - index: " << index << " name: " << name << " other_parent: " << other_parent << std::endl;
auto name_itr = this->m_nameSeqIndMap.find(name);
if (name_itr == this->m_nameSeqIndMap.end()) {
this->m_nameSeqIndMap.insert(std::make_pair(name, index));
this->m_seqIndNameMap.insert(std::make_pair(index, name));
index +=1;
}
auto parent_itr = this->m_nameSeqIndMap.find(other_parent);
if (parent_itr == this->m_nameSeqIndMap.end()) {
this->m_nameSeqIndMap.insert(std::make_pair(other_parent, index));
this->m_seqIndNameMap.insert(std::make_pair(index, other_parent));
}
}
bool GroupTree::exists( const std::string& name ) const {
return std::binary_search( this->groups.begin(),
this->groups.end(),

View File

@@ -20,6 +20,7 @@
#include <string>
#include <vector>
#include <stdexcept>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
@@ -1385,6 +1386,7 @@ namespace Opm {
const std::string& childName = record.getItem("CHILD_GROUP").getTrimmedString(0);
const std::string& parentName = record.getItem("PARENT_GROUP").getTrimmedString(0);
newTree.update(childName, parentName);
newTree.updateSeqIndex(childName, parentName);
if (!hasGroup(parentName))
addGroup( parentName , currentStep );