73 #include "../common/mfem-common.hpp" 87 static const char *enum_str[] =
103 int main(
int argc,
char *argv[])
107 int myid = Mpi::WorldRank();
111 const char *mesh_file =
"../../data/inline-quad.mesh";
117 bool static_cond =
false;
119 bool visualization =
true;
120 bool paraview =
false;
123 args.
AddOption(&mesh_file,
"-m",
"--mesh",
124 "Mesh file to use.");
126 "Finite element order (polynomial degree).");
127 args.
AddOption(&delta_order,
"-do",
"--delta_order",
128 "Order enrichment for DPG test space.");
129 args.
AddOption(&sref,
"-sref",
"--num-serial-refinements",
130 "Number of initial serial uniform refinements");
131 args.
AddOption(&pref,
"-pref",
"--num-parallel-refinements",
132 "Number of AMR refinements");
133 args.
AddOption(&theta,
"-theta",
"--theta-factor",
134 "Refinement factor (0 indicates uniform refinements) ");
135 args.
AddOption(&iprob,
"-prob",
"--problem",
"Problem case" 136 " 0: manufactured, 1: L-shape");
137 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
138 "--no-static-condensation",
"Enable static condensation.");
139 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
140 "--no-visualization",
141 "Enable or disable GLVis visualization.");
142 args.
AddOption(¶view,
"-paraview",
"--paraview",
"-no-paraview",
144 "Enable or disable ParaView visualization.");
155 if (iprob > 1) { iprob = 1; }
160 mesh_file =
"../../data/l-shape.mesh";
168 Mesh mesh(mesh_file, 1, 1);
170 MFEM_VERIFY(
dim > 1,
"Dimension = 1 is not supported in this example");
178 int size = nodes->
Size()/2;
179 for (
int i = 0; i<size; i++)
181 double x = (*nodes)[2*i];
182 (*nodes)[2*i] = 2*(*nodes)[2*i+1]-1;
183 (*nodes)[2*i+1] = -2*x+1;
188 for (
int i = 0; i<sref; i++)
195 ParMesh pmesh(MPI_COMM_WORLD, mesh);
230 int test_order = order+delta_order;
238 trial_fes.
Append(sigma_fes);
239 trial_fes.
Append(hatu_fes);
240 trial_fes.
Append(hatsigma_fes);
255 a->StoreMatrices(
true);
259 TrialSpace::u_space,TestSpace::tau_space);
263 negone)), TrialSpace::sigma_space, TestSpace::tau_space);
267 TrialSpace::sigma_space,TestSpace::v_space);
271 TrialSpace::hatu_space,TestSpace::tau_space);
275 TrialSpace::hatsigma_space, TestSpace::v_space);
280 TestSpace::tau_space, TestSpace::tau_space);
283 TestSpace::tau_space, TestSpace::tau_space);
286 TestSpace::v_space, TestSpace::v_space);
289 TestSpace::v_space, TestSpace::v_space);
306 std::cout <<
"\n Ref |" 312 <<
" PCG it |" << endl;
313 std::cout << std::string(72,
'-') << endl;
341 if (static_cond) {
a->EnableStaticCondensation(); }
342 for (
int it = 0; it<=pref; it++)
356 for (
int i = 0; i < ess_tdof_list.
Size(); i++)
366 offsets[4] = hatsigma_fes->
GetVSize();
375 a->FormLinearSystem(ess_tdof_list,x,Ah,X,B);
387 amg1->SetPrintLevel(0);
388 M.SetDiagonalBlock(0,amg0);
389 M.SetDiagonalBlock(1,amg1);
395 M.SetDiagonalBlock(skip,amg2);
407 M.SetDiagonalBlock(skip+1,prec);
417 a->RecoverFEMSolution(X,x);
419 Vector & residuals =
a->ComputeResidual(x);
421 double residual = residuals.
Norml2();
423 double maxresidual = residuals.
Max();
424 double globalresidual = residual * residual;
426 MPI_Allreduce(MPI_IN_PLACE,&maxresidual,1,MPI_DOUBLE,MPI_MAX,MPI_COMM_WORLD);
427 MPI_Allreduce(MPI_IN_PLACE,&globalresidual,1,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD);
429 globalresidual = sqrt(globalresidual);
439 double L2Error = sqrt(u_err*u_err + sigma_err*sigma_err);
440 double rate_err = (it) ?
dim*log(err0/L2Error)/log((
double)dof0/dofs) : 0.0;
441 double rate_res = (it) ?
dim*log(res0/globalresidual)/log((
442 double)dof0/dofs) : 0.0;
444 res0 = globalresidual;
449 std::ios oldState(
nullptr);
450 oldState.copyfmt(std::cout);
451 std::cout << std::right << std::setw(5) << it <<
" | " 452 << std::setw(10) << dof0 <<
" | " 453 << std::setprecision(3)
454 << std::setw(10) << std::scientific << err0 <<
" | " 455 << std::setprecision(2)
456 << std::setw(6) << std::fixed << rate_err <<
" | " 457 << std::setprecision(3)
458 << std::setw(10) << std::scientific << res0 <<
" | " 459 << std::setprecision(2)
460 << std::setw(6) << std::fixed << rate_res <<
" | " 463 std::cout.copyfmt(oldState);
468 const char * keys = (it == 0 &&
dim == 2) ?
"jRcm\n" :
nullptr;
473 "Numerical u", 0,0,500,500,keys);
475 "Numerical flux", 500,0,500,500,keys);
481 paraview_dc->
SetTime((
double)it);
485 if (it == pref) {
break; }
488 for (
int iel = 0; iel<pmesh.
GetNE(); iel++)
490 if (residuals[iel] >= theta * maxresidual)
492 elements_to_refine.
Append(iel);
498 for (
int i =0; i<trial_fes.
Size(); i++)
500 trial_fes[i]->Update(
false);
533 double r = sqrt(x*x + y*y);
534 double alpha = 2./3.;
535 double phi = atan2(y,x);
536 if (phi < 0) { phi += 2*M_PI; }
558 double r = sqrt(x*x + y*y);
559 double alpha = 2./3.;
560 double phi = atan2(y,x);
561 if (phi < 0) { phi += 2*M_PI; }
565 double phi_x = - y / (r*r);
566 double phi_y = x / (r*r);
576 for (
int i = 0; i<du.
Size(); i++)
578 du[i] = M_PI * cos(
alpha);
593 return - M_PI*M_PI *
u * X.
Size();
597 MFEM_ABORT(
"Should be unreachable");
623 "f_exact should not be called for l-shape benchmark problem, i.e., f = 0")
Class for domain integration L(v) := (f, v)
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1)
void exact_hatsigma(const Vector &X, Vector &hatsigma)
Conjugate gradient method.
The Auxiliary-space Maxwell Solver in hypre.
Class for grid function - Vector with associated FE space.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
The Auxiliary-space Divergence Solver in hypre.
A class to handle Vectors in a block fashion.
void SetDataFormat(VTKFormat fmt)
A coefficient that is constant across space and time.
Array< int > & RowOffsets()
Return the row offsets for block starts.
void PrintOptions(std::ostream &out) const
Print the options.
int Dimension() const
Dimension of the reference space used within the elements.
void SetSize(int s)
Resize the vector to size s.
Helper class for ParaView visualization data.
void PrintUsage(std::ostream &out) const
Print the usage message.
Pointer to an Operator of a specified type.
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
int Size() const
Returns the size of the vector.
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
bool Good() const
Return true if the command line options were parsed successfully.
Abstract parallel finite element space.
(Q div u, div v) for RT elements
Operator & GetBlock(int i, int j)
Return a reference to block i,j.
double exact_hatu(const Vector &X)
virtual void MakeRef(FiniteElementSpace *f, double *v)
Make the ParGridFunction reference external data on a new FiniteElementSpace.
The BoomerAMG solver in hypre.
double f_exact(const Vector &X)
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
A class to handle Block diagonal preconditioners in a matrix-free implementation. ...
int Append(const T &el)
Append element 'el' to array, resize if necessary.
void EnsureNCMesh(bool simplices_nonconforming=false)
int GetNumIterations() const
Returns the number of iterations taken during the last call to Mult()
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Arbitrary order "H^{1/2}-conforming" trace finite elements defined on the interface between mesh elem...
void SetPrintLevel(int print_level)
void SetMaxIter(int max_it)
void exact_sigma(const Vector &X, Vector &sigma)
double Sum() const
Return the sum of the vector entries.
int main(int argc, char *argv[])
void SetHighOrderOutput(bool high_order_output_)
void VisualizeField(socketstream &sock, const char *vishost, int visport, ParGridFunction &gf, const char *title, int x=0, int y=0, int w=400, int h=400, bool vec=false)
void SetTime(double t)
Set physical time (for time-dependent simulations)
virtual double ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const
HYPRE_BigInt GlobalTrueVSize() const
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
A general vector function coefficient.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void SetRelTol(double rtol)
double exact_laplacian_u(const Vector &X)
void ProjectBdrCoefficient(Coefficient *coeff[], VectorCoefficient *vcoeff, Array< int > &attr)
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
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...
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
void PartialSum()
Fill the entries of the array with the cumulative sum of the entries.
double Max() const
Returns the maximal element of the vector.
int GetNE() const
Returns number of elements.
virtual int GetTrueVSize() const
Return the number of local vector true dofs.
OpType * As() const
Return the Operator pointer statically cast to a specified OpType. Similar to the method Get()...
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
double Norml2() const
Returns the l2 norm of the vector.
Abstract class for hypre's solvers and preconditioners.
int Size() const
Return the logical size of the array.
void SetLevelsOfDetail(int levels_of_detail_)
void Clear()
Clear the contents of the Mesh.
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
A general function coefficient.
Arbitrary order "H^{-1/2}-conforming" face finite elements defined on the interface between mesh elem...
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
Arbitrary order H1-conforming (continuous) finite elements.
double sigma(const Vector &x)
double exact_u(const Vector &X)
void GetNodes(Vector &node_coord) const
virtual void Save() override
double u(const Vector &xvec)
Class for parallel grid function.
Wrapper for hypre's ParCSR matrix class.
A class to handle Block systems in a matrix-free implementation.
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
Class for parallel meshes.
void exact_gradu(const Vector &X, Vector &gradu)
void EnsureNodes()
Make sure that the mesh has valid nodes, i.e. its geometry is described by a vector finite element gr...
void SetPrefixPath(const std::string &prefix)
Set the path where the DataCollection will be saved.
Vector & GetBlock(int i)
Get the i-th vector in the block.
Arbitrary order "L2-conforming" discontinuous finite elements.
double f(const Vector &p)