Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PMesh.C
Go to the documentation of this file.
1 #include <iomanip>
7 #include <sstream>
8 
9 #include "PMesh.H"
10 
11 namespace Mesh {
12 
13  int Partition::GetBorderElements(std::vector<Mesh::IndexType> &be) const
14  {
15  std::list<Mesh::IndexType> belist;
16  Mesh::IndexType number_of_nodes = _mesh.NumberOfNodes();
17  Mesh::IndexType number_of_elements = _mesh.NumberOfElements();
18  std::vector<bool> element_processed(number_of_elements,false);
19  Mesh::IndexType nvolume_nodes = number_of_nodes - _info.nshared;
21  for(Mesh::IndexType nn = nvolume_nodes;nn < number_of_nodes;nn++){
22  std::vector<Mesh::IndexType>::const_iterator ei =
23  dc[nn].begin();
24  while(ei != dc[nn].end()){
25  if(!element_processed[*ei-1]){
26  element_processed[*ei-1] = true; // cheap uniquity
27  belist.push_back(*ei);
28  }
29  ei++;
30  }
31  }
32  belist.sort();
33  std::list<Mesh::IndexType>::iterator beli = belist.begin();
34  be.resize(belist.size());
35  std::vector<Mesh::IndexType>::iterator bei = be.begin();
36  while(bei != be.end())
37  *bei++ = *beli++;
38  return(0);
39  };
40 
41  int Partition::Read(const std::string &MeshName,IRAD::Comm::CommunicatorObject &comm,bool allow_n2m,std::ostream &ErrOut)
42  {
43  unsigned int nproc = comm.Size();
44  unsigned int rank = comm.Rank();
45  unsigned int id = rank + 1;
46  // Read the partitioning info
47  if(nproc > 1){
48  std::ifstream InfoInf;
49  std::ostringstream FNOstr;
50  FNOstr << MeshName << "." << id << ".info";
51  InfoInf.open(FNOstr.str().c_str());
52  if(!InfoInf){
53  comm.SetErr(1);
54  }
55  if(comm.Check()){
56  ErrOut << "Partition::Read Could not find partition info for " << MeshName;
57  return(1);
58  }
59  InfoInf >> _info.npart >> _info.part >> _info.nelem >> _info.nnodes >> _info.nborder
60  >> _info.nshared >> _info.nown;
61  if(_info.npart != nproc && !allow_n2m){
62  comm.SetErr(1);
63  }
64  if(comm.Check()){
65  ErrOut << "Partition::Read " << MeshName << " has partition/processor mismatch: ("
66  << _info.npart << "/" << nproc << ").\n";
67  return(1);
68  }
70  InfoInf.close();
71  }
72  else{
73  _info.nborder = 0;
74  _info.nshared = 0;
75  }
76  // done reading partition info
77  std::ifstream Inf;
78  std::ostringstream Ostr;
79  Ostr << MeshName;
80  if(nproc > 1)
81  Ostr << "." << id << ".pmesh";
82  else
83  Ostr << ".mesh";
84  Inf.open(Ostr.str().c_str());
85  // Don't blink or you'll miss the mesh actually being loaded here.
86  Inf >> _mesh.NC() >> _mesh.ECon();
87  _mesh.ECon().ShrinkWrap();
88  // Inf >> _nc >> _ec;
89  // _ec.ShrinkWrap();
90  // done loading actual mesh
91  // Mesh::IndexType number_of_nodes = _nc.Size();
92  // Mesh::IndexType number_of_elements = _ec.Nelem();
93  Mesh::IndexType number_of_nodes = _mesh.NumberOfNodes();
94  Mesh::IndexType number_of_elements = _mesh.NumberOfElements();
95  if(nproc == 1){
96  _info.nnodes = number_of_nodes;
97  _info.nown = 0;
98  _info.nlocal = number_of_nodes;
99  _info.nelem = number_of_elements;
100  }
101  else{
102  Inf >> _info.nborder;
103  _borders.resize(_info.nborder);
104  for(Mesh::IndexType nn = 0;nn < _info.nborder;nn++){
105  Mesh::IndexType nrecv = 0;
106  Mesh::IndexType nsend = 0;
107  Inf >> _borders[nn].rpart >> nrecv >> nsend;
108  _borders[nn].nrecv.resize(nrecv);
109  for(Mesh::IndexType ii = 0;ii < nrecv;ii++){
110  Mesh::IndexType nodeid = 0;
111  Inf >> _borders[nn].nrecv[ii] >> nodeid;
112  }
113  _borders[nn].nsend.resize(nsend);
114  for(Mesh::IndexType ii = 0;ii < nsend;ii++){
115  Mesh::IndexType nodeid = 0;
116  Inf >> _borders[nn].nsend[ii] >> nodeid;
117  }
118  }
119  }
120  Inf.close();
121  _communicator = &comm;
122  return(0);
123  }
124 
125 
126  int
127  Partition::Read(const std::string &MeshName,int id)
128  {
129  // rank = id - 1
130  std::ifstream Inf;
131  std::ostringstream FNOstr;
132  if(id > 0){
133  FNOstr << MeshName << "." << id << ".info";
134  Inf.open(FNOstr.str().c_str());
135  if(!Inf)
136  return(2);
138  Inf.close();
140  FNOstr.str("");
141  }
142  _info.nborder = 0;
143  _info.nshared = 0;
144  _info.nown = 0;
145  if(id > 0)
146  FNOstr << MeshName << "." << id << ".pmesh";
147  else
148  FNOstr << MeshName;
149  Inf.open(FNOstr.str().c_str());
150  if(!Inf)
151  return(3);
152  // Inf >> _nc;
153  // Inf >> _ec;
154  // _ec.ShrinkWrap();
155  // _ec.Sync();
156  Inf >> _mesh.NC();
157  Inf >> _mesh.ECon();
158  _mesh.ECon().ShrinkWrap();
159  _mesh.ECon().Sync();
160  if(id > 0){
161  Inf >> _info.nborder;
162  _borders.resize(_info.nborder);
163  for(Mesh::IndexType nn = 0;nn < _info.nborder;nn++){
164  Mesh::IndexType nrecv = 0;
165  Mesh::IndexType nsend = 0;
166  Inf >> _borders[nn].rpart >> nrecv >> nsend;
167  for(Mesh::IndexType ii = 0;ii < nrecv;ii++){
168  Mesh::IndexType nodeid = 0;
169  Inf >> nodeid;
170  _borders[nn].nrecv.push_back(nodeid);
171  Inf >> nodeid;
172  }
173  for(Mesh::IndexType ii = 0;ii < nsend;ii++){
174  Mesh::IndexType nodeid = 0;
175  Inf >> nodeid;
176  _borders[nn].nsend.push_back(nodeid);
177  Inf >> nodeid;
178  }
179  }
180  }
181  Inf.close();
182  return(0);
183  };
184 
185 }
void Sync()
Definition: Mesh.C:246
std::vector< Border > _borders
Definition: PMesh.H:104
void ShrinkWrap()
Definition: Mesh.C:247
General connectivity object.
Definition: Mesh.H:334
IRAD::Comm::CommunicatorObject * _communicator
Definition: PMesh.H:97
Parallel Mesh Stuff.
Class Mesh is the main class that holds all information to describe the current state of the mesh...
Definition: Mesh.hpp:19
Connectivity & GetCon(const MeshConType type)
Definition: Mesh.H:500
Connectivity & ECon()
Definition: Mesh.H:479
Mesh::IndexType npart
Definition: PMesh.H:84
Mesh::IndexType part
total number of partitions
Definition: PMesh.H:85
int Read(const std::string &meshname, int id)
Definition: PMesh.C:127
int NumberOfElements() const
Definition: Mesh.H:470
Mesh::IndexType nnodes
total number of elems
Definition: PMesh.H:87
Mesh::IndexType nborder
total number of nodes
Definition: PMesh.H:88
MeshUtilityObject _mesh
Definition: PMesh.H:99
Mesh::IndexType nlocal
number of shared nodes owned
Definition: PMesh.H:91
Mesh::IndexType nelem
partition id
Definition: PMesh.H:86
int NumberOfNodes() const
Definition: Mesh.H:469
int GetBorderElements(std::vector< Mesh::IndexType > &be) const
Definition: PMesh.C:13
static int rank
Definition: advectest.C:66
PartInfo _info
Definition: PMesh.H:103
IRAD::Primitive::IndexType IndexType
Definition: Mesh.H:57
Mesh::IndexType nown
number of shared nodes
Definition: PMesh.H:90
Mesh::IndexType nshared
number of borders
Definition: PMesh.H:89
NodalCoordinates & NC()
Definition: Mesh.H:471