86 if (
IsB ==
nullptr ) {
92 const PetscInt *loc_indices;
93 ISGetIndices(
IsA, &loc_indices);
95 a_used[ loc_indices[i] - ds->
begin()] =
true;
96 ISRestoreIndices(
IsA, &loc_indices);
100 PetscMalloc(
sizeof(PetscInt)*
loc_size_B, &b_indices);
102 if (! a_used[i]) b_indices[j++] = i + ds->
begin();
103 ISCreateGeneral(PETSC_COMM_WORLD, loc_size_B, b_indices, PETSC_COPY_VALUES, &
IsB);
104 PetscFree(b_indices);
116 MatCopy(other.
IA,
IA, DIFFERENT_NONZERO_PATTERN);
117 MatCopy(other.
IAB,
IAB, DIFFERENT_NONZERO_PATTERN);
166 PetscErrorCode ierr = 0;
168 MatStructure mat_subset_pattern;
169 PetscScalar *rhs_array, *sol_array;
171 mat_reuse=MAT_REUSE_MATRIX;
172 mat_subset_pattern=SUBSET_NONZERO_PATTERN;
174 mat_reuse=MAT_INITIAL_MATRIX;
175 mat_subset_pattern=DIFFERENT_NONZERO_PATTERN;
180 VecGetArray(
rhs_, &rhs_array);
181 VecCreateMPIWithArray(PETSC_COMM_WORLD,1,
loc_size_A,PETSC_DETERMINE,rhs_array,&(
RHS1));
185 VecCreateMPIWithArray(PETSC_COMM_WORLD,1,
loc_size_A,PETSC_DETERMINE,sol_array,&(
Sol1));
190 VecRestoreArray(
rhs_, &rhs_array);
193 VecGetArray(
Sol2, &sol_array );
196 VecRestoreArray(
Sol2, &sol_array );
224 ierr+=MatMatMult(
IA,
B, mat_reuse, 1.0 ,&(
IAB));
227 ierr+=MatMatMult(
Bt,
IAB, mat_reuse, 1.9 ,&(
xA));
245 OLD_ASSERT( ierr == 0,
"PETSC Error during calculation of Schur complement.\n");
289 if (
ds_ != NULL)
delete ds_;
297 PetscInt ncols, pos_start, pos_start_IA;
299 MatReuse mat_reuse=MAT_REUSE_MATRIX;
304 MatGetOwnershipRange(
matrix_,&pos_start,PETSC_NULL);
305 MatGetOwnershipRange(
IA,&pos_start_IA,PETSC_NULL);
308 const PetscInt *cols;
309 const PetscScalar *vals;
313 unsigned int mat_block=1;
314 for(
unsigned int loc_row=0; loc_row < processed_rows.size(); loc_row++) {
315 if (processed_rows[loc_row] != 0)
continue;
317 PetscInt min=std::numeric_limits<int>::max(), max=-1, size_submat;
320 MatGetRow(
matrix_, loc_row + pos_start, &ncols, &cols, PETSC_NULL);
321 for (PetscInt i=0; i<ncols; i++) {
322 if (cols[i] < pos_start || cols[i] >= pos_start+
loc_size_A) {
333 size_submat = max - min + 1;
334 OLD_ASSERT(ncols-b_vals == size_submat,
"Submatrix cannot contains empty values.\n");
336 MatRestoreRow(
matrix_, loc_row + pos_start, &ncols, &cols, PETSC_NULL);
337 arma::mat submat2(size_submat, size_submat);
339 for (PetscInt i=0; i<size_submat; i++) {
340 processed_rows[ loc_row + i ] = mat_block;
341 submat_rows.push_back( i + loc_row + pos_start_IA );
342 MatGetRow(
matrix_, i + loc_row + pos_start, &ncols, &cols, &vals);
343 for (PetscInt j=0; j<ncols; j++) {
344 if (cols[j] >= pos_start && cols[j] < pos_start+
loc_size_A) {
345 submat2( i, cols[j] - loc_row - pos_start ) = vals[j];
348 MatRestoreRow(
matrix_, i + loc_row + pos_start, &ncols, &cols, &vals);
351 arma::mat invmat = submat2.i();
353 const PetscInt* rows = &submat_rows[0];
354 MatSetValues(
IA, submat_rows.size(), rows, submat_rows.size(), rows, invmat.memptr(), INSERT_VALUES);
359 MatAssemblyBegin(
IA, MAT_FINAL_ASSEMBLY);
360 MatAssemblyEnd(
IA, MAT_FINAL_ASSEMBLY);
374 return std::numeric_limits<double>::infinity();
408 START_TIMER(
"SchurComplemet::resolve without form schur");
430 if (
B != NULL )
chkerr(MatDestroy(&
B));
432 if (
C != NULL )
chkerr(MatDestroy(&
C));
445 if (
ds_ != NULL)
delete ds_;
bool is_negative_definite()
void set_complement(LinSys_PETSC *ls)
Set complement LinSys object.
const Mat * get_matrix() override
void set_tolerances(double r_tol, double a_tol, unsigned int max_it) override
bool matrix_changed_
true if the matrix was changed since the last solve
void set_from_input(const Input::Record in_rec) override
LinSys::SolveInfo solve() override
Wrappers for linear systems based on MPIAIJ and MATIS format.
Vec rhs_
PETSc vector constructed with vx array.
LinSys::SolveInfo solve() override
void chkerr(unsigned int ierr)
Replacement of new/delete operator in the spirit of xmalloc.
bool rhs_changed_
true if the right hand side was changed since the last solve
double get_solution_precision() override
SchurComplement(Distribution *ds, IS ia, IS ib=nullptr)
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
#define START_TIMER(tag)
Starts a timer with specified tag.
void set_from_input(const Input::Record in_rec) override
double compute_residual() override
double compute_residual() override
void set_solution(Vec sol_vec)
void create_inversion_matrix()
create IA matrix
Support classes for parallel programing.
double get_solution_precision() override
get precision of solving
const Vec * get_rhs() override
Distribution * make_complement_distribution()
get distribution of complement object if complement is defined
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
void set_matrix_changed()
void set_tolerances(double r_tol, double a_tol, unsigned int max_it) override
Mat matrix_
Petsc matrix of the problem.
#define DebugOut()
Macro defining 'debug' record of log.
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