biharmonic_preconditioner.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// Version 1.0; svn revision $LastChangedRevision$
7 //LIC//
8 //LIC// $LastChangedDate$
9 //LIC//
10 //LIC// Copyright (C) 2006-2016 Matthias Heil and Andrew Hazel
11 //LIC//
12 //LIC// This library is free software; you can redistribute it and/or
13 //LIC// modify it under the terms of the GNU Lesser General Public
14 //LIC// License as published by the Free Software Foundation; either
15 //LIC// version 2.1 of the License, or (at your option) any later version.
16 //LIC//
17 //LIC// This library is distributed in the hope that it will be useful,
18 //LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 //LIC// Lesser General Public License for more details.
21 //LIC//
22 //LIC// You should have received a copy of the GNU Lesser General Public
23 //LIC// License along with this library; if not, write to the Free Software
24 //LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 //LIC// 02110-1301 USA.
26 //LIC//
27 //LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
28 //LIC//
29 //LIC//====================================================================
30 //Include guards
31 #ifndef OOMPH_BIHARMONIC_PRECONDITIONER_HEADER
32 #define OOMPH_BIHARMONIC_PRECONDITIONER_HEADER
33 
34 
35 // Config header generated by autoconfig
36 #ifdef HAVE_CONFIG_H
37  #include <oomph-lib-config.h>
38 #endif
39 
40 #include "../generic/preconditioner.h"
41 #include "../generic/block_preconditioner.h"
42 #include "../generic/hijacked_elements.h"
43 #include "biharmonic_elements.h"
44 #include "../meshes/hermite_element_quad_mesh.template.h"
45 #include "../generic/SuperLU_preconditioner.h"
46 #include "../generic/general_purpose_preconditioners.h"
47 
48 #ifdef OOMPH_HAS_HYPRE
49 #include "../generic/hypre_solver.h"
50 #endif
51 
52 namespace oomph
53 {
54 
55 
56 #ifdef OOMPH_HAS_HYPRE
57 
58 //=============================================================================
59 // defaults settings for the Hypre solver (AMG) when used as the approximate
60 // linear solver for the Schur complement (non-compound) linear subsidiary
61 // linear systems
62 //=============================================================================
63 namespace Biharmonic_schur_complement_Hypre_defaults
64 {
65 
66  /// smoother type - Gauss Seidel: 1
67  extern unsigned AMG_smoother;
68 
69  /// amg coarsening strategy: classical Ruge Stueben: 1
70  extern unsigned AMG_coarsening;
71 
72  /// number of V cycles: 2
73  extern unsigned N_cycle;
74 
75  /// amg strength parameter: 0.25 -- optimal for 2d
76  extern double AMG_strength;
77 
78  /// jacobi damping -- hierher not used 0.1;
79  extern double AMG_jacobi_damping;
80 
81  /// Amg smoother iterations: 2
82  extern unsigned AMG_smoother_iterations;
83 
84  /// set the defaults
85  extern void set_defaults(HyprePreconditioner* hypre_prec_pt);
86 
87 }
88 #endif
89 
90 
91 
92 //=============================================================================
93 /// \short Biharmonic Preconditioner - for two dimensional problems
94 //=============================================================================
95  class BiharmonicPreconditioner : public BlockPreconditioner<CRDoubleMatrix>
96  {
97 
98  public :
99 
100  /// Constructor - by default inexact preconditioning is used
102  {
103  // initialise both preconditioners to zero
104  Sub_preconditioner_1_pt = 0;
105  Sub_preconditioner_2_pt = 0;
106  Hijacked_sub_block_preconditioner_pt = 0;
107 
108  // by default we use the inexact biharmonic preconditioner
109  // and if possible use Hypre preconditioner
110 #ifdef OOMPH_HAS_HYPRE
111  Preconditioner_type = 2;
112 #else
113  Preconditioner_type = 1;
114 #endif
115 
116  // size mesh pt correctly
117  this->set_nmesh(1);
118  Bulk_element_mesh_pt = 0;
119  }
120 
121  /// destructor - cleans up preconditioners and delete matrices
123  {
124  this->clean_up_memory();
125  }
126 
127  // delete the subsidiary preconditioners and memory
129  {
130  // delete the sub preconditioners
131  delete Sub_preconditioner_1_pt;
132  delete Sub_preconditioner_2_pt;
133  delete Hijacked_sub_block_preconditioner_pt;
134  }
135 
136  /// Broken copy constructor
138  {
139  BrokenCopy::broken_copy("BiharmonicPreconditioner");
140  }
141 
142  /// Broken assignment operator
144  {
145  BrokenCopy::broken_assign("BiharmonicPreconditioner");
146  }
147 
148  /// \short Setup the preconditioner
149  void setup();
150 
151  /// Apply preconditioner to r
152  void preconditioner_solve(const DoubleVector &r, DoubleVector &z);
153 
154  /// \short Access function to the preconditioner type \n
155  /// + 0 : exact BBD \n
156  /// + 1 : inexact BBD w/ SuperLU \n
157  /// + 2 : inexact BBD w/ AMG (Hypre Boomer AMG)
158  /// + 3 : block diagonal (3x3)+(1x1)
160  {
161  return Preconditioner_type;
162  }
163 
164  /// \short Access function to the mesh pt for the bulk elements. The mesh
165  /// should only contain BiharmonicElement<2> and
166  /// Hijacked<BiharmonicElement<2> > elements
168  {
169  return Bulk_element_mesh_pt;
170  }
171 
172  private:
173 
174  /// preconditioner type \n
175  /// + 0 : exact BBD \n
176  /// + 1 : inexact BBD w/ SuperLU \n
177  /// + 2 : inexact BBD w/ AMG
178  /// + 3 : block diagonal (3x3)+(1x1)
180 
181  /// Exact Preconditioner Pointer
183 
184  /// Inexact Preconditioner Pointer
186 
187  /// Preconditioner the diagonal block associated with hijacked elements
189 
190  /// the bulk element mesh pt
192  };
193 
194 
195 
196 //=============================================================================
197 /// \short Sub Biharmonic Preconditioner - an exact preconditioner for the
198 /// 3x3 top left hand corner sub block matrix.
199 /// Used as part of the BiharmonicPreconditioner<MATRIX> .
200 /// By default this uses the BBD (block-bordered-diagonal/arrow-shaped)
201 /// preconditioner; can also switch to full BD version (in which case
202 /// all the 3x3 blocks are retained)
203 //=============================================================================
205  : public BlockPreconditioner<CRDoubleMatrix>
206  {
207 
208  public :
209 
210  /// \short Constructor - for a preconditioner acting as a sub preconditioner
212  const bool& retain_all_blocks=false) :
213  Retain_all_blocks(retain_all_blocks)
214  {
215  // Block mapping for ExactSubBiharmonicPreconditioner
216  Vector<unsigned> block_lookup(3);
217  block_lookup[0] = 0;
218  block_lookup[1] = 1;
219  block_lookup[2] = 2;
220 
221  // set as subsidiary block preconditioner
222  this->turn_into_subsidiary_block_preconditioner(master_prec_pt,
223  block_lookup);
224 
225  // null the Sub preconditioner pt
226  Sub_preconditioner_pt = 0;
227  }
228 
229  /// destructor deletes the exact preconditioner
231  {
232  this->clean_up_memory();
233  }
234 
235  /// delete the subsidiary preconditioner pointer
237  {
238  delete Sub_preconditioner_pt; Sub_preconditioner_pt = 0;
239  }
240 
241  /// Broken copy constructor
243  {
244  BrokenCopy::broken_copy("ExactSubBiharmonicPreconditioner");
245  }
246 
247  /// Broken assignment operator
249  {
250  BrokenCopy::broken_assign("ExactSubBiharmonicPreconditioner");
251  }
252 
253  /// \short Setup the preconditioner
254  void setup();
255 
256  /// Apply preconditioner to r
257  void preconditioner_solve(const DoubleVector &r, DoubleVector &z);
258 
259 // private:
260 
261  // Pointer to the sub preconditioner
263 
264 
265  /// Boolean indicating that all blocks are to be retained (defaults to false)
267 
268  };
269 
270 //=============================================================================
271 /// \short SubBiharmonic Preconditioner - an inexact preconditioner for the
272 /// 3x3 top left hand corner sub block matrix.
273 /// Used as part of the BiharmonicPreconditioner<MATRIX>
274 //=============================================================================
276  : public BlockPreconditioner<CRDoubleMatrix>
277  {
278 
279  public :
280 
281  /// \short Constructor for the inexact block preconditioner. \n
282  /// This a helper class for BiharmonicPreconditioner and cannot be used
283  /// as a standalone preconditioner. \n
284  /// master_prec_pt is the pointer to the master BiharmonicPreconditioner.
286  (BiharmonicPreconditioner* master_prec_pt, const bool use_amg)
287  {
288  // Block mapping for ExactSubBiharmonicPreconditioner
289  Vector<unsigned> block_lookup(3);
290  block_lookup[0] = 0;
291  block_lookup[1] = 1;
292  block_lookup[2] = 2;
293 
294  // set as subsidiary block preconditioner
295  this->turn_into_subsidiary_block_preconditioner
296  (master_prec_pt,block_lookup);
297 
298  // zero all the preconditioner pt
299  S_00_preconditioner_pt = 0;
300  Lumped_J_11_preconditioner_pt = 0;
301  Lumped_J_22_preconditioner_pt = 0;
302 
303  // store the preconditioner type
304  Use_amg = use_amg;
305  }
306 
307  /// destructor - just calls this->clean_up_memory()
309  {
310  this->clean_up_memory();
311  }
312 
313  /// clean the memory
315  {
316  // delete the sub preconditioner pt
317  delete S_00_preconditioner_pt;
318  S_00_preconditioner_pt = 0;
319 
320  // delete the lumped preconditioners
321  delete Lumped_J_11_preconditioner_pt;
322  Lumped_J_11_preconditioner_pt = 0;
323  delete Lumped_J_22_preconditioner_pt;
324  Lumped_J_22_preconditioner_pt = 0;
325 
326  // Number of block types
327  unsigned n = Matrix_of_block_pointers.nrow();
328 
329  // delete the block matrices
330  for (unsigned i = 0; i < n; i++)
331  {
332  for (unsigned j = 0; j < n; j++)
333  {
334  if (Matrix_of_block_pointers(i,j) != 0)
335  {
336  delete Matrix_of_block_pointers(i,j);
337  Matrix_of_block_pointers(i,j)=0;
338  }
339  }
340  }
341  }
342 
343  /// Broken copy constructor
346  {
347  BrokenCopy::broken_copy("InexactSubBiharmonicPreconditioner");
348  }
349 
350  /// Broken assignment operator
352  {
353  BrokenCopy::broken_assign("InexactSubBiharmonicPreconditioner");
354  }
355 
356  /// \short Setup the preconditioner
357  void setup();
358 
359  /// Apply preconditioner to r
360  void preconditioner_solve(const DoubleVector &r, DoubleVector &z);
361 
362 // private:
363 
364  /// \short Computes the inexact schur complement of the block J_00 using
365  /// lumping as an approximate inverse of block J_11 and J_22
366  /// (where possible)
367  void compute_inexact_schur_complement();
368 
369  /// \short Pointer to the S00 Schur Complement preconditioner
371 
372  /// \short Preconditioner for storing the lumped J_11 matrix
375 
376  /// \short Preconditioner for storing the lumped J_22 matrix
379 
380  ///
382 
383  ///
385 
386  /// \short booean indicating whether (Hypre BoomerAMG) AMG should be used
387  /// to solve the S00 subsidiary linear system.
388  unsigned Use_amg;
389  };
390 }
391 #endif
double AMG_strength
amg strength parameter: 0.25 – optimal for 2d
void set_defaults(HyprePreconditioner *hypre_prec_pt)
set the defaults
void clean_up_memory()
Clean up memory (empty). Generic interface function.
void broken_copy(const std::string &class_name)
Issue error message and terminate execution.
cstr elem_len * i
Definition: cfortran.h:607
BiharmonicPreconditioner(const BiharmonicPreconditioner &)
Broken copy constructor.
unsigned AMG_smoother
smoother type - Gauss Seidel: 1
BiharmonicPreconditioner()
Constructor - by default inexact preconditioning is used.
void operator=(const ExactSubBiharmonicPreconditioner &)
Broken assignment operator.
~ExactSubBiharmonicPreconditioner()
destructor deletes the exact preconditioner
ExactSubBiharmonicPreconditioner(const ExactSubBiharmonicPreconditioner &)
Broken copy constructor.
DenseMatrix< CRDoubleMatrix * > Matrix_of_block_pointers
void setup()
Setup terminate helper.
double AMG_jacobi_damping
jacobi damping – hierher not used 0.1
Sub Biharmonic Preconditioner - an exact preconditioner for the 3x3 top left hand corner sub block ma...
unsigned & preconditioner_type()
Access function to the preconditioner type .
void operator=(const BiharmonicPreconditioner &)
Broken assignment operator.
Mesh *& bulk_element_mesh_pt()
Access function to the mesh pt for the bulk elements. The mesh should only contain BiharmonicElement<...
ExactSubBiharmonicPreconditioner(BiharmonicPreconditioner *master_prec_pt, const bool &retain_all_blocks=false)
Constructor - for a preconditioner acting as a sub preconditioner.
MatrixBasedLumpedPreconditioner< CRDoubleMatrix > * Lumped_J_11_preconditioner_pt
Preconditioner for storing the lumped J_11 matrix.
Preconditioner * Hijacked_sub_block_preconditioner_pt
Preconditioner the diagonal block associated with hijacked elements.
~InexactSubBiharmonicPreconditioner()
destructor - just calls this->clean_up_memory()
void clean_up_memory()
delete the subsidiary preconditioner pointer
unsigned AMG_coarsening
amg coarsening strategy: classical Ruge Stueben: 1
Preconditioner base class. Gives an interface to call all other preconditioners through and stores th...
Preconditioner * S_00_preconditioner_pt
Pointer to the S00 Schur Complement preconditioner.
void broken_assign(const std::string &class_name)
Issue error message and terminate execution.
bool Retain_all_blocks
Boolean indicating that all blocks are to be retained (defaults to false)
Class for dense matrices, storing all the values of the matrix as a pointer to a pointer with assorte...
Definition: communicator.h:50
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*)
Definition: double_vector.h:61
MatrixBasedLumpedPreconditioner< CRDoubleMatrix > * Lumped_J_22_preconditioner_pt
Preconditioner for storing the lumped J_22 matrix.
SubBiharmonic Preconditioner - an inexact preconditioner for the 3x3 top left hand corner sub block m...
Preconditioner * Sub_preconditioner_2_pt
Inexact Preconditioner Pointer.
unsigned Use_amg
booean indicating whether (Hypre BoomerAMG) AMG should be used to solve the S00 subsidiary linear sys...
~BiharmonicPreconditioner()
destructor - cleans up preconditioners and delete matrices
A class for compressed row matrices. This is a distributable object.
Definition: matrices.h:872
Preconditioner * Sub_preconditioner_1_pt
Exact Preconditioner Pointer.
void operator=(const InexactSubBiharmonicPreconditioner &)
Broken assignment operator.
A general mesh class.
Definition: mesh.h:74
Mesh * Bulk_element_mesh_pt
the bulk element mesh pt
Biharmonic Preconditioner - for two dimensional problems.