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 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 --- as a direct stream should encapulste thingy
  15. return stream;
  16. }
  17. // ==================== LIFECYCLE =======================
  18. RectilinearGrid::RectilinearGrid( ) : Grid( ), nx(0), ny(0), nz(0) {
  19. }
  20. RectilinearGrid::RectilinearGrid( const YAML::Node& node ) : Grid(node) {
  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. std::shared_ptr<RectilinearGrid> sp(new RectilinearGrid( ), LemmaObjectDeleter() );
  35. return sp;
  36. }
  37. YAML::Node RectilinearGrid::Serialize() const {
  38. YAML::Node node = Grid::Serialize();
  39. node["nx"] = nx;
  40. node["ny"] = ny;
  41. node["nz"] = nz;
  42. node["ox"] = ox;
  43. node["oy"] = oy;
  44. node["oz"] = oz;
  45. node["dx"] = dx;
  46. node["dy"] = dy;
  47. node["dz"] = dz;
  48. node.SetTag( this->GetName() );
  49. return node;
  50. }
  51. //--------------------------------------------------------------------------------------
  52. // Class: RectilinearGrid
  53. // Method: DeSerialize
  54. //--------------------------------------------------------------------------------------
  55. std::shared_ptr<RectilinearGrid> RectilinearGrid::DeSerialize ( const YAML::Node& node ) {
  56. if (node.Tag() != "RectilinearGrid") {
  57. throw DeSerializeTypeMismatch( "RectilinearGrid", node.Tag());
  58. }
  59. std::shared_ptr<RectilinearGrid> Object(new RectilinearGrid(node), LemmaObjectDeleter() );
  60. return Object ;
  61. }
  62. // ==================== OPERATIONS =======================
  63. void RectilinearGrid::SetDimensions (const int &inx, const int &iny,
  64. const int &inz) {
  65. dx.resize(inx);
  66. dy.resize(iny);
  67. dz.resize(inz);
  68. nx = inx;
  69. ny = iny;
  70. nz = inz;
  71. }
  72. void RectilinearGrid::SetOffset (const Real& iox, const Real& ioy, const Real& ioz) {
  73. ox = iox;
  74. oy = ioy;
  75. oz = ioz;
  76. }
  77. void RectilinearGrid::SetSpacing (const VectorXr &idx, const VectorXr &idy,
  78. const VectorXr &idz) {
  79. nx = idx.size();
  80. ny = idy.size();
  81. nz = idz.size();
  82. dx = idx;
  83. dy = idy;
  84. dz = idz;
  85. }
  86. //--------------------------------------------------------------------------------------
  87. // Class: RectilinearGrid
  88. // Method: GetNx
  89. //--------------------------------------------------------------------------------------
  90. int RectilinearGrid::GetNx ( ) {
  91. return nx;
  92. } // ----- end of method RectilinearGrid::GetNx -----
  93. //--------------------------------------------------------------------------------------
  94. // Class: RectilinearGrid
  95. // Method: GetNy
  96. //--------------------------------------------------------------------------------------
  97. int RectilinearGrid::GetNy ( ) {
  98. return ny;
  99. } // ----- end of method RectilinearGrid::GetNy -----
  100. //--------------------------------------------------------------------------------------
  101. // Class: RectilinearGrid
  102. // Method: GetNz
  103. //--------------------------------------------------------------------------------------
  104. int RectilinearGrid::GetNz ( ) {
  105. return nz;
  106. } // ----- end of method RectilinearGrid::GetNz -----
  107. //--------------------------------------------------------------------------------------
  108. // Class: RectilinearGrid
  109. // Method: GetOx
  110. //--------------------------------------------------------------------------------------
  111. Real RectilinearGrid::GetOx ( ) {
  112. return ox;
  113. } // ----- end of method RectilinearGrid::GetOx -----
  114. //--------------------------------------------------------------------------------------
  115. // Class: RectilinearGrid
  116. // Method: GetOy
  117. //--------------------------------------------------------------------------------------
  118. Real RectilinearGrid::GetOy ( ) {
  119. return oy;
  120. } // ----- end of method RectilinearGrid::GetOy -----
  121. //--------------------------------------------------------------------------------------
  122. // Class: RectilinearGrid
  123. // Method: GetOz
  124. //--------------------------------------------------------------------------------------
  125. Real RectilinearGrid::GetOz ( ) {
  126. return oz;
  127. } // ----- end of method RectilinearGrid::GetOz -----
  128. //--------------------------------------------------------------------------------------
  129. // Class: RectilinearGrid
  130. // Method: GetDx
  131. //--------------------------------------------------------------------------------------
  132. VectorXr RectilinearGrid::GetDx ( ) {
  133. return dx;
  134. } // ----- end of method RectilinearGrid::GetDx -----
  135. //--------------------------------------------------------------------------------------
  136. // Class: RectilinearGrid
  137. // Method: GetDx
  138. //--------------------------------------------------------------------------------------
  139. Real RectilinearGrid::GetDx ( const int& ix ) {
  140. return dx[ix];
  141. } // ----- end of method RectilinearGrid::GetDx -----
  142. //--------------------------------------------------------------------------------------
  143. // Class: RectilinearGrid
  144. // Method: GetDy
  145. //--------------------------------------------------------------------------------------
  146. VectorXr RectilinearGrid::GetDy ( ) {
  147. return dy;
  148. } // ----- end of method RectilinearGrid::GetDy -----
  149. //--------------------------------------------------------------------------------------
  150. // Class: RectilinearGrid
  151. // Method: GetDy
  152. //--------------------------------------------------------------------------------------
  153. Real RectilinearGrid::GetDy ( const int& iy ) {
  154. return dy[iy];
  155. } // ----- end of method RectilinearGrid::GetDy -----
  156. //--------------------------------------------------------------------------------------
  157. // Class: RectilinearGrid
  158. // Method: GetDz
  159. //--------------------------------------------------------------------------------------
  160. VectorXr RectilinearGrid::GetDz ( ) {
  161. return dz;
  162. } // ----- end of method RectilinearGrid::GetDz -----
  163. //--------------------------------------------------------------------------------------
  164. // Class: RectilinearGrid
  165. // Method: GetDz
  166. //--------------------------------------------------------------------------------------
  167. Real RectilinearGrid::GetDz ( const int& iz ) {
  168. return dz[iz];
  169. } // ----- end of method RectilinearGrid::GetDz -----
  170. } // ----- end of Lemma name -----
  171. /* vim: set tabstop=4 expandtab: */
  172. /* vim: set filetype=cpp: */