36 #include "meshes/one_d_mesh.h"
40 using namespace oomph;
56 u[0] = double(
Sign)*((sin(sqrt(30.0))-1.0)*x[0]-sin(sqrt(30.0)*x[0]));
63 source = double(
Sign)*30.0*sin(sqrt(30.0)*x[0]);
77 template<
class ELEMENT>
85 PoissonEquations<1>::PoissonSourceFctPt source_fct_pt);
94 void actions_before_newton_solve();
101 void doc_solution(
const unsigned& label);
119 template<
class ELEMENT>
121 PoissonEquations<1>::PoissonSourceFctPt source_fct_pt) :
122 Source_fct_pt(source_fct_pt)
124 Problem::Sparse_assembly_method = Perform_assembly_using_two_arrays;
131 Problem::mesh_pt() =
new OneDMesh<ELEMENT>(n_element,L);
139 mesh_pt()->boundary_node_pt(0,0)->pin(0);
143 mesh_pt()->boundary_node_pt(1,0)->pin(0);
148 for(
unsigned i=0;i<n_element;i++)
151 ELEMENT *elem_pt =
dynamic_cast<ELEMENT*
>(mesh_pt()->element_pt(i));
158 assign_eqn_numbers();
169 template<
class ELEMENT>
177 Node* left_node_pt=mesh_pt()->node_pt(0);
182 x[0]=left_node_pt->x(0);
190 left_node_pt->set_value(0,u[0]);
194 unsigned last_node=mesh_pt()->nnode()-1;
195 Node* right_node_pt=mesh_pt()->node_pt(last_node);
198 x[0]=right_node_pt->x(0);
205 right_node_pt->set_value(0,u[0]);
215 template<
class ELEMENT>
218 using namespace StringConversion;
225 ofstream solution_file((
"soln" + to_string(label) +
".dat").c_str());
226 mesh_pt()->output(solution_file,npts);
227 solution_file.close();
231 ofstream exact_file((
"exact_soln" + to_string(label) +
".dat").c_str());
237 ofstream error_file((
"error" + to_string(label) +
".dat").c_str());
243 cout <<
"\nNorm of error : " << sqrt(error) << std::endl;
244 cout <<
"Norm of solution : " << sqrt(norm) << std::endl << std::endl;
265 unsigned n_element=40;
270 cout <<
"\n\n\nProblem self-test ";
271 if (problem.self_test()==0)
273 cout <<
"passed: Problem can be solved." << std::endl;
277 throw OomphLibError(
"failed!",
278 OOMPH_CURRENT_FUNCTION,OOMPH_EXCEPTION_LOCATION);
282 cout <<
"\n\n\nSolving with negative sign:\n" << std::endl;
286 problem.newton_solve();
293 cout <<
"\n\n\nSolving with positive sign:\n" << std::endl;
299 problem.newton_solve();
1D Poisson problem in unit interval.
PoissonEquations< 1 >::PoissonSourceFctPt Source_fct_pt
Pointer to source function.
void actions_before_newton_solve()
Update the problem specs before solve: (Re)set boundary conditions.
~OneDPoissonProblem()
Destructor (empty)
void doc_solution(const unsigned &label)
Doc the solution, pass the number of the case considered, so that output files can be distinguished.
void actions_after_newton_solve()
Update the problem specs after solve (empty)
OneDPoissonProblem(const unsigned &n_element, PoissonEquations< 1 >::PoissonSourceFctPt source_fct_pt)
Constructor: Pass number of elements and pointer to source function.
Namespace for fish-shaped solution of 1D Poisson equation.
int Sign
Sign of the source function (- gives the upper half of the fish, + the lower half)
void get_exact_u(const Vector< double > &x, Vector< double > &u)
Exact, fish-shaped solution as a 1D vector.
void source_function(const Vector< double > &x, double &source)
Source function required to make the fish shape an exact solution.
int main()
///////////////////////////////////////////////////////////////////// ///////////////////////////////...