32 #include "unsteady_heat.h"
35 #include "meshes/rectangular_quadmesh.h"
39 using namespace oomph;
41 using namespace MathematicalConstants;
64 double zeta=cos(
Phi)*x[0]+sin(
Phi)*x[1];
65 u[0]=exp(-
K*time)*sin(zeta*sqrt(
K));
69 void get_exact_u(
const double& time,
const Vector<double>& x,
double& u)
71 double zeta=cos(
Phi)*x[0]+sin(
Phi)*x[1];
72 u=exp(-
K*time)*sin(zeta*sqrt(
K));
76 void get_source(
const double& time,
const Vector<double>& x,
double& source)
90 template<
class ELEMENT>
114 void actions_before_implicit_timestep();
118 void set_initial_condition();
121 void doc_solution(DocInfo& doc_info, ofstream& trace_file);
137 template<
class ELEMENT>
139 UnsteadyHeatEquations<2>::UnsteadyHeatSourceFctPt source_fct_pt) :
140 Source_fct_pt(source_fct_pt)
146 add_time_stepper_pt(
new BDF<2>);
166 mesh_pt() =
new RectangularQuadMesh<ELEMENT>(nx,ny,lx,ly,time_stepper_pt());
171 unsigned n_el=mesh_pt()->nelement();
174 unsigned control_el=unsigned(n_el/2);
179 cout <<
"Recording trace of the solution at: "
188 unsigned n_bound = mesh_pt()->nboundary();
189 for(
unsigned b=0;b<n_bound;b++)
191 unsigned n_node = mesh_pt()->nboundary_node(b);
192 for (
unsigned n=0;n<n_node;n++)
194 mesh_pt()->boundary_node_pt(b,n)->pin(0);
203 unsigned n_element = mesh_pt()->nelement();
207 for(
unsigned i=0;i<n_element;i++)
210 ELEMENT *el_pt =
dynamic_cast<ELEMENT*
>(mesh_pt()->element_pt(i));
217 cout <<
"Number of equations: " << assign_eqn_numbers() << std::endl;
227 template<
class ELEMENT>
231 double time=time_pt()->time();
234 unsigned num_bound = mesh_pt()->nboundary();
235 for(
unsigned ibound=0;ibound<num_bound;ibound++)
238 unsigned num_nod=mesh_pt()->nboundary_node(ibound);
239 for (
unsigned inod=0;inod<num_nod;inod++)
241 Node* nod_pt=mesh_pt()->boundary_node_pt(ibound,inod);
249 nod_pt->set_value(0,u);
260 template<
class ELEMENT>
264 double backed_up_time=time_pt()->time();
271 Vector<double> soln(1);
275 unsigned num_nod = mesh_pt()->nnode();
279 int nprev_steps=time_stepper_pt()->nprev_values();
280 Vector<double> prev_time(nprev_steps+1);
281 for (
int t=nprev_steps;t>=0;t--)
283 prev_time[t]=time_pt()->time(
unsigned(t));
287 for (
int t=nprev_steps;t>=0;t--)
290 double time=prev_time[t];
291 cout <<
"setting IC at time =" << time << std::endl;
294 for (
unsigned n=0;n<num_nod;n++)
297 x[0]=mesh_pt()->node_pt(n)->x(0);
298 x[1]=mesh_pt()->node_pt(n)->x(1);
304 mesh_pt()->node_pt(n)->set_value(t,0,soln[0]);
308 for (
unsigned i=0;i<2;i++)
310 mesh_pt()->node_pt(n)->x(t,i)=x[i];
316 time_pt()->time()=backed_up_time;
325 template<
class ELEMENT>
338 cout <<
"=================================================" << std::endl;
339 cout <<
"Docing solution for t=" << time_pt()->time() << std::endl;
340 cout <<
"=================================================" << std::endl;
345 sprintf(filename,
"%s/soln%i.dat",doc_info.directory().c_str(),
347 some_file.open(filename);
348 mesh_pt()->output(some_file,npts);
351 some_file <<
"TEXT X=2.5,Y=93.6,F=HELV,HU=POINT,C=BLUE,H=26,T=\"time = "
352 << time_pt()->time() <<
"\"";
355 some_file <<
"GEOMETRY X=2.5,Y=98,T=LINE,C=BLUE,LT=0.4" << std::endl;
356 some_file <<
"1" << std::endl;
357 some_file <<
"2" << std::endl;
358 some_file <<
" 0 0" << std::endl;
359 some_file << time_pt()->time()*20.0 <<
" 0" << std::endl;
365 sprintf(filename,
"%s/exact_soln%i.dat",doc_info.directory().c_str(),
367 some_file.open(filename);
368 mesh_pt()->output_fct(some_file,npts,time_pt()->time(),
375 sprintf(filename,
"%s/error%i.dat",doc_info.directory().c_str(),
377 some_file.open(filename);
378 mesh_pt()->compute_error(some_file,
386 cout <<
"error: " << error << std::endl;
387 cout <<
"norm : " << norm << std::endl << std::endl;
390 Vector<double> x_ctrl(2);
391 x_ctrl[0]=Control_node_pt->x(0);
392 x_ctrl[1]=Control_node_pt->x(1);
395 trace_file << time_pt()->time() <<
" "
396 << Control_node_pt->value(0) <<
" "
399 << norm << std::endl;
425 doc_info.set_directory(
"RESLT");
433 sprintf(filename,
"%s/trace.dat",doc_info.directory().c_str());
434 trace_file.open(filename);
435 trace_file <<
"VARIABLES=\"time\",\"u<SUB>FE</SUB>\","
436 <<
"\"u<SUB>exact</SUB>\",\"norm of error\",\"norm of solution\""
445 problem.initialise_dt(dt);
457 unsigned nstep = unsigned(t_max/dt);
460 for (
unsigned istep=0;istep<nstep;istep++)
462 cout <<
" Timestep " << istep << std::endl;
465 problem.unsteady_newton_solve(dt);
///////////////////////////////////////////////////////////////////// ///////////////////////////////...
void doc_solution(DocInfo &doc_info, ofstream &trace_file)
Doc the solution.
void actions_before_implicit_timestep()
Update the problem specs before next timestep: Set Dirchlet boundary conditions from exact solution.
void actions_after_newton_solve()
Update the problem specs after solve (empty)
UnsteadyHeatEquations< 2 >::UnsteadyHeatSourceFctPt Source_fct_pt
Pointer to source function.
void set_initial_condition()
Set initial condition (incl previous timesteps) according to specified function.
void actions_before_newton_solve()
Update the problem specs before solve (empty)
UnsteadyHeatProblem(UnsteadyHeatEquations< 2 >::UnsteadyHeatSourceFctPt source_fct_pt)
Constructor.
Node * Control_node_pt
Pointer to control node at which the solution is documented.
~UnsteadyHeatProblem()
Destructor (empty)
void actions_after_implicit_timestep()
Update the problem specs after solve (empty)
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
void get_exact_u(const double &time, const Vector< double > &x, Vector< double > &u)
Exact solution as a Vector.
void get_exact_u(const double &time, const Vector< double > &x, double &u)
Exact solution as a scalar.
void get_source(const double &time, const Vector< double > &x, double &source)
Source function to make it an exact solution.
int main()
///////////////////////////////////////////////////////////////////// ///////////////////////////////...