Main Lemma Repository
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RectilinearGrid.h 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. @file
  7. @author Trevor Irons
  8. @date 10/28/2010
  9. @version $Id: rectilineargrid.h 193 2014-11-10 23:51:41Z tirons $
  10. **/
  11. #ifndef RECTILINEARGRID_INC
  12. #define RECTILINEARGRID_INC
  13. #include "Grid.h"
  14. namespace Lemma {
  15. /**
  16. * \ingroup LemmaCore
  17. * \brief Impliments a rectilinear grid.
  18. * \details A rectilinear grid can vary regularily in space but must be
  19. * constant variation across each dimension. In this way three
  20. * vectors can define the entire grid, and each cell is right
  21. * aligned with all its neighbours.
  22. */
  23. class RectilinearGrid : public Grid {
  24. friend std::ostream &operator<<(std::ostream &stream,
  25. const RectilinearGrid &ob);
  26. /*
  27. * This key is used to lock the constructors
  28. */
  29. //struct ctor_key {};
  30. public:
  31. // ==================== LIFECYCLE =======================
  32. /**
  33. * DeSerializing constructor.
  34. * @note This method is locked, and cannot be called directly.
  35. * The reason that the method is public is to enable the use
  36. * of make_shared whilst enforcing the use of shared_ptr,
  37. * in c++-17, this curiosity may be resolved.
  38. * @see RectilinearGrid::NewSP
  39. */
  40. explicit RectilinearGrid ( 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 RectilinearGrid (const YAML::Node& node, const ctor_key& );
  50. /** Default destructor.
  51. * @note This should never be called explicitly, use NewSP
  52. */
  53. virtual ~RectilinearGrid ();
  54. /**
  55. * Uses YAML to serialize this object.
  56. * @return a YAML::Node
  57. */
  58. virtual YAML::Node Serialize() const;
  59. /**
  60. * Factory method for generating concrete class.
  61. * @return a std::shared_ptr of type RectilinearGrid
  62. */
  63. static std::shared_ptr<RectilinearGrid> NewSP();
  64. /**
  65. * Constructs an object from a YAML::Node.
  66. */
  67. static std::shared_ptr< RectilinearGrid > DeSerialize(const YAML::Node& node);
  68. /**
  69. * Constructs an object from a string representation of a YAML::Node. This is primarily
  70. * used in Python wrapping
  71. */
  72. static std::shared_ptr<RectilinearGrid> DeSerialize( const std::string& node ) {
  73. return RectilinearGrid::DeSerialize(YAML::LoadFile(node));
  74. }
  75. // ==================== OPERATORS =======================
  76. // ==================== OPERATIONS =======================
  77. /**
  78. * Sets the dimensions in x, y and z
  79. * @param[in] nx is the number of cells in x
  80. * @param[in] ny is the number of cells in y
  81. * @param[in] nz is the number of cells in z
  82. */
  83. void SetDimensions (const int &nx, const int &ny, const int &nz);
  84. /**
  85. * Sets the offset in x, y and z. This sets the corner position of the top SW corner.
  86. * @param[in] ox is the number of cells in x
  87. * @param[in] oy is the number of cells in y
  88. * @param[in] oz is the number of cells in z
  89. */
  90. void SetOffset (const Real &ox, const Real &oy, const Real &oz);
  91. /**
  92. * Sets the spacing in x, y and z
  93. * @param[in] dx is a Vector of cell spacing in x, must be same
  94. * size ad nx
  95. * @param[in] dy is a Vector of cell spacing in x, must be same
  96. * size ad ny
  97. * @param[in] dz is a Vector of cell spacing in x, must be same
  98. * size ad nz
  99. */
  100. void SetSpacing (const VectorXr &dx, const VectorXr &dy,
  101. const VectorXr &dz);
  102. // ==================== ACCESS =======================
  103. /** Returns the number of cells in x
  104. * @return number of cells in x
  105. */
  106. int GetNx();
  107. /** Returns the number of cells in y
  108. * @return number of cells in y
  109. */
  110. int GetNy();
  111. /** Returns the number of cells in z
  112. * @return number of cells in z
  113. */
  114. int GetNz();
  115. /** Returns the offset of cells in x
  116. * @return offset of cells in x
  117. */
  118. Real GetOx();
  119. /** Returns the number of cells in y
  120. * @return number of cells in y
  121. */
  122. Real GetOy();
  123. /** Returns the offset of cells in z
  124. * @return offset of cells in z
  125. */
  126. Real GetOz();
  127. /** Returns Spacing Vector
  128. * @return dx
  129. */
  130. VectorXr GetDx();
  131. /** Returns a spacing
  132. * @return dx[ix]
  133. */
  134. Real GetDx1(const int& ix);
  135. /** Returns Spacing Vector
  136. * @return dy
  137. */
  138. VectorXr GetDy();
  139. /** Returns a spacing
  140. * @return dy[iy]
  141. */
  142. Real GetDy1(const int& iy);
  143. /** Returns Spacing Vector
  144. * @return dz
  145. */
  146. VectorXr GetDz();
  147. /** Returns Spacing Vector
  148. * @return dz[iz]
  149. */
  150. Real GetDz1(const int& iz);
  151. // ==================== INQUIRY =======================
  152. /** Returns the name of the underlying class, similiar to Python's type */
  153. virtual std::string GetName() const;
  154. protected:
  155. // ==================== LIFECYCLE =======================
  156. private:
  157. /** ASCII string representation of the class name */
  158. static constexpr auto CName = "RectilinearGrid";
  159. // ==================== DATA MEMBERS =========================
  160. /// Number of cells in the x dimension
  161. int nx;
  162. /// Number of cells in the y dimension
  163. int ny;
  164. /// Number of cells in the z dimension
  165. int nz;
  166. /// Grid offset in x dimension
  167. Real ox;
  168. /// Grid offset in y dimension
  169. Real oy;
  170. /// Grid offset in z dimension
  171. Real oz;
  172. /// Cell spacing in the x dimension
  173. VectorXr dx;
  174. /// Cell spacing in the y dimension
  175. VectorXr dy;
  176. /// Cell spacing in the z dimension
  177. VectorXr dz;
  178. }; // ----- end of class RectilinearGrid -----
  179. } // ----- end of Lemma name -----
  180. #endif // ----- #ifndef RECTILINEARGRID_INC -----
  181. /* vim: set tabstop=4 expandtab: */
  182. /* vim: set filetype=cpp syntax=cpp.doxygen */