Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ReadStanfordInput.C
Go to the documentation of this file.
1 #include "DriverProgram.H"
2 
3 namespace GridConversion{ namespace DriverProgram{
4 
6 
7  FunctionEntry("ReadStanfordInput");
8  std::ostringstream Ostr;
9 
10  // Open the specified input file for reading
11  Inf.open(input_name.c_str());
12  if(!Inf){
13  // If the input file failed to open, notify to
14  // the error stream and return non-zero
15  std::ostringstream ErrOstr;
16  ErrOstr << "Could not open input file, '"
17  << input_name << "'.\n";
18  StdOut(Ostr.str());
19  Ostr.str("");
20  ErrOut(ErrOstr.str());
21  ErrOstr.str("");
22  // don't forget to tell the profiler/stacker the
23  // function is exiting.
24  FunctionExit("ReadStanfordInput");
25  return(1);
26  }
27 
28  std::string line;
29  double valueD;
30  unsigned int valueI;
31  std::string valueS;
32  std::stringstream ss;
33 
34  //Read Input file in Stanford format from Poinwise
35  for(int i=0; i < 8; i++)
36  std::getline(Inf,line);
37  ss.clear();
38  ss.str("");
39  ss << line;
40  ss >> valueS >> numElems;
41 
42  //Print for check
43  if(verblevel > 1){
44  Ostr << "Number of nodes = " << numNodes << std::endl;
45  Ostr << "Number of elements = " << numElems << std::endl;
46  }
47  for(int i=0; i < numElems; i++){
48  std::getline(Inf,line);
49  ss.clear();
50  ss.str("");
51  ss << line;
52  ss >> valueI;
53 
54  //Make sure the elements all have the same shape
55  //For now we only support meshes with one shape of element
56  //(this is what Rocfrac requires as well).
57  if(i == 0){
58  elemShape = valueI;
59  //Print for check
60  if(verblevel > 1)
61  Ostr << "Element shape value: " << elemShape << std::endl;
62  if(elemShape == 10)
63  numNodesPerElem = 4;
64  else if(elemShape == 12)
65  numNodesPerElem = 8;
66  else{
67  std::ostringstream ErrOstr;
68  ErrOstr << "For Stanford format input only element shapes " << std::endl
69  << "10 and 12 are supported! Input file has shape "
70  << elemShape << "!" << std::endl;
71  StdOut(Ostr.str());
72  Ostr.str("");
73  ErrOut(ErrOstr.str());
74  ErrOstr.str("");
75  exit(1);
76  }
77  }
78  else{
79  if(valueI != elemShape){
80  std::ostringstream ErrOstr;
81  ErrOstr << "Meshes must have only one element shape!" << std::endl
82  << "Element " << i << " has shape value " << valueI << " but "
83  << "previous elements have shape value " << elemShape << std::endl;
84  StdOut(Ostr.str());
85  Ostr.str("");
86  ErrOut(ErrOstr.str());
87  ErrOstr.str("");
88  exit(1);
89  }
90  }
91 
92  //Read in 8 nodes for shape 12 (hexahedral) or 4 nodes for shape 10 (tetrahedral)
93  for(int j=0; j < numNodesPerElem; j++){
94  ss >> valueI;
95  //We are starting are node count at 1
96  valueI++;
97  elems.push_back(valueI);
98  }
99  }
100 
101  for(int i=0; i < 4; i++)
102  std::getline(Inf,line);
103  ss.clear();
104  ss.str("");
105  ss << line;
106  ss >> valueS >> numNodes;
107 
108  //Resize nodes vector
109  nodes.resize(3*numNodes);
110 
111  //Print for check
112  if(verblevel > 1){
113  Ostr << "Number of nodes = " << numNodes << std::endl;
114  Ostr << "Number of elements = " << numElems << std::endl;
115  }
116 
117  for(int i=0; i < numNodes; i++){
118  std::getline(Inf,line);
119  ss.clear();
120  ss.str("");
121  ss << line;
122  ss >> nodes[3*i + 0] >> nodes[3*i + 1] >> nodes[3*i + 2];
123  }
124 
125 
126  // Read the boundary domain info
127  for(int i=0; i < 4; i++)
128  getline(Inf,line);
129  ss.clear();
130  ss.str("");
131  ss << line;
132 
133  ss >> valueS >> numDomains;
134 
135  // loop over the domains
136  for(int i=0; i < numDomains; i++){
137  int packet, lines=0, domainNodes;
138  std::vector<unsigned int> oneDomain;
139  int numNodesPerFaceElem;
140 
141  getline(Inf,line);
142  getline(Inf,line);
143  ss.clear();
144  ss.str("");
145  ss << line;
146 
147  ss >> valueS >> lines;
148 
149  //loop over number of faces on domain
150  for(int j=0; j < lines; j++){
151  getline(Inf,line);
152  ss.clear();
153  ss.str("");
154  ss << line;
155 
156  ss >> valueI;
157  if(valueI == 9)
158  numNodesPerFaceElem = 4;
159  else if(valueI == 5)
160  numNodesPerFaceElem = 3;
161  else{
162  std::ostringstream ErrOstr;
163  ErrOstr << "Face elements must be of type 9 (quad) or 5 (tri)!" << std::endl
164  << "Face type " << valueI << " was read!" << std::endl;
165  StdOut(Ostr.str());
166  Ostr.str("");
167  ErrOut(ErrOstr.str());
168  ErrOstr.str("");
169  exit(1);
170  }
171 
172  //loop over the number of nodes for the face
173  for(int k=0; k < numNodesPerFaceElem; k++){
174  ss >> valueI;
175  //We are starting our node count at 1
176  valueI++;
177  //check to see if the node has been added to
178  //the domain already
179  bool newValue=true;
180  for(int l=0; l < oneDomain.size(); l++){
181  if(oneDomain[l] == valueI){
182  newValue=false;
183  break;
184  }
185  }
186  //Add the value to the domain if its new
187  if(newValue){
188  oneDomain.push_back(valueI);
189  }
190  }
191  }//faces on domain loop
192  //Add the one domain we read in to the vector of all the domains
193  domains.push_back(oneDomain);
194  }//domain loop
195 
196  //Close input file
197  Inf.close();
198 
199  // Open the bc input file for reading
200  Inf.open(bc_input_name.c_str());
201  if(!Inf){
202  // If the input file failed to open, notify to
203  // the error stream and return non-zero
204  std::ostringstream ErrOstr;
205  ErrOstr << "Could not open input file, '"
206  << bc_input_name << "'.\n";
207  StdOut(Ostr.str());
208  Ostr.str("");
209  ErrOut(ErrOstr.str());
210  ErrOstr.str("");
211  // don't forget to tell the profiler/stacker the
212  // function is exiting.
213  FunctionExit("ReadStanfordInput");
214  return(1);
215  }
216 
217  domainBCs.resize(domains.size());
218  domainBCValues.resize(domains.size());
219  while(std::getline(Inf,line)){
220  int numFlags=0, domainNum;
221  std::string edgeOrDomain;
222  bool domain = true;
223  ss.clear();
224  ss.str("");
225  ss << line;
226  ss >> edgeOrDomain >> domainNum;
227  //std::cout << "edgeOrDomain = " << edgeOrDomain << std::endl;
228  //std::cout << "domainNum = " << domainNum << std::endl;
229  domainNum--;
230  //bcs for an edge
231  if(edgeOrDomain == "edge" || edgeOrDomain == "Edge"
232  || edgeOrDomain == "EDGE"){
233  domain = false;
234  ss >> valueI;
235  edges[domainNum].push_back(valueI);
236  ss >> valueI;
237  edges[domainNum].push_back(valueI);
238  }
239  //tell the total number of edges with a bc
240  else if(edgeOrDomain == "edges" || edgeOrDomain == "Edges"
241  || edgeOrDomain == "EDGES"){
242  edges.resize(domainNum+1);
243  edgeBCs.resize(domainNum+1);
244  edgeBCValues.resize(domainNum+1);
245  continue;
246  }
247  //bcs for a domain
248  else if(edgeOrDomain != "domain" && edgeOrDomain != "Domain"
249  && edgeOrDomain != "DOMAIN"){
250  std::ostringstream ErrOstr;
251  ErrOstr << "First word of every line in bc file must be 'domain,'"
252  << std::endl << "'edge', or 'edges.'" << std::endl;
253  StdOut(Ostr.str());
254  Ostr.str("");
255  ErrOut(ErrOstr.str());
256  ErrOstr.str("");
257  // don't forget to tell the profiler/stacker the
258  // function is exiting.
259  FunctionExit("ReadStanfordInput");
260  return(1);
261  }
262 
263  ss >> numFlags;
264  //std::cout << "numFlags = " << numFlags << std::endl;
265  if(domain)
266  domainBCValues[domainNum].resize(numFlags);
267  else
268  edgeBCValues[domainNum].resize(numFlags);
269 
270  for(int j=0; j < numFlags; j++){
271  ss >> valueI;
272  //std::cout << "domain type = " << valueI << std::endl;
273  if(domain)
274  domainBCs[domainNum].push_back(valueI);
275  else
276  edgeBCs[domainNum].push_back(valueI);
277 
278  //std::cout << "values = " << std::endl;
279  if(valueI == 8){
280  for(int i=0; i < 7; i++){
281  ss >> valueD;
282  //std::cout << valueD << " ";
283  if(domain)
284  domainBCValues[domainNum][j].push_back(valueD);
285  else
286  edgeBCValues[domainNum][j].push_back(valueD);
287  }
288  }
289  else if(valueI == 6){
290  ss >> valueD;
291  //std::cout << valueD << " ";
292  if(domain)
293  domainBCValues[domainNum][j].push_back(valueD);
294  else
295  edgeBCValues[domainNum][j].push_back(valueD);
296  }
297  else{
298  // Error for invalid bc type
299  std::ostringstream ErrOstr;
300  ErrOstr << "Invalid boundary condition type of " << valueI
301  << " for boundary " << domainBCs.size() << "." << std::endl;
302  StdOut(Ostr.str());
303  Ostr.str("");
304  ErrOut(ErrOstr.str());
305  ErrOstr.str("");
306  // don't forget to tell the profiler/stacker the
307  // function is exiting.
308  FunctionExit("ReadStanfordInput");
309  return(1);
310  }
311  //std::cout << std::endl;
312  }
313  }
314 
315  //Close the bc input file
316  Inf.close();
317 
318  StdOut(Ostr.str());
319  Ostr.str("");
320 
321  FunctionExit("ReadStanfordInput");
322  return 0;
323 
324  } //ReadInput function
325 
326 }; //DriverProgram namespace
327 }; //GridConversion namespace
j indices k indices k
Definition: Indexing.h:6
std::vector< std::vector< unsigned int > > domains
vector of vectors to hold the domains
int numDomains
number of domains in mesh
GridConversion interface.
std::vector< unsigned int > elems
vector for holding element connectivies read from input
int numElems
number of elements in mesh
std::vector< std::vector< int > > edgeBCs
vector to hold list of edge bc flags
C by Argonne National Laboratory and Mississipi State University!All rights reserved See COPYRIGHT in top level directory!user include file for MPI with no dependencies!It really is not possible to make a perfect include file that can!be used by both F77 and F90 but this is close We have removed!continuation lines(allows free form input in F90)
blockLoc i
Definition: read.cpp:79
int numNodesPerElem
number of nodes per element
std::vector< std::vector< int > > domainBCs
vector to hold list of domain bc flags
std::ifstream Inf
Infile stream for input.
virtual int ReadStanfordInput()
This function parses a Stanford format input file.
std::vector< std::vector< int > > edges
vector of vectors to hold the edges
std::vector< std::vector< std::vector< double > > > domainBCValues
vector to hold list of domain bc values (these are different for each bc type - see the Rocfrac docum...
std::vector< std::vector< std::vector< double > > > edgeBCValues
vector to hold list of edge bc values (these are different for each bc type - see the Rocfrac documen...
j indices j
Definition: Indexing.h:6
int elemShape
integer to denote the shape of elements used in the mesh
std::string bc_input_name
Name of bc input file.
std::string input_name
Name of input file.
std::vector< double > nodes
vector for holding nodal coordinates read from input