oomph::HelmholtzSmoother Class Referenceabstract

#include <complex_smoother.h>

+ Inheritance diagram for oomph::HelmholtzSmoother:

Public Member Functions

 HelmholtzSmoother ()
 Empty constructor. More...
 
virtual ~HelmholtzSmoother ()
 Virtual empty destructor. More...
 
virtual void complex_smoother_solve (const Vector< DoubleVector > &rhs, Vector< DoubleVector > &result)=0
 
virtual void complex_smoother_setup (Vector< CRDoubleMatrix * > matrix_pt)=0
 Setup the smoother for the matrix specified by the pointer. More...
 
void complex_matrix_multiplication (Vector< CRDoubleMatrix * > matrices_pt, const Vector< DoubleVector > &x, Vector< DoubleVector > &soln)
 
template<typename MATRIX >
void check_validity_of_solve_helper_inputs (CRDoubleMatrix *const &real_matrix_pt, CRDoubleMatrix *const &imag_matrix_pt, const Vector< DoubleVector > &rhs, Vector< DoubleVector > &solution, const double &n_dof)
 
- Public Member Functions inherited from oomph::IterativeLinearSolver
 IterativeLinearSolver ()
 
 IterativeLinearSolver (const IterativeLinearSolver &)=delete
 Broken copy constructor. More...
 
void operator= (const IterativeLinearSolver &)=delete
 Broken assignment operator. More...
 
virtual ~IterativeLinearSolver ()
 Destructor (empty) More...
 
Preconditioner *& preconditioner_pt ()
 Access function to preconditioner. More...
 
Preconditioner *const & preconditioner_pt () const
 Access function to preconditioner (const version) More...
 
doubletolerance ()
 Access to convergence tolerance. More...
 
unsignedmax_iter ()
 Access to max. number of iterations. More...
 
virtual unsigned iterations () const =0
 Number of iterations taken. More...
 
void enable_doc_convergence_history ()
 Enable documentation of the convergence history. More...
 
void disable_doc_convergence_history ()
 Disable documentation of the convergence history. More...
 
void open_convergence_history_file_stream (const std::string &file_name, const std::string &zone_title="")
 
void close_convergence_history_file_stream ()
 Close convergence history output stream. More...
 
double jacobian_setup_time () const
 
double linear_solver_solution_time () const
 return the time taken to solve the linear system More...
 
virtual double preconditioner_setup_time () const
 returns the the time taken to setup the preconditioner More...
 
void enable_setup_preconditioner_before_solve ()
 Setup the preconditioner before the solve. More...
 
void disable_setup_preconditioner_before_solve ()
 Don't set up the preconditioner before the solve. More...
 
void enable_error_after_max_iter ()
 Throw an error if we don't converge within max_iter. More...
 
void disable_error_after_max_iter ()
 Don't throw an error if we don't converge within max_iter (default). More...
 
void enable_iterative_solver_as_preconditioner ()
 
void disable_iterative_solver_as_preconditioner ()
 
- Public Member Functions inherited from oomph::LinearSolver
 LinearSolver ()
 Empty constructor, initialise the member data. More...
 
 LinearSolver (const LinearSolver &dummy)=delete
 Broken copy constructor. More...
 
void operator= (const LinearSolver &)=delete
 Broken assignment operator. More...
 
virtual ~LinearSolver ()
 Empty virtual destructor. More...
 
void enable_doc_time ()
 Enable documentation of solve times. More...
 
void disable_doc_time ()
 Disable documentation of solve times. More...
 
bool is_doc_time_enabled () const
 Is documentation of solve times enabled? More...
 
bool is_resolve_enabled () const
 Boolean flag indicating if resolves are enabled. More...
 
virtual void enable_resolve ()
 
virtual void disable_resolve ()
 
virtual void solve (Problem *const &problem_pt, DoubleVector &result)=0
 
virtual void solve (DoubleMatrixBase *const &matrix_pt, const DoubleVector &rhs, DoubleVector &result)
 
virtual void solve (DoubleMatrixBase *const &matrix_pt, const Vector< double > &rhs, Vector< double > &result)
 
virtual void solve_transpose (Problem *const &problem_pt, DoubleVector &result)
 
virtual void solve_transpose (DoubleMatrixBase *const &matrix_pt, const DoubleVector &rhs, DoubleVector &result)
 
virtual void solve_transpose (DoubleMatrixBase *const &matrix_pt, const Vector< double > &rhs, Vector< double > &result)
 
virtual void resolve (const DoubleVector &rhs, DoubleVector &result)
 
virtual void resolve_transpose (const DoubleVector &rhs, DoubleVector &result)
 
virtual void clean_up_memory ()
 
virtual void enable_computation_of_gradient ()
 
void disable_computation_of_gradient ()
 
void reset_gradient ()
 
void get_gradient (DoubleVector &gradient)
 function to access the gradient, provided it has been computed More...
 
- Public Member Functions inherited from oomph::DistributableLinearAlgebraObject
 DistributableLinearAlgebraObject ()
 Default constructor - create a distribution. More...
 
 DistributableLinearAlgebraObject (const DistributableLinearAlgebraObject &matrix)=delete
 Broken copy constructor. More...
 
void operator= (const DistributableLinearAlgebraObject &)=delete
 Broken assignment operator. More...
 
virtual ~DistributableLinearAlgebraObject ()
 Destructor. More...
 
LinearAlgebraDistributiondistribution_pt () const
 access to the LinearAlgebraDistribution More...
 
unsigned nrow () const
 access function to the number of global rows. More...
 
unsigned nrow_local () const
 access function for the num of local rows on this processor. More...
 
unsigned nrow_local (const unsigned &p) const
 access function for the num of local rows on this processor. More...
 
unsigned first_row () const
 access function for the first row on this processor More...
 
unsigned first_row (const unsigned &p) const
 access function for the first row on this processor More...
 
bool distributed () const
 distribution is serial or distributed More...
 
bool distribution_built () const
 
void build_distribution (const LinearAlgebraDistribution *const dist_pt)
 
void build_distribution (const LinearAlgebraDistribution &dist)
 

Protected Attributes

bool Use_as_smoother
 
- Protected Attributes inherited from oomph::IterativeLinearSolver
bool Doc_convergence_history
 
std::ofstream Output_file_stream
 Output file stream for convergence history. More...
 
double Tolerance
 Convergence tolerance. More...
 
unsigned Max_iter
 Maximum number of iterations. More...
 
PreconditionerPreconditioner_pt
 Pointer to the preconditioner. More...
 
double Jacobian_setup_time
 Jacobian setup time. More...
 
double Solution_time
 linear solver solution time More...
 
double Preconditioner_setup_time
 Preconditioner setup time. More...
 
bool Setup_preconditioner_before_solve
 
bool Throw_error_after_max_iter
 
bool Use_iterative_solver_as_preconditioner
 Use the iterative solver as preconditioner. More...
 
bool First_time_solve_when_used_as_preconditioner
 
- Protected Attributes inherited from oomph::LinearSolver
bool Enable_resolve
 
bool Doc_time
 Boolean flag that indicates whether the time taken. More...
 
bool Compute_gradient
 
bool Gradient_has_been_computed
 flag that indicates whether the gradient was computed or not More...
 
DoubleVector Gradient_for_glob_conv_newton_solve
 

Additional Inherited Members

- Protected Member Functions inherited from oomph::DistributableLinearAlgebraObject
void clear_distribution ()
 
- Static Protected Attributes inherited from oomph::IterativeLinearSolver
static IdentityPreconditioner Default_preconditioner
 

Detailed Description

Helmholtz smoother class: The smoother class is designed for the Helmholtz equation to be used in conjunction with multigrid. The action of the smoother should reduce the high frequency errors. These methods are inefficient as stand-alone solvers

Constructor & Destructor Documentation

◆ HelmholtzSmoother()

oomph::HelmholtzSmoother::HelmholtzSmoother ( )
inline

Empty constructor.

49 : Use_as_smoother(false) {}
bool Use_as_smoother
Definition: complex_smoother.h:176

◆ ~HelmholtzSmoother()

virtual oomph::HelmholtzSmoother::~HelmholtzSmoother ( )
inlinevirtual

Virtual empty destructor.

52 {};

Member Function Documentation

◆ check_validity_of_solve_helper_inputs()

template<typename MATRIX >
void oomph::HelmholtzSmoother::check_validity_of_solve_helper_inputs ( CRDoubleMatrix *const &  real_matrix_pt,
CRDoubleMatrix *const &  imag_matrix_pt,
const Vector< DoubleVector > &  rhs,
Vector< DoubleVector > &  solution,
const double n_dof 
)

Self-test to check that all the dimensions of the inputs to solve helper are consistent and everything that needs to be built, is.

Self-test to be called inside solve_helper to ensure that all inputs are consistent and everything that needs to be built, is.

191  {
192  // Number of dof types should be 2 (real & imaginary)
193  unsigned n_dof_types = 2;
194 
195  // Create a vector to hold the matrices
196  Vector<CRDoubleMatrix*> matrix_storage_pt(2, 0);
197 
198  // Assign the first entry in matrix_storage_pt
199  matrix_storage_pt[0] = real_matrix_pt;
200 
201  // Assign the second entry in matrix_storage_pt
202  matrix_storage_pt[1] = imag_matrix_pt;
203 
204  // Loop over the real and imaginary parts
205  for (unsigned dof_type = 0; dof_type < n_dof_types; dof_type++)
206  {
207  // Check if the matrix is distributable. If it is then it should
208  // not be distributed
209  if (dynamic_cast<DistributableLinearAlgebraObject*>(
210  matrix_storage_pt[dof_type]) != 0)
211  {
212  if (dynamic_cast<DistributableLinearAlgebraObject*>(
213  matrix_storage_pt[dof_type])
214  ->distributed())
215  {
216  std::ostringstream error_message_stream;
217  error_message_stream << "The matrix must not be distributed.";
218  throw OomphLibError(error_message_stream.str(),
221  }
222  }
223  // Check that this rhs distribution is setup
224  if (!(rhs[dof_type].built()))
225  {
226  std::ostringstream error_message_stream;
227  error_message_stream << "The rhs vector distribution must be setup.";
228  throw OomphLibError(error_message_stream.str(),
231  }
232  // Check that the rhs has the right number of global rows
233  if (rhs[dof_type].nrow() != n_dof)
234  {
235  std::ostringstream error_message_stream;
236  error_message_stream << "RHS does not have the same dimension as the "
237  << "linear system";
238  throw OomphLibError(error_message_stream.str(),
241  }
242  // Check that the rhs is not distributed
243  if (rhs[dof_type].distribution_pt()->distributed())
244  {
245  std::ostringstream error_message_stream;
246  error_message_stream << "The rhs vector must not be distributed.";
247  throw OomphLibError(error_message_stream.str(),
250  }
251  // Check that if the result is setup it matches the distribution
252  // of the rhs
253  if (solution[dof_type].built())
254  {
255  if (!(*rhs[dof_type].distribution_pt() ==
256  *solution[dof_type].distribution_pt()))
257  {
258  std::ostringstream error_message_stream;
259  error_message_stream << "If the result distribution is setup then it "
260  << "must be the same as the rhs distribution";
261  throw OomphLibError(error_message_stream.str(),
264  }
265  } // if ((solution[0].built())||(solution[1].built()))
266  } // for (unsigned dof_type=0;dof_type<n_dof_types;dof_type)
267  } // End of check_validity_of_solve_helper_inputs
bool distributed() const
distribution is serial or distributed
Definition: linear_algebra_distribution.h:493
LinearAlgebraDistribution * distribution_pt() const
access to the LinearAlgebraDistribution
Definition: linear_algebra_distribution.h:457
unsigned nrow() const
access function to the number of global rows.
Definition: linear_algebra_distribution.h:463
DistributableLinearAlgebraObject()
Default constructor - create a distribution.
Definition: linear_algebra_distribution.h:438
void solution(const Vector< double > &x, Vector< double > &u)
Definition: two_d_biharmonic.cc:113
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References oomph::DistributableLinearAlgebraObject::distributed(), oomph::DistributableLinearAlgebraObject::distribution_pt(), oomph::DistributableLinearAlgebraObject::nrow(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and BiharmonicTestFunctions1::solution().

◆ complex_matrix_multiplication()

void oomph::HelmholtzSmoother::complex_matrix_multiplication ( Vector< CRDoubleMatrix * >  matrices_pt,
const Vector< DoubleVector > &  x,
Vector< DoubleVector > &  soln 
)
inline

Helper function to calculate a complex matrix-vector product. Assumes the matrix has been provided as a Vector of length two; the first entry containing the real part of the system matrix and the second entry containing the imaginary part

72  {
73 #ifdef PARANOID
74  // PARANOID check - Make sure the input matrix has the right size
75  if (matrices_pt.size() != 2)
76  {
77  // Create an output stream
78  std::ostringstream error_message_stream;
79 
80  // Create the error message
81  error_message_stream << "Can only deal with two matrices. You have "
82  << matrices_pt.size() << " matrices." << std::endl;
83 
84  // Throw an error
85  throw OomphLibError(error_message_stream.str(),
88  }
89  // PARANOID check - Make sure the vector x has the right size
90  if (x.size() != 2)
91  {
92  // Create an output stream
93  std::ostringstream error_message_stream;
94 
95  // Create the error message
96  error_message_stream
97  << "Can only deal with two input vectors. You have " << x.size()
98  << " vectors." << std::endl;
99 
100  // Throw an error
101  throw OomphLibError(error_message_stream.str(),
104  }
105  // PARANOID check - Make sure the vector soln has the right size
106  if (soln.size() != 2)
107  {
108  // Create an output stream
109  std::ostringstream error_message_stream;
110 
111  // Create the error message
112  error_message_stream
113  << "Can only deal with two output vectors. You have " << soln.size()
114  << " output vectors." << std::endl;
115 
116  // Throw an error
117  throw OomphLibError(error_message_stream.str(),
120  }
121 #endif
122 
123  //-----------------------------------------------------------------------
124  // Suppose we have a complex matrix, A, and two complex vectors, x and
125  // soln. We wish to compute the product A*x=soln (note, * does not mean
126  // we are using complex conjugates here, it is simply used to indicate
127  // a multiplication). To do this we must make use of the fact that we
128  // possess the real and imaginary separately. As a result, it is computed
129  // using:
130  // soln = A*x,
131  // = (A_r + i*A_c)*(x_r + i*x_c),
132  // = [A_r*x_r - A_c*x_c] + i*[A_r*x_c + A_c*x_r],
133  // ==> real(soln) = A_r*x_r - A_c*x_c,
134  // & imag(soln) = A_r*x_c + A_c*x_r,
135  // where the subscripts _r and _c are used to identify the real and
136  // imaginary part, respectively.
137  //-----------------------------------------------------------------------
138 
139  // Store the value of A_r*x_r in the real part of soln
140  matrices_pt[0]->multiply(x[0], soln[0]);
141 
142  // Store the value of A_r*x_c in the imaginary part of soln
143  matrices_pt[0]->multiply(x[1], soln[1]);
144 
145  // Create a temporary vector
146  DoubleVector temp(this->distribution_pt(), 0.0);
147 
148  // Calculate the value of A_c*x_c
149  matrices_pt[1]->multiply(x[1], temp);
150 
151  // Subtract the value of temp from soln[0] to get the real part of soln
152  soln[0] -= temp;
153 
154  // Calculate the value of A_c*x_r
155  matrices_pt[1]->multiply(x[0], temp);
156 
157  // Add the value of temp to soln[1] to get the imaginary part of soln
158  soln[1] += temp;
159  } // End of complex_matrix_multiplication
std::vector< double > DoubleVector
loads clump configuration
Definition: ClumpInput.h:26
list x
Definition: plotDoE.py:28

References oomph::DistributableLinearAlgebraObject::distribution_pt(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and plotDoE::x.

◆ complex_smoother_setup()

virtual void oomph::HelmholtzSmoother::complex_smoother_setup ( Vector< CRDoubleMatrix * >  matrix_pt)
pure virtual

Setup the smoother for the matrix specified by the pointer.

Implemented in oomph::ComplexGMRES< MATRIX >, and oomph::ComplexDampedJacobi< MATRIX >.

◆ complex_smoother_solve()

virtual void oomph::HelmholtzSmoother::complex_smoother_solve ( const Vector< DoubleVector > &  rhs,
Vector< DoubleVector > &  result 
)
pure virtual

The smoother_solve function performs fixed number of iterations on the system A*result=rhs. The number of (smoothing) iterations is the same as the max. number of iterations in the underlying IterativeLinearSolver class.

Implemented in oomph::ComplexGMRES< MATRIX >, and oomph::ComplexDampedJacobi< MATRIX >.

Member Data Documentation

◆ Use_as_smoother

bool oomph::HelmholtzSmoother::Use_as_smoother
protected

When a derived class object is being used as a smoother in the MG algorithm the residual norm does not need to be calculated. This boolean is used as a flag to indicate this in solve_helper(...)

Referenced by oomph::ComplexDampedJacobi< MATRIX >::complex_smoother_solve(), and oomph::ComplexGMRES< MATRIX >::complex_smoother_solve().


The documentation for this class was generated from the following file: