41template<
int problem=0>
48 for (
int i = 0; i <
dim; i++)
60 case 1: v(0) = 1.0;
break;
61 case 2: v(0) = sqrt(2./3.); v(1) = sqrt(1./3.);
break;
62 case 3: v(0) = sqrt(3./6.); v(1) = sqrt(2./6.); v(2) = sqrt(1./6.);
74 case 1: v(0) = 1.0;
break;
75 case 2: v(0) = w*X(1); v(1) = -w*X(0);
break;
76 case 3: v(0) = w*X(1); v(1) = -w*X(0); v(2) = 0.0;
break;
84 real_t d = max((X(0)+1.)*(1.-X(0)),0.) * max((X(1)+1.)*(1.-X(1)),0.);
88 case 1: v(0) = 1.0;
break;
89 case 2: v(0) = d*w*X(1); v(1) = -d*w*X(0);
break;
90 case 3: v(0) = d*w*X(1); v(1) = -d*w*X(0); v(2) = 0.0;
break;
98template<
int problem=0>
105 for (
int i = 0; i <
dim; i++)
119 return exp(-40.*pow(X(0)-0.5,2));
123 real_t rx = 0.45, ry = 0.25, cx = 0., cy = -0.2, w = 10.;
126 const real_t s = (1. + 0.25*cos(2*M_PI*X(2)));
130 return ( std::erfc(w*(X(0)-cx-rx))*std::erfc(-w*(X(0)-cx+rx)) *
131 std::erfc(w*(X(1)-cy-ry))*std::erfc(-w*(X(1)-cy+ry)) )/16;
137 real_t x_ = X(0), y_ = X(1), rho, phi;
138 rho = std::hypot(x_, y_);
140 return pow(sin(M_PI*rho),2)*sin(3*phi);
145 return sin(
f*X(0))*sin(
f*X(1));
153class Implicit_Solver :
public Solver
165 prec(fes.GetTypicalFE()->GetDof(),
166 BlockILU::Reordering::MINIMUM_DISCARDED_FILL),
177 void SetTimeStep(
real_t dt_)
182 epsilon = std::numeric_limits<real_t>::epsilon();
198 void SetOperator(
const Operator &op)
override
205 linear_solver.
Mult(x, y);
220 unique_ptr<Solver> M_prec;
222 unique_ptr<Implicit_Solver> implicit_solver;
238 if (TimeDependentOperator::EvalMode::ADDITIVE_TERM_1 ==
GetEvalMode())
244 mfem_error(
"TimeDependentOperator::Mult() is not overridden!");
250 if (TimeDependentOperator::EvalMode::ADDITIVE_TERM_2 ==
GetEvalMode())
252 ImplicitSolve2(dt,x,k);
256 mfem_error(
"TimeDependentOperator::ImplicitSolve() is not overridden!");
263int main(
int argc,
char *argv[])
267 const char *mesh_file =
"../data/periodic-square.mesh";
270 int ode_solver_type = 64;
273 bool paraview =
false;
276 real_t diffusion_term = 0.01;
279 bool visualization =
true;
284 args.
AddOption(&mesh_file,
"-m",
"--mesh",
"Mesh file to use.");
286 "Problem setup to use. See options in velocity_function().");
287 args.
AddOption(&ref_levels,
"-r",
"--refine",
288 "Number of times to refine the mesh uniformly.");
289 args.
AddOption(&order,
"-o",
"--order",
"Order of the finite elements.");
290 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
292 args.
AddOption(&t_final,
"-tf",
"--t-final",
"Final time; start time is 0.");
293 args.
AddOption(&dt,
"-dt",
"--time-step",
"Time step.");
294 args.
AddOption(&diffusion_term,
"-dc",
"--diffusion-coeff",
295 "Diffusion coefficient in the PDE.");
296 args.
AddOption(¶view,
"-paraview",
"--paraview-datafiles",
"-no-paraview",
297 "--no-paraview-datafiles",
298 "Save data files for ParaView (paraview.org) visualization.");
299 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
300 "Visualize every n-th timestep.");
301 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
302 "--no-visualization",
303 "Enable or disable GLVis visualization.");
304 args.
AddOption(&binary,
"-binary",
"--binary-datafiles",
"-ascii",
306 "Use binary (Sidre) or ascii format for VisIt data files.");
307 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
308 "--no-visit-datafiles",
309 "Save data files for VisIt (visit.llnl.gov) visualization.");
310 args.
AddOption(&cg,
"-cg",
"--continuous-galerkin",
"-dg",
311 "--discontinuous-galerkin",
312 "Use Continuous-Galerkin Finite elements (Default is DG)");
321 kappa = (order+1)*(order+1);
327 Mesh mesh(mesh_file);
355 cout <<
"Number of unknowns: " << fes.
GetVSize() << endl;
360 std::unique_ptr<VectorFunctionCoefficient> velocity;
414 std::unique_ptr<FunctionCoefficient> u0;
433 u.ProjectCoefficient(*u0);
445 MFEM_ABORT(
"Must build with MFEM_USE_SIDRE=YES for binary output.");
460 unique_ptr<ParaViewDataCollection> pv;
463 pv = make_unique<ParaViewDataCollection>(
"Example41", &mesh);
464 pv->SetPrefixPath(
"ParaView");
465 pv->RegisterField(
"solution", &
u);
466 pv->SetLevelsOfDetail(order);
467 pv->SetDataFormat(VTKFormat::BINARY);
468 pv->SetHighOrderOutput(
true);
482 cout <<
"Unable to connect to GLVis server at "
483 <<
vishost <<
':' << visport << endl;
484 visualization =
false;
485 cout <<
"GLVis visualization disabled.\n";
489 sout.precision(precision);
490 sout <<
"solution\n" << mesh <<
u;
493 cout <<
"GLVis visualization paused."
494 <<
" Press space (in the GLVis window) to resume it.\n";
501 IMEX_Evolution adv(m, k, s,
b);
505 ode_solver->Init(adv);
508 for (
int ti = 0; !done; )
510 real_t dt_real = min(dt, t_final - t);
511 ode_solver->Step(
u, t, dt_real);
514 done = (t >= t_final - 1e-8*dt);
516 if (done || ti % vis_steps == 0)
518 cout <<
"time step: " << ti <<
", time: " << t << endl;
527 sout <<
"solution\n" << mesh <<
u << flush;
548 M(M_), K(K_), S(S_),
b(b_), z(height)
553 M_prec = make_unique<DSmoother>(M.
SpMat());
555 implicit_solver = make_unique<Implicit_Solver>(M.
SpMat(), S.
SpMat(),
560 MFEM_ABORT(
"Implicit time integration is not supported with partial assembly");
570void IMEX_Evolution::Mult1(
const Vector &x,
Vector &y)
const
583 MFEM_VERIFY(implicit_solver != NULL,
584 "Implicit time integration is not supported with partial assembly");
587 implicit_solver->SetTimeStep(dt);
588 implicit_solver->Mult(z, k);
@ GaussLobatto
Closed type.
Conjugate gradient method.
void Mult(const Vector &b, Vector &x) const override
Iterative solution of the linear system using the Conjugate Gradient method.
void SetOperator(const Operator &op) override
Set/update the solver for the given operator.
A coefficient that is constant across space and time.
void SetPrecision(int prec)
Set the precision (number of digits) used for the text output of doubles.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
void SetTime(real_t t)
Set physical time (for time-dependent simulations)
virtual void Save()
Save the collection to disk.
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
A general function coefficient.
Class for grid function - Vector with associated FE space.
Arbitrary order H1-conforming (continuous) finite elements.
void SetRelTol(real_t rtol)
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
void SetMaxIter(int max_it)
void SetAbsTol(real_t atol)
NURBSExtension * NURBSext
Optional NURBS mesh extension.
void GetBoundingBox(Vector &min, Vector &max, int ref=2)
Returns the minimum and maximum corners of the mesh bounding box.
int Dimension() const
Dimension of the reference space used within the elements.
virtual void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
Set the curvature of the mesh nodes using the given polynomial degree.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
static MFEM_EXPORT std::unique_ptr< ODESolver > SelectIMEX(const int ode_solver_type)
static MFEM_EXPORT std::string IMEXTypes
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
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...
bool Good() const
Return true if the command line options were parsed successfully.
Data collection with Sidre routines following the Conduit mesh blueprint specification.
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
Base abstract class for first order time dependent operators.
virtual void SetTime(const real_t t_)
Set the current time.
EvalMode GetEvalMode() const
Return the current evaluation mode. See SetEvalMode() for details.
A general vector function coefficient.
void Neg()
(*this) = -(*this)
int Size() const
Returns the size of the vector.
Data collection with VisIt I/O routines.
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
real_t sigma(const Vector &x)
void velocity_function(const Vector &x, Vector &v)
real_t u0_function(const Vector &x)
int GetTrueVSize(const FieldDescriptor &f)
Get the true dof size of a field descriptor.
real_t u(const Vector &xvec)
void mfem_error(const char *msg)
L2_FECollection DG_FECollection
Declare an alternative name for L2_FECollection = DG_FECollection.
std::function< real_t(const Vector &)> f(real_t mass_coeff)
MFEM_HOST_DEVICE Complex exp(const Complex &q)