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;
64 const char *device_config =
"cpu";
67 args.
AddOption(&mesh_file,
"-m",
"--mesh",
69 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
70 "Number of times to refine the mesh uniformly in serial.");
71 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
72 "Number of times to refine the mesh uniformly in parallel.");
74 "Finite element order (polynomial degree).");
75 args.
AddOption(&
freq,
"-f",
"--frequency",
"Set the frequency for the exact"
77 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
78 "--no-static-condensation",
"Enable static condensation.");
79 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
81 "Enable or disable GLVis visualization.");
82 args.
AddOption(&use_petsc,
"-usepetsc",
"--usepetsc",
"-no-petsc",
84 "Use or not PETSc to solve the linear system.");
85 args.
AddOption(&petscrc_file,
"-petscopts",
"--petscopts",
86 "PetscOptions file to use.");
87 args.
AddOption(&use_nonoverlapping,
"-nonoverlapping",
"--nonoverlapping",
88 "-no-nonoverlapping",
"--no-nonoverlapping",
89 "Use or not the block diagonal PETSc's matrix format "
90 "for non-overlapping domain decomposition.");
91 args.
AddOption(&device_config,
"-d",
"--device",
92 "Device configuration string, see Device::Configure().");
110 Device device(device_config);
111 if (myid == 0) { device.
Print(); }
119 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
121#if PETSC_VERSION_LT(3,21,0)
122 if (
dim == 3 && use_petsc && use_nonoverlapping)
124 cout <<
"\nFor three-dimensional runs you need a version of PETSc greater or equal 3.21.\n\n";
128 return MFEM_SKIP_RETURN_VALUE;
138 if (ser_ref_levels < 0)
140 ser_ref_levels = (int)floor(log(1000./mesh->
GetNE())/log(2.)/
dim);
142 for (
int l = 0; l < ser_ref_levels; l++)
154 for (
int l = 0; l < par_ref_levels; l++)
167 cout <<
"Number of finite element unknowns: " << size << endl;
213 if (static_cond) {
a->EnableStaticCondensation(); }
230 (
a->StaticCondensationIsEnabled() ?
a->SCParFESpace() : fespace);
244 a->SetOperatorType(use_nonoverlapping ?
250 cout <<
"Size of linear system: " << A.
M() << endl;
255 (
a->StaticCondensationIsEnabled() ?
a->SCParFESpace() : fespace);
261 if (use_nonoverlapping)
293 cout <<
"\n|| E_h - E ||_{L^2} = " <<
err <<
'\n' << endl;
300 ostringstream mesh_name, sol_name;
301 mesh_name <<
"mesh." << setfill(
'0') << setw(6) << myid;
302 sol_name <<
"sol." << setfill(
'0') << setw(6) << myid;
304 ofstream mesh_ofs(mesh_name.str().c_str());
305 mesh_ofs.precision(8);
306 pmesh->
Print(mesh_ofs);
308 ofstream sol_ofs(sol_name.str().c_str());
309 sol_ofs.precision(8);
319 sol_sock <<
"parallel " << num_procs <<
" " << myid <<
"\n";
320 sol_sock.precision(8);
321 sol_sock <<
"solution\n" << *pmesh << x << flush;
46int main(
int argc,
char *argv[]) {
…}
344 E(0) = sin(
kappa * x(1));
345 E(1) = sin(
kappa * x(2));
346 E(2) = sin(
kappa * x(0));
350 E(0) = sin(
kappa * x(1));
351 E(1) = sin(
kappa * x(0));
352 if (x.
Size() == 3) { E(2) = 0.0; }
368 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.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
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 Mult(const HypreParVector &b, HypreParVector &x) const override
Solve Ax=b with hypre's PCG.
void SetPrintLevel(int print_lvl)
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
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
Returns ||u_ex - u_h||_L2 in parallel for H1 or L2 elements.
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)
void Mult(const Vector &b, Vector &x) const override
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 &)