33 #ifndef MFEM_USE_SUNDIALS
34 #error This example requires that MFEM is built with MFEM_USE_SUNDIALS=YES
81 int main(
int argc,
char *argv[])
85 const char *mesh_file =
"../../data/periodic-hexagon.mesh";
88 int ode_solver_type = 4;
89 double t_final = 10.0;
91 bool visualization =
true;
97 const double reltol = 1e-2, abstol = 1e-2;
100 cout.precision(precision);
103 args.
AddOption(&mesh_file,
"-m",
"--mesh",
104 "Mesh file to use.");
106 "Problem setup to use. See options in velocity_function().");
107 args.
AddOption(&ref_levels,
"-r",
"--refine",
108 "Number of times to refine the mesh uniformly.");
110 "Order (degree) of the finite elements.");
111 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
112 "ODE solver: 1 - Forward Euler,\n\t"
113 " 2 - RK2 SSP, 3 - RK3 SSP, 4 - RK4, 6 - RK6,\n\t"
114 " 11 - CVODE (adaptive order) explicit,\n\t"
115 " 12 - ARKODE default (4th order) explicit,\n\t"
116 " 13 - ARKODE RK8.");
117 args.
AddOption(&t_final,
"-tf",
"--t-final",
118 "Final time; start time is 0.");
119 args.
AddOption(&dt,
"-dt",
"--time-step",
121 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
122 "--no-visualization",
123 "Enable or disable GLVis visualization.");
124 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
125 "--no-visit-datafiles",
126 "Save data files for VisIt (visit.llnl.gov) visualization.");
127 args.
AddOption(&binary,
"-binary",
"--binary-datafiles",
"-ascii",
129 "Use binary (Sidre) or ascii format for VisIt data files.");
130 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
131 "Visualize every n-th timestep.");
142 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
150 switch (ode_solver_type)
153 case 2: ode_solver =
new RK2Solver(1.0);
break;
155 case 4: ode_solver =
new RK4Solver;
break;
156 case 6: ode_solver =
new RK6Solver;
break;
161 ode_solver = cvode;
break;
167 if (ode_solver_type == 13) { arkode->
SetERKTableNum(FEHLBERG_13_7_8); }
168 ode_solver = arkode;
break;
170 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
178 for (
int lev = 0; lev < ref_levels; lev++)
193 cout <<
"Number of unknowns: " << fes.
GetVSize() << endl;
229 ofstream omesh(
"ex9.mesh");
230 omesh.precision(precision);
232 ofstream osol(
"ex9-init.gf");
233 osol.precision(precision);
244 #ifdef MFEM_USE_SIDRE
247 MFEM_ABORT(
"Must build with MFEM_USE_SIDRE=YES for binary output.");
264 char vishost[] =
"localhost";
266 sout.
open(vishost, visport);
269 cout <<
"Unable to connect to GLVis server at "
270 << vishost <<
':' << visport << endl;
271 visualization =
false;
272 cout <<
"GLVis visualization disabled.\n";
276 sout.precision(precision);
277 sout <<
"solution\n" << *mesh << u;
280 cout <<
"GLVis visualization paused."
281 <<
" Press space (in the GLVis window) to resume it.\n";
292 ode_solver->
Init(adv);
295 for (
int ti = 0; !done; )
297 double dt_real = min(dt, t_final - t);
298 ode_solver->
Step(u, t, dt_real);
301 done = (t >= t_final - 1e-8*dt);
303 if (done || ti % vis_steps == 0)
305 cout <<
"time step: " << ti <<
", time: " << t << endl;
311 sout <<
"solution\n" << *mesh << u << flush;
326 ofstream osol(
"ex9-final.gf");
327 osol.precision(precision);
343 M_solver.SetPreconditioner(M_prec);
344 M_solver.SetOperator(M);
346 M_solver.iterative_mode =
false;
347 M_solver.SetRelTol(1e-9);
348 M_solver.SetAbsTol(0.0);
349 M_solver.SetMaxIter(100);
350 M_solver.SetPrintLevel(0);
369 for (
int i = 0; i <
dim; i++)
382 case 1: v(0) = 1.0;
break;
383 case 2: v(0) = sqrt(2./3.); v(1) = sqrt(1./3.);
break;
384 case 3: v(0) = sqrt(3./6.); v(1) = sqrt(2./6.); v(2) = sqrt(1./6.);
393 const double w = M_PI/2;
396 case 1: v(0) = 1.0;
break;
397 case 2: v(0) = w*X(1); v(1) = -w*X(0);
break;
398 case 3: v(0) = w*X(1); v(1) = -w*X(0); v(2) = 0.0;
break;
405 const double w = M_PI/2;
406 double d = max((X(0)+1.)*(1.-X(0)),0.) * max((X(1)+1.)*(1.-X(1)),0.);
410 case 1: v(0) = 1.0;
break;
411 case 2: v(0) = d*w*X(1); v(1) = -d*w*X(0);
break;
412 case 3: v(0) = d*w*X(1); v(1) = -d*w*X(0); v(2) = 0.0;
break;
426 for (
int i = 0; i <
dim; i++)
440 return exp(-40.*pow(X(0)-0.5,2));
444 double rx = 0.45, ry = 0.25, cx = 0., cy = -0.2, w = 10.;
447 const double s = (1. + 0.25*cos(2*M_PI*X(2)));
451 return ( erfc(w*(X(0)-cx-rx))*erfc(-w*(X(0)-cx+rx)) *
452 erfc(w*(X(1)-cy-ry))*erfc(-w*(X(1)-cy+ry)) )/16;
458 double x_ = X(0), y_ = X(1), rho, phi;
461 return pow(sin(M_PI*rho),2)*sin(3*phi);
465 const double f = M_PI;
466 return sin(f*X(0))*sin(f*X(1));
void SetPrecision(int prec)
Set the precision (number of digits) used for the text output of doubles.
virtual void Print(std::ostream &out=mfem::out) const
Conjugate gradient method.
Class for grid function - Vector with associated FE space.
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 Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
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)
void GetBoundingBox(Vector &min, Vector &max, int ref=2)
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]...
virtual void SetTime(const double _t)
Set the current time.
int Size() const
Returns the size of the vector.
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
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.
FE_Evolution(FiniteElementSpace &_vfes, Operator &_A, SparseMatrix &_Aflux)
Data collection with Sidre routines following the Conduit mesh blueprint specification.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
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 SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
void SetMaxStep(double dt_max)
Set the maximum time step of the linear multistep method.
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.
The classical explicit forth-order Runge-Kutta method, RK4.
void velocity_function(const Vector &x, Vector &v)
virtual void Mult(const Vector &x, Vector &y) const
Matrix vector multiplication.
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.
virtual void Mult(const Vector &x, Vector &y) const
Perform the action of the operator: y = k = f(x, t), where k solves the algebraic equation F(x...
NURBSExtension * NURBSext
Optional NURBS mesh extension.
void PrintOptions(std::ostream &out) const
virtual void ProjectCoefficient(Coefficient &coeff)
int open(const char hostname[], int port)
double u0_function(const Vector &x)
class for C-function coefficient
void PrintInfo() const
Print CVODE statistics.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
The classical forward Euler method.
void SetMaxStep(double dt_max)
Set the maximum time step of the Runge-Kutta method.
void PrintInfo() const
Print ARKODE statistics.
double inflow_function(const Vector &x)
Arbitrary order "L2-conforming" discontinuous finite elements.