Nektar++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
Nektar::FieldUtils::InputSemtex Class Reference

#include <InputSemtex.h>

Inheritance diagram for Nektar::FieldUtils::InputSemtex:
[legend]

Public Member Functions

 InputSemtex (FieldSharedPtr f)
 Set up InputSemtex object. More...
 
 ~InputSemtex () override
 
- Public Member Functions inherited from Nektar::FieldUtils::InputModule
 InputModule (FieldSharedPtr p_m)
 
void PrintSummary ()
 Print a brief summary of information. More...
 
- Public Member Functions inherited from Nektar::FieldUtils::Module
FIELD_UTILS_EXPORT Module (FieldSharedPtr p_f)
 
virtual ~Module ()=default
 
void Process (po::variables_map &vm)
 
std::string GetModuleName ()
 
std::string GetModuleDescription ()
 
const ConfigOptionGetConfigOption (const std::string &key) const
 
ModulePriority GetModulePriority ()
 
std::vector< ModuleKeyGetModulePrerequisites ()
 
FIELD_UTILS_EXPORT void RegisterConfig (std::string key, std::string value="")
 Register a configuration option with a module. More...
 
FIELD_UTILS_EXPORT void PrintConfig ()
 Print out all configuration options for a module. More...
 
FIELD_UTILS_EXPORT void SetDefaults ()
 Sets default configuration options for those which have not been set. More...
 
FIELD_UTILS_EXPORT void AddFile (std::string fileType, std::string fileName)
 
FIELD_UTILS_EXPORT void EvaluateTriFieldAtEquiSpacedPts (LocalRegions::ExpansionSharedPtr &exp, const Array< OneD, const NekDouble > &infield, Array< OneD, NekDouble > &outfield)
 

Static Public Member Functions

static ModuleSharedPtr create (FieldSharedPtr f)
 Creates an instance of this class. More...
 
- Static Public Member Functions inherited from Nektar::FieldUtils::InputModule
static FIELD_UTILS_EXPORT std::string GuessFormat (std::string fileName)
 Tries to guess the format of the input file. More...
 

Static Public Attributes

static ModuleKey m_className []
 ModuleKey for class. More...
 

Protected Member Functions

void v_Process (po::variables_map &vm) override
 Process Semtex input file. More...
 
std::string v_GetModuleName () override
 
std::string v_GetModuleDescription () override
 
ModulePriority v_GetModulePriority () override
 
- Protected Member Functions inherited from Nektar::FieldUtils::Module
 Module ()
 
virtual void v_Process (po::variables_map &vm)
 
virtual std::string v_GetModuleName ()
 
virtual std::string v_GetModuleDescription ()
 
virtual ModulePriority v_GetModulePriority ()
 
virtual std::vector< ModuleKeyv_GetModulePrerequisites ()
 

Additional Inherited Members

- Public Attributes inherited from Nektar::FieldUtils::Module
FieldSharedPtr m_f
 Field object. More...
 
- Protected Attributes inherited from Nektar::FieldUtils::Module
std::map< std::string, ConfigOptionm_config
 List of configuration values. More...
 
std::set< std::string > m_allowedFiles
 List of allowed file formats. More...
 

Detailed Description

Converter for Fld files.

Definition at line 46 of file InputSemtex.h.

Constructor & Destructor Documentation

◆ InputSemtex()

Nektar::FieldUtils::InputSemtex::InputSemtex ( FieldSharedPtr  f)

Set up InputSemtex object.

Definition at line 59 of file InputSemtex.cpp.

59 : InputModule(f)
60{
61 m_allowedFiles.insert("fldsem");
62}
InputModule(FieldSharedPtr p_m)
Definition: Module.cpp:61
std::set< std::string > m_allowedFiles
List of allowed file formats.
Definition: Module.h:274

References Nektar::FieldUtils::Module::m_allowedFiles.

◆ ~InputSemtex()

Nektar::FieldUtils::InputSemtex::~InputSemtex ( )
override

Definition at line 67 of file InputSemtex.cpp.

68{
69}

Member Function Documentation

◆ create()

static ModuleSharedPtr Nektar::FieldUtils::InputSemtex::create ( FieldSharedPtr  f)
inlinestatic

Creates an instance of this class.

Definition at line 53 of file InputSemtex.h.

54 {
56 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ v_GetModuleDescription()

std::string Nektar::FieldUtils::InputSemtex::v_GetModuleDescription ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 68 of file InputSemtex.h.

69 {
70 return "Processing Semtex field file";
71 }

◆ v_GetModuleName()

std::string Nektar::FieldUtils::InputSemtex::v_GetModuleName ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 63 of file InputSemtex.h.

64 {
65 return "InputSemtex";
66 }

◆ v_GetModulePriority()

ModulePriority Nektar::FieldUtils::InputSemtex::v_GetModulePriority ( )
inlineoverrideprotectedvirtual

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 73 of file InputSemtex.h.

74 {
75 return eCreateFieldData;
76 }

References Nektar::FieldUtils::eCreateFieldData.

◆ v_Process()

void Nektar::FieldUtils::InputSemtex::v_Process ( po::variables_map &  vm)
overrideprotectedvirtual

Process Semtex input file.

This routine reads a binary-format Semtex field file, loads the data into memory and populates the field definitions to match the data format. Semtex is a classic nodal-Lagrangian spectral element code at a single polynomial order, meaning that the field data are set up according to this structure.

Reimplemented from Nektar::FieldUtils::Module.

Definition at line 79 of file InputSemtex.cpp.

80{
81 // Variables to be read from session file
82 string sessionName, date, fields, endian;
83 int nr, ns, nz, nelmt, step;
84 NekDouble time, dt, kinvis, beta;
85
86 ifstream file(m_config["infile"].as<string>().c_str(), ios::binary);
87
88 // -- Read header information.
89 char buf[25];
90 string line;
91
92 // Session name
93 file.read(buf, 25);
94 sessionName = string(buf, 25);
95 boost::trim(sessionName);
96 getline(file, line);
97 m_f->m_fieldMetaDataMap["SessionName0"] = sessionName;
98
99 // Date
100 file.read(buf, 25);
101 date = string(buf, 25);
102 boost::trim(date);
103 getline(file, line);
104
105 // nP, nZ, nElmt
106 file >> nr >> ns >> nz >> nelmt;
107 getline(file, line);
108
109 // Step
110 file >> step;
111 getline(file, line);
112
113 // Time
114 file >> time;
115 getline(file, line);
116 m_f->m_fieldMetaDataMap["Time"] = boost::lexical_cast<string>(time);
117
118 // Timestep
119 file >> dt;
120 getline(file, line);
121 m_f->m_fieldMetaDataMap["TimeStep"] = boost::lexical_cast<string>(dt);
122
123 // Viscosity
124 file >> kinvis;
125 getline(file, line);
126 m_f->m_fieldMetaDataMap["Kinvis"] = boost::lexical_cast<string>(kinvis);
127
128 // Beta
129 file >> beta;
130 getline(file, line);
131
132 // Fields
133 file.read(buf, 25);
134 fields = string(buf, 25);
135 boost::trim(fields);
136 getline(file, line);
137
138 // Endian-ness
140 std::string endianSearch;
141 if (systemEndian == LibUtilities::eEndianBig)
142 {
143 endianSearch = "big";
144 }
145 else if (systemEndian == LibUtilities::eEndianLittle)
146 {
147 endianSearch = "little";
148 }
149 else
150 {
151 ASSERTL0(false, "Only little- or big-endian systems are supported");
152 }
153
154 file.read(buf, 25);
155 endian = string(buf, 25);
156 bool byteSwap = endian.find(endianSearch) == string::npos;
157 getline(file, line);
158
159 // Print some basic information for input if in verbose mode.
160 if (m_f->m_verbose)
161 {
162 cout << "Found header information:" << endl;
163 cout << " -- From session : " << sessionName << endl;
164 cout << " -- File generated : " << date << endl;
165 cout << " -- Polynomial order : " << nr - 1 << endl;
166 cout << " -- Number of planes : " << nz << endl;
167 cout << " -- Number of elements : " << nelmt << endl;
168 cout << " -- Simulation time : " << time << endl;
169 cout << " -- Timestep : " << dt << endl;
170 cout << " -- Viscosity : " << kinvis << endl;
171 cout << " -- Fields : " << fields << " (" << fields.size()
172 << " total)" << endl;
173
174 if (nz > 1)
175 {
176 cout << " -- Homogeneous length : " << 2 * M_PI / beta << endl;
177 }
178
179 cout << " -- " << (byteSwap ? "" : "do not ") << "need to swap endian"
180 << endl;
181 }
182
183 ASSERTL0(nr == ns, "Semtex reader assumes values of nr and ns are equal");
184
185 // Set up a field definition
188 fielddef->m_shapeType = LibUtilities::eQuadrilateral;
189 fielddef->m_homoStrips = false;
190 fielddef->m_pointsDef = false;
191 fielddef->m_uniOrder = true;
192 fielddef->m_numPointsDef = false;
193
194 // Set up basis
195 fielddef->m_basis.push_back(LibUtilities::eGLL_Lagrange);
196 fielddef->m_basis.push_back(LibUtilities::eGLL_Lagrange);
197 fielddef->m_numModes.push_back(nr);
198 fielddef->m_numModes.push_back(nr);
199
200 // Set up elements
201 fielddef->m_elementIDs.resize(nelmt);
202 for (int i = 0; i < nelmt; ++i)
203 {
204 fielddef->m_elementIDs[i] = i;
205 }
206
207 // Deal with homogeneous direction.
208 if (nz > 1)
209 {
210 fielddef->m_numHomogeneousDir = 1;
211 fielddef->m_homogeneousLengths.push_back(2 * M_PI / beta);
212 fielddef->m_numModes.push_back(nz);
213 fielddef->m_basis.push_back(LibUtilities::eFourier);
214
215 for (int i = 0; i < nz; ++i)
216 {
217 fielddef->m_homogeneousZIDs.push_back(i);
218 }
219 }
220 else
221 {
222 fielddef->m_numHomogeneousDir = 0;
223 }
224
225 for (string::size_type i = 0; i < fields.size(); ++i)
226 {
227 fielddef->m_fields.push_back(string(&fields[i], 1));
228 }
229
230 // Size of data to read.
231 size_t elmtSize = nr * ns;
232 size_t planeSize = elmtSize * nelmt;
233 size_t fieldSize = planeSize * nz;
234 size_t dataSize = fieldSize * fields.size();
235
236 // Allocate our storage.
237 m_f->m_data.resize(1);
238 m_f->m_data[0].resize(dataSize);
239
240 // Temporary storage for one plane of data.
241 vector<NekDouble> tmp(planeSize);
242 size_t offset = nz * nr * ns;
243
244 // Now reorder data; Semtex ordering traverses memory fastest over planes,
245 // whereas Nektar++ expects it over elements
246 for (int i = 0; i < fields.size(); ++i)
247 {
248 NekDouble *data = &m_f->m_data[0][i * fieldSize];
249 for (int j = 0; j < nz; ++j)
250 {
251 size_t elSizeJ = j * elmtSize;
252 file.read((char *)&tmp[0], planeSize * sizeof(NekDouble));
253
254 if (byteSwap)
255 {
256 swap_endian(tmp);
257 }
258
259 double *x = &tmp[0];
260 for (int k = 0; k < nelmt; ++k)
261 {
262 std::copy(x, x + elmtSize, data + k * offset + elSizeJ);
263 x += elmtSize;
264 }
265 }
266 }
267
268 m_f->m_fielddef.push_back(fielddef);
269
270 // save field names
271 m_f->m_variables = m_f->m_fielddef[0]->m_fields;
272}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272
def copy(self)
Definition: pycml.py:2663
void swap_endian(T &u)
Swap endian ordering of the input variable.
Definition: Module.h:98
EndianType Endianness(void)
std::shared_ptr< FieldDefinitions > FieldDefinitionsSharedPtr
Definition: FieldIO.h:184
@ beta
Gauss Radau pinned at x=-1,.
Definition: PointsType.h:59
@ eGLL_Lagrange
Lagrange for SEM basis .
Definition: BasisType.h:56
@ eFourier
Fourier Expansion .
Definition: BasisType.h:55
double NekDouble

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::beta, CellMLToNektar.pycml::copy(), Nektar::LibUtilities::eEndianBig, Nektar::LibUtilities::eEndianLittle, Nektar::LibUtilities::eFourier, Nektar::LibUtilities::eGLL_Lagrange, Nektar::LibUtilities::Endianness(), Nektar::LibUtilities::eQuadrilateral, Nektar::FieldUtils::Module::m_config, Nektar::FieldUtils::Module::m_f, and Nektar::FieldUtils::swap_endian().

Member Data Documentation

◆ m_className

ModuleKey Nektar::FieldUtils::InputSemtex::m_className
static
Initial value:
= {
"Reads Semtex field file.")}
static ModuleSharedPtr create(FieldSharedPtr f)
Creates an instance of this class.
Definition: InputSemtex.h:53
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47

ModuleKey for class.

Definition at line 58 of file InputSemtex.h.