Passing std::vectors to pass data for C and B faster. Variables for D are initialized in initializer list.

This commit is contained in:
T.D. (Tongdong) Qiu 2020-05-21 11:41:15 +02:00
parent f04a629546
commit 98a8dac155
5 changed files with 19 additions and 18 deletions

View File

@ -32,9 +32,9 @@ namespace Opm
MultisegmentWellContribution::MultisegmentWellContribution(unsigned int dim_, unsigned int dim_wells_,
unsigned int Nb_, unsigned int Mb_,
unsigned int BnumBlocks_, double *Bvalues, unsigned int *BcolIndices, unsigned int *BrowPointers,
unsigned int BnumBlocks_, std::vector<double> &Bvalues, std::vector<unsigned int> &BcolIndices, std::vector<unsigned int> &BrowPointers,
unsigned int DnumBlocks_, double *Dvalues, int *DcolPointers, int *DrowIndices,
double *Cvalues)
std::vector<double> &Cvalues)
:
dim(dim_), // size of blockvectors in vectors x and y, equal to MultisegmentWell::numEq
dim_wells(dim_wells_), // size of blocks in C, B and D, equal to MultisegmentWell::numWellEq
@ -43,16 +43,16 @@ namespace Opm
M(Mb_*dim_wells), // number of rows, M == dim_wells*Mb
Mb(Mb_), // number of blockrows in C, D and B
DnumBlocks(DnumBlocks_), // number of blocks in D
BnumBlocks(BnumBlocks_) // number of blocks in C and B
BnumBlocks(BnumBlocks_), // number of blocks in C and B
// copy data for matrix D into vectors to prevent it going out of scope
Dvals(Dvalues, Dvalues + DnumBlocks*dim_wells*dim_wells),
Dcols(DcolPointers, DcolPointers + M + 1),
Drows(DrowIndices, DrowIndices + DnumBlocks*dim_wells*dim_wells)
{
Cvals.insert(Cvals.end(), Cvalues, Cvalues + BnumBlocks*dim*dim_wells);
Dvals.insert(Dvals.end(), Dvalues, Dvalues + DnumBlocks*dim_wells*dim_wells);
Bvals.insert(Bvals.end(), Bvalues, Bvalues + BnumBlocks*dim*dim_wells);
Bcols.insert(Bcols.end(), BcolIndices, BcolIndices + BnumBlocks);
Brows.insert(Brows.end(), BrowPointers, BrowPointers + M + 1);
Dcols.insert(Dcols.end(), DcolPointers, DcolPointers + M + 1);
Drows.insert(Drows.end(), DrowIndices, DrowIndices + DnumBlocks*dim_wells*dim_wells);
Cvals = std::move(Cvalues);
Bvals = std::move(Bvalues);
Bcols = std::move(BcolIndices);
Brows = std::move(BrowPointers);
z1.resize(Mb * dim_wells);
z2.resize(Mb * dim_wells);

View File

@ -73,6 +73,7 @@ namespace Opm
/// Create a new MultisegmentWellContribution
/// Matrices C and B are passed in Blocked CSR, matrix D in CSC
/// The variables representing C, B and D will go out of scope when MultisegmentWell::addWellContribution() ends
/// \param[in] dim size of blocks in blockvectors x and y, equal to MultisegmentWell::numEq
/// \param[in] dim_wells size of blocks of C, B and D, equal to MultisegmentWell::numWellEq
/// \param[in] Nb number of blocks in vectors x and y
@ -88,9 +89,9 @@ namespace Opm
/// \param[in] Cvalues nonzero values of matrix C
MultisegmentWellContribution(unsigned int dim, unsigned int dim_wells,
unsigned int Nb, unsigned int Mb,
unsigned int BnumBlocks, double *Bvalues, unsigned int *BcolIndices, unsigned int *BrowPointers,
unsigned int BnumBlocks, std::vector<double> &Bvalues, std::vector<unsigned int> &BcolIndices, std::vector<unsigned int> &BrowPointers,
unsigned int DnumBlocks, double *Dvalues, int *DcolPointers, int *DrowIndices,
double *Cvalues);
std::vector<double> &Cvalues);
/// Destroy a MultisegmentWellContribution, and free memory
~MultisegmentWellContribution();

View File

@ -267,9 +267,9 @@ namespace Opm
void WellContributions::addMultisegmentWellContribution(unsigned int dim, unsigned int dim_wells,
unsigned int Nb, unsigned int Mb,
unsigned int BnumBlocks, double *Bvalues, unsigned int *BcolIndices, unsigned int *BrowPointers,
unsigned int BnumBlocks, std::vector<double> &Bvalues, std::vector<unsigned int> &BcolIndices, std::vector<unsigned int> &BrowPointers,
unsigned int DnumBlocks, double *Dvalues, int *DcolPointers, int *DrowIndices,
double *Cvalues)
std::vector<double> &Cvalues)
{
this->N = Nb * dim;
MultisegmentWellContribution *well = new MultisegmentWellContribution(dim, dim_wells, Nb, Mb, BnumBlocks, Bvalues, BcolIndices, BrowPointers, DnumBlocks, Dvalues, DcolPointers, DrowIndices, Cvalues);

View File

@ -142,9 +142,9 @@ namespace Opm
/// \param[in] Cvalues nonzero values of matrix C
void addMultisegmentWellContribution(unsigned int dim, unsigned int dim_wells,
unsigned int Nb, unsigned int Mb,
unsigned int BnumBlocks, double *Bvalues, unsigned int *BcolIndices, unsigned int *BrowPointers,
unsigned int BnumBlocks, std::vector<double> &Bvalues, std::vector<unsigned int> &BcolIndices, std::vector<unsigned int> &BrowPointers,
unsigned int DnumBlocks, double *Dvalues, int *DcolPointers, int *DrowIndices,
double *Cvalues);
std::vector<double> &Cvalues);
/// Return the number of wells added to this object
/// \return the number of wells added to this object

View File

@ -696,7 +696,7 @@ namespace Opm
Brows.emplace_back(sumBlocks);
}
wellContribs.addMultisegmentWellContribution(numEq, numWellEq, Nb, Mb, BnumBlocks, Bvals.data(), Bcols.data(), Brows.data(), DnumBlocks, Dvals, Dcols, Drows, Cvals.data());
wellContribs.addMultisegmentWellContribution(numEq, numWellEq, Nb, Mb, BnumBlocks, Bvals, Bcols, Brows, DnumBlocks, Dvals, Dcols, Drows, Cvals);
}
#endif