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...
 
 ~InputDat () override
 
- 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 ()
 
std::vector< ModuleKeyGetModulePrerequisites ()
 
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

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

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 44 of file InputDat.h.

Constructor & Destructor Documentation

◆ InputDat()

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

Set up InputDat object.

Definition at line 59 of file InputDat.cpp.

59 : InputModule(f)
60{
61 m_allowedFiles.insert("dat");
62}
InputModule(FieldSharedPtr p_m)
Definition: Module.cpp:61
std::set< std::string > m_allowedFiles
List of allowed file formats.
Definition: Module.h:274

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

◆ ~InputDat()

Nektar::FieldUtils::InputDat::~InputDat ( )
override

Definition at line 67 of file InputDat.cpp.

68{
69}

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 50 of file InputDat.h.

51 {
53 }
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 150 of file InputDat.cpp.

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

References ASSERTL0.

Referenced by v_Process().

◆ v_GetModuleDescription()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 65 of file InputDat.h.

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

◆ v_GetModuleName()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 60 of file InputDat.h.

61 {
62 return "InputDat";
63 }

◆ v_GetModulePriority()

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

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 70 of file InputDat.h.

71 {
72 return eCreatePts;
73 }

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

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

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

ModuleKey for class.

Definition at line 55 of file InputDat.h.