41 #include "meshes/triangle_mesh.h" 45 using namespace oomph;
63 u[0]=tanh(1.0-Alpha*(Beta*x[0]-x[1]));
70 u=tanh(1.0-Alpha*(Beta*x[0]-x[1]));
77 source = 2.0*tanh(-1.0+Alpha*(Beta*x[0]-x[1]))*
78 (1.0-pow(tanh(-1.0+Alpha*(Beta*x[0]-x[1])),2.0))*
79 Alpha*Alpha*Beta*Beta+2.0*tanh(-1.0+Alpha*(Beta*x[0]-x[1]))*
80 (1.0-pow(tanh(-1.0+Alpha*(Beta*x[0]-x[1])),2.0))*Alpha*Alpha;
96 template<
class ELEMENT>
105 PoissonProblem(PoissonEquations<2>::PoissonSourceFctPt source_fct_pt,
106 const string& node_file_name,
107 const string& element_file_name,
108 const string& poly_file_name);
117 unsigned num_bound = mesh_pt()->nboundary();
118 for(
unsigned ibound=0;ibound<num_bound;ibound++)
121 unsigned num_nod=mesh_pt()->nboundary_node(ibound);
122 for (
unsigned inod=0;inod<num_nod;inod++)
124 Node* nod_pt=mesh_pt()->boundary_node_pt(ibound,inod);
130 nod_pt->set_value(0,u);
141 void actions_after_adapt();
159 void doc_solution(DocInfo& doc_info);
181 template<
class ELEMENT>
184 const string& node_file_name,
185 const string& element_file_name,
186 const string& poly_file_name)
187 : Source_fct_pt(source_fct_pt)
221 unsigned num_bound =
mesh_pt()->nboundary();
222 for(
unsigned ibound=0;ibound<num_bound;ibound++)
224 unsigned num_nod=
mesh_pt()->nboundary_node(ibound);
225 for (
unsigned inod=0;inod<num_nod;inod++)
227 mesh_pt()->boundary_node_pt(ibound,inod)->pin(0);
234 unsigned n_element =
mesh_pt()->nelement();
238 for(
unsigned i=0;i<n_element;i++)
241 ELEMENT* el_pt =
dynamic_cast<ELEMENT*
>(
mesh_pt()->element_pt(i));
248 cout <<
"Number of equations: " << assign_eqn_numbers() << std::endl;
256 template<
class ELEMENT>
266 unsigned num_bound =
mesh_pt()->nboundary();
267 for(
unsigned ibound=0;ibound<num_bound;ibound++)
269 unsigned num_nod=
mesh_pt()->nboundary_node(ibound);
270 for (
unsigned inod=0;inod<num_nod;inod++)
272 mesh_pt()->boundary_node_pt(ibound,inod)->pin(0);
279 unsigned n_element =
mesh_pt()->nelement();
283 for(
unsigned i=0;i<n_element;i++)
286 ELEMENT* el_pt =
dynamic_cast<ELEMENT*
>(
mesh_pt()->element_pt(i));
293 cout <<
"Number of equations: " << assign_eqn_numbers() << std::endl;
301 template<
class ELEMENT>
316 sprintf(filename,
"%s/boundaries.dat",doc_info.directory().c_str());
317 some_file.open(filename);
318 mesh_pt()->output_boundaries(some_file);
324 sprintf(filename,
"%s/soln%i.dat",doc_info.directory().c_str(),
326 some_file.open(filename);
327 mesh_pt()->output(some_file,npts);
333 sprintf(filename,
"%s/exact_soln%i.dat",doc_info.directory().c_str(),
335 some_file.open(filename);
343 sprintf(filename,
"%s/error%i.dat",doc_info.directory().c_str(),
345 some_file.open(filename);
349 cout <<
"error: " << sqrt(error) << std::endl;
350 cout <<
"norm : " << sqrt(norm) << std::endl << std::endl;
354 sprintf(filename,
"%s/norm%i.dat",doc_info.directory().c_str(),
356 some_file.open(filename);
357 double norm_soln=0.0;
358 mesh_pt()->compute_norm(norm_soln);
359 some_file << sqrt(norm_soln) << std::endl;
360 cout <<
"Norm of computed solution: " << sqrt(norm_soln) << endl;
372 int main(
int argc,
char* argv[])
375 CommandLineArgs::setup(argc,argv);
380 std::string error_message =
381 "Wrong number of command line arguments.\n";
383 "Must specify the following file names \n";
385 "filename.node then filename.ele then filename.poly\n";
387 throw OomphLibError(error_message,
388 OOMPH_CURRENT_FUNCTION,
389 OOMPH_EXCEPTION_LOCATION);
393 const unsigned max_adapt = 3;
397 string node_file_name(argv[1]);
398 string element_file_name(argv[2]);
399 string poly_file_name(argv[3]);
405 doc_info.set_directory(
"RESLT");
411 cout << std::endl <<
"Cubic elements" << std::endl;
412 cout <<
"==============" << std::endl << std::endl;
421 problem.newton_solve();
435 cout << std::endl <<
"Quadratic elements" << std::endl;
436 cout <<
"===================" << std::endl << std::endl;
454 problem.newton_solve(max_adapt);
457 problem.newton_solve();
472 cout << std::endl <<
"Linear elements" << std::endl;
473 cout <<
"===============" << std::endl << std::endl;
491 problem.newton_solve(max_adapt);
494 problem.newton_solve();
int main(int argc, char *argv[])
Demonstrate how to solve Poisson problem.
~PoissonProblem()
Destructor (empty)
void actions_after_newton_solve()
Update the problem specs before solve (empty)
void doc_solution(DocInfo &doc_info)
Doc the solution.
void get_exact_u(const Vector< double > &x, Vector< double > &u)
Exact solution as a Vector.
RefineableTriangleMesh< ELEMENT > * Bulk_mesh_pt
Pointer to the bulk mesh.
Z2ErrorEstimator * error_estimator_pt
Error estimator.
RefineableTriangleMesh< ELEMENT > * mesh_pt()
Access function for the specific mesh.
double Alpha
Parameter for steepness of step.
void actions_before_newton_solve()
Update the problem specs before solve: (Re)set boundary conditions.
PoissonEquations< 2 >::PoissonSourceFctPt Source_fct_pt
Pointer to source function.
PoissonProblem(PoissonEquations< 2 >::PoissonSourceFctPt source_fct_pt, const string &node_file_name, const string &element_file_name, const string &poly_file_name)
Constructor: Pass pointer to source function and names of two triangle input files.
void get_exact_u(const Vector< double > &x, double &u)
Exact solution as a scalar.
Namespace for exact solution for Poisson equation with sharp step.
TriangleMesh< ELEMENT > * mesh_pt()
Access function for the specific mesh.
double Beta
Parameter for angle of step.
Micky mouse Poisson problem.
Unstructured refineable Triangle Mesh.
void get_source(const Vector< double > &x, double &source)
Source function to make it an exact solution.
void actions_after_adapt()
Actions performed after the adaptation steps.