40 #include "meshes/one_d_mesh.h" 44 using namespace oomph;
60 u[0] = double(Sign)*((sin(sqrt(30.0))-1.0)*x[0]-sin(sqrt(30.0)*x[0]));
67 source = double(Sign)*30.0*sin(sqrt(30.0)*x[0]);
81 template<
class ELEMENT>
89 PoissonEquations<1>::PoissonSourceFctPt source_fct_pt);
98 void actions_before_newton_solve();
105 void doc_solution(
const unsigned& label);
123 template<
class ELEMENT>
125 PoissonEquations<1>::PoissonSourceFctPt source_fct_pt) :
126 Source_fct_pt(source_fct_pt)
128 Problem::Sparse_assembly_method = Perform_assembly_using_two_arrays;
135 Problem::mesh_pt() =
new OneDMesh<ELEMENT>(n_element,L);
143 mesh_pt()->boundary_node_pt(0,0)->pin(0);
147 mesh_pt()->boundary_node_pt(1,0)->pin(0);
152 for(
unsigned i=0;i<n_element;i++)
155 ELEMENT *elem_pt =
dynamic_cast<ELEMENT*
>(mesh_pt()->element_pt(i));
162 assign_eqn_numbers();
173 template<
class ELEMENT>
181 Node* left_node_pt=mesh_pt()->node_pt(0);
186 x[0]=left_node_pt->x(0);
194 left_node_pt->set_value(0,u[0]);
198 unsigned last_node=mesh_pt()->nnode()-1;
199 Node* right_node_pt=mesh_pt()->node_pt(last_node);
202 x[0]=right_node_pt->x(0);
209 right_node_pt->set_value(0,u[0]);
219 template<
class ELEMENT>
222 using namespace StringConversion;
229 ofstream solution_file((
"soln" + to_string(label) +
".dat").c_str());
230 mesh_pt()->output(solution_file,npts);
231 solution_file.close();
235 ofstream exact_file((
"exact_soln" + to_string(label) +
".dat").c_str());
241 ofstream error_file((
"error" + to_string(label) +
".dat").c_str());
247 cout <<
"\nNorm of error : " << sqrt(error) << std::endl;
248 cout <<
"Norm of solution : " << sqrt(norm) << std::endl << std::endl;
269 unsigned n_element=40;
274 cout <<
"\n\n\nProblem self-test ";
275 if (problem.self_test()==0)
277 cout <<
"passed: Problem can be solved." << std::endl;
281 throw OomphLibError(
"failed!",
282 OOMPH_CURRENT_FUNCTION,OOMPH_EXCEPTION_LOCATION);
286 cout <<
"\n\n\nSolving with negative sign:\n" << std::endl;
290 problem.newton_solve();
297 cout <<
"\n\n\nSolving with positive sign:\n" << std::endl;
303 problem.newton_solve();
Namespace for fish-shaped solution of 1D Poisson equation.
1D Poisson problem in unit interval.
int main()
Driver for 1D Poisson problem.
void actions_before_newton_solve()
Update the problem specs before solve: (Re)set boundary conditions.
void source_function(const Vector< double > &x, double &source)
Source function required to make the fish shape an exact solution.
int Sign
Sign of the source function (- gives the upper half of the fish, + the lower half) ...
void doc_solution(const unsigned &label)
Doc the solution, pass the number of the case considered, so that output files can be distinguished...
PoissonEquations< 1 >::PoissonSourceFctPt Source_fct_pt
Pointer to source function.
~OneDPoissonProblem()
Destructor (empty)
void get_exact_u(const Vector< double > &x, Vector< double > &u)
Exact, fish-shaped solution as a 1D vector.
OneDPoissonProblem(const unsigned &n_element, PoissonEquations< 1 >::PoissonSourceFctPt source_fct_pt)
Constructor: Pass number of elements and pointer to source function.
void actions_after_newton_solve()
Update the problem specs after solve (empty)