Chi-Tech
chi_meshcontinuum_uniquebndryIDs.cc
Go to the documentation of this file.
1#include "chi_meshcontinuum.h"
2
3#include "chi_runtime.h"
4#include "chi_log.h"
5
6#include "chi_mpi.h"
7
8
9//###################################################################
10/**Builds and returns a vector of unique boundary id's present in
11 * the mesh.*/
13{
15 Chi::log.Log() << "Identifying unique boundary-ids.";
16
17 //====================================== Develop local bndry-id set
18 std::set<uint64_t> local_bndry_ids_set;
19 for (auto& cell : local_cells)
20 for (auto& face : cell.faces_)
21 if (not face.has_neighbor_)
22 local_bndry_ids_set.insert(face.neighbor_id_);
23
24 //====================================== Vectorify it and get local count
25 std::vector<uint64_t> local_bndry_ids(local_bndry_ids_set.begin(),
26 local_bndry_ids_set.end());
27 int local_num_bndry_ids = (int)local_bndry_ids.size();
28
29 //====================================== Everyone now tells everyone
30 // how many bndry-ids they have
31 std::vector<int> locI_bndry_count(Chi::mpi.process_count,0);
32
33 MPI_Allgather(&local_num_bndry_ids, //sendbuf
34 1, //sendcount
35 MPI_INT, //sendtype
36 locI_bndry_count.data(), //recvbuf
37 1, //recvcount
38 MPI_INT, //recvtype
39 Chi::mpi.comm); //communicator
40
41 //====================================== Build a displacement list, in prep
42 // for gathering all bndry-ids
43 std::vector<int> locI_bndry_ids_displs(Chi::mpi.process_count,0);
44 size_t total_num_global_bndry_ids=locI_bndry_count[0];
45 for (int locI=1; locI< Chi::mpi.process_count; ++locI)
46 {
47 locI_bndry_ids_displs[locI] = locI_bndry_ids_displs[locI-1] +
48 locI_bndry_count[locI-1];
49 total_num_global_bndry_ids += locI_bndry_count[locI];
50 }
51
52 //====================================== Everyone now sends everyone
53 // they're boundary-ids
54 std::vector<uint64_t> globl_bndry_ids(total_num_global_bndry_ids);
55
56 MPI_Allgatherv(local_bndry_ids.data(), //sendbuf
57 local_num_bndry_ids, //sendcount
58 MPI_UNSIGNED_LONG_LONG, //sendtype
59 globl_bndry_ids.data(), //recvbuf
60 locI_bndry_count.data(), //recvcounts
61 locI_bndry_ids_displs.data(), //displs
62 MPI_UNSIGNED_LONG_LONG, //recvtype
63 Chi::mpi.comm); //communicator
64
65 std::set<uint64_t> globl_bndry_ids_set(globl_bndry_ids.begin(),
66 globl_bndry_ids.end());
67
68 std::vector<uint64_t> unique_bdnry_ids(globl_bndry_ids_set.begin(),
69 globl_bndry_ids_set.end());
70 return unique_bdnry_ids;
71}
static chi::ChiLog & log
Definition: chi_runtime.h:81
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
const MPI_Comm & comm
MPI communicator.
Definition: mpi_info.h:28
void Barrier() const
Definition: mpi_info.cc:38
const int & process_count
Total number of processes.
Definition: mpi_info.h:27
LocalCellHandler local_cells
std::vector< uint64_t > GetDomainUniqueBoundaryIDs() const