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-2024 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 generated by autoconfig
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 
56 namespace oomph
57 {
58  //====================================================================
59  /// Wrapper to Mumps solver
60  //====================================================================
61  class MumpsSolver : public LinearSolver
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
69  MumpsSolver();
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
78  ~MumpsSolver();
79 
80  /// Overload disable resolve so that it cleans up memory too
82  {
85  }
86 
87  /// Set boolean to suppress warning about communicator
88  /// not equal to MPI_COMM_WORLD
90  {
92  }
93 
94  /// Don't suppress warning about communicator not equal to MPI_COMM_WORLD
96  {
98  }
99 
100  /// Set boolean to suppress info being printed to screen
101  /// during MUMPS solve
103  {
105  }
106 
107  /// Don't suppress info being printed to screen during MUMPS solve
109  {
111  }
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,
125  DoubleVector& result);
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.
130  void resolve(const DoubleVector& rhs, DoubleVector& result);
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.
202  void backsub(const DoubleVector& rhs, DoubleVector& result);
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
213  {
215  }
216 
217  /// Tell MUMPS that the Jacobian matrix is general symmetric
219  {
221  }
222 
223  /// Tell MUMPS that the Jacobian matrix is symmetric positive-definite
225  {
227  }
228 
229  // tell MUMPS to use the PORD package for the ordering
231  {
233  }
234 
235  // tell MUMPS to use the METIS package for the ordering
237  {
239  }
240 
241  // tell MUMPS to use the SCOTCH package for the ordering
243  {
245  }
246 
247  private:
248  /// Initialise instance of mumps data structure
249  void initialise_mumps();
250 
251  /// Shutdown mumps
252  void shutdown_mumps();
253 
254  /// Jacobian setup time
256 
257  /// Solution time
259 
260  /// Suppress solve?
262 
263  /// Set to true for MumpsSolver to output statistics (false by default).
264  bool Doc_stats;
265 
266  /// Boolean to suppress warning about communicator not equal to
267  /// MPI_COMM_WORLD
269 
270  /// Boolean to suppress info being printed to screen during MUMPS solve
272 
273  /// Has mumps been initialised?
275 
276  // Work space scaling factor
278 
279  /// Delete_matrix_data flag. MumpsSolver needs its own copy
280  /// of the input matrix, therefore a copy must be made if any matrix
281  /// used with this solver is to be preserved. If the input matrix can be
282  /// deleted the flag can be set to true to reduce the amount of memory
283  /// required, and the matrix data will be wiped using its clean_up_memory()
284  /// function. Default value is false.
286 
287  /// Vector for row numbers
289 
290  // Vector for column numbers
292 
293  // Vector for entries
295 
296  /// Pointer to MUMPS struct that contains the solver data
297  DMUMPS_STRUC_C* Mumps_struc_pt;
298 
299  /// values of the SYM variable used by the MUMPS solver
300  /// which dictates the symmetry properties of the Jacobian matrix;
301  /// magic numbers as defined by MUMPS documentation
303  {
306  Symmetric = 2
307  };
308 
309  /// ordering library to use for serial analysis;
310  /// magic numbers as defined by MUMPS documentation
312  {
315  Metis_ordering = 5
316  };
317 
318  /// symmetry of the Jacobian matrix we're solving;
319  /// takes one of the enum values above
321 
322  /// stores an integer from the public enum
323  /// which specifies which package (PORD, Metis or SCOTCH)
324  /// is used to reorder the Jacobian matrix during the analysis
326  };
327 
328 
329  /// ////////////////////////////////////////////////////////////////////
330  /// ////////////////////////////////////////////////////////////////////
331  /// ////////////////////////////////////////////////////////////////////
332 
333 
334  //====================================================================
335  /// An interface to allow Mumps to be used as an (exact) Preconditioner
336  //====================================================================
338  {
339  public:
340  /// Constructor.
342 
343  /// Destructor.
345 
346  /// Broken copy constructor.
348 
349  /// Broken assignment operator.
350  void operator=(const NewMumpsPreconditioner&) = delete;
351 
352  /// Function to set up a preconditioner for the linear
353  /// system defined by matrix_pt. This function must be called
354  /// before using preconditioner_solve.
355  /// Note: matrix_pt must point to an object of class
356  /// CRDoubleMatrix or CCDoubleMatrix
357  void setup()
358  {
359  oomph_info << "Setting up Mumps (exact) preconditioner" << std::endl;
360 
361  DistributableLinearAlgebraObject* dist_matrix_pt =
363  if (dist_matrix_pt != 0)
364  {
365  LinearAlgebraDistribution dist(dist_matrix_pt->distribution_pt());
366  this->build_distribution(dist);
368  }
369  else
370  {
371  std::ostringstream error_message_stream;
372  error_message_stream
373  << "NewMumpsPreconditioner can only be applied to matrices derived \n"
374  << "DistributableLinearAlgebraObject.\n";
375  throw OomphLibError(error_message_stream.str(),
376  OOMPH_CURRENT_FUNCTION,
377  OOMPH_EXCEPTION_LOCATION);
378  }
379  }
380 
381  /// Function applies Mumps to vector r for (exact)
382  /// preconditioning, this requires a call to setup(...) first.
384  {
385  Solver.resolve(r, z);
386  }
387 
388 
389  /// Clean up memory -- forward the call to the version in
390  /// Mumps in its LinearSolver incarnation.
392  {
394  }
395 
396 
397  /// Enable documentation of timings
399  {
401  }
402 
403  /// Disable the documentation of timings
405  {
407  }
408 
409  private:
410  /// the Mumps solver emplyed by this preconditioner
412  };
413 
414 } // namespace oomph
415 
416 #endif
Base class for any linear algebra object that is distributable. Just contains storage for the LinearA...
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
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....
Definition: double_vector.h:58
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,...
Definition: linear_solver.h:68
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...
Wrapper to Mumps solver.
Definition: mumps_solver.h:62
double Jacobian_setup_time
Jacobian setup time.
Definition: mumps_solver.h:255
DMUMPS_STRUC_C * Mumps_struc_pt
Pointer to MUMPS struct that contains the solver data.
Definition: mumps_solver.h:297
void enable_suppress_warning_about_MPI_COMM_WORLD()
Set boolean to suppress warning about communicator not equal to MPI_COMM_WORLD.
Definition: mumps_solver.h:89
~MumpsSolver()
Destructor: Cleanup.
void enable_doc_stats()
Enable documentation of statistics.
Definition: mumps_solver.h:133
unsigned Jacobian_ordering_flag
stores an integer from the public enum which specifies which package (PORD, Metis or SCOTCH) is used ...
Definition: mumps_solver.h:325
void disable_suppress_solve()
Unset the flag so that the system is actually solved again This is the default (obviously)
Definition: mumps_solver.h:168
void use_scotch_ordering()
Definition: mumps_solver.h:242
bool Mumps_is_initialised
Has mumps been initialised?
Definition: mumps_solver.h:274
bool Suppress_warning_about_MPI_COMM_WORLD
Boolean to suppress warning about communicator not equal to MPI_COMM_WORLD.
Definition: mumps_solver.h:268
void disable_delete_matrix_data()
Unset Delete_matrix_data flag. MumpsSolver needs its own copy of the input matrix,...
Definition: mumps_solver.h:190
virtual double linear_solver_solution_time()
Return the time taken to solve the linear system (needs to be overloaded for each linear solver)
Definition: mumps_solver.h:153
Vector< int > Jcn_loc
Definition: mumps_solver.h:291
Vector< double > A_loc
Definition: mumps_solver.h:294
void shutdown_mumps()
Shutdown mumps.
MumpsJacobianOrderingFlags
ordering library to use for serial analysis; magic numbers as defined by MUMPS documentation
Definition: mumps_solver.h:312
double Solution_time
Solution time.
Definition: mumps_solver.h:258
void declare_jacobian_is_symmetric()
Tell MUMPS that the Jacobian matrix is general symmetric.
Definition: mumps_solver.h:218
unsigned Workspace_scaling_factor
Definition: mumps_solver.h:277
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?
Definition: mumps_solver.h:261
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...
Definition: mumps_solver.h:285
void operator=(const MumpsSolver &)=delete
Broken assignment operator.
bool Doc_stats
Set to true for MumpsSolver to output statistics (false by default).
Definition: mumps_solver.h:264
void disable_doc_stats()
Disable documentation of statistics.
Definition: mumps_solver.h:139
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.
Definition: mumps_solver.h:288
void enable_suppress_mumps_info_during_solve()
Set boolean to suppress info being printed to screen during MUMPS solve.
Definition: mumps_solver.h:102
static bool Suppress_incorrect_rhs_distribution_warning_in_resolve
Static flag that determines whether the warning about incorrect distribution of RHSs will be printed ...
Definition: mumps_solver.h:66
void enable_suppress_solve()
Set the flag to avoid solution of the system, so just assemble the Jacobian and the rhs....
Definition: mumps_solver.h:161
unsigned Jacobian_symmetry_flag
symmetry of the Jacobian matrix we're solving; takes one of the enum values above
Definition: mumps_solver.h:320
void disable_resolve()
Overload disable resolve so that it cleans up memory too.
Definition: mumps_solver.h:81
MumpsSolver()
Constructor: Call setup.
Definition: mumps_solver.cc:69
bool Suppress_mumps_info_during_solve
Boolean to suppress info being printed to screen during MUMPS solve.
Definition: mumps_solver.h:271
static int Default_workspace_scaling_factor
Default factor for workspace – static so it can be overwritten globally.
Definition: mumps_solver.h:209
void disable_suppress_mumps_info_during_solve()
Don't suppress info being printed to screen during MUMPS solve.
Definition: mumps_solver.h:108
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.
Definition: mumps_solver.h:95
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.
Definition: mumps_solver.cc:86
double jacobian_setup_time()
Returns the time taken to assemble the Jacobian matrix and residual vector.
Definition: mumps_solver.h:146
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.
Definition: mumps_solver.h:224
MumpsJacobianSymmetryFlags
values of the SYM variable used by the MUMPS solver which dictates the symmetry properties of the Jac...
Definition: mumps_solver.h:303
void declare_jacobian_is_unsymmetric()
Tell MUMPS that the Jacobian matrix is unsymmetric.
Definition: mumps_solver.h:212
void enable_delete_matrix_data()
Set Delete_matrix_data flag. MumpsSolver needs its own copy of the input matrix, therefore a copy mus...
Definition: mumps_solver.h:179
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
Definition: mumps_solver.h:338
void operator=(const NewMumpsPreconditioner &)=delete
Broken assignment operator.
void enable_doc_time()
Enable documentation of timings.
Definition: mumps_solver.h:398
void setup()
Function to set up a preconditioner for the linear system defined by matrix_pt. This function must be...
Definition: mumps_solver.h:357
void clean_up_memory()
Clean up memory – forward the call to the version in Mumps in its LinearSolver incarnation.
Definition: mumps_solver.h:391
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Function applies Mumps to vector r for (exact) preconditioning, this requires a call to setup(....
Definition: mumps_solver.h:383
void disable_doc_time()
Disable the documentation of timings.
Definition: mumps_solver.h:404
NewMumpsPreconditioner(const NewMumpsPreconditioner &)=delete
Broken copy constructor.
MumpsSolver Solver
the Mumps solver emplyed by this preconditioner
Definition: mumps_solver.h:411
NewMumpsPreconditioner()
Constructor.
Definition: mumps_solver.h:341
~NewMumpsPreconditioner()
Destructor.
Definition: mumps_solver.h:344
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
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
OomphInfo oomph_info
Single (global) instantiation of the OomphInfo object – this is used throughout the library as a "rep...