21 {
22
24
25 try {
26
27 moab::Core mb_instance;
28 moab::Interface &moab = mb_instance;
29 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
30 if (pcomm == NULL)
31 pcomm = new ParallelComm(&moab, PETSC_COMM_WORLD);
32
36
37
38 char mesh_file_name[PETSC_MAX_PATH_LEN] = "";
39 char mesh_out_file[PETSC_MAX_PATH_LEN] = "out.h5m";
40 PetscBool flg_file = PETSC_FALSE;
41 PetscBool flg_n_part = PETSC_FALSE;
42 PetscBool flg_part = PETSC_FALSE;
43 PetscBool only_tags = PETSC_FALSE;
44 PetscInt n_partas = 1;
45 PetscBool create_lower_dim_ents = PETSC_TRUE;
46 PetscInt dim = 3;
47 PetscInt adj_dim = 0;
48
49 PetscOptionsBegin(PETSC_COMM_WORLD, "", "none", "none");
50
51 CHKERR PetscOptionsString(
"-my_file",
"mesh file name",
"",
"mesh.h5m",
52 mesh_file_name, sizeof(mesh_file_name), &flg_file);
53 if (flg_file != PETSC_TRUE)
54 CHKERR PetscOptionsString(
"-file_name",
"mesh file name",
"",
"mesh.h5m",
55 mesh_file_name, sizeof(mesh_file_name),
56 &flg_file);
57 if (flg_file != PETSC_TRUE)
58 SETERRQ(PETSC_COMM_SELF, 1,
59 "*** ERROR -my_file (-file_name) (mesh file needed)");
60
61 const char *option;
62 option = "";
63 CHKERR moab.load_file(mesh_file_name, 0, option);
64 CHKERR meshsets_interface_ptr->initialiseDatabaseFromMesh();
65
66 CHKERR PetscOptionsString(
"-output_file",
"output mesh file name",
"",
67 "out.h5m", mesh_out_file, sizeof(mesh_out_file),
68 PETSC_NULLPTR);
69 CHKERR PetscOptionsInt(
"-my_nparts",
"number of parts",
"", n_partas,
70 &n_partas, &flg_n_part);
71 CHKERR PetscOptionsInt(
"-nparts",
"number of parts",
"", n_partas,
72 &n_partas, &flg_part);
73
74 if (!flg_n_part && !flg_part)
75 SETERRQ(PETSC_COMM_SELF, 1,
76 "*** ERROR partitioning number not given (-nparts)");
77
78 auto get_nb_ents_by_dim = [&](const int dim) {
80 CHKERR moab.get_number_entities_by_dimension(0, dim,
nb);
82 };
83 for (; dim >= 0; dim--) {
84 if (get_nb_ents_by_dim(dim))
85 break;
86 }
87
88 if (!dim)
90 "Dimension of entities to partition not found");
91
92 CHKERR PetscOptionsInt(
"-dim",
"entities dim",
"", dim, &dim, PETSC_NULLPTR);
93
94 CHKERR PetscOptionsInt(
"-adj_dim",
"adjacency dim",
"", adj_dim, &adj_dim,
95 PETSC_NULLPTR);
97 "-my_create_lower_dim_ents", "if true create lower dimension entireties",
98 "", create_lower_dim_ents, &create_lower_dim_ents, PETSC_NULLPTR);
99 CHKERR PetscOptionsBool(
"-block_tags",
"only block and meshsests tags",
"",
100 only_tags, &only_tags, PETSC_NULLPTR);
101
102 PetscOptionsEnd();
103
105 for (
int d : {3, 2, 1})
106 if (ents.num_of_dimension(
d))
108 return 0;
109 };
110
111 CHKERR meshsets_interface_ptr->setMeshsetFromFile();
112
115 int min_dim = 3;
116 for (auto cit = meshsets_interface_ptr->getBegin();
117 cit != meshsets_interface_ptr->getEnd(); cit++) {
119 CHKERR m_field.
get_moab().get_entities_by_handle(cit->getMeshset(), ents,
120 true);
121 min_dim = std::min(min_dim,
get_dim(ents));
123 }
124
125 int g_dim;
126 MPI_Allreduce(&min_dim, &g_dim, 1, MPI_INT, MPI_MIN, m_field.
get_comm());
127 if (g_dim < adj_dim) {
129 << "The minimum meshsets dimension is = " << min_dim;
130 }
131 if (adj_dim >= dim) {
133 << "The -adj_dim >= dim, adj_dim = " << adj_dim << " dim = " << dim;
134 }
136
137 {
139 CHKERR moab.get_entities_by_dimension(0, dim, ents_dim,
false);
140 if (create_lower_dim_ents) {
141 if (dim == 3) {
143 CHKERR moab.get_adjacencies(ents_dim, 2,
true,
faces,
144 moab::Interface::UNION);
145 }
146 if (dim >= 2) {
147
149 CHKERR moab.get_adjacencies(ents_dim, 1,
true, edges,
150 moab::Interface::UNION);
151 }
152 }
155 ents_dim, dim, adj_dim, n_partas,
nullptr,
nullptr,
nullptr,
VERBOSE);
156 }
157
158 auto get_tag_list = [&]() {
159 std::vector<Tag> tags_list;
162 for (
auto &
m : list) {
163 auto meshset =
m.getMeshset();
164 std::vector<Tag> tmp_tags_list;
166 tmp_tags_list);
167 for (
auto t : tmp_tags_list) {
168 tags_list.push_back(
t);
169 }
170 }
171
172 return tags_list;
173 };
174
175 EntityHandle root_mesh = 0;
177 if (only_tags) {
178 auto tags_list = get_tag_list();
179 std::sort(tags_list.begin(), tags_list.end());
180 auto new_end = std::unique(tags_list.begin(), tags_list.end());
181 tags_list.resize(std::distance(tags_list.begin(), new_end));
182 tags_list.push_back(pcomm->part_tag());
183
184 CHKERR moab.write_file(mesh_out_file,
"MOAB",
"", &root_mesh, 1,
185 &*tags_list.begin(), tags_list.size());
186 } else {
187 CHKERR moab.write_file(mesh_out_file,
"MOAB",
"");
188 }
189 MOFEM_LOG(
"WORLD", Sev::inform) <<
"Wrote file " << mesh_out_file;
190 }
191 }
193
196
197 return 0;
198}
std::vector< std::array< EntityHandle, 3 > > faces
Sorted keys.
Vec t
Removal: the ring edge.
#define CATCH_ERRORS
Catch errors.
#define MYPCOMM_INDEX
default communicator number PCOMM
@ MOFEM_DATA_INCONSISTENCY
#define CHKERR
Inline error check.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
MoFEMErrorCode partitionMesh(const Range &ents, const int dim, const int adj_dim, const int n_parts, Tag *th_vertex_weights=nullptr, Tag *th_edge_weights=nullptr, Tag *th_part_weights=nullptr, int verb=VERBOSE, const bool debug=false, const bool preserve_vertex_ids=false)
Set partition tag to each finite element in the problem.
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
FTensor::Index< 'm', 3 > m
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
Interface for managing meshsets containing materials and boundary conditions.
CubitMeshSet_multiIndex & getMeshsetsMultindex()
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.