68 for (
int d = 0; d <
dim; d++) { res += std::pow(x(d),
func_order); }
75 for (
int i = 1; i < F.
Size(); i++) { F(i) = (i+1)*F(0); }
78int main (
int argc,
char *argv[])
87 const char *mesh_file =
"../../data/rt-2d-q3.mesh";
89 int mesh_poly_deg = 3;
92 bool visualization =
false;
95 bool search_on_rank_0 =
false;
96 bool hrefinement =
false;
97 int point_ordering = 0;
99 const char *devopt =
"cpu";
100 int randomization = 0;
106 args.
AddOption(&mesh_file,
"-m",
"--mesh",
107 "Mesh file to use.");
109 "Finite element order (polynomial degree).");
110 args.
AddOption(&mesh_poly_deg,
"-mo",
"--mesh-order",
111 "Polynomial degree of mesh finite element space.");
112 args.
AddOption(&rs_levels,
"-rs",
"--refine-serial",
113 "Number of times to refine the mesh uniformly in serial.");
114 args.
AddOption(&rp_levels,
"-rp",
"--refine-parallel",
115 "Number of times to refine the mesh uniformly in parallel.");
116 args.
AddOption(&fieldtype,
"-ft",
"--field-type",
117 "Field type: 0 - H1, 1 - L2, 2 - H(div), 3 - H(curl).");
119 "Number of components for H1 or L2 GridFunctions");
120 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
121 "--no-visualization",
122 "Enable or disable GLVis visualization.");
123 args.
AddOption(&search_on_rank_0,
"-sr0",
"--search-on-r0",
"-no-sr0",
125 "Enable search only on rank 0 (disable to search points on all tasks).");
126 args.
AddOption(&hrefinement,
"-hr",
"--h-refinement",
"-no-hr",
128 "Do random h refinements to mesh (does not work for pyramids).");
129 args.
AddOption(&point_ordering,
"-po",
"--point-ordering",
130 "Ordering of points to be found."
131 "0 (default): byNodes, 1: byVDIM");
132 args.
AddOption(&gf_ordering,
"-gfo",
"--gridfunc-ordering",
133 "Ordering of fespace that will be used for grid function to be interpolated."
134 "0 (default): byNodes, 1: byVDIM");
135 args.
AddOption(&devopt,
"-d",
"--device",
136 "Device configuration string, see Device::Configure().");
137 args.
AddOption(&randomization,
"-random",
"--random",
138 "0: generate points randomly in the bounding box of domain,"
139 "1: generate points randomly inside each element in mesh.");
141 "# points per proc or element");
142 args.
AddOption(&visport,
"-p",
"--send-port",
"Socket for GLVis.");
152 bool cpu_mode = strcmp(devopt,
"cpu")==0;
154 if (myid == 0) { device.
Print();}
159 Mesh *mesh =
new Mesh(mesh_file, 1, 1,
false);
175 cout <<
"Mesh curvature of the original mesh: ";
177 else { cout <<
"(NONE)"; }
183 MFEM_VERIFY(mesh_poly_deg > 0,
"The order of the mesh must be positive.");
187 cout <<
"--- Generating equidistant point for:\n"
188 <<
"x in [" << pos_min(0) <<
", " << pos_max(0) <<
"]\n"
189 <<
"y in [" << pos_min(1) <<
", " << pos_max(1) <<
"]" << std::endl;
192 cout <<
"z in [" << pos_min(2) <<
", " << pos_max(2) <<
"]" << std::endl;
198 ParMesh pmesh(MPI_COMM_WORLD, *mesh);
199 if (randomization == 0) {
delete mesh; }
218 cout <<
"Mesh curvature of the curved mesh: " << fecm.
Name() << endl;
223 MFEM_VERIFY(ncomp > 0,
"Invalid number of components.");
229 if (myid == 0) { cout <<
"H1-GridFunction" << std::endl; }
231 else if (fieldtype == 1)
234 if (myid == 0) { cout <<
"L2-GridFunction" << std::endl; }
236 else if (fieldtype == 2)
241 if (myid == 0) { cout <<
"H(div)-GridFunction" << std::endl; }
243 else if (fieldtype == 3)
248 if (myid == 0) { cout <<
"H(curl)-GridFunction" << std::endl; }
252 if (myid == 0) { MFEM_ABORT(
"Invalid FECollection type."); }
271 cout <<
"Unable to connect to GLVis server at "
272 <<
vishost <<
':' << visport << endl;
277 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
279 sout <<
"solution\n" << pmesh << field_vals;
280 if (
dim == 2) { sout <<
"keys RmjA*****\n"; }
281 if (
dim == 3) { sout <<
"keys mA\n"; }
292 int npt_face_per_elem = 4;
293 if (randomization == 0)
299 for (
int i = 0; i < pts_cnt; i++)
301 for (
int d = 0; d <
dim; d++)
305 vxyz(i + d*pts_cnt) =
306 pos_min(d) + vxyz(i + d*pts_cnt) * (pos_max(d) - pos_min(d));
311 pos_min(d) + vxyz(i*
dim + d) * (pos_max(d) - pos_min(d));
318 pts_cnt = npt*nelemglob;
320 for (
int i=0; i<mesh->
GetNE(); i++)
327 for (
int j=0; j<npt; j++)
330 ip.
x = pos_ref1(j*
dim + 0);
331 ip.
y = pos_ref1(j*
dim + 1);
334 ip.
z = pos_ref1(j*
dim + 2);
336 if (j < npt_face_per_elem)
342 for (
int d=0; d<
dim; d++)
346 vxyz(j + npt*i + d*npt*nelemglob) = pos_i(d);
350 vxyz((j + npt*i)*
dim + d) = pos_i(d);
357 if ( (myid != 0) && (search_on_rank_0) )
364 Vector interp_vals(pts_cnt*vec_dim);
392 int face_pts = 0, not_found = 0, found_loc = 0, found_away = 0;
393 double error = 0.0, max_error = 0.0, max_dist = 0.0;
396 for (
int j = 0; j < vec_dim; j++)
398 for (
int i = 0; i < pts_cnt; i++)
402 (task_id_out[i] == (unsigned)myid) ? found_loc++ : found_away++;
407 for (
int d = 0; d <
dim; d++)
410 vxyz(d*pts_cnt + i) :
413 Vector exact_val(vec_dim);
416 fabs(exact_val(j) - interp_vals[i + j*pts_cnt]) :
417 fabs(exact_val(j) - interp_vals[i*vec_dim + j]);
418 max_error = std::max(max_error, error);
419 max_dist = std::max(max_dist, dist_p_out(i));
420 if (code_out[i] == 1 && j == 0) { face_pts++; }
422 else {
if (j == 0) { not_found++; } }
426 MPI_Allreduce(MPI_IN_PLACE, &found_loc, 1, MPI_INT, MPI_SUM,
428 MPI_Allreduce(MPI_IN_PLACE, &found_away, 1, MPI_INT, MPI_SUM,
430 MPI_Allreduce(MPI_IN_PLACE, &face_pts, 1, MPI_INT, MPI_SUM, pfespace.
GetComm());
431 MPI_Allreduce(MPI_IN_PLACE, ¬_found, 1, MPI_INT, MPI_SUM,
433 MPI_Allreduce(MPI_IN_PLACE, &max_error, 1, MPI_DOUBLE, MPI_MAX,
435 MPI_Allreduce(MPI_IN_PLACE, &max_dist, 1, MPI_DOUBLE, MPI_MAX,
437 MPI_Allreduce(MPI_IN_PLACE, &error, 1, MPI_DOUBLE, MPI_SUM, pfespace.
GetComm());
442 cout << setprecision(16)
443 <<
"Total number of elements: " << nelemglob
444 <<
"\nTotal number of procs: " << num_procs
445 <<
"\nSearched total points: " << pts_cnt*num_procs
446 <<
"\nFound locally on ranks: " << found_loc
447 <<
"\nFound on other tasks: " << found_away
448 <<
"\nPoints not found: " << not_found
449 <<
"\nPoints on faces: " << face_pts
450 <<
"\nMax interp error: " << max_error
451 <<
"\nMax dist (of found): " << max_dist
459 if (randomization != 0) {
delete mesh; }
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
FindPointsGSLIB can robustly evaluate a GridFunction on an arbitrary collection of points.
virtual const Vector & GetDist() const
void FindPoints(const Vector &point_pos, int point_pos_ordering=Ordering::byNODES)
virtual const Vector & GetReferencePosition() const
Return reference coordinates for each point found by FindPoints.
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 const Array< unsigned int > & GetGSLIBElem() const
virtual const Vector & GetGSLIBReferencePosition() const
virtual const Array< unsigned int > & GetProc() const
Return MPI rank on which each point was found by FindPoints.
virtual void SetDistanceToleranceForPointsFoundOnBoundary(double bdr_tol_)
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...
ElementTransformation * GetElementTransformation(int i) const
Returns ElementTransformation for the i-th element.
Arbitrary order H1-conforming (continuous) finite elements.
const char * Name() const override
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
Class for integration point with weight.
Arbitrary order "L2-conforming" discontinuous finite elements.
Element::Type GetElementType(int i) const
Returns the type of element i.
const FiniteElementSpace * GetNodalFESpace() 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
long long GetGlobalNE() const
Return the total (global) number of elements.
void EnsureNCMesh(bool simplices_nonconforming=false)
int GetNumGeometries(int dim) const
Return the number of geometries of the given dimension present in the mesh.
virtual void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
Set the curvature of the mesh nodes using the given polynomial degree.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
static int WorldRank()
Return the MPI rank in MPI_COMM_WORLD.
static int WorldSize()
Return the size of MPI_COMM_WORLD.
static void Init(int &argc, char **&argv, int required=default_thread_required, int *provided=nullptr)
Singleton creation with Mpi::Init(argc, argv).
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.
Abstract parallel finite element space.
Class for parallel grid function.
void ProjectCoefficient(Coefficient &coeff) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Class for parallel meshes.
void SetNodalFESpace(FiniteElementSpace *nfes) override
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
A general vector function coefficient.
void Randomize(int seed=0)
Set random values in the vector.
void Destroy()
Destroy a vector.
int Size() const
Returns the size of the vector.
virtual void UseDevice(bool use_dev) const
Enable execution of Vector operations using the mfem::Device.
void SetSize(int s)
Resize the vector to size s.
virtual real_t * HostReadWrite()
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
real_t p(const Vector &x, real_t t)
double field_func(const Vector &x)
void F_exact(const Vector &p, Vector &F)