Lemma is an Electromagnetics API
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

RectilinearGrid.h 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. // ==================== OPERATORS =======================
  69. // ==================== OPERATIONS =======================
  70. /**
  71. * Sets the dimensions in x, y and z
  72. * @param[in] nx is the number of cells in x
  73. * @param[in] ny is the number of cells in y
  74. * @param[in] nz is the number of cells in z
  75. */
  76. void SetDimensions (const int &nx, const int &ny, const int &nz);
  77. /**
  78. * Sets the offset in x, y and z. This sets the corner position of the top SW corner.
  79. * @param[in] ox is the number of cells in x
  80. * @param[in] oy is the number of cells in y
  81. * @param[in] oz is the number of cells in z
  82. */
  83. void SetOffset (const Real &ox, const Real &oy, const Real &oz);
  84. /**
  85. * Sets the spacing in x, y and z
  86. * @param[in] dx is a Vector of cell spacing in x, must be same
  87. * size ad nx
  88. * @param[in] dy is a Vector of cell spacing in x, must be same
  89. * size ad ny
  90. * @param[in] dz is a Vector of cell spacing in x, must be same
  91. * size ad nz
  92. */
  93. void SetSpacing (const VectorXr &dx, const VectorXr &dy,
  94. const VectorXr &dz);
  95. // ==================== ACCESS =======================
  96. /** Returns the number of cells in x
  97. * @return number of cells in x
  98. */
  99. int GetNx();
  100. /** Returns the number of cells in y
  101. * @return number of cells in y
  102. */
  103. int GetNy();
  104. /** Returns the number of cells in z
  105. * @return number of cells in z
  106. */
  107. int GetNz();
  108. /** Returns the offset of cells in x
  109. * @return offset of cells in x
  110. */
  111. Real GetOx();
  112. /** Returns the number of cells in y
  113. * @return number of cells in y
  114. */
  115. Real GetOy();
  116. /** Returns the offset of cells in z
  117. * @return offset of cells in z
  118. */
  119. Real GetOz();
  120. /** Returns Spacing Vector
  121. * @return dx
  122. */
  123. VectorXr GetDx();
  124. /** Returns a spacing
  125. * @return dx[ix]
  126. */
  127. Real GetDx(const int& ix);
  128. /** Returns Spacing Vector
  129. * @return dy
  130. */
  131. VectorXr GetDy();
  132. /** Returns a spacing
  133. * @return dy[iy]
  134. */
  135. Real GetDy(const int& iy);
  136. /** Returns Spacing Vector
  137. * @return dz
  138. */
  139. VectorXr GetDz();
  140. /** Returns Spacing Vector
  141. * @return dz[iz]
  142. */
  143. Real GetDz(const int& iz);
  144. // ==================== INQUIRY =======================
  145. /** Returns the name of the underlying class, similiar to Python's type */
  146. virtual std::string GetName() const;
  147. protected:
  148. // ==================== LIFECYCLE =======================
  149. private:
  150. /** ASCII string representation of the class name */
  151. static constexpr auto CName = "RectilinearGrid";
  152. // ==================== DATA MEMBERS =========================
  153. /// Number of cells in the x dimension
  154. int nx;
  155. /// Number of cells in the y dimension
  156. int ny;
  157. /// Number of cells in the z dimension
  158. int nz;
  159. /// Grid offset in x dimension
  160. Real ox;
  161. /// Grid offset in y dimension
  162. Real oy;
  163. /// Grid offset in z dimension
  164. Real oz;
  165. /// Cell spacing in the x dimension
  166. VectorXr dx;
  167. /// Cell spacing in the y dimension
  168. VectorXr dy;
  169. /// Cell spacing in the z dimension
  170. VectorXr dz;
  171. }; // ----- end of class RectilinearGrid -----
  172. } // ----- end of Lemma name -----
  173. #endif // ----- #ifndef RECTILINEARGRID_INC -----
  174. /* vim: set tabstop=4 expandtab: */
  175. /* vim: set filetype=cpp syntax=cpp.doxygen: */