HypreSolver_test.cc File Reference
#include "generic.h"
#include "poisson.h"
#include "meshes/rectangular_quadmesh.h"

Classes

class  PoissonProblem< ELEMENT >
 Micky mouse Poisson problem. More...
 

Namespaces

 TanhSolnForPoisson
 Namespace for exact solution for Poisson equation with "sharp step".
 

Functions

void TanhSolnForPoisson::get_exact_u (const Vector< double > &x, Vector< double > &u)
 Exact solution as a Vector. More...
 
void TanhSolnForPoisson::source_function (const Vector< double > &x, double &source)
 Source function required to make the solution above an exact solution. More...
 
int main (int argc, char **argv)
 Driver code for 2D Poisson problem. More...
 

Variables

double TanhSolnForPoisson::TanPhi =0.0
 Parameter for angle Phi of "step". More...
 

Function Documentation

◆ main()

int main ( int argc  ,
char **  argv 
)

Driver code for 2D Poisson problem.

314 {
315  // Set the orientation of the "step" to 45 degrees
317 
318  // Initial value for the steepness of the "step"
320 
321  // Create the problem with 2D nine-node elements from the
322  // QPoissonElement family. Pass pointer to source function.
325 
326  DocInfo doc_info;
327  doc_info.set_directory("RESLT");
328 
329  // File to report the number of Newton iterations
330  ofstream conv_file;
331  char filename[100];
332  sprintf(filename,"%s/conv.dat",doc_info.directory().c_str());
333  conv_file.open(filename);
334 
335  // Test the Hypre linear solvers
336  cout << "=====================" << endl;
337  cout << "Testing Hypre solvers" << endl;
338  cout << "=====================" << endl;
339 
340  // Create a new Hypre linear solver
341  HypreSolver* hypre_linear_solver_pt = new HypreSolver;
342 
343  // Set the linear solver for problem
344  problem.linear_solver_pt() = hypre_linear_solver_pt;
345 
346  // Set some solver parameters
347  hypre_linear_solver_pt->max_iter() = 100;
348  hypre_linear_solver_pt->tolerance() = 1e-10;
349  hypre_linear_solver_pt->amg_simple_smoother() = 1;
350  hypre_linear_solver_pt->disable_doc_time();
351  hypre_linear_solver_pt->enable_hypre_error_messages();
352  hypre_linear_solver_pt->amg_print_level() = 0;
353  hypre_linear_solver_pt->krylov_print_level() = 0;
354 
355  // Loop over hypre solvers
356  //------------------------
357  for (unsigned s=0; s<=3; s++)
358  {
359  // Select the actual iterative linear solver
360  switch(s)
361  {
362  case 0:
363  hypre_linear_solver_pt->hypre_method() = HypreSolver::BoomerAMG;
364  break;
365  case 1:
366  hypre_linear_solver_pt->hypre_method() = HypreSolver::CG;
367  break;
368  case 2:
369  hypre_linear_solver_pt->hypre_method() = HypreSolver::GMRES;
370  break;
371  case 3:
372  hypre_linear_solver_pt->hypre_method() = HypreSolver::BiCGStab;
373  break;
374  default: cout << "Error selecting solver" << endl;
375  }
376 
377 
378  // Loop over preconditioners (except for AMG solver which is not
379  // preconditioned)
380  unsigned tests;
381  if (s==0)
382  {
383  tests = 1;
384  }
385  else
386  {
387  tests = 4;
388  }
389 
390  for (unsigned p=0; p<tests; p++)
391  {
392  // set the preconditioner
393  switch(p)
394  {
395  case 0:
396  hypre_linear_solver_pt->internal_preconditioner()=HypreSolver::None;
397  break;
398  case 1:
399  hypre_linear_solver_pt->internal_preconditioner()=HypreSolver::BoomerAMG;
400  break;
401  case 2:
402  hypre_linear_solver_pt->internal_preconditioner()=HypreSolver::Euclid;
403  break;
404  case 3:
405  hypre_linear_solver_pt->internal_preconditioner()=HypreSolver::ParaSails;
406  break;
407  default: cout << "Error selecting preconditioner" << endl;
408  }
409 
410  // Solve the problem
411  problem.newton_solve();
412 
413  // Doc
414  problem.doc_solution(doc_info);
415  doc_info.number()++;
416  oomph_info << "Number of Newton iterations: " << problem.newton_count()
417  << std::endl << std::endl;
418  conv_file << problem.newton_count() << std::endl;
419 
420  } // end of loop over preconditioner
421  } // end of loop over solvers
422 
423  // delete the Hypre solver
424  delete hypre_linear_solver_pt;
425 
426 
427 
428 
429  // Test the oomph-lib iterative linear solvers with the hypre preconditioners
430  //---------------------------------------------------------------------------
431 
432  cout
433  << "====================================================================="
434  << endl;
435  cout
436  << "Testing oomph-lib iterative linear solvers with Hypre preconditioners"
437  << endl;
438  cout
439  << "====================================================================="
440  << endl;
441 
442  // Create a new Hypre preconditioner
443  HyprePreconditioner* hypre_preconditioner_pt = new HyprePreconditioner;
444 
445  // Set preconditioner parameters
446  hypre_preconditioner_pt->enable_hypre_error_messages();
447 
448  // Test CG
449  //========
450 
451  cout << "CG iterative solver" << endl;
452  cout << "-------------------" << endl;
453 
454 
455  IterativeLinearSolver* oomph_linear_solver_pt = new CG<CRDoubleMatrix>;
456  problem.linear_solver_pt() = oomph_linear_solver_pt;
457  oomph_linear_solver_pt->tolerance()=1.0e-10;
458 
459 
460  // Run through the different hypre solver methods suitable for preconditioning
461  for (unsigned p=1; p<=3; p++)
462  {
463  unsigned prec_method=0;
464 
465  switch(p)
466  {
467  case 1:
468  prec_method = HyprePreconditioner::BoomerAMG;
469  break;
470 
471  case 2:
472  prec_method = HyprePreconditioner::Euclid;
473  break;
474 
475  case 3:
476  prec_method = HyprePreconditioner::ParaSails;
477  break;
478 
479  default: cout << "Error selecting preconditioner" << endl;
480  }
481 
482  // set the preconditioning method within the hypre solver
483  hypre_preconditioner_pt->hypre_method() = prec_method;
484 
485  // set the preconditioner in the iterative solver
486  oomph_linear_solver_pt->preconditioner_pt()=hypre_preconditioner_pt;
487 
488  // Solve the problem
489  problem.newton_solve();
490 
491  // Doc
492  problem.doc_solution(doc_info);
493  doc_info.number()++;
494  oomph_info << "Number of Newton iterations: " << problem.newton_count()
495  << std::endl << std::endl;
496  conv_file << problem.newton_count() << std::endl;
497  }
498  delete oomph_linear_solver_pt;
499 
500 
501  // Test BiCGStab
502  //==============
503 
504  cout << "BiCGStab iterative solver" << endl;
505  cout << "-------------------------" << endl;
506 
507  // Build and instance of BiCGStab and pass it to the problem
508  oomph_linear_solver_pt = new BiCGStab<CRDoubleMatrix>;
509 
510  problem.linear_solver_pt() = oomph_linear_solver_pt;
511 
512  oomph_linear_solver_pt->tolerance()=1.0e-10;
513 
514 
515  // Run through the different hypre methods suitable for preconditioning
516  for (unsigned p=1; p<=3; p++)
517  {
518  // set the preconditioning method
519  switch(p)
520  {
521  case 1:
522  hypre_preconditioner_pt->hypre_method() = HyprePreconditioner::BoomerAMG;
523  break;
524 
525  case 2:
526  hypre_preconditioner_pt->hypre_method() = HyprePreconditioner::Euclid;
527  break;
528 
529  case 3:
530  hypre_preconditioner_pt->hypre_method() = HyprePreconditioner::ParaSails;
531  break;
532 
533  default: cout << "Error selecting preconditioner" << endl;
534  }
535 
536 
537 
538  // set the preconditioner in the iterative solver
539  oomph_linear_solver_pt->preconditioner_pt()=hypre_preconditioner_pt;
540 
541  // Solve the problem
542  problem.newton_solve();
543 
544  // Doc
545  problem.doc_solution(doc_info);
546  doc_info.number()++;
547  oomph_info << "Number of Newton iterations: " << problem.newton_count()
548  << std::endl << std::endl;
549  conv_file << problem.newton_count() << std::endl;
550 
551  }
552  delete oomph_linear_solver_pt;
553 
554 
555  // Test GMRES
556  //===========
557 
558  cout << "GMRES iterative solver" << endl;
559  cout << "----------------------" << endl;
560  oomph_linear_solver_pt = new GMRES<CRDoubleMatrix>;
561  oomph_linear_solver_pt->tolerance()=1.0e-10;
562  problem.linear_solver_pt() = oomph_linear_solver_pt;
563 
564 
565  // run through the different hypre solver methods suitable for preconditioning
566  for (unsigned p=1; p<=3; p++)
567  {
568  unsigned prec_method=0;
569 
570 
571  switch(p)
572  {
573  case 1:
574  prec_method = HyprePreconditioner::BoomerAMG;
575  break;
576 
577  case 2:
578  prec_method = HyprePreconditioner::Euclid;
579  break;
580 
581  case 3:
582  prec_method = HyprePreconditioner::ParaSails;
583  break;
584 
585  default: cout << "Error selecting preconditioner" << endl;
586  }
587 
588  // set the preconditioning method within the hypre solver
589  hypre_preconditioner_pt->hypre_method() = prec_method;
590 
591  // set the preconditioner in the iterative solver
592  oomph_linear_solver_pt->preconditioner_pt() = hypre_preconditioner_pt;
593 
594  // Solve the problem
595  problem.newton_solve();
596 
597  // Doc
598  problem.doc_solution(doc_info);
599  doc_info.number()++;
600  oomph_info << "Number of Newton iterations: " << problem.newton_count()
601  << std::endl << std::endl;
602  conv_file << problem.newton_count() << std::endl;
603  }
604  delete oomph_linear_solver_pt;
605  delete hypre_preconditioner_pt;
606 
607  conv_file.close();
608 
609 } //end of main
Array< double, 1, 3 > e(1./3., 0.5, 2.)
float * p
Definition: Tutorial_Map_using.cpp:9
Micky mouse Poisson problem.
Definition: HypreSolver_test.cc:81
The conjugate gradient method.
Definition: iterative_linear_solver.h:410
The conjugate gradient method.
Definition: iterative_linear_solver.h:284
Definition: oomph_utilities.h:499
std::string directory() const
Output directory.
Definition: oomph_utilities.h:524
void set_directory(const std::string &directory)
Definition: oomph_utilities.cc:298
unsigned & number()
Number used (e.g.) for labeling output files.
Definition: oomph_utilities.h:554
The GMRES method.
Definition: iterative_linear_solver.h:1227
void enable_hypre_error_messages()
Turn on the hypre error messages.
Definition: hypre_solver.h:242
Definition: hypre_solver.h:826
unsigned & hypre_method()
Access function to Hypre_method flag – specified via enumeration.
Definition: hypre_solver.h:945
Definition: hypre_solver.h:514
unsigned & amg_simple_smoother()
Access function to AMG_simple_smoother flag.
Definition: hypre_solver.h:583
unsigned & max_iter()
Access function to Max_iter.
Definition: hypre_solver.h:551
unsigned & hypre_method()
Access function to Hypre_method flag – specified via enumeration.
Definition: hypre_solver.h:563
unsigned & amg_print_level()
Access function to AMG_print_level.
Definition: hypre_solver.h:602
unsigned & krylov_print_level()
Access function to Krylov_print_level.
Definition: hypre_solver.h:737
double & tolerance()
Access function to Tolerance.
Definition: hypre_solver.h:557
unsigned & internal_preconditioner()
Definition: hypre_solver.h:570
Definition: iterative_linear_solver.h:54
Preconditioner *& preconditioner_pt()
Access function to preconditioner.
Definition: iterative_linear_solver.h:95
double & tolerance()
Access to convergence tolerance.
Definition: iterative_linear_solver.h:107
void disable_doc_time()
Disable documentation of solve times.
Definition: linear_solver.h:116
RealScalar s
Definition: level1_cplx_impl.h:130
string filename
Definition: MergeRestartFiles.py:39
double TanPhi
Parameter for angle Phi of "step".
Definition: HypreSolver_test.cc:51
void source_function(const Vector< double > &x, double &source)
Source function required to make the solution above an exact solution.
Definition: HypreSolver_test.cc:60
double Alpha
Parameter for steepness of step.
Definition: extrude_with_macro_element_representation.cc:185
OomphInfo oomph_info
Definition: oomph_definitions.cc:319
Constructor for SteadyAxisymAdvectionDiffusion problem
Definition: steady_axisym_advection_diffusion.cc:213

References TanhSolnForPoisson::Alpha, oomph::HypreSolver::amg_print_level(), oomph::HypreSolver::amg_simple_smoother(), oomph::DocInfo::directory(), oomph::LinearSolver::disable_doc_time(), e(), oomph::HypreInterface::enable_hypre_error_messages(), MergeRestartFiles::filename, oomph::HypreSolver::hypre_method(), oomph::HyprePreconditioner::hypre_method(), oomph::HypreSolver::internal_preconditioner(), oomph::HypreSolver::krylov_print_level(), oomph::HypreSolver::max_iter(), oomph::DocInfo::number(), oomph::oomph_info, p, oomph::IterativeLinearSolver::preconditioner_pt(), problem, s, oomph::DocInfo::set_directory(), TanhSolnForPoisson::source_function(), TanhSolnForPoisson::TanPhi, oomph::HypreSolver::tolerance(), and oomph::IterativeLinearSolver::tolerance().