Lemma is an Electromagnetics API
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

RectilinearGrid.cpp 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. std::string RectilinearGrid::Print() const {
  51. YAML::Emitter out;
  52. out << this->Serialize();
  53. return out.c_str();
  54. }
  55. //--------------------------------------------------------------------------------------
  56. // Class: RectilinearGrid
  57. // Method: DeSerialize
  58. //--------------------------------------------------------------------------------------
  59. std::shared_ptr<RectilinearGrid> RectilinearGrid::DeSerialize ( const YAML::Node& node ) {
  60. if (node.Tag() != "RectilinearGrid") {
  61. throw DeSerializeTypeMismatch( "RectilinearGrid", node.Tag());
  62. }
  63. return std::make_shared< RectilinearGrid > ( node, ctor_key() );
  64. }
  65. //--------------------------------------------------------------------------------------
  66. // Class: RectilinearGrid
  67. // Method: GetName
  68. // Description: Class identifier
  69. //--------------------------------------------------------------------------------------
  70. inline std::string RectilinearGrid::GetName ( ) const {
  71. return CName;
  72. } // ----- end of method RectilinearGrid::get_GetName -----
  73. // ==================== OPERATIONS =======================
  74. void RectilinearGrid::SetDimensions (const int &inx, const int &iny,
  75. const int &inz) {
  76. dx.resize(inx);
  77. dy.resize(iny);
  78. dz.resize(inz);
  79. nx = inx;
  80. ny = iny;
  81. nz = inz;
  82. }
  83. void RectilinearGrid::SetOffset (const Real& iox, const Real& ioy, const Real& ioz) {
  84. ox = iox;
  85. oy = ioy;
  86. oz = ioz;
  87. }
  88. void RectilinearGrid::SetSpacing (const VectorXr &idx, const VectorXr &idy,
  89. const VectorXr &idz) {
  90. // MSVC doens't allow static_cast here
  91. //nx = std::static_cast<int>( idx.size() );
  92. //ny = std::static_cast<int>( idy.size() );
  93. //nz = std::static_cast<int>( idz.size() );
  94. nx = (int)( idx.size() );
  95. ny = (int)( idy.size() );
  96. nz = (int)( idz.size() );
  97. dx = idx;
  98. dy = idy;
  99. dz = idz;
  100. }
  101. //--------------------------------------------------------------------------------------
  102. // Class: RectilinearGrid
  103. // Method: GetNx
  104. //--------------------------------------------------------------------------------------
  105. int RectilinearGrid::GetNx ( ) {
  106. return nx;
  107. } // ----- end of method RectilinearGrid::GetNx -----
  108. //--------------------------------------------------------------------------------------
  109. // Class: RectilinearGrid
  110. // Method: GetNy
  111. //--------------------------------------------------------------------------------------
  112. int RectilinearGrid::GetNy ( ) {
  113. return ny;
  114. } // ----- end of method RectilinearGrid::GetNy -----
  115. //--------------------------------------------------------------------------------------
  116. // Class: RectilinearGrid
  117. // Method: GetNz
  118. //--------------------------------------------------------------------------------------
  119. int RectilinearGrid::GetNz ( ) {
  120. return nz;
  121. } // ----- end of method RectilinearGrid::GetNz -----
  122. //--------------------------------------------------------------------------------------
  123. // Class: RectilinearGrid
  124. // Method: GetOx
  125. //--------------------------------------------------------------------------------------
  126. Real RectilinearGrid::GetOx ( ) {
  127. return ox;
  128. } // ----- end of method RectilinearGrid::GetOx -----
  129. //--------------------------------------------------------------------------------------
  130. // Class: RectilinearGrid
  131. // Method: GetOy
  132. //--------------------------------------------------------------------------------------
  133. Real RectilinearGrid::GetOy ( ) {
  134. return oy;
  135. } // ----- end of method RectilinearGrid::GetOy -----
  136. //--------------------------------------------------------------------------------------
  137. // Class: RectilinearGrid
  138. // Method: GetOz
  139. //--------------------------------------------------------------------------------------
  140. Real RectilinearGrid::GetOz ( ) {
  141. return oz;
  142. } // ----- end of method RectilinearGrid::GetOz -----
  143. //--------------------------------------------------------------------------------------
  144. // Class: RectilinearGrid
  145. // Method: GetDx
  146. //--------------------------------------------------------------------------------------
  147. VectorXr RectilinearGrid::GetDx ( ) {
  148. return dx;
  149. } // ----- end of method RectilinearGrid::GetDx -----
  150. //--------------------------------------------------------------------------------------
  151. // Class: RectilinearGrid
  152. // Method: GetDx
  153. //--------------------------------------------------------------------------------------
  154. Real RectilinearGrid::GetDx1 ( const int& ix ) {
  155. return dx[ix];
  156. } // ----- end of method RectilinearGrid::GetDx -----
  157. //--------------------------------------------------------------------------------------
  158. // Class: RectilinearGrid
  159. // Method: GetDy
  160. //--------------------------------------------------------------------------------------
  161. VectorXr RectilinearGrid::GetDy ( ) {
  162. return dy;
  163. } // ----- end of method RectilinearGrid::GetDy -----
  164. //--------------------------------------------------------------------------------------
  165. // Class: RectilinearGrid
  166. // Method: GetDy
  167. //--------------------------------------------------------------------------------------
  168. Real RectilinearGrid::GetDy1 ( const int& iy ) {
  169. return dy[iy];
  170. } // ----- end of method RectilinearGrid::GetDy -----
  171. //--------------------------------------------------------------------------------------
  172. // Class: RectilinearGrid
  173. // Method: GetDz
  174. //--------------------------------------------------------------------------------------
  175. VectorXr RectilinearGrid::GetDz ( ) {
  176. return dz;
  177. } // ----- end of method RectilinearGrid::GetDz -----
  178. //--------------------------------------------------------------------------------------
  179. // Class: RectilinearGrid
  180. // Method: GetDz
  181. //--------------------------------------------------------------------------------------
  182. Real RectilinearGrid::GetDz1 ( const int& iz ) {
  183. return dz[iz];
  184. } // ----- end of method RectilinearGrid::GetDz -----
  185. } // ----- end of Lemma name -----
  186. /* vim: set tabstop=4 expandtab: */
  187. /* vim: set filetype=cpp: syntax=cpp.doxygen*/