89static const char *enum_str[] =
105int main(
int argc,
char *argv[])
113 const char *mesh_file =
"../../data/inline-quad.mesh";
121 real_t relax_factor = 2.0/3;
122 bool static_cond =
false;
124 bool visualization =
true;
126 bool paraview =
false;
129 args.
AddOption(&mesh_file,
"-m",
"--mesh",
130 "Mesh file to use.");
132 "Finite element order (polynomial degree).");
133 args.
AddOption(&delta_order,
"-do",
"--delta_order",
134 "Order enrichment for DPG test space.");
135 args.
AddOption(&sref,
"-sref",
"--num-serial-refinements",
136 "Number of initial serial uniform refinements");
137 args.
AddOption(&pref,
"-pref",
"--num-parallel-refinements",
138 "Number of AMR refinements");
139 args.
AddOption(&theta,
"-theta",
"--theta-factor",
140 "Refinement factor (0 indicates uniform refinements) ");
141 args.
AddOption(&iprob,
"-prob",
"--problem",
"Problem case"
142 " 0: manufactured, 1: L-shape");
143 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
144 "--no-static-condensation",
"Enable static condensation.");
145 args.
AddOption(&pmg,
"-pmg",
"--p-refinement-multigrid",
"-no-pmg",
146 "--no-p-refinement-multigrid",
"Enable P-Refinement Multigrid.");
147 args.
AddOption(&pmg_levels,
"-pmgl",
"--p-refinement-multigrid-levels",
148 "Number of levels for P-Refinement Multigrid.");
149 args.
AddOption(&relax_factor,
"-rf",
"--relaxation-factor",
150 "Relaxation factor for the p-multigrid smoother.");
151 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
152 "--no-visualization",
153 "Enable or disable GLVis visualization.");
154 args.
AddOption(¶view,
"-paraview",
"--paraview",
"-no-paraview",
156 "Enable or disable ParaView visualization.");
157 args.
AddOption(&visport,
"-p",
"--send-port",
"Socket for GLVis.");
168 if (iprob > 1) { iprob = 1; }
173 mesh_file =
"../../data/l-shape.mesh";
181 Mesh mesh(mesh_file, 1, 1);
183 MFEM_VERIFY(
dim > 1,
"Dimension = 1 is not supported in this example");
191 int size =
nodes->Size()/2;
192 for (
int i = 0; i<size; i++)
195 (*nodes)[2*i] = 2*(*nodes)[2*i+1]-1;
196 (*nodes)[2*i+1] = -2*x+1;
200 for (
int i = 0; i<sref; i++)
207 ParMesh pmesh(MPI_COMM_WORLD, mesh);
242 int test_order = order+delta_order;
250 trial_fes.
Append(sigma_fes);
251 trial_fes.
Append(hatu_fes);
252 trial_fes.
Append(hatsigma_fes);
267 a->StoreMatrices(
true);
271 TrialSpace::u_space,TestSpace::tau_space);
275 negone)), TrialSpace::sigma_space, TestSpace::tau_space);
279 TrialSpace::sigma_space,TestSpace::v_space);
283 TrialSpace::hatu_space,TestSpace::tau_space);
287 TrialSpace::hatsigma_space, TestSpace::v_space);
292 TestSpace::tau_space, TestSpace::tau_space);
295 TestSpace::tau_space, TestSpace::tau_space);
298 TestSpace::v_space, TestSpace::v_space);
301 TestSpace::v_space, TestSpace::v_space);
304 if (
prob == prob_type::manufactured)
318 std::cout <<
"\n Ref |"
324 <<
" PCG it |" << endl;
325 std::cout << std::string(72,
'-') << endl;
353 if (static_cond) {
a->EnableStaticCondensation(); }
354 for (
int it = 0; it<=pref; it++)
378 offsets[4] = hatsigma_fes->
GetVSize();
391 Solver * preconditioner =
nullptr;
395 a->GetTraceFESpaces(prec_fes);
399 prec_fes = trial_fes;
404 bool mumps_coarse_solver =
true;
406 bool mumps_coarse_solver =
false;
408 std::vector<Array<int>> ess_bdr_marker(prec_fes.
Size());
409 for (
int b = 0;
b<prec_fes.
Size();
b++)
412 int ess_block = (static_cond) ? 0 : 2;
415 ess_bdr_marker[
b] = ess_bdr;
419 ess_bdr_marker[
b] = 0;
423 pmg_levels, relax_factor, mumps_coarse_solver);
433 prec->SetOperator(A->
GetBlock(i,i));
434 block_diag->SetDiagonalBlock(i,prec);
443 cg.SetPreconditioner(*preconditioner);
446 delete preconditioner;
448 a->RecoverFEMSolution(X,x);
450 Vector & residuals =
a->ComputeResidual(x);
455 real_t globalresidual = residual * residual;
458 MPI_MAX, MPI_COMM_WORLD);
459 MPI_Allreduce(MPI_IN_PLACE, &globalresidual, 1,
462 globalresidual = sqrt(globalresidual);
472 real_t L2Error = sqrt(u_err*u_err + sigma_err*sigma_err);
473 real_t rate_err = (it) ?
dim*log(err0/L2Error)/log((
real_t)dof0/dofs) : 0.0;
474 real_t rate_res = (it) ?
dim*log(res0/globalresidual)/log((
477 res0 = globalresidual;
482 std::ios oldState(
nullptr);
483 oldState.copyfmt(std::cout);
484 std::cout << std::right << std::setw(5) << it <<
" | "
485 << std::setw(10) << dof0 <<
" | "
486 << std::setprecision(3)
487 << std::setw(10) << std::scientific << err0 <<
" | "
488 << std::setprecision(2)
489 << std::setw(6) << std::fixed << rate_err <<
" | "
490 << std::setprecision(3)
491 << std::setw(10) << std::scientific << res0 <<
" | "
492 << std::setprecision(2)
493 << std::setw(6) << std::fixed << rate_res <<
" | "
494 << std::setw(6) << std::fixed << cg.GetNumIterations() <<
" | "
496 std::cout.copyfmt(oldState);
501 const char * keys = (it == 0 &&
dim == 2) ?
"jRcm\n" :
nullptr;
505 "Numerical u", 0,0,500,500,keys);
507 "Numerical flux", 500,0,500,500,keys);
517 if (it == pref) {
break; }
520 for (
int iel = 0; iel<pmesh.
GetNE(); iel++)
522 if (residuals[iel] >= theta * maxresidual)
524 elements_to_refine.
Append(iel);
530 for (
int i =0; i<trial_fes.
Size(); i++)
532 trial_fes[i]->Update(
false);
565 real_t r = sqrt(x*x + y*y);
568 if (phi < 0) { phi += 2*M_PI; }
590 real_t r = sqrt(x*x + y*y);
593 if (phi < 0) { phi += 2*M_PI; }
597 real_t phi_x = - y / (r*r);
600 du[0] = beta*(r_x * sin(
alpha*phi) + r * phi_x * cos(
alpha*phi));
601 du[1] = beta*(r_y * sin(
alpha*phi) + r * phi_y * cos(
alpha*phi));
608 for (
int i = 0; i<du.
Size(); i++)
610 du[i] = M_PI * cos(
alpha);
621 case prob_type::manufactured:
625 return - M_PI*M_PI *
u * X.
Size();
629 MFEM_ABORT(
"Should be unreachable");
655 "f_exact should not be called for l-shape benchmark problem, i.e., f = 0")
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
int Size() const
Return the logical size of the array.
void PartialSum()
Fill the entries of the array with the cumulative sum of the entries.
int Append(const T &el)
Append element 'el' to array, resize if necessary.
A class to handle Block diagonal preconditioners in a matrix-free implementation.
A class to handle Block systems in a matrix-free implementation.
Array< int > & RowOffsets()
Return the row offsets for block starts.
Operator & GetBlock(int i, int j)
Return a reference to block i,j.
int NumRowBlocks() const
Return the number of row blocks.
A class to handle Vectors in a block fashion.
Vector & GetBlock(int i)
Get the i-th vector in the block.
Conjugate gradient method.
A coefficient that is constant across space and time.
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.
for Raviart-Thomas elements
Class for domain integration .
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
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.
Arbitrary order "H^{1/2}-conforming" trace finite elements defined on the interface between mesh elem...
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
Arbitrary order "L2-conforming" discontinuous finite elements.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
void EnsureNodes()
Make sure that the mesh has valid nodes, i.e. its geometry is described by a vector finite element gr...
void Clear()
Clear the contents of the Mesh.
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
void GetNodes(Vector &node_coord) const
void EnsureNCMesh(bool simplices_nonconforming=false)
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
static int WorldRank()
Return the MPI rank in 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).
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 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.
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.
Creates a p-refinement multigrid preconditioner for a given set of parallel finite element spaces and...
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
int GetTrueVSize() const override
Return the number of local vector true dofs.
Class for parallel grid function.
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 ProjectBdrCoefficient(Coefficient *coeff[], VectorCoefficient *vcoeff, const Array< int > &attr)
void MakeRef(FiniteElementSpace *f, real_t *v) override
Make the ParGridFunction reference external data on a new FiniteElementSpace.
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)
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
Arbitrary order "H^{-1/2}-conforming" face finite elements defined on the interface between mesh elem...
A general vector function coefficient.
real_t Norml2() const
Returns the l2 norm of the vector.
real_t Max() const
Returns the maximal element of the vector.
int Size() const
Returns the size of the vector.
real_t Sum() const
Return the sum of the vector entries.
void SetSize(int s)
Resize the vector to size s.
const int * ess_tdof_list
real_t sigma(const Vector &x)
void VisualizeField(socketstream &sock, const char *vishost, int visport, GridFunction &gf, const char *title, int x, int y, int w, int h, const char *keys, bool vec)
real_t u(const Vector &xvec)
Solver * MakeFESpaceDefaultSolver(const ParFiniteElementSpace *pfespace, int print_level)
Creates a default solver for a given parallel FE space. The default solvers are the following:
std::function< real_t(const Vector &)> f(real_t mass_coeff)
void exact_gradu(const Vector &X, Vector &gradu)
real_t exact_hatu(const Vector &X)
real_t exact_laplacian_u(const Vector &X)
real_t exact_u(const Vector &X)
void exact_sigma(const Vector &X, Vector &sigma)
void exact_hatsigma(const Vector &X, Vector &hatsigma)
real_t f_exact(const Vector &X)
Helper struct to convert a C++ type to an MPI type.
std::array< int, NCMesh::MaxFaceNodes > nodes