14static char help[] =
"...\n\n";
19MoFEMErrorCode writeElementIdFixture(
const char *file,
bool numbered) {
21 const med_idt fid = MEDfileOpen(file, MED_ACC_CREAT);
24 "Could not create MED element-ID fixture");
25 const char *
name =
"element_ids";
26 std::string axes(3 * MED_SNAME_SIZE,
' '), units(3 * MED_SNAME_SIZE,
' ');
27 for (
int d = 0;
d != 3; ++
d)
28 axes[
d * MED_SNAME_SIZE] =
"xyz"[
d];
29 CHKERR MEDmeshCr(fid,
name, 3, 3, MED_UNSTRUCTURED_MESH,
"Element ID test",
30 "", MED_SORT_DTIT, MED_CARTESIAN, axes.c_str(),
32 CHKERR MEDfamilyCr(fid,
name,
"FAMILY_0", 0, 0,
"");
33 const med_float
coordinates[] = {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
34 2, 0, 0, 3, 0, 0, 2, 1, 0, 2, 0, 1};
35 const med_int families[8] = {};
36 CHKERR MEDmeshNodeWr(fid,
name, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
37 MED_FULL_INTERLACE, 8,
coordinates, MED_FALSE,
nullptr,
38 MED_FALSE,
nullptr, MED_TRUE, families);
39 const med_int tets[] = {1, 2, 3, 4, 5, 6, 7, 8};
40 const med_int
triangles[] = {1, 2, 3, 5, 6, 7};
41 const med_int numbers[] = {41, 7};
42 for (
const auto type : {MED_TRIA3, MED_TETRA4}) {
43 CHKERR MEDmeshElementWr(fid,
name, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
44 MED_CELL,
type, MED_NODAL, MED_FULL_INTERLACE, 2,
46 nullptr, numbered ? MED_TRUE : MED_FALSE,
47 numbered ? numbers :
nullptr, MED_TRUE, families);
55 const char *numbered =
"reading_med_numbered_elements.med";
56 const char *unnumbered =
"reading_med_unnumbered_elements.med";
57 CHKERR writeElementIdFixture(numbered,
true);
58 CHKERR writeElementIdFixture(unnumbered,
false);
63 auto read = [&](
const char *file,
const std::vector<int> &expected) {
66 CHKERR mb.get_entities_by_handle(0, before);
69 for (
int dim : {2, 3}) {
71 CHKERR mb.get_entities_by_dimension(0, dim, entities);
72 const auto added = subtract(entities, before);
73 std::vector<int> ids(added.size());
74 CHKERR mb.tag_get_data(
mb.globalId_tag(), added, ids.data());
76 "MED imported element numbers", ids == expected ? 1 : 0, 1, {0, 0});
77 ids.resize(entities.size());
78 CHKERR mb.tag_get_data(
mb.globalId_tag(), entities, ids.data());
79 const std::set<int> unique(ids.begin(), ids.end());
81 "MED element IDs unique per dimension", unique.size(), ids.size(),
86 CHKERR read(unnumbered, {1, 2});
88 CHKERR read(numbered, {41, 7});
89 CHKERR read(numbered, {82, 48});
90 CHKERR read(unnumbered, {83, 84});
91 std::filesystem::remove(numbered);
92 std::filesystem::remove(unnumbered);
98int main(
int argc,
char *argv[]) {
106 moab::Core mb_instance;
107 moab::Interface &moab = mb_instance;
120 for (std::map<std::string, MedInterface::FieldData>::iterator fit =
122 fit != med_interface_ptr->
fieldNames.end(); fit++) {
124 fit->first,
false, 1);
127 PetscBool check = PETSC_TRUE;
131 const int check_list[] = {2163, 624, 65, 104};
133 EntityHandle meshset = cit->getMeshset();
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,
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;
160 return std::make_pair(verts.size(), ids);
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;
170 "MED vertex GLOBAL_ID not positive", not_positive, 0, {0, 0});
172 "MED vertex GLOBAL_ID distinct", distinct.size(), nb_verts, {0, 0});
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;
187 auto written = boost::make_shared<Range>();
190 CHKERR moab.get_entities_by_handle(meshset, ents,
true);
191 written->merge(ents);
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);
203 const auto [nb_read, ids_read] = vertex_ids(mb_read);
205 for (
const auto &[x,
id] : ids_read) {
206 const auto it = ids.find(x);
207 kept +=
it != ids.end() &&
it->second == id;
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});
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,
std::vector< std::array< double, 3 > > coordinates
#define CATCH_ERRORS
Catch errors.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#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_OPERATION_UNSUCCESSFUL
@ MOFEM_ATOM_TEST_INVALID
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#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 MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
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::vector< EntityHandle > meshMeshsets
meshset for each mesh
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.