frontal_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 HSL MA42
27 // frontal solver
28 
29 // Include guards to prevent multiple inclusions of the header
30 #ifndef HSL_MA42OOMPH__FRONTAL_SOLVER_HEADER
31 #define HSL_MA42OOMPH__FRONTAL_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 // oomph-lib headers
44 #include "Vector.h"
45 #include "linear_solver.h"
46 
47 namespace oomph
48 {
49  //====================================================================
50  /// Linear solver class that provides a wrapper to the frontal
51  /// solver MA42 from the <a href="http://www.hsl.rl.ac.uk/">HSL
52  /// library;</a> see <a href="http://www.hsl.rl.ac.uk/">
53  /// http://www.hsl.rl.ac.uk/.</A>
54  //====================================================================
55  class HSL_MA42 : public LinearSolver
56  {
57  private:
58  /// Special solver for problems with 1 dof (MA42 can't handle this
59  /// case so solve() forwards the "solve" to this function.
60  void solve_for_one_dof(Problem* const& problem_pt, DoubleVector& result);
61 
62 
63  /// Doc the solver stats or stay quiet?
64  bool Doc_stats;
65 
66  /// Reorder elements with Sloan's algorithm?
68 
69  /// Use direct access files?
71 
72  /// Factor to increase storage for lenbuf[0]; see MA42 documentation
73  /// for details.
75 
76  /// Factor to increase storage for lenbuf[1]; see MA42 documentation
77  /// for details
79 
80  /// Factor to increase storage for lenbuf[2]; see MA42 documentation
81  /// for details.
83 
84  /// Factor to increase storage for front size; see MA42 documentation
85  /// for details.
86  double Front_factor;
87 
88  /// Factor to increase size of direct access files; see
89  /// MA42 documentation for details.
90  double Lenfle_factor;
91 
92  /// Control flag for MA42; see MA42 documentation for details
93  int Icntl[8];
94 
95  /// Control flag for MA42; see MA42 documentation for details
96  int Isave[45];
97 
98  /// Control flag for MA42; see MA42 documentation for details
99  int Info[23];
100 
101  /// Workspace storage for MA42
102  double* W;
103 
104  /// Size of the workspace array, W
105  int Lw;
106 
107  /// Integer workspace storage for MA42
108  int* IW;
109 
110  /// Size of the integer workspace array
111  int Liw;
112 
113  /// Size of the linear system
114  unsigned long N_dof;
115 
116  public:
117  /// Constructor: By default suppress verbose output (stats), don't
118  /// reorder elements and don't use direct access files
119  HSL_MA42() : W(0), Lw(0), IW(0), Liw(0), N_dof(0)
120  {
121  Doc_stats = false;
122  Reorder_flag = false;
123  Use_direct_access_files = false;
124 
125  // Default values for memory allocation
126  Lenbuf_factor0 = 1.2;
127  Lenbuf_factor1 = 1.2;
128  Lenbuf_factor2 = 1.5;
129  Front_factor = 1.1;
130  Lenfle_factor = 1.5;
131  }
132 
133  /// Destructor, clean up the allocated memory
135  {
136  clean_up_memory();
137  }
138 
139  /// Broken copy constructor
140  HSL_MA42(const HSL_MA42&) = delete;
141 
142  /// Broken assignment operator
143  void operator=(const HSL_MA42&) = delete;
144 
145  /// Clean up memory
147  {
148  if (IW)
149  {
150  delete[] IW;
151  IW = 0;
152  Liw = 0;
153  }
154  if (W)
155  {
156  delete[] W;
157  W = 0;
158  Lw = 0;
159  }
160  }
161 
162  /// Overload disable resolve so that it cleans up memory too
164  {
166  clean_up_memory();
167  }
168 
169  /// Solver: Takes pointer to problem and returns the results Vector
170  /// which contains the solution of the linear system defined by
171  /// the problem's fully assembled Jacobian and residual Vector.
172  void solve(Problem* const& problem_pt, DoubleVector& result);
173 
174  /// Linear-algebra-type solver: Takes pointer to a matrix and rhs
175  /// vector and returns the solution of the linear system.
176  /// Call the broken base-class version. If you want this, please implement
177  /// it
178  void solve(DoubleMatrixBase* const& matrix_pt,
179  const DoubleVector& rhs,
180  DoubleVector& result)
181  {
182  LinearSolver::solve(matrix_pt, rhs, result);
183  }
184 
185 
186  /// Linear-algebra-type solver: Takes pointer to a matrix
187  /// and rhs vector and returns the solution of the linear system
188  /// Call the broken base-class version. If you want this, please
189  /// implement it
190  void solve(DoubleMatrixBase* const& matrix_pt,
191  const Vector<double>& rhs,
192  Vector<double>& result)
193  {
194  LinearSolver::solve(matrix_pt, rhs, result);
195  }
196 
197 
198  /// Return the solution to the linear system Ax = result, where
199  /// A is the most recently factorised jacobian matrix of the problem
200  /// problem_pt. The solution is returned in the result vector.
201  void resolve(const DoubleVector& rhs, DoubleVector& result);
202 
203  /// Function to reorder the elements based on Sloan's algorithm
204  void reorder_elements(Problem* const& problem_pt);
205 
206  /// Enable documentation of statistics
208  {
209  Doc_stats = true;
210  }
211 
212  /// Disable documentation of statistics
214  {
215  Doc_stats = false;
216  }
217 
218  /// Enable reordering using Sloan's algorithm
220  {
221  Reorder_flag = true;
222  }
223 
224  /// Disable reordering
226  {
227  Reorder_flag = false;
228  }
229 
230  /// Enable use of direct access files
232  {
234  }
235 
236  /// Disable use of direct access files
238  {
239  Use_direct_access_files = false;
240  }
241 
242  /// Factor to increase storage for lenbuf[0]; see MA42 documentation
243  /// for details.
244  double& lenbuf_factor0()
245  {
246  return Lenbuf_factor0;
247  }
248 
249  /// Factor to increase storage for lenbuf[1]; see MA42 documentation
250  /// for details.
251  double& lenbuf_factor1()
252  {
253  return Lenbuf_factor1;
254  }
255 
256  /// Factor to increase storage for lenbuf[2]; see MA42 documentation
257  /// for details.
258  double& lenbuf_factor2()
259  {
260  return Lenbuf_factor2;
261  }
262 
263  /// Factor to increase storage for front size; see MA42 documentation
264  /// for details.
265  double& front_factor()
266  {
267  return Front_factor;
268  }
269 
270  /// Factor to increase the size of the direct access files;
271  /// see MA42 documentation for details.
272  double& lenfle_factor()
273  {
274  return Lenfle_factor;
275  }
276  };
277 
278 } // namespace oomph
279 
280 #endif
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
Linear solver class that provides a wrapper to the frontal solver MA42 from the HSL library; see http...
int Lw
Size of the workspace array, W.
~HSL_MA42()
Destructor, clean up the allocated memory.
double & front_factor()
Factor to increase storage for front size; see MA42 documentation for details.
bool Doc_stats
Doc the solver stats or stay quiet?
double Lenfle_factor
Factor to increase size of direct access files; see MA42 documentation for details.
double & lenfle_factor()
Factor to increase the size of the direct access files; see MA42 documentation for details.
bool Use_direct_access_files
Use direct access files?
void disable_direct_access_files()
Disable use of direct access files.
bool Reorder_flag
Reorder elements with Sloan's algorithm?
void operator=(const HSL_MA42 &)=delete
Broken assignment operator.
double Lenbuf_factor2
Factor to increase storage for lenbuf[2]; see MA42 documentation for details.
void enable_doc_stats()
Enable documentation of statistics.
double Lenbuf_factor1
Factor to increase storage for lenbuf[1]; see MA42 documentation for details.
int Icntl[8]
Control flag for MA42; see MA42 documentation for details.
int Isave[45]
Control flag for MA42; see MA42 documentation for details.
double & lenbuf_factor1()
Factor to increase storage for lenbuf[1]; see MA42 documentation for details.
int Liw
Size of the integer workspace array.
void solve(DoubleMatrixBase *const &matrix_pt, const DoubleVector &rhs, DoubleVector &result)
Linear-algebra-type solver: Takes pointer to a matrix and rhs vector and returns the solution of the ...
void reorder_elements(Problem *const &problem_pt)
Function to reorder the elements based on Sloan's algorithm.
void solve_for_one_dof(Problem *const &problem_pt, DoubleVector &result)
Special solver for problems with 1 dof (MA42 can't handle this case so solve() forwards the "solve" t...
void clean_up_memory()
Clean up memory.
void disable_resolve()
Overload disable resolve so that it cleans up memory too.
void enable_reordering()
Enable reordering using Sloan's algorithm.
void enable_direct_access_files()
Enable use of direct access files.
HSL_MA42(const HSL_MA42 &)=delete
Broken copy constructor.
void disable_reordering()
Disable reordering.
double Front_factor
Factor to increase storage for front size; see MA42 documentation for details.
int Info[23]
Control flag for MA42; see MA42 documentation for details.
double * W
Workspace storage for MA42.
void resolve(const DoubleVector &rhs, DoubleVector &result)
Return the solution to the linear system Ax = result, where A is the most recently factorised jacobia...
double Lenbuf_factor0
Factor to increase storage for lenbuf[0]; see MA42 documentation for details.
void solve(DoubleMatrixBase *const &matrix_pt, const Vector< double > &rhs, Vector< double > &result)
Linear-algebra-type solver: Takes pointer to a matrix and rhs vector and returns the solution of the ...
HSL_MA42()
Constructor: By default suppress verbose output (stats), don't reorder elements and don't use direct ...
double & lenbuf_factor0()
Factor to increase storage for lenbuf[0]; see MA42 documentation for details.
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 disable_doc_stats()
Disable documentation of statistics.
int * IW
Integer workspace storage for MA42.
double & lenbuf_factor2()
Factor to increase storage for lenbuf[2]; see MA42 documentation for details.
unsigned long N_dof
Size of the linear system.
Base class for all linear solvers. This merely defines standard interfaces for linear solvers,...
Definition: linear_solver.h:68
virtual void solve(Problem *const &problem_pt, DoubleVector &result)=0
Solver: Takes pointer to problem and returns the results vector which contains the solution of the li...
virtual void disable_resolve()
Disable resolve (i.e. store matrix and/or LU decomposition, say) This function simply resets an inter...
////////////////////////////////////////////////////////////////// //////////////////////////////////...
Definition: problem.h:154
//////////////////////////////////////////////////////////////////// ////////////////////////////////...