41 #include <boost/algorithm/string.hpp> 
   42 #include <boost/core/ignore_unused.hpp> 
   51 ModuleKey InputNek5000::m_className[1] = {
 
   54         "Reads Nek5000 field file.")};
 
   85     boost::ignore_unused(vm);
 
   87     ifstream file(
m_config[
"infile"].as<string>().c_str(), ios::binary);
 
   90     vector<char> data(132);
 
   91     file.read(&data[0], 132);
 
   94     string check(&data[0], 4);
 
   95     string header(&data[4], 128);
 
   97     ASSERTL0(check == 
"#std", 
"Unable to read file");
 
  101     bool byteSwap = 
false;
 
  104     file.read((
char *)(&test), 4);
 
  105     if (test > 6.5 && test < 6.6)
 
  113                  "Unable to determine endian-ness of input file");
 
  120     int nBytes, nBlocksXYZ[3], nBlocks, nTotBlocks, dir, nDirs, nCycle, nDim;
 
  125     ss >> nBytes >> nBlocksXYZ[0] >> nBlocksXYZ[1] >> nBlocksXYZ[2] >>
 
  126         nBlocks >> nTotBlocks >> time >> nCycle >> dir >> nDirs >> remain;
 
  129     nDim = nBlocksXYZ[2] == 1 ? 2 : 3;
 
  134         cout << 
"Found header information:" << endl;
 
  135         cout << 
" -- " << (byteSwap ? 
"" : 
"do not ") << 
"need to swap endian" 
  137         cout << 
" -- Data byte size       : " << nBytes << endl;
 
  138         cout << 
" -- Number of xyz blocks : " << nBlocksXYZ[0] << 
"x" 
  139              << nBlocksXYZ[1] << 
"x" << nBlocksXYZ[2] << endl;
 
  140         cout << 
" -- Blocks in file/total : " << nBlocks << 
"/" << nTotBlocks
 
  142         cout << 
" -- Simulation time      : " << time << endl;
 
  143         cout << 
" -- Number of cycles     : " << nCycle << endl;
 
  144         cout << 
" -- Number of dirs       : " << dir << 
"/" << nDirs << endl;
 
  145         cout << 
" -- Remaining header     : " << remain << endl;
 
  149     ASSERTL0(nDirs == 1, 
"Number of directories must be one");
 
  152     ASSERTL0(nBlocks == nTotBlocks, 
"Partial field output not supported");
 
  155     ASSERTL0(nBytes == 8, 
"Data file must contain double-precision data");
 
  161     fielddef->m_numHomogeneousDir = 0;
 
  162     fielddef->m_homoStrips        = 
false;
 
  163     fielddef->m_pointsDef         = 
false;
 
  164     fielddef->m_uniOrder          = 
true;
 
  165     fielddef->m_numPointsDef      = 
false;
 
  167     for (
int i = 0; i < nDim; ++i)
 
  170         fielddef->m_numModes.push_back(nBlocksXYZ[i]);
 
  174     NekUInt32 maxID = 0, minID = numeric_limits<NekUInt32>::max();
 
  178         file.read((
char *)&blockNum, 4);
 
  183         fielddef->m_elementIDs.push_back(blockNum - 1);
 
  185         maxID = maxID > blockNum ? maxID : blockNum;
 
  186         minID = minID < blockNum ? minID : blockNum;
 
  190     size_t blockSize = nBlocksXYZ[0] * nBlocksXYZ[1] * nBlocksXYZ[2];
 
  191     size_t dataSize  = blockSize * nBlocks;
 
  193     for (string::size_type i = 0; i < remain.size(); ++i)
 
  198                 fielddef->m_fields.push_back(
"u");
 
  199                 fielddef->m_fields.push_back(
"v");
 
  202                     fielddef->m_fields.push_back(
"w");
 
  206                 fielddef->m_fields.push_back(
"p");
 
  209                 fielddef->m_fields.push_back(
"T");
 
  214                 fielddef->m_fields.push_back(
string(
"scalar") + remain[i]);
 
  219                 cerr << 
"Field contains unknown variable: " << remain[i]
 
  225     m_f->m_data.resize(1);
 
  226     m_f->m_data[0].resize(fielddef->m_fields.size() * dataSize);
 
  229     for (
size_t i = 0, cnt = 0; i < remain.size(); ++i)
 
  235                 size_t cntVel[3] = {cnt, cnt + dataSize, cnt + 2 * dataSize};
 
  237                 for (
size_t j = 0; j < nBlocks; ++j)
 
  239                     for (
size_t k = 0; k < nDim; ++k)
 
  241                         file.read((
char *)&
m_f->m_data[0][cntVel[k]],
 
  243                         cntVel[k] += blockSize;
 
  247                 cnt += nDim * dataSize;
 
  252                 file.read((
char *)&
m_f->m_data[0][cnt],
 
  261                 file.read((
char *)&
m_f->m_data[0][cnt],
 
  271     m_f->m_fielddef.push_back(fielddef);
 
  274     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 .
The above copyright notice and this permission notice shall be included.