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 <ios>
46 #include <iomanip>
47 #include <fstream>
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.
81  eHDF5
82 };
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, expr))
121  {
122  found = true;
123  fullpath = f.path();
124  break;
125  }
126  }
127 
128  ASSERTL0(found,std::string("Failed to open a PXXXXXXX.fld file "
129  "in directory: " + filename).c_str());
130 
131  datafilename = PortablePath(fullpath);
132  }
133  else
134  {
135  datafilename = filename;
136  }
137 
138  // Read first 8 bytes. If they correspond with magic bytes below it's an
139  // HDF5 file. XML is potentially a nightmare with all the different
140  // encodings so we'll just assume it's OK if it's not HDF.
141  const unsigned char magic[8] = {
142  0x89, 0x48, 0x44, 0x46, 0x0d, 0x0a, 0x1a, 0x0a};
143 
144  std::ifstream datafile(datafilename.c_str(), std::ios_base::binary);
145  ASSERTL0(datafile.good(), "Unable to open file: " + filename);
146 
147  ioType = eHDF5;
148  for (unsigned i = 0; i < 8 && datafile.good(); ++i)
149  {
150  int byte = datafile.get();
151  if (byte != magic[i])
152  {
153  ioType = eXML;
154  break;
155  }
156  }
157  }
158 
159  if (size > 1)
160  {
161  int code = (int)ioType;
162  comm->Bcast(code, 0);
163  ioType = (FieldIOType)code;
164  }
165 
166  std::string iofmt;
167  if (ioType == eXML)
168  {
169  iofmt = "Xml";
170  }
171  else if (ioType == eHDF5)
172  {
173  iofmt = "Hdf5";
174  }
175  else
176  {
177  // Error
178  NEKERROR(ErrorUtil::efatal, "Unknown file format");
179  }
180 
181  return iofmt;
182 }
183 
184 /**
185  * @brief Returns an object for the default FieldIO method.
186  *
187  * This function returns a FieldIO class as determined by the hard-coded default
188  * (XML), which can be overridden by changing the session reader SOLVERINFO
189  * variable FieldIOFormat.
190  *
191  * @param session Session reader
192  *
193  * @return FieldIO object
194  */
197 {
198  std::string iofmt("Xml");
199  if (session->DefinesSolverInfo("IOFormat"))
200  {
201  iofmt = session->GetSolverInfo("IOFormat");
202  }
203 
204  if (session->DefinesCmdLineArgument("io-format"))
205  {
206  iofmt = session->GetCmdLineArgument<std::string>("io-format");
207  }
208 
210  iofmt,
211  session->GetComm(),
212  session->GetSharedFilesystem());
213 }
214 
215 /**
216  * @brief Construct a FieldIO object for a given input filename.
217  *
218  * This is a convenience function that takes an input filename and constructs
219  * the appropriate FieldIO subclass, using FieldIO::GetFileType.
220  *
221  * @param session Session reader
222  * @param filename Input filename
223  *
224  * @return FieldIO class reader for @p filename.
225  */
228  const std::string &filename)
229 {
230  const std::string iofmt =
231  FieldIO::GetFileType(filename, session->GetComm());
233  iofmt,
234  session->GetComm(),
235  session->GetSharedFilesystem());
236 }
237 
238 /**
239  * @brief This function allows for data to be written to an FLD file when a
240  * session and/or communicator is not instantiated. Typically used in utilities
241  * which do not take XML input and operate in serial only.
242  *
243  * @param outFile Output filename
244  * @param fielddefs Field definitions that define the output
245  * @param fielddata Binary field data that stores the output corresponding
246  * to @p fielddefs.
247  * @param fieldinfomap Associated field metadata map.
248  */
249 void Write(const std::string &outFile,
250  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
251  std::vector<std::vector<NekDouble> > &fielddata,
252  const FieldMetaDataMap &fieldinfomap,
253  const bool backup)
254 {
255 #ifdef NEKTAR_USE_MPI
256  int size;
257  int init;
258  MPI_Initialized(&init);
259 
260  // If MPI has been initialised we can check the number of processes
261  // and, if > 1, tell the user he should not be running this
262  // function in parallel. If it is not initialised, we do not
263  // initialise it here, and assume the user knows what they are
264  // doing.
265  if (init)
266  {
267  MPI_Comm_size(MPI_COMM_WORLD, &size);
268  ASSERTL0(size == 1,
269  "This static function is not available in parallel. Please"
270  "instantiate a FieldIO object for parallel use.");
271  }
272 #endif
273  CommSharedPtr c = GetCommFactory().CreateInstance("Serial", 0, 0);
274  FieldIOSharedPtr f = GetFieldIOFactory().CreateInstance("Xml", c, false);
275  f->Write(outFile, fielddefs, fielddata, fieldinfomap, backup);
276 }
277 
278 /**
279  * @brief This function allows for data to be imported from an FLD file when a
280  * session and/or communicator is not instantiated. Typically used in utilities
281  * which only operate in serial.
282  *
283  * @param infilename Input filename (or directory if parallel format)
284  * @param fielddefs On return contains field definitions as read from the
285  * input.
286  * @param fielddata On return, contains binary field data that stores the
287  * input corresponding to @p fielddefs.
288  * @param fieldinfo On returnm, contains the associated field metadata map.
289  * @param ElementIDs Element IDs that lie on this processor, which can be
290  * optionally supplied to avoid reading the entire file on
291  * each processor.
292  */
294  const std::string &infilename,
295  std::vector<FieldDefinitionsSharedPtr> &fielddefs,
296  std::vector<std::vector<NekDouble> > &fielddata,
297  FieldMetaDataMap &fieldinfomap,
298  const Array<OneD, int> &ElementIDs)
299 {
300 #ifdef NEKTAR_USE_MPI
301  int size;
302  int init;
303  MPI_Initialized(&init);
304 
305  // If MPI has been initialised we can check the number of processes
306  // and, if > 1, tell the user he should not be running this
307  // function in parallel. If it is not initialised, we do not
308  // initialise it here, and assume the user knows what they are
309  // doing.
310  if (init)
311  {
312  MPI_Comm_size(MPI_COMM_WORLD, &size);
313  ASSERTL0(size == 1,
314  "This static function is not available in parallel. Please"
315  "instantiate a FieldIO object for parallel use.");
316  }
317 #endif
318  CommSharedPtr c = GetCommFactory().CreateInstance("Serial", 0, 0);
319  const std::string iofmt = FieldIO::GetFileType(infilename, c);
320  FieldIOSharedPtr f = GetFieldIOFactory().CreateInstance(iofmt, c, false);
321  f->Import(infilename, fielddefs, fielddata, fieldinfomap, ElementIDs);
322 }
323 
324 /**
325  * @brief Constructor for FieldIO base class.
326  */
327 FieldIO::FieldIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem)
328  : m_comm(pComm), m_sharedFilesystem(sharedFilesystem)
329 {
330 }
331 
332 /**
333  * @brief Add provenance information to the field metadata map.
334  *
335  * This routine adds some basic provenance information to the field metadata to
336  * enable better tracking of version information:
337  *
338  * - Nektar++ version
339  * - Date and time of simulation
340  * - Hostname of the machine the simulation was performed on
341  * - git SHA1 and branch name, if Nektar++ was compiled from git and not
342  * e.g. a tarball.
343  *
344  * @param root Root tag, which is encapsulated using the TagWriter
345  * structure to enable multi-file format support.
346  * @param fieldmetadatamap Any existing field metadata.
347  */
349  const FieldMetaDataMap &fieldmetadatamap)
350 {
351  FieldMetaDataMap ProvenanceMap;
352 
353  // Nektar++ release version from VERSION file
354  ProvenanceMap["NektarVersion"] = std::string(NEKTAR_VERSION);
355 
356  // Date/time stamp
357  auto now = std::chrono::system_clock::now();
358  auto now_t = std::chrono::system_clock::to_time_t(now);
359  auto now_tm = *std::localtime(&now_t);
360  char buffer[128];
361  strftime(buffer, sizeof(buffer), "%d-%b-%Y %H:%M:%S", &now_tm);
362  ProvenanceMap["Timestamp"] = buffer;
363 
364  // Hostname
365  boost::system::error_code ec;
366  ProvenanceMap["Hostname"] = ip::host_name(ec);
367 
368  // Git information
369  // If built from a distributed package, do not include this
370  if (NekConstants::kGitSha1 != "GITDIR-NOTFOUND")
371  {
372  ProvenanceMap["GitSHA1"] = NekConstants::kGitSha1;
373  ProvenanceMap["GitBranch"] = NekConstants::kGitBranch;
374  }
375 
376  TagWriterSharedPtr infoTag = root->AddChild("Metadata");
377 
378  TagWriterSharedPtr provTag = infoTag->AddChild("Provenance");
379  for (auto &infoit : ProvenanceMap)
380  {
381  provTag->SetAttr(infoit.first, infoit.second);
382  }
383 
384  //---------------------------------------------
385  // write field info section
386  if (fieldmetadatamap != NullFieldMetaDataMap)
387  {
388  for (auto &infoit : fieldmetadatamap)
389  {
390  infoTag->SetAttr(infoit.first, infoit.second);
391  }
392  }
393 }
394 
395 /**
396  * @brief Set up the filesystem ready for output.
397  *
398  * This function sets up the output given an output filename @p outname. This
399  * will therefore remove any file or directory with the desired output filename
400  * and return the absolute path to the output.
401  *
402  * If @p perRank is set, a new directory will be created to contain one file per
403  * process rank.
404  *
405  * @param outname Desired output filename.
406  * @param perRank True if one file-per-rank output is required.
407  *
408  * @return Absolute path to resulting file.
409  */
410 std::string FieldIO::SetUpOutput(const std::string outname, bool perRank, bool backup)
411 {
412  ASSERTL0(!outname.empty(), "Empty path given to SetUpOutput()");
413 
414  // Create a hash from the filename
415  std::size_t file_id = std::hash<std::string>{}(outname);
416 
417  // Find the minimum and maximum hash for each process
418  std::size_t file_id_max {file_id};
419  std::size_t file_id_min {file_id};
420  m_comm->AllReduce(file_id_max, ReduceMax);
421  m_comm->AllReduce(file_id_min, ReduceMin);
422 
423  // Check that each process has the same filename (hash)
424  ASSERTL0(file_id_min == file_id_max,
425  "All processes do not have the same filename.");
426 
427  int nprocs = m_comm->GetSize();
428  bool root = m_comm->TreatAsRankZero();
429 
430  // Path to output: will be directory if parallel, normal file if
431  // serial.
432  fs::path specPath(outname), fulloutname;
433 
434  // in case we are rank 0 or not on a shared filesystem, check if the specPath already exists
435  if (backup && (root || !m_sharedFilesystem) && fs::exists(specPath))
436  {
437  // rename. foo/bar_123.chk -> foo/bar_123.bak0.chk and in case
438  // foo/bar_123.bak0.chk already exists, foo/bar_123.chk -> 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 }
828 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#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:268
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:226
static std::shared_ptr< FieldIO > CreateDefault(const LibUtilities::SessionReaderSharedPtr session)
Returns an object for the default FieldIO method.
Definition: FieldIO.cpp:195
std::string SetUpOutput(const std::string outname, bool perRank, bool backup=false)
Set up the filesystem ready for output.
Definition: FieldIO.cpp:410
LibUtilities::CommSharedPtr m_comm
Communicator to use when writing parallel format.
Definition: FieldIO.h:266
FieldIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem)
Constructor for FieldIO base class.
Definition: FieldIO.cpp:327
static void AddInfoTag(TagWriterSharedPtr root, const FieldMetaDataMap &fieldmetadatamap)
Add provenance information to the field metadata map.
Definition: FieldIO.cpp:348
virtual std::string GetFileEnding() const
Helper function that determines default file extension.
Definition: FieldIO.h:276
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:145
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:61
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:287
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:240
int getNumberOfCoefficients(int Na, int Nb, int Nc)
Definition: ShapeType.hpp:194
int getNumberOfCoefficients(int Na, int Nb)
Definition: ShapeType.hpp:113
FieldIOType
Enumerator for auto-detection of FieldIO types.
Definition: FieldIO.cpp:79
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:293
std::shared_ptr< TagWriter > TagWriterSharedPtr
Definition: FieldIO.h:69
std::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:306
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:179
std::string fldCmdFormat
Definition: FieldIO.cpp:66
FieldIOFactory & GetFieldIOFactory()
Returns the FieldIO factory.
Definition: FieldIO.cpp:72
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:249
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