Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BSMesh.H
Go to the documentation of this file.
1 #ifndef _BSMESH_H_
7 #define _BSMESH_H_
8 #include "Mesh.H"
9 namespace Mesh {
15  template<typename T>
16  class BSExtent : public std::vector<std::vector<T> >
17  {
18  private:
19  size_t _nd;
20  std::vector<size_t> _Np;
21  std::vector<size_t> _N;
22  public:
24  {
25  this->resize(0);
26  _nd = 0;
27  _Np.resize(0);
28  _N.resize(0);
29  }
30  BSExtent(const std::vector<std::vector<T> > &inextent)
31  {
32  _nd = inextent.size();
33  this->resize(_nd);
34  for(size_t i = 0; i < _nd; i++){
35  typename std::vector<T>::const_iterator iei = inextent[i].begin();
36  while(iei != inextent[i].end())
37  (*this)[i].push_back(*iei++);
38  }
39  Sync();
40  };
41  BSExtent(const std::vector<T> &inflatextent){
42  _nd = inflatextent.size()/2;
43  this->resize(_nd);
44  size_t nd = 0;
45  typename BSExtent<T>::iterator bsi = this->begin();
46  while(bsi != this->end()){
47  bsi->push_back(inflatextent[nd++]);
48  bsi->push_back(inflatextent[nd++]);
49  bsi++;
50  }
51  Sync();
52  };
53  BSExtent(const T *src,int nd=3){
54  _nd = nd;
55  this->resize(_nd);
56  unsigned int nindex = 0;
57  typename BSExtent<T>::iterator bsi = this->begin();
58  while(bsi != this->end()){
59  bsi->push_back(src[nindex++]);
60  bsi->push_back(src[nindex++]);
61  bsi++;
62  }
63  Sync();
64  };
65  void destroy()
66  {
67  typename BSExtent<T>::iterator bsi = this->begin();
68  while(bsi != this->end())
69  bsi++->resize(0);
70  this->resize(0);
71  _nd = 0;
72  _Np.resize(0);
73  _N.resize(0);
74  };
75  void Init(const std::vector<T> &inflatextent){
76  destroy();
77  _nd = inflatextent.size()/2;
78  this->resize(_nd);
79  size_t nd = 0;
80  typename BSExtent<T>::iterator bsi = this->begin();
81  while(bsi != this->end()){
82  bsi->push_back(inflatextent[nd++]);
83  bsi->push_back(inflatextent[nd++]);
84  bsi++;
85  }
86  Sync();
87  };
88  void Sync()
89  {
90  _nd = this->size();
91  _N.resize(_nd);
92  _Np.resize(_nd);
93  for(size_t i = 0; i < _nd; i++){
94  _N[i] = (*this)[i][1] - (*this)[i][0] + 1;
95  }
96  _Np[0] = 1;
97  for(size_t i = 1; i < _nd;i++){
98  _Np[i] = _N[i-1] * _Np[i-1];
99  }
100  };
101  T NNodes(){
102  T nnodes = 1;
103  typename BSExtent<T>::iterator bsi = this->begin();
104  while(bsi != this->end()){
105  nnodes *= (((*bsi)[1] - (*bsi)[0])+1);
106  bsi++;
107  }
108  return(nnodes);
109  };
110  int ND(){return(this->size());};
111  void Flatten(std::vector<T> &output)
112  {
113  output.resize(0);
114  typename BSExtent<T>::iterator bsi = this->begin();
115  while(bsi != this->end()){
116  output.push_back((*bsi)[0]);
117  output.push_back((*bsi)[1]);
118  bsi++;
119  }
120  };
121  void dir_loop(int nd,T indoff,T plane,std::vector<T> &N,
122  std::vector<T> &NP,const BSExtent<T> &inextent,
123  std::vector<T> &indices)
124  {
125  int dindex = nd - 1;
126  plane += NP[dindex];
127  T start = inextent[dindex][0];
128  T end = inextent[dindex][1];
129  for(T dd = start;dd <= end;dd++){
130  if(dindex == 0)
131  indices.push_back(dd - (*this)[dindex][0]+1+indoff);
132  else{
133  T ndoff = indoff + (dd - (*this)[dindex][0])*NP[dindex];
134  dir_loop(dindex,ndoff,plane,N,NP,inextent,indices);
135  }
136  }
137 
138  };
139  void GetFlatIndices(const BSExtent<T> &extent,std::vector<T> &indices)
140  {
141  int nd = ND();
142  indices.resize(0);
143  std::vector<T> N(nd);
144  std::vector<T> NP(nd);
145  for(int nc = 0;nc < nd;nc++){
146  N[nc] = (*this)[nc][1] - (*this)[nc][0] + 1;
147  NP[nc] = (nc == 0 ? 1 : N[nc-1] * NP[nc-1]);
148  }
149  NP[0] = 0;
150  dir_loop(nd,0,0,N,NP,extent,indices);
151  };
152  void Overlap(const BSExtent<T> &inextent,BSExtent<T> &outextent)
153  {
154  size_t nd = ND();
155  outextent.resize(0);
156  bool match = true;
157  for(size_t j = 0;j < nd && match;j++){
158  if(!(((*this)[j][0] >= inextent[j][0] &&
159  (*this)[j][0] <= inextent[j][1]) ||
160  ((*this)[j][1] >= inextent[j][0] &&
161  (*this)[j][1] <= inextent[j][1])))
162  match = false;
163  }
164  if(match){ // then this extent has some overlap with the searched
165  outextent.resize(nd);
166  for(size_t i = 0;i < nd;i++)
167  outextent[i].resize(2);
168  for(size_t i = 0;i < nd;i++){
169  outextent[i][0] = std::max((*this)[i][0],inextent[i][0]);
170  outextent[i][1] = std::min((*this)[i][1],inextent[i][1]);
171  }
172  }
173  };
174  void FindSharedNodes(std::vector<BSExtent<T> > &extent_pool,std::vector<BSExtent<T> > &shared_extents,
175  std::vector<T> &neighbors)
176  {
177  shared_extents.resize(0);
178  T nindex = 0;
179  typename std::vector<BSExtent<T> >::iterator epi = extent_pool.begin();
180  while(epi != extent_pool.end()){
181  if(*epi != *this){
182  BSExtent<T> overlap;
183  this->Overlap(*epi,overlap);
184  if(!overlap.empty()){
185  neighbors.push_back(nindex);
186  shared_extents.push_back(overlap);
187  }
188  }
189  nindex++;
190  epi++;
191  }
192  };
193  inline T NodeNum(std::vector<T> &index)
194  {
195  T l0 = 1;
196  for(size_t i = (_nd-1);i >= 0;i--)
197  l0 += (index[i] - (*this)[i][0])*_Np[i];
198  };
200  {
201  // get coordinates of lower left hand coordinates:
202  // istart to (iend - 1), or istart
203  // jstart to (jend - 1), or jstart
204  // kstart to (kend - 1), or kstart
205  assert(_nd == 3);
206  BSExtent<T> lowerleft(*this);
207  int mesh_nd = 3;
208  for(int i = 0;i < 3;i++){
209  if(_N[i] > 1)
210  lowerleft[i][1]--;
211  else
212  mesh_nd--;
213  }
214  assert(mesh_nd > 1);
215  std::vector<T> indices;
216  GetFlatIndices(lowerleft,indices);
217  IndexType offset = (_N[0] > 1 ? _N[0] : _N[1]);
218  IndexType planeoffset = (mesh_nd == 2 ? 0 : offset*_N[1]);
219  IndexType number_of_elements = indices.size();
220  for(IndexType i = 0;i < number_of_elements;i++){
221  std::vector<IndexType> element;
222  element.push_back(indices[i]);
223  element.push_back(indices[i]+1);
224  element.push_back(indices[i]+1+offset);
225  element.push_back(indices[i]+offset);
226  if(planeoffset > 0){
227  element.push_back(indices[i]+planeoffset);
228  element.push_back(indices[i]+1+planeoffset);
229  element.push_back(indices[i]+planeoffset+offset+1);
230  element.push_back(indices[i]+planeoffset+offset);
231  }
232  conn.AddElement(element);
233  }
234  conn.Sync();
235  };
236  };
237 
240  std::vector<Mesh::IndexType> &gridsizes,
241  GeoPrim::CBox &box);
242 
243 }
244 #endif
void Sync()
Definition: Mesh.C:246
BSExtent(const std::vector< std::vector< T > > &inextent)
Definition: BSMesh.H:30
void AddElement(const std::vector< IndexType > &elem)
Definition: Mesh.C:235
General connectivity object.
Definition: Mesh.H:334
int GenerateCartesianGrid(Mesh::NodalCoordinates &nc, Mesh::BSExtent< Mesh::IndexType > &gridextent, std::vector< Mesh::IndexType > &gridsizes, GeoPrim::CBox &box)
void CreateUnstructuredMesh(Connectivity &conn)
Definition: BSMesh.H:199
void FindSharedNodes(std::vector< BSExtent< T > > &extent_pool, std::vector< BSExtent< T > > &shared_extents, std::vector< T > &neighbors)
Definition: BSMesh.H:174
void Overlap(const BSExtent< T > &inextent, BSExtent< T > &outextent)
Definition: BSMesh.H:152
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
void Sync()
Definition: BSMesh.H:88
KD_tree::Box box
Definition: Overlay_0d.C:47
Mesh Stuff.
Class Mesh is the main class that holds all information to describe the current state of the mesh...
Definition: Mesh.hpp:19
real *8 function offset(vNorm, x2, y2, z2)
Definition: PlaneNorm.f90:211
T NodeNum(std::vector< T > &index)
Definition: BSMesh.H:193
BSExtent(const T *src, int nd=3)
Definition: BSMesh.H:53
void dir_loop(int nd, T indoff, T plane, std::vector< T > &N, std::vector< T > &NP, const BSExtent< T > &inextent, std::vector< T > &indices)
Definition: BSMesh.H:121
void Flatten(std::vector< T > &output)
Definition: BSMesh.H:111
void GetFlatIndices(const BSExtent< T > &extent, std::vector< T > &indices)
Definition: BSMesh.H:139
blockLoc i
Definition: read.cpp:79
std::vector< size_t > _N
Definition: BSMesh.H:21
void destroy()
Definition: BSMesh.H:65
std::vector< size_t > _Np
Definition: BSMesh.H:20
size_t _nd
Definition: BSMesh.H:19
BSExtent(const std::vector< T > &inflatextent)
Definition: BSMesh.H:41
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
j indices j
Definition: Indexing.h:6
void Init(const std::vector< T > &inflatextent)
Definition: BSMesh.H:75
IRAD::Primitive::IndexType IndexType
Definition: Mesh.H:57
Simple Block Structured Mesh object.
Definition: BSMesh.H:16
int ND()
Definition: BSMesh.H:110