two_d_biharmonic.cc File Reference
#include "math.h"
#include "generic.h"
#include "biharmonic.h"

Classes

class  BiharmonicTestProblem1
 
class  BiharmonicTestProblem2
 

Namespaces

 RayParam
 
 BiharmonicTestFunctions1
 
 BiharmonicTestFunctions2
 

Functions

void BiharmonicTestFunctions1::u_NE (const double &s, double &u)
 
void BiharmonicTestFunctions1::dudn_NE (const double &s, double &dudn)
 
void BiharmonicTestFunctions1::u_SW (const double &s, double &u)
 
void BiharmonicTestFunctions1::dudn_SW (const double &s, double &dudn)
 
void BiharmonicTestFunctions1::surface_load (const Vector< double > &x, double &f)
 
void BiharmonicTestFunctions1::flux1_NE (const double &s, double &flux1)
 
void BiharmonicTestFunctions1::flux0_NE (const double &s, double &flux0)
 
void BiharmonicTestFunctions1::solution (const Vector< double > &x, Vector< double > &u)
 
void BiharmonicTestFunctions2::boundary_N (const double &s, Vector< double > &r)
 
void BiharmonicTestFunctions2::boundary_E (const double &s, Vector< double > &r)
 
void BiharmonicTestFunctions2::boundary_S (const double &s, Vector< double > &r)
 
void BiharmonicTestFunctions2::boundary_W (const double &s, Vector< double > &r)
 
void BiharmonicTestFunctions2::normal_N (const double &s, Vector< double > &n)
 
void BiharmonicTestFunctions2::normal_E (const double &s, Vector< double > &n)
 
void BiharmonicTestFunctions2::normal_S (const double &s, Vector< double > &n)
 
void BiharmonicTestFunctions2::normal_W (const double &s, Vector< double > &n)
 
void BiharmonicTestFunctions2::u_N (const double &s, double &u)
 
void BiharmonicTestFunctions2::u_E (const double &s, double &u)
 
void BiharmonicTestFunctions2::u_S (const double &s, double &u)
 
void BiharmonicTestFunctions2::u_W (const double &s, double &u)
 
double BiharmonicTestFunctions2::dudx_0 (const Vector< double > x)
 
double BiharmonicTestFunctions2::dudx_1 (const Vector< double > x)
 
void BiharmonicTestFunctions2::dudn_N (const double &s, double &dudn)
 
void BiharmonicTestFunctions2::dudn_E (const double &s, double &dudn)
 
void BiharmonicTestFunctions2::dudn_S (const double &s, double &dudn)
 
void BiharmonicTestFunctions2::dudn_W (const double &s, double &dudn)
 
void BiharmonicTestFunctions2::surface_load (const Vector< double > &x, double &f)
 
void BiharmonicTestFunctions2::solution (const Vector< double > &x, Vector< double > &u)
 
void print_elemental_jacobian (const unsigned &element_number, const Problem *const problem_pt)
 
void print_connectivity_matrix (const Problem *const problem_pt)
 
int main (int argc, char *argv[])
 main More...
 

Variables

bool RayParam::Unclamp_right_bound = false
 
unsigned RayParam::Noel = 0
 
int RayParam::X_min = 0
 
int RayParam::X_max = 0
 
int RayParam::Y_min = 0
 
int RayParam::Y_max = 0
 
bool RayParam::Print_connectivity_mat = false
 
bool RayParam::Print_natural_jacobian = false
 
bool RayParam::Print_subblocks = false
 
bool RayParam::Print_elemental_jacobian = false
 
std::string RayParam::Matbase_str = ""
 
std::string RayParam::Connectivity_dir = ""
 
std::string RayParam::Natural_jac_dir = ""
 
std::string RayParam::Blocked_dir = ""
 
std::string RayParam::Elemental_dir = ""
 
double BiharmonicTestFunctions2::Pi = MathematicalConstants::Pi
 
double BiharmonicTestFunctions2::theta = Pi/4
 
double BiharmonicTestFunctions2::r_min = sqrt(1*Pi)
 
double BiharmonicTestFunctions2::r_max = sqrt(3*Pi)
 

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)

main

557 {
558  // number of element
559  unsigned n_element = 20;
560 
561  // Set up doc info
562  DocInfo doc_info;
563  doc_info.set_directory("RESLT");
564  doc_info.number()=0;
565 
566 
567  // Store commandline arguments
568  CommandLineArgs::setup(argc,argv);
569 
570  CommandLineArgs::specify_command_line_flag("--unclamp_right_bound");
571 
572  // Need to make a string to reflect the type of problem
574  &RayParam::Noel);
576  &RayParam::X_min);
578  &RayParam::X_max);
580  &RayParam::Y_min);
582  &RayParam::Y_max);
583 
584  CommandLineArgs::specify_command_line_flag("--connectivity_mat",
586  CommandLineArgs::specify_command_line_flag("--natural_jacobian",
590  CommandLineArgs::specify_command_line_flag("--elemental_jacobian",
592 
593  // Parse the above flags.
596 
597 
598 
599  // If there is more than one argument, we Milan's tests.
600  if(argc > 1)
601  {
602 
604  "--unclamp_right_bound"))
605  {
607  RayParam::Matbase_str = "twod_bihar_right_bound_neumann";
608  }
609  else
610  {
612  RayParam::Matbase_str = "twod_bihar_clamp_all_bound";
613  }
614 
616  {
617  std::ostringstream err_stream;
618  err_stream << "Please set --noel." << std::endl;
619  throw OomphLibError(err_stream.str(),
622  }
623  else
624  {
625  std::ostringstream str_ss;
626  str_ss << RayParam::Matbase_str << "_Noel" << RayParam::Noel;
627  RayParam::Matbase_str = str_ss.str();
628  }
629 
631  {
632  std::ostringstream err_stream;
633  err_stream << "Please set --xmin." << std::endl;
634  throw OomphLibError(err_stream.str(),
637  }
639  {
640  std::ostringstream err_stream;
641  err_stream << "Please set --xmax." << std::endl;
642  throw OomphLibError(err_stream.str(),
645  }
647  {
648  std::ostringstream err_stream;
649  err_stream << "Please set --ymin." << std::endl;
650  throw OomphLibError(err_stream.str(),
653  }
655  {
656  std::ostringstream err_stream;
657  err_stream << "Please set --ymax." << std::endl;
658  throw OomphLibError(err_stream.str(),
661  }
662 
663  if(CommandLineArgs::command_line_flag_has_been_set("--connectivity_mat"))
664  {
666  }
667  else
668  {
670  }
671 
672  if(CommandLineArgs::command_line_flag_has_been_set("--natural_jacobian"))
673  {
675  }
676  else
677  {
679  }
680 
682  {
684  }
685  else
686  {
688  }
689 
690  if(CommandLineArgs::command_line_flag_has_been_set("--elemental_jacobian"))
691  {
693  }
694  else
695  {
697  }
698 
699 
700 
701  oomph_info << "n_element: " << RayParam::Noel << std::endl;
702  oomph_info << "x_min: " << RayParam::X_min << std::endl;
703  oomph_info << "x_max: " << RayParam::X_max << std::endl;
704  oomph_info << "y_min: " << RayParam::Y_min << std::endl;
705  oomph_info << "y_max: " << RayParam::Y_max << std::endl;
706 
712 
713  BiharmonicPreconditioner my_prec;
714  my_prec.bulk_element_mesh_pt() = problem.bulk_element_mesh_pt();
715  my_prec.preconditioner_type() = 0;
716 
717  IterativeLinearSolver* solver_pt = new CG<CRDoubleMatrix>;
718  solver_pt->preconditioner_pt() = &my_prec;
719 
720  // Apply the solver
721  problem.linear_solver_pt() = solver_pt;
722 
724  {
725  std::ostringstream dump_stream;
726  dump_stream << RayParam::Natural_jac_dir
727  << "/"
729  std::string dump_str = dump_stream.str();
730  problem.dump_jacobian(dump_str);
731  }
732 
734  {
736  }
737 
738 // if(RayParam::Print_elemental_jacobian)
739 // {
740 // //print_elemental_jacobian(&problem);
741 // }
742 
744  {
745  std::ostringstream dump_stream;
746  dump_stream << RayParam::Blocked_dir
747  << "/"
749  std::string dump_str = dump_stream.str();
750 
751 // my_prec.print_subblocks(dump_str);
752 
753  std::ostringstream dump_ss;
754  dump_ss << RayParam::Natural_jac_dir
755  << "/"
757  std::string another_dump_str = dump_ss.str();
758 
759 // my_prec.set_fullblock_dir(another_dump_str);
760 
761  problem.newton_solve();
762 
763  }
764  }
765  else
766  {
767  // Biharmonic Problem 1 (square)
768  // Exact Biharmonic Preconditioner
769  {
770  oomph_info
771  << "/////////////////////////////////////////////////////////////////////"
772  << std::endl;
773  oomph_info << "TESTING: Square 2D Biharmonic Problem w/ "
774  << "Exact Preconditioning"
775  << std::endl;
776  oomph_info
777  << "/////////////////////////////////////////////////////////////////////"
778  << std::endl;
779 
780  // create the problem
781  BiharmonicTestProblem1 problem(n_element);
782 
783  // setup the preconditioner
785  prec_pt->bulk_element_mesh_pt() = problem.bulk_element_mesh_pt();
786  prec_pt->preconditioner_type() = 0;
787 
788  // setup the solver
789  IterativeLinearSolver* solver_pt = new CG<CRDoubleMatrix>;
790  solver_pt->preconditioner_pt() = prec_pt;
791 
792  // apply the solver
793  problem.linear_solver_pt() = solver_pt;
794  problem.newton_solve();
795 
796  // ouput the solution
797  problem.doc_solution(doc_info,BiharmonicTestFunctions1::solution);
798  doc_info.number()++;
799 
800  // clean up
801  delete solver_pt;
802  delete prec_pt;
803  }
804 
805  // Biharmonic Problem 2 (section of annulus)
806  // Inexact Biharmonic Preconditioner w/ SuperLU
807  {
808  oomph_info
809  << "/////////////////////////////////////////////////////////////////////"
810  << std::endl;
811  oomph_info << "TESTING: Curved 2D Biharmonic Problem w/ "
812  << "Inexact Preconditioning"
813  << std::endl;
814  oomph_info
815  << "/////////////////////////////////////////////////////////////////////"
816  << std::endl;
817 
818  // create the problem
819  BiharmonicTestProblem2 problem(n_element);
820 
821  // setup the preconditioner
823  prec_pt->bulk_element_mesh_pt() = problem.bulk_element_mesh_pt();
824  prec_pt->preconditioner_type() = 1;
825 
826  // setup the solver
827  IterativeLinearSolver* solver_pt = new CG<CRDoubleMatrix>;
828  solver_pt->preconditioner_pt() = prec_pt;
829 
830  // apply the solver
831  problem.linear_solver_pt() = solver_pt;
832  problem.newton_solve();
833 
834  // ouput the solution
835  problem.doc_solution(doc_info,BiharmonicTestFunctions2::solution);
836  doc_info.number()++;
837 
838  // clean up
839  delete solver_pt;
840  delete prec_pt;
841  }
842  }
843 }
Definition: two_d_biharmonic.cc:126
Definition: two_d_biharmonic.cc:383
Biharmonic Preconditioner - for two dimensional problems.
Definition: biharmonic_preconditioner.h:88
unsigned & preconditioner_type()
Definition: biharmonic_preconditioner.h:143
Mesh *& bulk_element_mesh_pt()
Definition: biharmonic_preconditioner.h:151
The conjugate gradient method.
Definition: iterative_linear_solver.h:284
Definition: oomph_utilities.h:499
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
Definition: iterative_linear_solver.h:54
Preconditioner *& preconditioner_pt()
Access function to preconditioner.
Definition: iterative_linear_solver.h:95
Definition: oomph_definitions.h:222
void solution(const Vector< double > &x, Vector< double > &u)
Definition: two_d_biharmonic.cc:113
void solution(const Vector< double > &x, Vector< double > &u)
Definition: two_d_biharmonic.cc:370
void setup(Time *time_pt)
Create all GeomObjects needed to define the cylinder and the flag.
Definition: turek_flag_non_fsi.cc:277
bool Print_connectivity_mat
Definition: two_d_biharmonic.cc:46
std::string Natural_jac_dir
Definition: two_d_biharmonic.cc:54
bool Print_elemental_jacobian
Definition: two_d_biharmonic.cc:49
std::string Connectivity_dir
Definition: two_d_biharmonic.cc:53
std::string Elemental_dir
Definition: two_d_biharmonic.cc:56
int X_min
Definition: two_d_biharmonic.cc:41
bool Print_natural_jacobian
Definition: two_d_biharmonic.cc:47
std::string Blocked_dir
Definition: two_d_biharmonic.cc:55
bool Unclamp_right_bound
Definition: two_d_biharmonic.cc:39
bool Print_subblocks
Definition: two_d_biharmonic.cc:48
std::string Matbase_str
Definition: two_d_biharmonic.cc:51
int X_max
Definition: two_d_biharmonic.cc:42
unsigned Noel
Definition: two_d_biharmonic.cc:40
int Y_max
Definition: two_d_biharmonic.cc:44
int Y_min
Definition: two_d_biharmonic.cc:43
bool command_line_flag_has_been_set(const std::string &flag)
Definition: oomph_utilities.cc:501
void specify_command_line_flag(const std::string &command_line_flag, const std::string &doc)
Specify possible argument-free command line flag.
Definition: oomph_utilities.cc:451
void parse_and_assign(int argc, char *argv[], const bool &throw_on_unrecognised_args)
Definition: oomph_utilities.cc:760
void doc_specified_flags()
Document specified command line flags.
Definition: oomph_utilities.cc:610
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
OomphInfo oomph_info
Definition: oomph_definitions.cc:319
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86
Constructor for SteadyAxisymAdvectionDiffusion problem
Definition: steady_axisym_advection_diffusion.cc:213
void print_connectivity_matrix(const Problem *const problem_pt)
Definition: two_d_biharmonic.cc:495

References RayParam::Blocked_dir, oomph::BiharmonicPreconditioner::bulk_element_mesh_pt(), oomph::CommandLineArgs::command_line_flag_has_been_set(), RayParam::Connectivity_dir, oomph::CommandLineArgs::doc_specified_flags(), RayParam::Elemental_dir, RayParam::Matbase_str, RayParam::Natural_jac_dir, RayParam::Noel, oomph::DocInfo::number(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::oomph_info, oomph::CommandLineArgs::parse_and_assign(), oomph::IterativeLinearSolver::preconditioner_pt(), oomph::BiharmonicPreconditioner::preconditioner_type(), RayParam::Print_connectivity_mat, print_connectivity_matrix(), RayParam::Print_elemental_jacobian, RayParam::Print_natural_jacobian, RayParam::Print_subblocks, problem, oomph::DocInfo::set_directory(), oomph::CommandLineArgs::setup(), BiharmonicTestFunctions1::solution(), BiharmonicTestFunctions2::solution(), oomph::CommandLineArgs::specify_command_line_flag(), oomph::Global_string_for_annotation::string(), RayParam::Unclamp_right_bound, RayParam::X_max, RayParam::X_min, RayParam::Y_max, and RayParam::Y_min.

◆ print_connectivity_matrix()

void print_connectivity_matrix ( const Problem *const  problem_pt)
496 {
497  const Mesh* const mesh_pt = problem_pt->mesh_pt();
498 
499  const unsigned n_element = mesh_pt->nelement();
500 // const unsigned n_ele_1d = sqrt(n_element);
501 
502  // Set up out file
503  std::ostringstream filenamestream;
504  filenamestream << RayParam::Connectivity_dir
505  << "/"
507 
508 
509  std::ofstream outfile;
510  outfile.open(filenamestream.str().c_str());
511 
512  // Loop through the number of elements
513  for (unsigned ele_i = 0; ele_i < n_element; ele_i++)
514  {
515  outfile << "Element number: " << ele_i << std::endl;
516 
517  // Get pointer to the element
518  FiniteElement* elem_pt
519  = mesh_pt->finite_element_pt(ele_i);
520 
521  unsigned nnod=elem_pt->nnode();
522 
523  for (unsigned nod_i = 0; nod_i < nnod; nod_i++)
524  {
525  outfile << "Node number: " << nod_i << std::endl;
526 
527  // Get the node
528  Node* nod_pt = elem_pt->node_pt(nod_i);
529  const unsigned nval = nod_pt->nvalue();
530 
531  outfile << "x: " << nod_pt->x(0)
532  << ", y: " << nod_pt->x(1)
533  << std::endl;
534 
535  for (unsigned val_i = 0; val_i < nval; val_i++)
536  {
537  outfile << val_i << " ";
538  long eqn_num = nod_pt->eqn_number(val_i);
539  outfile << eqn_num << " ";
540  if(!nod_pt->is_pinned(val_i))
541  {
542  outfile << elem_pt->local_eqn_number(eqn_num) << " ";
543  }
544 
545  outfile << "\n";
546  } // for values in node
547  } // for node
548  } // for elements
549  outfile.close();
550 }
long & eqn_number(const unsigned &i)
Return the equation number of the i-th stored variable.
Definition: nodes.h:367
unsigned nvalue() const
Return number of values stored in data object (incl pinned ones).
Definition: nodes.h:483
bool is_pinned(const unsigned &i) const
Test whether the i-th variable is pinned (1: true; 0: false).
Definition: nodes.h:417
Definition: elements.h:1313
Node *& node_pt(const unsigned &n)
Return a pointer to the local node n.
Definition: elements.h:2175
unsigned nnode() const
Return the number of nodes.
Definition: elements.h:2210
int local_eqn_number(const unsigned long &ieqn_global) const
Definition: elements.h:726
Definition: mesh.h:67
FiniteElement * finite_element_pt(const unsigned &e) const
Definition: mesh.h:473
unsigned long nelement() const
Return number of elements in the mesh.
Definition: mesh.h:590
Definition: nodes.h:906
double & x(const unsigned &i)
Return the i-th nodal coordinate.
Definition: nodes.h:1060
Mesh *& mesh_pt()
Return a pointer to the global mesh.
Definition: problem.h:1280

References RayParam::Connectivity_dir, oomph::Data::eqn_number(), oomph::Mesh::finite_element_pt(), oomph::Data::is_pinned(), oomph::GeneralisedElement::local_eqn_number(), RayParam::Matbase_str, oomph::Problem::mesh_pt(), oomph::Mesh::nelement(), oomph::FiniteElement::nnode(), oomph::FiniteElement::node_pt(), oomph::Data::nvalue(), and oomph::Node::x().

Referenced by main().

◆ print_elemental_jacobian()

void print_elemental_jacobian ( const unsigned element_number,
const Problem *const  problem_pt 
)
432 {
433  AssemblyHandler* const assembly_handler_pt
434  = problem_pt->assembly_handler_pt();
435 
436  const Mesh* const mesh_pt = problem_pt->mesh_pt();
437 
438  const unsigned n_element = mesh_pt->nelement();
439  const unsigned n_ele_1d = sqrt(n_element);
440 
441  oomph_info << "Elements: 1D: " << n_ele_1d
442  << ", total: " << n_element << std::endl;
443 
444 #ifdef PARANOID
445  if(element_number >= n_element)
446  {
447  std::ostringstream err_stream;
448  err_stream << "Supplied element number: " << element_number << ",\n"
449  << "But number of elements is: " << n_element << std::endl;
450  throw OomphLibError(err_stream.str(),
453  }
454 #endif
455 
456  // Get pointer to the element
457  GeneralisedElement* elem_pt
458  = mesh_pt->element_pt(element_number);
459 
460  // Find number of dofs in the element
461  const unsigned n_element_dofs = assembly_handler_pt->ndof(elem_pt);
462 
463  // Set up an array
464  Vector<double> element_residuals(n_element_dofs);
465 
466  // Set up a matrix
467  DenseMatrix<double> element_jacobian(n_element_dofs);
468 
469  // Fill the array
470  assembly_handler_pt->get_jacobian(elem_pt,
471  element_residuals,
472  element_jacobian);
473 
474  std::ostringstream ele_stream;
475  ele_stream << "N"<< n_ele_1d << "_ele_" << element_number;
476  element_jacobian.sparse_indexed_output(ele_stream.str(),15,true);
477 
478  // // Output the coordinates just to make sure...
479  // FiniteElement* finite_element_pt
480  // = mesh_pt->finite_element_pt(element_number);
481  //
482  // const unsigned n_node = finite_element_pt->nnode();
483  //
484  // // Loop over nodes and output coordinates
485  // for (unsigned n = 0; n < n_node; n++)
486  // {
487  // Node* nod_pt = finite_element_pt->node_pt(n);
488  // const double x = nod_pt->x(0);
489  // const double y = nod_pt->x(1);
490  // oomph_info << "Node: " << n << ", " << x << ", " << y << std::endl;
491  // }
492 }
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
Definition: assembly_handler.h:63
virtual unsigned ndof(GeneralisedElement *const &elem_pt)
Return the number of degrees of freedom in the element elem_pt.
Definition: assembly_handler.cc:42
virtual void get_jacobian(GeneralisedElement *const &elem_pt, Vector< double > &residuals, DenseMatrix< double > &jacobian)
Definition: assembly_handler.cc:102
Definition: elements.h:73
GeneralisedElement *& element_pt(const unsigned long &e)
Return pointer to element e.
Definition: mesh.h:448
AssemblyHandler *& assembly_handler_pt()
Return a pointer to the assembly handler object.
Definition: problem.h:1570

References oomph::Problem::assembly_handler_pt(), oomph::Mesh::element_pt(), oomph::AssemblyHandler::get_jacobian(), oomph::Problem::mesh_pt(), oomph::AssemblyHandler::ndof(), oomph::Mesh::nelement(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::oomph_info, oomph::Matrix< T, MATRIX_TYPE >::sparse_indexed_output(), and sqrt().