File: partition.cpp

package info (click to toggle)
gmsh 4.15.1%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 52,880 kB
  • sloc: cpp: 440,657; ansic: 114,930; f90: 15,611; python: 13,907; yacc: 7,438; java: 3,491; lisp: 3,206; lex: 633; perl: 571; makefile: 500; xml: 414; sh: 407; javascript: 113; modula3: 32
file content (79 lines) | stat: -rw-r--r-- 2,867 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <gmsh.h>
#include <iostream>
#include <set>

int main(int argc, char **argv)
{
  bool write_file = false;
  bool write_one_file_per_partition = false;
  bool partition_using_metis = false;

  gmsh::initialize();

  // create a simple geometry and mesh it
  gmsh::model::add("test");
  gmsh::model::occ::addRectangle(0, 0, 0, 1, 1);
  gmsh::model::occ::synchronize();
  gmsh::model::mesh::generate(2);

  // partition the mesh using Metis, or using the SimplePartition plugin (to
  // create simple chessboard-like partitions). This will create new
  // ("partitioned") entities in the model, that will behave exactly like other
  // model entities. In particular, the full boundary representation is
  // constructed provided that Mesh.PartitionCreateTopology == 1. The only
  // difference is that partitioned entities have a "parent", which allows to
  // link the partitioned entity with the entity it is a subset of. There are
  // other options to govern how physical groups are treated
  // (Mesh.PartitionCreatePhysicals), and if ghost cells should be created
  // (Mesh.PartitionCreateGhostCells).
  if(partition_using_metis) { gmsh::model::mesh::partition(3); }
  else {
    gmsh::plugin::setNumber("SimplePartition", "NumSlicesX", 3.);
    gmsh::plugin::run("SimplePartition");
  }

  // write the partitioned mesh to disk?
  if(write_file) {
    // create one file per partition?
    if(write_one_file_per_partition) {
      gmsh::option::setNumber("Mesh.PartitionSplitMeshFiles", 1);
    }
    gmsh::write("partition.msh");
  }

  // iterate over partitioned entities and print some info
  std::vector<std::pair<int, int> > entities;
  gmsh::model::getEntities(entities);

  for(std::vector<std::pair<int, int> >::iterator it = entities.begin();
      it != entities.end(); it++) {
    std::vector<int> partitions;
    gmsh::model::getPartitions(it->first, it->second, partitions);
    if(partitions.size()) {
      std::string type;
      gmsh::model::getType(it->first, it->second, type);
      std::cout << "Entity (" << it->first << "," << it->second << ") "
                << "of type " << type << "\n";
      std::cout << " - Partition(s):";
      for(std::size_t i = 0; i < partitions.size(); i++)
        std::cout << " " << partitions[i];
      std::cout << "\n";
      int pdim, ptag;
      gmsh::model::getParent(it->first, it->second, pdim, ptag);
      std::cout << " - Parent: (" << pdim << "," << ptag << ")\n";
      std::vector<std::pair<int, int> > bnd;
      gmsh::model::getBoundary({*it}, bnd);
      std::cout << " - Boundary:";
      for(std::size_t i = 0; i < bnd.size(); i++)
        std::cout << " (" << bnd[i].first << "," << bnd[i].second << ")";
      std::cout << "\n";
    }
  }

  std::set<std::string> args(argv, argv + argc);
  if(!args.count("-nopopup")) gmsh::fltk::run();

  gmsh::finalize();

  return 0;
}