98 {
99
101
102 try {
103
105
106 moab::Core mb_instance;
107 moab::Interface &moab = mb_instance;
108
109
112
115
118
119
120 for (std::map<std::string, MedInterface::FieldData>::iterator fit =
122 fit != med_interface_ptr->
fieldNames.end(); fit++) {
124 fit->first, false, 1);
125 }
126
127 PetscBool check = PETSC_TRUE;
129
130 int ii = 0;
131 const int check_list[] = {2163, 624, 65, 104};
133 EntityHandle meshset = cit->getMeshset();
134 int nb_ents;
135 CHKERR moab.get_number_entities_by_handle(meshset, nb_ents,
true);
136 CHKERR PetscPrintf(PETSC_COMM_WORLD,
"Nb of ents in %s %d\n",
137 cit->getName().c_str(), nb_ents);
139 if (check && nb_ents != check_list[ii]) {
141 "Wrong numbers of entities in meshset %d != %d", nb_ents,
142 check_list[ii]);
143 }
144 ii++;
145 }
146
147
149 const auto vertex_ids = [](moab::Interface &
mb) {
152 std::map<std::array<double, 3>, int> ids;
153 for (
auto v : verts) {
154 std::array<double, 3> x;
155 int id;
158 ids.emplace(x, id);
159 }
160 return std::make_pair(verts.size(), ids);
161 };
162 const auto [nb_verts, read_ids] = vertex_ids(moab);
163 std::set<int> distinct;
164 int not_positive = 0;
165 for (const auto &[x, id] : read_ids) {
166 not_positive += id <= 0;
167 distinct.insert(id);
168 }
170 "MED vertex GLOBAL_ID not positive", not_positive, 0, {0, 0});
172 "MED vertex GLOBAL_ID distinct", distinct.size(), nb_verts, {0, 0});
173
174
175
176
177 {
179 CHKERR moab.get_entities_by_type(0, MBVERTEX, verts);
180 std::vector<int> renumbered(verts.size());
181 CHKERR moab.tag_get_data(moab.globalId_tag(), verts, renumbered.data());
182 for (auto &id : renumbered)
183 id = 2 * (static_cast<
int>(nb_verts) + 1 - id) + 7;
184 CHKERR moab.tag_set_data(moab.globalId_tag(), verts, renumbered.data());
185 const auto ids = vertex_ids(moab).second;
186
187 auto written = boost::make_shared<Range>();
188 for (auto meshset : med_interface_ptr->meshMeshsets) {
190 CHKERR moab.get_entities_by_handle(meshset, ents,
true);
191 written->merge(ents);
192 }
193 const std::string
file =
"reading_med_file_ids.med";
194 std::filesystem::remove(file);
195 boost::shared_ptr<std::vector<const CubitMeshSets *>> meshsets_ptr;
197 CHKERR med_interface_ptr->
writeMed(file, meshsets_ptr, written, 0);
198
199 moab::Core mb_read;
203 const auto [nb_read, ids_read] = vertex_ids(mb_read);
204 int kept = 0;
205 for (const auto &[x, id] : ids_read) {
206 const auto it = ids.find(x);
207 kept +=
it != ids.end() &&
it->second == id;
208 }
210 "MED vertex GLOBAL_ID kept after writing", kept, nb_read, {0, 0});
212 "MED vertices written and read", nb_read, nb_verts, {0, 0});
213 }
214
219 EntityHandle meshset = mit->getMeshset();
220 std::string
name = mit->getName();
221 PetscPrintf(m_field.
get_comm(),
"Write mesh %s\n",
name.c_str());
222 CHKERR moab.write_file((
"out_" + mit->getName() +
".vtk").c_str(), NULL,
223 NULL, &meshset, 1);
224 }
225 }
227
229
230 return 0;
231}
#define CATCH_ERRORS
Catch errors.
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ MOFEM_ATOM_TEST_INVALID
#define CHKERR
Inline error check.
#define _IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
const double v
phase velocity of light in medium (cm/ns)
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
virtual MPI_Comm & get_comm() 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 load MED files.
MoFEMErrorCode readMed(const string &file, int verb=1)
read MED file
MoFEMErrorCode writeMed(boost::shared_ptr< Range > range_ptr=nullptr, int verb=1)
write MED file
std::map< std::string, FieldData > fieldNames
std::string medFileName
MED file name.
MoFEMErrorCode getMeshsets(boost::shared_ptr< std::vector< const CubitMeshSets * > > &meshsets_ptr)
MoFEMErrorCode readFields(const std::string &file_name, const std::string &field_name, const bool load_series=false, const int only_step=-1, int verb=1)
MoFEMErrorCode medGetFieldNames(const string &file, int verb=1)
Get field names in MED file.
Interface for managing meshsets containing materials and boundary conditions.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.