Lemma is an Electromagnetics API
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

RectilinearGridReader.h 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* This file is part of Lemma, a geophysical modelling and inversion API */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. */
  6. /**
  7. @file
  8. @date 09/23/2013 11:05:11 AM
  9. @version $Id$
  10. @author Trevor Irons (ti)
  11. @email Trevor.Irons@xri-geo.com
  12. @copyright Copyright (c) 2013, XRI Geophysics, LLC
  13. @copyright Copyright (c) 2013, Trevor Irons
  14. **/
  15. #ifndef RECTILINEARGRIDREADER_INC
  16. #define RECTILINEARGRIDREADER_INC
  17. #include "GridReader.h"
  18. #include "RectilinearGrid.h"
  19. #include "ASCIIParser.h"
  20. namespace Lemma {
  21. /**
  22. \ingroup LemmaCore
  23. \brief Base Class for rectilinear grid reader data files
  24. \details
  25. \todo this set of classes is deprecated, use serialize methods!
  26. */
  27. class RectilinearGridReader : public GridReader {
  28. friend std::ostream &operator<<(std::ostream &stream,
  29. const RectilinearGridReader &ob);
  30. /*
  31. * This key is used to lock the constructors
  32. */
  33. //struct ctor_key {};
  34. public:
  35. // ==================== LIFECYCLE =======================
  36. /** Default constructor
  37. * @note This method is locked
  38. * @see NewSP
  39. */
  40. explicit RectilinearGridReader ( const ctor_key& );
  41. /**
  42. * DeSerializing constructor.
  43. * @note This method is locked, and cannot be called directly.
  44. * The reason that the method is public is to enable the use
  45. * of make_shared whilst enforcing the use of shared_ptr,
  46. * in c++-17, this curiosity may be resolved.
  47. * @see DeSerialize
  48. */
  49. explicit RectilinearGridReader ( const YAML::Node& node, const ctor_key& );
  50. /** Default destructor.
  51. * @note This should never be called explicitly, use NewSP
  52. */
  53. ~RectilinearGridReader ( );
  54. /**
  55. * Factory method for generating concrete class.
  56. * @return a std::shared_ptr of type RectilinearGridReader
  57. */
  58. static std::shared_ptr< RectilinearGridReader > NewSP();
  59. /**
  60. * Constructs an object from a YAML serialization
  61. * @return a std::shared_ptr of type RectilinearGridReader
  62. */
  63. static std::shared_ptr< RectilinearGridReader > DeSerialize( const YAML::Node& node );
  64. /**
  65. * Constructs an object from a string representation of a YAML::Node. This is primarily
  66. * used in Python wrapping
  67. */
  68. static std::shared_ptr<RectilinearGridReader> DeSerialize( const std::string& node ) {
  69. return RectilinearGridReader::DeSerialize(YAML::LoadFile(node));
  70. }
  71. /**
  72. * Uses YAML to serialize this object.
  73. * @return a YAML::Node
  74. */
  75. virtual YAML::Node Serialize() const;
  76. // ==================== OPERATORS =======================
  77. // ==================== OPERATIONS =======================
  78. /**
  79. Reads a .mod file, a simple representation of the grid. These files
  80. have the following format:
  81. @verbatim
  82. nx ny nz // number of cells in x, y, and z
  83. ox oy oz // grid offset of top SW corner
  84. hx[0] hx[1] ... hx[nx-1] // grid cell spacing in x, from 0 to nx-1
  85. hy[0] hy[1] ... hy[ny-1] // grid cell spacing in y, from 0 to ny-1
  86. hz[0] hz[1] ... hz[nz-1] // grid cell spacing in z, from 0 to nz-1
  87. // c++ style (//) comments are allowed anywhere, c-style are not
  88. @endverbatim
  89. */
  90. void ReadASCIIGridFile( const std::string& name );
  91. // ==================== ACCESS =======================
  92. /**
  93. * Accessor method for the underlying RectilinearGrid class constructed
  94. * from the input file.
  95. */
  96. virtual std::shared_ptr<Grid> GetGrid() const ;
  97. // ==================== INQUIRY =======================
  98. /** Returns the name of the underlying class, similiar to Python's type */
  99. virtual std::string GetName() const ;
  100. protected:
  101. // ==================== LIFECYCLE =======================
  102. private:
  103. // ==================== DATA MEMBERS =========================
  104. /** ASCII string representation of the class name */
  105. static constexpr auto CName = "RectilinearGridReader";
  106. /** Object holding constructed Grid */
  107. std::shared_ptr<RectilinearGrid> rGrid;
  108. /** Performs actual file parsing */
  109. std::shared_ptr<ASCIIParser> Parser;
  110. }; // ----- end of class RectilinearGridReader -----
  111. } // ----- end of Lemma name -----
  112. #endif // ----- #ifndef RECTILINEARGRIDREADER_INC -----
  113. /* vim: set tabstop=4 expandtab: */
  114. /* vim: set filetype=cpp syntax=cpp.doxygen: */