mumps_solver.h
Go to the documentation of this file.
1// LIC// ====================================================================
2// LIC// This file forms part of oomph-lib, the object-oriented,
3// LIC// multi-physics finite-element library, available
4// LIC// at http://www.oomph-lib.org.
5// LIC//
6// LIC// Copyright (C) 2006-2025 Matthias Heil and Andrew Hazel
7// LIC//
8// LIC// This library is free software; you can redistribute it and/or
9// LIC// modify it under the terms of the GNU Lesser General Public
10// LIC// License as published by the Free Software Foundation; either
11// LIC// version 2.1 of the License, or (at your option) any later version.
12// LIC//
13// LIC// This library is distributed in the hope that it will be useful,
14// LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// LIC// Lesser General Public License for more details.
17// LIC//
18// LIC// You should have received a copy of the GNU Lesser General Public
19// LIC// License along with this library; if not, write to the Free Software
20// LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21// LIC// 02110-1301 USA.
22// LIC//
23// LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24// LIC//
25// LIC//====================================================================
26// This is the header file for the C++ wrapper functions for the
27// mumps solver
28
29// Include guards to prevent multiple inclusions of the header
30#ifndef NEW_MUMPS_SOLVER_HEADER
31#define NEW_MUMPS_SOLVER_HEADER
32
33
34// Config header
35#ifdef HAVE_CONFIG_H
36#include <oomph-lib-config.h>
37#endif
38
39#ifdef OOMPH_HAS_MPI
40#include "mpi.h"
41#endif
42
43#include "linear_solver.h"
44#include "preconditioner.h"
45
46#include <mumps_c_types.h>
47#include <dmumps_c.h>
48
49// offset macros for the 1-indexed (FORTRAN) arrays in the
50// MUMPS interface; makes the control integers, info etc. easier to
51// read w.r.t. the MUMPS documentation
52#define ICNTL(i) icntl[(i) - 1]
53#define INFOG(i) infog[(i) - 1]
54#define INFO(i) info[(i) - 1]
55
56namespace oomph
57{
58 //====================================================================
59 /// Wrapper to Mumps solver
60 //====================================================================
62 {
63 public:
64 /// Static flag that determines whether the warning about
65 /// incorrect distribution of RHSs will be printed or not
67
68 /// Constructor: Call setup
70
71 /// Broken copy constructor
72 MumpsSolver(const MumpsSolver& dummy) = delete;
73
74 /// Broken assignment operator
75 void operator=(const MumpsSolver&) = delete;
76
77 /// Destructor: Cleanup
79
80 /// Overload disable resolve so that it cleans up memory too
86
87 /// Set boolean to suppress warning about communicator
88 /// not equal to MPI_COMM_WORLD
93
94 /// Don't suppress warning about communicator not equal to MPI_COMM_WORLD
99
100 /// Set boolean to suppress info being printed to screen
101 /// during MUMPS solve
106
107 /// Don't suppress info being printed to screen during MUMPS solve
112
113 /// Solver: Takes pointer to problem and returns the results Vector
114 /// which contains the solution of the linear system defined by
115 /// the problem's fully assembled Jacobian and residual Vector.
116 void solve(Problem* const& problem_pt, DoubleVector& result);
117
118 /// Linear-algebra-type solver: Takes pointer to a matrix and rhs
119 /// vector and returns the solution of the linear system.
120 /// The function returns the global result Vector.
121 /// Note: if Delete_matrix_data is true the function
122 /// matrix_pt->clean_up_memory() will be used to wipe the matrix data.
123 void solve(DoubleMatrixBase* const& matrix_pt,
124 const DoubleVector& rhs,
126
127 /// Resolve the system defined by the last assembled Jacobian
128 /// and the specified rhs vector if resolve has been enabled.
129 /// Note: returns the global result Vector.
131
132 /// Enable documentation of statistics
134 {
135 Doc_stats = true;
136 }
137
138 /// Disable documentation of statistics
140 {
141 Doc_stats = false;
142 }
143
144 /// Returns the time taken to assemble the Jacobian matrix and
145 /// residual vector
147 {
148 return Jacobian_setup_time;
149 }
150
151 /// Return the time taken to solve the linear system (needs to be
152 /// overloaded for each linear solver)
154 {
155 return Solution_time;
156 }
157
158 /// Set the flag to avoid solution of the system, so
159 /// just assemble the Jacobian and the rhs.
160 /// (Used only for timing runs, obviously)
162 {
163 Suppress_solve = true;
164 }
165
166 /// Unset the flag so that the system is actually solved again
167 /// This is the default (obviously)
169 {
170 Suppress_solve = false;
171 }
172
173 /// Set Delete_matrix_data flag. MumpsSolver needs its own copy
174 /// of the input matrix, therefore a copy must be made if any matrix
175 /// used with this solver is to be preserved. If the input matrix can be
176 /// deleted the flag can be set to true to reduce the amount of memory
177 /// required, and the matrix data will be wiped using its clean_up_memory()
178 /// function. Default value is false.
180 {
181 Delete_matrix_data = true;
182 }
183
184 /// Unset Delete_matrix_data flag. MumpsSolver needs its own copy
185 /// of the input matrix, therefore a copy must be made if any matrix
186 /// used with this solver is to be preserved. If the input matrix can be
187 /// deleted the flag can be set to true to reduce the amount of memory
188 /// required, and the matrix data will be wiped using its clean_up_memory()
189 /// function. Default value is false.
191 {
192 Delete_matrix_data = false;
193 }
194
195 /// Do the factorisation stage
196 /// Note: if Delete_matrix_data is true the function
197 /// matrix_pt->clean_up_memory() will be used to wipe the matrix data.
198 void factorise(DoubleMatrixBase* const& matrix_pt);
199
200 /// Do the backsubstitution for mumps solver
201 /// Note: returns the global result Vector.
203
204 /// Clean up the memory allocated by the mumps solver
205 void clean_up_memory();
206
207 /// Default factor for workspace -- static so it can be overwritten
208 /// globally.
210
211 /// Tell MUMPS that the Jacobian matrix is unsymmetric
216
217 /// Tell MUMPS that the Jacobian matrix is general symmetric
222
223 /// Tell MUMPS that the Jacobian matrix is symmetric positive-definite
228
229 // tell MUMPS to use the PORD package for the ordering
234
235 // tell MUMPS to use the METIS package for the ordering
240
241 // tell MUMPS to use the METIS package for the ordering
246
247 // tell MUMPS to use the parallel Scotch package for the ordering
252
253 // tell MUMPS to use the SCOTCH package for the ordering
258
259 private:
260 /// Initialise instance of mumps data structure
261 void initialise_mumps();
262
263 /// Shutdown mumps
264 void shutdown_mumps();
265
266 /// Jacobian setup time
268
269 /// Solution time
271
272 /// Suppress solve?
274
275 /// Set to true for MumpsSolver to output statistics (false by default).
277
278 /// Boolean to suppress warning about communicator not equal to
279 /// MPI_COMM_WORLD
281
282 /// Boolean to suppress info being printed to screen during MUMPS solve
284
285 /// Has mumps been initialised?
287
288 // Work space scaling factor
290
291 /// Delete_matrix_data flag. MumpsSolver needs its own copy
292 /// of the input matrix, therefore a copy must be made if any matrix
293 /// used with this solver is to be preserved. If the input matrix can be
294 /// deleted the flag can be set to true to reduce the amount of memory
295 /// required, and the matrix data will be wiped using its clean_up_memory()
296 /// function. Default value is false.
298
299 /// Vector for row numbers
301
302 // Vector for column numbers
304
305 // Vector for entries
307
308 /// Pointer to MUMPS struct that contains the solver data
310
311 /// values of the SYM variable used by the MUMPS solver
312 /// which dictates the symmetry properties of the Jacobian matrix;
313 /// magic numbers as defined by MUMPS documentation
320
321 /// ordering library to use for serial analysis;
322 /// magic numbers as defined by MUMPS documentation
331
338
339 /// symmetry of the Jacobian matrix we're solving;
340 /// takes one of the enum values above
342
343 /// stores an integer from the public enum
344 /// which specifies which package (PORD, Metis or SCOTCH)
345 /// is used to reorder the Jacobian matrix during the analysis
347 };
348
349
350 ///////////////////////////////////////////////////////////////////////
351 ///////////////////////////////////////////////////////////////////////
352 ///////////////////////////////////////////////////////////////////////
353
354
355 //====================================================================
356 /// An interface to allow Mumps to be used as an (exact) Preconditioner
357 //====================================================================
358 class MumpsPreconditioner : virtual public Preconditioner
359 {
360 public:
361 /// Constructor.
367
368 /// Destructor.
370
371 /// Broken copy constructor.
373
374 /// Broken assignment operator.
375 void operator=(const MumpsPreconditioner&) = delete;
376
377 /// Function to set up a preconditioner for the linear
378 /// system defined by matrix_pt. This function must be called
379 /// before using preconditioner_solve.
380 /// Note: matrix_pt must point to an object of class
381 /// CRDoubleMatrix or CCDoubleMatrix
382 void setup()
383 {
384 oomph_info << "Setting up Mumps (exact) preconditioner" << std::endl;
385
388 if (dist_matrix_pt != 0)
389 {
391 this->build_distribution(dist);
393 }
394 else
395 {
396 std::ostringstream error_message_stream;
398 << "MumpsPreconditioner can only be applied to matrices derived \n"
399 << "DistributableLinearAlgebraObject.\n";
403 }
404 }
405
406 /// Function applies Mumps to vector r for (exact)
407 /// preconditioning, this requires a call to setup(...) first.
409 {
410 Solver.resolve(r, z);
411 }
412
413
414 /// Clean up memory -- forward the call to the version in
415 /// Mumps in its LinearSolver incarnation.
417 {
419 }
420
421
422 /// Enable documentation of timings
424 {
426 }
427
428 /// Disable the documentation of timings
430 {
432 }
433
434 private:
435 /// the Mumps solver emplyed by this preconditioner
437 };
438
439} // namespace oomph
440
441#endif
Base class for any linear algebra object that is distributable. Just contains storage for the LinearA...
void build_distribution(const LinearAlgebraDistribution *const dist_pt)
setup the distribution of this distributable linear algebra object
Abstract base class for matrices of doubles – adds abstract interfaces for solving,...
Definition matrices.h:261
A vector in the mathematical sense, initially developed for linear algebra type applications....
Describes the distribution of a distributable linear algebra type object. Typically this is a contain...
Base class for all linear solvers. This merely defines standard interfaces for linear solvers,...
void disable_doc_time()
Disable documentation of solve times.
void enable_doc_time()
Enable documentation of solve times.
virtual void disable_resolve()
Disable resolve (i.e. store matrix and/or LU decomposition, say) This function simply resets an inter...
An interface to allow Mumps to be used as an (exact) Preconditioner.
void setup()
Function to set up a preconditioner for the linear system defined by matrix_pt. This function must be...
MumpsSolver Solver
the Mumps solver emplyed by this preconditioner
void operator=(const MumpsPreconditioner &)=delete
Broken assignment operator.
void clean_up_memory()
Clean up memory – forward the call to the version in Mumps in its LinearSolver incarnation.
~MumpsPreconditioner()
Destructor.
MumpsPreconditioner()
Constructor.
void enable_doc_time()
Enable documentation of timings.
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Function applies Mumps to vector r for (exact) preconditioning, this requires a call to setup(....
void disable_doc_time()
Disable the documentation of timings.
MumpsPreconditioner(const MumpsPreconditioner &)=delete
Broken copy constructor.
Wrapper to Mumps solver.
double Jacobian_setup_time
Jacobian setup time.
DMUMPS_STRUC_C * Mumps_struc_pt
Pointer to MUMPS struct that contains the solver data.
void enable_suppress_warning_about_MPI_COMM_WORLD()
Set boolean to suppress warning about communicator not equal to MPI_COMM_WORLD.
~MumpsSolver()
Destructor: Cleanup.
void enable_doc_stats()
Enable documentation of statistics.
unsigned Jacobian_ordering_flag
stores an integer from the public enum which specifies which package (PORD, Metis or SCOTCH) is used ...
void disable_suppress_solve()
Unset the flag so that the system is actually solved again This is the default (obviously)
bool Mumps_is_initialised
Has mumps been initialised?
bool Suppress_warning_about_MPI_COMM_WORLD
Boolean to suppress warning about communicator not equal to MPI_COMM_WORLD.
void disable_delete_matrix_data()
Unset Delete_matrix_data flag. MumpsSolver needs its own copy of the input matrix,...
virtual double linear_solver_solution_time()
Return the time taken to solve the linear system (needs to be overloaded for each linear solver)
Vector< int > Jcn_loc
Vector< double > A_loc
void shutdown_mumps()
Shutdown mumps.
MumpsJacobianOrderingFlags
ordering library to use for serial analysis; magic numbers as defined by MUMPS documentation
double Solution_time
Solution time.
void declare_jacobian_is_symmetric()
Tell MUMPS that the Jacobian matrix is general symmetric.
unsigned Workspace_scaling_factor
void resolve(const DoubleVector &rhs, DoubleVector &result)
Resolve the system defined by the last assembled Jacobian and the specified rhs vector if resolve has...
bool Suppress_solve
Suppress solve?
MumpsSolver(const MumpsSolver &dummy)=delete
Broken copy constructor.
bool Delete_matrix_data
Delete_matrix_data flag. MumpsSolver needs its own copy of the input matrix, therefore a copy must be...
void operator=(const MumpsSolver &)=delete
Broken assignment operator.
bool Doc_stats
Set to true for MumpsSolver to output statistics (false by default).
void disable_doc_stats()
Disable documentation of statistics.
void backsub(const DoubleVector &rhs, DoubleVector &result)
Do the backsubstitution for mumps solver Note: returns the global result Vector.
Vector< int > Irn_loc
Vector for row numbers.
void enable_suppress_mumps_info_during_solve()
Set boolean to suppress info being printed to screen during MUMPS solve.
static bool Suppress_incorrect_rhs_distribution_warning_in_resolve
Static flag that determines whether the warning about incorrect distribution of RHSs will be printed ...
void enable_suppress_solve()
Set the flag to avoid solution of the system, so just assemble the Jacobian and the rhs....
unsigned Jacobian_symmetry_flag
symmetry of the Jacobian matrix we're solving; takes one of the enum values above
void disable_resolve()
Overload disable resolve so that it cleans up memory too.
MumpsSolver()
Constructor: Call setup.
bool Suppress_mumps_info_during_solve
Boolean to suppress info being printed to screen during MUMPS solve.
static int Default_workspace_scaling_factor
Default factor for workspace – static so it can be overwritten globally.
void disable_suppress_mumps_info_during_solve()
Don't suppress info being printed to screen during MUMPS solve.
void clean_up_memory()
Clean up the memory allocated by the mumps solver.
void disable_suppress_warning_about_MPI_COMM_WORLD()
Don't suppress warning about communicator not equal to MPI_COMM_WORLD.
void solve(Problem *const &problem_pt, DoubleVector &result)
Solver: Takes pointer to problem and returns the results Vector which contains the solution of the li...
void initialise_mumps()
Initialise instance of mumps data structure.
double jacobian_setup_time()
Returns the time taken to assemble the Jacobian matrix and residual vector.
void factorise(DoubleMatrixBase *const &matrix_pt)
Do the factorisation stage Note: if Delete_matrix_data is true the function matrix_pt->clean_up_memor...
void declare_jacobian_is_symmetric_positive_definite()
Tell MUMPS that the Jacobian matrix is symmetric positive-definite.
MumpsJacobianSymmetryFlags
values of the SYM variable used by the MUMPS solver which dictates the symmetry properties of the Jac...
void declare_jacobian_is_unsymmetric()
Tell MUMPS that the Jacobian matrix is unsymmetric.
void enable_delete_matrix_data()
Set Delete_matrix_data flag. MumpsSolver needs its own copy of the input matrix, therefore a copy mus...
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...
virtual DoubleMatrixBase * matrix_pt() const
Get function for matrix pointer.
////////////////////////////////////////////////////////////////// //////////////////////////////////...
Definition problem.h:154
TAdvectionDiffusionReactionElement<NREAGENT,DIM,NNODE_1D> elements are isoparametric triangular DIM-d...
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
OomphInfo oomph_info
Single (global) instantiation of the OomphInfo object – this is used throughout the library as a "rep...