Feellgood
meshUtils.h
1 #ifndef MESHUTILS_H
2 #define MESHUTILS_H
3 
4 #include <gmsh.h>
5 
9 template <int TYPE>
10 bool all_elems_are(std::vector<int> &container)
11  { return std::all_of(container.begin(), container.end(), [](int &e_type){return e_type == TYPE;} ); }
12 
16 template <class T>
17 bool checkNamedObjects(std::vector<T> const &v_prm, const int dim_obj)
18  {
19  bool existRegions(true);
20  std::vector<std::pair<int, int> > physGroups;
21  gmsh::model::getPhysicalGroups(physGroups,dim_obj);
22  std::vector<std::string> o_names;
23  std::for_each(physGroups.begin(),physGroups.end(),[&o_names]( std::pair<int, int> &pGroup)
24  {
25  std::string physGroupName;
26  gmsh::model::getPhysicalName(pGroup.first, pGroup.second, physGroupName);
27  o_names.push_back(physGroupName);
28  });
29 
30  std::for_each(v_prm.begin(),v_prm.end(),[&existRegions,&o_names](const auto &p)
31  {
32  if (p.regName != "__default__")
33  {
34  if (!std::any_of(o_names.begin(),o_names.end(),
35  [&p] (std::string &elem) { return p.regName == elem; } ) )
36  {
37  std::cout << "Fatal Error: region " << p.regName << " not found.\n";
38  existRegions = false;
39  }
40  }
41  } );
42  return existRegions;
43  }
44 
46 template<typename T>
47 void suppress_copies(std::vector<T> &v_idx)
48  {
49  std::sort(v_idx.begin(), v_idx.end());
50  v_idx.resize( std::distance(v_idx.begin(), std::unique(v_idx.begin(), v_idx.end())) );
51  v_idx.shrink_to_fit();
52  }
53 
54 #endif