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 
96  if(!fields.empty())
97  {
99  fields.c_str(),m_f->m_fieldPts->m_fields);
100  ASSERTL0(valid,"Unable to process list of field variable in "
101  " FIELDS attribute: "+ fields);
102  }
103 
104  nfields = m_f->m_fieldPts->m_nFields = m_f->m_fieldPts->m_fields.size();
105 
106  int totvars = dim + nfields;
107  m_f->m_fieldPts->m_ptsDim = dim;
108  m_f->m_fieldPts->m_nFields = nfields;
109  m_f->m_fieldPts->m_pts = Array<OneD, Array<OneD, NekDouble> >(totvars);
110 
111  TiXmlNode *pointsBody = points->FirstChild();
112 
113  std::istringstream pointsDataStrm(pointsBody->ToText()->Value());
114 
115  vector<NekDouble> pts;
116  NekDouble in_pts;
117  try
118  {
119  while(!pointsDataStrm.fail())
120  {
121  pointsDataStrm >> in_pts;
122 
123  pts.push_back(in_pts);
124  }
125  }
126  catch(...)
127  {
128  ASSERTL0(false, "Unable to read Points data.");
129  }
130 
131  int npts = pts.size()/totvars;
132 
133  if(m_f->m_verbose)
134  {
135  cout << " Read " << npts << " points of dimension " << dim << " and "
136  << nfields << " field variables" << endl;
137  }
138 
139  for(int i = 0; i < totvars; ++i)
140  {
141  m_f->m_fieldPts->m_pts[i] = Array<OneD, NekDouble>(npts);
142  }
143 
144  for(int i = 0; i < npts; ++i)
145  {
146  for(int j = 0; j < totvars; ++j)
147  {
148  m_f->m_fieldPts->m_pts[j][i] = pts[i*totvars +j];
149  }
150  }
151 }
152 
153 }
154 }