41 #include <boost/core/ignore_unused.hpp> 42 #include <boost/algorithm/string.hpp> 56 "Reads Semtex field file.")
85 boost::ignore_unused(vm);
88 string sessionName, date, fields, endian;
89 int nr, ns, nz, nelmt, step;
92 ifstream file(
m_config[
"infile"].as<string>().c_str(), ios::binary);
100 sessionName = string(buf, 25);
101 boost::trim(sessionName);
103 m_f->m_fieldMetaDataMap[
"SessionName0"] = sessionName;
107 date = string(buf, 25);
112 file >> nr >> ns >> nz >> nelmt;
122 m_f->m_fieldMetaDataMap[
"Time"] = boost::lexical_cast<
string>(time);
127 m_f->m_fieldMetaDataMap[
"TimeStep"] = boost::lexical_cast<
string>(dt);
132 m_f->m_fieldMetaDataMap[
"Kinvis"] = boost::lexical_cast<
string>(kinvis);
140 fields = string(buf, 25);
146 std::string endianSearch;
149 endianSearch =
"big";
153 endianSearch =
"little";
157 ASSERTL0(
false,
"Only little- or big-endian systems are supported");
161 endian = string(buf, 25);
162 bool byteSwap = endian.find(endianSearch) == string::npos;
168 cout <<
"Found header information:" << endl;
169 cout <<
" -- From session : " << sessionName << endl;
170 cout <<
" -- File generated : " << date << endl;
171 cout <<
" -- Polynomial order : " << nr-1 << endl;
172 cout <<
" -- Number of planes : " << nz << endl;
173 cout <<
" -- Number of elements : " << nelmt << endl;
174 cout <<
" -- Simulation time : " << time << endl;
175 cout <<
" -- Timestep : " << dt << endl;
176 cout <<
" -- Viscosity : " << kinvis << endl;
177 cout <<
" -- Fields : " << fields
178 <<
" (" << fields.size() <<
" total)" << endl;
182 cout <<
" -- Homogeneous length : " << 2*M_PI/beta << endl;
185 cout <<
" -- " << (byteSwap ?
"" :
"do not ") <<
"need to swap endian" 189 ASSERTL0(nr == ns,
"Semtex reader assumes values of nr and ns are equal");
195 fielddef->m_homoStrips =
false;
196 fielddef->m_pointsDef =
false;
197 fielddef->m_uniOrder =
true;
198 fielddef->m_numPointsDef =
false;
203 fielddef->m_numModes.push_back(nr);
204 fielddef->m_numModes.push_back(nr);
207 fielddef->m_elementIDs.resize(nelmt);
208 for (
int i = 0; i < nelmt; ++i)
210 fielddef->m_elementIDs[i] = i;
216 fielddef->m_numHomogeneousDir = 1;
217 fielddef->m_homogeneousLengths.push_back(2 * M_PI / beta);
218 fielddef->m_numModes.push_back(nz);
221 for (
int i = 0; i < nz; ++i)
223 fielddef->m_homogeneousZIDs.push_back(i);
228 fielddef->m_numHomogeneousDir = 0;
231 for (string::size_type i = 0; i < fields.size(); ++i)
233 fielddef->m_fields.push_back(
string(&fields[i], 1));
237 size_t elmtSize = nr * ns;
238 size_t planeSize = elmtSize * nelmt;
239 size_t fieldSize = planeSize * nz;
240 size_t dataSize = fieldSize * fields.size();
243 m_f->m_data.resize(1);
244 m_f->m_data[0].resize(dataSize);
247 vector<NekDouble> tmp(planeSize);
248 size_t offset = nz * nr * ns;
252 for (
int i = 0; i < fields.size(); ++i)
255 for (
int j = 0; j < nz; ++j)
257 size_t elSizeJ = j * elmtSize;
258 file.read((
char *)&tmp[0], planeSize *
sizeof(
NekDouble));
266 for (
int k = 0; k < nelmt; ++k)
268 std::copy(x, x + elmtSize, data + k * offset + elSizeJ);
275 m_f->m_fielddef.push_back(fielddef);
278 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
EndianType Endianness(void)
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.