57inline bool operator==(
const Data& d1,
const Data& d2) {
return (d1.x == d2.x); }
58inline bool operator <(
const Data& d1,
const Data& d2) {
return (d1.x < d2.x); }
65#ifndef MFEM_THREAD_SAFE
72 Diffusion2Integrator() { Q = NULL; }
87#ifdef MFEM_THREAD_SAFE
131 w *= Q->
Eval(Trans, ip);
134 for (
int jj = 0; jj < nd; jj++)
136 for (
int ii = 0; ii < nd; ii++)
138 elmat(ii, jj) += w*shape(ii)*laplace(jj);
150 if ((x[1] - x[0] - 0.5 < 0.0) &&
151 (x[0] + x[1] -0.99 < 0.0))
160int main(
int argc,
char *argv[])
163 const char *mesh_file =
"../../data/square-nurbs.mesh";
164 const char *per_file =
"none";
165 const char *ref_file =
"";
170 bool static_cond =
false;
171 bool visualization = 1;
179 bool homogenousBC =
true;
182 args.
AddOption(&mesh_file,
"-m",
"--mesh",
183 "Mesh file to use.");
184 args.
AddOption(&ref_levels,
"-r",
"--refine",
185 "Number of times to refine the mesh uniformly, -1 for auto.");
187 "Periodic BCS file.");
188 args.
AddOption(&ref_file,
"-rf",
"--ref-file",
189 "File with refinement data");
190 args.
AddOption(&master,
"-pm",
"--master",
191 "Master boundaries for periodic BCs");
193 "Slave boundaries for periodic BCs");
195 "Boundaries with Neumann BCs");
196 args.
AddOption(&homogenousBC,
"-h",
"--hom",
198 "Selection for using homogeneous Dirichelet boundary conditions.");
200 "Finite element order (polynomial degree) or -1 for"
201 " isoparametric space.");
203 "-no-ibp",
"--no-ibp",
204 "Selects the standard weak form (IBP) or the nonstandard (NO-IBP).");
205 args.
AddOption(&strongBC,
"-sbc",
"--strong-bc",
"-wbc",
207 "Selects strong or weak enforcement of Dirichlet BCs.");
209 "Sets the SIPG penalty parameters, should be positive."
210 " Negative values are replaced with (order+1)^2.");
211 args.
AddOption(&static_cond,
"-sc",
"--static-condensation",
"-no-sc",
212 "--no-static-condensation",
"Enable static condensation.");
213 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
214 "--no-visualization",
215 "Enable or disable GLVis visualization.");
216 args.
AddOption(&lod,
"-lod",
"--level-of-detail",
217 "Refinement level for 1D solution output (0 means no output).");
218 args.
AddOption(&visport,
"-p",
"--send-port",
"Socket for GLVis.");
225 if (!strongBC & (
kappa < 0))
234 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
243 if (mesh->
NURBSext && (strlen(ref_file) != 0))
251 (int)floor(log(5000./mesh->
GetNE())/log(2.)/
dim);
254 for (
int l = 0; l < ref_levels; l++)
274 if (order.
Size() == 1)
281 if (order.
Size() != nkv ) {
mfem_error(
"Wrong number of orders set."); }
286 in.open(per_file, std::ifstream::in);
293 master.
Load(in, psize);
294 slave.
Load(in, psize);
299 else if (order[0] == -1)
305 cout <<
"Using isoparametric FEs: " << fec->
Name() << endl;
309 cout <<
"Mesh does not have FEs --> Assume order 1.\n";
316 if (order.
Size() > 1) { cout <<
"Wrong number of orders set, needs one.\n"; }
322 cout <<
"Number of finite element unknowns: "
329 cout <<
"No integration by parts requires a NURBS mesh."<< endl;
334 cout <<
"No integration by parts requires a NURBS mesh, with only 1 patch."<<
336 cout <<
"A C_1 discretisation is required."<< endl;
337 cout <<
"Currently only C_0 multipatch coupling implemented."<< endl;
342 cout <<
"No integration by parts requires at least quadratic NURBS."<< endl;
343 cout <<
"A C_1 discretisation is required."<< endl;
366 for (
int i = 0; i < neu.
Size(); i++)
368 if ( neu[i]-1 >= 0 &&
371 ess_bdr[neu[i]-1] = 0;
372 neu_bdr[neu[i]-1] = 1;
376 cout <<
"Neumann boundary "<<neu[i]<<
" out of range -- discarded"<< endl;
381 for (
int i = 0; i < master.
Size(); i++)
383 if ( master[i]-1 >= 0 &&
386 ess_bdr[master[i]-1] = 0;
387 neu_bdr[master[i]-1] = 0;
388 per_bdr[master[i]-1] = 1;
392 cout <<
"Master boundary "<<master[i]<<
" out of range -- discarded"<< endl;
395 for (
int i = 0; i < slave.
Size(); i++)
397 if ( slave[i]-1 >= 0 &&
400 ess_bdr[slave[i]-1] = 0;
401 neu_bdr[slave[i]-1] = 0;
402 per_bdr[slave[i]-1] = 1;
406 cout <<
"Slave boundary "<<slave[i]<<
" out of range -- discarded"<< endl;
410 cout <<
"Boundary conditions:"<< endl;
411 cout <<
" - Periodic : "; per_bdr.
Print();
412 cout <<
" - Essential : "; ess_bdr.
Print();
413 cout <<
" - Neumann : "; neu_bdr.
Print();
427 b->AddBdrFaceIntegrator(
458 a->AddDomainIntegrator(
new Diffusion2Integrator(one));
471 if (static_cond) {
a->EnableStaticCondensation(); }
483 cout <<
"Size of linear system: " << A.
Height() << endl;
485#ifndef MFEM_USE_SUITESPARSE
489 PCG(A, M, B, X, 1, 200, 1e-12, 0.0);
493 umf_solver.
Control[UMFPACK_ORDERING] = UMFPACK_ORDERING_METIS;
495 umf_solver.
Mult(B, X);
499 a->RecoverFEMSolution(X, *
b, x);
504 ofstream mesh_ofs(
"refined.mesh");
505 mesh_ofs.precision(8);
506 mesh->
Print(mesh_ofs);
507 ofstream sol_ofs(
"sol.gf");
508 sol_ofs.precision(8);
518 sol_sock.precision(8);
519 sol_sock <<
"solution\n" << *mesh << x << flush;
534 for (
int i = 0; i < mesh->
GetNE(); i++)
543 for (
int j = 0; j < vals.
Size(); j++)
545 sol.push_back(Data(coords[j],vals[j]));
550 ofstream sol_ofs(
"solution.dat");
551 for (std::list<Data>::iterator d =
sol.begin(); d !=
sol.end(); ++d)
553 sol_ofs<<d->x <<
"\t"<<d->val<<endl;
577 if (own_fec) {
delete fec; }
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void Load(std::istream &in, int fmt=0)
Read an Array from the stream in using format fmt. The format fmt can be:
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 Print(std::ostream &out=mfem::out, int width=4) const
Prints array to stream with width elements per row.
Class for boundary integration .
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
virtual real_t Eval(ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the coefficient in the element described by T at the point ip.
A coefficient that is constant across space and time.
Data type dense matrix using column-major storage.
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
Class for domain integration .
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
virtual const char * Name() const
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.
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 ...
Abstract class for all finite elements.
int GetOrder() const
Returns the order of the finite element. In the case of anisotropic orders, returns the maximum order...
int GetDim() const
Returns the reference space dimension for the finite element.
Geometry::Type GetGeomType() const
Returns the Geometry::Type of the reference element.
int Space() const
Returns the type of FunctionSpace on the element.
void CalcPhysLaplacian(ElementTransformation &Trans, Vector &Laplacian) const
Evaluate the Laplacian of all shape functions of a scalar finite element in physical space at the giv...
virtual void CalcShape(const IntegrationPoint &ip, Vector &shape) const =0
Evaluate the values of all shape functions of a scalar finite element in reference space at the given...
int GetDof() const
Returns the number of degrees of freedom in the finite element.
A general function coefficient.
@ Pk
Polynomials of order k.
@ rQk
Refined tensor products of polynomials of order k.
Gauss-Seidel smoother of a sparse matrix.
RefinedGeometry * Refine(Geometry::Type Geom, int Times, int ETimes=1)
Class for grid function - Vector with associated FE space.
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
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 integration point with weight.
Class for an integration rule - an Array of IntegrationPoint.
int GetNPoints() const
Returns the number of the points in the integration rule.
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
const IntegrationRule * IntRule
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
NURBSExtension * NURBSext
Optional NURBS mesh extension.
void RefineNURBSFromFile(std::string ref_file)
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.
void GetNodes(Vector &node_coord) const
virtual void PrintInfo(std::ostream &os=mfem::out)
In serial, this method calls PrintCharacteristics(). In parallel, additional information about the pa...
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Geometry::Type GetElementBaseGeometry(int i) const
NURBSExtension generally contains multiple NURBSPatch objects spanning an entire Mesh....
int GetNP() const
Return the number of patches.
int GetNKV() const
Return the number of KnotVectors.
void ConnectBoundaries()
Set DOF maps for periodic BC.
Arbitrary order non-uniform rational B-splines (NURBS) finite elements.
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.
Direct sparse solver using UMFPACK.
real_t Control[UMFPACK_CONTROL]
void SetOperator(const Operator &op) override
Factorize the given Operator op which must be a SparseMatrix.
void Mult(const Vector &b, Vector &x) const override
Direct solution of the linear system using UMFPACK.
int Size() const
Returns the size of the vector.
void SetSize(int s)
Resize the vector to size s.
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.
const int * ess_tdof_list
void mfem_error(const char *msg)
GeometryRefiner GlobGeometryRefiner
void PCG(const Operator &A, Solver &B, const Vector &b, Vector &x, int print_iter, int max_num_iter, real_t RTOLERANCE, real_t ATOLERANCE)
Preconditioned conjugate gradient method. (tolerances are squared)
bool operator==(const Array< T > &LHS, const Array< T > &RHS)
IntegrationRules RefinedIntRules(1, Quadrature1D::GaussLegendre)
A global object with all refined integration rules.
bool operator<(const Pair< A, B > &p, const Pair< A, B > &q)
Comparison operator for class Pair, based on the first element only.
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)
real_t sol(const Vector &x)
MFEM_HOST_DEVICE real_t abs(const Complex &z)
std::array< int, NCMesh::MaxFaceNodes > nodes