19int main(
int argc, 
char *argv[]) {
 
   27    char mesh_out_file[255] = 
"out.h5m";
 
   30    PetscBool shift = PETSC_TRUE;
 
   31    PetscBool flg_file = PETSC_FALSE;
 
   32    PetscBool 
debug = PETSC_FALSE;
 
   34    PetscOptionsBegin(PETSC_COMM_WORLD, 
"", 
"none", 
"none");
 
   36    CHKERR PetscOptionsString(
"-my_file", 
"mesh file name", 
"", 
"mesh.h5m",
 
   38    if (flg_file != PETSC_TRUE)
 
   39      CHKERR PetscOptionsString(
"-file_name", 
"mesh file name", 
"", 
"mesh.h5m",
 
   41    CHKERR PetscOptionsString(
"-output_file", 
"output mesh file name", 
"",
 
   42                              "mesh.h5m", mesh_out_file, 255, PETSC_NULLPTR);
 
   43    CHKERR PetscOptionsInt(
"-dim", 
"entities dim", 
"", dim, &dim, PETSC_NULLPTR);
 
   44    CHKERR PetscOptionsInt(
"-nb_levels", 
"number of refinement levels", 
"",
 
   46    CHKERR PetscOptionsBool(
"-shift",
 
   47                            "shift bits, squash entities of refined elements",
 
   48                            "", shift, &shift, PETSC_NULLPTR);
 
   49    CHKERR PetscOptionsBool(
"-debug",
 
   50                            "write additional files with bit ref levels", 
"",
 
   55    moab::Core mb_instance;
 
   56    moab::Interface &moab = mb_instance;
 
   57    ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, 
MYPCOMM_INDEX);
 
   59      pcomm = 
new ParallelComm(&moab, PETSC_COMM_WORLD);
 
   69    if (flg_file != PETSC_TRUE) {
 
   71              "*** ERROR -my_file (-file_name) (mesh file needed)");
 
   87      CHKERR moab.get_adjacencies(ents, 1, 
true, edges, moab::Interface::UNION);
 
   90      CHKERR moab.create_meshset(MESHSET_SET, meshset_ref_edges);
 
   91      CHKERR moab.add_entities(meshset_ref_edges, edges);
 
   99      } 
else if (dim == 2) {
 
  103                "Refinement implemented only for three and two dimensions");
 
  106      auto update_meshsets = [&]() {
 
  112              cubit_meshset, 
bit(
l + 1), cubit_meshset, MBMAXTYPE, 
true);
 
  117      auto update_partition_sets = [&]() {
 
  120        ParallelComm *pcomm = ParallelComm::get_pcomm(
 
  122        Tag part_tag = pcomm->part_tag();
 
  126            0, MBENTITYSET, &part_tag, NULL, 1, r_tagged_sets,
 
  127            moab::Interface::UNION);
 
  129        std::vector<EntityHandle> tagged_sets(r_tagged_sets.size());
 
  130        std::copy(r_tagged_sets.begin(), r_tagged_sets.end(),
 
  131                  tagged_sets.begin());
 
  133        auto order_tagged_sets = [&]() {
 
  135          std::vector<int> parts(tagged_sets.size());
 
  137              part_tag, &*tagged_sets.begin(), tagged_sets.size(),
 
  139          map<int, EntityHandle> m_tagged_sets;
 
  140          for (
int p = 0; p != tagged_sets.size(); ++p) {
 
  141            m_tagged_sets[parts[p]] = tagged_sets[p];
 
  143          for (
int p = 0; p != tagged_sets.size(); ++p) {
 
  144            tagged_sets[p] = m_tagged_sets.at(p);
 
  149        auto add_children = [&]() {
 
  151          std::vector<Range> part_ents(tagged_sets.size());
 
  153          for (
int p = 0; p != tagged_sets.size(); ++p) {
 
  155            CHKERR moab.get_entities_by_dimension(tagged_sets[p], dim, ents,
 
  162            children = children.subset_by_dimension(dim);
 
  167            for (
auto d = 1; d != dim; ++d) {
 
  168              CHKERR moab.get_adjacencies(children.subset_by_dimension(dim), d,
 
  169                                          false, adj, moab::Interface::UNION);
 
  172            part_ents[p].merge(children);
 
  173            part_ents[p].merge(adj);
 
  176          for (
int p = 1; p != tagged_sets.size(); ++p) {
 
  177            for (
int pp = 0; pp != p; pp++) {
 
  178              part_ents[p] = subtract(part_ents[p], part_ents[pp]);
 
  182          for (
int p = 0; p != tagged_sets.size(); ++p) {
 
  183            CHKERR moab.add_entities(tagged_sets[p], part_ents[p]);
 
  184            CHKERR moab.tag_clear_data(part_tag, part_ents[p], &p);
 
  194                                                   meshset_ptr->get_ptr(), 1);
 
  198            for (
int p = 0; p != tagged_sets.size(); ++p) {
 
  200                  << 
"Write part " << p << 
" level " << 
l;
 
  207                                    "_" + boost::lexical_cast<std::string>(
l) +
 
  216        CHKERR order_tagged_sets();
 
  222      CHKERR update_partition_sets();
 
  225      CHKERR moab.delete_entities(&meshset_ref_edges, 1);
 
  230        MOFEM_LOG(
"WORLD", Sev::inform) << 
"Write level " << 
l;
 
  233            (
"level" + boost::lexical_cast<std::string>(
l) + 
".vtk").c_str(),
 
  238    if (shift == PETSC_TRUE) {
 
  239      MOFEM_LOG(
"WORLD", Sev::inform) << 
"Shift bits";
 
  244    CHKERR moab.write_file(mesh_out_file);
 
 
MoFEMErrorCode updateMeshsetByEntitiesChildren(const EntityHandle parent, const BitRefLevel &parent_bit, const BitRefLevel &parent_mask, const BitRefLevel &child_bit, const BitRefLevel &child_mask, const EntityHandle child, EntityType child_type, const bool recursive=false, int verb=0)
Get child entities form meshset containing parent entities.