Nektar++
FieldIO.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: FieldIO.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: I/O routines relating to Fields
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <boost/asio/ip/host_name.hpp>
36 #include <boost/format.hpp>
37 #include <boost/regex.hpp>
38 
42 
43 #include <chrono>
44 #include <ctime>
45 #include <fstream>
46 #include <iomanip>
47 #include <ios>
48 #include <set>
49 
50 #ifdef NEKTAR_USE_MPI
51 #include <mpi.h>
52 #endif
53 
54 #ifndef NEKTAR_VERSION
55 #define NEKTAR_VERSION "Unknown"
56 #endif
57 
58 namespace berrc = boost::system::errc;
59 namespace ip = boost::asio::ip;
60 
61 namespace Nektar
62 {
63 namespace LibUtilities
64 {
65 
67  "io-format", "i", "Default input/output format (e.g. Xml, Hdf5)");
68 
69 /**
70  * @brief Returns the FieldIO factory.
71  */
73 {
74  static FieldIOFactory instance;
75  return instance;
76 }
77 
78 /// Enumerator for auto-detection of FieldIO types.
80 {
82  eHDF5
83 };
84 
85 /**
86  * @brief Determine file type of given input file.
87  *
88  * This method attempts to identify the file type of a given input file @p
89  * filename. It returns a string corresponding to GetFieldIOFactory() or throws
90  * an assertion if it cannot be identified.
91  *
92  * @param filename Input filename
93  * @param comm Communicator for parallel runs
94  *
95  * @return FieldIO format of @p filename.
96  */
97 const std::string FieldIO::GetFileType(const std::string &filename,
98  CommSharedPtr comm)
99 {
100  FieldIOType ioType = eXML;
101  int size = comm->GetSize();
102  bool root = comm->TreatAsRankZero();
103 
104  if (size == 1 || root)
105  {
106  std::string datafilename;
107 
108  // If input is a directory, check for root processor file.
109  if (fs::is_directory(filename))
110  {
111  fs::path fullpath = filename;
112 
113  fs::path d = fullpath;
114  boost::regex expr("P\\d{7}.fld");
115  boost::smatch what;
116 
117  bool found = false;
118  for (auto &f : fs::directory_iterator(d))
119  {
120  if (boost::regex_match(f.path().filename().string(), what,
121  expr))
122  {
123  found = true;
124  fullpath = f.path();
125  break;
126  }
127  }
128 
129  ASSERTL0(found, std::string("Failed to open a PXXXXXXX.fld file "
130  "in directory: " +
131  filename)
132  .c_str());
133 
134  datafilename = PortablePath(fullpath);
135  }
136  else
137  {
138  datafilename = filename;
139  }
140 
141  // Read first 8 bytes. If they correspond with magic bytes below it's an
142  // HDF5 file. XML is potentially a nightmare with all the different
143  // encodings so we'll just assume it's OK if it's not HDF.
144  const unsigned char magic[8] = {0x89, 0x48, 0x44, 0x46,
145  0x0d, 0x0a, 0x1a, 0x0a};
146 
147  std::ifstream datafile(datafilename.c_str(), std::ios_base::binary);
148  ASSERTL0(datafile.good(), "Unable to open file: " + filename);
149 
150  ioType = eHDF5;
151  for (unsigned i = 0; i < 8 && datafile.good(); ++i)
152  {
153  int byte = datafile.get();
154  if (byte != magic[i])
155  {
156  ioType = eXML;
157  break;
158  }
159  }
160  }
161 
162  if (size > 1)
163  {
164  int code = (int)ioType;
165  comm->Bcast(code, 0);
166  ioType = (FieldIOType)code;
167  }
168 
169  std::string iofmt;
170  if (ioType == eXML)
171  {
172  iofmt = "Xml";
173  }
174  else if (ioType == eHDF5)
175  {
176  iofmt = "Hdf5";
177  }
178  else
179  {
180  // Error
181  NEKERROR(ErrorUtil::efatal, "Unknown file format");
182  }
183 
184  return iofmt;
185 }
186 
187 /**
188  * @brief Returns an object for the default FieldIO method.
189  *
190  * This function returns a FieldIO class as determined by the hard-coded default
191  * (XML), which can be overridden by changing the session reader SOLVERINFO
192  * variable FieldIOFormat.
193  *
194  * @param session Session reader
195  *
196  * @return FieldIO object
197  */
200 {
201  std::string iofmt("Xml");
202  if (session->DefinesSolverInfo("IOFormat"))
203  {
204  iofmt = session->GetSolverInfo("IOFormat");
205  }
206 
207  if (session->DefinesCmdLineArgument("io-format"))
208  {
209  iofmt = session->GetCmdLineArgument<std::string>("io-format");
210  }
211 
212  return GetFieldIOFactory().CreateInstance(iofmt, session->GetComm(),
213  session->GetSharedFilesystem());
214 }
215 
216 /**
217  * @brief Construct a FieldIO object for a given input filename.
218  *
219  * This is a convenience function that takes an input filename and constructs
220  * the appropriate FieldIO subclass, using FieldIO::GetFileType.
221  *
222  * @param session Session reader
223  * @param filename Input filename
224  *
225  * @return FieldIO class reader for @p filename.
226  */
229  const std::string &filename)
230 {
231  const std::string iofmt =
232  FieldIO::GetFileType(filename, session->GetComm());
233  return GetFieldIOFactory().CreateInstance(iofmt, session->GetComm(),
234  session->GetSharedFilesystem());
235 }
236 
237 /**
238  * @brief This function allows for data to be written to an FLD file when a
239  * session and/or communicator is not instantiated. Typically used in utilities
240  * which do not take XML input and operate in serial only.
241  *
242  * @param outFile Output filename
243  * @param fielddefs Field definitions that define the output
244  * @param fielddata Binary field data that stores the output corresponding
245  * to @p fielddefs.
246  * @param fieldinfomap Associated field metadata map.
247  */
248 void Write(const std::string &outFile,
249  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
250  std::vector<std::vector<NekDouble>> &fielddata,
251  const FieldMetaDataMap &fieldinfomap, const bool backup)
252 {
253 #ifdef NEKTAR_USE_MPI
254  int size;
255  int init;
256  MPI_Initialized(&init);
257 
258  // If MPI has been initialised we can check the number of processes
259  // and, if > 1, tell the user he should not be running this
260  // function in parallel. If it is not initialised, we do not
261  // initialise it here, and assume the user knows what they are
262  // doing.
263  if (init)
264  {
265  MPI_Comm_size(MPI_COMM_WORLD, &size);
266  ASSERTL0(size == 1,
267  "This static function is not available in parallel. Please"
268  "instantiate a FieldIO object for parallel use.");
269  }
270 #endif
271  CommSharedPtr c = GetCommFactory().CreateInstance("Serial", 0, 0);
272  FieldIOSharedPtr f = GetFieldIOFactory().CreateInstance("Xml", c, false);
273  f->Write(outFile, fielddefs, fielddata, fieldinfomap, backup);
274 }
275 
276 /**
277  * @brief This function allows for data to be imported from an FLD file when a
278  * session and/or communicator is not instantiated. Typically used in utilities
279  * which only operate in serial.
280  *
281  * @param infilename Input filename (or directory if parallel format)
282  * @param fielddefs On return contains field definitions as read from the
283  * input.
284  * @param fielddata On return, contains binary field data that stores the
285  * input corresponding to @p fielddefs.
286  * @param fieldinfo On returnm, contains the associated field metadata map.
287  * @param ElementIDs Element IDs that lie on this processor, which can be
288  * optionally supplied to avoid reading the entire file on
289  * each processor.
290  */
292  const std::string &infilename,
293  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
294  std::vector<std::vector<NekDouble>> &fielddata,
295  FieldMetaDataMap &fieldinfomap, const Array<OneD, int> &ElementIDs)
296 {
297 #ifdef NEKTAR_USE_MPI
298  int size;
299  int init;
300  MPI_Initialized(&init);
301 
302  // If MPI has been initialised we can check the number of processes
303  // and, if > 1, tell the user he should not be running this
304  // function in parallel. If it is not initialised, we do not
305  // initialise it here, and assume the user knows what they are
306  // doing.
307  if (init)
308  {
309  MPI_Comm_size(MPI_COMM_WORLD, &size);
310  ASSERTL0(size == 1,
311  "This static function is not available in parallel. Please"
312  "instantiate a FieldIO object for parallel use.");
313  }
314 #endif
315  CommSharedPtr c = GetCommFactory().CreateInstance("Serial", 0, 0);
316  const std::string iofmt = FieldIO::GetFileType(infilename, c);
317  FieldIOSharedPtr f = GetFieldIOFactory().CreateInstance(iofmt, c, false);
318  f->Import(infilename, fielddefs, fielddata, fieldinfomap, ElementIDs);
319 }
320 
321 /**
322  * @brief Constructor for FieldIO base class.
323  */
324 FieldIO::FieldIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem)
325  : m_comm(pComm), m_sharedFilesystem(sharedFilesystem)
326 {
327 }
328 
329 /**
330  * @brief Add provenance information to the field metadata map.
331  *
332  * This routine adds some basic provenance information to the field metadata to
333  * enable better tracking of version information:
334  *
335  * - Nektar++ version
336  * - Date and time of simulation
337  * - Hostname of the machine the simulation was performed on
338  * - git SHA1 and branch name, if Nektar++ was compiled from git and not
339  * e.g. a tarball.
340  *
341  * @param root Root tag, which is encapsulated using the TagWriter
342  * structure to enable multi-file format support.
343  * @param fieldmetadatamap Any existing field metadata.
344  */
346  const FieldMetaDataMap &fieldmetadatamap)
347 {
348  FieldMetaDataMap ProvenanceMap;
349 
350  // Nektar++ release version from VERSION file
351  ProvenanceMap["NektarVersion"] = std::string(NEKTAR_VERSION);
352 
353  // Date/time stamp
354  auto now = std::chrono::system_clock::now();
355  auto now_t = std::chrono::system_clock::to_time_t(now);
356  auto now_tm = *std::localtime(&now_t);
357  char buffer[128];
358  strftime(buffer, sizeof(buffer), "%d-%b-%Y %H:%M:%S", &now_tm);
359  ProvenanceMap["Timestamp"] = buffer;
360 
361  // Hostname
362  boost::system::error_code ec;
363  ProvenanceMap["Hostname"] = ip::host_name(ec);
364 
365  // Git information
366  // If built from a distributed package, do not include this
367  if (NekConstants::kGitSha1 != "GITDIR-NOTFOUND")
368  {
369  ProvenanceMap["GitSHA1"] = NekConstants::kGitSha1;
370  ProvenanceMap["GitBranch"] = NekConstants::kGitBranch;
371  }
372 
373  TagWriterSharedPtr infoTag = root->AddChild("Metadata");
374 
375  TagWriterSharedPtr provTag = infoTag->AddChild("Provenance");
376  for (auto &infoit : ProvenanceMap)
377  {
378  provTag->SetAttr(infoit.first, infoit.second);
379  }
380 
381  //---------------------------------------------
382  // write field info section
383  if (fieldmetadatamap != NullFieldMetaDataMap)
384  {
385  for (auto &infoit : fieldmetadatamap)
386  {
387  infoTag->SetAttr(infoit.first, infoit.second);
388  }
389  }
390 }
391 
392 /**
393  * @brief Set up the filesystem ready for output.
394  *
395  * This function sets up the output given an output filename @p outname. This
396  * will therefore remove any file or directory with the desired output filename
397  * and return the absolute path to the output.
398  *
399  * If @p perRank is set, a new directory will be created to contain one file per
400  * process rank.
401  *
402  * @param outname Desired output filename.
403  * @param perRank True if one file-per-rank output is required.
404  *
405  * @return Absolute path to resulting file.
406  */
407 std::string FieldIO::SetUpOutput(const std::string outname, bool perRank,
408  bool backup)
409 {
410  ASSERTL0(!outname.empty(), "Empty path given to SetUpOutput()");
411 
412  // Create a hash from the filename
413  std::size_t file_id = std::hash<std::string>{}(outname);
414 
415  // Find the minimum and maximum hash for each process
416  std::size_t file_id_max{file_id};
417  std::size_t file_id_min{file_id};
418  m_comm->AllReduce(file_id_max, ReduceMax);
419  m_comm->AllReduce(file_id_min, ReduceMin);
420 
421  // Check that each process has the same filename (hash)
422  ASSERTL0(file_id_min == file_id_max,
423  "All processes do not have the same filename.");
424 
425  int nprocs = m_comm->GetSize();
426  bool root = m_comm->TreatAsRankZero();
427 
428  // Path to output: will be directory if parallel, normal file if
429  // serial.
430  fs::path specPath(outname), fulloutname;
431 
432  // in case we are rank 0 or not on a shared filesystem, check if the
433  // specPath already exists
434  if (backup && (root || !m_sharedFilesystem) && fs::exists(specPath))
435  {
436  // rename. foo/bar_123.chk -> foo/bar_123.bak0.chk and in case
437  // foo/bar_123.bak0.chk already exists, foo/bar_123.chk ->
438  // foo/bar_123.bak1.chk
439  fs::path bakPath = specPath;
440  int cnt = 0;
441  while (fs::exists(bakPath))
442  {
443  bakPath = specPath.parent_path();
444  bakPath += specPath.stem();
445  bakPath += fs::path(".bak" + std::to_string(cnt++));
446  bakPath += specPath.extension();
447  }
448  std::cout << "renaming " << specPath << " -> " << bakPath << std::endl;
449  try
450  {
451  fs::rename(specPath, bakPath);
452  }
453  catch (fs::filesystem_error &e)
454  {
455  ASSERTL0(e.code().value() == berrc::no_such_file_or_directory,
456  "Filesystem error: " + std::string(e.what()));
457  }
458  }
459 
460  // wait until rank 0 has moved the old specPath and the changes
461  // have propagated through the filesystem
462  if (backup)
463  {
464  m_comm->Block();
465  int exists = 1;
466  while (exists && perRank)
467  {
468  exists = fs::exists(specPath);
469  m_comm->AllReduce(exists, ReduceMax);
470  }
471  }
472 
473  if (nprocs == 1)
474  {
475  fulloutname = specPath;
476  }
477  else
478  {
479  // Guess at filename that might belong to this process.
480  boost::format pad("P%1$07d.%2$s");
481  pad % m_comm->GetRank() % GetFileEnding();
482 
483  // Generate full path name
484  fs::path poutfile(pad.str());
485  fulloutname = specPath / poutfile;
486  }
487 
488  // Remove any existing file which is in the way
489  if (m_comm->RemoveExistingFiles() && !backup)
490  {
491  if (m_sharedFilesystem)
492  {
493  // First, each process clears up its .fld file. This might or might
494  // not be there (we might have changed numbers of processors between
495  // runs, for example), but we can try anyway.
496  try
497  {
498  fs::remove_all(fulloutname);
499  }
500  catch (fs::filesystem_error &e)
501  {
502  ASSERTL0(e.code().value() == berrc::no_such_file_or_directory,
503  "Filesystem error: " + std::string(e.what()));
504  }
505  }
506 
507  m_comm->Block();
508 
509  // Now get rank 0 processor to tidy everything else up.
510  if (root || !m_sharedFilesystem)
511  {
512  try
513  {
514  fs::remove_all(specPath);
515  }
516  catch (fs::filesystem_error &e)
517  {
518  ASSERTL0(e.code().value() == berrc::no_such_file_or_directory,
519  "Filesystem error: " + std::string(e.what()));
520  }
521  }
522 
523  // wait until rank 0 has removed specPath and the changes
524  // have propagated through the filesystem
525  m_comm->Block();
526  int exists = 1;
527  while (exists && perRank)
528  {
529  exists = fs::exists(specPath);
530  m_comm->AllReduce(exists, ReduceMax);
531  }
532  }
533 
534  if (root)
535  {
536  std::cout << "Writing: " << specPath;
537  }
538 
539  // serial processing just add ending.
540  if (nprocs == 1)
541  {
542  return LibUtilities::PortablePath(specPath);
543  }
544 
545  // Create the destination directory
546  if (perRank)
547  {
548  try
549  {
550  if (root || !m_sharedFilesystem)
551  {
552  fs::create_directory(specPath);
553  }
554  }
555  catch (fs::filesystem_error &e)
556  {
558  "Filesystem error: " + std::string(e.what()));
559  }
560 
561  m_comm->Block();
562 
563  // Sit in a loop and make sure target directory has been created
564  int created = 0;
565  while (!created)
566  {
567  created = fs::is_directory(specPath);
568  m_comm->AllReduce(created, ReduceMin);
569  }
570  }
571  else
572  {
573  fulloutname = specPath;
574  }
575 
576  // Return the full path to the partition for this process
577  return LibUtilities::PortablePath(fulloutname);
578 }
579 
580 /**
581  * @brief Check field definitions for correctness and return storage size.
582  *
583  * @param fielddefs Field definitions to check.
584  */
586 {
587  int i;
588 
589  if (fielddefs->m_elementIDs.size() == 0) // empty partition
590  {
591  return 0;
592  }
593 
594  unsigned int numbasis = 0;
595 
596  // Determine nummodes vector lists are correct length
597  switch (fielddefs->m_shapeType)
598  {
599  case eSegment:
600  numbasis = 1;
601  if (fielddefs->m_numHomogeneousDir)
602  {
603  numbasis += fielddefs->m_numHomogeneousDir;
604  }
605 
606  break;
607  case eTriangle:
608  case eQuadrilateral:
609  if (fielddefs->m_numHomogeneousDir)
610  {
611  numbasis = 3;
612  }
613  else
614  {
615  numbasis = 2;
616  }
617  break;
618  case eTetrahedron:
619  case ePyramid:
620  case ePrism:
621  case eHexahedron:
622  numbasis = 3;
623  break;
624  default:
625  NEKERROR(ErrorUtil::efatal, "Unsupported shape type.");
626  break;
627  }
628 
629  size_t datasize = 0;
630 
631  ASSERTL0(fielddefs->m_basis.size() == numbasis,
632  "Length of basis vector is incorrect");
633 
634  if (fielddefs->m_uniOrder == true)
635  {
636  unsigned int cnt = 0;
637  // calculate datasize
638  switch (fielddefs->m_shapeType)
639  {
640  case eSegment:
641  {
642  int l = fielddefs->m_numModes[cnt++];
643  if (fielddefs->m_numHomogeneousDir == 1)
644  {
645  datasize += l * fielddefs->m_homogeneousZIDs.size();
646  cnt++;
647  }
648  else if (fielddefs->m_numHomogeneousDir == 2)
649  {
650  datasize += l * fielddefs->m_homogeneousYIDs.size();
651  cnt += 2;
652  }
653  else
654  {
655  datasize += l;
656  }
657  }
658  break;
659  case eTriangle:
660  {
661  int l = fielddefs->m_numModes[cnt++];
662  int m = fielddefs->m_numModes[cnt++];
663 
664  if (fielddefs->m_numHomogeneousDir == 1)
665  {
666  datasize += StdTriData::getNumberOfCoefficients(l, m) *
667  fielddefs->m_homogeneousZIDs.size();
668  }
669  else
670  {
671  datasize += StdTriData::getNumberOfCoefficients(l, m);
672  }
673  }
674  break;
675  case eQuadrilateral:
676  {
677  int l = fielddefs->m_numModes[cnt++];
678  int m = fielddefs->m_numModes[cnt++];
679  if (fielddefs->m_numHomogeneousDir == 1)
680  {
681  datasize += l * m * fielddefs->m_homogeneousZIDs.size();
682  }
683  else
684  {
685  datasize += l * m;
686  }
687  }
688  break;
689  case eTetrahedron:
690  {
691  int l = fielddefs->m_numModes[cnt++];
692  int m = fielddefs->m_numModes[cnt++];
693  int n = fielddefs->m_numModes[cnt++];
694  datasize += StdTetData::getNumberOfCoefficients(l, m, n);
695  }
696  break;
697  case ePyramid:
698  {
699  int l = fielddefs->m_numModes[cnt++];
700  int m = fielddefs->m_numModes[cnt++];
701  int n = fielddefs->m_numModes[cnt++];
702  datasize += StdPyrData::getNumberOfCoefficients(l, m, n);
703  }
704  break;
705  case ePrism:
706  {
707  int l = fielddefs->m_numModes[cnt++];
708  int m = fielddefs->m_numModes[cnt++];
709  int n = fielddefs->m_numModes[cnt++];
710  datasize += StdPrismData::getNumberOfCoefficients(l, m, n);
711  }
712  break;
713  case eHexahedron:
714  {
715  int l = fielddefs->m_numModes[cnt++];
716  int m = fielddefs->m_numModes[cnt++];
717  int n = fielddefs->m_numModes[cnt++];
718  datasize += l * m * n;
719  }
720  break;
721  default:
722  NEKERROR(ErrorUtil::efatal, "Unsupported shape type.");
723  break;
724  }
725 
726  datasize *= fielddefs->m_elementIDs.size();
727  }
728  else
729  {
730  unsigned int cnt = 0;
731  // calculate data length
732  for (i = 0; i < fielddefs->m_elementIDs.size(); ++i)
733  {
734  switch (fielddefs->m_shapeType)
735  {
736  case eSegment:
737  {
738  int l = fielddefs->m_numModes[cnt++];
739  if (fielddefs->m_numHomogeneousDir == 1)
740  {
741  datasize += l * fielddefs->m_homogeneousZIDs.size();
742  cnt++;
743  }
744  else if (fielddefs->m_numHomogeneousDir == 2)
745  {
746  datasize += l * fielddefs->m_homogeneousYIDs.size();
747  cnt += 2;
748  }
749  else
750  {
751  datasize += l;
752  }
753  }
754  break;
755  case eTriangle:
756  {
757  int l = fielddefs->m_numModes[cnt++];
758  int m = fielddefs->m_numModes[cnt++];
759  if (fielddefs->m_numHomogeneousDir == 1)
760  {
761  datasize += StdTriData::getNumberOfCoefficients(l, m) *
762  fielddefs->m_homogeneousZIDs.size();
763  cnt++;
764  }
765  else
766  {
767  datasize += StdTriData::getNumberOfCoefficients(l, m);
768  }
769  }
770  break;
771  case eQuadrilateral:
772  {
773  int l = fielddefs->m_numModes[cnt++];
774  int m = fielddefs->m_numModes[cnt++];
775  if (fielddefs->m_numHomogeneousDir == 1)
776  {
777  datasize += l * m * fielddefs->m_homogeneousZIDs.size();
778  cnt++;
779  }
780  else
781  {
782  datasize += l * m;
783  }
784  }
785  break;
786  case eTetrahedron:
787  {
788  int l = fielddefs->m_numModes[cnt++];
789  int m = fielddefs->m_numModes[cnt++];
790  int n = fielddefs->m_numModes[cnt++];
791  datasize += StdTetData::getNumberOfCoefficients(l, m, n);
792  }
793  break;
794  case ePyramid:
795  {
796  int l = fielddefs->m_numModes[cnt++];
797  int m = fielddefs->m_numModes[cnt++];
798  int n = fielddefs->m_numModes[cnt++];
799  datasize += StdPyrData::getNumberOfCoefficients(l, m, n);
800  }
801  break;
802  case ePrism:
803  {
804  int l = fielddefs->m_numModes[cnt++];
805  int m = fielddefs->m_numModes[cnt++];
806  int n = fielddefs->m_numModes[cnt++];
807  datasize += StdPrismData::getNumberOfCoefficients(l, m, n);
808  }
809  break;
810  case eHexahedron:
811  {
812  int l = fielddefs->m_numModes[cnt++];
813  int m = fielddefs->m_numModes[cnt++];
814  int n = fielddefs->m_numModes[cnt++];
815  datasize += l * m * n;
816  }
817  break;
818  default:
819  NEKERROR(ErrorUtil::efatal, "Unsupported shape type.");
820  break;
821  }
822  }
823  }
824 
825  return (int)datasize;
826 }
827 } // namespace LibUtilities
828 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209
#define NEKTAR_VERSION
Definition: FieldIO.cpp:55
#define LIB_UTILITIES_EXPORT
int CheckFieldDefinition(const FieldDefinitionsSharedPtr &fielddefs)
Check field definitions for correctness and return storage size.
Definition: FieldIO.cpp:585
static const std::string GetFileType(const std::string &filename, CommSharedPtr comm)
Determine file type of given input file.
Definition: FieldIO.cpp:97
bool m_sharedFilesystem
Boolean dictating whether we are on a shared filesystem.
Definition: FieldIO.h:263
static std::shared_ptr< FieldIO > CreateForFile(const LibUtilities::SessionReaderSharedPtr session, const std::string &filename)
Construct a FieldIO object for a given input filename.
Definition: FieldIO.cpp:227
static std::shared_ptr< FieldIO > CreateDefault(const LibUtilities::SessionReaderSharedPtr session)
Returns an object for the default FieldIO method.
Definition: FieldIO.cpp:198
std::string SetUpOutput(const std::string outname, bool perRank, bool backup=false)
Set up the filesystem ready for output.
Definition: FieldIO.cpp:407
LibUtilities::CommSharedPtr m_comm
Communicator to use when writing parallel format.
Definition: FieldIO.h:261
FieldIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem)
Constructor for FieldIO base class.
Definition: FieldIO.cpp:324
static void AddInfoTag(TagWriterSharedPtr root, const FieldMetaDataMap &fieldmetadatamap)
Add provenance information to the field metadata map.
Definition: FieldIO.cpp:345
virtual std::string GetFileEnding() const
Helper function that determines default file extension.
Definition: FieldIO.h:271
Provides a generic Factory class.
Definition: NekFactory.hpp:105
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
static std::string RegisterCmdLineArgument(const std::string &pName, const std::string &pShortName, const std::string &pDescription)
Registers a command-line argument with the session reader.
array buffer
Definition: GsLib.hpp:83
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:282
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:235
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:190
int getNumberOfCoefficients(int Na, int Nb)
Definition: ShapeType.hpp:112
void Write(const std::string &outFile, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble >> &fielddata, const FieldMetaDataMap &fieldinfomap, const bool backup)
This function allows for data to be written to an FLD file when a session and/or communicator is not ...
Definition: FieldIO.cpp:248
FieldIOType
Enumerator for auto-detection of FieldIO types.
Definition: FieldIO.cpp:80
std::shared_ptr< TagWriter > TagWriterSharedPtr
Definition: FieldIO.h:71
std::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:301
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble >> &fielddata, FieldMetaDataMap &fieldinfomap, const Array< OneD, int > &ElementIDs)
This function allows for data to be imported from an FLD file when a session and/or communicator is n...
Definition: FieldIO.cpp:291
std::map< std::string, std::string > FieldMetaDataMap
Definition: FieldIO.h:52
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
Definition: FileSystem.cpp:41
std::shared_ptr< SessionReader > SessionReaderSharedPtr
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:53
std::shared_ptr< FieldDefinitions > FieldDefinitionsSharedPtr
Definition: FieldIO.h:177
std::string fldCmdFormat
Definition: FieldIO.cpp:66
FieldIOFactory & GetFieldIOFactory()
Returns the FieldIO factory.
Definition: FieldIO.cpp:72
CommFactory & GetCommFactory()
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
const std::string kGitBranch
const std::string kGitSha1
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1