35 #include "meshes/triangle_mesh.h"
38 using namespace oomph;
72 void zero(
const Vector<double>& x, Vector<double>& u)
89 template<
class ELEMENT>
110 complete_problem_setup();
119 apply_boundary_conditions();
123 void doc_solution(
const std::string& comment=
"");
132 void apply_boundary_conditions();
136 void complete_problem_setup();
153 template<
class ELEMENT>
157 Vector<double> zeta(1);
160 Vector<double> posn(2);
163 double x_center = 0.0;
164 double y_center = 0.0;
167 Ellipse * outer_boundary_ellipse_pt =
new Ellipse(A,B);
170 TriangleMeshClosedCurve* closed_curve_pt=0;
174 bool polygon_for_outer_boundary=
false;
176 polygon_for_outer_boundary=
true;
178 if (polygon_for_outer_boundary)
182 double unit_zeta = 0.5*MathematicalConstants::Pi/double(n_seg);
186 Vector<TriangleMeshCurveSection*> boundary_polyline_pt(2);
189 Vector<Vector<double> > bound_coords(n_seg+1);
193 for(
unsigned ipoint=0; ipoint<n_seg+1;ipoint++)
196 bound_coords[ipoint].resize(2);
199 zeta[0]=unit_zeta*double(ipoint);
200 outer_boundary_ellipse_pt->position(zeta,posn);
201 bound_coords[ipoint][0]=posn[0]+x_center;
202 bound_coords[ipoint][1]=posn[1]+y_center;
206 unsigned boundary_id=0;
207 boundary_polyline_pt[0]=
new TriangleMeshPolyLine(bound_coords,boundary_id);
212 for(
unsigned ipoint=0; ipoint<n_seg+1;ipoint++)
215 bound_coords[ipoint].resize(2);
218 zeta[0]=(unit_zeta*double(ipoint))+0.5*MathematicalConstants::Pi;
219 outer_boundary_ellipse_pt->position(zeta,posn);
220 bound_coords[ipoint][0]=posn[0]+x_center;
221 bound_coords[ipoint][1]=posn[1]+y_center;
226 boundary_polyline_pt[1]=
new TriangleMeshPolyLine(bound_coords,boundary_id);
231 TriangleMeshPolygon *outer_polygon =
232 new TriangleMeshPolygon(boundary_polyline_pt);
236 enable_redistribution_of_segments_between_polylines();
239 closed_curve_pt = outer_polygon;
248 Vector<TriangleMeshCurveSection*> outer_curvilinear_boundary_pt(2);
252 double zeta_start=0.0;
253 double zeta_end=MathematicalConstants::Pi;
255 unsigned boundary_id=0;
256 outer_curvilinear_boundary_pt[0]=
new TriangleMeshCurviLine(
257 outer_boundary_ellipse_pt,zeta_start,zeta_end,nsegment,boundary_id);
261 zeta_start=MathematicalConstants::Pi;
262 zeta_end=2.0*MathematicalConstants::Pi;
265 outer_curvilinear_boundary_pt[1]=
new TriangleMeshCurviLine(
266 outer_boundary_ellipse_pt,zeta_start,zeta_end,nsegment,boundary_id);
273 new TriangleMeshClosedCurve(outer_curvilinear_boundary_pt);
280 Vector<TriangleMeshClosedCurve*> hole_pt(2);
290 Ellipse* polygon_ellipse_pt=
new Ellipse(A,B);
294 double unit_zeta = MathematicalConstants::Pi/double(n_seg);
298 Vector<TriangleMeshCurveSection*> hole_polyline_pt(2);
305 Vector<Vector<double> > bound_hole(n_seg+1);
306 for(
unsigned ipoint=0; ipoint<n_seg+1;ipoint++)
309 bound_hole[ipoint].resize(2);
312 zeta[0]=unit_zeta*double(ipoint);
313 polygon_ellipse_pt->position(zeta,posn);
314 bound_hole[ipoint][0]=posn[0]+x_center;
315 bound_hole[ipoint][1]=posn[1]+y_center;
319 unsigned boundary_id=2;
322 hole_polyline_pt[0] =
new TriangleMeshPolyLine(bound_hole,boundary_id);
327 for(
unsigned ipoint=0; ipoint<n_seg+1;ipoint++)
330 bound_hole[ipoint].resize(2);
333 zeta[0]=(unit_zeta*double(ipoint))+MathematicalConstants::Pi;
334 polygon_ellipse_pt->position(zeta,posn);
335 bound_hole[ipoint][0]=posn[0]+x_center;
336 bound_hole[ipoint][1]=posn[1]+y_center;
343 hole_polyline_pt[1] =
new TriangleMeshPolyLine(bound_hole,boundary_id);
350 Vector<double> hole_center(2);
351 hole_center[0]=x_center;
352 hole_center[1]=y_center;
354 hole_pt[0] =
new TriangleMeshPolygon(hole_polyline_pt, hole_center);
363 Ellipse* ellipse_pt=
new Ellipse(A,B);
366 Vector<TriangleMeshCurveSection*> curvilinear_boundary_pt(2);
371 double zeta_start=0.0;
372 double zeta_end=MathematicalConstants::Pi;
373 unsigned nsegment=10;
375 curvilinear_boundary_pt[0]=
new TriangleMeshCurviLine(
376 ellipse_pt,zeta_start,zeta_end,
377 nsegment,boundary_id);
381 zeta_start=MathematicalConstants::Pi;
382 zeta_end=2.0*MathematicalConstants::Pi;
385 curvilinear_boundary_pt[1]=
new TriangleMeshCurviLine(
386 ellipse_pt,zeta_start,zeta_end,
387 nsegment,boundary_id);
392 Vector<double> hole_coords(2);
395 Vector<TriangleMeshClosedCurve*> curvilinear_hole_pt(1);
397 new TriangleMeshClosedCurve(curvilinear_boundary_pt,
412 TriangleMeshParameters triangle_mesh_parameters(closed_curve_pt);
415 triangle_mesh_parameters.internal_closed_curve_pt() = hole_pt;
418 double uniform_element_area=0.2;
419 triangle_mesh_parameters.element_area() = uniform_element_area;
423 RefineableTriangleMesh<ELEMENT>(triangle_mesh_parameters);
426 Problem::mesh_pt()=My_mesh_pt;
429 Z2ErrorEstimator* error_estimator_pt=
new Z2ErrorEstimator;
430 My_mesh_pt->spatial_error_estimator_pt()=error_estimator_pt;
433 My_mesh_pt->max_element_size()=0.2;
434 My_mesh_pt->min_element_size()=0.002;
437 complete_problem_setup();
441 sprintf(filename,
"RESLT/trace.dat");
442 Trace_file.open(filename);
445 oomph_info <<
"Number of equations: "
446 << this->assign_eqn_numbers() << std::endl;
457 template<
class ELEMENT>
464 unsigned nbound=My_mesh_pt->nboundary();
465 for(
unsigned ibound=0;ibound<nbound;ibound++)
467 unsigned num_nod=My_mesh_pt->nboundary_node(ibound);
468 for (
unsigned inod=0;inod<num_nod;inod++)
471 Node* nod_pt=My_mesh_pt->boundary_node_pt(ibound,inod);
480 unsigned n_element = My_mesh_pt->nelement();
481 for(
unsigned e=0;e<n_element;e++)
484 ELEMENT* el_pt =
dynamic_cast<ELEMENT*
>(My_mesh_pt->element_pt(e));
492 apply_boundary_conditions();
501 template<
class ELEMENT>
506 unsigned nbound=this->My_mesh_pt->nboundary();
507 for(
unsigned ibound=0;ibound<nbound;ibound++)
509 unsigned num_nod=this->My_mesh_pt->nboundary_node(ibound);
510 for (
unsigned inod=0;inod<num_nod;inod++)
513 Node* nod_pt=this->My_mesh_pt->boundary_node_pt(ibound,inod);
525 nod_pt->set_value(0,u[0]);
535 template<
class ELEMENT>
537 std::string& comment)
546 sprintf(filename,
"RESLT/soln%i.dat",Doc_info.number());
547 some_file.open(filename);
548 this->My_mesh_pt->output(some_file,npts);
549 some_file <<
"TEXT X = 22, Y = 92, CS=FRAME T = \""
550 << comment <<
"\"\n";
555 sprintf(filename,
"RESLT/exact_soln%i.dat",Doc_info.number());
556 some_file.open(filename);
562 sprintf(filename,
"RESLT/boundaries%i.dat",Doc_info.number());
563 some_file.open(filename);
564 My_mesh_pt->output_boundaries(some_file);
570 double error,norm,dummy_error,zero_norm;
571 sprintf(filename,
"RESLT/error%i.dat",Doc_info.number());
572 some_file.open(filename);
577 dummy_error,zero_norm);
581 oomph_info <<
"\nNorm of error : " << sqrt(error) << std::endl;
582 oomph_info <<
"Norm of exact solution: " << sqrt(norm) << std::endl;
583 oomph_info <<
"Norm of computed solution: " << sqrt(dummy_error) << std::endl;
584 Trace_file << sqrt(norm) <<
" " << sqrt(dummy_error) << std::endl;
595 int main(
int argc,
char **argv)
598 CommandLineArgs::setup(argc,argv);
604 CommandLineArgs::specify_command_line_flag(
"--validation");
607 CommandLineArgs::parse_and_assign();
610 CommandLineArgs::doc_specified_flags();
630 std::stringstream comment_stream;
631 comment_stream <<
"Initial mesh ";
638 if (CommandLineArgs::command_line_flag_has_been_set(
"--validation"))
642 for (
unsigned i=0;i<nstep;i++)
646 unsigned max_adapt=3;
647 if (CommandLineArgs::command_line_flag_has_been_set(
"--validation"))
651 problem.newton_solve(max_adapt);
655 std::stringstream comment_stream;
//////////////////////////////////////////////////////// ////////////////////////////////////////////...
UnstructuredPoissonProblem()
Constructor.
void actions_before_newton_solve()
Update the problem specs before solve: Re-apply boundary conditons.
DocInfo Doc_info
Doc info object for labeling output.
void complete_problem_setup()
Helper function to (re-)set boundary condition and complete the build of all elements.
void actions_after_adapt()
Actions after adapt: Setup the problem again – remember that the mesh has been completely rebuilt and...
void actions_after_newton_solve()
Update after solve (empty)
void doc_solution(const std::string &comment="")
Doc the solution.
ofstream Trace_file
Trace file to document norm of solution.
void actions_before_adapt()
Actions before adapt. Empty.
void apply_boundary_conditions()
Helper function to apply boundary conditions.
~UnstructuredPoissonProblem()
Destructor.
RefineableTriangleMesh< ELEMENT > * My_mesh_pt
Pointers to specific mesh.
int main(int argc, char **argv)
Driver code for demo of inline triangle mesh generation.
Namespace for exact solution for Poisson equation with "sharp step".
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 when...
double TanPhi
Parameter for angle Phi of "step".
void get_source(const Vector< double > &x, double &source)
Source function required to make the solution above an exact solution.
double Alpha
Parameter for steepness of "step".
void get_exact_u(const Vector< double > &x, Vector< double > &u)
Exact solution as a Vector.