61 class DG_Solver :
public Solver
75 linear_solver(M.GetComm()),
77 BlockILU::Reordering::MINIMUM_DISCARDED_FILL),
80 linear_solver.iterative_mode =
false;
81 linear_solver.SetRelTol(1e-9);
82 linear_solver.SetAbsTol(0.0);
83 linear_solver.SetMaxIter(100);
84 linear_solver.SetPrintLevel(0);
85 linear_solver.SetPreconditioner(prec);
90 void SetTimeStep(
double dt_)
97 A =
Add(-dt, K, 0.0, K);
100 A_diag.
Add(1.0, M_diag);
102 linear_solver.SetOperator(*A);
106 void SetOperator(
const Operator &op)
108 linear_solver.SetOperator(op);
113 linear_solver.Mult(x, y);
134 DG_Solver *dg_solver;
142 virtual void ImplicitSolve(
const double dt,
const Vector &x,
Vector &k);
148 int main(
int argc,
char *argv[])
152 MPI_Init(&argc, &argv);
153 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
154 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
158 const char *mesh_file =
"../data/periodic-hexagon.mesh";
159 int ser_ref_levels = 2;
160 int par_ref_levels = 0;
163 const char *device_config =
"cpu";
164 int ode_solver_type = 4;
165 double t_final = 10.0;
167 bool visualization =
true;
169 bool paraview =
false;
174 cout.precision(precision);
177 args.
AddOption(&mesh_file,
"-m",
"--mesh",
178 "Mesh file to use.");
180 "Problem setup to use. See options in velocity_function().");
181 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
182 "Number of times to refine the mesh uniformly in serial.");
183 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
184 "Number of times to refine the mesh uniformly in parallel.");
186 "Order (degree) of the finite elements.");
187 args.
AddOption(&pa,
"-pa",
"--partial-assembly",
"-no-pa",
188 "--no-partial-assembly",
"Enable Partial Assembly.");
189 args.
AddOption(&device_config,
"-d",
"--device",
190 "Device configuration string, see Device::Configure().");
191 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
192 "ODE solver: 1 - Forward Euler,\n\t"
193 " 2 - RK2 SSP, 3 - RK3 SSP, 4 - RK4, 6 - RK6,\n\t"
194 " 11 - Backward Euler,\n\t"
195 " 12 - SDIRK23 (L-stable), 13 - SDIRK33,\n\t"
196 " 22 - Implicit Midpoint Method,\n\t"
197 " 23 - SDIRK23 (A-stable), 24 - SDIRK34");
198 args.
AddOption(&t_final,
"-tf",
"--t-final",
199 "Final time; start time is 0.");
200 args.
AddOption(&dt,
"-dt",
"--time-step",
202 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
203 "--no-visualization",
204 "Enable or disable GLVis visualization.");
205 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
206 "--no-visit-datafiles",
207 "Save data files for VisIt (visit.llnl.gov) visualization.");
208 args.
AddOption(¶view,
"-paraview",
"--paraview-datafiles",
"-no-paraview",
209 "--no-paraview-datafiles",
210 "Save data files for ParaView (paraview.org) visualization.");
211 args.
AddOption(&binary,
"-binary",
"--binary-datafiles",
"-ascii",
213 "Use binary (Sidre) or ascii format for VisIt data files.");
214 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
215 "Visualize every n-th timestep.");
231 Device device(device_config);
232 if (myid == 0) { device.
Print(); }
236 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
242 switch (ode_solver_type)
246 case 2: ode_solver =
new RK2Solver(1.0);
break;
248 case 4: ode_solver =
new RK4Solver;
break;
249 case 6: ode_solver =
new RK6Solver;
break;
261 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
272 for (
int lev = 0; lev < ser_ref_levels; lev++)
287 for (
int lev = 0; lev < par_ref_levels; lev++)
300 cout <<
"Number of unknowns: " << global_vSize << endl;
346 ostringstream mesh_name, sol_name;
347 mesh_name <<
"ex9-mesh." << setfill(
'0') << setw(6) << myid;
348 sol_name <<
"ex9-init." << setfill(
'0') << setw(6) << myid;
349 ofstream omesh(mesh_name.str().c_str());
350 omesh.precision(precision);
352 ofstream osol(sol_name.str().c_str());
353 osol.precision(precision);
364 #ifdef MFEM_USE_SIDRE
367 MFEM_ABORT(
"Must build with MFEM_USE_SIDRE=YES for binary output.");
400 char vishost[] =
"localhost";
402 sout.
open(vishost, visport);
406 cout <<
"Unable to connect to GLVis server at "
407 << vishost <<
':' << visport << endl;
408 visualization =
false;
411 cout <<
"GLVis visualization disabled.\n";
416 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
417 sout.precision(precision);
418 sout <<
"solution\n" << *pmesh << *u;
422 cout <<
"GLVis visualization paused."
423 <<
" Press space (in the GLVis window) to resume it.\n";
434 ode_solver->
Init(adv);
437 for (
int ti = 0; !done; )
439 double dt_real = min(dt, t_final - t);
440 ode_solver->
Step(*U, t, dt_real);
443 done = (t >= t_final - 1e-8*dt);
445 if (done || ti % vis_steps == 0)
449 cout <<
"time step: " << ti <<
", time: " << t << endl;
458 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
459 sout <<
"solution\n" << *pmesh << *u << flush;
482 ostringstream sol_name;
483 sol_name <<
"ex9-final." << setfill(
'0') << setw(6) << myid;
484 ofstream osol(sol_name.str().c_str());
485 osol.precision(precision);
512 M_solver(_M.ParFESpace()->GetComm()),
543 dg_solver =
new DG_Solver(M_mat, K_mat, *_M.
FESpace());
558 dg_solver->SetTimeStep(dt);
559 dg_solver->Mult(z, k);
584 for (
int i = 0; i <
dim; i++)
597 case 1: v(0) = 1.0;
break;
598 case 2: v(0) = sqrt(2./3.); v(1) = sqrt(1./3.);
break;
599 case 3: v(0) = sqrt(3./6.); v(1) = sqrt(2./6.); v(2) = sqrt(1./6.);
608 const double w = M_PI/2;
611 case 1: v(0) = 1.0;
break;
612 case 2: v(0) = w*X(1); v(1) = -w*X(0);
break;
613 case 3: v(0) = w*X(1); v(1) = -w*X(0); v(2) = 0.0;
break;
620 const double w = M_PI/2;
621 double d = max((X(0)+1.)*(1.-X(0)),0.) * max((X(1)+1.)*(1.-X(1)),0.);
625 case 1: v(0) = 1.0;
break;
626 case 2: v(0) = d*w*X(1); v(1) = -d*w*X(0);
break;
627 case 3: v(0) = d*w*X(1); v(1) = -d*w*X(0); v(2) = 0.0;
break;
641 for (
int i = 0; i <
dim; i++)
655 return exp(-40.*pow(X(0)-0.5,2));
659 double rx = 0.45, ry = 0.25, cx = 0., cy = -0.2, w = 10.;
662 const double s = (1. + 0.25*cos(2*M_PI*X(2)));
666 return ( erfc(w*(X(0)-cx-rx))*erfc(-w*(X(0)-cx+rx)) *
667 erfc(w*(X(1)-cy-ry))*erfc(-w*(X(1)-cy+ry)) )/16;
673 double x_ = X(0), y_ = X(1), rho, phi;
676 return pow(sin(M_PI*rho),2)*sin(3*phi);
680 const double f = M_PI;
681 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.
void Add(const int i, const int j, const double a)
Conjugate gradient method.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
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.
Pointer to an Operator of a specified type.
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 RegisterField(const std::string &field_name, mfem::GridFunction *gf) override
Add a grid function to the collection.
virtual void Init(TimeDependentOperator &f)
Associate a TimeDependentOperator with the ODE solver.
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)
virtual void Save(std::ostream &out) const
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
Abstract parallel finite element space.
virtual void ProjectCoefficient(Coefficient &coeff)
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
int main(int argc, char *argv[])
Backward Euler ODE solver. L-stable.
FE_Evolution(FiniteElementSpace &_vfes, Operator &_A, SparseMatrix &_Aflux)
Data collection with Sidre routines following the Conduit mesh blueprint specification.
void Add(const DenseMatrix &A, const DenseMatrix &B, double alpha, DenseMatrix &C)
C = A + alpha*B.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
void SetPrintLevel(int print_lvl)
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)
HYPRE_Int GlobalTrueVSize() const
virtual void Print(std::ostream &out=mfem::out) const
Parallel smoothers in hypre.
void SetHighOrderOutput(bool high_order_output_)
void PrintUsage(std::ostream &out) const
void SetTime(double t)
Set physical time (for time-dependent simulations)
Wrapper for hypre's parallel vector class.
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)
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.
NURBSExtension * NURBSext
Optional NURBS mesh extension.
void GetDiag(Vector &d) const
Returns the Diagonal of A.
const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement associated with i'th element.
void PrintOptions(std::ostream &out) const
HypreParVector * GetTrueDofs() const
Returns the true dofs in a new HypreParVector.
int open(const char hostname[], int port)
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.
class for C-function coefficient
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
virtual void Save() override
Class for parallel grid function.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
The classical forward Euler method.
Wrapper for hypre's ParCSR matrix class.
Class for parallel meshes.
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.