57class PRefinementGFUpdate
68 ~PRefinementGFUpdate();
85PRefinementGFUpdate::~PRefinementGFUpdate()
92 if (src) {
delete src; }
96void 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++)
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); }
201int 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)
360 if (mesh_prefinement && visualization)
367 if (prefinement && visualization)
389 0, 0, 400, 400,
"RmjA*****");
396 const int pts_cnt_1D = 25;
397 int pts_cnt = pow(pts_cnt_1D,
dim);
408 vxyz(i) = pos_min(0) + ip.
x * (pos_max(0)-pos_min(0));
409 vxyz(pts_cnt + i) = pos_min(1) + ip.
y * (pos_max(1)-pos_min(1));
413 vxyz(i*
dim + 0) = pos_min(0) + ip.
x * (pos_max(0)-pos_min(0));
414 vxyz(i*
dim + 1) = pos_min(1) + ip.
y * (pos_max(1)-pos_min(1));
427 vxyz(i) = pos_min(0) + ip.
x * (pos_max(0)-pos_min(0));
428 vxyz(pts_cnt + i) = pos_min(1) + ip.
y * (pos_max(1)-pos_min(1));
429 vxyz(2*pts_cnt + i) = pos_min(2) + ip.
z * (pos_max(2)-pos_min(2));
433 vxyz(i*
dim + 0) = pos_min(0) + ip.
x * (pos_max(0)-pos_min(0));
434 vxyz(i*
dim + 1) = pos_min(1) + ip.
y * (pos_max(1)-pos_min(1));
435 vxyz(i*
dim + 2) = pos_min(2) + ip.
z * (pos_max(2)-pos_min(2));
441 Vector interp_vals(pts_cnt*vec_dim);
445 finder.
Interpolate(vxyz, field_vals, interp_vals, point_ordering);
449 int face_pts = 0, not_found = 0, found = 0;
450 double error = 0.0, max_err = 0.0, max_dist = 0.0;
452 for (
int j = 0; j < vec_dim; j++)
454 for (
int i = 0; i < pts_cnt; i++)
458 if (j == 0) { found++; }
459 for (
int d = 0; d <
dim; d++)
462 vxyz(d*pts_cnt + i) :
465 Vector exact_val(vec_dim);
468 fabs(exact_val(j) - interp_vals[i + j*pts_cnt]) :
469 fabs(exact_val(j) - interp_vals[i*vec_dim + j]);
470 max_err = std::max(max_err, error);
471 max_dist = std::max(max_dist, dist_p_out(i));
472 if (code_out[i] == 1 && j == 0) { face_pts++; }
474 else {
if (j == 0) { not_found++; } }
478 cout << setprecision(16)
479 <<
"Searched points: " << pts_cnt
480 <<
"\nFound points: " << found
481 <<
"\nMax interp error: " << max_err
482 <<
"\nMax dist (of found): " << max_dist
483 <<
"\nPoints not found: " << not_found
484 <<
"\nPoints on faces: " << face_pts << endl;
489 if (mesh_prefinement) {
delete mesh_nodes_pref; }
490 if (prefinement) {
delete field_vals_pref; }
int Size() const
Return the logical size of the array.
@ ClosedUniform
Nodes: x_i = i/(n-1), i=0,...,n-1.
Data type dense matrix using column-major storage.
FindPointsGSLIB can robustly evaluate a GridFunction on an arbitrary collection of points....
virtual const Vector & GetDist() const
void Setup(Mesh &m, const double bb_t=0.1, const double newt_tol=1.0e-12, const int npt_max=256)
virtual void Interpolate(const GridFunction &field_in, Vector &field_out)
virtual const Array< unsigned int > & GetCode() const
virtual void SetL2AvgType(AvgType avgtype_)
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
const FiniteElement * GetFE(Geometry::Type geom, int p) const
Variable order version of FiniteElementForGeometry().
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
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 ...
Ordering::Type GetOrdering() const
Return the ordering method.
virtual void Update(bool want_transform=true)
Reflect changes in the mesh: update number of DOFs, etc. Also, calculate GridFunction transformation ...
int GetElementOrder(int i) const
Returns the order of the i'th finite element.
void SetElementOrder(int i, int p)
Sets the order of the i'th finite element.
const FiniteElementCollection * FEColl() const
Mesh * GetMesh() const
Returns the mesh.
int GetMaxElementOrder() const
Return the maximum polynomial order.
int GetVDim() const
Returns vector dimension.
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...
const IntegrationRule & GetNodes() const
Get a const reference to the nodes of the element.
Class for grid function - Vector with associated FE space.
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
void MakeOwner(FiniteElementCollection *fec_)
Make the GridFunction the owner of fec and fes.
FiniteElementSpace * FESpace()
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Arbitrary order H1-conforming (continuous) finite elements.
const char * Name() const override
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.
Arbitrary order "L2-conforming" discontinuous finite elements.
Arbitrary order L2 elements in 3D on a cube.
Arbitrary order L2 elements in 2D on a square.
Geometry::Type GetElementGeometry(int i) const
int GetNE() const
Returns number of elements.
void GetBoundingBox(Vector &min, Vector &max, int ref=2)
Returns the minimum and maximum corners of the mesh bounding box.
int Dimension() const
Dimension of the reference space used within the elements.
void RandomRefinement(real_t prob, bool aniso=false, int nonconforming=-1, int nc_limit=0)
Refine each element with given probability. Uses GeneralRefinement.
void SetNodalGridFunction(GridFunction *nodes, bool make_owner=false)
void GetNodes(Vector &node_coord) const
virtual void SetNodalFESpace(FiniteElementSpace *nfes)
void EnsureNCMesh(bool simplices_nonconforming=false)
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Arbitrary order H(curl)-conforming Nedelec finite elements.
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.
Matrix-free transfer operator between finite element spaces on the same mesh.
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...
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
A general vector function coefficient.
void SetSubVector(const Array< int > &dofs, const real_t value)
Set the entries listed in dofs to the given value.
int Size() const
Returns the size of the vector.
void SetSize(int s)
Resize the vector to size s.
real_t * GetData() const
Return a pointer to the beginning of the Vector data.
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)
GridFunction * ProlongToMaxOrder(const GridFunction *x, const int fieldtype)
void VisualizeFESpacePolynomialOrder(FiniteElementSpace &fespace, const char *title)
void F_exact(const Vector &p, Vector &F)
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)
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
real_t p(const Vector &x, real_t t)