50 #include "../common/mfem-common.hpp" 57 class PRefinementGFUpdate
68 ~PRefinementGFUpdate();
85 PRefinementGFUpdate::~PRefinementGFUpdate()
92 if (src) {
delete src; }
96 void PRefinementGFUpdate::GridFunctionUpdate(
GridFunction &targf)
99 "GridFunction should not be updated prior to UpdateGF.");
104 preft.
Mult(srcgf, targf);
113 const int vdim = fespace->
GetVDim();
124 else if (fieldtype == 1)
138 for (
int i = 0; i < mesh->
GetNE(); i++)
141 T.SetIdentityTransformation(geom);
145 Vector elemvect(0), vectInt(0);
150 const auto *feInt = fecInt->
GetFE(geom, max_order);
158 Mult(I, elemvecMat, vectIntMat);
174 for (
int e = 0; e < mesh->
GetNE(); e++)
181 400, 0, 400, 400,
"RjmAcp");
191 for (
int d = 0; d <
dim; d++) { res += std::pow(x(d),
func_order); }
198 for (
int i = 1; i < F.
Size(); i++) { F(i) = (i+1)*F(0); }
201 int main (
int argc,
char *argv[])
204 const char *mesh_file =
"../../data/rt-2d-q3.mesh";
206 int mesh_poly_deg = 3;
208 bool visualization =
true;
211 bool hrefinement =
false;
212 bool prefinement =
false;
213 int point_ordering = 0;
215 bool mesh_prefinement =
false;
219 args.
AddOption(&mesh_file,
"-m",
"--mesh",
220 "Mesh file to use.");
222 "Finite element order (polynomial degree).");
223 args.
AddOption(&mesh_poly_deg,
"-mo",
"--mesh-order",
224 "Polynomial degree of mesh finite element space.");
225 args.
AddOption(&rs_levels,
"-rs",
"--refine-serial",
226 "Number of times to refine the mesh uniformly in serial.");
227 args.
AddOption(&fieldtype,
"-ft",
"--field-type",
228 "Field type: 0 - H1, 1 - L2, 2 - H(div), 3 - H(curl).");
230 "Number of components for H1 or L2 GridFunctions");
231 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
232 "--no-visualization",
233 "Enable or disable GLVis visualization.");
234 args.
AddOption(&hrefinement,
"-hr",
"--h-refinement",
"-no-hr",
236 "Do random h refinements to mesh (does not work for pyramids).");
237 args.
AddOption(&prefinement,
"-pr",
"--p-refinement",
"-no-pr",
239 "Do random p refinements to solution field (does not work for pyramids).");
240 args.
AddOption(&point_ordering,
"-po",
"--point-ordering",
241 "Ordering of points to be found." 242 "0 (default): byNodes, 1: byVDIM");
243 args.
AddOption(&gf_ordering,
"-fo",
"--fespace-ordering",
244 "Ordering of fespace that will be used for gridfunction to be interpolated." 245 "0 (default): byNodes, 1: byVDIM");
246 args.
AddOption(&mesh_prefinement,
"-mpr",
"--mesh-p-refinement",
"-no-mpr",
247 "--no-mesh-p-refinement",
248 "Do random p refinements to mesh Nodes.");
261 Mesh mesh(mesh_file, 1, 1,
false);
264 cout <<
"Mesh curvature of the original mesh: ";
266 else { cout <<
"(NONE)"; }
271 MFEM_VERIFY(mesh_poly_deg > 0,
"The order of the mesh must be positive.");
273 if (hrefinement || prefinement || mesh_prefinement) { mesh.
EnsureNCMesh(
true); }
274 cout <<
"--- Generating equidistant point for:\n" 275 <<
"x in [" << pos_min(0) <<
", " << pos_max(0) <<
"]\n" 276 <<
"y in [" << pos_min(1) <<
", " << pos_max(1) <<
"]\n";
279 cout <<
"z in [" << pos_min(2) <<
", " << pos_max(2) <<
"]\n";
291 cout <<
"Mesh curvature of the curved mesh: " << fecm.
Name() << endl;
293 PRefinementGFUpdate preft_fespace = PRefinementGFUpdate(fespace);
295 if (mesh_prefinement)
297 for (
int e = 0; e < mesh.
GetNE(); e++)
299 if ((
double) rand() / RAND_MAX < 0.2)
306 preft_fespace.GridFunctionUpdate(Nodes);
309 MFEM_VERIFY(ncomp > 0,
"Invalid number of components.");
315 cout <<
"H1-GridFunction\n";
317 else if (fieldtype == 1)
320 cout <<
"L2-GridFunction\n";
322 else if (fieldtype == 2)
327 cout <<
"H(div)-GridFunction\n";
329 else if (fieldtype == 3)
334 cout <<
"H(curl)-GridFunction\n";
338 MFEM_ABORT(
"Invalid field type.");
346 for (
int e = 0; e < mesh.
GetNE(); e++)
348 if ((
double) rand() / RAND_MAX < 0.5)
361 if (mesh_prefinement && visualization)
368 if (prefinement && visualization)
390 0, 0, 400, 400,
"RmjA*****");
397 const int pts_cnt_1D = 25;
398 int pts_cnt = pow(pts_cnt_1D,
dim);
409 vxyz(i) = pos_min(0) + ip.
x * (pos_max(0)-pos_min(0));
410 vxyz(pts_cnt + i) = pos_min(1) + ip.
y * (pos_max(1)-pos_min(1));
414 vxyz(i*
dim + 0) = pos_min(0) + ip.
x * (pos_max(0)-pos_min(0));
415 vxyz(i*
dim + 1) = pos_min(1) + ip.
y * (pos_max(1)-pos_min(1));
428 vxyz(i) = pos_min(0) + ip.
x * (pos_max(0)-pos_min(0));
429 vxyz(pts_cnt + i) = pos_min(1) + ip.
y * (pos_max(1)-pos_min(1));
430 vxyz(2*pts_cnt + i) = pos_min(2) + ip.
z * (pos_max(2)-pos_min(2));
434 vxyz(i*
dim + 0) = pos_min(0) + ip.
x * (pos_max(0)-pos_min(0));
435 vxyz(i*
dim + 1) = pos_min(1) + ip.
y * (pos_max(1)-pos_min(1));
436 vxyz(i*
dim + 2) = pos_min(2) + ip.
z * (pos_max(2)-pos_min(2));
442 Vector interp_vals(pts_cnt*vec_dim);
446 finder.
Interpolate(vxyz, field_vals, interp_vals, point_ordering);
450 int face_pts = 0, not_found = 0, found = 0;
451 double error = 0.0, max_err = 0.0, max_dist = 0.0;
453 for (
int j = 0; j < vec_dim; j++)
455 for (
int i = 0; i < pts_cnt; i++)
459 if (j == 0) { found++; }
460 for (
int d = 0; d <
dim; d++)
463 vxyz(d*pts_cnt + i) :
466 Vector exact_val(vec_dim);
469 fabs(exact_val(j) - interp_vals[i + j*pts_cnt]) :
470 fabs(exact_val(j) - interp_vals[i*vec_dim + j]);
471 max_err = std::max(max_err, error);
472 max_dist = std::max(max_dist, dist_p_out(i));
473 if (code_out[i] == 1 && j == 0) { face_pts++; }
475 else {
if (j == 0) { not_found++; } }
479 cout << setprecision(16)
480 <<
"Searched points: " << pts_cnt
481 <<
"\nFound points: " << found
482 <<
"\nMax interp error: " << max_err
483 <<
"\nMax dist (of found): " << max_dist
484 <<
"\nPoints not found: " << not_found
485 <<
"\nPoints on faces: " << face_pts << endl;
490 if (mesh_prefinement) {
delete mesh_nodes_pref; }
491 if (prefinement) {
delete field_vals_pref; }
virtual void Interpolate(const GridFunction &field_in, Vector &field_out)
void SetSubVector(const Array< int > &dofs, const double value)
Set the entries listed in dofs to the given value.
int GetNPoints() const
Returns the number of the points in the integration rule.
Class for an integration rule - an Array of IntegrationPoint.
Class for grid function - Vector with associated FE space.
virtual void Update(bool want_transform=true)
Reflect changes in the mesh: update number of DOFs, etc. Also, calculate GridFunction transformation ...
void PrintOptions(std::ostream &out) const
Print the options.
Arbitrary order L2 elements in 3D on a cube.
int Dimension() const
Dimension of the reference space used within the elements.
Matrix-free transfer operator between finite element spaces on the same mesh.
const FiniteElement * GetFE(Geometry::Type geom, int p) const
Variable order version of FiniteElementForGeometry().
void SetSize(int s)
Resize the vector to size s.
void PrintUsage(std::ostream &out) const
Print the usage message.
void SetElementOrder(int i, int p)
Sets the order of the i'th finite element.
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
void GetBoundingBox(Vector &min, Vector &max, int ref=2)
Returns the minimum and maximum corners of the mesh bounding box.
int Size() const
Returns the size of the vector.
Data type dense matrix using column-major storage.
bool Good() const
Return true if the command line options were parsed successfully.
void MakeOwner(FiniteElementCollection *fec_)
Make the GridFunction the owner of fec and fes.
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
double field_func(const Vector &x)
virtual void SetL2AvgType(AvgType avgtype_)
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
void VisualizeFESpacePolynomialOrder(FiniteElementSpace &fespace, const char *title)
int GetMaxElementOrder() const
Return the maximum polynomial order.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void EnsureNCMesh(bool simplices_nonconforming=false)
const FiniteElementCollection * FEColl() const
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
GridFunction * ProlongToMaxOrder(const GridFunction *x, const int fieldtype)
void Setup(Mesh &m, const double bb_t=0.1, const double newt_tol=1.0e-12, const int npt_max=256)
void RandomRefinement(double prob, bool aniso=false, int nonconforming=-1, int nc_limit=0)
Refine each element with given probability. Uses GeneralRefinement.
virtual void GetTransferMatrix(const FiniteElement &fe, ElementTransformation &Trans, DenseMatrix &I) const
Return interpolation matrix, I, which maps dofs from a coarse element, fe, to the fine dofs on this f...
virtual void SetNodalFESpace(FiniteElementSpace *nfes)
FiniteElementSpace * FESpace()
double * GetData() const
Return a pointer to the beginning of the Vector data.
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
int GetVDim() const
Returns vector dimension.
A general vector function coefficient.
DofTransformation * GetElementVDofs(int i, Array< int > &vdofs) const
Returns indices of degrees of freedom for the i'th element. The returned indices are offsets into an ...
Geometry::Type GetElementGeometry(int i) const
Mesh * GetMesh() const
Returns the mesh.
double p(const Vector &x, double t)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
virtual const char * Name() const
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...
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
int GetNE() const
Returns number of elements.
Class for integration point with weight.
int GetElementOrder(int i) const
Returns the order of the i'th finite element.
virtual void Mult(const Vector &x, Vector &y) const override
Interpolation or prolongation of a vector x corresponding to the coarse space to the vector y corresp...
Ordering::Type GetOrdering() const
Return the ordering method.
virtual const Vector & GetDist() const
Arbitrary order L2 elements in 2D on a square.
void F_exact(const Vector &p, Vector &F)
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
int Size() const
Return the logical size of the array.
Arbitrary order H(curl)-conforming Nedelec finite elements.
Nodes: x_i = i/(n-1), i=0,...,n-1.
FindPointsGSLIB can robustly evaluate a GridFunction on an arbitrary collection of points...
void VisualizeField(socketstream &sock, const char *vishost, int visport, GridFunction &gf, const char *title, int x, int y, int w, int h, const char *keys, bool vec)
Arbitrary order H1-conforming (continuous) finite elements.
void GetNodes(Vector &node_coord) const
void SetNodalGridFunction(GridFunction *nodes, bool make_owner=false)
virtual const Array< unsigned int > & GetCode() const
const IntegrationRule & GetNodes() const
Get a const reference to the nodes of the element.
int main(int argc, char *argv[])
Arbitrary order "L2-conforming" discontinuous finite elements.