35 namespace Pseudo_Elastic_Preconditioner_Subsidiary_Operator_Helper
37 #ifdef OOMPH_HAS_HYPRE
60 return hypre_preconditioner_pt;
73 #ifdef OOMPH_HAS_TRILINOS
80 return trilinos_prec_pt;
99 prec_pt->solver_pt()->disable_doc_time();
123 std::ostringstream error_message;
124 error_message <<
"The elastic mesh must be set.";
126 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
130 std::ostringstream error_message;
131 error_message <<
"The Lagrange multiplier mesh must be set.";
133 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
143 unsigned n_solid_dof_types = 0;
144 unsigned n_dof_types = 0;
157 n_solid_dof_types = n_dof_types - (n_dof_types / 3);
160 if (n_dof_types % 3 != 0)
162 std::ostringstream error_message;
163 error_message <<
"This preconditioner requires DIM*3 types of DOF";
165 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
170 Dim = n_dof_types / 3;
176 if (cr_matrix_pt == 0)
178 std::ostringstream error_message;
179 error_message <<
"FSIPreconditioner only works with"
180 <<
" CRDoubleMatrix matrices" << std::endl;
182 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
202 for (
unsigned dim_i = 0; dim_i <
Dim; dim_i++)
205 dof_list_for_block_setup[dim_i] = 2 * dim_i;
208 dof_list_for_block_setup[dim_i +
Dim] = 2 * dim_i + 1;
211 dof_list_for_block_setup[dim_i + 2 *
Dim] = 2 *
Dim + dim_i;
240 for (
unsigned dim_i = 0; dim_i <
Dim; dim_i++)
243 dof_list_for_subsidiary_prec[2 * dim_i] = dim_i;
246 dof_list_for_subsidiary_prec[2 * dim_i + 1] = dim_i +
Dim;
251 n_solid_dof_types, n_solid_dof_types, 0);
253 for (
unsigned row_i = 0; row_i < n_solid_dof_types; row_i++)
255 for (
unsigned col_i = 0; col_i < n_solid_dof_types; col_i++)
258 this->
get_block(row_i, col_i, *solid_matrix_pt(row_i, col_i));
273 for (
unsigned d = 0; d <
Dim; d++)
276 unsigned block_i = 2 * d + 1;
279 double* s_values = solid_matrix_pt(block_i, block_i)->value();
280 int* s_column_index = solid_matrix_pt(block_i, block_i)->column_index();
281 int* s_row_start = solid_matrix_pt(block_i, block_i)->row_start();
282 int s_nrow_local = solid_matrix_pt(block_i, block_i)->nrow_local();
283 int s_first_row = solid_matrix_pt(block_i, block_i)->first_row();
286 for (
int i = 0;
i < s_nrow_local;
i++)
289 for (
int j = s_row_start[
i]; j < s_row_start[
i + 1] && !found; j++)
291 if (s_column_index[j] ==
i + s_first_row)
301 std::ostringstream error_message;
302 error_message <<
"The diagonal entry for the constained block("
303 << block_i <<
"," << block_i <<
")\n"
304 <<
"on local row " <<
i <<
" does not exist."
307 OOMPH_CURRENT_FUNCTION,
308 OOMPH_EXCEPTION_LOCATION);
329 for (
unsigned i = 0;
i < n_solid_dof_types;
i++)
331 doftype_to_doftype_map[
i][0] =
i;
335 this, dof_list_for_subsidiary_prec, doftype_to_doftype_map);
344 for (
unsigned d = 0; d <
Dim; d++)
347 unsigned block_i = 2 * d + 1;
350 unsigned dof_block_i =
Dim + d;
352 dof_block_i, dof_block_i, solid_matrix_pt(block_i, block_i));
355 s_prec_pt->Preconditioner::setup(
matrix_pt());
374 block_triangular_prec_pt =
378 s_prec_pt = block_triangular_prec_pt;
384 block_triangular_prec_pt =
388 s_prec_pt = block_triangular_prec_pt;
393 std::ostringstream error_msg;
395 <<
"There is no such block based preconditioner.\n"
396 <<
"Candidates are:\n"
397 <<
"PseudoElasticPreconditioner::Block_diagonal_preconditioner\n"
398 <<
"PseudoElasticPreconditioner::Block_upper_triangular_"
400 <<
"PseudoElasticPreconditioner::Block_lower_triangular_"
403 error_msg.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
418 unsigned tmp_index = 0;
419 for (
unsigned d = 0; d <
Dim; d++)
421 s_prec_dof_to_block_map[d] = d;
422 doftype_to_doftype_map[d][0] = tmp_index++;
423 doftype_to_doftype_map[d][1] = tmp_index++;
427 this, dof_list_for_subsidiary_prec, doftype_to_doftype_map);
436 for (
unsigned d = 0; d <
Dim; d++)
439 unsigned block_i = 2 * d + 1;
442 unsigned dof_block_i =
Dim + d;
444 dof_block_i, dof_block_i, solid_matrix_pt(block_i, block_i));
448 s_prec_pt->Preconditioner::setup(
matrix_pt());
454 for (
unsigned row_i = 0; row_i < n_solid_dof_types; row_i++)
456 for (
unsigned col_i = 0; col_i < n_solid_dof_types; col_i++)
458 delete solid_matrix_pt(row_i, col_i);
459 solid_matrix_pt(row_i, col_i) = 0;
465 for (
unsigned d = 0; d <
Dim; d++)
468 this->
get_block(2 * Dim + d, 2 * d + 1, *b_pt);
475 (*Lagrange_multiplier_subsidiary_preconditioner_function_pt)();
507 for (
unsigned d = 0; d <
Dim; d++)
538 for (
unsigned i = 0;
i < sz;
i++)
561 std::ostringstream error_message;
562 error_message <<
"The elastic mesh must be set.";
564 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
568 std::ostringstream error_message;
569 error_message <<
"The Lagrange multiplier mesh must be set.";
571 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
576 unsigned n_solid_dof_types = 0;
577 unsigned n_dof_types = 0;
591 n_solid_dof_types = n_dof_types - (n_dof_types / 3);
594 if (n_dof_types % 3 != 0)
596 std::ostringstream error_message;
597 error_message <<
"This preconditioner requires DIM*3 types of DOF";
599 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
604 Dim = n_dof_types / 3;
610 if (cr_matrix_pt == 0)
612 std::ostringstream error_message;
613 error_message <<
"FSIPreconditioner only works with"
614 <<
" CRDoubleMatrix matrices" << std::endl;
616 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
626 for (
unsigned i = 0;
i < n_solid_dof_types;
i++)
628 dof_list_for_subsidiary_prec[
i] =
i;
635 for (
unsigned i = 0;
i < n_solid_dof_types;
i++)
661 for (
unsigned i = 0;
i < n_solid_dof_types;
i++)
672 s_prec_pt->Preconditioner::setup(
matrix_pt());
683 for (
unsigned i = 0;
i < n_solid_dof_types;
i++)
716 s_prec_pt->Preconditioner::setup(
matrix_pt());
722 for (
unsigned d = 0; d <
Dim; d++)
732 (*Lagrange_multiplier_subsidiary_preconditioner_function_pt)();
766 for (
unsigned d = 0; d <
Dim; d++)
797 for (
unsigned i = 0;
i < sz;
i++)
822 std::ostringstream error_message;
824 <<
"This SUBSIDIARY preconditioner requires an even number of "
827 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
836 dof_to_block_map[
i] = 1;
846 double* s11_values = s11_pt->
value();
848 int* s11_row_start = s11_pt->
row_start();
851 for (
int i = 0;
i < s11_nrow_local;
i++)
854 for (
int j = s11_row_start[
i]; j < s11_row_start[
i + 1] && !found; j++)
856 if (s11_column_index[j] ==
i + s11_first_row)
865 const bool want_block =
true;
866 for (
unsigned b_i = 0; b_i < 2; b_i++)
868 for (
unsigned b_j = 0; b_j < 2; b_j++)
870 required_blocks[b_i][b_j].select_block(b_i, b_j, want_block);
874 required_blocks[1][1].set_replacement_block_pt(s11_pt);
922 for (
unsigned i = 0;
i < n_block;
i++)
928 for (
unsigned j =
i + 1; j < n_block; j++)
936 for (
unsigned j = 0; j <
i; j++)
961 if (n_dof_types % 2 != 0)
963 std::ostringstream error_message;
964 error_message <<
"This preconditioner requires DIM*3 types of DOF";
966 error_message.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
971 unsigned dim = n_dof_types / 2;
975 for (
unsigned d = 0; d < dim; d++)
977 dof_to_block_map[d] = d;
978 dof_to_block_map[d + dim] = d;
991 for (
unsigned d = 0; d < dim; d++)
995 dof_list[1] = d + dim;
1000 ->turn_into_subsidiary_block_preconditioner(
this, dof_list);
1004 ->set_subsidiary_preconditioner_function(
1025 for (
unsigned j = l; j < u; j++)
1028 this->
get_block(d, j, *block_matrix_pt);
1034 delete block_matrix_pt;
1035 block_matrix_pt = 0;
1056 int start = n_block - 1;
1080 for (
int i =
start;
i != end;
i += step)
1090 for (
int j =
i + step; j != end; j += step)
Block diagonal preconditioner. By default SuperLU is used to solve the subsidiary systems,...
void return_block_vector(const unsigned &n, const DoubleVector &b, DoubleVector &v) const
Takes the n-th block ordered vector, b, and copies its entries to the appropriate entries in the natu...
unsigned ndof_types_in_mesh(const unsigned &i) const
Return the number of DOF types in mesh i. WARNING: This should only be used by the upper-most master ...
CRDoubleMatrix get_concatenated_block(const VectorMatrix< BlockSelector > &selected_block)
Returns a concatenation of the block matrices specified by the argument selected_block....
void get_block(const unsigned &i, const unsigned &j, CRDoubleMatrix &output_matrix, const bool &ignore_replacement_block=false) const
Put block (i,j) into output_matrix. This block accounts for any coarsening of dof types and any repla...
void clear_block_preconditioner_base()
Clears all BlockPreconditioner data. Called by the destructor and the block_setup(....
void get_block_vector(const unsigned &n, const DoubleVector &v, DoubleVector &b) const
Takes the naturally ordered vector, v and returns the n-th block vector, b. Here n is the block numbe...
bool is_master_block_preconditioner() const
Return true if this preconditioner is the master block preconditioner.
unsigned nblock_types() const
Return the number of block types.
void set_replacement_dof_block(const unsigned &block_i, const unsigned &block_j, CRDoubleMatrix *replacement_dof_block_pt)
Set replacement dof-level blocks. Only dof-level blocks can be set. This is important due to how the ...
void return_block_ordered_preconditioner_vector(const DoubleVector &w, DoubleVector &v) const
Takes the block ordered vector, w, and reorders it in natural order. Reordered vector is returned in ...
CRDoubleMatrix * matrix_pt() const
Access function to matrix_pt. If this is the master then cast the matrix pointer to MATRIX*,...
unsigned ndof_types() const
Return the total number of DOF types.
void turn_into_subsidiary_block_preconditioner(BlockPreconditioner< MATRIX > *master_block_prec_pt, const Vector< unsigned > &doftype_in_master_preconditioner_coarse)
Function to turn this preconditioner into a subsidiary preconditioner that operates within a bigger "...
void setup_matrix_vector_product(MatrixVectorProduct *matvec_prod_pt, CRDoubleMatrix *block_pt, const Vector< unsigned > &block_col_indices)
Setup a matrix vector product. matvec_prod_pt is a pointer to the MatrixVectorProduct,...
void set_nmesh(const unsigned &n)
Specify the number of meshes required by this block preconditioner. Note: elements in different meshe...
virtual void block_setup()
Determine the size of the matrix blocks and setup the lookup schemes relating the global degrees of f...
void set_mesh(const unsigned &i, const Mesh *const mesh_pt, const bool &allow_multiple_element_type_in_mesh=false)
Set the i-th mesh for this block preconditioner. Note: The method set_nmesh(...) must be called befor...
void get_block_ordered_preconditioner_vector(const DoubleVector &v, DoubleVector &w)
Given the naturally ordered vector, v, return the vector rearranged in block order in w....
//////////////////////////////////////////////////////////////////////////// ////////////////////////...
void upper_triangular()
Use as an upper triangular preconditioner.
void lower_triangular()
Use as a lower triangular preconditioner.
A class for compressed row matrices. This is a distributable object.
int * column_index()
Access to C-style column index array.
int * row_start()
Access to C-style row_start array.
double * value()
Access to C-style value array.
//////////////////////////////////////////////////////////////////////////// ////////////////////////...
unsigned nrow_local() const
access function for the num of local rows on this processor.
unsigned first_row() const
access function for the first row on this processor
A vector in the mathematical sense, initially developed for linear algebra type applications....
double * values_pt()
access function to the underlying values
void clear()
wipes the DoubleVector
//////////////////////////////////////////////////////////////////////////// ////////////////////////...
Base class for general purpose block preconditioners. Deals with setting subsidiary preconditioners a...
void set_dof_to_block_map(Vector< unsigned > &dof_to_block_map)
Specify a DOF to block map.
void set_subsidiary_preconditioner_function(SubsidiaryPreconditionerFctPt sub_prec_fn)
access function to set the subsidiary preconditioner function.
///////////////////////////////////////////////////////////////////// ///////////////////////////////...
unsigned & amg_simple_smoother()
Access function to AMG_simple_smoother flag.
double & amg_damping()
Access function to AMG_damping parameter.
void set_amg_iterations(const unsigned &amg_iterations)
Function to set the number of times to apply BoomerAMG.
unsigned & hypre_method()
Access function to Hypre_method flag – specified via enumeration.
void amg_using_simple_smoothing()
Function to select use of 'simple' AMG smoothers as controlled by the flag AMG_simple_smoother.
unsigned & amg_coarsening()
Access function to AMG_coarsening flag.
A preconditioner for performing inner iteration preconditioner solves. The template argument SOLVER s...
static OomphCommunicator * communicator_pt()
access to global communicator. This is the oomph-lib equivalent of MPI_COMM_WORLD
Matrix-based diagonal preconditioner.
Matrix vector product helper class - primarily a wrapper to Trilinos's Epetra matrix vector product m...
An OomphLibError object which should be thrown when an run-time error is encountered....
Preconditioner base class. Gives an interface to call all other preconditioners through and stores th...
void setup(DoubleMatrixBase *matrix_pt)
Setup the preconditioner: store the matrix pointer and the communicator pointer then call preconditio...
virtual void preconditioner_solve(const DoubleVector &r, DoubleVector &z)=0
Apply the preconditioner. Pure virtual generic interface function. This method should apply the preco...
virtual const OomphCommunicator * comm_pt() const
Get function for comm pointer.
void lagrange_multiplier_preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply the lagrange multiplier subsidiary preconditioner.
Preconditioner * Elastic_preconditioner_pt
storage for the preconditioner for the solid system
Vector< Preconditioner * > Lagrange_multiplier_preconditioner_pt
lagrange multiplier preconditioner pt
void setup()
Broken assignment operator.
bool Use_inf_norm_of_s_scaling
boolean indicating whether the inf-norm of S should be used as scaling. Default = true;
SubsidiaryPreconditionerFctPt Elastic_subsidiary_preconditioner_function_pt
The solid subsidiary preconditioner function pointer.
Elastic_preconditioner_type E_preconditioner_type
An unsigned indicating which method should be used for preconditioning the solid component.
void elastic_preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply the elastic subsidiary preconditioner.
double Scaling
The scaling. Defaults to infinity norm of S.
unsigned Dim
the dimension of the problem
@ Exact_block_preconditioner
@ Block_upper_triangular_preconditioner
@ Block_lower_triangular_preconditioner
@ Block_diagonal_preconditioner
SubsidiaryPreconditionerFctPt Lagrange_multiplier_subsidiary_preconditioner_function_pt
The Lagrange multiplier subsidary preconditioner function pointer.
Mesh * Elastic_mesh_pt
Pointer to the mesh containing the solid elements.
void clean_up_memory()
Clears the memory.
Mesh * Lagrange_multiplier_mesh_pt
Pointer to the mesh containing the Lagrange multiplier elements.
//////////////////////////////////////////////////////////////////////////// ////////////////////////...
double s_inf_norm()
Broken assignment operator.
///////////////////////////////////////////////////////////////////////////// ///////////////////////...
void use_block_diagonal_approximation()
use as a block diagonal preconditioner
void preconditioner_solve(const DoubleVector &res, DoubleVector &z)
Apply preconditioner to r.
SubsidiaryPreconditionerFctPt Subsidiary_preconditioner_function_pt
The SubisidaryPreconditionerFctPt.
void use_upper_triangular_approximation()
Use as an upper triangular preconditioner.
Vector< PseudoElasticPreconditionerSubsidiaryPreconditionerOld * > Diagonal_block_preconditioner_pt
Vector of SuperLU preconditioner pointers for storing the preconditioners for each diagonal block.
void setup()
Setup the preconditioner.
void use_lower_triangular_approximation()
Use as a lower triangular preconditioner.
double Scaling
The scaling. default 1.0.
unsigned Method
the preconditioning method. 0 - block diagonal 1 - upper triangular 2 - lower triangular
void set_subsidiary_preconditioner_function(SubsidiaryPreconditionerFctPt sub_prec_fn)
access function to set the subsidiary preconditioner function.
void clean_up_memory()
Broken assignment operator.
DenseMatrix< MatrixVectorProduct * > Off_diagonal_matrix_vector_products
Matrix of matrix vector product operators for the off diagonals.
double & scaling()
Specify the scaling. Default is 1.0 Must be set before setup(...).
///////////////////////////////////////////////////////////////////////////// ///////////////////////...
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply the preconditioner.
SubsidiaryPreconditionerFctPt Subsidiary_preconditioner_function_pt
the SubisidaryPreconditionerFctPt
double & scaling()
Specify the scaling. Default is 1.0 Must be called before setup(...).
void clean_up_memory()
clears the memory
Preconditioner * Preconditioner_pt
the preconditioner pt
void setup()
Broken assignment operator.
void set_subsidiary_preconditioner_function(SubsidiaryPreconditionerFctPt sub_prec_fn)
access function to set the subsidiary preconditioner function.
SubsidiaryPreconditionerFctPt Lagrange_multiplier_subsidiary_preconditioner_function_pt
The Lagrange multiplier subsidiary preconditioner function pointer.
void lagrange_multiplier_preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply the lagrange multiplier subsidiary preconditioner.
bool Use_inf_norm_of_s_scaling
boolean indicating whether the inf-norm of S should be used as scaling. Default = true;
double Scaling
The scaling. Defaults to infinity norm of S.
void setup()
Broken assignment operator.
Vector< Preconditioner * > Lagrange_multiplier_preconditioner_pt
lagrange multiplier preconditioner pt
void elastic_preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply the elastic subsidiary preconditioner.
Mesh * Lagrange_multiplier_mesh_pt
Pointer to the mesh containing the Lagrange multiplier elements.
SubsidiaryPreconditionerFctPt Elastic_subsidiary_preconditioner_function_pt
The solid subsidiary preconditioner function pointer.
Mesh * Elastic_mesh_pt
Pointer to the mesh containing the solid elements.
Elastic_preconditioner_type E_preconditioner_type
An unsigned indicating which method should be used for preconditioning the solid component.
@ Block_diagonal_preconditioner
@ Exact_block_preconditioner
@ Block_lower_triangular_preconditioner
@ Block_upper_triangular_preconditioner
void clean_up_memory()
Clears the memory.
Preconditioner * Elastic_preconditioner_pt
storage for the preconditioner for the solid system
unsigned Dim
the dimension of the problem
An interface to allow SuperLU to be used as an (exact) Preconditioner.
An interface to the Trilinos AztecOO classes allowing it to be used as an Oomph-lib LinearSolver....
An interface to the Trilinos ML class - provides a function to construct a serial ML object,...
VectorMatrix is a generalised, STL-map-based, matrix based on a Vector of Vectors.
double inf_norm(const DenseMatrix< CRDoubleMatrix * > &matrix_pt)
Compute infinity (maximum) norm of sub blocks as if it was one matrix.
void start(const unsigned &i)
(Re-)start i-th timer
Preconditioner * get_lagrange_multiplier_preconditioner()
CG with diagonal preconditioner for the lagrange multiplier subsidiary linear systems.
Preconditioner * get_elastic_preconditioner()
AMG w/ GS smoothing for the augmented elastic subsidiary linear systems – calls Hypre version to stay...
Preconditioner * get_elastic_preconditioner_trilinos_ml()
TrilinosML smoothing for the augmented elastic subsidiary linear systems.
Preconditioner * get_elastic_preconditioner_hypre()
AMG w/ GS smoothing for the augmented elastic subsidiary linear systems.
//////////////////////////////////////////////////////////////////// ////////////////////////////////...