46template <
typename CoefficientType>
52int main(
int argc,
char *argv[])
55 const char *mesh_file =
"../../data/cube-nurbs.mesh";
60 bool static_cond =
false;
62 int proj_type_int = 0;
63 const char *device_config =
"cpu";
65 bool visualization = 1;
68 args.
AddOption(&mesh_file,
"-m",
"--mesh",
70 args.
AddOption(&ref_levels,
"-r",
"--refine",
71 "Number of times to refine the mesh uniformly, -1 for auto.");
73 "Finite element order (polynomial degree).");
74 args.
AddOption(&NURBS,
"-n",
"--nurbs",
"-nn",
"--no-nurbs",
75 "Use NURBS spaces if the mesh is a NURBS mesh.");
77 "Choose between 0: grad, 1: curl, 2: div");
78 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
79 "--no-static-condensation",
"Enable static condensation.");
80 args.
AddOption(&pa,
"-pa",
"--partial-assembly",
"-no-pa",
81 "--no-partial-assembly",
"Enable Partial Assembly.");
82 args.
AddOption(&proj_type_int,
"-proj",
"--projection",
84 " 0 = DEFAULT: ELEMENTL2 for NURBS elements, ELEMENT else.\n"
85 " 1 = ELEMENT: As defined in the respective element.\n"
86 " 2 = GLOBALL2: Global L2 projection.\n"
87 " 3 = ELEMENTL2: Element L2 projection.");
88 args.
AddOption(&device_config,
"-d",
"--device",
89 "Device configuration string, see Device::Configure().");
90 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
92 "Enable or disable GLVis visualization.");
94 args.
AddOption(&visport,
"-p",
"--send-port",
"Socket for GLVis.");
107 Device device(device_config);
113 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
117 MFEM_ABORT(
"The curl problem is only defined in 3D.");
128 ref_levels = (int)floor(log(50000./mesh->
GetNE())/log(2.)/
dim);
130 for (
int l = 0; l < ref_levels; l++)
159 mfem::out <<
"Create NURBS finite element" << endl;
178 mfem::out <<
"Create standard finite elements" << endl;
189 mfem::out <<
"Number of HCurl finite element unknowns: " << test_size << endl;
190 mfem::out <<
"Number of H1 finite element unknowns: " << trial_size << endl;
194 mfem::out <<
"Number of HCurl finite element unknowns: " << trial_size << endl;
195 mfem::out <<
"Number of HDiv finite element unknowns: " << test_size
200 mfem::out <<
"Number of HDiv finite element unknowns: "
201 << trial_size << endl;
202 mfem::out <<
"Number of L2 finite element unknowns: " << test_size << endl;
237 a.SetAssemblyLevel(AssemblyLevel::PARTIAL);
261 if (static_cond) {
a.EnableStaticCondensation(); }
264 if (!pa) {
a.Finalize(); }
271 a_mixed.
Mult(gftrial, x);
276 mixed.
Mult(gftrial, x);
295 cg.SetPreconditioner(Jacobi);
303 cg.SetOperator(Amat);
304 cg.SetPreconditioner(Jacobi);
333 mfem::out <<
"\n Solution of (E_h,v) = (grad p_h,v) for E_h and v in H(curl): "
334 "|| E_h - grad p ||_{L_2} = " << errSol <<
'\n' << endl;
335 mfem::out <<
" Projection E_h of exact grad p in H(curl): || E_h - grad p "
336 "||_{L_2} = " << errProj <<
'\n' << endl;
343 mfem::out <<
"\n Solution of (E_h,w) = (curl v_h,w) for E_h and w in H(div): "
344 "|| E_h - curl v ||_{L_2} = " << errSol <<
'\n' << endl;
345 mfem::out <<
" Projection E_h of exact curl v in H(div): || E_h - curl v "
346 "||_{L_2} = " << errProj <<
'\n' << endl;
350 int order_quad = max(3, 2*order+1);
360 mfem::out <<
"\n Solution of (f_h,q) = (div v_h,q) for f_h and q in L_2: "
361 "|| f_h - div v ||_{L_2} = " << errSol <<
'\n' << endl;
363 mfem::out <<
" Projection f_h of exact div v in L_2: || f_h - div v "
364 "||_{L_2} = " << errProj <<
'\n' << endl;
369 ofstream mesh_ofs(
"refined.mesh");
370 mesh_ofs.precision(8);
371 mesh->
Print(mesh_ofs);
372 ofstream sol_ofs(
"sol.gf");
373 sol_ofs.precision(8);
381 sol_sock.precision(8);
382 sol_sock <<
"solution\n" << *mesh << x << flush;
397 return sin(x(0)) * sin(x(1)) * sin(x(2));
401 return sin(x(0)) * sin(x(1));
411 f(0) = cos(x(0)) * sin(x(1)) * sin(x(2));
412 f(1) = sin(x(0)) * cos(x(1)) * sin(x(2));
413 f(2) = sin(x(0)) * sin(x(1)) * cos(x(2));
417 f(0) = cos(x(0)) * sin(x(1));
418 f(1) = sin(x(0)) * cos(x(1));
419 if (x.
Size() == 3) {
f(2) = 0.0; }
427 return -3.0 * sin(x(0)) * sin(x(1)) * sin(x(2));
431 return -2.0 * sin(x(0)) * sin(x(1));
441 v(0) = sin(
kappa * x(1));
442 v(1) = sin(
kappa * x(2));
443 v(2) = sin(
kappa * x(0));
447 v(0) = sin(
kappa * x(1));
448 v(1) = sin(
kappa * x(0));
449 if (x.
Size() == 3) { v(2) = 0.0; }
Conjugate gradient method.
A coefficient that is constant across space and time.
Jacobi-type diagonal smoother of a sparse matrix.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
void Print(std::ostream &os=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...
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.
NURBSExtension * StealNURBSext()
A general function coefficient.
Class for grid function - Vector with associated FE space.
void SetTrueVector()
Shortcut for calling GetTrueDofs() with GetTrueVector() as argument.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
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.
void SetFromTrueVector()
Shortcut for calling SetFromTrueDofs() with GetTrueVector() as argument.
virtual void ProjectCoefficient(Coefficient &coeff, ProjectType type=ProjectType::DEFAULT)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Arbitrary order H1-conforming (continuous) finite elements.
Class for an integration rule - an Array of IntegrationPoint.
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
Arbitrary order "L2-conforming" discontinuous finite elements.
NURBSExtension * NURBSext
Optional NURBS mesh extension.
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
Print the mesh to the given stream using the default MFEM mesh format.
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 *)
Arbitrary order H(curl)-conforming Nedelec finite elements.
NURBSExtension generally contains multiple NURBSPatch objects spanning an entire Mesh....
Arbitrary order non-uniform rational B-splines (NURBS) finite elements.
Arbitrary order H(curl) NURBS finite elements.
Arbitrary order H(div) NURBS finite elements.
Jacobi smoothing for a given bilinear form (no matrix necessary).
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.
void Mult(const Vector &x, Vector &y) const override
Matrix vector multiplication.
A general vector function coefficient.
int Size() const
Returns the size of the vector.
const int * ess_tdof_list
ProjectType
This enumerated type describes the main projection types used by GridFunction::ProjectCoefficient():
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
std::function< real_t(const Vector &)> f(real_t mass_coeff)
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)
void Project(GridFunction &gf, CoefficientType &coef, int proj_type)
real_t p_exact(const Vector &x)
void curlv_exact(const Vector &x, Vector &cv)
void v_exact(const Vector &x, Vector &v)
void gradp_exact(const Vector &, Vector &)
real_t div_gradp_exact(const Vector &x)