Nektar++
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:
[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 ()
 
virtual std::string GetModuleDescription ()
 
virtual ModulePriority GetModulePriority ()
 
- Public Member Functions inherited from Nektar::FieldUtils::InputModule
 InputModule (FieldSharedPtr p_m)
 
void PrintSummary ()
 Print a brief summary of information. More...
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
virtual ~Module ()=default
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::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 void AddFile (std::string fileType, std::string fileName)
 
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 Member Functions inherited from Nektar::FieldUtils::InputModule
static FIELD_UTILS_EXPORT std::string GuessFormat (std::string fileName)
 Tries to guess the format of the input file. More...
 

Static Public Attributes

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

Private Member Functions

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

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 
std::set< std::string > m_allowedFiles
 List of allowed file formats. More...
 

Detailed Description

Input module for Xml files.

Definition at line 46 of file InputDat.h.

Constructor & Destructor Documentation

◆ InputDat()

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

Set up InputDat object.

Definition at line 65 of file InputDat.cpp.

65  : InputModule(f)
66 {
67  m_allowedFiles.insert("dat");
68 }
InputModule(FieldSharedPtr p_m)
Definition: Module.cpp:63
std::set< std::string > m_allowedFiles
List of allowed file formats.
Definition: Module.h:238

References Nektar::FieldUtils::Module::m_allowedFiles.

◆ ~InputDat()

Nektar::FieldUtils::InputDat::~InputDat ( )
virtual

Definition at line 73 of file InputDat.cpp.

74 {
75 }

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 54 of file InputDat.h.

55  {
57  }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

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

◆ GetModuleDescription()

virtual std::string Nektar::FieldUtils::InputDat::GetModuleDescription ( )
inlinevirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 66 of file InputDat.h.

67  {
68  return "Processing input dat file";
69  }

◆ GetModuleName()

virtual std::string Nektar::FieldUtils::InputDat::GetModuleName ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 61 of file InputDat.h.

62  {
63  return "InputDat";
64  }

◆ GetModulePriority()

virtual ModulePriority Nektar::FieldUtils::InputDat::GetModulePriority ( )
inlinevirtual

Implements Nektar::FieldUtils::Module.

Definition at line 71 of file InputDat.h.

72  {
73  return eCreatePts;
74  }

References Nektar::FieldUtils::eCreatePts.

◆ Process()

void Nektar::FieldUtils::InputDat::Process ( po::variables_map &  vm)
virtual

Implements Nektar::FieldUtils::Module.

Definition at line 80 of file InputDat.cpp.

81 {
82  boost::ignore_unused(vm);
83 
84  string line;
85  std::ifstream datFile;
86 
87  // Open the file stream.
88  string fname = m_f->m_inputfiles["dat"][0];
89 
90  datFile.open(fname.c_str());
91  if (!datFile.good())
92  {
93  cerr << "Error opening file: " << fname << endl;
94  abort();
95  }
96 
97  // read variables
98  // currently assume there are x y and z coordinates
99  int dim = 3;
100  vector<string> fieldNames;
101  while (!datFile.eof())
102  {
103  getline(datFile, line);
104  string linetest = line;
105  boost::to_upper(linetest);
106  if (linetest.find("VARIABLES") != string::npos)
107  {
108  std::size_t pos = line.find('=');
109  pos++;
110 
111  // note this expects a comma separated list but
112  // does not work for white space separated lists!
113  bool valid = ParseUtils::GenerateVector(
114  line.substr(pos), fieldNames);
115  ASSERTL0(valid, "Unable to process list of field variable in "
116  " VARIABLES list: " +
117  line.substr(pos));
118 
119  // remove coordinates from fieldNames
120  fieldNames.erase(fieldNames.begin(), fieldNames.begin() + dim);
121 
122  break;
123  }
124  }
125 
126  // set up basic parameters
127  int nfields = fieldNames.size();
128  int totvars = dim + nfields;
129  Array<OneD, Array<OneD, NekDouble> > pts(totvars);
130  vector<Array<OneD, int> > ptsConn;
131 
132  // read zones
133  while (!datFile.eof())
134  {
135  getline(datFile, line);
136  string linetest = line;
137  boost::to_upper(linetest);
138  if ((linetest.find("ZONE") != string::npos))
139  {
140  ReadTecplotFEBlockZone(datFile, line, pts, ptsConn);
141  }
142  }
143 
144  datFile.close();
145 
147  dim, fieldNames, pts);
148  m_f->m_fieldPts->SetPtsType(LibUtilities::ePtsTriBlock);
149  m_f->m_fieldPts->SetConnectivity(ptsConn);
150 
151  // save field names
152  m_f->m_variables = fieldNames;
153 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
void ReadTecplotFEBlockZone(std::ifstream &datFile, std::string &line, Array< OneD, Array< OneD, NekDouble > > &pts, std::vector< Array< OneD, int > > &ptsConn)
Definition: InputDat.cpp:158
FieldSharedPtr m_f
Field object.
Definition: Module.h:230
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
Definition: ParseUtils.cpp:135

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

◆ ReadTecplotFEBlockZone()

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

Definition at line 158 of file InputDat.cpp.

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

References ASSERTL0.

Referenced by Process().

Member Data Documentation

◆ m_className

ModuleKey Nektar::FieldUtils::InputDat::m_className
static
Initial value:
= {
"Reads Tecplot dat file for FE block triangular format.")
}
static ModuleSharedPtr create(FieldSharedPtr f)
Creates an instance of this class.
Definition: InputDat.h:54
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:200
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:290
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49

ModuleKey for class.

Definition at line 59 of file InputDat.h.