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

RectilinearGrid.h 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. // Class: RectilinearGrid
  17. /**
  18. @class
  19. \ingroup LemmaCore
  20. \brief Impliments a rectilinear grid.
  21. \details A rectilinear grid can vary regularily in space but must be
  22. constant variation across each dimension. In this way three
  23. vectors can define the entire grid, and each cell is right
  24. aligned with all its neighbours.
  25. */
  26. // ===================================================================
  27. class RectilinearGrid : public Grid {
  28. friend std::ostream &operator<<(std::ostream &stream,
  29. const RectilinearGrid &ob);
  30. /*
  31. * This key is used to lock the constructors
  32. */
  33. struct ctor_key {};
  34. public:
  35. // ==================== LIFECYCLE =======================
  36. /**
  37. * Factory method for generating concrete class.
  38. * @return a std::shared_ptr of type RectilinearGrid
  39. */
  40. static std::shared_ptr<RectilinearGrid> NewSP();
  41. /**
  42. * Uses YAML to serialize this object.
  43. * @return a YAML::Node
  44. */
  45. virtual YAML::Node Serialize() const;
  46. /**
  47. * Constructs an object from a YAML::Node.
  48. */
  49. static std::shared_ptr< RectilinearGrid > DeSerialize(const YAML::Node& node);
  50. // ==================== OPERATORS =======================
  51. // ==================== OPERATIONS =======================
  52. /**
  53. * Sets the dimensions in x, y and z
  54. * @param[in] nx is the number of cells in x
  55. * @param[in] ny is the number of cells in y
  56. * @param[in] nz is the number of cells in z
  57. */
  58. void SetDimensions (const int &nx, const int &ny, const int &nz);
  59. /**
  60. * Sets the offset in x, y and z. This sets the corner position of the top SW corner.
  61. * @param[in] ox is the number of cells in x
  62. * @param[in] oy is the number of cells in y
  63. * @param[in] oz is the number of cells in z
  64. */
  65. void SetOffset (const Real &ox, const Real &oy, const Real &oz);
  66. /**
  67. * Sets the spacing in x, y and z
  68. * @param[in] dx is a Vector of cell spacing in x, must be same
  69. * size ad nx
  70. * @param[in] dy is a Vector of cell spacing in x, must be same
  71. * size ad ny
  72. * @param[in] dz is a Vector of cell spacing in x, must be same
  73. * size ad nz
  74. */
  75. void SetSpacing (const VectorXr &dx, const VectorXr &dy,
  76. const VectorXr &dz);
  77. // ==================== ACCESS =======================
  78. /** Returns the number of cells in x
  79. * @return number of cells in x
  80. */
  81. int GetNx();
  82. /** Returns the number of cells in y
  83. * @return number of cells in y
  84. */
  85. int GetNy();
  86. /** Returns the number of cells in z
  87. * @return number of cells in z
  88. */
  89. int GetNz();
  90. /** Returns the offset of cells in x
  91. * @return offset of cells in x
  92. */
  93. Real GetOx();
  94. /** Returns the number of cells in y
  95. * @return number of cells in y
  96. */
  97. Real GetOy();
  98. /** Returns the offset of cells in z
  99. * @return offset of cells in z
  100. */
  101. Real GetOz();
  102. /** Returns Spacing Vector
  103. * @return dx
  104. */
  105. VectorXr GetDx();
  106. /** Returns a spacing
  107. * @return dx[ix]
  108. */
  109. Real GetDx(const int& ix);
  110. /** Returns Spacing Vector
  111. * @return dy
  112. */
  113. VectorXr GetDy();
  114. /** Returns a spacing
  115. * @return dy[iy]
  116. */
  117. Real GetDy(const int& iy);
  118. /** Returns Spacing Vector
  119. * @return dz
  120. */
  121. VectorXr GetDz();
  122. /** Returns Spacing Vector
  123. * @return dz[iz]
  124. */
  125. Real GetDz(const int& iz);
  126. // ==================== INQUIRY =======================
  127. /** Returns the name of the underlying class, similiar to Python's type */
  128. virtual inline std::string GetName() const {
  129. return this->CName;
  130. }
  131. protected:
  132. // ==================== LIFECYCLE =======================
  133. /** Default protected constructor. */
  134. RectilinearGrid ( );
  135. /** Protected DeDerializing constructor, use factory DeSerialize method*/
  136. RectilinearGrid (const YAML::Node& node);
  137. /** Default protected constructor. */
  138. ~RectilinearGrid ();
  139. // ==================== DATA MEMBERS =========================
  140. /// Number of cells in the x dimension
  141. int nx;
  142. /// Number of cells in the y dimension
  143. int ny;
  144. /// Number of cells in the z dimension
  145. int nz;
  146. /// Grid offset in x dimension
  147. Real ox;
  148. /// Grid offset in y dimension
  149. Real oy;
  150. /// Grid offset in z dimension
  151. Real oz;
  152. /// Cell spacing in the x dimension
  153. VectorXr dx;
  154. /// Cell spacing in the y dimension
  155. VectorXr dy;
  156. /// Cell spacing in the z dimension
  157. VectorXr dz;
  158. private:
  159. /** ASCII string representation of the class name */
  160. static constexpr auto CName = "RectilinearGrid";
  161. }; // ----- end of class RectilinearGrid -----
  162. } // ----- end of Lemma name -----
  163. #endif // ----- #ifndef RECTILINEARGRID_INC -----
  164. /* vim: set tabstop=4 expandtab: */
  165. /* vim: set filetype=cpp: */