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.cpp 8.0KB

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.cpp 193 2014-11-10 23:51:41Z tirons $
  10. **/
  11. #include "RectilinearGrid.h"
  12. namespace Lemma {
  13. std::ostream &operator << (std::ostream &stream, const RectilinearGrid &ob) {
  14. stream << ob.Serialize() << "\n---\n"; // End of doc
  15. return stream;
  16. }
  17. // ==================== LIFECYCLE =======================
  18. RectilinearGrid::RectilinearGrid( const ctor_key& key ) : Grid( key ), nx(0), ny(0), nz(0) {
  19. }
  20. RectilinearGrid::RectilinearGrid( const YAML::Node& node, const ctor_key& key ) : Grid(node, key) {
  21. nx = node["nx"].as<int>( );
  22. ny = node["ny"].as<int>( );
  23. nz = node["nz"].as<int>( );
  24. ox = node["ox"].as<Real>( );
  25. oy = node["oy"].as<Real>( );
  26. oz = node["oz"].as<Real>( );
  27. dx = node["dx"].as< VectorXr >();
  28. dy = node["dy"].as< VectorXr >();
  29. dz = node["dz"].as< VectorXr >();
  30. }
  31. RectilinearGrid::~RectilinearGrid() {
  32. }
  33. std::shared_ptr< RectilinearGrid > RectilinearGrid::NewSP() {
  34. return std::make_shared< RectilinearGrid > ( ctor_key() );
  35. }
  36. YAML::Node RectilinearGrid::Serialize() const {
  37. YAML::Node node = Grid::Serialize();
  38. node["nx"] = nx;
  39. node["ny"] = ny;
  40. node["nz"] = nz;
  41. node["ox"] = ox;
  42. node["oy"] = oy;
  43. node["oz"] = oz;
  44. node["dx"] = dx;
  45. node["dy"] = dy;
  46. node["dz"] = dz;
  47. node.SetTag( this->GetName() );
  48. return node;
  49. }
  50. //--------------------------------------------------------------------------------------
  51. // Class: RectilinearGrid
  52. // Method: DeSerialize
  53. //--------------------------------------------------------------------------------------
  54. std::shared_ptr<RectilinearGrid> RectilinearGrid::DeSerialize ( const YAML::Node& node ) {
  55. if (node.Tag() != "RectilinearGrid") {
  56. throw DeSerializeTypeMismatch( "RectilinearGrid", node.Tag());
  57. }
  58. return std::make_shared< RectilinearGrid > ( node, ctor_key() );
  59. }
  60. //--------------------------------------------------------------------------------------
  61. // Class: RectilinearGrid
  62. // Method: GetName
  63. // Description: Class identifier
  64. //--------------------------------------------------------------------------------------
  65. inline std::string RectilinearGrid::GetName ( ) const {
  66. return CName;
  67. } // ----- end of method RectilinearGrid::get_GetName -----
  68. // ==================== OPERATIONS =======================
  69. void RectilinearGrid::SetDimensions (const int &inx, const int &iny,
  70. const int &inz) {
  71. dx.resize(inx);
  72. dy.resize(iny);
  73. dz.resize(inz);
  74. nx = inx;
  75. ny = iny;
  76. nz = inz;
  77. }
  78. void RectilinearGrid::SetOffset (const Real& iox, const Real& ioy, const Real& ioz) {
  79. ox = iox;
  80. oy = ioy;
  81. oz = ioz;
  82. }
  83. void RectilinearGrid::SetSpacing (const VectorXr &idx, const VectorXr &idy,
  84. const VectorXr &idz) {
  85. nx = idx.size();
  86. ny = idy.size();
  87. nz = idz.size();
  88. dx = idx;
  89. dy = idy;
  90. dz = idz;
  91. }
  92. //--------------------------------------------------------------------------------------
  93. // Class: RectilinearGrid
  94. // Method: GetNx
  95. //--------------------------------------------------------------------------------------
  96. int RectilinearGrid::GetNx ( ) {
  97. return nx;
  98. } // ----- end of method RectilinearGrid::GetNx -----
  99. //--------------------------------------------------------------------------------------
  100. // Class: RectilinearGrid
  101. // Method: GetNy
  102. //--------------------------------------------------------------------------------------
  103. int RectilinearGrid::GetNy ( ) {
  104. return ny;
  105. } // ----- end of method RectilinearGrid::GetNy -----
  106. //--------------------------------------------------------------------------------------
  107. // Class: RectilinearGrid
  108. // Method: GetNz
  109. //--------------------------------------------------------------------------------------
  110. int RectilinearGrid::GetNz ( ) {
  111. return nz;
  112. } // ----- end of method RectilinearGrid::GetNz -----
  113. //--------------------------------------------------------------------------------------
  114. // Class: RectilinearGrid
  115. // Method: GetOx
  116. //--------------------------------------------------------------------------------------
  117. Real RectilinearGrid::GetOx ( ) {
  118. return ox;
  119. } // ----- end of method RectilinearGrid::GetOx -----
  120. //--------------------------------------------------------------------------------------
  121. // Class: RectilinearGrid
  122. // Method: GetOy
  123. //--------------------------------------------------------------------------------------
  124. Real RectilinearGrid::GetOy ( ) {
  125. return oy;
  126. } // ----- end of method RectilinearGrid::GetOy -----
  127. //--------------------------------------------------------------------------------------
  128. // Class: RectilinearGrid
  129. // Method: GetOz
  130. //--------------------------------------------------------------------------------------
  131. Real RectilinearGrid::GetOz ( ) {
  132. return oz;
  133. } // ----- end of method RectilinearGrid::GetOz -----
  134. //--------------------------------------------------------------------------------------
  135. // Class: RectilinearGrid
  136. // Method: GetDx
  137. //--------------------------------------------------------------------------------------
  138. VectorXr RectilinearGrid::GetDx ( ) {
  139. return dx;
  140. } // ----- end of method RectilinearGrid::GetDx -----
  141. //--------------------------------------------------------------------------------------
  142. // Class: RectilinearGrid
  143. // Method: GetDx
  144. //--------------------------------------------------------------------------------------
  145. Real RectilinearGrid::GetDx ( const int& ix ) {
  146. return dx[ix];
  147. } // ----- end of method RectilinearGrid::GetDx -----
  148. //--------------------------------------------------------------------------------------
  149. // Class: RectilinearGrid
  150. // Method: GetDy
  151. //--------------------------------------------------------------------------------------
  152. VectorXr RectilinearGrid::GetDy ( ) {
  153. return dy;
  154. } // ----- end of method RectilinearGrid::GetDy -----
  155. //--------------------------------------------------------------------------------------
  156. // Class: RectilinearGrid
  157. // Method: GetDy
  158. //--------------------------------------------------------------------------------------
  159. Real RectilinearGrid::GetDy ( const int& iy ) {
  160. return dy[iy];
  161. } // ----- end of method RectilinearGrid::GetDy -----
  162. //--------------------------------------------------------------------------------------
  163. // Class: RectilinearGrid
  164. // Method: GetDz
  165. //--------------------------------------------------------------------------------------
  166. VectorXr RectilinearGrid::GetDz ( ) {
  167. return dz;
  168. } // ----- end of method RectilinearGrid::GetDz -----
  169. //--------------------------------------------------------------------------------------
  170. // Class: RectilinearGrid
  171. // Method: GetDz
  172. //--------------------------------------------------------------------------------------
  173. Real RectilinearGrid::GetDz ( const int& iz ) {
  174. return dz[iz];
  175. } // ----- end of method RectilinearGrid::GetDz -----
  176. } // ----- end of Lemma name -----
  177. /* vim: set tabstop=4 expandtab: */
  178. /* vim: set filetype=cpp: syntax=cpp.doxygen*/