10 static char help[] =
"Uniform mesh refinement\n\n"
14 "$ ./uniform_mesh_refinement -my_file mesh.h5m "
15 "-output_file refined_mesh.h5m"
19 int 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 ierr = PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"none",
"none");
37 CHKERR PetscOptionsString(
"-my_file",
"mesh file name",
"",
"mesh.h5m",
39 if (flg_file != PETSC_TRUE)
40 CHKERR PetscOptionsString(
"-file_name",
"mesh file name",
"",
"mesh.h5m",
42 CHKERR PetscOptionsString(
"-output_file",
"output mesh file name",
"",
43 "mesh.h5m", mesh_out_file, 255, PETSC_NULL);
44 CHKERR PetscOptionsInt(
"-dim",
"entities dim",
"", dim, &dim, PETSC_NULL);
45 CHKERR PetscOptionsInt(
"-nb_levels",
"number of refinement levels",
"",
47 CHKERR PetscOptionsBool(
"-shift",
48 "shift bits, squash entities of refined elements",
49 "", shift, &shift, PETSC_NULL);
50 CHKERR PetscOptionsBool(
"-debug",
51 "write additional files with bit ref levels",
"",
54 ierr = PetscOptionsEnd();
59 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
61 pcomm =
new ParallelComm(&moab, PETSC_COMM_WORLD);
71 if (flg_file != PETSC_TRUE) {
73 "*** ERROR -my_file (-file_name) (mesh file needed)");
89 CHKERR moab.get_adjacencies(ents, 1,
true, edges, moab::Interface::UNION);
92 CHKERR moab.create_meshset(MESHSET_SET, meshset_ref_edges);
93 CHKERR moab.add_entities(meshset_ref_edges, edges);
101 }
else if (dim == 2) {
105 "Refinement implemented only for three and two dimensions");
108 auto update_meshsets = [&]() {
114 cubit_meshset,
bit(
l + 1), cubit_meshset, MBMAXTYPE,
true);
119 auto update_partition_sets = [&]() {
122 ParallelComm *pcomm = ParallelComm::get_pcomm(
124 Tag part_tag = pcomm->part_tag();
128 0, MBENTITYSET, &part_tag, NULL, 1, r_tagged_sets,
129 moab::Interface::UNION);
131 std::vector<EntityHandle> tagged_sets(r_tagged_sets.size());
132 std::copy(r_tagged_sets.begin(), r_tagged_sets.end(),
133 tagged_sets.begin());
135 auto order_tagged_sets = [&]() {
137 std::vector<int> parts(tagged_sets.size());
139 part_tag, &*tagged_sets.begin(), tagged_sets.size(),
141 map<int, EntityHandle> m_tagged_sets;
142 for (
int p = 0; p != tagged_sets.size(); ++p) {
143 m_tagged_sets[parts[p]] = tagged_sets[p];
145 for (
int p = 0; p != tagged_sets.size(); ++p) {
146 tagged_sets[p] = m_tagged_sets.at(p);
151 auto add_children = [&]() {
153 std::vector<Range> part_ents(tagged_sets.size());
155 for (
int p = 0; p != tagged_sets.size(); ++p) {
157 CHKERR moab.get_entities_by_dimension(tagged_sets[p], dim, ents,
164 children = children.subset_by_dimension(dim);
169 for (
auto d = 1;
d != dim; ++
d) {
170 CHKERR moab.get_adjacencies(children.subset_by_dimension(dim),
d,
171 false, adj, moab::Interface::UNION);
174 part_ents[p].merge(children);
175 part_ents[p].merge(adj);
178 for (
int p = 1; p != tagged_sets.size(); ++p) {
179 for (
int pp = 0; pp != p; pp++) {
180 part_ents[p] = subtract(part_ents[p], part_ents[pp]);
184 for (
int p = 0; p != tagged_sets.size(); ++p) {
185 CHKERR moab.add_entities(tagged_sets[p], part_ents[p]);
186 CHKERR moab.tag_clear_data(part_tag, part_ents[p], &p);
196 meshset_ptr->get_ptr(), 1);
200 for (
int p = 0; p != tagged_sets.size(); ++p) {
202 <<
"Write part " << p <<
" level " <<
l;
209 "_" + boost::lexical_cast<std::string>(
l) +
218 CHKERR order_tagged_sets();
224 CHKERR update_partition_sets();
227 CHKERR moab.delete_entities(&meshset_ref_edges, 1);
232 MOFEM_LOG(
"WORLD", Sev::inform) <<
"Write level " <<
l;
235 (
"level" + boost::lexical_cast<std::string>(
l) +
".vtk").c_str(),
240 if (shift == PETSC_TRUE) {
241 MOFEM_LOG(
"WORLD", Sev::inform) <<
"Shift bits";
246 CHKERR moab.write_file(mesh_out_file);