41#include <boost/algorithm/string.hpp>
51 "Reads Nek5000 field file.")};
82 ifstream file(
m_config[
"infile"].as<string>().c_str(), ios::binary);
85 vector<char> data(132);
86 file.read(&data[0], 132);
89 string check(&data[0], 4);
90 string header(&data[4], 128);
92 ASSERTL0(check ==
"#std",
"Unable to read file");
96 bool byteSwap =
false;
99 file.read((
char *)(&
test), 4);
108 "Unable to determine endian-ness of input file");
115 int nBytes, nBlocksXYZ[3], nBlocks, nTotBlocks, dir, nDirs, nCycle, nDim;
120 ss >> nBytes >> nBlocksXYZ[0] >> nBlocksXYZ[1] >> nBlocksXYZ[2] >>
121 nBlocks >> nTotBlocks >> time >> nCycle >> dir >> nDirs >> remain;
124 nDim = nBlocksXYZ[2] == 1 ? 2 : 3;
129 cout <<
"Found header information:" << endl;
130 cout <<
" -- " << (byteSwap ?
"" :
"do not ") <<
"need to swap endian"
132 cout <<
" -- Data byte size : " << nBytes << endl;
133 cout <<
" -- Number of xyz blocks : " << nBlocksXYZ[0] <<
"x"
134 << nBlocksXYZ[1] <<
"x" << nBlocksXYZ[2] << endl;
135 cout <<
" -- Blocks in file/total : " << nBlocks <<
"/" << nTotBlocks
137 cout <<
" -- Simulation time : " << time << endl;
138 cout <<
" -- Number of cycles : " << nCycle << endl;
139 cout <<
" -- Number of dirs : " << dir <<
"/" << nDirs << endl;
140 cout <<
" -- Remaining header : " << remain << endl;
144 ASSERTL0(nDirs == 1,
"Number of directories must be one");
147 ASSERTL0(nBlocks == nTotBlocks,
"Partial field output not supported");
150 ASSERTL0(nBytes == 8,
"Data file must contain double-precision data");
156 fielddef->m_numHomogeneousDir = 0;
157 fielddef->m_homoStrips =
false;
158 fielddef->m_pointsDef =
false;
159 fielddef->m_uniOrder =
true;
160 fielddef->m_numPointsDef =
false;
162 for (
int i = 0; i < nDim; ++i)
165 fielddef->m_numModes.push_back(nBlocksXYZ[i]);
169 NekUInt32 maxID = 0, minID = numeric_limits<NekUInt32>::max();
173 file.read((
char *)&blockNum, 4);
178 fielddef->m_elementIDs.push_back(blockNum - 1);
180 maxID = maxID > blockNum ? maxID : blockNum;
181 minID = minID < blockNum ? minID : blockNum;
185 size_t blockSize = nBlocksXYZ[0] * nBlocksXYZ[1] * nBlocksXYZ[2];
186 size_t dataSize = blockSize * nBlocks;
188 for (string::size_type i = 0; i < remain.size(); ++i)
193 fielddef->m_fields.push_back(
"u");
194 fielddef->m_fields.push_back(
"v");
197 fielddef->m_fields.push_back(
"w");
201 fielddef->m_fields.push_back(
"p");
204 fielddef->m_fields.push_back(
"T");
209 fielddef->m_fields.push_back(
string(
"scalar") + remain[i]);
214 cerr <<
"Field contains unknown variable: " << remain[i]
220 m_f->m_data.resize(1);
221 m_f->m_data[0].resize(fielddef->m_fields.size() * dataSize);
224 for (
size_t i = 0, cnt = 0; i < remain.size(); ++i)
230 size_t cntVel[3] = {cnt, cnt + dataSize, cnt + 2 * dataSize};
232 for (
size_t j = 0; j < nBlocks; ++j)
234 for (
size_t k = 0; k < nDim; ++k)
236 file.read((
char *)&
m_f->m_data[0][cntVel[k]],
238 cntVel[k] += blockSize;
242 cnt += nDim * dataSize;
247 file.read((
char *)&
m_f->m_data[0][cnt],
256 file.read((
char *)&
m_f->m_data[0][cnt],
266 m_f->m_fielddef.push_back(fielddef);
269 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()
std::shared_ptr< FieldDefinitions > FieldDefinitionsSharedPtr
@ eGLL_Lagrange
Lagrange for SEM basis .