41 char *title,
int pos_x,
int pos_y);
43int main (
int argc,
char *argv[])
50 const char *mesh_file =
"../gslib/triple-pt-1.mesh";
51 const char *sltn_file =
"../gslib/triple-pt-1.gf";
53 bool visualization =
true;
56 bool continuous =
true;
63 args.
AddOption(&mesh_file,
"-m",
"--mesh",
65 args.
AddOption(&sltn_file,
"-s",
"--sltn",
66 "Solution file to use.");
67 args.
AddOption(&ref,
"-ref",
"--piecewise-linear-ref-factor",
68 "Scaling factor for resolution of piecewise linear bounds."
69 " If less than 2, the resolution is picked automatically");
70 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
72 "Enable or disable GLVis visualization.");
73 args.
AddOption(&visit,
"-visit",
"--visit",
"-no-visit",
75 "Enable or disable VisIt output.");
76 args.
AddOption(&b_type,
"-bt",
"--basis-type",
77 "Project input function to a different bases. "
78 "-1 = don't project (default)."
79 "0 = Gauss-Legendre nodes. "
80 "1 = Gauss-Lobatto nodes. "
81 "2 = uniformly spaced nodes. ");
82 args.
AddOption(&continuous,
"-h1",
"--h1",
"-l2",
"--l2",
83 "Use continuous or discontinuous space.");
84 args.
AddOption(&nbrute,
"-nb",
"--nbrute",
85 "Brute force search for minimum in an array of nxnxn points "
87 args.
AddOption(&rec_depth,
"-rd",
"--rec-depth",
88 "Maximum depth for recursive subdivision to compute function "
90 args.
AddOption(&rel_tol,
"-rt",
"--rel-tol",
91 "Relative tolerance for termination of recursive "
95 Mesh mesh(mesh_file, 1, 1,
false);
97 if (continuous && b_type != -1)
99 MFEM_VERIFY(b_type > 0,
"Continuous space do not support GL nodes. "
100 "Please use basis type: 1 for Lagrange interpolants on GLL "
101 " nodes 2 for positive bases on uniformly spaced nodes.");
104 std::unique_ptr<int[]> partition(
108 ifstream mat_stream_1(sltn_file);
109 std::unique_ptr<GridFunction> func(
new GridFunction(&mesh, mat_stream_1));
111 ParMesh pmesh(MPI_COMM_WORLD, mesh, partition.get());
113 int func_order = func->FESpace()->GetMaxElementOrder();
115 int nel = pmesh.
GetNE();
144 cout <<
"fec name: " << fec->
Name() << endl;
164 Vector bound_rec_min(vdim), bound_rec_max(vdim);
165 for (
int d = 0; d < vdim; d++)
171 bound_rec_min(d) = min_interval.first;
172 bound_rec_max(d) = max_interval.second;
175 Vector bound_min(vdim), bound_max(vdim);
176 for (
int d = 0; d < vdim; d++)
178 Vector lowerT(lowerb.GetData() + d*nel, nel);
180 bound_min(d) = lowerT.
Min();
181 bound_max(d) = upperT.
Max();
184 MPI_Allreduce(MPI_IN_PLACE, bound_min.GetData(), vdim,
186 MPI_Allreduce(MPI_IN_PLACE, bound_max.
GetData(), vdim,
192 char title1[] =
"Input gridfunction";
196 char title1p[] =
"Projected gridfunction";
199 char title2[] =
"Element-wise lower bound";
201 char title3[] =
"Element-wise upper bound";
222 Vector global_min(vdim), global_max(vdim);
223 global_min = numeric_limits<real_t>::max();
224 global_max = numeric_limits<real_t>::min();
227 for (
int e = 0; e < pmesh.
GetNE(); e++)
230 for (
int k = 0; k < (
dim > 2 ? nbrute : 1); k++)
232 ip.
z = k/(nbrute-1.0);
233 for (
int j = 0; j < (
dim > 1 ? nbrute : 1); j++)
235 ip.
y = j/(nbrute-1.0);
236 for (
int i = 0; i < nbrute; i++)
238 ip.
x = i/(nbrute-1.0);
239 for (
int d = 0; d < vdim; d++)
242 global_min(d) = min(global_min(d), val);
243 global_max(d) = max(global_max(d), val);
250 MPI_Allreduce(MPI_IN_PLACE, global_min.GetData(), vdim,
252 MPI_Allreduce(MPI_IN_PLACE, global_max.
GetData(), vdim,
256 for (
int d = 0; d < vdim; d++)
258 cout <<
"Compare function extremum for component " <<
260 constexpr int w = 20;
261 cout << left << setw(w) <<
" "
262 << setw(w) <<
"Brute force"
263 << setw(w) <<
"PL Bound"
264 << setw(w) <<
"PL Bound + recursion" << endl
265 << left << setw(w) <<
"Minimum: "
266 << setw(w) << global_min(d)
267 << setw(w) << bound_min(d)
268 << setw(w) << bound_rec_min(d) << endl
269 << left << setw(w) <<
"Difference: "
271 << setw(w) << global_min(d)-bound_min(d)
272 << setw(w) << global_min(d)-bound_rec_min(d) << endl;
274 << left << setw(w) <<
"Maximum: "
275 << setw(w) << global_max(d)
276 << setw(w) << bound_max(d)
277 << setw(w) << bound_rec_max(d) << endl
278 << left << setw(w) <<
"Difference: "
280 << setw(w) << bound_max(d)-global_max(d)
281 << setw(w) << bound_rec_max(d)-global_max(d) << endl;
289 for (
int d = 0; d < vdim; d++)
291 cout <<
"Compare function extremum for component " <<
293 constexpr int w = 20;
294 cout << left << setw(w) <<
" "
295 << setw(w) <<
"PL Bound"
296 << setw(w) <<
"PL Bound + recursion" << endl
297 << left << setw(w) <<
"Minimum: "
298 << setw(w) << bound_min(d)
299 << setw(w) << bound_rec_min(d) << endl;
301 << left << setw(w) <<
"Maximum: "
302 << setw(w) << bound_max(d)
303 << setw(w) << bound_rec_max(d) << endl;
315 char *title,
int pos_x,
int pos_y)
320 sock.
open(
"localhost", 19916);
321 sock <<
"solution\n";
327 sock <<
"window_title '"<< title <<
"'\n"
328 <<
"window_geometry "
329 << pos_x <<
" " << pos_y <<
" " << 400 <<
" " << 400 <<
"\n"
330 <<
"keys jRmclApppppppppppp//]]]]]]]]" << endl;
virtual void SetFormat(int fmt)
Set the desired output mesh and data format.
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
virtual const char * Name() const
Ordering::Type GetOrdering() const
Return the ordering method.
const FiniteElementCollection * FEColl() const
int GetVDim() const
Returns the vector dimension of the finite element space.
Class for grid function - Vector with associated FE space.
PLBound GetElementBounds(Vector &lower, Vector &upper, const int ref_factor=1, const int vdim=-1) const
void MakeOwner(FiniteElementCollection *fec_)
Make the GridFunction the owner of fec_owned and fes.
FiniteElementSpace * FESpace()
void ProjectGridFunction(const GridFunction &src)
Project the src GridFunction to this GridFunction, both of which must be on the same mesh.
Arbitrary order H1-conforming (continuous) finite elements.
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.
void Clear()
Clear the contents of the Mesh.
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
int * GeneratePartitioning(int nparts, int part_method=1)
static bool Root()
Return true if the rank in MPI_COMM_WORLD is zero.
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).
void ParseCheck(std::ostream &out=mfem::out)
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...
Abstract parallel finite element space.
Class for parallel grid function.
real_t GetValue(int i, const IntegrationPoint &ip, int vdim=1) const override
std::pair< real_t, real_t > EstimateFunctionMaximum(const int vdim, const PLBound &plb, const int max_depth, const real_t tol) const override
Estimate the GridFunction maximum across all elements.
std::pair< real_t, real_t > EstimateFunctionMinimum(const int vdim, const PLBound &plb, const int max_depth, const real_t tol) const override
Estimate the GridFunction minimum across all elements.
void SaveAsOne(const char *fname, int precision=16) const
Class for parallel meshes.
void PrintAsOne(std::ostream &out=mfem::out, const std::string &comments="") const
Write the mesh to the stream 'out' on Process 0 in a form suitable for visualization.
real_t Max() const
Returns the maximal element of the vector.
real_t * GetData() const
Return a pointer to the beginning of the Vector data.
real_t Min() const
Returns the minimal element of the vector.
Data collection with VisIt I/O routines.
void Save() override
Save the collection and a VisIt root file.
void RegisterField(const std::string &field_name, GridFunction *gf) override
Add a grid function to the collection and update the root file.
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
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)
Helper struct to convert a C++ type to an MPI type.