21 CHKERR PetscPushErrorHandler(PetscReturnErrorHandler,
nullptr);
22 const auto error = operation();
23 CHKERR PetscPopErrorHandler();
25 "Invalid ancestry was not rejected");
30 std::initializer_list<EntityHandle>
vertices,
31 EntityHandle &entity) {
33 ReadUtilIface *reader;
39 CHKERR reader->update_adjacencies(entity, 1,
40 static_cast<int>(
vertices.size()), conn);
45 std::initializer_list<EntityHandle>
vertices,
46 EntityHandle &entity) {
50 matches, moab::Interface::INTERSECT);
51 CHKERR require(matches.size() == 1,
"Fixture has ambiguous topology");
52 entity = matches.front();
57 EntityHandle expected) {
63 CHKERR require(
parent == expected,
"Incorrect persistent parent tag");
65 const auto it = entities->find(child);
66 CHKERR require(
it != entities->end() && (*it)->getParentEnt() == expected,
67 "Refinement entity is missing or has an incorrect parent");
69 const auto range =
index.equal_range(expected);
71 std::find_if(range.first, range.second,
72 [&](
const auto &e) { return e->getEnt() == child; });
73 CHKERR require(found != range.second,
"Parent multi-index was not updated");
75 const auto element = elements->find(child);
76 CHKERR require(element != elements->end() &&
77 (*element)->getParentEnt() == expected,
78 "Refinement element has an incorrect parent");
88 PetscBool found = PETSC_FALSE;
92 "JSON must supply a positive parentage_scale");
94 const std::vector<std::array<double, 3>> x{
95 {0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {.25, 0, 0},
96 {.75, 0, 0}, {0, .25, 0}, {.25, .25, 0}, {.125, .125, .125}};
97 ReadUtilIface *reader;
100 std::vector<double *> arrays;
101 CHKERR reader->get_node_coords(3, x.size(), 0, start, arrays);
102 for (
size_t n = 0;
n != x.size(); ++
n)
103 for (
int d = 0;
d != 3; ++
d)
105 const EntityHandle
a = start + 4, b = start + 5,
c = start + 6;
106 const EntityHandle
f = start + 7,
v = start + 8;
108 CHKERR makeEntity(
mb, MBTET, {start, start + 1, start + 2, start + 3}, tet);
109 CHKERR bits->setBitRefLevel(
Range(tet, tet), level(0));
112 EntityHandle ab, ac, abc;
113 CHKERR getEntity(
mb, 1, {start, start + 1}, ab);
114 CHKERR getEntity(
mb, 1, {start, start + 2}, ac);
115 CHKERR getEntity(
mb, 2, {start, start + 1, start + 2}, abc);
116 std::map<EntityHandle, EntityHandle> vertex_parents{
117 {
a, ab}, {b, ab}, {
c, ac}, {
f, abc}, {
v, tet}};
118 std::map<EntityHandle, EntityHandle> expected = vertex_parents;
119 EntityHandle split_edge, face_edge, volume_edge, boundary_face, interior_face;
120 EntityHandle retained_edge, child_tet;
121 CHKERR makeEntity(
mb, MBEDGE, {
a, b}, split_edge);
122 CHKERR makeEntity(
mb, MBEDGE, {
a,
c}, face_edge);
123 CHKERR makeEntity(
mb, MBEDGE, {
f,
v}, volume_edge);
124 CHKERR makeEntity(
mb, MBEDGE, {start,
a}, retained_edge);
125 CHKERR makeEntity(
mb, MBTRI, {
a,
f,
c}, boundary_face);
126 CHKERR makeEntity(
mb, MBTRI, {
a,
c,
v}, interior_face);
128 expected.insert({{split_edge, ab},
132 {boundary_face, abc},
133 {interior_face, tet},
135 Range children(start + 4, start + 8);
136 children.insert(start);
137 for (
const auto &[child,
parent] : expected)
138 children.insert(child);
139 for (
int dim = 2; dim >= 1; --dim) {
141 for (
int upper = dim + 1; upper <= 3; ++upper) {
142 const auto entities = children.subset_by_dimension(upper);
143 CHKERR mb.get_adjacencies(entities, dim,
true, adjacent,
144 moab::Interface::UNION);
146 children.merge(adjacent);
150 EntityHandle retained_parent;
153 1, &retained_parent);
154 for (
int repeat = 0; repeat != 2; ++repeat) {
155 CHKERR refinement->setParents(
source, children, vertex_parents, level(1));
156 for (
const auto &[child,
parent] : expected)
158 CHKERR checkParent(m_field, start, retained_parent);
162 EntityHandle face_set, edge_set;
163 CHKERR mb.create_meshset(MESHSET_SET, face_set);
164 CHKERR mb.create_meshset(MESHSET_SET, edge_set);
165 CHKERR mb.add_entities(face_set, &abc, 1);
166 CHKERR mb.add_entities(edge_set, &ab, 1);
167 for (
auto meshset : {face_set, edge_set})
168 CHKERR bits->updateMeshsetByEntitiesChildren(meshset, level(1), meshset,
170 Range face_members, edge_members;
171 CHKERR mb.get_entities_by_handle(face_set, face_members);
172 CHKERR mb.get_entities_by_handle(edge_set, edge_members);
173 CHKERR require(face_members.find(boundary_face) != face_members.end() &&
174 face_members.find(face_edge) != face_members.end() &&
175 edge_members.find(split_edge) != edge_members.end() &&
176 edge_members.find(
a) != edge_members.end() &&
177 edge_members.find(b) != edge_members.end(),
178 "Meshset transfer missed descendants");
184 vertex_parents[
a] = abc;
185 CHKERR refinement->setParents(
source, children, vertex_parents, level(1));
186 CHKERR checkParent(m_field,
a, abc);
187 CHKERR checkParent(m_field, split_edge, abc);
189 const auto old_bucket = parent_index.equal_range(ab);
190 for (
auto it = old_bucket.first;
it != old_bucket.second; ++
it)
191 CHKERR require((*it)->getEnt() !=
a && (*it)->getEnt() != split_edge,
192 "Changed child remains in its previous parent bucket");
194 auto missing = vertex_parents;
197 return refinement->setParents(
source, children, missing, level(2));
199 CHKERR checkParent(m_field,
a, abc);
203 CHKERR require(unpublished.empty(),
204 "Failed ancestry published an output level");
207 EntityHandle duplicate, face_child;
208 CHKERR makeEntity(
mb, MBTRI, {start, start + 1, start + 2}, duplicate);
209 CHKERR bits->setEntitiesBitRefLevel(
Range(duplicate, duplicate), level(3));
210 CHKERR makeEntity(
mb, MBTRI, {start, start + 1, start + 2}, face_child);
211 Range face_children(start, start + 2);
212 face_children.insert(face_child);
213 CHKERR refinement->setParents(
source, face_children, {}, level(4));
214 CHKERR checkParent(m_field, face_child, abc);
216 ambiguous_source.insert(duplicate);
218 return refinement->setParents(ambiguous_source, face_children, {},
221 CHKERR checkParent(m_field, face_child, abc);
225 return refinement->setParents(
source.subset_by_type(MBVERTEX),
226 face_children, {}, level(2));
228 CHKERR refinement->setParents({}, {}, {}, level(5));
234int main(
int argc,
char **argv) {
236 "Topological parentage test\n");
241 MOFEM_LOG(
"WORLD", Sev::inform) <<
"Topological parentage checks passed";
std::map< EntityHandle, int > index
std::vector< int > source
std::vector< int > vertices
std::vector< int > parent
#define CATCH_ERRORS
Catch errors.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
virtual const RefEntity_multiIndex * get_ref_ents() const =0
Get the ref ents object.
virtual const RefElement_multiIndex * get_ref_finite_elements() const =0
Get the ref finite elements object.
#define MOFEM_LOG(channel, severity)
Log.
const double c
speed of light (cm/ns)
const double v
phase velocity of light in medium (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
implementation of Data Operators for Forces and Sources
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)
MoFEMErrorCode run(MoFEM::Interface &m_field)
Tag get_th_RefParentHandle() const
virtual moab::Interface & get_moab()=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.
Mesh refinement interface.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.