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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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";
  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. // MSVC doens't allow static_cast here
  86. //nx = std::static_cast<int>( idx.size() );
  87. //ny = std::static_cast<int>( idy.size() );
  88. //nz = std::static_cast<int>( idz.size() );
  89. nx = (int)( idx.size() );
  90. ny = (int)( idy.size() );
  91. nz = (int)( idz.size() );
  92. dx = idx;
  93. dy = idy;
  94. dz = idz;
  95. }
  96. //--------------------------------------------------------------------------------------
  97. // Class: RectilinearGrid
  98. // Method: GetNx
  99. //--------------------------------------------------------------------------------------
  100. int RectilinearGrid::GetNx ( ) {
  101. return nx;
  102. } // ----- end of method RectilinearGrid::GetNx -----
  103. //--------------------------------------------------------------------------------------
  104. // Class: RectilinearGrid
  105. // Method: GetNy
  106. //--------------------------------------------------------------------------------------
  107. int RectilinearGrid::GetNy ( ) {
  108. return ny;
  109. } // ----- end of method RectilinearGrid::GetNy -----
  110. //--------------------------------------------------------------------------------------
  111. // Class: RectilinearGrid
  112. // Method: GetNz
  113. //--------------------------------------------------------------------------------------
  114. int RectilinearGrid::GetNz ( ) {
  115. return nz;
  116. } // ----- end of method RectilinearGrid::GetNz -----
  117. //--------------------------------------------------------------------------------------
  118. // Class: RectilinearGrid
  119. // Method: GetOx
  120. //--------------------------------------------------------------------------------------
  121. Real RectilinearGrid::GetOx ( ) {
  122. return ox;
  123. } // ----- end of method RectilinearGrid::GetOx -----
  124. //--------------------------------------------------------------------------------------
  125. // Class: RectilinearGrid
  126. // Method: GetOy
  127. //--------------------------------------------------------------------------------------
  128. Real RectilinearGrid::GetOy ( ) {
  129. return oy;
  130. } // ----- end of method RectilinearGrid::GetOy -----
  131. //--------------------------------------------------------------------------------------
  132. // Class: RectilinearGrid
  133. // Method: GetOz
  134. //--------------------------------------------------------------------------------------
  135. Real RectilinearGrid::GetOz ( ) {
  136. return oz;
  137. } // ----- end of method RectilinearGrid::GetOz -----
  138. //--------------------------------------------------------------------------------------
  139. // Class: RectilinearGrid
  140. // Method: GetDx
  141. //--------------------------------------------------------------------------------------
  142. VectorXr RectilinearGrid::GetDx ( ) {
  143. return dx;
  144. } // ----- end of method RectilinearGrid::GetDx -----
  145. //--------------------------------------------------------------------------------------
  146. // Class: RectilinearGrid
  147. // Method: GetDx
  148. //--------------------------------------------------------------------------------------
  149. Real RectilinearGrid::GetDx1 ( const int& ix ) {
  150. return dx[ix];
  151. } // ----- end of method RectilinearGrid::GetDx -----
  152. //--------------------------------------------------------------------------------------
  153. // Class: RectilinearGrid
  154. // Method: GetDy
  155. //--------------------------------------------------------------------------------------
  156. VectorXr RectilinearGrid::GetDy ( ) {
  157. return dy;
  158. } // ----- end of method RectilinearGrid::GetDy -----
  159. //--------------------------------------------------------------------------------------
  160. // Class: RectilinearGrid
  161. // Method: GetDy
  162. //--------------------------------------------------------------------------------------
  163. Real RectilinearGrid::GetDy1 ( const int& iy ) {
  164. return dy[iy];
  165. } // ----- end of method RectilinearGrid::GetDy -----
  166. //--------------------------------------------------------------------------------------
  167. // Class: RectilinearGrid
  168. // Method: GetDz
  169. //--------------------------------------------------------------------------------------
  170. VectorXr RectilinearGrid::GetDz ( ) {
  171. return dz;
  172. } // ----- end of method RectilinearGrid::GetDz -----
  173. //--------------------------------------------------------------------------------------
  174. // Class: RectilinearGrid
  175. // Method: GetDz
  176. //--------------------------------------------------------------------------------------
  177. Real RectilinearGrid::GetDz1 ( const int& iz ) {
  178. return dz[iz];
  179. } // ----- end of method RectilinearGrid::GetDz -----
  180. } // ----- end of Lemma name -----
  181. /* vim: set tabstop=4 expandtab: */
  182. /* vim: set filetype=cpp: syntax=cpp.doxygen*/