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.

RectilinearGridReader.cpp 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. /**
  7. @file
  8. @date 09/23/2013 11:05:48 AM
  9. @version $Id$
  10. @author Trevor Irons (ti)
  11. @email Trevor.Irons@xri-geo.com
  12. @copyright Copyright (c) 2013, XRI Geophysics, LLC
  13. @copyright Copyright (c) 2013, Trevor Irons
  14. **/
  15. #include "RectilinearGridReader.h"
  16. namespace Lemma {
  17. // ==================== FRIEND METHODS =====================
  18. std::ostream &operator << (std::ostream &stream, const RectilinearGridReader &ob) {
  19. stream << ob.Serialize() << "\n---\n"; // End of doc
  20. return stream;
  21. }
  22. // ==================== LIFECYCLE =======================
  23. //--------------------------------------------------------------------------------------
  24. // Class: RectilinearGridReader
  25. // Method: RectilinearGridReader
  26. // Description: constructor (locked)
  27. //--------------------------------------------------------------------------------------
  28. RectilinearGridReader::RectilinearGridReader ( const ctor_key& ) : GridReader( ),
  29. rGrid( nullptr ), Parser( nullptr ) {
  30. } // ----- end of method RectilinearGridReader::RectilinearGridReader (constructor) -----
  31. //--------------------------------------------------------------------------------------
  32. // Class: RectilinearGridReader
  33. // Method: RectilinearGridReader
  34. // Description: DeSerializing constructor (protected)
  35. //--------------------------------------------------------------------------------------
  36. RectilinearGridReader::RectilinearGridReader (const YAML::Node& node, const ctor_key& key) : GridReader(node) {
  37. } // ----- end of method RectilinearGridReader::RectilinearGridReader (constructor) -----
  38. //--------------------------------------------------------------------------------------
  39. // Class: RectilinearGridReader
  40. // Method: NewSP()
  41. // Description: constructor
  42. //--------------------------------------------------------------------------------------
  43. std::shared_ptr< RectilinearGridReader > RectilinearGridReader::NewSP() {
  44. return std::make_shared< RectilinearGridReader > ( ctor_key() );
  45. }
  46. //--------------------------------------------------------------------------------------
  47. // Class: RectilinearGridReader
  48. // Method: ~RectilinearGridReader
  49. // Description: destructor (protected)
  50. //--------------------------------------------------------------------------------------
  51. RectilinearGridReader::~RectilinearGridReader () {
  52. } // ----- end of method RectilinearGridReader::~RectilinearGridReader (destructor) -----
  53. //--------------------------------------------------------------------------------------
  54. // Class: ASCIIParser
  55. // Method: Serialize
  56. //--------------------------------------------------------------------------------------
  57. YAML::Node RectilinearGridReader::Serialize ( ) const {
  58. YAML::Node node = GridReader::Serialize();;
  59. node.SetTag( GetName() );
  60. //node["CommentString"] = CommentString;
  61. //node["BufferSize"] = BufferSize;
  62. return node;
  63. } // ----- end of method ASCIIParser::Serialize -----
  64. //--------------------------------------------------------------------------------------
  65. // Class: RectilinearGridReader
  66. // Method: DeSerialize
  67. //--------------------------------------------------------------------------------------
  68. std::shared_ptr<RectilinearGridReader> RectilinearGridReader::DeSerialize ( const YAML::Node& node ) {
  69. if (node.Tag() != "RectilinearGridReader") {
  70. throw DeSerializeTypeMismatch( "RectilinearGridReader", node.Tag());
  71. }
  72. return std::make_shared< RectilinearGridReader >( node, ctor_key() ); //, ctor_key() );
  73. } // ----- end of method ASCIIParser::DeSerialize -----
  74. //--------------------------------------------------------------------------------------
  75. // Class: RectilinearGridReader
  76. // Method: ReadASCIIGridFile
  77. //--------------------------------------------------------------------------------------
  78. void RectilinearGridReader::ReadASCIIGridFile ( const std::string& name ) {
  79. rGrid = RectilinearGrid::NewSP();
  80. Parser = ASCIIParser::NewSP();
  81. Parser->SetCommentString("//");
  82. Parser->Open(name);
  83. std::vector<int> vals = Parser->ReadInts(3);
  84. rGrid->SetDimensions(vals[0], vals[1], vals[2]);
  85. std::vector<Real> rvals = Parser->ReadReals(3);
  86. rGrid->SetOffset(rvals[0], rvals[1], rvals[2]);
  87. rvals.clear();
  88. rvals = Parser->ReadReals( vals[0] );
  89. VectorXr temp = VectorXr::Map(&rvals[0], vals[0]);
  90. VectorXr hx = temp;
  91. rvals.clear();
  92. rvals = Parser->ReadReals( vals[1] );
  93. VectorXr hy = VectorXr::Map(&rvals[0], vals[1]);
  94. rvals.clear();
  95. rvals = Parser->ReadReals( vals[2] );
  96. VectorXr hz = VectorXr::Map(&rvals[0], vals[2]);
  97. rGrid->SetSpacing(hx, hy, hz);
  98. // Read in model(s)/data? Where should this be done?
  99. Parser->Close();
  100. return;
  101. } // ----- end of method RectilinearGridReader::ReadSCIIGridFile -----
  102. //--------------------------------------------------------------------------------------
  103. // Class: RectilinearGridReader
  104. // Method: GetGrid
  105. //--------------------------------------------------------------------------------------
  106. std::shared_ptr<Grid> RectilinearGridReader::GetGrid ( ) {
  107. return std::static_pointer_cast<Grid> (rGrid);
  108. } // ----- end of method RectilinearGridReader::GetGrid -----
  109. } // ----- end of Lemma name -----