Nektar++
Public Member Functions | List of all members
Nektar::LibUtilities::PtsIO Class Reference

#include <PtsIO.h>

Public Member Functions

 PtsIO ()
 
void Import (const string &inFile, LibUtilities::PtsFieldSharedPtr &ptsField)
 Import a pts field from file. More...
 
void Write (const string &outFile, const LibUtilities::PtsFieldSharedPtr &ptsField)
 Save a pts field to a file. More...
 

Detailed Description

Definition at line 64 of file PtsIO.h.

Constructor & Destructor Documentation

Nektar::LibUtilities::PtsIO::PtsIO ( )
inline

Definition at line 68 of file PtsIO.h.

69  {
70  };

Member Function Documentation

void Nektar::LibUtilities::PtsIO::Import ( const string &  inFile,
LibUtilities::PtsFieldSharedPtr ptsField 
)

Import a pts field from file.

Parameters
inFilefilename of the file to read
ptsFieldthe resulting pts field.

Definition at line 64 of file PtsIO.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::ParseUtils::GenerateOrderedStringVector(), and npts.

Referenced by Nektar::LibUtilities::Import().

65 {
66  TiXmlDocument docInput;
67  ASSERTL0(docInput.LoadFile(inFile), "Unable to open file '" + inFile + "'.");
68 
69  TiXmlElement *nektar = docInput.FirstChildElement("NEKTAR");
70  TiXmlElement *points = nektar->FirstChildElement("POINTS");
71  int dim;
72  int err = points->QueryIntAttribute("DIM", &dim);
73 
74  ASSERTL0(err == TIXML_SUCCESS, "Unable to read attribute DIM.");
75 
76  std::string fields = points->Attribute("FIELDS");
77 
78  vector<string> fieldNames;
79  if (!fields.empty())
80  {
82  fields.c_str(), fieldNames);
83  ASSERTL0(valid,
84  "Unable to process list of field variable in FIELDS attribute: " + fields);
85  }
86 
87  int nfields = fieldNames.size();
88  int totvars = dim + nfields;
89 
90  TiXmlNode *pointsBody = points->FirstChild();
91 
92  std::istringstream pointsDataStrm(pointsBody->ToText()->Value());
93 
94  vector<NekDouble> ptsSerial;
95  Array<OneD, Array<OneD, NekDouble> > pts(totvars);
96 
97  try
98  {
99  NekDouble ptsStream;
100  while (!pointsDataStrm.fail())
101  {
102  pointsDataStrm >> ptsStream;
103 
104  ptsSerial.push_back(ptsStream);
105  }
106  }
107  catch (...)
108  {
109  ASSERTL0(false, "Unable to read Points data.");
110  }
111 
112  int npts = ptsSerial.size() / totvars;
113 
114  for (int i = 0; i < totvars; ++i)
115  {
116  pts[i] = Array<OneD, NekDouble>(npts);
117  }
118 
119  for (int i = 0; i < npts; ++i)
120  {
121  for (int j = 0; j < totvars; ++j)
122  {
123  pts[j][i] = ptsSerial[i * totvars + j];
124  }
125  }
126 
127  ptsField = MemoryManager<PtsField>::AllocateSharedPtr(dim, fieldNames, pts);
128 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
static bool GenerateOrderedStringVector(const char *const str, std::vector< std::string > &vec)
Definition: ParseUtils.hpp:142
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
static std::string npts
Definition: InputFld.cpp:43
double NekDouble
void Nektar::LibUtilities::PtsIO::Write ( const string &  outFile,
const LibUtilities::PtsFieldSharedPtr ptsField 
)

Save a pts field to a file.

Parameters
inFilefilename of the file
ptsFieldthe pts field

Definition at line 137 of file PtsIO.cpp.

References ASSERTL0.

Referenced by Nektar::LibUtilities::Write().

138 {
139 
140  ASSERTL0(false, "Not implemented yet");
141 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161