39 #include "meshes/triangle_mesh.h"    42 using namespace oomph;
    61   u[0]=tanh(1.0-Alpha*(TanPhi*x[0]-x[1]));
    67   source = 2.0*tanh(-1.0+Alpha*(TanPhi*x[0]-x[1]))*
    68    (1.0-pow(tanh(-1.0+Alpha*(TanPhi*x[0]-x[1])),2.0))*
    69    Alpha*Alpha*TanPhi*TanPhi+2.0*tanh(-1.0+Alpha*(TanPhi*x[0]-x[1]))*
    70    (1.0-pow(tanh(-1.0+Alpha*(TanPhi*x[0]-x[1])),2.0))*Alpha*Alpha;
    76  void zero(
const Vector<double>& x, Vector<double>& u)
    93 template<
class ELEMENT>
   114    complete_problem_setup();
   123    apply_boundary_conditions();
   127  void doc_solution(
const std::string& comment=
"");
   136  void apply_boundary_conditions();
   140  void complete_problem_setup();
   157 template<
class ELEMENT>
   161  Vector<double> zeta(1);
   164  Vector<double> posn(2);
   167  double x_center = 0.0;
   168  double y_center = 0.0;
   171  Ellipse * outer_boundary_ellipse_pt = 
new Ellipse(A,B);
   174  TriangleMeshClosedCurve* closed_curve_pt=0;
   178  bool polygon_for_outer_boundary=
false;
   180  polygon_for_outer_boundary=
true;
   182  if (polygon_for_outer_boundary)
   186    double unit_zeta = 0.5*MathematicalConstants::Pi/double(n_seg);
   190    Vector<TriangleMeshCurveSection*> boundary_polyline_pt(2);
   193    Vector<Vector<double> > bound_coords(n_seg+1);
   197    for(
unsigned ipoint=0; ipoint<n_seg+1;ipoint++)
   200      bound_coords[ipoint].resize(2);
   203      zeta[0]=unit_zeta*double(ipoint);
   204      outer_boundary_ellipse_pt->position(zeta,posn);
   205      bound_coords[ipoint][0]=posn[0]+x_center;
   206      bound_coords[ipoint][1]=posn[1]+y_center;
   210    unsigned boundary_id=0;
   211    boundary_polyline_pt[0]=
new TriangleMeshPolyLine(bound_coords,boundary_id);
   216    for(
unsigned ipoint=0; ipoint<n_seg+1;ipoint++)
   219      bound_coords[ipoint].resize(2);
   222      zeta[0]=(unit_zeta*double(ipoint))+0.5*MathematicalConstants::Pi;
   223      outer_boundary_ellipse_pt->position(zeta,posn);
   224      bound_coords[ipoint][0]=posn[0]+x_center;
   225      bound_coords[ipoint][1]=posn[1]+y_center;
   230    boundary_polyline_pt[1]=
new TriangleMeshPolyLine(bound_coords,boundary_id);
   235    TriangleMeshPolygon *outer_polygon =
   236     new TriangleMeshPolygon(boundary_polyline_pt);
   240     enable_redistribution_of_segments_between_polylines();
   243    closed_curve_pt = outer_polygon;
   252    Vector<TriangleMeshCurveSection*> outer_curvilinear_boundary_pt(2);
   256    double zeta_start=0.0;
   257    double zeta_end=MathematicalConstants::Pi;
   259    unsigned boundary_id=0;
   260    outer_curvilinear_boundary_pt[0]=
new TriangleMeshCurviLine(
   261     outer_boundary_ellipse_pt,zeta_start,zeta_end,nsegment,boundary_id);
   265    zeta_start=MathematicalConstants::Pi;
   266    zeta_end=2.0*MathematicalConstants::Pi;
   269    outer_curvilinear_boundary_pt[1]=
new TriangleMeshCurviLine(
   270     outer_boundary_ellipse_pt,zeta_start,zeta_end,nsegment,boundary_id);
   277      new TriangleMeshClosedCurve(outer_curvilinear_boundary_pt);
   284  Vector<TriangleMeshClosedCurve*> hole_pt(2);
   294  Ellipse* polygon_ellipse_pt=
new Ellipse(A,B);
   298  double unit_zeta = MathematicalConstants::Pi/double(n_seg);
   302  Vector<TriangleMeshCurveSection*> hole_polyline_pt(2);
   309  Vector<Vector<double> > bound_hole(n_seg+1);
   310  for(
unsigned ipoint=0; ipoint<n_seg+1;ipoint++)
   313    bound_hole[ipoint].resize(2);
   316    zeta[0]=unit_zeta*double(ipoint);
   317    polygon_ellipse_pt->position(zeta,posn);
   318    bound_hole[ipoint][0]=posn[0]+x_center;
   319    bound_hole[ipoint][1]=posn[1]+y_center;
   323  unsigned boundary_id=2;
   326  hole_polyline_pt[0] = 
new TriangleMeshPolyLine(bound_hole,boundary_id);
   331  for(
unsigned ipoint=0; ipoint<n_seg+1;ipoint++)
   334    bound_hole[ipoint].resize(2);
   337    zeta[0]=(unit_zeta*double(ipoint))+MathematicalConstants::Pi;
   338    polygon_ellipse_pt->position(zeta,posn);
   339    bound_hole[ipoint][0]=posn[0]+x_center;
   340    bound_hole[ipoint][1]=posn[1]+y_center;
   347  hole_polyline_pt[1] = 
new TriangleMeshPolyLine(bound_hole,boundary_id);
   354  Vector<double> hole_center(2);
   355  hole_center[0]=x_center;
   356  hole_center[1]=y_center;
   358  hole_pt[0] = 
new TriangleMeshPolygon(hole_polyline_pt, hole_center);
   367  Ellipse* ellipse_pt=
new Ellipse(A,B);
   370  Vector<TriangleMeshCurveSection*> curvilinear_boundary_pt(2);
   375  double zeta_start=0.0;
   376  double zeta_end=MathematicalConstants::Pi;
   377  unsigned nsegment=10;
   379  curvilinear_boundary_pt[0]=
new TriangleMeshCurviLine(
   380   ellipse_pt,zeta_start,zeta_end, 
   381   nsegment,boundary_id);
   385  zeta_start=MathematicalConstants::Pi;
   386  zeta_end=2.0*MathematicalConstants::Pi;
   389  curvilinear_boundary_pt[1]=
new TriangleMeshCurviLine(
   390   ellipse_pt,zeta_start,zeta_end, 
   391   nsegment,boundary_id);
   396  Vector<double> hole_coords(2);
   399  Vector<TriangleMeshClosedCurve*> curvilinear_hole_pt(1);
   401   new TriangleMeshClosedCurve(curvilinear_boundary_pt,
   416  TriangleMeshParameters triangle_mesh_parameters(closed_curve_pt);
   419  triangle_mesh_parameters.internal_closed_curve_pt() = hole_pt;
   422  double uniform_element_area=0.2;
   423  triangle_mesh_parameters.element_area() = uniform_element_area;
   427   RefineableTriangleMesh<ELEMENT>(triangle_mesh_parameters);
   430  Problem::mesh_pt()=My_mesh_pt;
   433  Z2ErrorEstimator* error_estimator_pt=
new Z2ErrorEstimator;
   434  My_mesh_pt->spatial_error_estimator_pt()=error_estimator_pt;
   437  My_mesh_pt->max_element_size()=0.2;
   438  My_mesh_pt->min_element_size()=0.002; 
   441  complete_problem_setup();
   445  sprintf(filename,
"RESLT/trace.dat");
   446  Trace_file.open(filename);
   449  oomph_info <<
"Number of equations: "    450             << this->assign_eqn_numbers() << std::endl;
   461 template<
class ELEMENT>
   468  unsigned nbound=My_mesh_pt->nboundary();
   469  for(
unsigned ibound=0;ibound<nbound;ibound++)
   471    unsigned num_nod=My_mesh_pt->nboundary_node(ibound);
   472    for (
unsigned inod=0;inod<num_nod;inod++)
   475      Node* nod_pt=My_mesh_pt->boundary_node_pt(ibound,inod);
   484  unsigned n_element = My_mesh_pt->nelement();
   485  for(
unsigned e=0;e<n_element;e++)
   488    ELEMENT* el_pt = 
dynamic_cast<ELEMENT*
>(My_mesh_pt->element_pt(e));
   496  apply_boundary_conditions();
   505 template<
class ELEMENT>
   510  unsigned nbound=this->My_mesh_pt->nboundary();
   511  for(
unsigned ibound=0;ibound<nbound;ibound++)
   513    unsigned num_nod=this->My_mesh_pt->nboundary_node(ibound);
   514    for (
unsigned inod=0;inod<num_nod;inod++)
   517      Node* nod_pt=this->My_mesh_pt->boundary_node_pt(ibound,inod);
   529      nod_pt->set_value(0,u[0]);
   539 template<
class ELEMENT>
   541                                                        std::string& comment)
   550  sprintf(filename,
"RESLT/soln%i.dat",Doc_info.number());
   551  some_file.open(filename);
   552  this->My_mesh_pt->output(some_file,npts); 
   553  some_file << 
"TEXT X = 22, Y = 92, CS=FRAME T = \""    554            << comment << 
"\"\n";
   559  sprintf(filename,
"RESLT/exact_soln%i.dat",Doc_info.number());
   560  some_file.open(filename);
   566  sprintf(filename,
"RESLT/boundaries%i.dat",Doc_info.number());
   567  some_file.open(filename);
   568  My_mesh_pt->output_boundaries(some_file);
   574  double error,norm,dummy_error,zero_norm;
   575  sprintf(filename,
"RESLT/error%i.dat",Doc_info.number());
   576  some_file.open(filename);
   581                            dummy_error,zero_norm); 
   585  oomph_info << 
"\nNorm of error   : " << sqrt(error) << std::endl; 
   586  oomph_info << 
"Norm of exact solution: " << sqrt(norm) << std::endl;
   587  oomph_info << 
"Norm of computed solution: " << sqrt(dummy_error) << std::endl;
   588  Trace_file << sqrt(norm) << 
" " << sqrt(dummy_error) << std::endl;
   599 int main(
int argc, 
char **argv)
   602  CommandLineArgs::setup(argc,argv);
   608  CommandLineArgs::specify_command_line_flag(
"--validation");
   611  CommandLineArgs::parse_and_assign(); 
   614  CommandLineArgs::doc_specified_flags();
   634  std::stringstream comment_stream;
   635  comment_stream << 
"Initial mesh ";
   642  if (CommandLineArgs::command_line_flag_has_been_set(
"--validation"))
   646  for (
unsigned i=0;i<nstep;i++)
   650    unsigned max_adapt=3;
   651    if (CommandLineArgs::command_line_flag_has_been_set(
"--validation"))
   655    problem.newton_solve(max_adapt);
   659    std::stringstream comment_stream;
   664    TanhSolnForPoisson::TanPhi+=0.5;
 UnstructuredPoissonProblem()
Constructor. 
 
int main(int argc, char **argv)
Driver code for demo of inline triangle mesh generation. 
 
ofstream Trace_file
Trace file to document norm of solution. 
 
DocInfo Doc_info
Doc info object for labeling output. 
 
void get_exact_u(const Vector< double > &x, Vector< double > &u)
Exact solution as a Vector. 
 
void actions_after_adapt()
Actions after adapt: Setup the problem again – remember that the mesh has been completely rebuilt an...
 
void zero(const Vector< double > &x, Vector< double > &u)
Zero function – used to compute norm of the computed solution by computing the norm of the error whe...
 
double Alpha
Parameter for steepness of "step". 
 
RefineableTriangleMesh< ELEMENT > * My_mesh_pt
Pointers to specific mesh. 
 
void actions_before_adapt()
Actions before adapt. Empty. 
 
void doc_solution(const std::string &comment="")
Doc the solution. 
 
void actions_after_newton_solve()
Update after solve (empty) 
 
double TanPhi
Parameter for angle Phi of "step". 
 
~UnstructuredPoissonProblem()
Destructor. 
 
void apply_boundary_conditions()
Helper function to apply boundary conditions. 
 
Namespace for exact solution for Poisson equation with "sharp step". 
 
void actions_before_newton_solve()
Update the problem specs before solve: Re-apply boundary conditons. 
 
void complete_problem_setup()
Helper function to (re-)set boundary condition and complete the build of all elements. 
 
void get_source(const Vector< double > &x, double &source)
Source function required to make the solution above an exact solution.