41 #include <boost/core/ignore_unused.hpp> 42 #include <boost/algorithm/string.hpp> 51 ModuleKey InputNek5000::m_className[1] = {
54 "Reads Nek5000 field file.")
86 boost::ignore_unused(vm);
88 ifstream file(
m_config[
"infile"].as<string>().c_str(), ios::binary);
91 vector<char> data(132);
92 file.read(&data[0], 132);
95 string check(&data[0], 4);
96 string header(&data[4], 128);
98 ASSERTL0(check ==
"#std",
"Unable to read file");
102 bool byteSwap =
false;
105 file.read((
char *)(&test), 4);
106 if (test > 6.5 && test < 6.6)
114 "Unable to determine endian-ness of input file");
121 int nBytes, nBlocksXYZ[3], nBlocks, nTotBlocks, dir, nDirs, nCycle, nDim;
126 ss >> nBytes >> nBlocksXYZ[0] >> nBlocksXYZ[1] >> nBlocksXYZ[2]
127 >> nBlocks >> nTotBlocks >> time >> nCycle >> dir >> nDirs >> remain;
130 nDim = nBlocksXYZ[2] == 1 ? 2 : 3;
135 cout <<
"Found header information:" << endl;
136 cout <<
" -- " << (byteSwap ?
"" :
"do not ") <<
"need to swap endian" 138 cout <<
" -- Data byte size : " << nBytes << endl;
139 cout <<
" -- Number of xyz blocks : " << nBlocksXYZ[0] <<
"x" 140 << nBlocksXYZ[1] <<
"x" << nBlocksXYZ[2] << endl;
141 cout <<
" -- Blocks in file/total : " << nBlocks <<
"/" << nTotBlocks
143 cout <<
" -- Simulation time : " << time << endl;
144 cout <<
" -- Number of cycles : " << nCycle << endl;
145 cout <<
" -- Number of dirs : " << dir <<
"/" << nDirs << endl;
146 cout <<
" -- Remaining header : " << remain << endl;
150 ASSERTL0(nDirs == 1,
"Number of directories must be one");
153 ASSERTL0(nBlocks == nTotBlocks,
"Partial field output not supported");
156 ASSERTL0(nBytes == 8,
"Data file must contain double-precision data");
162 fielddef->m_numHomogeneousDir = 0;
163 fielddef->m_homoStrips =
false;
164 fielddef->m_pointsDef =
false;
165 fielddef->m_uniOrder =
true;
166 fielddef->m_numPointsDef =
false;
168 for (
int i = 0; i < nDim; ++i)
171 fielddef->m_numModes.push_back(nBlocksXYZ[i]);
175 NekUInt32 maxID = 0, minID = numeric_limits<NekUInt32>::max();
179 file.read((
char *)&blockNum, 4);
184 fielddef->m_elementIDs.push_back(blockNum-1);
186 maxID = maxID > blockNum ? maxID : blockNum;
187 minID = minID < blockNum ? minID : blockNum;
191 size_t blockSize = nBlocksXYZ[0] * nBlocksXYZ[1] * nBlocksXYZ[2];
192 size_t dataSize = blockSize * nBlocks;
194 for (string::size_type i = 0; i < remain.size(); ++i)
199 fielddef->m_fields.push_back(
"u");
200 fielddef->m_fields.push_back(
"v");
203 fielddef->m_fields.push_back(
"w");
207 fielddef->m_fields.push_back(
"p");
210 fielddef->m_fields.push_back(
"T");
215 fielddef->m_fields.push_back(
string(
"scalar") + remain[i]);
220 cerr <<
"Field contains unknown variable: " 221 << remain[i] << endl;
226 m_f->m_data.resize(1);
227 m_f->m_data[0].resize(fielddef->m_fields.size() * dataSize);
230 for (
size_t i = 0, cnt = 0; i < remain.size(); ++i)
237 cnt, cnt + dataSize, cnt + 2*dataSize
240 for (
size_t j = 0; j < nBlocks; ++j)
242 for (
size_t k = 0; k < nDim; ++k)
245 (
char *)&
m_f->m_data[0][cntVel[k]],
247 cntVel[k] += blockSize;
251 cnt += nDim * dataSize;
257 (
char *)&
m_f->m_data[0][cnt],
267 (
char *)&
m_f->m_data[0][cnt],
277 m_f->m_fielddef.push_back(fielddef);
280 m_f->m_variables =
m_f->m_fielddef[0]->m_fields;
void swap_endian(T &u)
Swap endian ordering of the input variable.
#define ASSERTL0(condition, msg)
std::map< std::string, ConfigOption > m_config
List of configuration values.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::shared_ptr< Field > FieldSharedPtr
Metadata that describes the storage properties of field output.
std::pair< ModuleType, std::string > ModuleKey
std::shared_ptr< FieldDefinitions > FieldDefinitionsSharedPtr
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.