Added containsNaN() method to GridProperty

This commit is contained in:
Joakim Hove
2014-09-27 13:51:09 +02:00
parent b26475031c
commit e8c5176f1b
3 changed files with 39 additions and 0 deletions

View File

@@ -32,4 +32,25 @@ void GridProperty<double>::setDataPoint(size_t sourceIdx, size_t targetIdx, Opm:
m_data[targetIdx] = deckItem->getSIDouble(sourceIdx);
}
template<>
bool GridProperty<double>::containsNaN( ) {
bool return_value = false;
size_t size = m_data.size();
size_t index = 0;
while (true) {
if (std::isnan(m_data[index])) {
return_value = true;
break;
}
index++;
if (index == size)
break;
}
return return_value;
}
}

View File

@@ -144,6 +144,9 @@ public:
iset(g,value);
}
bool containsNaN( ) {
throw std::logic_error("Only <double> and can be meaningfully queried for nan");
}
void multiplyWith(const GridProperty<T>& other) {
if ((m_nx == other.m_nx) && (m_ny == other.m_ny) && (m_nz == other.m_nz)) {

View File

@@ -61,6 +61,21 @@ BOOST_AUTO_TEST_CASE(Empty) {
}
BOOST_AUTO_TEST_CASE(HasNAN) {
double nan = std::numeric_limits<double>::quiet_NaN();
typedef Opm::GridProperty<double>::SupportedKeywordInfo SupportedKeywordInfo;
SupportedKeywordInfo keywordInfo("PORO" , nan , "1");
Opm::GridProperty<double> poro( 2 , 2 , 1 , keywordInfo);
BOOST_CHECK( poro.containsNaN() );
poro.iset(0,0.15);
poro.iset(1,0.15);
poro.iset(2,0.15);
BOOST_CHECK( poro.containsNaN() );
poro.iset(3,0.15);
BOOST_CHECK( !poro.containsNaN() );
}
BOOST_AUTO_TEST_CASE(EmptyDefault) {
typedef Opm::GridProperty<int>::SupportedKeywordInfo SupportedKeywordInfo;
SupportedKeywordInfo keywordInfo("SATNUM" , 0, "1");