39template<
int problem=0>
46 for (
int i = 0; i <
dim; i++)
58 case 1: v(0) = 1.0;
break;
59 case 2: v(0) = sqrt(2./3.); v(1) = sqrt(1./3.);
break;
60 case 3: v(0) = sqrt(3./6.); v(1) = sqrt(2./6.); v(2) = sqrt(1./6.);
72 case 1: v(0) = 1.0;
break;
73 case 2: v(0) = w*X(1); v(1) = -w*X(0);
break;
74 case 3: v(0) = w*X(1); v(1) = -w*X(0); v(2) = 0.0;
break;
82 real_t d = max((X(0)+1.)*(1.-X(0)),0.) * max((X(1)+1.)*(1.-X(1)),0.);
86 case 1: v(0) = 1.0;
break;
87 case 2: v(0) = d*w*X(1); v(1) = -d*w*X(0);
break;
88 case 3: v(0) = d*w*X(1); v(1) = -d*w*X(0); v(2) = 0.0;
break;
97template<
int problem=0>
104 for (
int i = 0; i <
dim; i++)
118 return exp(-40.*pow(X(0)-0.5,2));
122 real_t rx = 0.45, ry = 0.25, cx = 0., cy = -0.2, w = 10.;
125 const real_t s = (1. + 0.25*cos(2*M_PI*X(2)));
129 return ( std::erfc(w*(X(0)-cx-rx))*std::erfc(-w*(X(0)-cx+rx)) *
130 std::erfc(w*(X(1)-cy-ry))*std::erfc(-w*(X(1)-cy+ry)) )/16;
136 real_t x_ = X(0), y_ = X(1), rho, phi;
137 rho = std::hypot(x_, y_);
139 return pow(sin(M_PI*rho),2)*sin(3*phi);
144 return sin(
f*X(0))*sin(
f*X(1));
151class Implicit_Solver :
public Solver
165 linear_solver(M.GetComm()),
177 void SetTimeStep(
real_t dt_)
184 MPI_Comm_rank(comm, &myrank);
185 MPI_Bcast(&ddt, 1, MPI_DOUBLE, 0, comm);
188 epsilon = std::numeric_limits<real_t>::epsilon();
196 cout <<
"Updating Implicit_Solver time step from " << dt
197 <<
" to " << dt_ << endl;
203 A =
Add(dt, S, 1.0, M);
208 void SetOperator(
const Operator &op)
override
215 linear_solver.
Mult(x, y);
218 void SetPreconditioner(
Solver &precond)
223 ~Implicit_Solver()
override
241 Implicit_Solver *implicit_solver;
254 delete implicit_solver;
265 if (TimeDependentOperator::EvalMode::ADDITIVE_TERM_1 ==
GetEvalMode())
271 mfem_error(
"TimeDependentOperator::Mult() is not overridden!");
277 if (TimeDependentOperator::EvalMode::ADDITIVE_TERM_2 ==
GetEvalMode())
279 ImplicitSolve2(dt,x,k);
283 mfem_error(
"TimeDependentOperator::ImplicitSolve() is not overridden!");
289int main(
int argc,
char *argv[])
299 const char *mesh_file =
"../data/periodic-square.mesh";
300 int ser_ref_levels = 2;
301 int par_ref_levels = 0;
303 int ode_solver_type = 64;
309 bool paraview =
false;
314 real_t diffusion_term = 0.01;
317 bool visualization =
true;
320 cout.precision(precision);
323 args.
AddOption(&mesh_file,
"-m",
"--mesh",
324 "Mesh file to use.");
326 "Problem setup to use. See options in velocity_function().");
327 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
328 "Number of times to refine the mesh uniformly in serial.");
329 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
330 "Number of times to refine the mesh uniformly in parallel.");
332 "Order (degree) of the finite elements.");
333 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
335 args.
AddOption(&t_final,
"-tf",
"--t-final",
336 "Final time; start time is 0.");
337 args.
AddOption(&dt,
"-dt",
"--time-step",
339 args.
AddOption(&diffusion_term,
"-dc",
"--diffusion-coeff",
340 "Diffusion coefficient in the PDE.");
341 args.
AddOption(¶view,
"-paraview",
"--paraview-datafiles",
"-no-paraview",
342 "--no-paraview-datafiles",
343 "Save data files for ParaView (paraview.org) visualization.");
344 args.
AddOption(&visit,
"-visit",
"--visit-datafiles",
"-no-visit",
345 "--no-visit-datafiles",
346 "Save data files for VisIt (visit.llnl.gov) visualization.");
347 args.
AddOption(&adios2,
"-adios2",
"--adios2-streams",
"-no-adios2",
348 "--no-adios2-streams",
349 "Save data using adios2 streams.");
350 args.
AddOption(&binary,
"-binary",
"--binary-datafiles",
"-ascii",
352 "Use binary (Sidre) or ascii format for VisIt data files.");
353 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
354 "Visualize every n-th timestep.");
355 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
356 "--no-visualization",
357 "Enable or disable GLVis visualization.");
358 args.
AddOption(&cg,
"-cg",
"--continuous-galerkin",
"-dg",
359 "--discontinuous-galerkin",
360 "Use Continuous-Galerkin Finite elements (Default is DG)");
376 kappa = (order+1)*(order+1);
405 for (
int lev = 0; lev < par_ref_levels; lev++)
426 cout <<
"Number of unknowns: " << global_vSize << endl;
432 std::unique_ptr<VectorFunctionCoefficient> velocity;
490 a->Finalize(skip_zeros);
495 std::unique_ptr<FunctionCoefficient> u0;
513 u->ProjectCoefficient(*u0);
524 MFEM_ABORT(
"Must build with MFEM_USE_SIDRE=YES for binary output.");
562 cout <<
"Unable to connect to GLVis server at "
563 <<
vishost <<
':' << visport << endl;
565 visualization =
false;
568 cout <<
"GLVis visualization disabled.\n";
573 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
574 sout.precision(precision);
575 sout <<
"solution\n" << *pmesh << *
u;
580 cout <<
"GLVis visualization paused."
581 <<
" Press space (in the GLVis window) to resume it.\n";
585#ifdef MFEM_USE_ADIOS2
589 std::string postfix(mesh_file);
590 postfix.erase(0, std::string(
"../data/").size() );
591 postfix +=
"_o" + std::to_string(order);
592 const std::string collection_name =
"ex41-p-" + postfix +
".bp";
596 adios2_dc->
SetParameter(
"SubStreams", std::to_string(num_procs/2) );
609 IMEX_Evolution adv(*m, *k, *s,
b, *
a);
613 ode_solver->Init(adv);
617 for (
int ti = 0; !done; )
619 real_t dt_real = min(dt, t_final - t);
620 ode_solver->Step(*U, t, dt_real);
623 done = (t >= t_final - 1e-8*dt);
625 if (done || ti % vis_steps == 0)
629 cout <<
"time step: " << ti <<
", time: " << t << endl;
634 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
635 sout <<
"solution\n" << *pmesh << *
u << flush;
643#ifdef MFEM_USE_ADIOS2
675 M_solver(M_.ParFESpace()->GetComm()), z(height), w(height)
701 implicit_solver =
new Implicit_Solver(M_mat, S_mat, *M_.
FESpace());
704 implicit_solver -> SetPreconditioner(*lor_solver);
708 MFEM_ABORT(
"Implicit time integration is not supported with partial assembly");
718void IMEX_Evolution::Mult1(
const Vector &x,
Vector &y)
const
731 MFEM_VERIFY(implicit_solver != NULL,
732 "Implicit time integration is not supported with partial assembly");
735 implicit_solver->SetTimeStep(dt);
736 implicit_solver->Mult(z, k);
void SetParameter(const std::string key, const std::string value) noexcept
@ 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)
void SetPrefixPath(const std::string &prefix)
Set the path where the DataCollection will be saved.
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...
int GetVDim() const
Returns the vector dimension of the finite element space.
A general function coefficient.
Arbitrary order H1-conforming (continuous) finite elements.
Wrapper for hypre's ParCSR matrix class.
void GetDiag(Vector &diag) const
Get the local diagonal of the matrix.
MPI_Comm GetComm() const
MPI communicator.
Wrapper for hypre's parallel vector class.
Parallel smoothers in hypre.
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
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)
Represents a solver of type SolverType created using the low-order refined version of the given Bilin...
SolverType & GetSolver()
Access the underlying solver.
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 bool Root()
Return true if the rank in MPI_COMM_WORLD is zero.
static int WorldRank()
Return the MPI rank in MPI_COMM_WORLD.
static int WorldSize()
Return the size of MPI_COMM_WORLD.
static void Init(int &argc, char **&argv, int required=default_thread_required, int *provided=nullptr)
Singleton creation with Mpi::Init(argc, argv).
static MFEM_EXPORT std::unique_ptr< ODESolver > SelectIMEX(const int ode_solver_type)
static MFEM_EXPORT std::string IMEXTypes
Pointer to an Operator of a specified type.
OpType * As() const
Return the Operator pointer statically cast to a specified OpType. Similar to the method Get().
void Reset(OpType *A, bool own_A=true)
Reset the OperatorHandle to the given OpType pointer, A.
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
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.
Abstract parallel finite element space.
HYPRE_BigInt GlobalTrueVSize() const
Class for parallel grid function.
Class for parallel meshes.
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 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.
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)
void Add(const DenseMatrix &A, const DenseMatrix &B, real_t alpha, DenseMatrix &C)
C = A + alpha*B.
MFEM_HOST_DEVICE Complex exp(const Complex &q)