Lemma is an Electromagnetics API
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

datareaderfemubc.cpp 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 M. Andy Kass
  8. @date 01/03/2013
  9. @version $Id$
  10. **/
  11. #include "datareaderfemubc.h"
  12. namespace Lemma {
  13. std::ostream &operator<<(std::ostream &stream,
  14. const DataReaderFemUBC &ob) {
  15. stream << *(DataReader*)(&ob);
  16. return stream;
  17. }
  18. DataReaderFemUBC::DataReaderFemUBC(const std::string &name) :
  19. DataReader(name), InputData(NULL) {
  20. }
  21. DataReaderFemUBC::~DataReaderFemUBC() {
  22. if (NumberOfReferences != 0) {
  23. throw DeleteObjectWithReferences(this);
  24. }
  25. }
  26. DataReaderFemUBC* DataReaderFemUBC::New() {
  27. DataReaderFemUBC* Obj = new DataReaderFemUBC("DataReaderFemUBC");
  28. Obj->AttachTo(Obj);
  29. return Obj;
  30. }
  31. void DataReaderFemUBC::Delete() {
  32. this->DetachFrom(this);
  33. }
  34. void DataReaderFemUBC::Release() {
  35. delete this;
  36. }
  37. DataFEM* DataReaderFemUBC::GetData() {
  38. return this->InputData;
  39. }
  40. void DataReaderFemUBC::SetDataFEM(DataFEM* inputtemp) {
  41. if (this->InputData != NULL) {
  42. this->InputData->DetachFrom(this);
  43. }
  44. inputtemp->AttachTo(this);
  45. this->InputData = inputtemp;
  46. }
  47. void DataReaderFemUBC::ReadData(const std::string &datafile,int vbs) {
  48. if (vbs != 0) {
  49. std::cout << std::endl << " Reading datafile: " << datafile <<
  50. std::endl;
  51. }
  52. std::string temp;
  53. Real rtemp;
  54. //MatrixXr datamatrix;
  55. //MatrixXr uncertainties
  56. //Vector3Xr positions;
  57. //VectorXr freqs;
  58. //VectorXr txmom;
  59. Eigen::Matrix<ORIENTATION,Eigen::Dynamic,1> txorien;
  60. Eigen::Matrix<ORIENTATION,Eigen::Dynamic,1> rxorien;
  61. //VectorXr scalefactor;
  62. //Vector3Xr txrxsep;
  63. int ontype;
  64. std::fstream infile(datafile.c_str(),std::ios::in);
  65. if (infile.fail()) {
  66. throw GenericFileIOError(this,datafile);
  67. }
  68. ///*
  69. // Get down to brass tacks and read the file
  70. infile >> this->nObs;
  71. this->PositionVec.resize(Eigen::NoChange,this->nObs);
  72. for (int ii=0;ii<this->nObs;ii++) {
  73. infile >> this->PositionVec(0,ii);
  74. infile >> this->PositionVec(1,ii);
  75. infile >> this->nFreq;
  76. if (ii==0) {
  77. this->DataMatrix.resize(this->nObs,this->nFreq*2);
  78. this->Uncertainties.resize(this->nObs,this->nFreq*2);
  79. this->Freqs.resize(this->nFreq,Eigen::NoChange);
  80. txorien.resize(this->nFreq,Eigen::NoChange);
  81. rxorien.resize(this->nFreq,Eigen::NoChange);
  82. this->ScaleFac.resize(this->nFreq);
  83. this->TxRxSep.resize(Eigen::NoChange,this->nFreq);
  84. this->TxMom.resize(this->nFreq,Eigen::NoChange);
  85. }
  86. for (int jj=0;jj<this->nFreq;jj++) {
  87. infile >> this->Freqs(jj);
  88. infile >> temp;
  89. infile >> this->TxMom(jj);
  90. infile >> this->PositionVec(2,ii);
  91. this->PositionVec(2,ii) = this->PositionVec(2,ii) * -1;
  92. infile >> temp;
  93. if (temp.compare("x")==0 || temp.compare("X")==0) {
  94. txorien(jj) = X;
  95. }
  96. else if (temp.compare("y")==0 || temp.compare("Y")==0) {
  97. txorien(jj) = Y;
  98. }
  99. else if (temp.compare("z")==0 || temp.compare("Z")==0) {
  100. txorien(jj) = Z;
  101. }
  102. else {
  103. std::cout << "Error reading transmitter orientation. " <<
  104. "Assuming z." << std::endl;
  105. txorien(jj) = Z;
  106. }
  107. infile >> temp;
  108. infile >> this->ScaleFac(jj);
  109. infile >> this->TxRxSep(0,jj);
  110. infile >> this->TxRxSep(1,jj);
  111. infile >> rtemp;
  112. this->TxRxSep(2,jj) = this->PositionVec(2,ii) + rtemp;
  113. infile >> temp;
  114. if (temp.compare("x")==0 || temp.compare("X")==0) {
  115. rxorien(jj) = X;
  116. }
  117. else if (temp.compare("y")==0 || temp.compare("Y")==0) {
  118. rxorien(jj) = Y;
  119. }
  120. else if (temp.compare("z")==0 || temp.compare("Z")==0) {
  121. rxorien(jj) = Z;
  122. }
  123. else {
  124. std::cout << "Error reading receiver orientation. " <<
  125. "Assuming z." << std::endl;
  126. rxorien(jj) = Z;
  127. }
  128. infile >> ontype;
  129. //ASSUMING THAT ONLY INPHASE AND QUADRATURE ARE PRESENT
  130. infile >> temp;
  131. infile >> this->DataMatrix(ii,(2*jj));
  132. infile >> this->DataMatrix(ii,(2*jj)+1);
  133. //uncertainty type
  134. infile >> temp;
  135. //pair of uncertainties
  136. if (temp.compare("v") == 0 || temp.compare("V") == 0) {
  137. infile >> this->Uncertainties(ii,(2*jj));
  138. infile >> this->Uncertainties(ii,(2*jj)+1);
  139. }
  140. else if (temp.compare("p")==0 || temp.compare("P")==0) {
  141. infile >> rtemp;
  142. this->Uncertainties(ii,(2*jj)) = this->DataMatrix(ii,(2*jj))*rtemp;
  143. infile >> rtemp;
  144. this->Uncertainties(ii,(2*jj)+1)=this->DataMatrix(ii,(2*jj)+1)*rtemp;
  145. }
  146. else {
  147. std::cout << "Error reading data file. Unknown uncertainty parameter." << std::endl;
  148. }
  149. }
  150. }
  151. infile.close();
  152. this->TxOrientation = txorien;
  153. this->RxOrientation = rxorien;
  154. // Populate the data object now
  155. this->SendData();
  156. }
  157. void DataReaderFemUBC::SendData() {
  158. this->InputData->SetSize(this->nObs,this->nFreq);
  159. this->InputData->SetData(this->DataMatrix);
  160. this->InputData->SetUncertainties(this->Uncertainties);
  161. this->InputData->SetPositions(this->PositionVec);
  162. this->InputData->SetFreq(this->Freqs);
  163. this->InputData->SetTxMom(this->TxMom);
  164. this->InputData->SetTxRxSep(this->TxRxSep);
  165. this->InputData->SetTxOrientation(this->TxOrientation);
  166. this->InputData->SetRxOrientation(this->RxOrientation);
  167. this->InputData->SetScaleFac(this->ScaleFac);
  168. }
  169. } // end of namespace Lemma