38 #include "pml_helmholtz.h"
41 #include "meshes/triangle_mesh.h"
42 #include "meshes/rectangular_quadmesh.h"
44 using namespace oomph;
74 template<
class ELEMENT>
94 void doc_solution(DocInfo& doc_info);
97 void create_pml_meshes();
100 void apply_boundary_conditions();
105 void actions_before_adapt();
108 void actions_after_adapt();
164 template<
class ELEMENT>
169 Trace_file.open(
"RESLT/trace.dat");
175 Circle* inner_circle_pt=
new Circle(x_c,y_c,a);
179 TriangleMeshClosedCurve* outer_boundary_pt=0;
181 unsigned n_segments = 20;
182 Vector<TriangleMeshCurveSection*> outer_boundary_line_pt(4);
186 Vector<Vector<double> > vertex_coord(2);
187 for(
unsigned i=0;i<2;i++)
189 vertex_coord[i].resize(2);
193 vertex_coord[0][0]=-2.0;
194 vertex_coord[0][1]=-2.0;
195 vertex_coord[1][0]=-2.0;
196 vertex_coord[1][1]=2.0;
199 unsigned boundary_id=2;
200 outer_boundary_line_pt[0] =
new TriangleMeshPolyLine(vertex_coord,
204 vertex_coord[0][0]=-2.0;
205 vertex_coord[0][1]=2.0;
206 vertex_coord[1][0]=2.0;
207 vertex_coord[1][1]=2.0;
211 outer_boundary_line_pt[1] =
new TriangleMeshPolyLine(vertex_coord,
215 vertex_coord[0][0]=2.0;
216 vertex_coord[0][1]=2.0;
217 vertex_coord[1][0]=2.0;
218 vertex_coord[1][1]=-2.0;
222 outer_boundary_line_pt[2] =
new TriangleMeshPolyLine(vertex_coord,
226 vertex_coord[0][0]=2.0;
227 vertex_coord[0][1]=-2.0;
228 vertex_coord[1][0]=-2.0;
229 vertex_coord[1][1]=-2.0;
233 outer_boundary_line_pt[3] =
new TriangleMeshPolyLine(vertex_coord,
237 outer_boundary_pt =
new TriangleMeshPolygon(outer_boundary_line_pt);
241 Vector<TriangleMeshCurveSection*> inner_boundary_line_pt(2);
244 double s_start = 0.0;
245 double s_end = MathematicalConstants::Pi;
247 inner_boundary_line_pt[0]=
248 new TriangleMeshCurviLine(inner_circle_pt,
255 s_start = MathematicalConstants::Pi;
256 s_end = 2.0*MathematicalConstants::Pi;
258 inner_boundary_line_pt[1]=
259 new TriangleMeshCurviLine(inner_circle_pt,
268 Vector<TriangleMeshClosedCurve*> hole_pt(1);
269 Vector<double> hole_coords(2);
272 hole_pt[0]=
new TriangleMeshClosedCurve(inner_boundary_line_pt,
279 TriangleMeshParameters triangle_mesh_parameters(outer_boundary_pt);
282 triangle_mesh_parameters.internal_closed_curve_pt() = hole_pt;
285 triangle_mesh_parameters.element_area() = 0.1;
290 Bulk_mesh_pt=
new RefineableTriangleMesh<ELEMENT>(triangle_mesh_parameters);
293 Bulk_mesh_pt->spatial_error_estimator_pt()=
new Z2ErrorEstimator;
296 Bulk_mesh_pt->min_permitted_error()=0.00004;
297 Bulk_mesh_pt->max_permitted_error()=0.0001;
302 Bulk_mesh_pt=
new TriangleMesh<ELEMENT>(triangle_mesh_parameters);
307 add_sub_mesh(Bulk_mesh_pt);
316 this->mesh_pt()->output(
"global_mesh.dat");
317 this->mesh_pt()->output_boundaries(
"global_mesh_boundary.dat");
320 unsigned n_element = this->mesh_pt()->nelement();
321 for(
unsigned e=0;e<n_element;e++)
324 PMLHelmholtzEquations<2> *el_pt =
325 dynamic_cast<PMLHelmholtzEquations<2>*
>(mesh_pt()->element_pt(e));
332 apply_boundary_conditions();
335 cout <<
"Number of equations: " << assign_eqn_numbers() << std::endl;
345 template<
class ELEMENT>
351 delete PML_right_mesh_pt;
353 delete PML_top_mesh_pt;
355 delete PML_left_mesh_pt;
357 delete PML_bottom_mesh_pt;
358 PML_bottom_mesh_pt=0;
359 delete PML_top_right_mesh_pt;
360 PML_top_right_mesh_pt=0;
361 delete PML_top_left_mesh_pt;
362 PML_top_left_mesh_pt=0;
363 delete PML_bottom_right_mesh_pt;
364 PML_bottom_right_mesh_pt=0;
365 delete PML_bottom_left_mesh_pt;
366 PML_bottom_left_mesh_pt=0;
373 add_sub_mesh(Bulk_mesh_pt);
377 rebuild_global_mesh();
385 template<
class ELEMENT>
393 rebuild_global_mesh();
399 unsigned n_element = this->mesh_pt()->nelement();
401 for(
unsigned e=0;e<n_element;e++)
404 PMLHelmholtzEquations<2> *el_pt =
405 dynamic_cast<PMLHelmholtzEquations<2>*
>(mesh_pt()->element_pt(e));
412 apply_boundary_conditions();
421 template<
class ELEMENT>
427 unsigned n_bound = Bulk_mesh_pt->nboundary();
429 for(
unsigned b=0;b<n_bound;b++)
431 unsigned n_node = Bulk_mesh_pt->nboundary_node(b);
432 for (
unsigned n=0;n<n_node;n++)
434 if ((b==0) || (b==1))
436 Node* nod_pt=Bulk_mesh_pt->boundary_node_pt(b,n);
440 nod_pt->set_value(0,0.1);
441 nod_pt->set_value(1,0.0);
452 template<
class ELEMENT>
456 ofstream some_file,some_file2;
465 sprintf(filename,
"%s/soln%i.dat",doc_info.directory().c_str(),
467 some_file.open(filename);
468 Bulk_mesh_pt->output(some_file,npts);
473 sprintf(filename,
"%s/coarse_soln%i.dat",doc_info.directory().c_str(),
475 some_file.open(filename);
476 unsigned npts_coarse=2;
477 Bulk_mesh_pt->output(some_file,npts_coarse);
483 sprintf(filename,
"%s/pml_soln%i.dat",doc_info.directory().c_str(),
485 some_file.open(filename);
486 PML_top_mesh_pt->output(some_file,npts);
487 PML_right_mesh_pt->output(some_file,npts);
488 PML_bottom_mesh_pt->output(some_file,npts);
489 PML_left_mesh_pt->output(some_file,npts);
490 PML_top_right_mesh_pt->output(some_file,npts);
491 PML_bottom_right_mesh_pt->output(some_file,npts);
492 PML_top_left_mesh_pt->output(some_file,npts);
493 PML_bottom_left_mesh_pt->output(some_file,npts);
501 Bulk_mesh_pt->compute_norm(norm);
502 Trace_file << norm << std::endl;
529 template<
class ELEMENT>
534 unsigned int left_boundary_id = 2;
537 unsigned int top_boundary_id = 3;
540 unsigned int right_boundary_id = 4;
543 unsigned int bottom_boundary_id = 5;
546 unsigned n_x_right_pml = 3;
549 unsigned n_y_top_pml = 3;
552 unsigned n_x_left_pml = 3;
555 unsigned n_y_bottom_pml = 3;
560 double width_x_right_pml = 0.2;
561 double width_y_top_pml = 0.2;
562 double width_x_left_pml = 0.2;
563 double width_y_bottom_pml = 0.2;
567 TwoDimensionalPMLHelper::create_right_pml_mesh
568 <PMLLayerElement<ELEMENT> >
569 (Bulk_mesh_pt,right_boundary_id,
570 n_x_right_pml, width_x_right_pml);
572 TwoDimensionalPMLHelper::create_top_pml_mesh
573 <PMLLayerElement<ELEMENT> >
574 (Bulk_mesh_pt, top_boundary_id,
575 n_y_top_pml, width_y_top_pml);
577 TwoDimensionalPMLHelper::create_left_pml_mesh
578 <PMLLayerElement<ELEMENT> >
579 (Bulk_mesh_pt, left_boundary_id,
580 n_x_left_pml, width_x_left_pml);
582 TwoDimensionalPMLHelper::create_bottom_pml_mesh
583 <PMLLayerElement<ELEMENT> >
584 (Bulk_mesh_pt, bottom_boundary_id,
585 n_y_bottom_pml, width_y_bottom_pml);
588 add_sub_mesh(PML_right_mesh_pt);
589 add_sub_mesh(PML_top_mesh_pt);
590 add_sub_mesh(PML_left_mesh_pt);
591 add_sub_mesh(PML_bottom_mesh_pt);
594 PML_top_right_mesh_pt =
595 TwoDimensionalPMLHelper::create_top_right_pml_mesh
596 <PMLLayerElement<ELEMENT> >
597 (PML_right_mesh_pt, PML_top_mesh_pt,
598 Bulk_mesh_pt, right_boundary_id);
600 PML_bottom_right_mesh_pt =
601 TwoDimensionalPMLHelper::create_bottom_right_pml_mesh
602 <PMLLayerElement<ELEMENT> >
603 (PML_right_mesh_pt, PML_bottom_mesh_pt,
604 Bulk_mesh_pt, right_boundary_id);
606 PML_top_left_mesh_pt =
607 TwoDimensionalPMLHelper::create_top_left_pml_mesh
608 <PMLLayerElement<ELEMENT> >
609 (PML_left_mesh_pt, PML_top_mesh_pt,
610 Bulk_mesh_pt, left_boundary_id);
612 PML_bottom_left_mesh_pt =
613 TwoDimensionalPMLHelper::create_bottom_left_pml_mesh
614 <PMLLayerElement<ELEMENT> >
615 (PML_left_mesh_pt, PML_bottom_mesh_pt,
616 Bulk_mesh_pt, left_boundary_id);
619 add_sub_mesh(PML_top_right_mesh_pt);
620 add_sub_mesh(PML_bottom_right_mesh_pt);
621 add_sub_mesh(PML_top_left_mesh_pt);
622 add_sub_mesh(PML_bottom_left_mesh_pt);
631 int main(
int argc,
char **argv)
641 <TPMLHelmholtzElement<2,3> > > problem;
665 doc_info.set_directory(
"RESLT");
671 unsigned max_adapt=1;
675 problem.newton_solve(max_adapt);
680 problem.newton_solve();
////////////////////////////////////////////////////////////////// //////////////////////////////////...
Mesh * PML_bottom_left_mesh_pt
Pointer to the bottom left corner PML mesh.
void actions_before_newton_solve()
Update the problem specs before solve (empty)
void apply_boundary_conditions()
Apply boundary conditions.
void actions_before_adapt()
Actions before adapt: Wipe the PML meshes.
~PMLProblem()
Destructor (empty)
Mesh * PML_bottom_right_mesh_pt
Pointer to the bottom right corner PML mesh.
Mesh * PML_bottom_mesh_pt
Pointer to the bottom PML mesh.
ofstream Trace_file
Trace file.
TriangleMesh< ELEMENT > * Bulk_mesh_pt
Pointer to the "bulk" mesh.
void actions_after_adapt()
Actions after adapt: Rebuild the PML meshes.
Mesh * PML_top_mesh_pt
Pointer to the top PML mesh.
Mesh * PML_top_right_mesh_pt
Pointer to the top right corner PML mesh.
void create_pml_meshes()
Create PML meshes.
Mesh * PML_right_mesh_pt
Pointer to the right PML mesh.
Mesh * PML_top_left_mesh_pt
Pointer to the top left corner PML mesh.
Mesh * PML_left_mesh_pt
Pointer to the left PML mesh.
void actions_after_newton_solve()
Update the problem specs after solve (empty)
RefineableTriangleMesh< ELEMENT > * Bulk_mesh_pt
Pointer to the refineable "bulk" mesh.
void doc_solution(DocInfo &doc_info)
Doc the solution. DocInfo object stores flags/labels for where the output gets written to.
////////////////////////////////////////////////////////////////// //////////////////////////////////...
double Wavenumber
Wavenumber (also known as k), k=omega/c.
double K_squared
Square of the wavenumber (also known as k^2)
int main(int argc, char **argv)
Solve 2D Helmholtz problem.