Main Lemma Repository
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.

WireAntenna.cpp 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 12/16/2009
  9. @version $Id: wireantenna.cpp 199 2014-12-29 19:25:20Z tirons $
  10. **/
  11. #include "WireAntenna.h"
  12. namespace Lemma {
  13. std::ostream &operator << (std::ostream &stream, const WireAntenna &ob) {
  14. stream << ob.Serialize() << "\n---\n"; // End of doc ---
  15. return stream;
  16. }
  17. // ==================== LIFECYCLE =======================
  18. WireAntenna::WireAntenna( const ctor_key& ) : LemmaObject( ),
  19. NumberOfPoints(0), Current(1), NumberOfTurns(1) {
  20. }
  21. WireAntenna::WireAntenna( const YAML::Node& node, const ctor_key& ) : LemmaObject( node ) {
  22. Points = node["Points"].as<Vector3Xr>();
  23. Freqs = node["Freqs"].as<VectorXr>();
  24. NumberOfPoints = node["NumberOfPoints"].as<int>();
  25. NumberOfTurns = node["NumberOfTurns"].as<int>();
  26. Current = node["Current"].as<Real>();
  27. }
  28. WireAntenna::~WireAntenna() {
  29. }
  30. std::shared_ptr<WireAntenna> WireAntenna::NewSP() {
  31. return std::make_shared<WireAntenna>( ctor_key() );
  32. }
  33. std::shared_ptr<WireAntenna> WireAntenna::Clone() {
  34. auto copy = WireAntenna::NewSP();
  35. copy->NumberOfPoints = this->NumberOfPoints;
  36. copy->Freqs = this->Freqs;
  37. copy->Current = this->Current;
  38. copy->NumberOfTurns = this->NumberOfTurns;
  39. copy->Points = this->Points;
  40. //copy->Dipoles = this->Dipoles; // no, disaster
  41. return copy;
  42. }
  43. //--------------------------------------------------------------------------------------
  44. // Class: WireAntenna
  45. // Method: Serialize
  46. //--------------------------------------------------------------------------------------
  47. YAML::Node WireAntenna::Serialize ( ) const {
  48. YAML::Node node = LemmaObject::Serialize();
  49. node.SetTag( GetName() );
  50. node["NumberOfPoints"] = NumberOfPoints;
  51. node["NumberOfTurns"] = NumberOfTurns;
  52. node["Current"] = Current;
  53. node["Points"] = Points;
  54. node["Freqs"] = Freqs;
  55. return node;
  56. } // ----- end of method WireAntenna::Serialize -----
  57. //--------------------------------------------------------------------------------------
  58. // Class: WireAntenna
  59. // Method: DeSerialize
  60. //--------------------------------------------------------------------------------------
  61. std::shared_ptr<WireAntenna> WireAntenna::DeSerialize ( const YAML::Node& node ) {
  62. if (node.Tag() != "WireAntenna") {
  63. throw DeSerializeTypeMismatch( "WireAntenna", node.Tag());
  64. }
  65. return std::make_shared<WireAntenna> ( node, ctor_key() );
  66. } // ----- end of method WireAntenna::DeSerialize -----
  67. // ==================== ACCESS =======================
  68. void WireAntenna::SetNumberOfTurns(const int &nturns) {
  69. this->NumberOfTurns = nturns;
  70. }
  71. int WireAntenna::GetNumberOfTurns( ) {
  72. return this->NumberOfTurns;
  73. }
  74. void WireAntenna::SetNumberOfPoints(const int &np) {
  75. Points.resize( Eigen::NoChange, np);
  76. NumberOfPoints = np;
  77. }
  78. void WireAntenna::SetNumberOfFrequencies(const int &nfreq){
  79. Freqs.resize(nfreq);
  80. Freqs.setZero();
  81. }
  82. void WireAntenna::SetFrequency(const int& ifreq, const Real & freq) {
  83. assert(ifreq < Freqs.size());
  84. this->Freqs[ifreq] = freq;
  85. }
  86. Real WireAntenna::GetFrequency(const int& ifreq) {
  87. return this->Freqs[ifreq];
  88. }
  89. int WireAntenna::GetNumberOfFrequencies() {
  90. return Freqs.size();
  91. }
  92. Vector3Xr WireAntenna::GetPoints() {
  93. return Points;
  94. }
  95. MatrixXr WireAntenna::GetPointsMat() {
  96. return MatrixXr(Points.transpose());
  97. }
  98. void WireAntenna::SetCurrent(const Real &amps) {
  99. this->Current = amps;
  100. }
  101. Real WireAntenna::GetCurrent( ) {
  102. return this->Current;
  103. }
  104. void WireAntenna::SetPoint(const int &p, const Vector3r& pos) {
  105. if (p >= 0 && p<NumberOfPoints ) {
  106. Points.col(p) = pos;
  107. } else {
  108. throw 7;
  109. }
  110. }
  111. void WireAntenna::SetPoint(const int &p, const Real& x, const Real& y, const Real& z) {
  112. if (p >= 0 && p<NumberOfPoints ) {
  113. Points.col(p) = Vector3r(x,y,z);
  114. } else {
  115. throw 7;
  116. }
  117. }
  118. void WireAntenna::ApproximateWithElectricDipoles(const Real &deltai) {
  119. // Get rid of any dipoles
  120. Dipoles.clear();
  121. Real Dist(0);
  122. Vector3r r;
  123. Vector3r p;
  124. for (int ip=0; ip<NumberOfPoints-1; ++ip) {
  125. Dist = (Points.col(ip+1) - Points.col(ip)).norm();
  126. r = (Points.col(ip+1) - Points.col(ip))/Dist;
  127. int nd = (int)(Dist/deltai);
  128. Real add = (Dist - (Real)(nd)*deltai) / (Real)(nd);
  129. Real delta = deltai + add;
  130. Real scale = (Real)(NumberOfTurns)*Current;
  131. p = Points.col(ip) + .5*delta*r;
  132. for (Real id=0.; id<Dist-delta/2; id+=delta) {
  133. // X dipoles
  134. if (std::abs(r[0]) > 1e-6) {
  135. auto tx = DipoleSource::NewSP();
  136. tx->SetLocation(p);
  137. tx->SetType(GROUNDEDELECTRICDIPOLE);
  138. tx->SetPolarisation(XPOLARISATION);
  139. tx->SetFrequencies(Freqs);
  140. tx->SetMoment(scale*delta*r[0]);
  141. Dipoles.push_back(tx);
  142. }
  143. // Y dipoles
  144. if (std::abs(r[1]) > 1e-6) {
  145. auto ty = DipoleSource::NewSP();
  146. ty->SetLocation(p);
  147. ty->SetType(GROUNDEDELECTRICDIPOLE);
  148. ty->SetPolarisation(YPOLARISATION);
  149. ty->SetFrequencies(Freqs);
  150. ty->SetMoment(scale*delta*r[1]);
  151. Dipoles.push_back(ty);
  152. }
  153. // Z dipoles
  154. if (std::abs(r[2]) > 1e-6) {
  155. auto tz = DipoleSource::NewSP();
  156. tz->SetLocation(p);
  157. tz->SetType(GROUNDEDELECTRICDIPOLE);
  158. tz->SetPolarisation(ZPOLARISATION);
  159. tz->SetFrequencies(Freqs);
  160. tz->SetMoment(scale*delta*r[2]);
  161. Dipoles.push_back(tz);
  162. }
  163. p += delta*r;
  164. }
  165. }
  166. }
  167. // ==================== INQUIRY =======================
  168. int WireAntenna::GetNumberOfDipoles() {
  169. return Dipoles.size();
  170. }
  171. std::shared_ptr<DipoleSource> WireAntenna::GetDipoleSource(const int &dip) {
  172. return this->Dipoles[dip];
  173. }
  174. #ifdef LEMMAUSEVTK
  175. vtkActor* WireAntenna::GetVtkActor(const int &idip) {
  176. return Dipoles[idip]->GetVtkActor();
  177. }
  178. #endif
  179. //--------------------------------------------------------------------------------------
  180. // Class: WireAntenna
  181. // Method: IsPlanar
  182. //--------------------------------------------------------------------------------------
  183. bool WireAntenna::IsHorizontallyPlanar ( ) {
  184. //for (int ip=0; ip<NumberOfPoints; ++ip) {
  185. // std::cout << Points(2,ip) << std::endl;
  186. //}
  187. if ( std::abs(Points.row(2).sum() - (NumberOfPoints*Points(2,0))) < 1e-5 ) {
  188. return true ;
  189. } else {
  190. return false;
  191. }
  192. } // ----- end of method WireAntenna::IsPlanar -----
  193. }