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';
242 for (
int lev = 0; lev < ref_levels; lev++)
253 cout <<
"Number of temperature unknowns: " << fe_size << endl;
265 ConductionOperator oper(fespace, alpha, kappa, u);
269 ofstream omesh(
"ex16.mesh");
270 omesh.precision(precision);
272 ofstream osol(
"ex16-init.gf");
273 osol.precision(precision);
289 char vishost[] =
"localhost";
291 sout.
open(vishost, visport);
294 cout <<
"Unable to connect to GLVis server at "
295 << vishost <<
':' << visport << endl;
296 visualization =
false;
297 cout <<
"GLVis visualization disabled.\n";
301 sout.precision(precision);
302 sout <<
"solution\n" << *mesh << u_gf;
305 cout <<
"GLVis visualization paused."
306 <<
" Press space (in the GLVis window) to resume it.\n";
312 cout <<
"Integrating the ODE ..." << endl;
315 ode_solver->
Init(oper);
318 bool last_step =
false;
319 for (
int ti = 1; !last_step; ti++)
321 double dt_real = min(dt, t_final - t);
328 ode_solver->
Step(u, t, dt_real);
330 last_step = (t >= t_final - 1e-8*dt);
332 if (last_step || (ti % vis_steps) == 0)
334 cout <<
"step " << ti <<
", t = " << t << endl;
341 sout <<
"solution\n" << *mesh << u_gf << flush;
351 oper.SetParameters(u);
359 ofstream osol(
"ex16-final.gf");
360 osol.precision(precision);
372 double kap,
const Vector &u)
374 T(NULL), current_dt(0.0), z(height)
376 const double rel_tol = 1e-8;
381 M->FormSystemMatrix(ess_tdof_list, Mmat);
383 M_solver.iterative_mode =
false;
384 M_solver.SetRelTol(rel_tol);
385 M_solver.SetAbsTol(0.0);
386 M_solver.SetMaxIter(50);
387 M_solver.SetPrintLevel(0);
388 M_solver.SetPreconditioner(M_prec);
389 M_solver.SetOperator(Mmat);
394 T_solver.iterative_mode =
false;
395 T_solver.SetRelTol(rel_tol);
396 T_solver.SetAbsTol(0.0);
397 T_solver.SetMaxIter(100);
398 T_solver.SetPrintLevel(0);
399 T_solver.SetPreconditioner(T_prec);
411 M_solver.Mult(z, du_dt);
414 void ConductionOperator::ImplicitSolve(
const double dt,
422 T =
Add(1.0, Mmat, dt, Kmat);
424 T_solver.SetOperator(*T);
426 MFEM_VERIFY(dt == current_dt,
"");
429 T_solver.Mult(z, du_dt);
432 void ConductionOperator::SundialsSolve(
const double dt,
Vector &b)
435 if (!T || dt != current_dt)
438 T =
Add(1.0, Mmat, dt, Kmat);
440 T_solver.SetOperator(*T);
446 void ConductionOperator::SetParameters(
const Vector &u)
449 u_alpha_gf.SetFromTrueDofs(u);
450 for (
int i = 0; i < u_alpha_gf.Size(); i++)
462 K->FormSystemMatrix(ess_tdof_list, Kmat);
467 ConductionOperator::~ConductionOperator()
475 int SundialsJacSolver::InitSystem(
void *sundials_mem)
480 oper =
dynamic_cast<ConductionOperator*
>(td_oper);
481 MFEM_VERIFY(oper,
"operator is not ConductionOperator");
489 int SundialsJacSolver::SetupSystem(
void *sundials_mem,
int conv_fail,
491 int &jac_cur,
Vector &v_temp1,
499 int SundialsJacSolver::SolveSystem(
void *sundials_mem,
Vector &b,
503 oper->SundialsSolve(GetTimeStep(sundials_mem), b);
508 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)
int main(int argc, char *argv[])
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.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
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.