Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
Nektar::FieldUtils::InputDat Class Reference

Input module for Xml files. More...

#include <InputDat.h>

Inheritance diagram for Nektar::FieldUtils::InputDat:
Inheritance graph
[legend]
Collaboration diagram for Nektar::FieldUtils::InputDat:
Collaboration graph
[legend]

Public Member Functions

 InputDat (FieldSharedPtr f)
 Set up InputDat object. More...
 
virtual ~InputDat ()
 
virtual void Process (po::variables_map &vm)
 
virtual std::string GetModuleName ()
 
- Public Member Functions inherited from Nektar::FieldUtils::InputModule
 InputModule (FieldSharedPtr p_m)
 
FIELD_UTILS_EXPORT void AddFile (string fileType, string fileName)
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
FIELD_UTILS_EXPORT void RegisterConfig (string key, string value)
 Register a configuration option with a module. More...
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
FIELD_UTILS_EXPORT bool GetRequireEquiSpaced (void)
 
FIELD_UTILS_EXPORT void SetRequireEquiSpaced (bool pVal)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

static ModuleSharedPtr create (FieldSharedPtr f)
 Creates an instance of this class. More...
 

Static Public Attributes

static ModuleKey m_className []
 ModuleKey for class. More...
 

Private Member Functions

void ReadTecplotFEBlockZone (std::ifstream &datFile, string &line, Array< OneD, Array< OneD, NekDouble > > &pts, vector< Array< OneD, int > > &ptsConn)
 

Additional Inherited Members

- Protected Member Functions inherited from Nektar::FieldUtils::InputModule
void PrintSummary ()
 Print summary of elements. More...
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
- Protected Attributes inherited from Nektar::FieldUtils::InputModule
set< string > m_allowedFiles
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
map< string, ConfigOptionm_config
 List of configuration values. More...
 
bool m_requireEquiSpaced
 

Detailed Description

Input module for Xml files.

Definition at line 47 of file InputDat.h.

Constructor & Destructor Documentation

Nektar::FieldUtils::InputDat::InputDat ( FieldSharedPtr  f)

Set up InputDat object.

Definition at line 63 of file InputDat.cpp.

References Nektar::FieldUtils::InputModule::m_allowedFiles.

63  : InputModule(f)
64 {
65  m_allowedFiles.insert("dat");
66 }
Nektar::FieldUtils::InputDat::~InputDat ( )
virtual

Definition at line 71 of file InputDat.cpp.

72 {
73 }

Member Function Documentation

static ModuleSharedPtr Nektar::FieldUtils::InputDat::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 55 of file InputDat.h.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

56  {
58  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
virtual std::string Nektar::FieldUtils::InputDat::GetModuleName ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 62 of file InputDat.h.

63  {
64  return "InputDat";
65  }
void Nektar::FieldUtils::InputDat::Process ( po::variables_map &  vm)
virtual

Implements Nektar::FieldUtils::Module.

Definition at line 78 of file InputDat.cpp.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::ePtsTriBlock, Nektar::ParseUtils::GenerateOrderedStringVector(), Nektar::FieldUtils::Module::m_f, and ReadTecplotFEBlockZone().

79 {
80 
81  if (m_f->m_verbose)
82  {
83  if (m_f->m_comm->TreatAsRankZero())
84  {
85  cout << "Processing input dat file" << endl;
86  }
87  }
88 
89  string line, word, tag;
90  std::ifstream datFile;
91  stringstream s;
92 
93  // Open the file stream.
94  string fname = m_f->m_inputfiles["dat"][0];
95 
96  datFile.open(fname.c_str());
97  if (!datFile.good())
98  {
99  cerr << "Error opening file: " << fname << endl;
100  abort();
101  }
102 
103  // read variables
104  // currently assum there are x y and z coordinates
105  int dim = 3;
106  vector<string> fieldNames;
107  while (!datFile.eof())
108  {
109  getline(datFile, line);
110  string linetest = line;
111  boost::to_upper(linetest);
112  if (linetest.find("VARIABLES") != string::npos)
113  {
114  std::size_t pos = line.find('=');
115  pos++;
116 
117  // note this expects a comma separated list but
118  // does not work for white space separated lists!
120  line.substr(pos).c_str(), fieldNames);
121  ASSERTL0(valid, "Unable to process list of field variable in "
122  " VARIABLES list: " +
123  line.substr(pos));
124 
125  // remove coordinates from fieldNames
126  fieldNames.erase(fieldNames.begin(), fieldNames.begin() + dim);
127 
128  break;
129  }
130  }
131 
132  // set up basic parameters
133  int nfields = fieldNames.size();
134  int totvars = dim + nfields;
135  Array<OneD, Array<OneD, NekDouble> > pts(totvars);
136  vector<Array<OneD, int> > ptsConn;
137 
138  // read zones
139  while (!datFile.eof())
140  {
141  getline(datFile, line);
142  string linetest = line;
143  boost::to_upper(linetest);
144  if ((linetest.find("ZONE") != string::npos))
145  {
146  ReadTecplotFEBlockZone(datFile, line, pts, ptsConn);
147  }
148  }
149 
150  datFile.close();
151 
153  dim, fieldNames, pts);
154  m_f->m_fieldPts->SetPtsType(LibUtilities::ePtsTriBlock);
155  m_f->m_fieldPts->SetConnectivity(ptsConn);
156 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
static bool GenerateOrderedStringVector(const char *const str, std::vector< std::string > &vec)
Definition: ParseUtils.hpp:143
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
void ReadTecplotFEBlockZone(std::ifstream &datFile, string &line, Array< OneD, Array< OneD, NekDouble > > &pts, vector< Array< OneD, int > > &ptsConn)
Definition: InputDat.cpp:161
FieldSharedPtr m_f
Field object.
void Nektar::FieldUtils::InputDat::ReadTecplotFEBlockZone ( std::ifstream &  datFile,
string &  line,
Array< OneD, Array< OneD, NekDouble > > &  pts,
vector< Array< OneD, int > > &  ptsConn 
)
private

Definition at line 161 of file InputDat.cpp.

References ASSERTL0.

Referenced by Process().

165 {
166  ASSERTL0(line.find("FEBlock") != string::npos,
167  "Routine only set up for FEBLock format");
168  ASSERTL0(line.find("ET") != string::npos, "Routine only set up TRIANLES");
169 
170  // read the number of nodes
171 
172  stringstream s;
173  string tag;
174  int start, end;
175 
176  s.clear();
177  s.str(line);
178  tag = s.str();
179 
180  // read the number of vertices
181  start = tag.find("N=");
182  end = tag.find_first_of(',', start);
183  int nvert = atoi(tag.substr(start + 2, end).c_str());
184 
185  // read the number of elements
186  start = tag.find("E=");
187  end = tag.find_first_of(',', start);
188  int nelmt = atoi(tag.substr(start + 2, end).c_str());
189 
190  // set-up or extend m_pts array;
191  int norigpts = pts[0].num_elements();
192  int totfields = pts.num_elements();
193  Array<OneD, Array<OneD, NekDouble> > origpts(totfields);
194  for (int i = 0; i < totfields; ++i)
195  {
196  origpts[i] = pts[i];
197  pts[i] = Array<OneD, NekDouble>(norigpts + nvert);
198  }
199 
200  NekDouble value;
201  for (int n = 0; n < totfields; ++n)
202  {
203 
204  for (int i = 0; i < norigpts; ++i)
205  {
206  pts[n][i] = origpts[n][i];
207  }
208  for (int i = 0; i < nvert; ++i)
209  {
210  datFile >> value;
211  pts[n][norigpts + i] = value;
212  }
213  }
214 
215  // read connectivity and add to list
216  int intvalue;
217  Array<OneD, int> conn(3 * nelmt);
218  for (int i = 0; i < 3 * nelmt; ++i)
219  {
220  datFile >> intvalue;
221  intvalue -= 1; // decrement intvalue by 1 for c array convention
222  conn[i] = norigpts + intvalue;
223  }
224  ptsConn.push_back(conn);
225 
226  getline(datFile, line);
227 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
double NekDouble

Member Data Documentation

ModuleKey Nektar::FieldUtils::InputDat::m_className
static
Initial value:
= {
"Reads Tecplot dat file for FE block triangular format."),
}

ModuleKey for class.

Definition at line 60 of file InputDat.h.