Lemma is an Electromagnetics API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RectilinearGrid.h 6.4KB

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