59int main(
int argc,
char *argv[])
64 const char *mesh_file =
"../../data/square-nurbs.mesh";
68 const char *device_config =
"cpu";
70 bool visualization = 1;
73 args.
AddOption(&mesh_file,
"-m",
"--mesh",
75 args.
AddOption(&ref_levels,
"-r",
"--refine",
76 "Number of times to refine the mesh uniformly, -1 for auto.");
78 "Finite element order (polynomial degree).");
79 args.
AddOption(&pa,
"-pa",
"--partial-assembly",
"-no-pa",
80 "--no-partial-assembly",
"Enable Partial Assembly.");
81 args.
AddOption(&device_config,
"-d",
"--device",
82 "Device configuration string, see Device::Configure().");
83 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
85 "Enable or disable GLVis visualization.");
86 args.
AddOption(&visport,
"-p",
"--send-port",
"Socket for GLVis.");
97 Device device(device_config);
103 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
114 (int)floor(log(10000./mesh->
GetNE())/log(2.)/
dim);
116 for (
int l = 0; l < ref_levels; l++)
133 mfem::out<<
"Create NURBS fec and ext"<<std::endl;
139 mfem::out<<
"Create Normal fec"<<std::endl;
151 block_offsets[0] = 0;
152 block_offsets[1] = R_space->
GetVSize();
153 block_offsets[2] = W_space->
GetVSize();
156 std::cout <<
"***********************************************************\n";
157 std::cout <<
"dim(R) = " << block_offsets[1] - block_offsets[0] <<
"\n";
158 std::cout <<
"dim(W) = " << block_offsets[2] - block_offsets[1] <<
"\n";
159 std::cout <<
"dim(R+W) = " << block_offsets.
Last() <<
"\n";
160 std::cout <<
"***********************************************************\n";
169 cout <<
"Number boundary dofs in H(div): "
170 << ess_tdof_list.
Size() << endl;
181 cout <<
"Number boundary dofs in H1: "
182 << ess_tdof_list.
Size() << endl;
201 BlockVector x(block_offsets, mt), rhs(block_offsets, mt);
280 for (
int i=0; i<mVarf->
Height(); ++i)
282 invMd(i) = 1.0 / Md_host[i];
302 for (
int i = 0; i < Md.
Size(); i++)
307 S =
Mult(B, *MinvBt);
311#ifndef MFEM_USE_SUITESPARSE
341 if (device.
IsEnabled()) { x.HostRead(); }
347 <<
" iterations with a residual norm of "
353 <<
" iterations. Residual norm is " << solver.
GetFinalNorm()
356 std::cout <<
"MINRES solver took " << chrono.
RealTime() <<
"s.\n";
360 u.
MakeRef(R_space, x.GetBlock(0), 0);
361 p.MakeRef(W_space, x.GetBlock(1), 0);
363 int order_quad = max(2, 2*order+1);
370 real_t err_u =
u.ComputeL2Error(ucoeff, irs);
372 real_t err_p =
p.ComputeL2Error(pcoeff, irs);
375 std::cout <<
"|| u_h - u_ex || / || u_ex || = " << err_u / norm_u <<
"\n";
376 std::cout <<
"|| p_h - p_ex || / || p_ex || = " << err_p / norm_p <<
"\n";
382 ofstream mesh_ofs(
"ex5.mesh");
383 mesh_ofs.precision(8);
384 mesh->
Print(mesh_ofs);
386 ofstream u_ofs(
"sol_u.gf");
390 ofstream p_ofs(
"sol_p.gf");
419 u_sock <<
"solution\n" << *mesh <<
u <<
"window_title 'Velocity'" << endl;
422 p_sock <<
"solution\n" << *mesh <<
p <<
"window_title 'Pressure'" << endl;
455 u(0) = - exp(xi)*sin(yi)*cos(zi);
456 u(1) = - exp(xi)*cos(yi)*cos(zi);
460 u(2) = exp(xi)*sin(yi)*sin(zi);
476 return exp(xi)*sin(yi)*cos(zi);
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.
void PartialSum()
Fill the entries of the array with the cumulative sum of the entries.
T & Last()
Return the last element in the array.
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.
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.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
static MemoryType GetMemoryType()
(DEPRECATED) Equivalent to GetDeviceMemoryType().
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
static bool IsEnabled()
Return true if any backend other than Backend::CPU is enabled.
Class for domain integration .
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 void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1) const
Get a list of essential true dofs, ess_tdof_list, corresponding to the boundary attributes marked in ...
NURBSExtension * StealNURBSext()
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
A general function coefficient.
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.
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.
real_t GetFinalNorm() const
Returns the final residual norm after termination of the solver during the last call to Mult().
void SetRelTol(real_t rtol)
int GetNumIterations() const
Returns the number of iterations taken during the last call to Mult()
virtual void SetPrintLevel(int print_lvl)
Legacy method to set the level of verbosity of the solver output.
void SetMaxIter(int max_it)
bool GetConverged() const
Returns true if the last call to Mult() converged successfully.
void SetAbsTol(real_t atol)
Arbitrary order "L2-conforming" discontinuous finite elements.
void Mult(const Vector &b, Vector &x) const override
Iterative solution of the linear system using the MINRES method.
void SetOperator(const Operator &op) override
Also calls SetOperator for the preconditioner if there is one.
void SetPreconditioner(Solver &pr) override
This should be called before SetOperator.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
NURBSExtension * NURBSext
Optional NURBS mesh extension.
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
NURBSExtension generally contains multiple NURBSPatch objects spanning an entire Mesh....
Arbitrary order non-uniform rational B-splines (NURBS) finite elements.
Arbitrary order H(div) NURBS finite elements.
Jacobi smoothing for a given bilinear form (no matrix necessary).
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.
Helper class for ParaView visualization data.
void SetHighOrderOutput(bool high_order_output_)
void SetLevelsOfDetail(int levels_of_detail_)
void SetDataFormat(VTKFormat fmt)
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
bool iterative_mode
If true, use the second argument of Mult() as an initial guess.
void GetDiag(Vector &d) const
Returns the Diagonal of A.
void ScaleRow(const int row, const real_t scale)
double RealTime()
Return the number of real seconds elapsed since the stopwatch was started.
void Start()
Start the stopwatch. The elapsed time is not cleared.
void Stop()
Stop the stopwatch.
void Clear()
Clear the elapsed time on the stopwatch and restart it if it's running.
The transpose of a given operator. Switches the roles of the methods Mult() and MultTranspose().
Direct sparse solver using UMFPACK.
for VectorFiniteElements (Nedelec, Raviart-Thomas)
A general vector function coefficient.
virtual const real_t * HostRead() const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), false).
void SyncAliasMemory(const Vector &v) const
Update the alias memory location of the vector to match v.
int Size() const
Returns the size of the vector.
virtual real_t * HostReadWrite()
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
Data collection with VisIt I/O routines.
void Save() override
Save the collection and a VisIt root file.
void RegisterField(const std::string &field_name, GridFunction *gf) override
Add a grid function to the collection and update the root file.
real_t u(const Vector &xvec)
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
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.
real_t ComputeLpNorm(real_t p, Coefficient &coeff, Mesh &mesh, const IntegrationRule *irs[])
Compute the Lp norm of a function f. .
MemoryType
Memory types supported by MFEM.
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)
real_t p(const Vector &x, real_t t)
real_t pFun_ex(const Vector &x)
void uFun_ex(const Vector &x, Vector &u)
real_t gFun(const Vector &x)
real_t f_natural(const Vector &x)
void fFun(const Vector &x, Vector &f)