Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InputPts.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: InputPts.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 xml file of a series of points and hold
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include <tinyxml.h>
41 
42 #include "InputPts.h"
43 
44 namespace Nektar
45 {
46 namespace Utilities
47 {
48 
49 ModuleKey InputPts::m_className[5] = {
51  ModuleKey(eInputModule, "pts"), InputPts::create, "Reads Pts file."),
53  ModuleKey(eInputModule, "pts.gz"), InputPts::create, "Reads Pts file."),
54 };
55 
56 /**
57  * @brief Set up InputPts object.
58  *
59  */
60 InputPts::InputPts(FieldSharedPtr f) : InputModule(f)
61 {
62  m_allowedFiles.insert("pts");
64 }
65 
67 {
68 }
69 
70 /**
71  *
72  */
73 void InputPts::Process(po::variables_map &vm)
74 {
75  if(m_f->m_verbose)
76  {
77  cout << "Processing input pts file" << endl;
78  }
79 
80  string pts_ending = "pts";
81 
82  TiXmlDocument docInput;
83  ASSERTL0(!docInput.LoadFile((m_f->m_inputfiles["pts"][0]).c_str()),
84  "Unable to open file '" + m_f->m_inputfiles["pts"][0] + "'.");
85 
86  TiXmlElement *nektar = docInput.FirstChildElement("NEKTAR");
87  TiXmlElement *points = nektar->FirstChildElement("POINTS");
88  int dim;
89  int err = points->QueryIntAttribute("DIM", &dim);
90 
91  ASSERTL0(err == TIXML_SUCCESS, "Unable to read attribute DIM.");
92 
93  int nfields;
94  std::string fields = points->Attribute("FIELDS");
95 
97  fields.c_str(),m_f->m_fieldPts->m_fields);
98  ASSERTL0(valid,"Unable to process list of field variable in "
99  " FIELDS attribute: "+ fields);
100 
101  nfields = m_f->m_fieldPts->m_nFields = m_f->m_fieldPts->m_fields.size();
102 
103  int totvars = dim + nfields;
104  m_f->m_fieldPts->m_ptsDim = dim;
105  m_f->m_fieldPts->m_nFields = nfields;
106  m_f->m_fieldPts->m_pts = Array<OneD, Array<OneD, NekDouble> >(totvars);
107 
108  TiXmlNode *pointsBody = points->FirstChild();
109 
110  std::istringstream pointsDataStrm(pointsBody->ToText()->Value());
111 
112  vector<NekDouble> pts;
113  NekDouble in_pts;
114  try
115  {
116  while(!pointsDataStrm.fail())
117  {
118  pointsDataStrm >> in_pts;
119 
120  pts.push_back(in_pts);
121  }
122  }
123  catch(...)
124  {
125  ASSERTL0(false, "Unable to read Points data.");
126  }
127 
128  int npts = pts.size()/totvars;
129 
130  if(m_f->m_verbose)
131  {
132  cout << " Read " << npts << " points of dimension " << dim << " and "
133  << nfields << " field variables" << endl;
134  }
135 
136  for(int i = 0; i < totvars; ++i)
137  {
138  m_f->m_fieldPts->m_pts[i] = Array<OneD, NekDouble>(npts);
139  }
140 
141  for(int i = 0; i < npts; ++i)
142  {
143  for(int j = 0; j < totvars; ++j)
144  {
145  m_f->m_fieldPts->m_pts[j][i] = pts[i*totvars +j];
146  }
147  }
148 }
149 
150 }
151 }