63 const char *title,
int locx)
70 for (
int e = 0; e < mesh->
GetNE(); e++)
77 locx, 0, 400, 400,
"RjmAcp");
87 for (
int d = 0; d <
dim; d++) { res += std::pow(x(d),
func_order); }
94 for (
int i = 1; i < F.
Size(); i++) { F(i) = (i+1)*F(0); }
97int main (
int argc,
char *argv[])
100 const char *mesh_file =
"../../data/rt-2d-q3.mesh";
102 int mesh_poly_deg = 3;
104 bool visualization =
true;
107 bool hrefinement =
false;
108 bool prefinement =
false;
109 int point_ordering = 0;
111 bool mesh_prefinement =
false;
112 int randomization = 0;
114 bool surface =
false;
115 double surf_aabb_sz_inc = 0.0;
119 args.
AddOption(&mesh_file,
"-m",
"--mesh",
120 "Mesh file to use.");
122 "Finite element order (polynomial degree).");
123 args.
AddOption(&mesh_poly_deg,
"-mo",
"--mesh-order",
124 "Polynomial degree of mesh finite element space.");
125 args.
AddOption(&rs_levels,
"-rs",
"--refine-serial",
126 "Number of times to refine the mesh uniformly in serial.");
127 args.
AddOption(&fieldtype,
"-ft",
"--field-type",
128 "Field type: 0 - H1, 1 - L2, 2 - H(div), 3 - H(curl).");
130 "Number of components for H1 or L2 GridFunctions");
131 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
132 "--no-visualization",
133 "Enable or disable GLVis visualization.");
134 args.
AddOption(&hrefinement,
"-hr",
"--h-refinement",
"-no-hr",
136 "Do random h refinements to mesh (does not work for pyramids).");
137 args.
AddOption(&prefinement,
"-pr",
"--p-refinement",
"-no-pr",
139 "Do random p refinements to solution field (does not work for pyramids).");
140 args.
AddOption(&point_ordering,
"-po",
"--point-ordering",
141 "Ordering of points to be found."
142 "0 (default): byNodes, 1: byVDIM");
143 args.
AddOption(&gf_ordering,
"-fo",
"--fespace-ordering",
144 "Ordering of fespace that will be used for grid function to be interpolated."
145 "0 (default): byNodes, 1: byVDIM");
146 args.
AddOption(&mesh_prefinement,
"-mpr",
"--mesh-p-refinement",
"-no-mpr",
147 "--no-mesh-p-refinement",
148 "Do random p refinements to mesh Nodes.");
149 args.
AddOption(&randomization,
"-random",
"--random",
150 "0: generate points randomly in the bounding box of domain, "
151 "1: generate points randomly inside each element in mesh.");
153 "Number of points per element when -random 1 is used.");
154 args.
AddOption(&surface,
"-surf",
"--surface",
"-no-surf",
156 "Extract surface mesh from volume mesh.");
157 args.
AddOption(&surf_aabb_sz_inc,
"-sabs",
"--surface-aabb-size-inc",
158 "Absolute AABB expansion applied to surface-search "
159 "axis-aligned bounding boxes in FindPointsGSLIB surface meshes.");
172 Mesh input_mesh(mesh_file, 1, 1,
false);
173 Mesh *mesh = surface ? nullptr : &input_mesh;
177 "--surface requires a mesh with boundary attributes.");
182 MFEM_VERIFY(!(surface && prefinement),
183 "Surface interpolation does not support variable-order "
184 "solution spaces; use -no-pr with --surface.");
189 cout <<
"Mesh curvature of the original mesh: ";
191 else { cout <<
"(NONE)"; }
196 MFEM_VERIFY(mesh_poly_deg > 0,
"The order of the mesh must be positive.");
198 if (hrefinement || prefinement || mesh_prefinement)
203 cout <<
"--- Generating points for:\n"
204 <<
"x in [" << pos_min(0) <<
", " << pos_max(0) <<
"]\n";
207 cout <<
"y in [" << pos_min(1) <<
", " << pos_max(1) <<
"]" << std::endl;
211 cout <<
"z in [" << pos_min(2) <<
", " << pos_max(2) <<
"]\n";
223 cout <<
"Mesh curvature of the curved mesh: " << fecm.
Name() << endl;
225 if (mesh_prefinement)
228 for (
int e = 0; e < mesh->
GetNE(); e++)
230 if ((
double) rand() / RAND_MAX < 0.2)
235 std::cout << refs.
Size() <<
" elements will be p-refined for the mesh." <<
241 MFEM_VERIFY(ncomp > 0,
"Invalid number of components.");
247 cout <<
"H1-GridFunction\n";
249 else if (fieldtype == 1)
252 cout <<
"L2-GridFunction\n";
254 else if (fieldtype == 2)
259 cout <<
"H(div)-GridFunction\n";
261 else if (fieldtype == 3)
266 cout <<
"H(curl)-GridFunction\n";
270 MFEM_ABORT(
"Invalid field type.");
279 for (
int e = 0; e < mesh->
GetNE(); e++)
281 if ((
double) rand() / RAND_MAX < 0.5)
290 std::unique_ptr<GridFunction> mesh_nodes_max;
293 mesh_nodes_max.get() : &Nodes;
295 if (mesh_prefinement && visualization)
302 if (prefinement && visualization)
313 std::unique_ptr<GridFunction> field_vals_max;
316 field_vals_max.get() : &field_vals;
325 0, 0, 400, 400,
"RmjA*****");
333 int npt_face_per_elem = 4;
334 int npt_total_face = 0;
335 if (randomization == 0)
341 for (
int i = 0; i < pts_cnt; i++)
343 for (
int d = 0; d < sdim; d++)
347 vxyz(i + d*pts_cnt) =
348 pos_min(d) + vxyz(i + d*pts_cnt) * (pos_max(d) - pos_min(d));
353 pos_min(d) + vxyz(i*sdim + d) * (pos_max(d) - pos_min(d));
360 pts_cnt = npt * mesh->
GetNE();
362 for (
int i = 0; i < mesh->
GetNE(); i++)
366 for (
int j = 0; j < npt; j++)
370 if (j < npt_face_per_elem)
377 for (
int d = 0; d < sdim; d++)
381 vxyz(j + npt*i + d*pts_cnt) = pos_i(d);
385 vxyz((j + npt*i)*sdim + d) = pos_i(d);
393 Vector interp_vals(pts_cnt*vec_dim);
395 if (surface && surf_aabb_sz_inc > 0.0)
397 Vector bb_size({surf_aabb_sz_inc});
406 finder.
Interpolate(vxyz, field_vals, interp_vals, point_ordering);
410 int face_pts = 0, not_found = 0, found = 0;
411 double error = 0.0, max_err = 0.0, max_dist = 0.0;
413 for (
int j = 0; j < vec_dim; j++)
415 for (
int i = 0; i < pts_cnt; i++)
419 if (j == 0) { found++; }
420 for (
int d = 0; d < sdim; d++)
423 vxyz(d*pts_cnt + i) :
426 Vector exact_val(vec_dim);
429 fabs(exact_val(j) - interp_vals[i + j*pts_cnt]) :
430 fabs(exact_val(j) - interp_vals[i*vec_dim + j]);
431 max_err = std::max(max_err, error);
432 max_dist = std::max(max_dist, dist_p_out(i));
433 if (code_out[i] == 1 && j == 0) { face_pts++; }
435 else {
if (j == 0) { not_found++; } }
439 cout << setprecision(16)
440 <<
"Searched points: " << pts_cnt
441 <<
"\nFound points: " << found
442 <<
"\nMax interp error: " << max_err
443 <<
"\nMax dist^2 (of found): " << max_dist
444 <<
"\nPoints not found: " << not_found;
445 if (randomization == 1)
447 cout <<
"\nPoints on faces: " << face_pts <<
" out of "
448 << npt_total_face << endl;
452 cout <<
"\nPoints on faces: " << face_pts << endl;
456 if (surface) {
delete mesh; }
int Size() const
Return the logical size of the array.
int Append(const T &el)
Append element 'el' to array, resize if necessary.
FindPointsGSLIB can robustly evaluate a GridFunction on an arbitrary collection of points....
virtual const Vector & GetDist() const
Return distance between the sought and the found point in physical space.
void Setup(Mesh &m, const double bbox_rel_size_inc=0.1, const double newt_tol=1.0e-12, const int npt_max=256)
Preprocess the internal mesh in gslib.
virtual void Interpolate(const GridFunction &field_in, Vector &field_out)
Interpolation of field values at prescribed reference space positions.
virtual const Array< unsigned int > & GetCode() const
Return code for each point searched by FindPoints: inside element (0), element boundary (1),...
void SetupSurfWithAABBExpansion(Mesh &m, const Vector &aabb_sz_inc, const double newt_tol=1.0e-12)
Preprocess the surface mesh to compute data for FindPoints using absolute AABB expansion.
virtual void SetL2AvgType(AvgType avgtype_)
Average type to be used for L2 functions in-case a point is located at an element boundary where the ...
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...
int GetElementOrder(int i) const
Returns the order of the i'th finite element.
Mesh * GetMesh() const
Returns the mesh.
virtual void PRefineAndUpdate(const Array< pRefinement > &refs, bool want_transfer=true)
static void GetRandomPoint(int GeomType, IntegrationPoint &ip)
Get a random point in the reference element specified by GeomType.
Class for grid function - Vector with associated FE space.
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
std::unique_ptr< GridFunction > ProlongateToMaxOrder() const
Return a GridFunction with the values of this, prolongated to the maximum order of all elements in th...
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.
const char * Name() const override
Class for integration point with weight.
Arbitrary order "L2-conforming" discontinuous finite elements.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
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 GetElementTransformation(int i, IsoparametricTransformation *ElTr) const
Builds the transformation defining the i-th element in ElTr. ElTr must be allocated in advance and wi...
int SpaceDimension() const
Dimension of the physical space containing the mesh.
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.
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
static SubMesh CreateFromBoundary(const Mesh &parent, const Array< int > &boundary_attributes)
Create a surface SubMesh from its parent.
A general vector function coefficient.
void Randomize(int seed=0)
Set random values in the vector.
int Size() const
Returns the size of the vector.
void SetSize(int s)
Resize the vector to size s.
double field_func(const Vector &x)
void F_exact(const Vector &p, Vector &F)
void VisualizeFESpacePolynomialOrder(FiniteElementSpace &fespace, const char *title, int locx)
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)
real_t p(const Vector &x, real_t t)