Skip to content

Commit e922738

Browse files
Nightly Botcwsmith
authored andcommitted
Merging develop into master
2 parents a005f7c + acbe1ba commit e922738

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

test/makeAllCavities.cc

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ static apf::MeshTag* tagMesh(
5555
int dim,
5656
int model);
5757

58+
static apf::MeshTag* tagMesh(
59+
apf::Mesh2* m,
60+
const std::vector<std::string>& ids);
61+
5862
int main(int argc, char** argv)
5963
{
6064

@@ -81,6 +85,7 @@ int main(int argc, char** argv)
8185
printf("fa: creates all face cavities\n");
8286
printf("fi: creates all face cavities classified on interior\n");
8387
printf("fb: creates all face cavities classified on boundary\n");
88+
printf("ls: get a list from user and creates cavities for that list\n");
8489
printf("tagname: creates cavities for all entities that have tagname\n");
8590
MPI_Finalize();
8691
exit(EXIT_FAILURE);
@@ -132,6 +137,31 @@ int main(int argc, char** argv)
132137
tag = tagMesh(m, 2, 2);
133138
else if (mode.compare(std::string("fb")) == 0)
134139
tag = tagMesh(m, 2, 3);
140+
else if (mode.compare(std::string("ls")) == 0) {
141+
std::cout << "provide the list of entities format \"v_i,e_i,f_i\"" << std::endl;
142+
std::cout << "example: v120 e23 f0 represents vert 120," << std::endl;
143+
std::cout << "edge 23 and face 0." << std::endl;
144+
std::cout << "total #verts=" << m->count(0);
145+
std::cout << ", #edges=" << m->count(1);
146+
std::cout << ", #faces=" << m->count(2) << std::endl;
147+
int cnt=0;
148+
std::cout << "enter #of ents in the list:" << std::endl;
149+
std::cin >> cnt;
150+
std::vector<std::string> ents;
151+
ents.clear();
152+
while ((int)ents.size() < cnt) {
153+
std::string temp;
154+
std::cin >> temp;
155+
ents.push_back(temp);
156+
}
157+
PCU_ALWAYS_ASSERT((int)ents.size() == cnt);
158+
std::cout << "creating cavities for " << std::endl;
159+
for (int i = 0; i < (int)ents.size(); i++)
160+
std::cout << ents[i] << " ";
161+
std::cout << std::endl;
162+
163+
tag = tagMesh(m, ents);
164+
}
135165
else {
136166
tag = m->findTag(mode.c_str());
137167
if (!tag) {
@@ -845,3 +875,64 @@ static apf::MeshTag* tagMesh(
845875
}
846876
return t;
847877
}
878+
879+
static void getEntIds(
880+
const std::vector<std::string>& ids,
881+
std::vector<int>& vids,
882+
std::vector<int>& eids,
883+
std::vector<int>& fids)
884+
{
885+
vids.clear();
886+
eids.clear();
887+
fids.clear();
888+
889+
for (std::size_t i = 0; i < ids.size(); i++) {
890+
std::string key = ids[i].substr(0,1);
891+
int value = atoi(ids[i].substr(1).c_str());
892+
if (key.compare(std::string("v")) == 0)
893+
vids.push_back(value);
894+
if (key.compare(std::string("e")) == 0)
895+
eids.push_back(value);
896+
if (key.compare(std::string("f")) == 0)
897+
fids.push_back(value);
898+
}
899+
900+
}
901+
902+
static apf::MeshTag* tagMesh(
903+
apf::Mesh2* m,
904+
const std::vector<std::string>& ids)
905+
{
906+
std::vector<int> vids;
907+
std::vector<int> eids;
908+
std::vector<int> fids;
909+
getEntIds(ids, vids, eids, fids);
910+
PCU_ALWAYS_ASSERT(ids.size() == vids.size()+eids.size()+fids.size());
911+
912+
std::vector<int>::iterator vit;
913+
apf::MeshEntity* e;
914+
apf::MeshIterator* it;
915+
apf::MeshTag* t = m->createIntTag("which_ent", 1);
916+
for (int d = 0; d < 3; d++) {
917+
int index = 0;
918+
it = m->begin(d);
919+
while ( (e = m->iterate(it)) ) {
920+
bool found = false;
921+
if (d == 0 &&
922+
std::find(vids.begin(), vids.end(), index) != vids.end())
923+
found = true;
924+
if (d == 1 &&
925+
std::find(eids.begin(), eids.end(), index) != eids.end())
926+
found = true;
927+
if (d == 2 &&
928+
std::find(fids.begin(), fids.end(), index) != fids.end())
929+
found = true;
930+
int val = 1; // the value does not matter
931+
if (found)
932+
m->setIntTag(e, t, &val);
933+
index++;
934+
}
935+
m->end(it);
936+
}
937+
return t;
938+
}

0 commit comments

Comments
 (0)