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