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// Copyright (C) 2006-2022 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 // Include guards
27 #ifndef OOMPH_BIHARMONIC_PRECONDITIONER_HEADER
28 #define OOMPH_BIHARMONIC_PRECONDITIONER_HEADER
29 
30 
31 // Config header generated by autoconfig
32 #ifdef HAVE_CONFIG_H
33 #include <oomph-lib-config.h>
34 #endif
35 
36 #include "../generic/preconditioner.h"
37 #include "../generic/block_preconditioner.h"
38 #include "../generic/hijacked_elements.h"
39 #include "biharmonic_elements.h"
40 #include "../meshes/hermite_element_quad_mesh.template.h"
41 #include "../generic/SuperLU_preconditioner.h"
42 #include "../generic/general_purpose_preconditioners.h"
43 
44 #ifdef OOMPH_HAS_HYPRE
45 #include "../generic/hypre_solver.h"
46 #endif
47 
48 namespace oomph
49 {
50 #ifdef OOMPH_HAS_HYPRE
51 
52  //=============================================================================
53  // defaults settings for the Hypre solver (AMG) when used as the approximate
54  // linear solver for the Schur complement (non-compound) linear subsidiary
55  // linear systems
56  //=============================================================================
57  namespace Biharmonic_schur_complement_Hypre_defaults
58  {
60  extern unsigned AMG_smoother;
61 
63  extern unsigned AMG_coarsening;
64 
66  extern unsigned N_cycle;
67 
69  extern double AMG_strength;
70 
72  extern double AMG_jacobi_damping;
73 
75  extern unsigned AMG_smoother_iterations;
76 
78  extern void set_defaults(HyprePreconditioner* hypre_prec_pt);
79 
80  } // namespace Biharmonic_schur_complement_Hypre_defaults
81 #endif
82 
83 
84  //=============================================================================
86  //=============================================================================
87  class BiharmonicPreconditioner : public BlockPreconditioner<CRDoubleMatrix>
88  {
89  public:
92  {
93  // initialise both preconditioners to zero
97 
98  // by default we use the inexact biharmonic preconditioner
99  // and if possible use Hypre preconditioner
100 #ifdef OOMPH_HAS_HYPRE
102 #else
104 #endif
105 
106  // size mesh pt correctly
107  this->set_nmesh(1);
109  }
110 
113  {
114  this->clean_up_memory();
115  }
116 
117  // delete the subsidiary preconditioners and memory
119  {
120  // delete the sub preconditioners
124  }
125 
128 
130  void operator=(const BiharmonicPreconditioner&) = delete;
131 
133  void setup();
134 
137 
144  {
145  return Preconditioner_type;
146  }
147 
152  {
153  return Bulk_element_mesh_pt;
154  }
155 
156  private:
163 
166 
169 
172 
175  };
176 
177 
178  //=============================================================================
185  //=============================================================================
187  : public BlockPreconditioner<CRDoubleMatrix>
188  {
189  public:
192  const bool& retain_all_blocks = false)
193  : Retain_all_blocks(retain_all_blocks)
194  {
195  // Block mapping for ExactSubBiharmonicPreconditioner
196  Vector<unsigned> block_lookup(3);
197  block_lookup[0] = 0;
198  block_lookup[1] = 1;
199  block_lookup[2] = 2;
200 
201  // set as subsidiary block preconditioner
202  this->turn_into_subsidiary_block_preconditioner(master_prec_pt,
203  block_lookup);
204 
205  // null the Sub preconditioner pt
207  }
208 
211  {
212  this->clean_up_memory();
213  }
214 
217  {
218  delete Sub_preconditioner_pt;
220  }
221 
224  delete;
225 
228 
230  void setup();
231 
234 
235  // private:
236 
237  // Pointer to the sub preconditioner
239 
240 
244  };
245 
246  //=============================================================================
250  //=============================================================================
252  : public BlockPreconditioner<CRDoubleMatrix>
253  {
254  public:
260  const bool use_amg)
261  {
262  // Block mapping for ExactSubBiharmonicPreconditioner
263  Vector<unsigned> block_lookup(3);
264  block_lookup[0] = 0;
265  block_lookup[1] = 1;
266  block_lookup[2] = 2;
267 
268  // set as subsidiary block preconditioner
269  this->turn_into_subsidiary_block_preconditioner(master_prec_pt,
270  block_lookup);
271 
272  // zero all the preconditioner pt
276 
277  // store the preconditioner type
278  Use_amg = use_amg;
279  }
280 
283  {
284  this->clean_up_memory();
285  }
286 
289  {
290  // delete the sub preconditioner pt
291  delete S_00_preconditioner_pt;
293 
294  // delete the lumped preconditioners
299 
300  // Number of block types
301  unsigned n = Matrix_of_block_pointers.nrow();
302 
303  // delete the block matrices
304  for (unsigned i = 0; i < n; i++)
305  {
306  for (unsigned j = 0; j < n; j++)
307  {
308  if (Matrix_of_block_pointers(i, j) != 0)
309  {
310  delete Matrix_of_block_pointers(i, j);
312  }
313  }
314  }
315  }
316 
319  const InexactSubBiharmonicPreconditioner&) = delete;
320 
323 
325  void setup();
326 
329 
330  // private:
331 
336 
339 
343 
347 
350 
353 
356  unsigned Use_amg;
357  };
358 } // namespace oomph
359 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Biharmonic Preconditioner - for two dimensional problems.
Definition: biharmonic_preconditioner.h:88
BiharmonicPreconditioner()
Constructor - by default inexact preconditioning is used.
Definition: biharmonic_preconditioner.h:91
Preconditioner * Hijacked_sub_block_preconditioner_pt
Preconditioner the diagonal block associated with hijacked elements.
Definition: biharmonic_preconditioner.h:171
Preconditioner * Sub_preconditioner_2_pt
Inexact Preconditioner Pointer.
Definition: biharmonic_preconditioner.h:168
void clean_up_memory()
Clean up memory (empty). Generic interface function.
Definition: biharmonic_preconditioner.h:118
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply preconditioner to r.
Definition: biharmonic_preconditioner.cc:243
BiharmonicPreconditioner(const BiharmonicPreconditioner &)=delete
Broken copy constructor.
~BiharmonicPreconditioner()
destructor - cleans up preconditioners and delete matrices
Definition: biharmonic_preconditioner.h:112
void operator=(const BiharmonicPreconditioner &)=delete
Broken assignment operator.
unsigned & preconditioner_type()
Definition: biharmonic_preconditioner.h:143
void setup()
Setup the preconditioner.
Definition: biharmonic_preconditioner.cc:107
unsigned Preconditioner_type
Definition: biharmonic_preconditioner.h:162
Mesh * Bulk_element_mesh_pt
the bulk element mesh pt
Definition: biharmonic_preconditioner.h:174
Mesh *& bulk_element_mesh_pt()
Definition: biharmonic_preconditioner.h:151
Preconditioner * Sub_preconditioner_1_pt
Exact Preconditioner Pointer.
Definition: biharmonic_preconditioner.h:165
Definition: block_preconditioner.h:422
void turn_into_subsidiary_block_preconditioner(BlockPreconditioner< CRDoubleMatrix > *master_block_prec_pt, const Vector< unsigned > &doftype_in_master_preconditioner_coarse)
Definition: block_preconditioner.cc:2376
void set_nmesh(const unsigned &n)
Definition: block_preconditioner.h:2851
Definition: matrices.h:888
Definition: matrices.h:386
Definition: double_vector.h:58
Definition: biharmonic_preconditioner.h:188
ExactSubBiharmonicPreconditioner(BiharmonicPreconditioner *master_prec_pt, const bool &retain_all_blocks=false)
Constructor - for a preconditioner acting as a sub preconditioner.
Definition: biharmonic_preconditioner.h:191
ExactSubBiharmonicPreconditioner(const ExactSubBiharmonicPreconditioner &)=delete
Broken copy constructor.
void clean_up_memory()
delete the subsidiary preconditioner pointer
Definition: biharmonic_preconditioner.h:216
void operator=(const ExactSubBiharmonicPreconditioner &)=delete
Broken assignment operator.
Preconditioner * Sub_preconditioner_pt
Definition: biharmonic_preconditioner.h:238
bool Retain_all_blocks
Definition: biharmonic_preconditioner.h:243
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply preconditioner to r.
Definition: biharmonic_preconditioner.cc:335
~ExactSubBiharmonicPreconditioner()
destructor deletes the exact preconditioner
Definition: biharmonic_preconditioner.h:210
void setup()
Setup the preconditioner.
Definition: biharmonic_preconditioner.cc:274
Definition: biharmonic_preconditioner.h:253
DenseMatrix< CRDoubleMatrix * > Matrix_of_block_pointers
Definition: biharmonic_preconditioner.h:349
void compute_inexact_schur_complement()
Definition: biharmonic_preconditioner.cc:446
Preconditioner * S_00_preconditioner_pt
Pointer to the S00 Schur Complement preconditioner.
Definition: biharmonic_preconditioner.h:338
unsigned Use_amg
Definition: biharmonic_preconditioner.h:356
InexactSubBiharmonicPreconditioner(BiharmonicPreconditioner *master_prec_pt, const bool use_amg)
Definition: biharmonic_preconditioner.h:259
void clean_up_memory()
clean the memory
Definition: biharmonic_preconditioner.h:288
~InexactSubBiharmonicPreconditioner()
destructor - just calls this->clean_up_memory()
Definition: biharmonic_preconditioner.h:282
void operator=(const InexactSubBiharmonicPreconditioner &)=delete
Broken assignment operator.
MatrixBasedLumpedPreconditioner< CRDoubleMatrix > * Lumped_J_22_preconditioner_pt
Preconditioner for storing the lumped J_22 matrix.
Definition: biharmonic_preconditioner.h:346
InexactSubBiharmonicPreconditioner(const InexactSubBiharmonicPreconditioner &)=delete
Broken copy constructor.
CRDoubleMatrix * S_00_pt
Definition: biharmonic_preconditioner.h:352
void setup()
Setup the preconditioner.
Definition: biharmonic_preconditioner.cc:356
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply preconditioner to r.
Definition: biharmonic_preconditioner.cc:657
MatrixBasedLumpedPreconditioner< CRDoubleMatrix > * Lumped_J_11_preconditioner_pt
Preconditioner for storing the lumped J_11 matrix.
Definition: biharmonic_preconditioner.h:342
Matrix-based lumped preconditioner.
Definition: general_purpose_preconditioners.h:81
Definition: mesh.h:67
Definition: preconditioner.h:54
r
Definition: UniformPSDSelfTest.py:20
static void set_defaults(double knobs[NKnobs])
set default parameters The use of this routine is optional.
Definition: Eigen_Colamd.h:295
unsigned AMG_coarsening
Definition: hypre_solver.cc:134
double AMG_strength
Definition: hypre_solver.cc:118
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2