75 ASSERT(
IsA != NULL,
"Index set IsA is not defined.\n" );
103 loc_size_A(other.loc_size_A), loc_size_B(other.loc_size_B), state(other.state),
104 Compl(other.Compl), ds_(other.ds_)
106 MatCopy(other.
IA,
IA, DIFFERENT_NONZERO_PATTERN);
107 MatCopy(other.
IAB,
IAB, DIFFERENT_NONZERO_PATTERN);
143 PetscErrorCode ierr = 0;
145 PetscScalar *rhs_array, *sol_array;
147 mat_reuse=MAT_REUSE_MATRIX;
149 mat_reuse=MAT_INITIAL_MATRIX;
154 VecGetArray(
rhs_, &rhs_array);
155 VecCreateMPIWithArray(PETSC_COMM_WORLD,1,
loc_size_A,PETSC_DETERMINE,rhs_array,&(
RHS1));
159 VecCreateMPIWithArray(PETSC_COMM_WORLD,1,
loc_size_A,PETSC_DETERMINE,sol_array,&(
Sol1));
164 VecRestoreArray(
rhs_, &rhs_array);
167 VecGetArray(
Sol2, &sol_array );
170 VecRestoreArray(
Sol2, &sol_array );
194 ierr+=MatMatMult(
IA,
B, mat_reuse, 1.0 ,&(
IAB));
199 ierr+=MatMatMult(
Bt,
IAB, mat_reuse, 1.9 ,&(
xA));
223 ASSERT( ierr == 0,
"PETSC Error during calculation of Schur complement.\n");
279 ASSERT(ls !=
nullptr,
"NULL complement ls.\n");
293 PetscInt ncols, pos_start, pos_start_IA;
295 MatReuse mat_reuse=MAT_REUSE_MATRIX;
300 MatGetOwnershipRange(
matrix_,&pos_start,PETSC_NULL);
301 MatGetOwnershipRange(
IA,&pos_start_IA,PETSC_NULL);
304 const PetscInt *cols;
305 const PetscScalar *vals;
309 unsigned int mat_block=1;
310 for(
unsigned int loc_row=0; loc_row < processed_rows.size(); loc_row++) {
311 if (processed_rows[loc_row] != 0)
continue;
313 PetscInt min=std::numeric_limits<int>::max(), max=-1, size_submat;
314 unsigned int b_vals = 0;
316 ierr = MatGetRow(
matrix_, loc_row + pos_start, &ncols, &cols, PETSC_NULL);
317 for (PetscInt i=0; i<ncols; i++) {
318 if (cols[i] < pos_start || cols[i] >= pos_start+
loc_size_A) {
329 size_submat = max - min + 1;
330 ASSERT(ncols-b_vals == size_submat,
"Submatrix cannot contains empty values.\n");
332 ierr = MatRestoreRow(
matrix_, loc_row + pos_start, &ncols, &cols, PETSC_NULL);
333 arma::mat submat2(size_submat, size_submat);
335 for (PetscInt i=0; i<size_submat; i++) {
336 processed_rows[ loc_row + i ] = mat_block;
337 submat_rows.push_back( i + loc_row + pos_start_IA );
338 ierr = MatGetRow(
matrix_, i + loc_row + pos_start, &ncols, &cols, &vals);
339 for (PetscInt j=0; j<ncols; j++) {
340 if (cols[j] >= pos_start && cols[j] < pos_start+
loc_size_A) {
341 submat2( i, cols[j] - loc_row - pos_start ) = vals[j];
344 ierr = MatRestoreRow(
matrix_, i + loc_row + pos_start, &ncols, &cols, &vals);
356 arma::mat invmat = submat2.i();
358 const PetscInt* rows = &submat_rows[0];
359 MatSetValues(
IA, submat_rows.size(), rows, submat_rows.size(), rows, invmat.memptr(), INSERT_VALUES);
364 MatAssemblyBegin(
IA, MAT_FINAL_ASSEMBLY);
365 MatAssemblyEnd(
IA, MAT_FINAL_ASSEMBLY);
374 return std::numeric_limits<double>::infinity();
384 return converged_reason;
393 if (
B != NULL ) MatDestroy(&
B);
394 if (
Bt != NULL ) MatDestroy(&
Bt);
395 if (
xA != NULL ) MatDestroy(&
xA);
396 if (
IA != NULL ) MatDestroy(&
IA);
397 if (
IAB != NULL ) MatDestroy(&
IAB);
398 if (
IsA != NULL ) ISDestroy(&
IsA);
399 if (
IsB != NULL ) ISDestroy(&
IsB);
400 if (
RHS1 != NULL ) VecDestroy(&
RHS1);
401 if (
RHS2 != NULL ) VecDestroy(&
RHS2);
402 if (
Sol1 != NULL ) VecDestroy(&
Sol1);
403 if (
Sol2 != NULL ) VecDestroy(&
Sol2);
404 if (
IA != NULL ) MatDestroy(&
IA);