68 class DG_Solver :
public Solver
80 BlockILU::Reordering::MINIMUM_DISCARDED_FILL),
83 linear_solver.iterative_mode =
false;
84 linear_solver.SetRelTol(1e-9);
85 linear_solver.SetAbsTol(0.0);
86 linear_solver.SetMaxIter(100);
87 linear_solver.SetPrintLevel(0);
88 linear_solver.SetPreconditioner(prec);
91 void SetTimeStep(
double dt_)
102 linear_solver.SetOperator(A);
106 void SetOperator(
const Operator &op)
108 linear_solver.SetOperator(op);
113 linear_solver.Mult(x, y);
129 DG_Solver *dg_solver;
137 virtual void ImplicitSolve(
const double dt,
const Vector &x,
Vector &k);
143 int main(
int argc,
char *argv[])
147 const char *mesh_file =
"../data/periodic-hexagon.mesh";
153 const char *device_config =
"cpu";
154 int ode_solver_type = 4;
155 double t_final = 10.0;
157 bool visualization =
true;
159 bool paraview =
false;
164 cout.precision(precision);
167 args.
AddOption(&mesh_file,
"-m",
"--mesh",
168 "Mesh file to use.");
170 "Problem setup to use. See options in velocity_function().");
171 args.
AddOption(&ref_levels,
"-r",
"--refine",
172 "Number of times to refine the mesh uniformly.");
174 "Order (degree) of the finite elements.");
175 args.
AddOption(&pa,
"-pa",
"--partial-assembly",
"-no-pa",
176 "--no-partial-assembly",
"Enable Partial Assembly.");
177 args.
AddOption(&ea,
"-ea",
"--element-assembly",
"-no-ea",
178 "--no-element-assembly",
"Enable Element Assembly.");
179 args.
AddOption(&fa,
"-fa",
"--full-assembly",
"-no-fa",
180 "--no-full-assembly",
"Enable Full Assembly.");
181 args.
AddOption(&device_config,
"-d",
"--device",
182 "Device configuration string, see Device::Configure().");
183 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
184 "ODE solver: 1 - Forward Euler,\n\t"
185 " 2 - RK2 SSP, 3 - RK3 SSP, 4 - RK4, 6 - RK6,\n\t"
186 " 11 - Backward Euler,\n\t"
187 " 12 - SDIRK23 (L-stable), 13 - SDIRK33,\n\t"
188 " 22 - Implicit Midpoint Method,\n\t"
189 " 23 - SDIRK23 (A-stable), 24 - SDIRK34");
190 args.
AddOption(&t_final,
"-tf",
"--t-final",
191 "Final time; start time is 0.");
192 args.
AddOption(&dt,
"-dt",
"--time-step",
194 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
195 "--no-visualization",
196 "Enable or disable GLVis visualization.");
197 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
198 "--no-visit-datafiles",
199 "Save data files for VisIt (visit.llnl.gov) visualization.");
200 args.
AddOption(¶view,
"-paraview",
"--paraview-datafiles",
"-no-paraview",
201 "--no-paraview-datafiles",
202 "Save data files for ParaView (paraview.org) visualization.");
203 args.
AddOption(&binary,
"-binary",
"--binary-datafiles",
"-ascii",
205 "Use binary (Sidre) or ascii format for VisIt data files.");
206 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
207 "Visualize every n-th timestep.");
216 Device device(device_config);
221 Mesh mesh(mesh_file, 1, 1);
227 switch (ode_solver_type)
231 case 2: ode_solver =
new RK2Solver(1.0);
break;
233 case 4: ode_solver =
new RK4Solver;
break;
234 case 6: ode_solver =
new RK6Solver;
break;
245 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
253 for (
int lev = 0; lev < ref_levels; lev++)
268 cout <<
"Number of unknowns: " << fes.
GetVSize() << endl;
295 constexpr
double alpha = -1.0;
320 ofstream omesh(
"ex9.mesh");
321 omesh.precision(precision);
323 ofstream osol(
"ex9-init.gf");
324 osol.precision(precision);
335 #ifdef MFEM_USE_SIDRE
338 MFEM_ABORT(
"Must build with MFEM_USE_SIDRE=YES for binary output.");
371 sout.
open(vishost, visport);
374 cout <<
"Unable to connect to GLVis server at "
375 << vishost <<
':' << visport << endl;
376 visualization =
false;
377 cout <<
"GLVis visualization disabled.\n";
381 sout.precision(precision);
382 sout <<
"solution\n" << mesh <<
u;
385 cout <<
"GLVis visualization paused."
386 <<
" Press space (in the GLVis window) to resume it.\n";
397 ode_solver->
Init(adv);
400 for (
int ti = 0; !done; )
402 double dt_real = min(dt, t_final - t);
403 ode_solver->
Step(u, t, dt_real);
406 done = (t >= t_final - 1e-8*dt);
408 if (done || ti % vis_steps == 0)
410 cout <<
"time step: " << ti <<
", time: " << t << endl;
414 sout <<
"solution\n" << mesh << u << flush;
436 ofstream osol(
"ex9-final.gf");
437 osol.precision(precision);
485 MFEM_VERIFY(dg_solver != NULL,
486 "Implicit time integration is not supported with partial assembly");
489 dg_solver->SetTimeStep(dt);
490 dg_solver->Mult(z, k);
506 for (
int i = 0; i <
dim; i++)
519 case 1: v(0) = 1.0;
break;
520 case 2: v(0) = sqrt(2./3.); v(1) = sqrt(1./3.);
break;
521 case 3: v(0) = sqrt(3./6.); v(1) = sqrt(2./6.); v(2) = sqrt(1./6.);
530 const double w = M_PI/2;
533 case 1: v(0) = 1.0;
break;
534 case 2: v(0) = w*X(1); v(1) = -w*X(0);
break;
535 case 3: v(0) = w*X(1); v(1) = -w*X(0); v(2) = 0.0;
break;
542 const double w = M_PI/2;
543 double d = max((X(0)+1.)*(1.-X(0)),0.) * max((X(1)+1.)*(1.-X(1)),0.);
547 case 1: v(0) = 1.0;
break;
548 case 2: v(0) = d*w*X(1); v(1) = -d*w*X(0);
break;
549 case 3: v(0) = d*w*X(1); v(1) = -d*w*X(0); v(2) = 0.0;
break;
563 for (
int i = 0; i <
dim; i++)
577 return exp(-40.*pow(X(0)-0.5,2));
581 double rx = 0.45, ry = 0.25, cx = 0., cy = -0.2, w = 10.;
584 const double s = (1. + 0.25*cos(2*M_PI*X(2)));
588 return ( erfc(w*(X(0)-cx-rx))*erfc(-w*(X(0)-cx+rx)) *
589 erfc(w*(X(1)-cy-ry))*erfc(-w*(X(1)-cy+ry)) )/16;
595 double x_ = X(0), y_ = X(1), rho, phi;
598 return pow(sin(M_PI*rho),2)*sin(3*phi);
602 const double f = M_PI;
603 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.
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
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 SetDataFormat(VTKFormat fmt)
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
Helper class for ParaView visualization data.
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)
void GetBoundingBox(Vector &min, Vector &max, int ref=2)
Returns the minimum and maximum corners of the mesh bounding box.
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]...
int Size() const
Returns the size of the vector.
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
virtual void SetTime(const double t_)
Set the current time.
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
Backward Euler ODE solver. L-stable.
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.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
void SetPrintLevel(int print_lvl)
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
virtual void Save()
Save the collection to disk.
Jacobi smoothing for a given bilinear form (no matrix necessary).
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Data collection with VisIt I/O routines.
void SetMaxIter(int max_it)
virtual void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
void SetHighOrderOutput(bool high_order_output_)
void PrintUsage(std::ostream &out) const
Print the usage message.
void SetTime(double t)
Set physical time (for time-dependent simulations)
A general vector function coefficient.
The classical explicit forth-order Runge-Kutta method, RK4.
void SetAbsTol(double atol)
virtual void ImplicitSolve(const double dt, const Vector &x, Vector &k)
Solve the equation: k = f(x + dt k, t), for the unknown k at the current time t.
void SetRelTol(double rtol)
void velocity_function(const Vector &x, Vector &v)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
int GetDof() const
Returns the number of degrees of freedom in the finite element.
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 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...
Implicit midpoint method. A-stable, not L-stable.
FE_Evolution(FiniteElementSpace &vfes_, Operator &A_, SparseMatrix &Aflux_)
NURBSExtension * NURBSext
Optional NURBS mesh extension.
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
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'.
double u0_function(const Vector &x)
void SetLevelsOfDetail(int levels_of_detail_)
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
A general function coefficient.
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
virtual void Save() override
double u(const Vector &xvec)
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
The classical forward Euler method.
virtual void Init(TimeDependentOperator &f_)
Associate a TimeDependentOperator with the ODE solver.
void SetPrefixPath(const std::string &prefix)
Set the path where the DataCollection will be saved.
double inflow_function(const Vector &x)
Arbitrary order "L2-conforming" discontinuous finite elements.
double f(const Vector &p)
bool Good() const
Return true if the command line options were parsed successfully.