32 #ifndef OOMPH_GENERAL_BLOCK_PRECONDITIONERS 33 #define OOMPH_GENERAL_BLOCK_PRECONDITIONERS 38 #include <oomph-lib-config.h> 57 namespace PreconditionerCreationFunctions
78 template<
typename MATRIX>
94 Subsidiary_preconditioner_creation_function_pt
105 this->clean_up_memory();
107 for(
unsigned j=0, nj=Subsidiary_preconditioner_pt.size(); j<nj; j++)
109 delete Subsidiary_preconditioner_pt[j];
119 for(
unsigned j=0, nj=Subsidiary_preconditioner_pt.size(); j<nj; j++)
121 if(Subsidiary_preconditioner_pt[j] != 0)
123 Subsidiary_preconditioner_pt[j]->clean_up_memory();
128 this->clear_block_preconditioner_base();
144 void set_subsidiary_preconditioner_function
145 (SubsidiaryPreconditionerFctPt sub_prec_fn)
147 Subsidiary_preconditioner_creation_function_pt = sub_prec_fn;
153 Subsidiary_preconditioner_creation_function_pt =
166 if(Subsidiary_preconditioner_pt.size() < i +1)
168 Subsidiary_preconditioner_pt.resize(i+1, 0);
178 Subsidiary_preconditioner_pt[
i] = prec;
184 {
return Subsidiary_preconditioner_pt[
i]; }
189 Dof_to_block_map = dof_to_block_map;
196 const bool &allow_multiple_element_type_in_mesh =
false)
202 std::ostringstream err_msg;
203 err_msg <<
"The mesh_pt is null, please point it to a mesh.\n";
205 OOMPH_CURRENT_FUNCTION,
206 OOMPH_EXCEPTION_LOCATION);
210 Gp_mesh_pt.push_back(std::make_pair(mesh_pt,
211 allow_multiple_element_type_in_mesh));
218 return Gp_mesh_pt.size();
226 const unsigned nmesh = gp_nmesh();
230 std::ostringstream err_msg;
231 err_msg <<
"There are no meshes set.\n" 232 <<
"Have you remembered to call add_mesh(...)?\n";
234 OOMPH_CURRENT_FUNCTION,
235 OOMPH_EXCEPTION_LOCATION);
239 this->set_nmesh(nmesh);
240 for (
unsigned mesh_i = 0; mesh_i < nmesh; mesh_i++)
242 this->set_mesh(mesh_i,
243 Gp_mesh_pt[mesh_i].first,
244 Gp_mesh_pt[mesh_i].second);
251 if (Dof_to_block_map.size() > 0)
268 if(Subsidiary_preconditioner_pt.empty())
270 Subsidiary_preconditioner_pt.assign(nprec_needed, 0);
276 if(Subsidiary_preconditioner_pt.size() != nprec_needed)
278 using namespace StringConversion;
279 std::string error_msg =
"Wrong number of precondtioners in";
280 error_msg +=
"Subsidiary_preconditioner_pt, should have ";
281 error_msg +=
to_string(nprec_needed) +
" but we actually have ";
282 error_msg +=
to_string(Subsidiary_preconditioner_pt.size());
284 OOMPH_EXCEPTION_LOCATION);
291 for(
unsigned j=0, nj=Subsidiary_preconditioner_pt.size(); j<nj; j++)
293 if(Subsidiary_preconditioner_pt[j] == 0)
295 Subsidiary_preconditioner_pt[j] =
296 (*Subsidiary_preconditioner_creation_function_pt)();
328 template<
typename MATRIX>
339 Use_two_level_parallelisation =
false;
342 Preconditioner_array_pt = 0;
345 Doc_time_during_preconditioner_solve=
false;
351 this->clean_up_memory();
357 if (Use_two_level_parallelisation)
359 delete Preconditioner_array_pt;
360 Preconditioner_array_pt = 0;
383 virtual void setup();
388 #ifndef OOMPH_HAS_MPI 389 throw OomphLibError(
"Cannot do any parallelism since we don't have MPI.",
390 OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
392 Use_two_level_parallelisation =
true;
397 { Use_two_level_parallelisation =
false;}
401 {Doc_time_during_preconditioner_solve=
true;}
405 {Doc_time_during_preconditioner_solve=
false;}
410 if((Use_two_level_parallelisation) &&
411 !this->Subsidiary_preconditioner_pt.empty())
414 "Two level parallelism diagonal block preconditioners cannot have";
415 err_msg +=
" any preset preconditioners (due to weird memory management";
416 err_msg +=
" in the PreconditionerArray, you could try fixing it).";
418 OOMPH_EXCEPTION_LOCATION);
435 const unsigned &nblock)
const 470 template<
typename MATRIX>
482 Upper_triangular =
true;
488 this->clean_up_memory();
495 for(
unsigned i=0, ni=Off_diagonal_matrix_vector_products.nrow();
i < ni;
i++)
497 for(
unsigned j=0, nj=Off_diagonal_matrix_vector_products.ncol(); j < nj; j++)
499 delete Off_diagonal_matrix_vector_products(
i,j);
500 Off_diagonal_matrix_vector_products(
i,j) = 0;
529 Upper_triangular =
true;
535 Upper_triangular =
false;
559 template<
typename MATRIX>
595 return this->Subsidiary_preconditioner_pt[0];
605 template<
typename MATRIX>
617 const unsigned &nblock)
const 618 {
return nblock - i -1; }
628 template<
typename MATRIX>
void broken_copy(const std::string &class_name)
Issue error message and terminate execution.
virtual ~ExactBlockPreconditioner()
Destructor.
void set_subsidiary_preconditioner_pt(Preconditioner *prec, const unsigned &i)
Set the subsidiary preconditioner to use for block i. The subsidiary preconditioner should have been ...
GeneralPurposeBlockPreconditioner(const GeneralPurposeBlockPreconditioner &)
Broken copy constructor.
bool Doc_time_during_preconditioner_solve
Doc timings in application of block sub-preconditioners?
virtual unsigned get_other_diag_ds(const unsigned &i, const unsigned &nblock) const
unsigned gp_nmesh()
Returns the number of meshes currently set in the GeneralPurposeBlockPreconditioner base class...
DummyBlockPreconditioner(const DummyBlockPreconditioner &)
Broken copy constructor.
virtual void clean_up_memory()
clean up the memory
PreconditionerArray * Preconditioner_array_pt
pointer for the PreconditionerArray
void operator=(const DummyBlockPreconditioner &)
Broken assignment operator.
void reset_subsidiary_preconditioner_function_to_default()
Reset the subsidiary preconditioner function to its default.
unsigned get_other_diag_ds(const unsigned &i, const unsigned &nblock) const
ExactBlockPreconditioner()
constructor
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply preconditioner to r (just copy r to z).
ExactBlockPreconditioner(const ExactBlockPreconditioner &)
Broken copy constructor.
void enable_doc_time_during_preconditioner_solve()
Enable Doc timings in application of block sub-preconditioners.
bool Upper_triangular
Boolean indicating upper or lower triangular.
void gp_preconditioner_set_all_meshes()
Set the mesh in the block preconditioning framework.
void lower_triangular()
Use as a lower triangular preconditioner.
PreconditionerArray - NOTE - first implementation, a number of assumptions / simplifications were mad...
virtual void clean_up_memory()
??ds I think clean_up_memory is supposed to clear out any stuff that doesn't need to be stored betwee...
Block "anti-diagonal" preconditioner, i.e. same as block diagonal but along the other diagonal of the...
GeneralPurposeBlockPreconditioner()
constructor
void fill_in_subsidiary_preconditioners(const unsigned &nprec_needed)
Create any subsidiary preconditioners needed. Usually nprec_needed = nblock_types, except for the ExactBlockPreconditioner which only requires one preconditioner.
void setup()
Setup terminate helper.
bool Use_two_level_parallelisation
Use two level parallelism using the PreconditionerArray.
void operator=(const GeneralPurposeBlockPreconditioner &)
Broken assignment operator.
virtual ~BlockTriangularPreconditioner()
Destructor - delete the preconditioner matrices.
void build(const DoubleVector &old_vector)
Just copys the argument DoubleVector.
BlockTriangularPreconditioner()
Constructor. (By default this preconditioner is upper triangular).
Vector< unsigned > Dof_to_block_map
the set of dof to block maps for this preconditioner
void operator=(const BlockDiagonalPreconditioner &)
Broken assignment operator.
virtual void block_setup()
Determine the size of the matrix blocks and setup the lookup schemes relating the global degrees of f...
~DummyBlockPreconditioner()
Destructor.
void setup()
Setup the preconditioner.
void disable_doc_time_during_preconditioner_solve()
Disable Doc timings in application of block sub-preconditioners.
void disable_two_level_parallelisation()
Don't use two-level parallelisation.
void operator=(const BlockTriangularPreconditioner &)
Broken assignment operator.
void enable_two_level_parallelisation()
Use two level parallelisation.
void operator=(const ExactBlockPreconditioner &)
Broken assignment operator.
Preconditioner * subsidiary_preconditioner_pt(const unsigned &i) const
Get the subsidiary precondtioner pointer in block i (is allowed to be null if not yet set)...
An interface to allow SuperLU to be used as an (exact) Preconditioner.
Preconditioner base class. Gives an interface to call all other preconditioners through and stores th...
DummyBlockPreconditioner()
Constructor.
BlockDiagonalPreconditioner(const BlockDiagonalPreconditioner &)
Broken copy constructor.
void broken_assign(const std::string &class_name)
Issue error message and terminate execution.
Block diagonal preconditioner. By default SuperLU is used to solve the subsidiary systems...
void upper_triangular()
Use as an upper triangular preconditioner.
virtual ~GeneralPurposeBlockPreconditioner()
virtual void clean_up_memory()
clean up the memory
std::string string(const unsigned &i)
Return the i-th string or "" if the relevant string hasn't been defined.
BlockTriangularPreconditioner(const BlockTriangularPreconditioner &)
Broken copy constructor.
void gp_preconditioner_block_setup()
Modified block setup for general purpose block preconditioners.
Class for dense matrices, storing all the values of the matrix as a pointer to a pointer with assorte...
void fill_in_subsidiary_preconditioners(const unsigned &nprec_needed)
Vector< Preconditioner * > Subsidiary_preconditioner_pt
List of preconditioners to use for the blocks to be solved.
A vector in the mathematical sense, initially developed for linear algebra type applications. If MPI then this vector can be distributed - its distribution is described by the LinearAlgebraDistribution object at Distribution_pt. Data is stored in a C-style pointer vector (double*)
void set_dof_to_block_map(Vector< unsigned > &dof_to_block_map)
Specify a DOF to block map.
General purpose block triangular preconditioner By default this is Upper triangular. By default SuperLUPreconditioner (or SuperLUDistPreconditioner) is used to solve the subsidiary systems, but other preconditioners can be used by setting them using passing a pointer to a function of type SubsidiaryPreconditionerFctPt to the method subsidiary_preconditioner_function_pt().
Vector< std::pair< const Mesh *, bool > > Gp_mesh_pt
void add_mesh(const Mesh *mesh_pt, const bool &allow_multiple_element_type_in_mesh=false)
Adds a mesh to be used by the block preconditioning framework for classifying DOF types...
DenseMatrix< MatrixVectorProduct * > Off_diagonal_matrix_vector_products
Matrix of matrix vector product operators for the off diagonals.
virtual ~BlockDiagonalPreconditioner()
Destructor - delete the preconditioner matrices.
BlockDiagonalPreconditioner()
constructor - when the preconditioner is used as a master preconditioner
Preconditioner *& preconditioner_pt()
Access for the preconditioner pointer used to solve the system (stored in the vector of pointers in t...
SubsidiaryPreconditionerFctPt Subsidiary_preconditioner_creation_function_pt
std::string to_string(T object, unsigned float_precision=8)
Conversion function that should work for anything with operator<< defined (at least all basic types)...
Preconditioner * create_super_lu_preconditioner()
Helper function to create a SuperLu preconditioner (for use as the default subsididary preconditioner...