Added copyFrom() property to GridProperty
This commit is contained in:
committed by
Andreas Lauser
parent
22ed38b319
commit
bd1c756e30
@@ -81,6 +81,21 @@ public:
|
||||
void loadFromDeckKeyword(std::shared_ptr<const Box> inputBox , DeckKeywordConstPtr deckKeyword);
|
||||
void loadFromDeckKeyword(DeckKeywordConstPtr deckKeyword);
|
||||
|
||||
|
||||
|
||||
void copyFrom(const GridProperty<T>& src, std::shared_ptr<const Box> inputBox) {
|
||||
if (inputBox->isGlobal()) {
|
||||
std::copy( src.m_data.begin() , src.m_data.end() , m_data.begin());
|
||||
} else {
|
||||
const std::vector<size_t>& indexList = inputBox->getIndexList();
|
||||
for (size_t i = 0; i < indexList.size(); i++) {
|
||||
size_t targetIndex = indexList[i];
|
||||
m_data[targetIndex] = src.m_data[targetIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void setFromVector(const std::vector<T>& data) {
|
||||
|
||||
@@ -120,3 +120,22 @@ BOOST_AUTO_TEST_CASE(SetFromDeckKeyword) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(copy) {
|
||||
Opm::GridProperty<int> prop1( 4 , 4 , 2 , "P1" , 0);
|
||||
Opm::GridProperty<int> prop2( 4 , 4 , 2 , "P2" , 9);
|
||||
|
||||
Opm::Box global(4,4,2);
|
||||
std::shared_ptr<Opm::Box> layer0 = std::make_shared<Opm::Box>(global , 0,3,0,3,0,0);
|
||||
|
||||
prop2.copyFrom(prop1 , layer0);
|
||||
|
||||
for (size_t j=0; j < 4; j++) {
|
||||
for (size_t i=0; i < 4; i++) {
|
||||
|
||||
BOOST_CHECK_EQUAL( prop2.iget(i,j,0) , 0 );
|
||||
BOOST_CHECK_EQUAL( prop2.iget(i,j,1) , 9 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user