75 ASSERT(
IsA != NULL,
"Index set IsA is not defined.\n" );
101 loc_size_A(other.loc_size_A), loc_size_B(other.loc_size_B), state(other.state),
102 Compl(other.Compl), ds_(other.ds_)
104 MatCopy(other.
IA,
IA, DIFFERENT_NONZERO_PATTERN);
105 MatCopy(other.
IAB,
IAB, DIFFERENT_NONZERO_PATTERN);
141 PetscErrorCode ierr = 0;
143 PetscScalar *rhs_array, *sol_array;
145 mat_reuse=MAT_REUSE_MATRIX;
147 mat_reuse=MAT_INITIAL_MATRIX;
152 VecGetArray(
rhs_, &rhs_array);
153 VecCreateMPIWithArray(PETSC_COMM_WORLD,1,
loc_size_A,PETSC_DETERMINE,rhs_array,&(
RHS1));
157 VecCreateMPIWithArray(PETSC_COMM_WORLD,1,
loc_size_A,PETSC_DETERMINE,sol_array,&(
Sol1));
162 VecRestoreArray(
rhs_, &rhs_array);
165 VecGetArray(
Sol2, &sol_array );
168 VecRestoreArray(
Sol2, &sol_array );
186 ierr+=MatMatMult(
IA,
B, mat_reuse, 1.0 ,&(
IAB));
189 ierr+=MatMatMult(
Bt,
IAB, mat_reuse, 1.9 ,&(
xA));
202 ASSERT( ierr == 0,
"PETSC Error during calculation of Schur complement.\n");
246 ASSERT(ls !=
nullptr,
"NULL complement ls.\n");
259 PetscInt ncols, pos_start, pos_start_IA;
261 MatReuse mat_reuse=MAT_REUSE_MATRIX;
265 MatGetOwnershipRange(
matrix_,&pos_start,PETSC_NULL);
266 MatGetOwnershipRange(
IA,&pos_start_IA,PETSC_NULL);
269 const PetscInt *cols;
270 const PetscScalar *vals;
274 unsigned int mat_block=1;
275 for(
unsigned int loc_row=0; loc_row < processed_rows.size(); loc_row++) {
276 if (processed_rows[loc_row] != 0)
continue;
278 PetscInt min=std::numeric_limits<int>::max(), max=-1, size_submat;
281 MatGetRow(
matrix_, loc_row + pos_start, &ncols, &cols, PETSC_NULL);
282 for (PetscInt i=0; i<ncols; i++) {
283 if (cols[i] < pos_start || cols[i] >= pos_start+
loc_size_A) {
294 size_submat = max - min + 1;
295 ASSERT(ncols-b_vals == size_submat,
"Submatrix cannot contains empty values.\n");
297 MatRestoreRow(
matrix_, loc_row + pos_start, &ncols, &cols, PETSC_NULL);
298 arma::mat submat2(size_submat, size_submat);
300 for (PetscInt i=0; i<size_submat; i++) {
301 processed_rows[ loc_row + i ] = mat_block;
302 submat_rows.push_back( i + loc_row + pos_start_IA );
303 MatGetRow(
matrix_, i + loc_row + pos_start, &ncols, &cols, &vals);
304 for (PetscInt j=0; j<ncols; j++) {
305 if (cols[j] >= pos_start && cols[j] < pos_start+
loc_size_A) {
306 submat2( i, cols[j] - loc_row - pos_start ) = vals[j];
309 MatRestoreRow(
matrix_, i + loc_row + pos_start, &ncols, &cols, &vals);
312 arma::mat invmat = submat2.i();
314 const PetscInt* rows = &submat_rows[0];
315 MatSetValues(
IA, submat_rows.size(), rows, submat_rows.size(), rows, invmat.memptr(), INSERT_VALUES);
320 MatAssemblyBegin(
IA, MAT_FINAL_ASSEMBLY);
321 MatAssemblyEnd(
IA, MAT_FINAL_ASSEMBLY);
330 return std::numeric_limits<double>::infinity();
340 return converged_reason;
349 if (
B != NULL ) MatDestroy(&
B);
350 if (
Bt != NULL ) MatDestroy(&
Bt);
351 if (
xA != NULL ) MatDestroy(&
xA);
352 if (
IA != NULL ) MatDestroy(&
IA);
353 if (
IAB != NULL ) MatDestroy(&
IAB);
354 if (
IsA != NULL ) ISDestroy(&
IsA);
355 if (
IsB != NULL ) ISDestroy(&
IsB);
356 if (
RHS1 != NULL ) VecDestroy(&
RHS1);
357 if (
RHS2 != NULL ) VecDestroy(&
RHS2);
358 if (
Sol1 != NULL ) VecDestroy(&
Sol1);
359 if (
Sol2 != NULL ) VecDestroy(&
Sol2);
360 if (
IA != NULL ) MatDestroy(&
IA);
bool is_negative_definite()
void set_complement(LinSys_PETSC *ls)
Set complement LinSys object.
bool matrix_changed_
true if the matrix was changed since the last solve
Wrappers for linear systems based on MPIAIJ and MATIS format.
Vec rhs_
PETSc vector constructed with vx array.
void set_from_input(const Input::Record in_rec)
bool rhs_changed_
true if the right hand side was changed since the last solve
Assembly explicit Schur complement for the given linear system. Provides method for resolution of the...
const Vec & get_solution()
unsigned int begin(int proc) const
get starting local index
const Distribution * rows_ds_
final distribution of rows of MH matrix
void set_solution(double *sol_array)
SchurComplement(IS ia, Distribution *ds)
void create_inversion_matrix()
create IA matrix
Support classes for parallel programing.
double get_solution_precision() override
get precision of solving
Distribution * make_complement_distribution()
get distribution of complement object if complement is defined
double get_solution_precision()
void set_matrix_changed()
Mat matrix_
Petsc matrix of the problem.
Vec solution_
PETSc vector constructed with vb array.
Solver based on Multilevel BDDC - using corresponding class of OpenFTL package.
unsigned int lsize(int proc) const
get local size