92int main(
int argc,
char *argv[])
95 const char *mesh_file =
"../data/star.mesh";
101 real_t newton_scaling = 0.8;
104 bool visualization =
true;
107 args.
AddOption(&mesh_file,
"-m",
"--mesh",
108 "Mesh file to use.");
110 "Finite element order (polynomial degree).");
111 args.
AddOption(&ref_levels,
"-r",
"--refs",
112 "Number of h-refinements.");
113 args.
AddOption(&max_it,
"-mi",
"--max-it",
114 "Maximum number of iterations");
116 "Stopping criteria based on the difference between"
117 "successive solution updates");
119 "Initial size alpha");
120 args.
AddOption(&growth_rate,
"-gr",
"--growth-rate",
121 "Growth rate of the step size alpha");
122 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
123 "--no-visualization",
124 "Enable or disable GLVis visualization.");
134 Mesh mesh(mesh_file, 1, 1);
139 "This example does not support meshes"
140 " without boundary attributes."
145 for (
int l = 0; l < ref_levels; l++)
152 int curvature_order = max(order,2);
162 cout <<
"Number of H(div) dofs: "
164 cout <<
"Number of Lยฒ dofs: "
180 delta_psi_gf.
MakeRef(&RTfes,x,offsets[0]);
181 u_gf.
MakeRef(&L2fes,x,offsets[1]);
201 sol_sock.precision(8);
207 IsomorphismCoefficient Z(sdim, psi_gf);
208 DIsomorphismCoefficient DZ(sdim, psi_gf, eps);
212 SumCoefficient psi_old_minus_psi(div_psi_old_cf, div_psi_cf, 1.0, -1.0);
235 int total_iterations = 0;
238 for (k = 0; k < max_it; k++)
242 mfem::out <<
"\nOUTER ITERATION " << k+1 << endl;
245 for ( j = 0; j < 5; j++)
264#ifndef MFEM_USE_SUITESPARSE
276 MINRES(A,prec,rhs,x,0,2000,1e-12);
284 psi_gf.
Add(newton_scaling, delta_psi_gf);
289 sol_sock <<
"solution\n" << mesh << u_gf <<
"window_title 'Discrete solution'"
293 mfem::out <<
"Newton_update_size = " << Newton_update_size << endl;
295 if (Newton_update_size < increment_u)
305 mfem::out <<
"Number of Newton iterations = " << j+1 << endl;
306 mfem::out <<
"Increment (|| uโ - uโ_prvs||) = " << increment_u << endl;
311 if (increment_u < tol || k == max_it-1)
316 alpha *= max(growth_rate, 1_r);
321 mfem::out <<
"\n Outer iterations: " << k+1
322 <<
"\n Total iterations: " << total_iterations
333 MFEM_ASSERT(psi != NULL,
"grid function is not set");
337 real_t norm = psi_vals.Norml2();
338 real_t phi = 1.0 / sqrt(1.0 + norm*norm);
347 MFEM_ASSERT(psi != NULL,
"grid function is not set");
348 MFEM_ASSERT(eps >= 0,
"eps is negative");
352 real_t norm = psi_vals.Norml2();
353 real_t phi = 1.0 / sqrt(1.0 + norm*norm);
356 for (
int i = 0; i <
height; i++)
359 for (
int j = 0; j <
height; j++)
361 K(i,j) -= psi_vals(i) * psi_vals(j) * pow(phi, 3);
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.
A class to handle Block diagonal preconditioners in a matrix-free implementation.
void SetDiagonalBlock(int iblock, Operator *op)
Add a square block op in the block-entry (iblock, iblock).
A class to handle Block systems in a matrix-free implementation.
void SetBlock(int iRow, int iCol, Operator *op, real_t c=1.0)
Add a block op in the block-entry (iblock, jblock).
A class to handle Vectors in a block fashion.
Vector & GetBlock(int i)
Get the i-th vector in the block.
A coefficient that is constant across space and time.
Data type for scaled Jacobi-type smoother of sparse matrix.
Data type dense matrix using column-major storage.
Scalar coefficient defined as the Divergence of a vector GridFunction.
Class for domain integration .
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
virtual int GetTrueVSize() const
Return the number of vector true (conforming) dofs.
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
Data type for Gauss-Seidel smoother of sparse matrix.
Class for grid function - Vector with associated FE space.
virtual void MakeRef(FiniteElementSpace *f, real_t *v)
Make the GridFunction reference external data on a new FiniteElementSpace.
virtual real_t ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const
Returns ||exsol - u_h||_L2 for scalar or vector H1 or L2 elements.
virtual void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const
Class for integration point with weight.
Arbitrary order "L2-conforming" discontinuous finite elements.
Base class for Matrix Coefficients that optionally depend on time and space.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
int Dimension() const
Dimension of the reference space used within the elements.
int SpaceDimension() const
Dimension of the physical space containing the mesh.
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 *)
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
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.
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
Vector coefficient defined as a product of scalar and vector coefficients.
void GetDiag(Vector &d) const
Returns the Diagonal of A.
Scalar coefficient defined as the linear combination of two scalar coefficients or a scalar and a sca...
Direct sparse solver using UMFPACK.
Base class for vector Coefficients that optionally depend on time and space.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
for VectorFiniteElements (Nedelec, Raviart-Thomas)
void Reciprocal()
(*this)(i) = 1.0 / (*this)(i)
Vector & Add(const real_t a, const Vector &Va)
(*this) += a * Va
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
void Transpose(const Table &A, Table &At, int ncols_A_)
Transpose a Table.
void MINRES(const Operator &A, const Vector &b, Vector &x, int print_it, int max_it, real_t rtol, real_t atol)
MINRES method without preconditioner. (tolerances are squared)
SparseMatrix * Mult_AtDA(const SparseMatrix &A, const Vector &D, SparseMatrix *OAtDA)
Matrix multiplication A^t D A. All matrices must be finalized.