Make Box+BoxManager no longer use shared_ptr
This commit is contained in:
@@ -697,7 +697,7 @@ namespace Opm {
|
||||
for( const auto& deckKeyword : section ) {
|
||||
|
||||
if (supportsGridProperty(deckKeyword.name()) )
|
||||
loadGridPropertyFromDeckKeyword( *boxManager.getActiveBox(),
|
||||
loadGridPropertyFromDeckKeyword( boxManager.getActiveBox(),
|
||||
deckKeyword);
|
||||
else {
|
||||
if (deckKeyword.name() == "BOX")
|
||||
|
||||
@@ -150,5 +150,9 @@ namespace Opm {
|
||||
return true;
|
||||
}
|
||||
|
||||
Box::operator bool() const {
|
||||
return this->size() != 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace Opm {
|
||||
|
||||
class Box {
|
||||
public:
|
||||
Box() = default;
|
||||
Box(int nx , int ny , int nz);
|
||||
Box(const Box& globalBox , int i1 , int i2 , int j1 , int j2 , int k1 , int k2); // Zero offset coordinates.
|
||||
size_t size() const;
|
||||
@@ -36,11 +37,13 @@ namespace Opm {
|
||||
const std::vector<size_t>& getIndexList() const;
|
||||
bool equal(const Box& other) const;
|
||||
|
||||
explicit operator bool() const;
|
||||
|
||||
|
||||
private:
|
||||
void initIndexList();
|
||||
static void assertDims(const Box& globalBox, size_t idim , int l1 , int l2);
|
||||
size_t m_dims[3];
|
||||
size_t m_dims[3] = { 0, 0, 0 };
|
||||
size_t m_offset[3];
|
||||
size_t m_stride[3];
|
||||
|
||||
|
||||
@@ -24,26 +24,25 @@
|
||||
|
||||
namespace Opm {
|
||||
|
||||
BoxManager::BoxManager(int nx , int ny , int nz) {
|
||||
m_globalBox = std::make_shared<const Box>(nx,ny,nz);
|
||||
}
|
||||
BoxManager::BoxManager(int nx , int ny , int nz) :
|
||||
m_globalBox( nx, ny, nz )
|
||||
{}
|
||||
|
||||
|
||||
std::shared_ptr<const Box> BoxManager::getGlobalBox() const {
|
||||
const Box& BoxManager::getGlobalBox() const {
|
||||
return m_globalBox;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const Box> BoxManager::getInputBox() const {
|
||||
const Box& BoxManager::getInputBox() const {
|
||||
return m_inputBox;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const Box> BoxManager::getKeywordBox() const {
|
||||
const Box& BoxManager::getKeywordBox() const {
|
||||
return m_keywordBox;
|
||||
}
|
||||
|
||||
std::shared_ptr<const Box> BoxManager::getActiveBox() const {
|
||||
const Box& BoxManager::getActiveBox() const {
|
||||
if (m_keywordBox)
|
||||
return m_keywordBox;
|
||||
|
||||
@@ -55,14 +54,14 @@ namespace Opm {
|
||||
|
||||
|
||||
void BoxManager::setInputBox( int i1,int i2 , int j1 , int j2 , int k1 , int k2) {
|
||||
m_inputBox.reset( new Box( *m_globalBox , i1,i2,j1,j2,k1,k2) );
|
||||
this->m_inputBox = Box( this->m_globalBox, i1, i2, j1, j2, k1, k2 );
|
||||
}
|
||||
|
||||
void BoxManager::endInputBox() {
|
||||
if (m_keywordBox)
|
||||
if(m_keywordBox)
|
||||
throw std::invalid_argument("Hmmm - this seems like an internal error - the SECTION is terminated with an active keyword box");
|
||||
|
||||
m_inputBox.reset( );
|
||||
m_inputBox = Box{};
|
||||
}
|
||||
|
||||
void BoxManager::endSection() {
|
||||
@@ -70,11 +69,11 @@ namespace Opm {
|
||||
}
|
||||
|
||||
void BoxManager::setKeywordBox( int i1,int i2 , int j1 , int j2 , int k1 , int k2) {
|
||||
m_keywordBox.reset( new Box( *m_globalBox , i1,i2,j1,j2,k1,k2) );
|
||||
this->m_keywordBox = Box( this->m_globalBox, i1, i2, j1, j2, k1, k2 );
|
||||
}
|
||||
|
||||
void BoxManager::endKeyword() {
|
||||
m_keywordBox.reset( );
|
||||
this->m_keywordBox = Box{};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -62,15 +62,15 @@ namespace Opm {
|
||||
void endInputBox();
|
||||
void endKeyword();
|
||||
|
||||
std::shared_ptr<const Box> getActiveBox() const;
|
||||
std::shared_ptr<const Box> getGlobalBox() const;
|
||||
std::shared_ptr<const Box> getInputBox() const;
|
||||
std::shared_ptr<const Box> getKeywordBox() const;
|
||||
const Box& getActiveBox() const;
|
||||
const Box& getGlobalBox() const;
|
||||
const Box& getInputBox() const;
|
||||
const Box& getKeywordBox() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const Box> m_globalBox;
|
||||
std::shared_ptr<const Box> m_inputBox;
|
||||
std::shared_ptr<const Box> m_keywordBox;
|
||||
Box m_globalBox;
|
||||
Box m_inputBox;
|
||||
Box m_keywordBox;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -276,7 +276,7 @@ namespace Opm {
|
||||
GridProperty<T>& property = getKeyword( field );
|
||||
T shiftValue = convertInputValue( property , record.getItem("shift").get< double >(0) );
|
||||
setKeywordBox(record, boxManager);
|
||||
property.add( shiftValue , *boxManager.getActiveBox() );
|
||||
property.add( shiftValue , boxManager.getActiveBox() );
|
||||
} else
|
||||
throw std::invalid_argument("Fatal error processing ADD keyword. Tried to shift not defined keyword " + field);
|
||||
}
|
||||
@@ -289,7 +289,7 @@ namespace Opm {
|
||||
GridProperty<T>& property = getKeyword( field );
|
||||
T factor = convertInputValue( record.getItem("factor").get< double >(0) );
|
||||
setKeywordBox(record, boxManager);
|
||||
property.scale( factor , *boxManager.getActiveBox() );
|
||||
property.scale( factor , boxManager.getActiveBox() );
|
||||
} else
|
||||
throw std::invalid_argument("Fatal error processing ADD keyword. Tried to shift not defined keyword " + field);
|
||||
}
|
||||
@@ -302,7 +302,7 @@ namespace Opm {
|
||||
|
||||
if (hasKeyword( srcField )) {
|
||||
setKeywordBox(record, boxManager);
|
||||
copyKeyword( srcField , targetField , *boxManager.getActiveBox() );
|
||||
copyKeyword( srcField , targetField , boxManager.getActiveBox() );
|
||||
} else {
|
||||
if (!supportsKeyword( srcField))
|
||||
throw std::invalid_argument("Fatal error processing COPY keyword."
|
||||
@@ -320,7 +320,7 @@ namespace Opm {
|
||||
T targetValue = convertInputValue( property , value );
|
||||
|
||||
setKeywordBox(record, boxManager);
|
||||
property.setScalar( targetValue , *boxManager.getActiveBox() );
|
||||
property.setScalar( targetValue , boxManager.getActiveBox() );
|
||||
} else
|
||||
throw std::invalid_argument("Fatal error processing EQUALS keyword. Tried to set not defined keyword " + field);
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ BOOST_AUTO_TEST_CASE(CreateBoxManager) {
|
||||
Opm::BoxManager boxManager(10,10,10);
|
||||
Opm::Box box(10,10,10);
|
||||
|
||||
BOOST_CHECK( box.equal( *boxManager.getGlobalBox()) );
|
||||
BOOST_CHECK( box.equal( *boxManager.getActiveBox()) );
|
||||
BOOST_CHECK( box.equal( boxManager.getGlobalBox()) );
|
||||
BOOST_CHECK( box.equal( boxManager.getActiveBox()) );
|
||||
BOOST_CHECK( !boxManager.getInputBox() );
|
||||
BOOST_CHECK( !boxManager.getKeywordBox() );
|
||||
}
|
||||
@@ -45,16 +45,16 @@ BOOST_AUTO_TEST_CASE(CreateBoxManager) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestInputBox) {
|
||||
Opm::BoxManager boxManager(10,10,10);
|
||||
Opm::Box inputBox( *boxManager.getGlobalBox() , 0,4,0,4,0,4);
|
||||
Opm::Box inputBox( boxManager.getGlobalBox(), 0,4,0,4,0,4);
|
||||
|
||||
boxManager.setInputBox( 0,4,0,4,0,4 );
|
||||
BOOST_CHECK( inputBox.equal( *boxManager.getInputBox()) );
|
||||
BOOST_CHECK( inputBox.equal( *boxManager.getActiveBox()) );
|
||||
BOOST_CHECK( inputBox.equal( boxManager.getInputBox()) );
|
||||
BOOST_CHECK( inputBox.equal( boxManager.getActiveBox()) );
|
||||
|
||||
|
||||
boxManager.endSection();
|
||||
BOOST_CHECK( !boxManager.getInputBox() );
|
||||
BOOST_CHECK( boxManager.getActiveBox()->equal( *boxManager.getGlobalBox()));
|
||||
BOOST_CHECK( boxManager.getActiveBox().equal( boxManager.getGlobalBox()));
|
||||
}
|
||||
|
||||
|
||||
@@ -62,24 +62,24 @@ BOOST_AUTO_TEST_CASE(TestInputBox) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestKeywordBox) {
|
||||
Opm::BoxManager boxManager(10,10,10);
|
||||
Opm::Box inputBox( *boxManager.getGlobalBox() , 0,4,0,4,0,4);
|
||||
Opm::Box keywordBox( *boxManager.getGlobalBox() , 0,2,0,2,0,2);
|
||||
Opm::Box inputBox( boxManager.getGlobalBox() , 0,4,0,4,0,4);
|
||||
Opm::Box keywordBox( boxManager.getGlobalBox() , 0,2,0,2,0,2);
|
||||
|
||||
|
||||
boxManager.setInputBox( 0,4,0,4,0,4 );
|
||||
boxManager.setKeywordBox( 0,2,0,2,0,2 );
|
||||
BOOST_CHECK( inputBox.equal( *boxManager.getInputBox()) );
|
||||
BOOST_CHECK( keywordBox.equal( *boxManager.getKeywordBox()) );
|
||||
BOOST_CHECK( keywordBox.equal( *boxManager.getActiveBox()) );
|
||||
BOOST_CHECK( inputBox.equal( boxManager.getInputBox()) );
|
||||
BOOST_CHECK( keywordBox.equal( boxManager.getKeywordBox()) );
|
||||
BOOST_CHECK( keywordBox.equal( boxManager.getActiveBox()) );
|
||||
|
||||
// Must end keyword first
|
||||
BOOST_CHECK_THROW( boxManager.endSection() , std::invalid_argument );
|
||||
|
||||
boxManager.endKeyword();
|
||||
BOOST_CHECK( inputBox.equal( *boxManager.getActiveBox()) );
|
||||
BOOST_CHECK( inputBox.equal( boxManager.getActiveBox()) );
|
||||
BOOST_CHECK( !boxManager.getKeywordBox() );
|
||||
|
||||
boxManager.endSection();
|
||||
BOOST_CHECK( !boxManager.getInputBox() );
|
||||
BOOST_CHECK( boxManager.getActiveBox()->equal( *boxManager.getGlobalBox()));
|
||||
BOOST_CHECK( boxManager.getActiveBox().equal( boxManager.getGlobalBox()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user