Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Dual_connectivity.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Dual_connectivity.C,v 1.17 2008/12/06 08:43:21 mtcampbe Exp $
24 
25 #include <algorithm>
26 
27 #include "Dual_connectivity.h"
28 
30 
32  bool with_ghost)
33  : _pane(*p), _with_ghost(with_ghost) {
34 
35  if ( p->dimension()==2 && p->is_structured())
37  else {
38  assert( !p->is_structured());
40  }
41 }
42 
44  std::vector<int>& elists) {
45  COM_assertion( node_id > 0); // Node id start from 1.
46  elists.clear();
47  elists.insert( elists.begin(), &_eids[_offsets[node_id-1]], &_eids[_offsets[node_id]]);
48 }
49 
51  COM_assertion_msg( _with_ghost || _pane.size_of_ghost_layers()==0,
52  "Not yet implemented for structured mesh with ghosts");
53 
54  int n=_with_ghost ? _pane.size_of_nodes() : _pane.size_of_real_nodes();
55  { // First, count the number of incident elements of each .
56  std::vector<char> nielems(n);
57  std::fill_n( nielems.begin(), n, 4);
58 
59  int ni=_pane.size_i(), nj=_pane.size_j();
60 
61  std::fill_n( nielems.begin(), ni, 2);
62  std::fill_n( nielems.begin()+ni*(nj-1), ni, 2);
63 
64  for ( int i=ni; i<ni*(nj-1); i+=ni)
65  nielems[i] = nielems[i+ni-1] = 2;
66 
67  nielems[0] = nielems[ni-1] = 1;
68  nielems[ni*nj-ni] = nielems[ni*nj-1] = 1;
69 
70  // Now construct a vector for storing the offsets
71  _offsets.clear(); _offsets.resize(n+1, 0);
72 
73  for ( int i=1; i<=n; ++i) _offsets[i] = _offsets[i-1]+nielems[i-1];
74  _eids.resize( _offsets[n]);
75  }
76 
77  { // Fill in the connectivity table
78  const int nn = 4;
80  for ( int i=1,size=_pane.size_of_elements(); i<=size; ++i, ene.next())
81  for ( int k=0; k<nn; ++k)
82  _eids[ _offsets[ene[k]-1]++] = i;
83 
84  // Recover _offsets
85  for ( int i=n; i>0; --i) _offsets[i] = _offsets[i-1];
86  _offsets[0] = 0;
87  }
88 }
89 
91 
92  int nnodes, nelems;
93 
94  if ( _with_ghost) {
95  nnodes=_pane.size_of_nodes();
96  nelems=_pane.size_of_elements();
97  }
98  else {
99  nnodes=_pane.size_of_real_nodes();
100  nelems=_pane.size_of_real_elements();
101  }
102 
103  { // First, count the number of incident elements of each node.
104  std::vector<char> nielems(nnodes);
105  std::fill_n( nielems.begin(), nnodes, 0);
106 
108  for ( int i=1; i<=nelems; ++i, ene.next())
109  for ( int k=0, nn=ene.size_of_nodes(); k<nn; ++k)
110  ++nielems[ ene[k]-1];
111 
112  // Now construct a vector for storing the offsets
113  _offsets.clear(); _offsets.resize(nnodes+1);
114  _offsets[0] = 0;
115  for ( int i=1; i<=nnodes; ++i) _offsets[i] = _offsets[i-1]+nielems[i-1];
116 
117  _eids.resize( _offsets[nnodes]);
118  }
119 
120  { // Fill in the connectivity table
122  for ( int i=1; i<=nelems; ++i, ene.next())
123  for ( int k=0, nn=ene.size_of_nodes(); k<nn; ++k)
124  _eids[ _offsets[ene[k]-1]++] = i;
125 
126  // Recover _offsets
127  for ( int i=nnodes; i>0; --i) _offsets[i] = _offsets[i-1];
128  _offsets[0] = 0;
129  }
130 }
131 
133 
134 
135 
136 
137 
138 
#define MAP_END_NAMESPACE
Definition: mapbasic.h:29
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
j indices k indices k
Definition: Indexing.h:6
#define COM_assertion_msg(EX, msg)
void incident_elements(int node_id, std::vector< int > &elists)
Obtain the IDs of the elements incident on a given node.
std::vector< int > _eids
const COM::Pane & _pane
blockLoc i
Definition: read.cpp:79
std::vector< int > _offsets
const NT & n
Pane_dual_connectivity(const COM::Pane *p, bool with_ghost=true)
Constructs the dual connectivity for a given pane.
#define MAP_BEGIN_NAMESPACE
Definition: mapbasic.h:28
void int int REAL REAL REAL *z blockDim dim * ni
Definition: read.cpp:77
void int * nj
Definition: read.cpp:74
Optimized version for unstructured meshes.
void construct_connectivity_unstr()
Construct dual connectivity for unstructured meshes.
void construct_connectivity_str_2()
Construct dual connectivity for 2-D structured meshes.
Optimized version for 2-D structured meshes.