Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HigherOrder.C
Go to the documentation of this file.
1 #include <iomanip>
2 #include "DriverProgram.H"
3 
4 namespace GridConversion{ namespace DriverProgram{
5 
6  int SerialProgram::HigherOrderTets(SolverUtils::Mesh::Connectivity elemEdgeToElems,
7  SolverUtils::Mesh::Connectivity nodesToDomains){
8 
9  std::ostringstream Ostr;
10  std::stringstream ss;
11 
12  FunctionEntry("HigherOrderTets");
13 
14  //new numNodesPerElem
15  int newNumNPE=10;
16 
17  //a vector for the new elements
18  std::vector<unsigned int> newElems(numElems*newNumNPE,0);
19 
20  //Loop over every element
21  for(int i=0; i < numElems; i++){
22  std::cout << "elem " << i+1 << std::endl;
23  //loop over all the nodes for the element
24  for(int j=0; j < numNodesPerElem; j++){
25  //first populate the new element with the original nodes
26  newElems[i*newNumNPE + j] = elems[i*numNodesPerElem + j];
27  }//loop over nodes for the element
28  }//loop over all the elements
29 
30  //Loop over every edge (we want to add a node in the middle
31  //of each edge
32  double x, y, z;
33  unsigned int n1, n2;
34  for(int i=0; i < numElemEdges; i++){
35 
36  std::cout << "edge " << i+1 << std::endl;
37  //create the new node
38  numNodes++;
40  n2 = elemEdges[i*numNodesPerElemEdge + 1]-1;
41 
42  x = (nodes[3*n1 + 0] + nodes[3*n2 + 0])/2.0;
43  y = (nodes[3*n1 + 1] + nodes[3*n2 + 1])/2.0;
44  z = (nodes[3*n1 + 2] + nodes[3*n2 + 2])/2.0;
45 
46  nodes.push_back(x);
47  nodes.push_back(y);
48  nodes.push_back(z);
49 
50  std::cout << " new node " << numNodes << ": "
51  << x << " " << y << " " << z << std::endl;
52 
53  //add the new node to the appropriate domain
54  //if its on one
55  //loop over the domains for the first node
56  for(int j=0; j < nodesToDomains[n1].size(); j++){
57  //loop over the domains for the second node
58  for(int k=0; k < nodesToDomains[n2].size(); k++){
59  //If they share a domain this new node is also on it
60  if(nodesToDomains[n1][j] == nodesToDomains[n2][k]){
61  int domain = nodesToDomains[n1][j]-1;
62  domains[domain].push_back(numNodes);
63  }
64  }
65  }
66 
67  //now add the node to the appropriate places
68  //in the element connectivity
69 
70  //loop over every element for the edge
71  for(int j=0; j < elemEdgeToElems[i].size(); j++){
72  int elem = elemEdgeToElems[i][j];
73  std::cout << " element " << elem << std::endl;
74  //find which edge this edge is for the element
75  //(1st, 2nd, ... 6th edge)
76  //loop over the edges for the element
77  for(int k=0; k < numEdgesPerElem; k++){
78  std::cout << " edge " << elemToElemEdges[numEdgesPerElem*(elem-1) + k] << std::endl;
79  //if we found the edge number add the node
80  //to the element in the appropriate place
81  //(if it hasn't already been added)
82  if(elemToElemEdges[numEdgesPerElem*(elem-1) + k] == i+1){
83  switch (k) {
84  case 0:
85  //Add the node if it hasn't already been added
86  if(newElems[newNumNPE*(elem-1) + 4] == 0){
87  newElems[newNumNPE*(elem-1) + 4] = numNodes;
88  }
89  break;
90  case 1:
91  //Add the node if it hasn't already been added
92  if(newElems[newNumNPE*(elem-1) + 6] == 0){
93  newElems[newNumNPE*(elem-1) + 6] = numNodes;
94  }
95  break;
96  case 2:
97  //Add the node if it hasn't already been added
98  if(newElems[newNumNPE*(elem-1) + 7] == 0){
99  newElems[newNumNPE*(elem-1) + 7] = numNodes;
100  }
101  break;
102  case 3:
103  //Add the node if it hasn't already been added
104  if(newElems[newNumNPE*(elem-1) + 5] == 0){
105  newElems[newNumNPE*(elem-1) + 5] = numNodes;
106  }
107  break;
108  case 4:
109  //Add the node if it hasn't already been added
110  if(newElems[newNumNPE*(elem-1) + 8] == 0){
111  newElems[newNumNPE*(elem-1) + 8] = numNodes;
112  }
113  break;
114  case 5:
115  //Add the node if it hasn't already been added
116  if(newElems[newNumNPE*(elem-1) + 9] == 0){
117  newElems[newNumNPE*(elem-1) + 9] = numNodes;
118  }
119  break;
120  }//switch over k
121  }//if we found the edge
122  }//loop over edges for the element
123  }//loop over elements for the edge
124  }//loop over every edge
125 
126  std::cout << "line " << __LINE__ << std::endl;
127 
128  //print to check
129  if(verblevel > 3){
130  Ostr << "new elements: " << std::endl;
131  for(int i=0; i < numElems; i++){
132  Ostr << i+1 << ":" << std::endl;
133  for(int j=0; j < newNumNPE; j++){
134  Ostr << newElems[i*newNumNPE + j] << " ";
135  }
136  Ostr << std::endl;
137  }
138  }
139  StdOut(Ostr.str());
140  Ostr.str("");
141 
142  std::cout << "line " << __LINE__ << std::endl;
143  //save the new elements arrray to the old one
144  elems.resize(numElems*newNumNPE);
145  elems = newElems;
146  numNodesPerElem = newNumNPE;
147 
148  StdOut(Ostr.str());
149  Ostr.str("");
150 
151  std::cout << "line " << __LINE__ << std::endl;
152  FunctionExit("HigherOrderTets");
153 
154  std::cout << "line " << __LINE__ << std::endl;
155  return 0;
156 
157  } //HigherOrderTets function
158 
159 }; //DriverProgram namespace
160 }; //GridConversion namespace
virtual int HigherOrderTets(SolverUtils::Mesh::Connectivity elemEdgeToElems, SolverUtils::Mesh::Connectivity nodesToDomains)
This function creates higher order tets from linear tets.
Definition: HigherOrder.C:6
j indices k indices k
Definition: Indexing.h:6
void int int REAL REAL * y
Definition: read.cpp:74
std::vector< std::vector< unsigned int > > domains
vector of vectors to hold the domains
int numElemEdges
number of element edges in mesh
std::vector< unsigned int > elemToElemEdges
map of elements to element edges
GridConversion interface.
std::vector< unsigned int > elems
vector for holding element connectivies read from input
int numElems
number of elements in mesh
int numNodesPerElemEdge
number of nodes per element edge
void int int int REAL REAL REAL * z
Definition: write.cpp:76
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
int numNodesPerElem
number of nodes per element
j indices j
Definition: Indexing.h:6
std::vector< unsigned int > elemEdges
vector for holding element edges
std::vector< double > nodes
vector for holding nodal coordinates read from input