mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Fixes performance bug in matrix construction.
At the same time changes the construction to be value-oriented, not constructing it in OEM_DATA, but rather in to_petsc_mat
This commit is contained in:
parent
e69d92cca3
commit
43d82a232c
@ -134,11 +134,7 @@ namespace{
|
||||
VecSetFromOptions( solution );
|
||||
VecDuplicate( solution, &rhs );
|
||||
|
||||
MatCreate( PETSC_COMM_WORLD, &A );
|
||||
err = MatSetSizes( A, PETSC_DECIDE, PETSC_DECIDE, size, size );
|
||||
CHKERRXX( err );
|
||||
MatSetFromOptions( A );
|
||||
MatSetUp( A );
|
||||
VecSetFromOptions( b );
|
||||
|
||||
KSPCreate( PETSC_COMM_WORLD, &ksp );
|
||||
}
|
||||
@ -179,23 +175,13 @@ namespace{
|
||||
VecRestoreArray( v, &vec );
|
||||
}
|
||||
|
||||
void to_petsc_mat( const int size, const int nonzeros,
|
||||
const int* ia, const int* ja, const double* sa, Mat A ) {
|
||||
Mat to_petsc_mat( const int size, const int nonzeros,
|
||||
const int* ia, const int* ja, const double* sa ) {
|
||||
|
||||
for( int i = 0; i < size; ++i ) {
|
||||
int nrows = ia[ i + 1 ] - ia[ i ];
|
||||
|
||||
if( nrows == 0 ) continue;
|
||||
|
||||
for( int j = ia[ i ]; j < ia[ i + 1 ]; ++j ) {
|
||||
auto err = MatSetValues( A, 1, &i, 1, &ja[ j ], &sa[ j ], INSERT_VALUES );
|
||||
CHKERRXX( err );
|
||||
}
|
||||
|
||||
auto err = MatAssemblyBegin( A, MAT_FINAL_ASSEMBLY );
|
||||
CHKERRXX( err );
|
||||
MatAssemblyEnd( A, MAT_FINAL_ASSEMBLY );
|
||||
}
|
||||
Mat A;
|
||||
auto err = MatCreateSeqAIJWithArrays( PETSC_COMM_WORLD, size, size, (int*)ia, (int*)ja, (double*)sa, &A );
|
||||
CHKERRXX( err );
|
||||
return A;
|
||||
}
|
||||
|
||||
|
||||
@ -267,7 +253,7 @@ namespace{
|
||||
PCType pc_type = pc.find(pc_type_);
|
||||
|
||||
OEM_DATA t( size );
|
||||
to_petsc_mat( size, nonzeros, ia, ja, sa, t.A );
|
||||
t.A = to_petsc_mat( size, nonzeros, ia, ja, sa );
|
||||
to_petsc_vec( rhs, t.rhs );
|
||||
|
||||
solve_system( t, ksp_type, pc_type, rtol_, atol_, dtol_, maxits_, ksp_view_ );
|
||||
|
Loading…
Reference in New Issue
Block a user