33 #include "unsteady_heat.h"
36 #include "meshes/rectangular_quadmesh.h"
40 using namespace oomph;
42 using namespace MathematicalConstants;
68 double zeta=cos(
Phi)*x[0]+sin(
Phi)*x[1];
70 0.5*(1.0+tanh(
Gamma*cos(2.0*MathematicalConstants::Pi*time)));
74 void get_exact_u(
const double& time,
const Vector<double>& x,
double& u)
76 double zeta=cos(
Phi)*x[0]+sin(
Phi)*x[1];
78 0.5*(1.0+tanh(
Gamma*cos(2.0*MathematicalConstants::Pi*time)));
82 void get_source(
const double& time,
const Vector<double>& x,
double& source)
85 -0.5*sin(
K*(cos(
Phi)*x[0]+sin(
Phi)*x[1]))*
K*
K*pow(cos(
Phi),2.0)*(
86 0.1E1+tanh(
Gamma*cos(0.2E1*0.3141592653589793E1*time)))-
87 0.5*sin(
K*(cos(
Phi)*x[0]+sin(
Phi)*x[1]))*
K*
K*pow(sin(
Phi),2.0)*
88 (0.1E1+tanh(
Gamma*cos(0.2E1*0.3141592653589793E1*time)))+
89 0.1E1*sin(
K*(cos(
Phi)*x[0]+sin(
Phi)*x[1]))*
90 (1.0-pow(tanh(
Gamma*cos(0.2E1*0.3141592653589793E1*time)),2.0))*
91 Gamma*sin(0.2E1*0.3141592653589793E1*time)*0.3141592653589793E1;
103 template<
class ELEMENT>
127 void actions_before_implicit_timestep();
131 void set_initial_condition();
134 void doc_solution(DocInfo& doc_info, ofstream& trace_file);
137 void dump_it(ofstream& dump_file);
140 void restart(ifstream& restart_file);
143 double global_temporal_error_norm();
161 template<
class ELEMENT>
163 UnsteadyHeatEquations<2>::UnsteadyHeatSourceFctPt source_fct_pt) :
164 Source_fct_pt(source_fct_pt)
170 add_time_stepper_pt(
new BDF<2>(
true));
193 mesh_pt() =
new RectangularQuadMesh<ELEMENT>(nx,ny,lx,ly,time_stepper_pt());
198 unsigned n_el=mesh_pt()->nelement();
201 unsigned control_el=unsigned(n_el/2);
206 cout <<
"Recording trace of the solution at: "
215 unsigned n_bound = mesh_pt()->nboundary();
216 for(
unsigned b=0;b<n_bound;b++)
218 unsigned n_node = mesh_pt()->nboundary_node(b);
219 for (
unsigned n=0;n<n_node;n++)
221 mesh_pt()->boundary_node_pt(b,n)->pin(0);
230 unsigned n_element = mesh_pt()->nelement();
234 for(
unsigned i=0;i<n_element;i++)
237 ELEMENT *el_pt =
dynamic_cast<ELEMENT*
>(mesh_pt()->element_pt(i));
244 cout <<
"Number of equations: " << assign_eqn_numbers() << std::endl;
254 template<
class ELEMENT>
258 double time=time_pt()->time();
261 unsigned num_bound = mesh_pt()->nboundary();
262 for(
unsigned ibound=0;ibound<num_bound;ibound++)
265 unsigned num_nod=mesh_pt()->nboundary_node(ibound);
266 for (
unsigned inod=0;inod<num_nod;inod++)
268 Node* nod_pt=mesh_pt()->boundary_node_pt(ibound,inod);
276 nod_pt->set_value(0,u);
287 template<
class ELEMENT>
292 ifstream* restart_file_pt=0;
298 if (CommandLineArgs::Argc==1)
300 cout <<
"No restart -- setting IC from exact solution" << std::endl;
302 else if (CommandLineArgs::Argc==2)
305 restart_file_pt=
new ifstream(CommandLineArgs::Argv[1],ios_base::in);
306 if (restart_file_pt!=0)
308 cout <<
"Have opened " << CommandLineArgs::Argv[1] <<
309 " for restart. " << std::endl;
313 std::ostringstream error_stream;
315 <<
"ERROR while trying to open " << CommandLineArgs::Argv[1] <<
316 " for restart." << std::endl;
320 OOMPH_CURRENT_FUNCTION,
321 OOMPH_EXCEPTION_LOCATION);
327 std::ostringstream error_stream;
328 error_stream <<
"Can only specify one input file\n"
329 <<
"You specified the following command line arguments:\n";
331 CommandLineArgs::output();
335 OOMPH_CURRENT_FUNCTION,
336 OOMPH_EXCEPTION_LOCATION);
342 if (restart_file_pt!=0)
347 restart(*restart_file_pt);
362 double backed_up_time=time_pt()->time();
369 Vector<double> soln(1);
373 unsigned num_nod = mesh_pt()->nnode();
376 int nprev_steps=time_stepper_pt()->nprev_values();
377 Vector<double> prev_time(nprev_steps+1);
378 for (
int itime=nprev_steps;itime>=0;itime--)
380 prev_time[itime]=time_pt()->time(
unsigned(itime));
384 for (
int itime=nprev_steps;itime>=0;itime--)
387 double time=prev_time[itime];
388 cout <<
"setting IC at time =" << time << std::endl;
391 for (
unsigned n=0;n<num_nod;n++)
394 x[0]=mesh_pt()->node_pt(n)->x(0);
395 x[1]=mesh_pt()->node_pt(n)->x(1);
401 mesh_pt()->node_pt(n)->set_value(itime,0,soln[0]);
404 for (
unsigned i=0;i<2;i++)
406 mesh_pt()->node_pt(n)->x(itime,i)=x[i];
412 time_pt()->time()=backed_up_time;
424 template<
class ELEMENT>
437 cout <<
"=================================================" << std::endl;
438 cout <<
"Docing solution for t=" << time_pt()->time() << std::endl;
439 cout <<
"=================================================" << std::endl;
442 cout <<
" Timestep: " << doc_info.number() << std::endl;
446 sprintf(filename,
"%s/soln%i.dat",doc_info.directory().c_str(),
448 some_file.open(filename);
449 mesh_pt()->output(some_file,npts);
452 some_file <<
"TEXT X=2.5,Y=93.6,F=HELV,HU=POINT,C=BLUE,H=26,T=\"time = "
453 << time_pt()->time() <<
"\"";
456 some_file <<
"GEOMETRY X=2.5,Y=98,T=LINE,C=BLUE,LT=0.4" << std::endl;
457 some_file <<
"1" << std::endl;
458 some_file <<
"2" << std::endl;
459 some_file <<
" 0 0" << std::endl;
460 some_file << time_pt()->time()*20.0 <<
" 0" << std::endl;
463 some_file <<
"ZONE I=2,J=2" << std::endl;
464 some_file <<
"0.0 0.0 0.0" << std::endl;
465 some_file <<
"1.0 0.0 0.0" << std::endl;
466 some_file <<
"0.0 1.0 0.0" << std::endl;
467 some_file <<
"1.0 1.0 0.0" << std::endl;
468 some_file <<
"ZONE I=2,J=2" << std::endl;
469 some_file <<
"0.0 0.0 1.0" << std::endl;
470 some_file <<
"1.0 0.0 1.0" << std::endl;
471 some_file <<
"0.0 1.0 1.0" << std::endl;
472 some_file <<
"1.0 1.0 1.0" << std::endl;
478 sprintf(filename,
"%s/exact_soln%i.dat",doc_info.directory().c_str(),
480 some_file.open(filename);
481 mesh_pt()->output_fct(some_file,npts,time_pt()->time(),
484 some_file <<
"ZONE I=2,J=2" << std::endl;
485 some_file <<
"0.0 0.0 0.0" << std::endl;
486 some_file <<
"1.0 0.0 0.0" << std::endl;
487 some_file <<
"0.0 1.0 0.0" << std::endl;
488 some_file <<
"1.0 1.0 0.0" << std::endl;
489 some_file <<
"ZONE I=2,J=2" << std::endl;
490 some_file <<
"0.0 0.0 1.0" << std::endl;
491 some_file <<
"1.0 0.0 1.0" << std::endl;
492 some_file <<
"0.0 1.0 1.0" << std::endl;
493 some_file <<
"1.0 1.0 1.0" << std::endl;
499 sprintf(filename,
"%s/error%i.dat",doc_info.directory().c_str(),
501 some_file.open(filename);
502 mesh_pt()->compute_error(some_file,
510 cout <<
"error: " << error << std::endl;
511 cout <<
"norm : " << norm << std::endl << std::endl;
514 Vector<double> x_ctrl(2);
515 x_ctrl[0]=Control_node_pt->x(0);
516 x_ctrl[1]=Control_node_pt->x(1);
519 trace_file << time_pt()->time() <<
" "
520 << time_pt()->dt() <<
" "
521 << Control_node_pt->value(0) <<
" "
524 << norm << std::endl;
528 sprintf(filename,
"%s/restart%i.dat",doc_info.directory().c_str(),
530 some_file.open(filename);
542 template<
class ELEMENT>
547 Problem::dump(dump_file);
556 template<
class ELEMENT>
561 Problem::read(restart_file);
572 template<
class ELEMENT>
575 double global_error = 0.0;
578 unsigned n_node = mesh_pt()->nnode();
581 for(
unsigned i=0;i<n_node;i++)
585 double error = mesh_pt()->node_pt(i)->time_stepper_pt()->
586 temporal_error_in_value(mesh_pt()->node_pt(i),0);
589 global_error += error*error;
593 global_error /= double(n_node);
596 return sqrt(global_error);
612 int main(
int argc,
char* argv[])
616 CommandLineArgs::setup(argc,argv);
626 doc_info.set_directory(
"RESLT");
634 sprintf(filename,
"%s/trace.dat",doc_info.directory().c_str());
635 trace_file.open(filename);
636 trace_file <<
"VARIABLES=\"time\",\"dt\",\"u<SUB>FE</SUB>\","
637 <<
"\"u<SUB>exact</SUB>\",\"norm of error\",\"norm of solution\""
649 double dt=problem.time_pt()->dt();
658 double epsilon_t=1.0e-4;
662 while (problem.time_pt()->time()<t_max)
671 double dt_next=problem.adaptive_unsteady_newton_solve(dt,epsilon_t);
///////////////////////////////////////////////////////////////////// ///////////////////////////////...
UnsteadyHeatEquations< 2 >::UnsteadyHeatSourceFctPt Source_fct_pt
Pointer to source function.
void doc_solution(DocInfo &doc_info, ofstream &trace_file)
Doc the solution.
Node * Control_node_pt
Pointer to control node at which the solution is documented.
void actions_before_implicit_timestep()
Update the problem specs before next timestep: Set Dirchlet boundary conditions from exact solution.
double global_temporal_error_norm()
Global error norm for adaptive time-stepping.
void actions_after_newton_solve()
Update the problem specs after solve (empty)
void set_initial_condition()
Set initial condition (incl previous timesteps) according to specified function.
void dump_it(ofstream &dump_file)
Dump problem to disk to allow for restart.
void actions_before_newton_solve()
Update the problem specs before solve (empty)
UnsteadyHeatProblem(UnsteadyHeatEquations< 2 >::UnsteadyHeatSourceFctPt source_fct_pt)
Constructor.
~UnsteadyHeatProblem()
Destructor (empty)
void restart(ifstream &restart_file)
Read problem for restart from specified restart file.
void actions_after_implicit_timestep()
Update the problem specs after solve (empty)
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
double Gamma
Factor controlling the rate of change.
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(int argc, char *argv[])
///////////////////////////////////////////////////////////////////// ///////////////////////////////...