Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | 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 ()
 
- 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
 
void Process (po::variables_map &vm)
 
std::string GetModuleName ()
 
std::string GetModuleDescription ()
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
ModulePriority GetModulePriority ()
 
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...
 

Protected Member Functions

virtual void v_Process (po::variables_map &vm) override
 
virtual std::string v_GetModuleName () override
 
virtual std::string v_GetModuleDescription () override
 
virtual ModulePriority v_GetModulePriority () override
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 

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 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 63 of file InputDat.cpp.

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

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

◆ ~InputDat()

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

Definition at line 71 of file InputDat.cpp.

72 {
73 }

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 52 of file InputDat.h.

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

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

◆ 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 156 of file InputDat.cpp.

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

References ASSERTL0.

Referenced by v_Process().

◆ v_GetModuleDescription()

virtual std::string Nektar::FieldUtils::InputDat::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 67 of file InputDat.h.

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

◆ v_GetModuleName()

virtual std::string Nektar::FieldUtils::InputDat::v_GetModuleName ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 62 of file InputDat.h.

63  {
64  return "InputDat";
65  }

◆ v_GetModulePriority()

virtual ModulePriority Nektar::FieldUtils::InputDat::v_GetModulePriority ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 72 of file InputDat.h.

73  {
74  return eCreatePts;
75  }

References Nektar::FieldUtils::eCreatePts.

◆ v_Process()

void Nektar::FieldUtils::InputDat::v_Process ( po::variables_map &  vm)
overrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 78 of file InputDat.cpp.

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

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

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:52
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49

ModuleKey for class.

Definition at line 57 of file InputDat.h.