{
int N = 10, dim = 3;
#ifdef USE_MPI
MPI_Init(&argc, &argv);
#endif
ProgOptions opts;
opts.addOpt<int>(std::string("dim,d"), std::string("Dimension of mesh (default=3)"),
&dim);
opts.addOpt<int>(std::string(",n"), std::string("Number of elements on a side (default=10)"),
&N);
opts.parseCommandLine(argc, argv);
Interface *mb = new Core();
ScdInterface *scdiface;
ErrorCode rval = mb->query_interface(scdiface);
if (MB_SUCCESS != rval) return rval;
int ilow = 0, ihigh = N;
int rank = 0, nprocs = 1;
#ifdef USE_MPI
MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank);
ilow = rank*N; ihigh = ilow + N;
#endif
ScdBox *box;
rval = scdiface->construct_box(HomCoord(ilow, (dim>1?0:-1), (dim>2?0:-1)),
HomCoord(ihigh, (dim>1?N:-1), (dim>2?N:-1)),
NULL, 0,
box);
if (MB_SUCCESS != rval) return rval;
Range verts, elems;
rval = mb->get_entities_by_dimension(0, 0, verts);
if (MB_SUCCESS != rval) return rval;
rval = mb->get_entities_by_dimension(0, dim, elems);
if (MB_SUCCESS != rval) return rval;
#define MYSTREAM(a) if (!rank) std::cout << a << std::endl
if (pow(N,dim) == (int) elems.size() && pow(N+1,dim) == (int) verts.size()) {
#ifdef USE_MPI
MYSTREAM("Proc 0: ");
#endif
MYSTREAM("Created " << elems.size() << " " << CN::EntityTypeName(mb->type_from_handle(*elems.begin()))
<< " elements and " << verts.size() << " vertices." << std::endl);
}
else
std::cout << "Created the wrong number of vertices or hexes!" << std::endl;
std::vector<double> coords(3*pow(N+1,dim));
std::vector<EntityHandle> connect;
for (int k = 0; k < (dim>2?N:1); k++) {
for (int j = 0; j < (dim>1?N:1); j++) {
for (int i = 0; i < N-1; i++) {
EntityHandle ehandle = box->get_element(i, j, k);
if (0 == ehandle) return MB_FAILURE;
rval = mb->get_connectivity(&ehandle, 1, connect);
if (MB_SUCCESS != rval) return rval;
rval = mb->get_coords(connect.data(), connect.size(), coords.data());
if (MB_SUCCESS != rval) return rval;
}
}
}
mb->release_interface(scdiface);
delete mb;
#ifdef USE_MPI
MPI_Finalize();
#endif
return 0;
}