80 virtual void ImplicitSolve(
const double dt,
const Vector &u,
Vector &k);
84 void SundialsSolve(
const double dt,
Vector &b);
87 void SetParameters(
const Vector &u);
89 virtual ~ConductionOperator();
105 ConductionOperator *oper;
108 SundialsJacSolver() : oper(NULL) { }
110 int InitSystem(
void *sundials_mem);
111 int SetupSystem(
void *sundials_mem,
int conv_fail,
112 const Vector &y_pred,
const Vector &f_pred,
int &jac_cur,
114 int SolveSystem(
void *sundials_mem,
Vector &b,
const Vector &weight,
116 int FreeSystem(
void *sundials_mem);
121 int main(
int argc,
char *argv[])
124 const char *mesh_file =
"../../data/star.mesh";
127 int ode_solver_type = 11;
128 double t_final = 0.5;
130 double alpha = 1.0e-2;
132 bool visualization =
true;
137 const double reltol = 1e-4, abstol = 1e-4;
140 cout.precision(precision);
143 args.
AddOption(&mesh_file,
"-m",
"--mesh",
144 "Mesh file to use.");
145 args.
AddOption(&ref_levels,
"-r",
"--refine",
146 "Number of times to refine the mesh uniformly.");
148 "Order (degree) of the finite elements.");
149 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
151 "\t 1/11 - CVODE (explicit/implicit),\n"
152 "\t 2/12 - ARKODE (default explicit/implicit),\n"
153 "\t 3 - ARKODE (Fehlberg-6-4-5)\n"
154 "\t 4 - Forward Euler, 5 - RK2, 6 - RK3 SSP, 7 - RK4,\n"
155 "\t 8 - Backward Euler, 9 - SDIRK23, 10 - SDIRK33.");
156 args.
AddOption(&t_final,
"-tf",
"--t-final",
157 "Final time; start time is 0.");
158 args.
AddOption(&dt,
"-dt",
"--time-step",
161 "Alpha coefficient.");
163 "Kappa coefficient offset.");
164 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
165 "--no-visualization",
166 "Enable or disable GLVis visualization.");
167 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
168 "--no-visit-datafiles",
169 "Save data files for VisIt (visit.llnl.gov) visualization.");
170 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
171 "Visualize every n-th timestep.");
182 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
191 SundialsJacSolver sun_solver;
192 switch (ode_solver_type)
199 ode_solver = cvode;
break;
205 ode_solver = cvode;
break;
211 if (ode_solver_type == 3) { arkode->
SetERKTableNum(FEHLBERG_13_7_8); }
212 ode_solver = arkode;
break;
218 ode_solver = arkode;
break;
221 case 5: ode_solver =
new RK2Solver(0.5);
break;
223 case 7: ode_solver =
new RK4Solver;
break;
229 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
241 for (
int lev = 0; lev < ref_levels; lev++)
252 cout <<
"Number of temperature unknowns: " << fe_size << endl;
264 ConductionOperator oper(fespace, alpha, kappa, u);
268 ofstream omesh(
"ex16.mesh");
269 omesh.precision(precision);
271 ofstream osol(
"ex16-init.gf");
272 osol.precision(precision);
288 char vishost[] =
"localhost";
290 sout.
open(vishost, visport);
293 cout <<
"Unable to connect to GLVis server at "
294 << vishost <<
':' << visport << endl;
295 visualization =
false;
296 cout <<
"GLVis visualization disabled.\n";
300 sout.precision(precision);
301 sout <<
"solution\n" << *mesh << u_gf;
304 cout <<
"GLVis visualization paused."
305 <<
" Press space (in the GLVis window) to resume it.\n";
311 cout <<
"Integrating the ODE ..." << endl;
314 ode_solver->
Init(oper);
317 bool last_step =
false;
318 for (
int ti = 1; !last_step; ti++)
320 double dt_real = min(dt, t_final - t);
327 ode_solver->
Step(u, t, dt_real);
329 last_step = (t >= t_final - 1e-8*dt);
331 if (last_step || (ti % vis_steps) == 0)
333 cout <<
"step " << ti <<
", t = " << t << endl;
340 sout <<
"solution\n" << *mesh << u_gf << flush;
350 oper.SetParameters(u);
358 ofstream osol(
"ex16-final.gf");
359 osol.precision(precision);
371 double kap,
const Vector &u)
373 T(NULL), current_dt(0.0), z(height)
375 const double rel_tol = 1e-8;
380 M->FormSystemMatrix(ess_tdof_list, Mmat);
382 M_solver.iterative_mode =
false;
383 M_solver.SetRelTol(rel_tol);
384 M_solver.SetAbsTol(0.0);
385 M_solver.SetMaxIter(50);
386 M_solver.SetPrintLevel(0);
387 M_solver.SetPreconditioner(M_prec);
388 M_solver.SetOperator(Mmat);
393 T_solver.iterative_mode =
false;
394 T_solver.SetRelTol(rel_tol);
395 T_solver.SetAbsTol(0.0);
396 T_solver.SetMaxIter(100);
397 T_solver.SetPrintLevel(0);
398 T_solver.SetPreconditioner(T_prec);
410 M_solver.Mult(z, du_dt);
413 void ConductionOperator::ImplicitSolve(
const double dt,
421 T =
Add(1.0, Mmat, dt, Kmat);
423 T_solver.SetOperator(*T);
425 MFEM_VERIFY(dt == current_dt,
"");
428 T_solver.Mult(z, du_dt);
431 void ConductionOperator::SundialsSolve(
const double dt,
Vector &b)
434 if (!T || dt != current_dt)
437 T =
Add(1.0, Mmat, dt, Kmat);
439 T_solver.SetOperator(*T);
445 void ConductionOperator::SetParameters(
const Vector &u)
448 u_alpha_gf.SetFromTrueDofs(u);
449 for (
int i = 0; i < u_alpha_gf.Size(); i++)
461 K->FormSystemMatrix(ess_tdof_list, Kmat);
466 ConductionOperator::~ConductionOperator()
474 int SundialsJacSolver::InitSystem(
void *sundials_mem)
479 oper =
dynamic_cast<ConductionOperator*
>(td_oper);
480 MFEM_VERIFY(oper,
"operator is not ConductionOperator");
488 int SundialsJacSolver::SetupSystem(
void *sundials_mem,
int conv_fail,
490 int &jac_cur,
Vector &v_temp1,
498 int SundialsJacSolver::SolveSystem(
void *sundials_mem,
Vector &b,
502 oper->SundialsSolve(GetTimeStep(sundials_mem), b);
507 int SundialsJacSolver::FreeSystem(
void *sundials_mem)
virtual void Print(std::ostream &out=mfem::out) const
Conjugate gradient method.
Class for grid function - Vector with associated FE space.
double InitialTemperature(const Vector &x)
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
Data type for scaled Jacobi-type smoother of sparse matrix.
void SetSStolerances(double reltol, double abstol)
Set the scalar relative and scalar absolute tolerances.
virtual void Init(TimeDependentOperator &f)
Associate a TimeDependentOperator with the ODE solver.
Base abstract class for time dependent operators.
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
double Norml2() const
Returns the l2 norm of the vector.
virtual void Step(Vector &x, double &t, double &dt)=0
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in]...
void SetStepMode(int itask)
ARKode supports two modes, specified by itask: ARK_NORMAL (default) and ARK_ONE_STEP.
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
virtual void Save()
Save the collection and a VisIt root file.
void SetLinearSolver(SundialsODELinearSolver &ls_spec)
Backward Euler ODE solver. L-stable.
void SetSStolerances(double reltol, double abstol)
Specify the scalar relative and scalar absolute tolerances.
void SetERKTableNum(int table_num)
Choose a specific Butcher table for explicit RK method.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
void Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
Wrapper for SUNDIALS' CVODE library – Multi-step time integration.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Data collection with VisIt I/O routines.
void SetMaxStep(double dt_max)
Set the maximum time step of the linear multistep method.
void GetTrueDofs(Vector &tv) const
Extract the true-dofs from the GridFunction. If all dofs are true, then tv will be set to point to th...
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
void PrintUsage(std::ostream &out) const
void SetTime(double t)
Set physical time (for time-dependent simulations)
Wrapper for SUNDIALS' ARKODE library – Runge-Kutta time integration.
void SetLinearSolver(SundialsODELinearSolver &ls_spec)
Set a custom Jacobian system solver for implicit methods.
The classical explicit forth-order Runge-Kutta method, RK4.
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
Third-order, strong stability preserving (SSP) Runge-Kutta method.
Abstract base class, wrapping the custom linear solvers interface in SUNDIALS' CVODE and ARKODE solve...
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection and update the root file.
void PrintOptions(std::ostream &out) const
virtual void ProjectCoefficient(Coefficient &coeff)
int open(const char hostname[], int port)
class for C-function coefficient
Arbitrary order H1-conforming (continuous) finite elements.
void PrintInfo() const
Print CVODE statistics.
The classical forward Euler method.
void SetMaxStep(double dt_max)
Set the maximum time step of the Runge-Kutta method.
virtual void SetFromTrueDofs(const Vector &tv)
Set the GridFunction from the given true-dof vector.
void PrintInfo() const
Print ARKODE statistics.
void SetStepMode(int itask)
CVode supports two modes, specified by itask: CV_NORMAL (default) and CV_ONE_STEP.