40 #include "meshes/simple_rectangular_quadmesh.h"
49 using namespace oomph;
57 template<
class ELEMENT>
59 public virtual SimpleRectangularQuadMesh<ELEMENT>,
60 public RefineableQuadMesh<ELEMENT>
70 const double &Lx,
const double &Ly,
71 TimeStepper* time_stepper_pt=
72 &Mesh::Default_TimeStepper) :
73 SimpleRectangularQuadMesh<ELEMENT>(Nx,Ny,Lx,Ly,time_stepper_pt)
79 this->setup_quadtree_forest();
113 (1.0-pow(tanh(-1.0+
Alpha*(
TanPhi*x[0]-x[1])),2.0))*
123 double N[2] = {1.0, 0.0};
140 template<
class ELEMENT>
154 void doc_solution(DocInfo& doc_info);
161 void actions_before_newton_solve();
167 void actions_before_adapt();
170 void actions_after_adapt();
175 void create_flux_elements(
const unsigned &b, Mesh*
const &bulk_mesh_pt,
176 Mesh*
const &surface_mesh_pt);
179 void delete_flux_elements(Mesh*
const &surface_mesh_pt);
183 void set_prescribed_flux_pt();
202 template<
class ELEMENT>
205 : Source_fct_pt(source_fct_pt)
227 Bulk_mesh_pt->spatial_error_estimator_pt()=
new Z2ErrorEstimator;
252 for(
unsigned b=0;b<n_bound;b++)
258 for (
unsigned n=0;n<n_node;n++)
271 for(
unsigned e=0;e<n_element;e++)
274 ELEMENT *el_pt =
dynamic_cast<ELEMENT*
>(
Bulk_mesh_pt->element_pt(e));
284 cout <<
"Number of equations: " << assign_eqn_numbers() << std::endl;
295 template<
class ELEMENT>
299 unsigned n_bound = Bulk_mesh_pt->nboundary();
302 for(
unsigned i=0;i<n_bound;i++)
308 unsigned n_node = Bulk_mesh_pt->nboundary_node(i);
311 for (
unsigned n=0;n<n_node;n++)
314 Node* nod_pt=Bulk_mesh_pt->boundary_node_pt(i,n);
326 nod_pt->set_value(0,u[0]);
337 template<
class ELEMENT>
341 delete_flux_elements(Surface_mesh_pt);
344 rebuild_global_mesh();
353 template<
class ELEMENT>
358 create_flux_elements(1,Bulk_mesh_pt,Surface_mesh_pt);
361 rebuild_global_mesh();
364 set_prescribed_flux_pt();
367 unsigned min_refinement_level;
368 unsigned max_refinement_level;
369 Bulk_mesh_pt->get_refinement_levels(min_refinement_level,
370 max_refinement_level);
371 cout <<
"Min/max. refinement levels in bulk mesh: "
372 << min_refinement_level <<
" "
373 << max_refinement_level << std::endl;
383 template<
class ELEMENT>
387 unsigned n_element=Surface_mesh_pt->nelement();
388 for(
unsigned e=0;e<n_element;e++)
391 PoissonFluxElement<ELEMENT> *el_pt =
392 dynamic_cast< PoissonFluxElement<ELEMENT>*
>(
393 Surface_mesh_pt->element_pt(e));
396 el_pt->flux_fct_pt() =
408 template<
class ELEMENT>
413 unsigned min_refinement_level;
414 unsigned max_refinement_level;
415 Bulk_mesh_pt->get_refinement_levels(min_refinement_level,
416 max_refinement_level);
417 cout <<
"Ultimate min/max. refinement levels in bulk mesh : "
418 << min_refinement_level <<
" "
419 << max_refinement_level << std::endl;
431 sprintf(filename,
"%s/soln%i.dat",doc_info.directory().c_str(),
433 some_file.open(filename);
434 Bulk_mesh_pt->output(some_file,npts);
439 sprintf(filename,
"%s/exact_soln%i.dat",doc_info.directory().c_str(),
441 some_file.open(filename);
449 sprintf(filename,
"%s/error%i.dat",doc_info.directory().c_str(),
451 some_file.open(filename);
457 cout <<
"\nNorm of error : " << sqrt(error) << std::endl;
458 cout <<
"Norm of solution: " << sqrt(norm) << std::endl << std::endl;
469 template<
class ELEMENT>
472 Mesh*
const &surface_mesh_pt)
475 unsigned n_element = bulk_mesh_pt->nboundary_element(b);
478 for(
unsigned e=0;e<n_element;e++)
481 ELEMENT* bulk_elem_pt =
dynamic_cast<ELEMENT*
>(
482 bulk_mesh_pt->boundary_element_pt(b,e));
485 int face_index = bulk_mesh_pt->face_index_at_boundary(b,e);
488 PoissonFluxElement<ELEMENT>* flux_element_pt =
new
489 PoissonFluxElement<ELEMENT>(bulk_elem_pt,face_index);
492 surface_mesh_pt->add_element_pt(flux_element_pt);
503 template<
class ELEMENT>
508 unsigned n_element = surface_mesh_pt->nelement();
511 for(
unsigned e=0;e<n_element;e++)
514 delete surface_mesh_pt->element_pt(e);
518 surface_mesh_pt->flush_element_and_node_storage();
545 doc_info.set_directory(
"RESLT");
554 cout <<
"\n\n\nProblem self-test ";
555 if (problem.self_test()==0)
557 cout <<
"passed: Problem can be solved." << std::endl;
561 throw OomphLibError(
"Self test failed",
562 OOMPH_CURRENT_FUNCTION,
563 OOMPH_EXCEPTION_LOCATION);
576 for (
unsigned istep=0;istep<nstep;istep++)
581 cout <<
"\n\nSolving for TanhSolnForPoisson::Alpha="
585 problem.newton_solve(3);
2D Poisson problem on rectangular domain, discretised with 2D QPoisson elements. Flux boundary condit...
void actions_after_adapt()
Actions after adapt: Rebuild the mesh of prescribed flux elements.
PoissonEquations< 2 >::PoissonSourceFctPt Source_fct_pt
Pointer to source function.
void actions_before_adapt()
Actions before adapt: Wipe the mesh of prescribed flux elements.
Mesh * Surface_mesh_pt
Pointer to the "surface" mesh.
void actions_before_newton_solve()
Update the problem specs before solve: Reset boundary conditions to the values from the exact solutio...
SimpleRefineableRectangularQuadMesh< ELEMENT > * Bulk_mesh_pt
Pointer to the "bulk" mesh.
RefineableTwoMeshFluxPoissonProblem(PoissonEquations< 2 >::PoissonSourceFctPt source_fct_pt)
Constructor: Pass pointer to source function.
~RefineableTwoMeshFluxPoissonProblem()
Destructor (empty)
void set_prescribed_flux_pt()
Set pointer to prescribed-flux function for all elements in the surface mesh.
void delete_flux_elements(Mesh *const &surface_mesh_pt)
Delete Poisson flux elements and wipe the surface mesh.
void actions_after_newton_solve()
Update the problem specs after solve (empty)
void create_flux_elements(const unsigned &b, Mesh *const &bulk_mesh_pt, Mesh *const &surface_mesh_pt)
Create Poisson flux elements on boundary b of the Mesh pointed to by bulk_mesh_pt and add them to the...
void doc_solution(DocInfo &doc_info)
Doc the solution. DocInfo object stores flags/labels for where the output gets written to.
Refineable equivalent of the SimpleRectangularQuadMesh. Refinement is performed by the QuadTree-based...
virtual ~SimpleRefineableRectangularQuadMesh()
Destructor: Empty.
SimpleRefineableRectangularQuadMesh(const unsigned &Nx, const unsigned &Ny, const double &Lx, const double &Ly, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Pass number of elements in the horizontal and vertical directions, and the corresponding dimensions....
Namespace for exact solution for Poisson equation with "sharp step".
void prescribed_flux_on_fixed_x_boundary(const Vector< double > &x, double &flux)
Flux required by the exact solution on a boundary on which x is fixed.
double TanPhi
Parameter for angle Phi of "step".
void source_function(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.
int main()
Demonstrate how to solve 2D Poisson problem with flux boundary conditions, using two meshes.