41#include <boost/algorithm/string.hpp>
53 "Reads Semtex field file.")};
82 string sessionName, date, fields, endian;
83 int nr, ns, nz, nelmt, step;
86 ifstream file(
m_config[
"infile"].as<string>().c_str(), ios::binary);
94 sessionName = string(buf, 25);
95 boost::trim(sessionName);
97 m_f->m_fieldMetaDataMap[
"SessionName0"] = sessionName;
101 date = string(buf, 25);
106 file >> nr >> ns >> nz >> nelmt;
116 m_f->m_fieldMetaDataMap[
"Time"] = boost::lexical_cast<string>(time);
121 m_f->m_fieldMetaDataMap[
"TimeStep"] = boost::lexical_cast<string>(dt);
126 m_f->m_fieldMetaDataMap[
"Kinvis"] = boost::lexical_cast<string>(kinvis);
134 fields = string(buf, 25);
140 std::string endianSearch;
143 endianSearch =
"big";
147 endianSearch =
"little";
151 ASSERTL0(
false,
"Only little- or big-endian systems are supported");
155 endian = string(buf, 25);
156 bool byteSwap = endian.find(endianSearch) == string::npos;
162 cout <<
"Found header information:" << endl;
163 cout <<
" -- From session : " << sessionName << endl;
164 cout <<
" -- File generated : " << date << endl;
165 cout <<
" -- Polynomial order : " << nr - 1 << endl;
166 cout <<
" -- Number of planes : " << nz << endl;
167 cout <<
" -- Number of elements : " << nelmt << endl;
168 cout <<
" -- Simulation time : " << time << endl;
169 cout <<
" -- Timestep : " << dt << endl;
170 cout <<
" -- Viscosity : " << kinvis << endl;
171 cout <<
" -- Fields : " << fields <<
" (" << fields.size()
172 <<
" total)" << endl;
176 cout <<
" -- Homogeneous length : " << 2 * M_PI /
beta << endl;
179 cout <<
" -- " << (byteSwap ?
"" :
"do not ") <<
"need to swap endian"
183 ASSERTL0(nr == ns,
"Semtex reader assumes values of nr and ns are equal");
189 fielddef->m_homoStrips =
false;
190 fielddef->m_pointsDef =
false;
191 fielddef->m_uniOrder =
true;
192 fielddef->m_numPointsDef =
false;
197 fielddef->m_numModes.push_back(nr);
198 fielddef->m_numModes.push_back(nr);
201 fielddef->m_elementIDs.resize(nelmt);
202 for (
int i = 0; i < nelmt; ++i)
204 fielddef->m_elementIDs[i] = i;
210 fielddef->m_numHomogeneousDir = 1;
211 fielddef->m_homogeneousLengths.push_back(2 * M_PI /
beta);
212 fielddef->m_numModes.push_back(nz);
215 for (
int i = 0; i < nz; ++i)
217 fielddef->m_homogeneousZIDs.push_back(i);
222 fielddef->m_numHomogeneousDir = 0;
225 for (string::size_type i = 0; i < fields.size(); ++i)
227 fielddef->m_fields.push_back(
string(&fields[i], 1));
231 size_t elmtSize = nr * ns;
232 size_t planeSize = elmtSize * nelmt;
233 size_t fieldSize = planeSize * nz;
234 size_t dataSize = fieldSize * fields.size();
237 m_f->m_data.resize(1);
238 m_f->m_data[0].resize(dataSize);
241 vector<NekDouble> tmp(planeSize);
242 size_t offset = nz * nr * ns;
246 for (
int i = 0; i < fields.size(); ++i)
249 for (
int j = 0; j < nz; ++j)
251 size_t elSizeJ = j * elmtSize;
252 file.read((
char *)&tmp[0], planeSize *
sizeof(
NekDouble));
260 for (
int k = 0; k < nelmt; ++k)
262 std::copy(x, x + elmtSize, data + k * offset + elSizeJ);
268 m_f->m_fielddef.push_back(fielddef);
271 m_f->m_variables =
m_f->m_fielddef[0]->m_fields;
#define ASSERTL0(condition, msg)
std::set< std::string > m_allowedFiles
List of allowed file formats.
FieldSharedPtr m_f
Field object.
std::map< std::string, ConfigOption > m_config
List of configuration values.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Field > FieldSharedPtr
std::pair< ModuleType, std::string > ModuleKey
void swap_endian(T &u)
Swap endian ordering of the input variable.
ModuleFactory & GetModuleFactory()
EndianType Endianness(void)
std::shared_ptr< FieldDefinitions > FieldDefinitionsSharedPtr
@ beta
Gauss Radau pinned at x=-1,.
@ eGLL_Lagrange
Lagrange for SEM basis .
@ eFourier
Fourier Expansion .