70class DG_Solver :
public Solver
82 BlockILU::Reordering::MINIMUM_DISCARDED_FILL),
93 void SetTimeStep(
real_t dt_)
108 void SetOperator(
const Operator &op)
override
115 linear_solver.
Mult(x, y);
131 DG_Solver *dg_solver;
141 ~FE_Evolution()
override;
145int main(
int argc,
char *argv[])
149 const char *mesh_file =
"../data/periodic-hexagon.mesh";
155 const char *device_config =
"cpu";
156 int ode_solver_type = 4;
159 bool visualization =
true;
161 bool paraview =
false;
164 bool solve_implicit_state =
false;
167 cout.precision(precision);
170 args.
AddOption(&mesh_file,
"-m",
"--mesh",
171 "Mesh file to use.");
173 "Problem setup to use. See options in velocity_function().");
174 args.
AddOption(&ref_levels,
"-r",
"--refine",
175 "Number of times to refine the mesh uniformly.");
177 "Order (degree) of the finite elements.");
178 args.
AddOption(&pa,
"-pa",
"--partial-assembly",
"-no-pa",
179 "--no-partial-assembly",
"Enable Partial Assembly.");
180 args.
AddOption(&ea,
"-ea",
"--element-assembly",
"-no-ea",
181 "--no-element-assembly",
"Enable Element Assembly.");
182 args.
AddOption(&fa,
"-fa",
"--full-assembly",
"-no-fa",
183 "--no-full-assembly",
"Enable Full Assembly.");
184 args.
AddOption(&device_config,
"-d",
"--device",
185 "Device configuration string, see Device::Configure().");
186 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
188 args.
AddOption(&t_final,
"-tf",
"--t-final",
189 "Final time; start time is 0.");
190 args.
AddOption(&dt,
"-dt",
"--time-step",
192 args.
AddOption(&solve_implicit_state,
"-imp-state",
"--implicit-state",
193 "-imp-slope",
"--implicit-slope",
194 "Implicitly solve for stage state or slope.");
195 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
196 "--no-visualization",
197 "Enable or disable GLVis visualization.");
198 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
199 "--no-visit-datafiles",
200 "Save data files for VisIt (visit.llnl.gov) visualization.");
201 args.
AddOption(¶view,
"-paraview",
"--paraview-datafiles",
"-no-paraview",
202 "--no-paraview-datafiles",
203 "Save data files for ParaView (paraview.org) visualization.");
204 args.
AddOption(&binary,
"-binary",
"--binary-datafiles",
"-ascii",
206 "Use binary (Sidre) or ascii format for VisIt data files.");
207 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
208 "Visualize every n-th timestep.");
217 Device device(device_config);
222 Mesh mesh(mesh_file, 1, 1);
233 for (
int lev = 0; lev < ref_levels; lev++)
248 cout <<
"Number of unknowns: " << fes.
GetVSize() << endl;
283 b.AddBdrFaceIntegrator(
297 u.ProjectCoefficient(u0);
300 ofstream omesh(
"ex9.mesh");
301 omesh.precision(precision);
303 ofstream osol(
"ex9-init.gf");
304 osol.precision(precision);
318 MFEM_ABORT(
"Must build with MFEM_USE_SIDRE=YES for binary output.");
354 cout <<
"Unable to connect to GLVis server at "
355 <<
vishost <<
':' << visport << endl;
356 visualization =
false;
357 cout <<
"GLVis visualization disabled.\n";
361 sout.precision(precision);
362 sout <<
"solution\n" << mesh <<
u;
365 cout <<
"GLVis visualization paused."
366 <<
" Press space (in the GLVis window) to resume it.\n";
373 FE_Evolution adv(m, k,
b);
375 ImplicitVariableType imp_var = solve_implicit_state ?
376 ImplicitVariableType::STATE
377 : ImplicitVariableType::SLOPE;
381 ode_solver->Init(adv);
382 ode_solver->SetImplicitVariableType(imp_var);
385 for (
int ti = 0; !done; )
387 real_t dt_real = min(dt, t_final - t);
388 ode_solver->Step(
u, t, dt_real);
391 done = (t >= t_final - 1e-8*dt);
393 if (done || ti % vis_steps == 0)
395 cout <<
"time step: " << ti <<
", time: " << t << endl;
399 sout <<
"solution\n" << mesh <<
u << flush;
421 ofstream osol(
"ex9-final.gf");
422 osol.precision(precision);
437 M(M_), K(K_),
b(b_), z(height)
440 if (M.GetAssemblyLevel() == AssemblyLevel::LEGACY)
443 M_solver.SetOperator(M.SpMat());
444 dg_solver =
new DG_Solver(M.SpMat(), K.SpMat(), *M.FESpace());
449 M_solver.SetOperator(M);
452 M_solver.SetPreconditioner(*M_prec);
453 M_solver.iterative_mode =
false;
454 M_solver.SetRelTol(1e-9);
455 M_solver.SetAbsTol(0.0);
456 M_solver.SetMaxIter(100);
457 M_solver.SetPrintLevel(0);
460void FE_Evolution::Mult(
const Vector &x,
Vector &y)
const
470 MFEM_VERIFY(dg_solver != NULL,
471 "Implicit time integration is not supported with partial assembly");
486 dg_solver->SetTimeStep(dt);
487 dg_solver->Mult(z, k);
490FE_Evolution::~FE_Evolution()
503 for (
int i = 0; i <
dim; i++)
516 case 1: v(0) = 1.0;
break;
517 case 2: v(0) = sqrt(2./3.); v(1) = sqrt(1./3.);
break;
518 case 3: v(0) = sqrt(3./6.); v(1) = sqrt(2./6.); v(2) = sqrt(1./6.);
530 case 1: v(0) = 1.0;
break;
531 case 2: v(0) = w*X(1); v(1) = -w*X(0);
break;
532 case 3: v(0) = w*X(1); v(1) = -w*X(0); v(2) = 0.0;
break;
540 real_t d = max((X(0)+1.)*(1.-X(0)),0.) * max((X(1)+1.)*(1.-X(1)),0.);
544 case 1: v(0) = 1.0;
break;
545 case 2: v(0) = d*w*X(1); v(1) = -d*w*X(0);
break;
546 case 3: v(0) = d*w*X(1); v(1) = -d*w*X(0); v(2) = 0.0;
break;
560 for (
int i = 0; i <
dim; i++)
574 return exp(-40.*pow(X(0)-0.5,2));
578 real_t rx = 0.45, ry = 0.25, cx = 0., cy = -0.2, w = 10.;
581 const real_t s = (1. + 0.25*cos(2*M_PI*X(2)));
585 return ( std::erfc(w*(X(0)-cx-rx))*std::erfc(-w*(X(0)-cx+rx)) *
586 std::erfc(w*(X(1)-cy-ry))*std::erfc(-w*(X(1)-cy+ry)) )/16;
592 real_t x_ = X(0), y_ = X(1), rho, phi;
593 rho = std::hypot(x_, y_);
595 return pow(sin(M_PI*rho),2)*sin(3*phi);
600 return sin(
f*X(0))*sin(
f*X(1));
@ 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.
Jacobi-type diagonal smoother of a sparse matrix.
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)
void SetPrefixPath(const std::string &prefix)
Set the path where the DataCollection will be saved.
virtual void Save()
Save the collection to disk.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
void Print(std::ostream &os=mfem::out)
Print the configuration of the MFEM virtual device object.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
const FiniteElement * GetTypicalFE() const
Return GetFE(0) if the local mesh is not empty; otherwise return a typical FE based on the Geometry t...
int GetDof() const
Returns the number of degrees of freedom in the finite element.
A general function coefficient.
void Mult(const Vector &b, Vector &x) const override
Iterative solution of the linear system using the GMRES method.
Class for grid function - Vector with associated FE space.
void SetOperator(const Operator &op) override
Also calls SetOperator for the preconditioner if there is one.
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)
Arbitrary order "L2-conforming" discontinuous finite elements.
NURBSExtension * NURBSext
Optional NURBS mesh extension.
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
Print the mesh to the given stream using the default MFEM mesh format.
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, int pyr_type=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::string Types
static MFEM_EXPORT std::unique_ptr< ODESolver > Select(const int ode_solver_type)
Jacobi smoothing for a given bilinear form (no matrix necessary).
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.
void SetLevelsOfDetail(int levels_of_detail_)
Set the refinement level.
void SetHighOrderOutput(bool high_order_output_)
Sets whether or not to output the data as high-order elements (false by default).
void SetDataFormat(VTKFormat fmt)
Set the data format for the ParaView output files.
Writer for ParaView visualization (PVD and VTU format)
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 bool ImplicitVarTypeIsState() const
Returns true if implicit variable is STATE and false otherwise. Used by ODESolver to identify the sta...
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.
Vector & Add(const real_t a, const Vector &Va)
(*this) += a * Va
Data collection with VisIt I/O routines.
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
const int * ess_tdof_list
void velocity_function(const Vector &x, Vector &v)
real_t u0_function(const Vector &x)
real_t inflow_function(const Vector &x)
int GetTrueVSize(const FieldDescriptor &f)
Get the true dof size of a field descriptor.
real_t u(const Vector &xvec)
std::function< real_t(const Vector &)> f(real_t mass_coeff)
MFEM_HOST_DEVICE Complex exp(const Complex &q)