mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #1 from atgeirr/update-get-messages-from-parser
Update get messages from parser branch
This commit is contained in:
commit
8f34d9e375
@ -1,136 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
import sys
|
|
||||||
from trans_graph import TransGraph
|
|
||||||
|
|
||||||
# This file just contains some example functions for how one can poke
|
|
||||||
# around in the TransGraph datastructure.
|
|
||||||
|
|
||||||
|
|
||||||
def direction_count(tg):
|
|
||||||
dir_count = {"X" : 0 ,
|
|
||||||
"Y" : 0 ,
|
|
||||||
"Z" : 0 ,
|
|
||||||
"NNC" : 0 }
|
|
||||||
|
|
||||||
for cell in tg:
|
|
||||||
if cell:
|
|
||||||
for conn in cell:
|
|
||||||
dir_count[ conn.dir ] += 1
|
|
||||||
|
|
||||||
dir_count["Total"] = dir_count["X"] + dir_count["Y"] + dir_count["Z"] + dir_count["NNC"]
|
|
||||||
return dir_count
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def print_cell( prefix , cell ):
|
|
||||||
print "%s: Cell: (%d,%d,%d) " % (prefix , cell.i , cell.j , cell.k)
|
|
||||||
for conn in cell:
|
|
||||||
print " Connection => (%3d,%3d,%3d) Transmissibility: %g Direction: %s" % (conn.i , conn.j , conn.k , conn.T , conn.dir)
|
|
||||||
|
|
||||||
|
|
||||||
print " cell[\"X\"] => %s" % cell["X"]
|
|
||||||
print " cell[\"Y\"] => %s" % cell["Y"]
|
|
||||||
print " cell[\"Z\"] => %s" % cell["Z"]
|
|
||||||
|
|
||||||
|
|
||||||
def connection_to_count(tg , i,j,k):
|
|
||||||
count = 0
|
|
||||||
for cell in tg:
|
|
||||||
if cell.connectsWith(i,j,k):
|
|
||||||
count += 1
|
|
||||||
|
|
||||||
return count
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------
|
|
||||||
|
|
||||||
def direction_example( opm_tg , ecl_tg ):
|
|
||||||
opm_count = direction_count( opm_tg )
|
|
||||||
ecl_count = direction_count( ecl_tg )
|
|
||||||
|
|
||||||
print "OPM: %s" % opm_count
|
|
||||||
print "ECL: %s" % ecl_count
|
|
||||||
print
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def cell_example(opm_tg , ecl_tg ):
|
|
||||||
opm_cell = opm_tg[21,27,10]
|
|
||||||
ecl_cell = ecl_tg[21,27,10]
|
|
||||||
|
|
||||||
print_cell( "OPM: " , opm_cell )
|
|
||||||
print_cell( "ECL: " , ecl_cell )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def count_example(opm_tg , ecl_tg ):
|
|
||||||
i = 5
|
|
||||||
j = 10
|
|
||||||
k = 7
|
|
||||||
print "Opm connections to (%d,%d,%d): %d" % (i,j,k , connection_to_count(opm_tg , i,j,k))
|
|
||||||
print "Ecl connections to (%d,%d,%d): %d" % (i,j,k , connection_to_count(ecl_tg , i,j,k))
|
|
||||||
print
|
|
||||||
|
|
||||||
|
|
||||||
def xtrace_example( opm_tg , ecl_tg , j , k):
|
|
||||||
opm_trace = opm_tg.getXTrace( j , k)
|
|
||||||
ecl_trace = ecl_tg.getXTrace( j , k)
|
|
||||||
|
|
||||||
print "OPM: %s" % opm_trace
|
|
||||||
print "ECL: %s" % ecl_trace
|
|
||||||
print
|
|
||||||
|
|
||||||
|
|
||||||
def ytrace_example( opm_tg , ecl_tg , i , k):
|
|
||||||
opm_trace = opm_tg.getYTrace( i , k )
|
|
||||||
ecl_trace = ecl_tg.getYTrace( i , k )
|
|
||||||
|
|
||||||
print "OPM: %s" % opm_trace
|
|
||||||
print "ECL: %s" % ecl_trace
|
|
||||||
print
|
|
||||||
|
|
||||||
|
|
||||||
def ztrace_example( opm_tg , ecl_tg , i , j):
|
|
||||||
opm_trace = opm_tg.getZTrace( i , j )
|
|
||||||
ecl_trace = ecl_tg.getZTrace( i , j )
|
|
||||||
|
|
||||||
print "OPM: %s" % opm_trace
|
|
||||||
print "ECL: %s" % ecl_trace
|
|
||||||
print
|
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------
|
|
||||||
|
|
||||||
if len(sys.argv) < 3:
|
|
||||||
sys.exit("example.py opm_trans.json eclipse_trans.json")
|
|
||||||
|
|
||||||
opm_tg = TransGraph.load(sys.argv[1])
|
|
||||||
ecl_tg = TransGraph.load(sys.argv[2])
|
|
||||||
|
|
||||||
|
|
||||||
direction_example( opm_tg , ecl_tg )
|
|
||||||
cell_example( opm_tg , ecl_tg )
|
|
||||||
count_example( opm_tg , ecl_tg )
|
|
||||||
|
|
||||||
|
|
||||||
xtrace_example( opm_tg , ecl_tg , 20 ,20)
|
|
||||||
ytrace_example( opm_tg , ecl_tg , 10 ,10)
|
|
||||||
|
|
||||||
ztrace_example( opm_tg , ecl_tg , 10 ,10)
|
|
||||||
ztrace_example( opm_tg , ecl_tg , 10 ,20)
|
|
||||||
ztrace_example( opm_tg , ecl_tg , 20 ,10)
|
|
||||||
ztrace_example( opm_tg , ecl_tg , 20 ,20)
|
|
||||||
ztrace_example( opm_tg , ecl_tg , 30 ,70)
|
|
||||||
ztrace_example( opm_tg , ecl_tg , 30 ,60)
|
|
@ -1,198 +0,0 @@
|
|||||||
# The opm_init_check cpp program will produce two json files which
|
|
||||||
# should describe the transmissibility graph. The structure of the
|
|
||||||
# main chunk of data is a list:
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# ((i1,j1,k1) , (((i2,j2,k2), T12) , ((i3,j3,k3) , T13))),
|
|
||||||
# ((iA,jA,kA) , (((iB,jB,kB), TAB) , ((iC,jC,kC) , TAC))),
|
|
||||||
# ....
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# Cell(i1,j1,k1) is connected to cells (i2,j2,k2) and (i3,j3,k3)
|
|
||||||
# respectively, with transmissibility T12 and T13
|
|
||||||
# respectively. Furthermore cell (iA,iB,iC) is connected to cells
|
|
||||||
# (iB,jB,kB) and (iC,jC,kC) with transmissibilty TAB and TAC
|
|
||||||
# respectively.
|
|
||||||
|
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Connection(object):
|
|
||||||
"""
|
|
||||||
The connection class holds connection information for one cell;
|
|
||||||
including the i,j,k of the cell and the Transmissibility of connection.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self , i1, j1 , k1 , i2 , j2 , k2 , T):
|
|
||||||
self.i = i2
|
|
||||||
self.j = j2
|
|
||||||
self.k = k2
|
|
||||||
self.T = T
|
|
||||||
|
|
||||||
dx = abs(i1 - i2)
|
|
||||||
dy = abs(j1 - j2)
|
|
||||||
dz = abs(k1 - k2)
|
|
||||||
|
|
||||||
if dx == 1 and dy == 0 and dz == 0:
|
|
||||||
self.dir = "X"
|
|
||||||
elif dx == 0 and dy == 1 and dz == 0:
|
|
||||||
self.dir = "Y"
|
|
||||||
elif dx == 0 and dy == 0 and dz == 1:
|
|
||||||
self.dir = "Z"
|
|
||||||
else:
|
|
||||||
self.dir = "NNC"
|
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "<%d,%d,%d>(T:%g)" % (self.i , self.j , self.k , self.T)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CellConnections(object):
|
|
||||||
|
|
||||||
def __init__(self , i,j,k):
|
|
||||||
self.i = i
|
|
||||||
self.j = j
|
|
||||||
self.k = k
|
|
||||||
self.connection_list = []
|
|
||||||
self.connection_map = {}
|
|
||||||
|
|
||||||
|
|
||||||
def __getitem__(self , index):
|
|
||||||
if isinstance(index,int):
|
|
||||||
return self.connection_list[index]
|
|
||||||
else:
|
|
||||||
return self.connection_map[index]
|
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
return len(self.connection_list)
|
|
||||||
|
|
||||||
def has_key(self , dir_key):
|
|
||||||
return self.connection_map.has_key(dir_key)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def addConnections(self , connections):
|
|
||||||
for ijk,T in connections:
|
|
||||||
new_conn = Connection( self.i , self.j , self.k , ijk[0] , ijk[1] , ijk[2] , T)
|
|
||||||
self.connection_list.append( new_conn )
|
|
||||||
if new_conn.dir == "NNC":
|
|
||||||
if not self.connection_map.has_key("NNC"):
|
|
||||||
self.connection_map["NNC"] = []
|
|
||||||
self.connection_map["NNC"].append( new_conn )
|
|
||||||
else:
|
|
||||||
self.connection_map[new_conn.dir] = new_conn
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __nonzero__(self):
|
|
||||||
if len(self.connection_list) > 0:
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def connectsWith(self, i , j , k):
|
|
||||||
for conn in self.connection_list:
|
|
||||||
if conn.i == i and conn.j == j and conn.k == k:
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "<%d,%d,%d> : %s" % (self.i , self.j , self.k , [ conn.__str__() for conn in self.connection_list ])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TransGraph(object):
|
|
||||||
|
|
||||||
def __init__(self , nx , ny , nz):
|
|
||||||
self.nx = nx
|
|
||||||
self.ny = ny
|
|
||||||
self.nz = nz
|
|
||||||
|
|
||||||
self.cell_connections = [ None ] * nx * ny * nz
|
|
||||||
|
|
||||||
|
|
||||||
def __getitem__(self, index):
|
|
||||||
if isinstance(index , tuple):
|
|
||||||
g = index[0] + index[1] * self.nx + index[2]*self.nx*self.ny
|
|
||||||
else:
|
|
||||||
g = index
|
|
||||||
|
|
||||||
connections = self.cell_connections[g]
|
|
||||||
if connections is None:
|
|
||||||
k = g / (self.nx * self.ny)
|
|
||||||
j = (g - k * self.nx * self.ny) / self.nx
|
|
||||||
i = g - k * self.nx * self.ny - j * self.nx
|
|
||||||
self.cell_connections[g] = CellConnections( i,j,k )
|
|
||||||
|
|
||||||
return self.cell_connections[g]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def addCell(self , ijk , new_connections):
|
|
||||||
g = ijk[0] + ijk[1] * self.nx + ijk[2]*self.nx*self.ny
|
|
||||||
connections = self[g]
|
|
||||||
connections.addConnections( new_connections )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getZTrace(self , i , j):
|
|
||||||
trace = []
|
|
||||||
for k in range(self.nz):
|
|
||||||
cell = self[i,j,k]
|
|
||||||
if cell.has_key("Z"):
|
|
||||||
trace.append( cell["Z"].T )
|
|
||||||
else:
|
|
||||||
trace.append( 0 )
|
|
||||||
|
|
||||||
return trace
|
|
||||||
|
|
||||||
|
|
||||||
def getXTrace(self , j , k):
|
|
||||||
trace = []
|
|
||||||
for i in range(self.nx):
|
|
||||||
cell = self[i,j,k]
|
|
||||||
if cell.has_key("X"):
|
|
||||||
trace.append( cell["X"].T )
|
|
||||||
else:
|
|
||||||
trace.append( 0 )
|
|
||||||
|
|
||||||
return trace
|
|
||||||
|
|
||||||
|
|
||||||
def getYTrace(self , i , k):
|
|
||||||
trace = []
|
|
||||||
for j in range(self.ny):
|
|
||||||
cell = self[i,j,k]
|
|
||||||
if cell.has_key("Y"):
|
|
||||||
trace.append( cell["Y"].T )
|
|
||||||
else:
|
|
||||||
trace.append( 0 )
|
|
||||||
|
|
||||||
return trace
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def load(json_file):
|
|
||||||
with open(json_file) as fileH:
|
|
||||||
data = json.load( fileH )
|
|
||||||
|
|
||||||
dims = data["dims"]
|
|
||||||
graph = data["graph"]
|
|
||||||
|
|
||||||
trans_graph = TransGraph( dims[0] , dims[1] , dims[2])
|
|
||||||
|
|
||||||
for cell,connections in graph:
|
|
||||||
trans_graph.addCell( cell , connections )
|
|
||||||
|
|
||||||
return trans_graph
|
|
||||||
|
|
@ -103,56 +103,18 @@
|
|||||||
namespace Opm
|
namespace Opm
|
||||||
{
|
{
|
||||||
|
|
||||||
boost::filesystem::path simulationCaseName( const std::string& casename ) {
|
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
|
|
||||||
const auto exists = []( const fs::path& f ) -> bool {
|
namespace detail
|
||||||
if( !fs::exists( f ) ) return false;
|
|
||||||
|
|
||||||
if( fs::is_regular_file( f ) ) return true;
|
|
||||||
|
|
||||||
return fs::is_symlink( f )
|
|
||||||
&& fs::is_regular_file( fs::read_symlink( f ) );
|
|
||||||
};
|
|
||||||
|
|
||||||
auto simcase = fs::path( casename );
|
|
||||||
|
|
||||||
if( exists( simcase ) ) {
|
|
||||||
return simcase;
|
|
||||||
}
|
|
||||||
|
|
||||||
for( const auto& ext : { std::string("data"), std::string("DATA") } ) {
|
|
||||||
if( exists( simcase.replace_extension( ext ) ) ) {
|
|
||||||
return simcase;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw std::invalid_argument( "Cannot find input case " + casename );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int64_t convertMessageType(const Message::type& mtype)
|
|
||||||
{
|
{
|
||||||
switch (mtype) {
|
boost::filesystem::path simulationCaseName( const std::string& casename );
|
||||||
case Message::type::Debug:
|
int64_t convertMessageType(const Message::type& mtype);
|
||||||
return Log::MessageType::Debug;
|
|
||||||
case Message::type::Info:
|
|
||||||
return Log::MessageType::Info;
|
|
||||||
case Message::type::Warning:
|
|
||||||
return Log::MessageType::Warning;
|
|
||||||
case Message::type::Error:
|
|
||||||
return Log::MessageType::Error;
|
|
||||||
case Message::type::Problem:
|
|
||||||
return Log::MessageType::Problem;
|
|
||||||
case Message::type::Bug:
|
|
||||||
return Log::MessageType::Bug;
|
|
||||||
}
|
|
||||||
throw std::logic_error("Invalid messages type!\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// This class encapsulates the setup and running of
|
/// This class encapsulates the setup and running of
|
||||||
/// a simulator based on an input deck.
|
/// a simulator based on an input deck.
|
||||||
template <class Implementation, class Grid, class Simulator>
|
template <class Implementation, class Grid, class Simulator>
|
||||||
@ -331,7 +293,7 @@ namespace Opm
|
|||||||
std::cerr << "You can only specify a single input deck on the command line.\n";
|
std::cerr << "You can only specify a single input deck on the command line.\n";
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
const auto casename = simulationCaseName( param_.unhandledArguments()[ 0 ] );
|
const auto casename = detail::simulationCaseName( param_.unhandledArguments()[ 0 ] );
|
||||||
param_.insertParameter("deck_filename", casename.string() );
|
param_.insertParameter("deck_filename", casename.string() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -598,41 +560,39 @@ namespace Opm
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Extract messages from parser.
|
||||||
// extract messages from parser
|
// Writes to:
|
||||||
// Write to:
|
// OpmLog singleton.
|
||||||
// logFile_
|
|
||||||
|
|
||||||
void extractMessages()
|
void extractMessages()
|
||||||
{
|
{
|
||||||
// extract messages from deck.
|
auto extractMessage = [](const Message& msg) {
|
||||||
|
auto log_type = detail::convertMessageType(msg.mtype);
|
||||||
|
const auto& location = msg.location;
|
||||||
|
if (location) {
|
||||||
|
OpmLog::addMessage(log_type, Log::fileMessage(location.filename, location.lineno, msg.message));
|
||||||
|
} else {
|
||||||
|
OpmLog::addMessage(log_type, msg.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Extract messages from Deck.
|
||||||
for(const auto& msg : deck_->getMessageContainer()) {
|
for(const auto& msg : deck_->getMessageContainer()) {
|
||||||
auto log_type = convertMessageType(msg.mtype);
|
extractMessage(msg);
|
||||||
const auto& location = msg.location;
|
|
||||||
if (location) {
|
|
||||||
OpmLog::addMessage(log_type, Log::fileMessage(location.filename, location.lineno, msg.message));
|
|
||||||
} else {
|
|
||||||
OpmLog::addMessage(log_type, msg.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// extract messages from EclipseState.
|
|
||||||
|
// Extract messages from EclipseState.
|
||||||
for (const auto& msg : eclipse_state_->getMessageContainer()) {
|
for (const auto& msg : eclipse_state_->getMessageContainer()) {
|
||||||
auto log_type = convertMessageType(msg.mtype);
|
extractMessage(msg);
|
||||||
const auto& location = msg.location;
|
|
||||||
if (location) {
|
|
||||||
OpmLog::addMessage(log_type, Log::fileMessage(location.filename, location.lineno, msg.message));
|
|
||||||
} else {
|
|
||||||
OpmLog::addMessage(log_type, msg.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// run diagnostics
|
|
||||||
|
// Run diagnostics.
|
||||||
// Writes to:
|
// Writes to:
|
||||||
// logFile_
|
// OpmLog singleton.
|
||||||
void runDiagnostics()
|
void runDiagnostics()
|
||||||
{
|
{
|
||||||
// Run relperm diagnostics
|
// Run relperm diagnostics
|
||||||
@ -797,6 +757,67 @@ namespace Opm
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
boost::filesystem::path simulationCaseName( const std::string& casename ) {
|
||||||
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
|
const auto exists = []( const fs::path& f ) -> bool {
|
||||||
|
if( !fs::exists( f ) ) return false;
|
||||||
|
|
||||||
|
if( fs::is_regular_file( f ) ) return true;
|
||||||
|
|
||||||
|
return fs::is_symlink( f )
|
||||||
|
&& fs::is_regular_file( fs::read_symlink( f ) );
|
||||||
|
};
|
||||||
|
|
||||||
|
auto simcase = fs::path( casename );
|
||||||
|
|
||||||
|
if( exists( simcase ) ) {
|
||||||
|
return simcase;
|
||||||
|
}
|
||||||
|
|
||||||
|
for( const auto& ext : { std::string("data"), std::string("DATA") } ) {
|
||||||
|
if( exists( simcase.replace_extension( ext ) ) ) {
|
||||||
|
return simcase;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::invalid_argument( "Cannot find input case " + casename );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int64_t convertMessageType(const Message::type& mtype)
|
||||||
|
{
|
||||||
|
switch (mtype) {
|
||||||
|
case Message::type::Debug:
|
||||||
|
return Log::MessageType::Debug;
|
||||||
|
case Message::type::Info:
|
||||||
|
return Log::MessageType::Info;
|
||||||
|
case Message::type::Warning:
|
||||||
|
return Log::MessageType::Warning;
|
||||||
|
case Message::type::Error:
|
||||||
|
return Log::MessageType::Error;
|
||||||
|
case Message::type::Problem:
|
||||||
|
return Log::MessageType::Problem;
|
||||||
|
case Message::type::Bug:
|
||||||
|
return Log::MessageType::Bug;
|
||||||
|
}
|
||||||
|
throw std::logic_error("Invalid messages type!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Opm
|
} // namespace Opm
|
||||||
|
|
||||||
#endif // OPM_FLOWMAIN_HEADER_INCLUDED
|
#endif // OPM_FLOWMAIN_HEADER_INCLUDED
|
||||||
|
Loading…
Reference in New Issue
Block a user