34#error This example requires that MFEM is built with MFEM_USE_PETSC=YES
46int main(
int argc,
char *argv[])
55 const char *mesh_file =
"../../data/beam-tet.mesh";
56 int ser_ref_levels = -1;
57 int par_ref_levels = 2;
59 bool static_cond =
false;
60 bool visualization = 1;
61 bool use_petsc =
true;
62 const char *petscrc_file =
"";
63 bool use_nonoverlapping =
false;
66 args.
AddOption(&mesh_file,
"-m",
"--mesh",
68 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
69 "Number of times to refine the mesh uniformly in serial.");
70 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
71 "Number of times to refine the mesh uniformly in parallel.");
73 "Finite element order (polynomial degree).");
74 args.
AddOption(&
freq,
"-f",
"--frequency",
"Set the frequency for the exact"
76 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
77 "--no-static-condensation",
"Enable static condensation.");
78 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
80 "Enable or disable GLVis visualization.");
81 args.
AddOption(&use_petsc,
"-usepetsc",
"--usepetsc",
"-no-petsc",
83 "Use or not PETSc to solve the linear system.");
84 args.
AddOption(&petscrc_file,
"-petscopts",
"--petscopts",
85 "PetscOptions file to use.");
86 args.
AddOption(&use_nonoverlapping,
"-nonoverlapping",
"--nonoverlapping",
87 "-no-nonoverlapping",
"--no-nonoverlapping",
88 "Use or not the block diagonal PETSc's matrix format "
89 "for non-overlapping domain decomposition.");
110 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
112#if PETSC_VERSION_LT(3,21,0)
113 if (
dim == 3 && use_petsc && use_nonoverlapping)
115 cout <<
"\nFor three-dimensional runs you need a version of PETSc greater or equal 3.21.\n\n";
119 return MFEM_SKIP_RETURN_VALUE;
129 if (ser_ref_levels < 0)
131 ser_ref_levels = (int)floor(log(1000./mesh->
GetNE())/log(2.)/
dim);
133 for (
int l = 0; l < ser_ref_levels; l++)
145 for (
int l = 0; l < par_ref_levels; l++)
158 cout <<
"Number of finite element unknowns: " << size << endl;
204 if (static_cond) {
a->EnableStaticCondensation(); }
221 (
a->StaticCondensationIsEnabled() ?
a->SCParFESpace() : fespace);
235 a->SetOperatorType(use_nonoverlapping ?
241 cout <<
"Size of linear system: " << A.
M() << endl;
246 (
a->StaticCondensationIsEnabled() ?
a->SCParFESpace() : fespace);
252 if (use_nonoverlapping)
284 cout <<
"\n|| E_h - E ||_{L^2} = " <<
err <<
'\n' << endl;
291 ostringstream mesh_name, sol_name;
292 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
293 sol_name <<
"sol." << setfill(
'0') << setw(6) << myid;
295 ofstream mesh_ofs(mesh_name.str().c_str());
296 mesh_ofs.precision(8);
297 pmesh->
Print(mesh_ofs);
299 ofstream sol_ofs(sol_name.str().c_str());
300 sol_ofs.precision(8);
310 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
311 sol_sock.precision(8);
312 sol_sock <<
"solution\n" << *pmesh << x << flush;
335 E(0) = sin(
kappa * x(1));
336 E(1) = sin(
kappa * x(2));
337 E(2) = sin(
kappa * x(0));
341 E(0) = sin(
kappa * x(1));
342 E(1) = sin(
kappa * x(0));
343 if (x.
Size() == 3) { E(2) = 0.0; }
359 if (x.
Size() == 3) {
f(2) = 0.0; }
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
int Size() const
Return the logical size of the array.
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
A coefficient that is constant across space and time.
Integrator for for Nedelec elements.
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
The Auxiliary-space Maxwell Solver in hypre.
void SetPrintLevel(int print_lvl)
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre's PCG.
void SetMaxIter(int max_iter)
Wrapper for hypre's ParCSR matrix class.
HYPRE_BigInt GetGlobalNumRows() const
Return the global number of rows.
Abstract class for hypre's solvers and preconditioners.
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
int SpaceDimension() const
Dimension of the physical space containing the mesh.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
static void Finalize()
Finalize MPI (if it has been initialized and not yet already finalized).
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).
Arbitrary order H(curl)-conforming Nedelec finite elements.
void FormLinearSystem(const Array< int > &ess_tdof_list, Vector &x, Vector &b, Operator *&A, Vector &X, Vector &B, int copy_interior=0)
Form a constrained linear system using a matrix-free approach.
@ PETSC_MATIS
ID for class PetscParMatrix, MATIS format.
@ PETSC_MATAIJ
ID for class PetscParMatrix, MATAIJ format.
virtual void RecoverFEMSolution(const Vector &X, const Vector &b, Vector &x)
Reconstruct a solution vector x (e.g. a GridFunction) from the solution X of a constrained linear sys...
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.
void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1) const override
HYPRE_BigInt GlobalTrueVSize() const
Class for parallel grid function.
void Save(std::ostream &out) const override
real_t ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const override
void ProjectCoefficient(Coefficient &coeff) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Class for parallel meshes.
void Print(std::ostream &out=mfem::out, const std::string &comments="") const override
Auxiliary class for BDDC customization.
void SetEssBdrDofs(const Array< int > *essdofs, bool loc=false)
Specify dofs on the essential boundary.
void SetSpace(ParFiniteElementSpace *fe)
void SetPreconditioner(Solver &precond)
virtual void Mult(const Vector &b, Vector &x) const
Application of the solver.
Wrapper for PETSc's matrix class.
PetscInt M() const
Returns the global number of rows.
Abstract class for PETSc's preconditioners.
void SetPrintLevel(int plev)
void SetMaxIter(int max_iter)
for VectorFiniteElements (Nedelec, Raviart-Thomas)
A general vector function coefficient.
int Size() const
Returns the size of the vector.
real_t sigma(const Vector &x)
void MFEMInitializePetsc()
Convenience functions to initialize/finalize PETSc.
OutStream err(std::cerr)
Global stream used by the library for standard error output. Initially it uses the same std::streambu...
std::function< real_t(const Vector &)> f(real_t mass_coeff)
void E_exact(const Vector &, Vector &)
void f_exact(const Vector &, Vector &)