69 virtual ~FE_Evolution() { }
73 int main(
int argc,
char *argv[])
77 const char *mesh_file =
"../data/periodic-hexagon.mesh";
80 int ode_solver_type = 4;
81 double t_final = 10.0;
83 bool visualization =
true;
88 cout.precision(precision);
91 args.
AddOption(&mesh_file,
"-m",
"--mesh",
94 "Problem setup to use. See options in velocity_function().");
95 args.
AddOption(&ref_levels,
"-r",
"--refine",
96 "Number of times to refine the mesh uniformly.");
98 "Order (degree) of the finite elements.");
99 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
100 "ODE solver: 1 - Forward Euler, 2 - RK2 SSP, 3 - RK3 SSP,"
101 " 4 - RK4, 6 - RK6.");
102 args.
AddOption(&t_final,
"-tf",
"--t-final",
103 "Final time; start time is 0.");
104 args.
AddOption(&dt,
"-dt",
"--time-step",
106 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
107 "--no-visualization",
108 "Enable or disable GLVis visualization.");
109 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
110 "--no-visit-datafiles",
111 "Save data files for VisIt (visit.llnl.gov) visualization.");
112 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
113 "Visualize every n-th timestep.");
125 ifstream imesh(mesh_file);
128 cerr <<
"\nCan not open mesh file: " << mesh_file <<
'\n' << endl;
131 mesh =
new Mesh(imesh, 1, 1);
138 switch (ode_solver_type)
141 case 2: ode_solver =
new RK2Solver(1.0);
break;
143 case 4: ode_solver =
new RK4Solver;
break;
144 case 6: ode_solver =
new RK6Solver;
break;
146 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
154 for (
int lev = 0; lev < ref_levels; lev++)
161 int mesh_order = std::max(order, 1);
173 cout <<
"Number of unknowns: " << fes.
GetVSize() << endl;
209 ofstream omesh(
"ex9.mesh");
210 omesh.precision(precision);
212 ofstream osol(
"ex9-init.gf");
213 osol.precision(precision);
229 char vishost[] =
"localhost";
231 sout.
open(vishost, visport);
234 cout <<
"Unable to connect to GLVis server at "
235 << vishost <<
':' << visport << endl;
236 visualization =
false;
237 cout <<
"GLVis visualization disabled.\n";
241 sout.precision(precision);
242 sout <<
"solution\n" << *mesh << u;
245 cout <<
"GLVis visualization paused."
246 <<
" Press space (in the GLVis window) to resume it.\n";
254 ode_solver->
Init(adv);
257 for (
int ti = 0;
true; )
259 if (t >= t_final - dt/2)
264 ode_solver->
Step(u, t, dt);
267 if (ti % vis_steps == 0)
269 cout <<
"time step: " << ti <<
", time: " << t << endl;
273 sout <<
"solution\n" << *mesh << u << flush;
288 ofstream osol(
"ex9-final.gf");
289 osol.precision(precision);
305 M_solver.SetPreconditioner(M_prec);
306 M_solver.SetOperator(M);
308 M_solver.iterative_mode =
false;
309 M_solver.SetRelTol(1e-9);
310 M_solver.SetAbsTol(0.0);
311 M_solver.SetMaxIter(100);
312 M_solver.SetPrintLevel(0);
336 case 1: v(0) = 1.0;
break;
337 case 2: v(0) = sqrt(2./3.); v(1) = sqrt(1./3.);
break;
338 case 3: v(0) = sqrt(3./6.); v(1) = sqrt(2./6.); v(2) = sqrt(1./6.);
347 const double w = M_PI/2;
350 case 1: v(0) = 1.0;
break;
351 case 2: v(0) = w*x(1); v(1) = -w*x(0);
break;
352 case 3: v(0) = w*x(1); v(1) = -w*x(0); v(2) = 0.0;
break;
359 const double w = M_PI/2;
360 double d = max((x(0)+1.)*(1.-x(0)),0.) * max((x(1)+1.)*(1.-x(1)),0.);
364 case 1: v(0) = 1.0;
break;
365 case 2: v(0) = d*w*x(1); v(1) = -d*w*x(0);
break;
366 case 3: v(0) = d*w*x(1); v(1) = -d*w*x(0); v(2) = 0.0;
break;
386 return exp(-40.*pow(x(0)-0.5,2));
390 double rx = 0.45, ry = 0.25, cx = 0., cy = -0.2, w = 10.;
393 const double s = (1. + 0.25*cos(2*M_PI*x(2)));
397 return ( erfc(w*(x(0)-cx-rx))*erfc(-w*(x(0)-cx+rx)) *
398 erfc(w*(x(1)-cy-ry))*erfc(-w*(x(1)-cy+ry)) )/16;
404 const double r = sqrt(8.);
405 double x_ = x(0), y_ = x(1), rho, phi;
406 rho = hypot(x_, y_) / r;
408 return pow(sin(M_PI*rho),2)*sin(3*phi);
412 const double f = M_PI;
413 return sin(f*x(0))*sin(f*x(1));
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.
virtual void RegisterField(const char *field_name, GridFunction *gf)
Add a grid function to the collection and update the root file.
Base abstract class for time dependent operators: (x,t) -> f(x,t)
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
virtual void Step(Vector &x, double &t, double &dt)=0
int Size() const
Returns the size of the vector.
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
virtual void Save()
Save the collection and a VisIt root file.
virtual void Init(TimeDependentOperator &_f)
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Data collection with VisIt I/O routines.
void SetNodalFESpace(FiniteElementSpace *nfes)
void PrintUsage(std::ostream &out) const
void SetTime(double t)
Set physical time (for time-dependent simulations)
virtual void Print(std::ostream &out=std::cout) const
Print the mesh to the given stream using the default MFEM mesh format.
The classical explicit forth-order Runge-Kutta method, RK4.
int main(int argc, char *argv[])
void velocity_function(const Vector &x, Vector &v)
Abstract finite element space.
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.
NURBSExtension * NURBSext
void PrintOptions(std::ostream &out) const
void ProjectCoefficient(Coefficient &coeff)
int open(const char hostname[], int port)
double u0_function(const Vector &x)
class for C-function coefficient
void GetNodes(Vector &node_coord) const
Arbitrary order H1-conforming (continuous) finite elements.
The classical forward Euler method.
double inflow_function(const Vector &x)
Arbitrary order "L2-conforming" discontinuous finite elements.