41 #include <boost/algorithm/string.hpp> 
   42 #include <boost/core/ignore_unused.hpp> 
   56         "Reads Semtex field file.")};
 
   84     boost::ignore_unused(vm);
 
   87     string sessionName, date, fields, endian;
 
   88     int nr, ns, nz, nelmt, step;
 
   91     ifstream file(
m_config[
"infile"].as<string>().c_str(), ios::binary);
 
   99     sessionName = string(buf, 25);
 
  100     boost::trim(sessionName);
 
  102     m_f->m_fieldMetaDataMap[
"SessionName0"] = sessionName;
 
  106     date = string(buf, 25);
 
  111     file >> nr >> ns >> nz >> nelmt;
 
  121     m_f->m_fieldMetaDataMap[
"Time"] = boost::lexical_cast<string>(time);
 
  126     m_f->m_fieldMetaDataMap[
"TimeStep"] = boost::lexical_cast<string>(dt);
 
  131     m_f->m_fieldMetaDataMap[
"Kinvis"] = boost::lexical_cast<string>(kinvis);
 
  139     fields = string(buf, 25);
 
  145     std::string endianSearch;
 
  148         endianSearch = 
"big";
 
  152         endianSearch = 
"little";
 
  156         ASSERTL0(
false, 
"Only little- or big-endian systems are supported");
 
  160     endian        = string(buf, 25);
 
  161     bool byteSwap = endian.find(endianSearch) == string::npos;
 
  167         cout << 
"Found header information:" << endl;
 
  168         cout << 
" -- From session         : " << sessionName << endl;
 
  169         cout << 
" -- File generated       : " << date << endl;
 
  170         cout << 
" -- Polynomial order     : " << nr - 1 << endl;
 
  171         cout << 
" -- Number of planes     : " << nz << endl;
 
  172         cout << 
" -- Number of elements   : " << nelmt << endl;
 
  173         cout << 
" -- Simulation time      : " << time << endl;
 
  174         cout << 
" -- Timestep             : " << dt << endl;
 
  175         cout << 
" -- Viscosity            : " << kinvis << endl;
 
  176         cout << 
" -- Fields               : " << fields << 
" (" << fields.size()
 
  177              << 
" total)" << endl;
 
  181             cout << 
" -- Homogeneous length   : " << 2 * M_PI / 
beta << endl;
 
  184         cout << 
" -- " << (byteSwap ? 
"" : 
"do not ") << 
"need to swap endian" 
  188     ASSERTL0(nr == ns, 
"Semtex reader assumes values of nr and ns are equal");
 
  194     fielddef->m_homoStrips   = 
false;
 
  195     fielddef->m_pointsDef    = 
false;
 
  196     fielddef->m_uniOrder     = 
true;
 
  197     fielddef->m_numPointsDef = 
false;
 
  202     fielddef->m_numModes.push_back(nr);
 
  203     fielddef->m_numModes.push_back(nr);
 
  206     fielddef->m_elementIDs.resize(nelmt);
 
  207     for (
int i = 0; i < nelmt; ++i)
 
  209         fielddef->m_elementIDs[i] = i;
 
  215         fielddef->m_numHomogeneousDir = 1;
 
  216         fielddef->m_homogeneousLengths.push_back(2 * M_PI / 
beta);
 
  217         fielddef->m_numModes.push_back(nz);
 
  220         for (
int i = 0; i < nz; ++i)
 
  222             fielddef->m_homogeneousZIDs.push_back(i);
 
  227         fielddef->m_numHomogeneousDir = 0;
 
  230     for (string::size_type i = 0; i < fields.size(); ++i)
 
  232         fielddef->m_fields.push_back(
string(&fields[i], 1));
 
  236     size_t elmtSize  = nr * ns;
 
  237     size_t planeSize = elmtSize * nelmt;
 
  238     size_t fieldSize = planeSize * nz;
 
  239     size_t dataSize  = fieldSize * fields.size();
 
  242     m_f->m_data.resize(1);
 
  243     m_f->m_data[0].resize(dataSize);
 
  246     vector<NekDouble> tmp(planeSize);
 
  247     size_t offset = nz * nr * ns;
 
  251     for (
int i = 0; i < fields.size(); ++i)
 
  254         for (
int j = 0; j < nz; ++j)
 
  256             size_t elSizeJ = j * elmtSize;
 
  257             file.read((
char *)&tmp[0], planeSize * 
sizeof(
NekDouble));
 
  265             for (
int k = 0; k < nelmt; ++k)
 
  267                 std::copy(x, x + elmtSize, data + k * offset + elSizeJ);
 
  273     m_f->m_fielddef.push_back(fielddef);
 
  276     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 .
The above copyright notice and this permission notice shall be included.