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  {
12  return std::all_of(container.begin(), container.end(), [](int &e_type){return e_type == TYPE;});
13  }
14 
19 template <class T>
20 bool checkNamedObjects(std::vector<T> const &v_prm, const int dim_obj)
21  {
22  bool existRegions(true);
23  std::vector<std::pair<int, int> > physGroups;
24  gmsh::model::getPhysicalGroups(physGroups,dim_obj);
25  std::vector<std::string> o_names;
26  std::for_each(physGroups.begin(),physGroups.end(),[&o_names]( std::pair<int, int> &pGroup)
27  {
28  std::string physGroupName;
29  gmsh::model::getPhysicalName(pGroup.first, pGroup.second, physGroupName);
30  o_names.push_back(physGroupName);
31  });
32 
33  std::for_each(v_prm.begin(),v_prm.end(),[&existRegions,&o_names](const auto &p)
34  {
35  if (p.regName != "__default__")
36  {
37  if (!std::any_of(o_names.begin(),o_names.end(),
38  [&p] (std::string &elem) { return p.regName == elem; } ) )
39  {
40  std::cout << "Fatal Error: region " << p.regName << " not found.\n";
41  existRegions = false;
42  }
43  }
44  } );
45  return existRegions;
46  }
47 
49 template<typename T>
50 void suppress_copies(std::vector<T> &v_idx)
51  {
52  std::sort(v_idx.begin(), v_idx.end());
53  v_idx.resize( std::distance(v_idx.begin(), std::unique(v_idx.begin(), v_idx.end())) );
54  v_idx.shrink_to_fit();
55  }
56 
57 #endif