67 for (
int d = 0; d <
dim; d++) { res += std::pow(x(d),
func_order); }
74 for (
int i = 1; i < F.
Size(); i++) { F(i) = (i+1)*F(0); }
77int main (
int argc,
char *argv[])
86 const char *mesh_file =
"../../data/rt-2d-q3.mesh";
88 int mesh_poly_deg = 3;
91 bool visualization =
false;
94 bool search_on_rank_0 =
false;
95 bool hrefinement =
false;
96 int point_ordering = 0;
98 const char *devopt =
"cpu";
99 int randomization = 0;
105 args.
AddOption(&mesh_file,
"-m",
"--mesh",
106 "Mesh file to use.");
108 "Finite element order (polynomial degree).");
109 args.
AddOption(&mesh_poly_deg,
"-mo",
"--mesh-order",
110 "Polynomial degree of mesh finite element space.");
111 args.
AddOption(&rs_levels,
"-rs",
"--refine-serial",
112 "Number of times to refine the mesh uniformly in serial.");
113 args.
AddOption(&rp_levels,
"-rp",
"--refine-parallel",
114 "Number of times to refine the mesh uniformly in parallel.");
115 args.
AddOption(&fieldtype,
"-ft",
"--field-type",
116 "Field type: 0 - H1, 1 - L2, 2 - H(div), 3 - H(curl).");
118 "Number of components for H1 or L2 GridFunctions");
119 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
120 "--no-visualization",
121 "Enable or disable GLVis visualization.");
122 args.
AddOption(&search_on_rank_0,
"-sr0",
"--search-on-r0",
"-no-sr0",
124 "Enable search only on rank 0 (disable to search points on all tasks). "
125 "All points added by other procs are ignored.");
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 / rank initialized on entire mesh (random = 0) or every element (random = 1).");
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);
172 cout <<
"Mesh curvature of the original mesh: ";
174 else { cout <<
"(NONE)"; }
180 MFEM_VERIFY(mesh_poly_deg > 0,
"The order of the mesh must be positive.");
184 cout <<
"--- Generating points for:\n"
185 <<
"x in [" << pos_min(0) <<
", " << pos_max(0) <<
"]\n"
186 <<
"y in [" << pos_min(1) <<
", " << pos_max(1) <<
"]" << std::endl;
189 cout <<
"z in [" << pos_min(2) <<
", " << pos_max(2) <<
"]" << std::endl;
195 ParMesh pmesh(MPI_COMM_WORLD, *mesh);
196 if (randomization == 0) {
delete mesh; }
215 cout <<
"Mesh curvature of the curved mesh: " << fecm.
Name() << endl;
220 MFEM_VERIFY(ncomp > 0,
"Invalid number of components.");
226 if (myid == 0) { cout <<
"H1-GridFunction" << std::endl; }
228 else if (fieldtype == 1)
231 if (myid == 0) { cout <<
"L2-GridFunction" << std::endl; }
233 else if (fieldtype == 2)
238 if (myid == 0) { cout <<
"H(div)-GridFunction" << std::endl; }
240 else if (fieldtype == 3)
245 if (myid == 0) { cout <<
"H(curl)-GridFunction" << std::endl; }
249 if (myid == 0) { MFEM_ABORT(
"Invalid FECollection type."); }
268 cout <<
"Unable to connect to GLVis server at "
269 <<
vishost <<
':' << visport << endl;
274 sout <<
"parallel " << num_procs <<
" " << myid <<
"\n";
276 sout <<
"solution\n" << pmesh << field_vals;
277 if (
dim == 2) { sout <<
"keys RmjA*****\n"; }
278 if (
dim == 3) { sout <<
"keys mA\n"; }
288 int npt_face_per_elem = 4;
289 if (randomization == 0)
295 for (
int i = 0; i < pts_cnt; i++)
297 for (
int d = 0; d <
dim; d++)
301 vxyz(i + d*pts_cnt) =
302 pos_min(d) + vxyz(i + d*pts_cnt) * (pos_max(d) - pos_min(d));
307 pos_min(d) + vxyz(i*
dim + d) * (pos_max(d) - pos_min(d));
314 pts_cnt = npt*nelemglob;
316 for (
int i=0; i<mesh->
GetNE(); i++)
323 for (
int j=0; j<npt; j++)
326 ip.
x = pos_ref1(j*
dim + 0);
327 ip.
y = pos_ref1(j*
dim + 1);
330 ip.
z = pos_ref1(j*
dim + 2);
332 if (j < npt_face_per_elem)
338 for (
int d=0; d<
dim; d++)
342 vxyz(j + npt*i + d*npt*nelemglob) = pos_i(d);
346 vxyz((j + npt*i)*
dim + d) = pos_i(d);
353 if ( (myid != 0) && (search_on_rank_0) )
360 Vector interp_vals(pts_cnt*vec_dim);
380 int face_pts = 0, not_found = 0, found_loc = 0, found_away = 0;
381 double error = 0.0, max_error = 0.0, max_dist = 0.0;
384 for (
int j = 0; j < vec_dim; j++)
386 for (
int i = 0; i < pts_cnt; i++)
390 (task_id_out[i] == (unsigned)myid) ? found_loc++ : found_away++;
395 for (
int d = 0; d <
dim; d++)
398 vxyz(d*pts_cnt + i) :
401 Vector exact_val(vec_dim);
404 fabs(exact_val(j) - interp_vals[i + j*pts_cnt]) :
405 fabs(exact_val(j) - interp_vals[i*vec_dim + j]);
406 max_error = std::max(max_error, error);
407 max_dist = std::max(max_dist, dist_p_out(i));
408 if (code_out[i] == 1 && j == 0) { face_pts++; }
410 else {
if (j == 0) { not_found++; } }
414 MPI_Allreduce(MPI_IN_PLACE, &found_loc, 1, MPI_INT, MPI_SUM,
416 MPI_Allreduce(MPI_IN_PLACE, &found_away, 1, MPI_INT, MPI_SUM,
418 MPI_Allreduce(MPI_IN_PLACE, &face_pts, 1, MPI_INT, MPI_SUM, pfespace.
GetComm());
419 MPI_Allreduce(MPI_IN_PLACE, ¬_found, 1, MPI_INT, MPI_SUM,
421 MPI_Allreduce(MPI_IN_PLACE, &max_error, 1, MPI_DOUBLE, MPI_MAX,
423 MPI_Allreduce(MPI_IN_PLACE, &max_dist, 1, MPI_DOUBLE, MPI_MAX,
425 MPI_Allreduce(MPI_IN_PLACE, &error, 1, MPI_DOUBLE, MPI_SUM, pfespace.
GetComm());
430 cout << setprecision(16)
431 <<
"Total number of elements: " << nelemglob
432 <<
"\nTotal number of procs: " << num_procs
433 <<
"\nSearched total points: " << (search_on_rank_0 ? pts_cnt :
435 <<
"\nFound locally on ranks: " << found_loc
436 <<
"\nFound on other tasks: " << found_away
437 <<
"\nPoints not found: " << not_found
438 <<
"\nPoints on faces: " << face_pts
439 <<
"\nMax interp error: " << max_error
440 <<
"\nMax dist (of found): " << max_dist
445 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 &os=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.
virtual void Interpolate(const GridFunction &field_in, Vector &field_out)
virtual const Array< unsigned int > & GetCode() 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
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)