general_purpose_space_time_block_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-2023 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 // Header file for SpaceTime elements
27 #ifndef OOMPH_GENERAL_PURPOSE_SPACE_TIME_BLOCK_PRECONDITIONER_HEADER
28 #define OOMPH_GENERAL_PURPOSE_SPACE_TIME_BLOCK_PRECONDITIONER_HEADER
29 
30 // Config header generated by autoconfig
31 #ifdef HAVE_CONFIG_H
32 #include <oomph-lib-config.h>
33 #endif
34 
35 // Oomph-lib headers
38 
39 // Add in the subsidiary preconditioners
41 
42 /// /////////////////////////////////////////////////////////////////////////
43 /// /////////////////////////////////////////////////////////////////////////
44 /// /////////////////////////////////////////////////////////////////////////
45 
46 namespace oomph
47 {
48  //=============================================================================
49  /// General purpose block tridiagonal preconditioner. By default
50  /// SuperLUPreconditioner (or SuperLUDistPreconditioner) is used to solve the
51  /// subsidiary systems, but other preconditioners can be used by setting them
52  /// using passing a pointer to a function of type
53  /// SubsidiaryPreconditionerFctPt to the method
54  /// subsidiary_preconditioner_function_pt().
55  //=============================================================================
56  template<typename MATRIX>
58  : public GeneralPurposeBlockPreconditioner<MATRIX>
59  {
60  public:
61  /// Constructor. (By default this preconditioner is upper triangular).
63  {
64  // The preconditioner has been created but it hasn't been set up yet
66 
67  // By default, don't store the memory statistics of this preconditioner
69 
70  // Initialise the value of Memory_usage_in_bytes
72  } // End of ExactDGPBlockPreconditioner
73 
74 
75  /// Destructor - delete the preconditioner matrices
77  {
78  // Forward the call to a helper clean-up function
79  this->clean_up_memory();
80  } // End of ~ExactDGPBlockPreconditioner
81 
82 
83  /// Clean up the memory
84  virtual void clean_up_memory()
85  {
86  // Clean up the base class too
88  } // End of clean_up_memory
89 
90 
91  /// Broken copy constructor
93 
94  /// Broken assignment operator
95  void operator=(const ExactDGPBlockPreconditioner&) = delete;
96 
97  /// Apply preconditioner to r
99 
100 
101  /// Setup the preconditioner
102  void setup();
103 
104 
105  /// Document the memory usage
107  {
108  /// Set the appropriate flag to true
110  } // End of enable_doc_memory_usage
111 
112 
113  /// Don't document the memory usage!
115  {
116  /// Set the appropriate flag to false
118  } // End of disable_doc_memory_usage
119 
120 
121  /// Get the memory statistics
123  {
124  // Has the preconditioner even been set up yet?
126  {
127  // Were we meant to compute the statistics?
129  {
130  // Return the appropriate variable value
131  return Memory_usage_in_bytes;
132  }
133  else
134  {
135  // Allocate storage for an output stream
136  std::ostringstream warning_message_stream;
137 
138  // Create a warning message
139  warning_message_stream
140  << "The memory statistics have not been calculated "
141  << "so I'm returning\nthe value zero." << std::endl;
142 
143  // Give the user a warning
144  OomphLibWarning(warning_message_stream.str(),
145  OOMPH_CURRENT_FUNCTION,
146  OOMPH_EXCEPTION_LOCATION);
147 
148  // Return the value zero
149  return 0.0;
150  }
151  }
152  // If the preconditioner hasn't been set up yet
153  else
154  {
155  // Allocate storage for an output stream
156  std::ostringstream warning_message_stream;
157 
158  // Create a warning message
159  warning_message_stream
160  << "The preconditioner hasn't even been set up yet "
161  << "so I'm returning\nthe value zero." << std::endl;
162 
163  // Give the user a warning
164  OomphLibWarning(warning_message_stream.str(),
165  OOMPH_CURRENT_FUNCTION,
166  OOMPH_EXCEPTION_LOCATION);
167 
168  // Return the value zero
169  return 0.0;
170  } // if (Preconditioner_has_been_setup)
171  } // End of get_memory_usage_in_bytes
172 
173  private:
174  /// Control flag is true if the preconditioner has been setup
175  /// (used so we can wipe the data when the preconditioner is called again)
177 
178  /// Flag to indicate whether or not to record the memory statistics
179  /// this preconditioner
181 
182  /// Storage for the memory usage of the solver if the flag above
183  /// is set to true (in bytes)
185  };
186 
187  //=============================================================================
188  /// General purpose block triangular preconditioner. By default this
189  /// operates as an upper triangular preconditioner. Also, by default
190  /// SuperLUPreconditioner (or SuperLUDistPreconditioner) is used to solve the
191  /// subsidiary systems, but other preconditioners can be used by setting them
192  /// using passing a pointer to a function of type
193  /// SubsidiaryPreconditionerFctPt to the method
194  /// subsidiary_preconditioner_function_pt().
195  //=============================================================================
196  template<typename MATRIX>
198  : public GeneralPurposeBlockPreconditioner<MATRIX>
199  {
200  public:
201  /// Constructor. (By default this preconditioner is upper triangular).
204  {
205  // Default to upper triangular
206  Upper_triangular = true;
207 
208  // Default is to assume every block above the diagonal is non-empty
209  Block_bandwidth = -1;
210 
211  // The preconditioner has been created but it hasn't been set up yet
213 
214  // By default, don't store the memory statistics of this preconditioner
216 
217  // Initialise the value of Memory_usage_in_bytes
218  Memory_usage_in_bytes = 0.0;
219  } // End of BandedBlockTriangularPreconditioner
220 
221 
222  /// Destructor - delete the preconditioner matrices
224  {
225  // Forward the call to a helper clean-up function
226  this->clean_up_memory();
227  } // End of ~BandedBlockTriangularPreconditioner
228 
229 
230  /// Clean up the memory
231  virtual void clean_up_memory()
232  {
233  // Delete anything in Off_diagonal_matrix_vector_products
234  for (unsigned i = 0, ni = Off_diagonal_matrix_vector_products.nrow();
235  i < ni;
236  i++)
237  {
238  for (unsigned j = 0, nj = Off_diagonal_matrix_vector_products.ncol();
239  j < nj;
240  j++)
241  {
242  // Delete the matrix-vector product
244 
245  // Make it a null pointer
247  }
248  } // for (unsigned i=0,ni=Off_diagonal_matrix_vector_products.nrow();...
249 
250  // Clean up the base class too
252  } // End of clean_up_memory
253 
254 
255  /// Broken copy constructor
257  const BandedBlockTriangularPreconditioner&) = delete;
258 
259  /// Broken assignment operator
261 
262  /// Apply preconditioner to r
264 
265 
266  /// Setup the preconditioner
267  void setup();
268 
269 
270  /// Set the block bandwidth of the preconditioner
272  {
273  // Store it
275  } // End of set_block_bandwidth
276 
277 
278  /// Get the block bandwidth of the preconditioner
280  {
281  // Store it
282  return Block_bandwidth;
283  } // End of block_bandwidth
284 
285 
286  /// Use as an upper triangular preconditioner
288  {
289  // Update the Upper_triangular flag
290  Upper_triangular = true;
291  } // End of upper_triangular
292 
293 
294  /// Use as a lower triangular preconditioner
296  {
297  // Update the Upper_triangular flag
298  Upper_triangular = false;
299  } // End of lower_triangular
300 
301 
302  /// Is this being used as an upper triangular preconditioner?
304  {
305  // Return the value of the Upper_triangular flag
306  return Upper_triangular;
307  } // End of is_upper_triangular
308 
309 
310  /// Document the memory usage
312  {
313  /// Set the appropriate flag to true
315  } // End of enable_doc_memory_usage
316 
317 
318  /// Don't document the memory usage!
320  {
321  /// Set the appropriate flag to false
323  } // End of disable_doc_memory_usage
324 
325 
326  /// Get the memory statistics
328  {
329  // Has the preconditioner even been set up yet?
331  {
332  // Were we meant to compute the statistics?
334  {
335  // Return the appropriate variable value
336  return Memory_usage_in_bytes;
337  }
338  else
339  {
340  // Allocate storage for an output stream
341  std::ostringstream warning_message_stream;
342 
343  // Create a warning message
344  warning_message_stream
345  << "The memory statistics have not been calculated "
346  << "so I'm returning\nthe value zero." << std::endl;
347 
348  // Give the user a warning
349  OomphLibWarning(warning_message_stream.str(),
350  OOMPH_CURRENT_FUNCTION,
351  OOMPH_EXCEPTION_LOCATION);
352 
353  // Return the value zero
354  return 0.0;
355  }
356  }
357  // If the preconditioner hasn't been set up yet
358  else
359  {
360  // Allocate storage for an output stream
361  std::ostringstream warning_message_stream;
362 
363  // Create a warning message
364  warning_message_stream
365  << "The preconditioner hasn't even been set up yet "
366  << "so I'm returning\nthe value zero." << std::endl;
367 
368  // Give the user a warning
369  OomphLibWarning(warning_message_stream.str(),
370  OOMPH_CURRENT_FUNCTION,
371  OOMPH_EXCEPTION_LOCATION);
372 
373  // Return the value zero
374  return 0.0;
375  } // if (Preconditioner_has_been_setup)
376  } // End of get_memory_usage_in_bytes
377 
378  protected:
379  /// Matrix of matrix-vector product operators for the off diagonals
381 
382  private:
383  /// Storage for the block bandwidth of the matrix. Defaults to -1
384  /// indicating that we assume every off-diagonal block is non-empty. If
385  /// the matrix is block diagonal then the value is zero
387 
388  /// Boolean indicating upper or lower triangular
390 
391  /// Control flag is true if the preconditioner has been setup
392  /// (used so we can wipe the data when the preconditioner is called again)
394 
395  /// Flag to indicate whether or not to record the memory statistics
396  /// this preconditioner
398 
399  /// Storage for the memory usage of the solver if the flag above
400  /// is set to true (in bytes)
402  };
403 } // End of namespace oomph
404 #endif
cstr elem_len * i
Definition: cfortran.h:603
General purpose block triangular preconditioner. By default this operates as an upper triangular prec...
DenseMatrix< MatrixVectorProduct * > Off_diagonal_matrix_vector_products
Matrix of matrix-vector product operators for the off diagonals.
bool Preconditioner_has_been_setup
Control flag is true if the preconditioner has been setup (used so we can wipe the data when the prec...
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply preconditioner to r.
bool Compute_memory_statistics
Flag to indicate whether or not to record the memory statistics this preconditioner.
bool Upper_triangular
Boolean indicating upper or lower triangular.
bool is_upper_triangular()
Is this being used as an upper triangular preconditioner?
BandedBlockTriangularPreconditioner()
Constructor. (By default this preconditioner is upper triangular).
void upper_triangular()
Use as an upper triangular preconditioner.
int block_bandwidth()
Get the block bandwidth of the preconditioner.
void lower_triangular()
Use as a lower triangular preconditioner.
double Memory_usage_in_bytes
Storage for the memory usage of the solver if the flag above is set to true (in bytes)
int Block_bandwidth
Storage for the block bandwidth of the matrix. Defaults to -1 indicating that we assume every off-dia...
BandedBlockTriangularPreconditioner(const BandedBlockTriangularPreconditioner &)=delete
Broken copy constructor.
virtual ~BandedBlockTriangularPreconditioner()
Destructor - delete the preconditioner matrices.
void set_block_bandwidth(const int &block_bandwidth)
Set the block bandwidth of the preconditioner.
void operator=(const BandedBlockTriangularPreconditioner &)=delete
Broken assignment operator.
//////////////////////////////////////////////////////////////////////////// ////////////////////////...
Definition: matrices.h:386
A vector in the mathematical sense, initially developed for linear algebra type applications....
Definition: double_vector.h:58
General purpose block tridiagonal preconditioner. By default SuperLUPreconditioner (or SuperLUDistPre...
ExactDGPBlockPreconditioner()
Constructor. (By default this preconditioner is upper triangular).
void operator=(const ExactDGPBlockPreconditioner &)=delete
Broken assignment operator.
bool Compute_memory_statistics
Flag to indicate whether or not to record the memory statistics this preconditioner.
bool Preconditioner_has_been_setup
Control flag is true if the preconditioner has been setup (used so we can wipe the data when the prec...
virtual ~ExactDGPBlockPreconditioner()
Destructor - delete the preconditioner matrices.
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply preconditioner to r.
ExactDGPBlockPreconditioner(const ExactDGPBlockPreconditioner &)=delete
Broken copy constructor.
double Memory_usage_in_bytes
Storage for the memory usage of the solver if the flag above is set to true (in bytes)
Base class for general purpose block preconditioners. Deals with setting subsidiary preconditioners a...
virtual void clean_up_memory()
??ds I think clean_up_memory is supposed to clear out any stuff that doesn't need to be stored betwee...
An OomphLibWarning object which should be created as a temporary object to issue a warning....
//////////////////////////////////////////////////////////////////// ////////////////////////////////...