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-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 // 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 
45 
46 namespace oomph
47 {
48  //=============================================================================
55  //=============================================================================
56  template<typename MATRIX>
58  : public GeneralPurposeBlockPreconditioner<MATRIX>
59  {
60  public:
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 
77  {
78  // Forward the call to a helper clean-up function
79  this->clean_up_memory();
80  } // End of ~ExactDGPBlockPreconditioner
81 
82 
84  virtual void clean_up_memory()
85  {
86  // Clean up the base class too
88  } // End of clean_up_memory
89 
90 
93 
95  void operator=(const ExactDGPBlockPreconditioner&) = delete;
96 
99 
100 
102  void setup();
103 
104 
107  {
110  } // End of enable_doc_memory_usage
111 
112 
115  {
118  } // End of disable_doc_memory_usage
119 
120 
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(),
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(),
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:
177 
181 
185  };
186 
187  //=============================================================================
195  //=============================================================================
196  template<typename MATRIX>
198  : public GeneralPurposeBlockPreconditioner<MATRIX>
199  {
200  public:
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 
224  {
225  // Forward the call to a helper clean-up function
226  this->clean_up_memory();
227  } // End of ~BandedBlockTriangularPreconditioner
228 
229 
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 
257  const BandedBlockTriangularPreconditioner&) = delete;
258 
261 
264 
265 
267  void setup();
268 
269 
272  {
273  // Store it
275  } // End of set_block_bandwidth
276 
277 
280  {
281  // Store it
282  return Block_bandwidth;
283  } // End of block_bandwidth
284 
285 
288  {
289  // Update the Upper_triangular flag
290  Upper_triangular = true;
291  } // End of upper_triangular
292 
293 
296  {
297  // Update the Upper_triangular flag
298  Upper_triangular = false;
299  } // End of lower_triangular
300 
301 
304  {
305  // Return the value of the Upper_triangular flag
306  return Upper_triangular;
307  } // End of is_upper_triangular
308 
309 
312  {
315  } // End of enable_doc_memory_usage
316 
317 
320  {
323  } // End of disable_doc_memory_usage
324 
325 
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(),
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(),
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:
381 
382  private:
387 
390 
394 
398 
402  };
403 } // End of namespace oomph
404 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Definition: general_purpose_space_time_block_preconditioner.h:199
void enable_doc_memory_usage()
Document the memory usage.
Definition: general_purpose_space_time_block_preconditioner.h:311
DenseMatrix< MatrixVectorProduct * > Off_diagonal_matrix_vector_products
Matrix of matrix-vector product operators for the off diagonals.
Definition: general_purpose_space_time_block_preconditioner.h:380
void setup()
Setup the preconditioner.
Definition: general_purpose_space_time_block_preconditioner.cc:218
virtual void clean_up_memory()
Clean up the memory.
Definition: general_purpose_space_time_block_preconditioner.h:231
bool Preconditioner_has_been_setup
Definition: general_purpose_space_time_block_preconditioner.h:393
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply preconditioner to r.
Definition: general_purpose_space_time_block_preconditioner.cc:600
bool Compute_memory_statistics
Definition: general_purpose_space_time_block_preconditioner.h:397
bool Upper_triangular
Boolean indicating upper or lower triangular.
Definition: general_purpose_space_time_block_preconditioner.h:389
bool is_upper_triangular()
Is this being used as an upper triangular preconditioner?
Definition: general_purpose_space_time_block_preconditioner.h:303
void disable_doc_memory_usage()
Don't document the memory usage!
Definition: general_purpose_space_time_block_preconditioner.h:319
BandedBlockTriangularPreconditioner()
Constructor. (By default this preconditioner is upper triangular).
Definition: general_purpose_space_time_block_preconditioner.h:202
void upper_triangular()
Use as an upper triangular preconditioner.
Definition: general_purpose_space_time_block_preconditioner.h:287
int block_bandwidth()
Get the block bandwidth of the preconditioner.
Definition: general_purpose_space_time_block_preconditioner.h:279
void lower_triangular()
Use as a lower triangular preconditioner.
Definition: general_purpose_space_time_block_preconditioner.h:295
double Memory_usage_in_bytes
Definition: general_purpose_space_time_block_preconditioner.h:401
int Block_bandwidth
Definition: general_purpose_space_time_block_preconditioner.h:386
BandedBlockTriangularPreconditioner(const BandedBlockTriangularPreconditioner &)=delete
Broken copy constructor.
virtual ~BandedBlockTriangularPreconditioner()
Destructor - delete the preconditioner matrices.
Definition: general_purpose_space_time_block_preconditioner.h:223
void set_block_bandwidth(const int &block_bandwidth)
Set the block bandwidth of the preconditioner.
Definition: general_purpose_space_time_block_preconditioner.h:271
void operator=(const BandedBlockTriangularPreconditioner &)=delete
Broken assignment operator.
double get_memory_usage_in_bytes()
Get the memory statistics.
Definition: general_purpose_space_time_block_preconditioner.h:327
Definition: matrices.h:386
Definition: double_vector.h:58
Definition: general_purpose_space_time_block_preconditioner.h:59
void enable_doc_memory_usage()
Document the memory usage.
Definition: general_purpose_space_time_block_preconditioner.h:106
ExactDGPBlockPreconditioner()
Constructor. (By default this preconditioner is upper triangular).
Definition: general_purpose_space_time_block_preconditioner.h:62
void operator=(const ExactDGPBlockPreconditioner &)=delete
Broken assignment operator.
bool Compute_memory_statistics
Definition: general_purpose_space_time_block_preconditioner.h:180
virtual void clean_up_memory()
Clean up the memory.
Definition: general_purpose_space_time_block_preconditioner.h:84
void disable_doc_memory_usage()
Don't document the memory usage!
Definition: general_purpose_space_time_block_preconditioner.h:114
bool Preconditioner_has_been_setup
Definition: general_purpose_space_time_block_preconditioner.h:176
void setup()
Setup the preconditioner.
Definition: general_purpose_space_time_block_preconditioner.cc:42
virtual ~ExactDGPBlockPreconditioner()
Destructor - delete the preconditioner matrices.
Definition: general_purpose_space_time_block_preconditioner.h:76
void preconditioner_solve(const DoubleVector &r, DoubleVector &z)
Apply preconditioner to r.
Definition: general_purpose_space_time_block_preconditioner.cc:181
double get_memory_usage_in_bytes()
Get the memory statistics.
Definition: general_purpose_space_time_block_preconditioner.h:122
ExactDGPBlockPreconditioner(const ExactDGPBlockPreconditioner &)=delete
Broken copy constructor.
double Memory_usage_in_bytes
Definition: general_purpose_space_time_block_preconditioner.h:184
Definition: general_purpose_block_preconditioners.h:77
virtual void clean_up_memory()
Definition: general_purpose_block_preconditioners.h:112
Definition: oomph_definitions.h:267
r
Definition: UniformPSDSelfTest.py:20
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2