60int main(
int argc,
char *argv[])
64 const real_t specific_heat_ratio = 1.4;
65 const real_t gas_constant = 1.0;
67 string mesh_file =
"";
68 int IntOrderOffset = 1;
71 int ode_solver_type = 4;
75 bool visualization =
true;
76 bool preassembleWeakDiv =
true;
80 cout.precision(precision);
83 args.
AddOption(&mesh_file,
"-m",
"--mesh",
84 "Mesh file to use. If not provided, then a periodic square"
85 " mesh will be used.");
87 "Problem setup to use. See EulerInitialCondition().");
88 args.
AddOption(&ref_levels,
"-r",
"--refine",
89 "Number of times to refine the mesh uniformly.");
91 "Order (degree) of the finite elements.");
92 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
93 "ODE solver: 1 - Forward Euler,\n\t"
94 " 2 - RK2 SSP, 3 - RK3 SSP, 4 - RK4, 6 - RK6.");
95 args.
AddOption(&t_final,
"-tf",
"--t-final",
"Final time; start time is 0.");
97 "Time step. Positive number skips CFL timestep calculation.");
98 args.
AddOption(&cfl,
"-c",
"--cfl-number",
99 "CFL number for timestep calculation.");
100 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
101 "--no-visualization",
102 "Enable or disable GLVis visualization.");
103 args.
AddOption(&preassembleWeakDiv,
"-ea",
"--element-assembly-divergence",
104 "-mf",
"--matrix-free-divergence",
105 "Weak divergence assembly level\n"
106 " ea - Element assembly with interpolated F\n"
107 " mf - Nonlinear assembly in matrix-free manner");
108 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
109 "Visualize every n-th timestep.");
116 const int num_equations =
dim + 2;
121 for (
int lev = 0; lev < ref_levels; lev++)
129 switch (ode_solver_type)
132 case 2: ode_solver =
new RK2Solver(1.0);
break;
134 case 4: ode_solver =
new RK4Solver;
break;
135 case 6: ode_solver =
new RK6Solver;
break;
137 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
154 cout <<
"Number of unknowns: " << vfes.
GetVSize() << endl;
169 ostringstream mesh_name;
170 mesh_name <<
"euler-mesh.mesh";
171 ofstream mesh_ofs(mesh_name.str().c_str());
172 mesh_ofs.precision(precision);
175 for (
int k = 0; k < num_equations; k++)
178 ostringstream sol_name;
179 sol_name <<
"euler-" << k <<
"-init.gf";
180 ofstream sol_ofs(sol_name.str().c_str());
181 sol_ofs.precision(precision);
190 vfes, std::unique_ptr<HyperbolicFormIntegrator>(
204 visualization =
false;
205 cout <<
"Unable to connect to GLVis server at " <<
vishost <<
':'
207 cout <<
"GLVis visualization disabled.\n";
211 sout.precision(precision);
213 sout <<
"solution\n" << mesh << mom;
214 sout <<
"window_title 'momentum, t = 0'\n";
215 sout <<
"view 0 0\n";
216 sout <<
"keys jlm\n";
219 cout <<
"GLVis visualization paused."
220 <<
" Press space (in the GLVis window) to resume it.\n";
231 for (
int i = 0; i < mesh.
GetNE(); i++)
242 dt = cfl * hmin / max_char_speed / (2 * order + 1);
252 ode_solver->
Init(euler);
256 for (
int ti = 0; !done;)
258 real_t dt_real = min(dt, t_final -
t);
260 ode_solver->
Step(sol,
t, dt_real);
264 dt = cfl * hmin / max_char_speed / (2 * order + 1);
268 done = (
t >= t_final - 1e-8 * dt);
269 if (done || ti % vis_steps == 0)
271 cout <<
"time step: " << ti <<
", time: " <<
t << endl;
274 sout <<
"window_title 'momentum, t = " <<
t <<
"'\n";
275 sout <<
"solution\n" << mesh << mom << flush;
286 ostringstream mesh_name;
287 mesh_name <<
"euler-mesh-final.mesh";
288 ofstream mesh_ofs(mesh_name.str().c_str());
289 mesh_ofs.precision(precision);
292 for (
int k = 0; k < num_equations; k++)
295 ostringstream sol_name;
296 sol_name <<
"euler-" << k <<
"-final.gf";
297 ofstream sol_ofs(sol_name.str().c_str());
298 sol_ofs.precision(precision);
305 cout <<
"Solution error: " << error << endl;
Time dependent DG operator for hyperbolic conservation laws.
void Mult(const Vector &x, Vector &y) const override
Apply nonlinear form to obtain M⁻¹(DIVF + JUMP HAT(F))
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
int GetNDofs() const
Returns number of degrees of freedom. This is the number of Local Degrees of Freedom.
Ordering::Type GetOrdering() const
Return the ordering method.
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
The classical forward Euler method.
Class for grid function - Vector with associated FE space.
virtual real_t ComputeLpError(const real_t p, Coefficient &exsol, Coefficient *weight=NULL, const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Arbitrary order "L2-conforming" discontinuous finite elements.
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
real_t GetElementSize(int i, int type=0)
Get the size of the i-th element relative to the perfect reference element.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
virtual void Init(TimeDependentOperator &f_)
Associate a TimeDependentOperator with the ODE solver.
virtual void Step(Vector &x, real_t &t, real_t &dt)=0
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in].
void ParseCheck(std::ostream &out=mfem::out)
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.
The classical explicit forth-order Runge-Kutta method, RK4.
Rusanov flux, also known as local Lax-Friedrichs, F̂ n = ½(F(u⁺,x)n + F(u⁻,x)n) - ½λ(u⁺ - u⁻) where λ...
double RealTime()
Return the number of real seconds elapsed since the stopwatch was started.
void Start()
Start the stopwatch. The elapsed time is not cleared.
void Stop()
Stop the stopwatch.
void Clear()
Clear the elapsed time on the stopwatch and restart it if it's running.
virtual void SetTime(const real_t t_)
Set the current time.
A general vector function coefficient.
int Size() const
Returns the size of the vector.
real_t * GetData() const
Return a pointer to the beginning of the Vector data.
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
Mesh EulerMesh(const int problem)
VectorFunctionCoefficient EulerInitialCondition(const int problem, const real_t specific_heat_ratio, const real_t gas_constant)