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