Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InputDat.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: InputDat.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Read tecplot dat for isontours in 2D triangular FE block format
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include <tinyxml.h>
41 
42 #include "InputDat.h"
43 
44 namespace Nektar
45 {
46  namespace Utilities
47  {
48 
49  ModuleKey InputDat::m_className[1] = {
51  ModuleKey(eInputModule, "dat"),
52  InputDat::create,
53  "Reads Tecplot dat file for FE block triangular format."),
54  };
55 
56  /**
57  * @brief Set up InputDat object.
58  *
59  */
60  InputDat::InputDat(FieldSharedPtr f) : InputModule(f)
61  {
62  m_allowedFiles.insert("dat");
64  }
65 
67  {
68  }
69 
70  /**
71  *
72  */
73  void InputDat::Process(po::variables_map &vm)
74  {
75 
76  if(m_f->m_verbose)
77  {
78  cout << "Processing input dat file" << endl;
79  }
80 
81  string line, word, tag;
82  std::ifstream datFile;
83  stringstream s;
84 
85  // Open the file stream.
86  string fname = m_f->m_inputfiles["dat"][0];
87 
88 
89  datFile.open(fname.c_str());
90  if (!datFile.good())
91  {
92  cerr << "Error opening file: " << fname << endl;
93  abort();
94  }
95 
96  // read variables
97  while (!datFile.eof())
98  {
99  getline(datFile, line);
100 
101  if(line.find("VARIABLES") != string::npos)
102  {
103  vector<string> variables;
104  std::size_t pos = line.find('=');
105  pos++;
106 
107  // note this expects a comma separated list but
108  // does not work for white space separated lists!
110  line.substr(pos).c_str(), variables);
111  ASSERTL0(valid,"Unable to process list of field variable in "
112  " VARIABLES list: "+ line.substr(pos));
113 
114 
115  // currently assum there are x y and z coordinates
116  for(int i = 3; i < variables.size(); ++i)
117  {
118  m_f->m_fieldPts->m_fields.push_back(variables[i]);
119  }
120 
121  break;
122  }
123  }
124 
125  // set up basic parameters
126  m_f->m_fieldPts->m_ptsDim = 3;
127  m_f->m_fieldPts->m_nFields = m_f->m_fieldPts->m_fields.size();
128  m_f->m_fieldPts->m_pts = Array<OneD, Array<OneD, NekDouble> > (
129  m_f->m_fieldPts->m_nFields +
130  m_f->m_fieldPts->m_ptsDim);
131  m_f->m_fieldPts->m_ptype = ePtsTriBlock;
132 
133  // read zones
134  while (!datFile.eof())
135  {
136  getline(datFile, line);
137 
138  if((line.find("ZONE") != string::npos)||
139  (line.find("Zone") != string::npos)||
140  (line.find("zone") != string::npos))
141  {
142  ReadTecplotFEBlockZone(datFile,line);
143  }
144  }
145 
146  datFile.close();
147  }
148 
150  std::ifstream &datFile,
151  string &line)
152  {
153 
154  ASSERTL0(line.find("FEBlock") != string::npos,
155  "Routine only set up for FEBLock format");
156  ASSERTL0(line.find("ET") != string::npos,
157  "Routine only set up TRIANLES");
158 
159  // read the number of nodes
160 
161  stringstream s;
162  string tag;
163  int start,end;
164 
165  s.clear();
166  s.str(line);
167  tag = s.str();
168 
169  // read the number of vertices
170  start = tag.find("N=");
171  end = tag.find_first_of(',',start);
172  int nvert = atoi(tag.substr(start+2,end).c_str());
173 
174  // read the number of elements
175  start = tag.find("E=");
176  end = tag.find_first_of(',',start);
177  int nelmt = atoi(tag.substr(start+2,end).c_str());
178 
179 
180  // set-up or extend m_pts array;
181  int norigpts = m_f->m_fieldPts->m_pts[0].num_elements();
182  int totfields = m_f->m_fieldPts->m_pts.num_elements();
183  Array<OneD, Array<OneD, NekDouble> > origpts(totfields);
184  for(int i = 0; i < totfields; ++i)
185  {
186  origpts[i] = m_f->m_fieldPts->m_pts[i];
187  m_f->m_fieldPts->m_pts[i] =
188  Array<OneD, NekDouble>(norigpts + nvert);
189  }
190 
191  NekDouble value;
192  for(int n = 0; n < totfields; ++n)
193  {
194 
195  for(int i = 0; i < norigpts; ++i)
196  {
197  m_f->m_fieldPts->m_pts[n][i] = origpts[n][i];
198  }
199  for(int i = 0; i < nvert; ++i)
200  {
201  datFile >> value;
202  m_f->m_fieldPts->m_pts[n][norigpts+i] = value;
203  }
204  }
205 
206  // read connectivity and add to list
207  int intvalue;
208  Array<OneD, int> conn(3*nelmt);
209  for(int i = 0; i < 3*nelmt; ++i)
210  {
211  datFile >> intvalue;
212  intvalue -=1; // decrement intvalue by 1 for c array convention
213  conn[i] = norigpts + intvalue;
214  }
215  m_f->m_fieldPts->m_ptsConn.push_back(conn);
216 
217  getline(datFile, line);
218  }
219  }
220 }
221