80 virtual void ImplicitSolve(
const double dt,
const Vector &
u,
Vector &k);
95 virtual int SUNImplicitSetup(
const Vector &x,
const Vector &fx,
96 int jok,
int *jcur,
double gamma);
100 virtual int SUNImplicitSolve(
const Vector &
b,
Vector &x,
double tol);
103 void SetParameters(
const Vector &
u);
105 virtual ~ConductionOperator();
110 int main(
int argc,
char *argv[])
113 const char *mesh_file =
"../../data/star.mesh";
116 int ode_solver_type = 9;
117 double t_final = 0.5;
119 double alpha = 1.0e-2;
121 bool visualization =
true;
126 const double reltol = 1e-4, abstol = 1e-4;
129 cout.precision(precision);
132 args.
AddOption(&mesh_file,
"-m",
"--mesh",
133 "Mesh file to use.");
134 args.
AddOption(&ref_levels,
"-r",
"--refine",
135 "Number of times to refine the mesh uniformly.");
137 "Order (degree) of the finite elements.");
138 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
140 "1 - Forward Euler,\n\t"
144 "5 - Backward Euler,\n\t"
147 "8 - CVODE (implicit Adams),\n\t"
148 "9 - CVODE (implicit BDF),\n\t"
149 "10 - ARKODE (default explicit),\n\t"
150 "11 - ARKODE (explicit Fehlberg-6-4-5),\n\t"
151 "12 - ARKODE (default impicit).");
152 args.
AddOption(&t_final,
"-tf",
"--t-final",
153 "Final time; start time is 0.");
154 args.
AddOption(&dt,
"-dt",
"--time-step",
157 "Alpha coefficient.");
159 "Kappa coefficient offset.");
160 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
161 "--no-visualization",
162 "Enable or disable GLVis visualization.");
163 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
164 "--no-visit-datafiles",
165 "Save data files for VisIt (visit.llnl.gov) visualization.");
166 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
167 "Visualize every n-th timestep.");
174 if (ode_solver_type < 1 || ode_solver_type > 12)
176 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
183 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
189 for (
int lev = 0; lev < ref_levels; lev++)
200 cout <<
"Number of temperature unknowns: " << fe_size << endl;
212 ConductionOperator oper(fespace, alpha, kappa, u);
216 ofstream omesh(
"ex16.mesh");
217 omesh.precision(precision);
219 ofstream osol(
"ex16-init.gf");
220 osol.precision(precision);
238 sout.
open(vishost, visport);
241 cout <<
"Unable to connect to GLVis server at "
242 << vishost <<
':' << visport << endl;
243 visualization =
false;
244 cout <<
"GLVis visualization disabled.\n";
248 sout.precision(precision);
249 sout <<
"solution\n" << *mesh << u_gf;
252 cout <<
"GLVis visualization paused."
253 <<
" Press space (in the GLVis window) to resume it.\n";
262 switch (ode_solver_type)
266 case 2: ode_solver =
new RK2Solver(0.5);
break;
268 case 4: ode_solver =
new RK4Solver;
break;
279 ode_solver = cvode;
break;
285 ode_solver = cvode;
break;
293 if (ode_solver_type == 11) { arkode->
SetERKTableNum(FEHLBERG_13_7_8); }
294 ode_solver = arkode;
break;
300 ode_solver = arkode;
break;
304 if (ode_solver_type < 8) { ode_solver->
Init(oper); }
313 cout <<
"Integrating the ODE ..." << endl;
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);
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,
420 T =
Add(1.0, Mmat, dt, Kmat);
421 T_solver.SetOperator(*T);
424 T_solver.Mult(z, du_dt);
427 void ConductionOperator::SetParameters(
const Vector &u)
430 u_alpha_gf.SetFromTrueDofs(u);
431 for (
int i = 0; i < u_alpha_gf.Size(); i++)
443 K->FormSystemMatrix(ess_tdof_list, Kmat);
446 int ConductionOperator::SUNImplicitSetup(
const Vector &x,
447 const Vector &fx,
int jok,
int *jcur,
452 T =
Add(1.0, Mmat, gamma, Kmat);
453 T_solver.SetOperator(*T);
458 int ConductionOperator::SUNImplicitSolve(
const Vector &
b,
Vector &x,
double tol)
466 ConductionOperator::~ConductionOperator()
void Init(TimeDependentOperator &f_)
Initialize CVODE: calls CVodeCreate() to create the CVODE memory and set some defaults.
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.
void SetStepMode(int itask)
Select the ARKode step mode: ARK_NORMAL (default) or ARK_ONE_STEP.
Base abstract class for first order 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]...
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 SetMaxStep(double dt_max)
Set the maximum time step.
Backward Euler ODE solver. L-stable.
void Stop()
Stop the stopwatch.
Interface to ARKode's ARKStep module – additive Runge-Kutta methods.
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.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
Interface to the CVODE library – linear multi-step methods.
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.
void GetTrueDofs(Vector &tv) const
Extract the true-dofs from the GridFunction.
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
void PrintUsage(std::ostream &out) const
Print the usage message.
void SetTime(double t)
Set physical time (for time-dependent simulations)
void Start()
Start the stopwatch. The elapsed time is not cleared.
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)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
Third-order, strong stability preserving (SSP) Runge-Kutta method.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection and update the root file.
virtual void Print(std::ostream &os=mfem::out) const
void PrintInfo() const
Print various ARKStep statistics.
void PrintOptions(std::ostream &out) const
Print the options.
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
A general function coefficient.
Arbitrary order H1-conforming (continuous) finite elements.
void PrintInfo() const
Print various CVODE statistics.
double u(const Vector &xvec)
void SetERKTableNum(int table_num)
Choose a specific Butcher table for an explicit RK method.
The classical forward Euler method.
virtual void SetFromTrueDofs(const Vector &tv)
Set the GridFunction from the given true-dof vector.
void Init(TimeDependentOperator &f_)
Initialize ARKode: calls ARKStepCreate() to create the ARKStep memory and set some defaults...
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.
void Clear()
Clear the elapsed time on the stopwatch and restart it if it's running.
double f(const Vector &p)
void SetStepMode(int itask)
Select the CVODE step mode: CV_NORMAL (default) or CV_ONE_STEP.
bool Good() const
Return true if the command line options were parsed successfully.