Main Lemma Repository
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Hantenna.cpp 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // ===========================================================================
  2. //
  3. // Filename: hantenna.cpp
  4. //
  5. // Created: 10/07/2010 08:57:04 AM
  6. // Modified: 11 April 2018
  7. // Compiler: Tested with g++, icpc, and MSVC 2017
  8. //
  9. // Author: Trevor Irons (ti)
  10. //
  11. // Copyright (C) 2012,2018 Trevor Irons
  12. //
  13. // Organisation: Lemma Software
  14. //
  15. // Email: Trevor.Irons@lemmasoftware.org
  16. //
  17. // ===========================================================================
  18. /**
  19. @file
  20. @author Trevor Irons
  21. @date 10/07/2010
  22. $Id$
  23. **/
  24. #include "LemmaCore"
  25. #include "FDEM1D"
  26. #include "timer.h"
  27. #if defined(__clang__)
  28. /* Clang/LLVM. ---------------------------------------------- */
  29. const char* compiler = "clang";
  30. #elif defined(__ICC) || defined(__INTEL_COMPILER)
  31. /* Intel ICC/ICPC. ------------------------------------------ */
  32. const char* compiler = "icpc";
  33. #elif defined(__GNUC__) || defined(__GNUG__)
  34. /* GNU GCC/G++. --------------------------------------------- */
  35. const char* compiler = "gcc (GCC) " __VERSION__;
  36. #elif defined(_MSC_VER)
  37. /* Microsoft Visual Studio. --------------------------------- */
  38. const char* compiler = "msvc " _MSC_FULL_VER;
  39. #elif defined(__PGI)
  40. /* Portland Group PGCC/PGCPP. ------------------------------- */
  41. const char* compiler = "pgc";
  42. #endif
  43. using namespace Lemma;
  44. std::vector<Real> readinpfile(const std::string& fname);
  45. std::vector<std::string> readinpfile2(const std::string& fname);
  46. int main(int argc, char** argv) {
  47. const char *buildString = __DATE__ ", " __TIME__;
  48. std::cout
  49. << "===========================================================================\n"
  50. << "Lemma " << LEMMA_VERSION << "\n"
  51. << "[" << compiler << " " << buildString << "]\n"
  52. << "This program is part of Lemma, a geophysical modelling and inversion API. \n"
  53. << " This Source Code Form is subject to the terms of the Mozilla Public\n"
  54. << " License, v. 2.0. If a copy of the MPL was not distributed with this\n"
  55. << " file, You can obtain one at http://mozilla.org/MPL/2.0/. \n"
  56. << "Copyright (C) 2018 Lemma Software \n"
  57. << "More information may be found at: https://lemmasoftware.org\n"
  58. << " info@lemmasoftware.org\n"
  59. << "===========================================================================\n\n"
  60. << "Hantenna calculates the harmonic H field from polygonal wire loop sources\n";
  61. if (argc < 5) {
  62. std::cout << "usage: hantenna.exe trans.inp cond.inp points.inp config.inp \n";
  63. exit(0);
  64. }
  65. #ifdef LEMMAUSEOMP
  66. std::cout << "OpenMP is using " << omp_get_max_threads() << " threads" << std::endl;
  67. #endif
  68. std::vector<Real> Trans = readinpfile(std::string(argv[1]));
  69. std::vector<Real> CondMod = readinpfile(std::string(argv[2]));
  70. std::vector<Real> Points = readinpfile(std::string(argv[3]));
  71. std::vector<std::string> config = readinpfile2(std::string(argv[4]));
  72. //////////////////////////////////////
  73. // Define transmitter
  74. auto trans = PolygonalWireAntenna::NewSP();
  75. trans->SetNumberOfPoints((int)(Trans[0]));
  76. int ip=1;
  77. for ( ; ip<=(int)(Trans[0])*2; ip+=2) {
  78. trans->SetPoint(ip/2, Vector3r (Trans[ip], Trans[ip+1], -1e-3));
  79. }
  80. trans->SetNumberOfFrequencies(1);
  81. trans->SetFrequency(0, Trans[ip]);
  82. trans->SetCurrent(Trans[ip+1]);
  83. trans->SetMinDipoleRatio(atof(config[1].c_str()));
  84. trans->SetMinDipoleMoment(atof(config[2].c_str()));
  85. trans->SetMaxDipoleMoment(atof(config[3].c_str()));
  86. /////////////////////////////////////
  87. // Field calculations
  88. auto receivers = FieldPoints::NewSP();
  89. int nx = (int)Points[0];
  90. int ny = (int)Points[1];
  91. int nz = (int)Points[2];
  92. Real ox = Points[3];
  93. Real oy = Points[4];
  94. Real oz = Points[5];
  95. Vector3r loc;
  96. VectorXr dx(nx-1);
  97. VectorXr dy(ny-1);
  98. VectorXr dz(nz-1);
  99. ip = 6;
  100. int ir = 0;
  101. for ( ; ip <6+nx-1; ++ip) {
  102. dx[ir] = Points[ip];
  103. ++ir;
  104. }
  105. ir = 0;
  106. for ( ; ip <6+ny-1+nx-1; ++ip) {
  107. dy[ir] = Points[ip];
  108. ++ir;
  109. }
  110. ir = 0;
  111. for ( ; ip <6+nz-1+ny-1+nx-1; ++ip) {
  112. dz[ir] = Points[ip];
  113. ++ir;
  114. }
  115. receivers->SetNumberOfPoints(nx*ny*nz);
  116. ir = 0;
  117. Real pz = oz;
  118. for (int iz=0; iz<nz; ++iz) {
  119. Real py = oy;
  120. for (int iy=0; iy<ny; ++iy) {
  121. Real px = ox;
  122. for (int ix=0; ix<nx; ++ix) {
  123. loc << px, py, pz;
  124. receivers->SetLocation(ir, loc);
  125. if (ix < nx-1) px += dx[ix];
  126. ++ ir;
  127. }
  128. if (iy<ny-1) py += dy[iy];
  129. }
  130. if (iz<nz-1) pz += dz[iz];
  131. }
  132. ////////////////////////////////////
  133. // Define model
  134. auto earth = LayeredEarthEM::NewSP();
  135. VectorXcr sigma;
  136. VectorXr thick;
  137. earth->SetNumberOfLayers(CondMod[0]+1);
  138. sigma.resize(CondMod[0]+1); sigma(0) = 0; // airlayer
  139. thick.resize(CondMod[0]-1);
  140. int ilay=1;
  141. for ( ; ilay/2<CondMod[0]-1; ilay+=2) {
  142. sigma(ilay/2+1) = 1./CondMod[ilay];
  143. thick(ilay/2) = CondMod[ilay+1];
  144. }
  145. sigma(ilay/2+1) = 1./ CondMod[ilay];
  146. earth->SetLayerConductivity(sigma);
  147. if (thick.size() > 0) earth->SetLayerThickness(thick);
  148. auto EmEarth = EMEarth1D::NewSP();
  149. EmEarth->AttachWireAntenna(trans);
  150. EmEarth->AttachLayeredEarthEM(earth);
  151. EmEarth->AttachFieldPoints(receivers);
  152. EmEarth->SetFieldsToCalculate(H);
  153. EmEarth->SetHankelTransformMethod(string2Enum<HANKELTRANSFORMTYPE>(config[0]));
  154. ///////////////////////////////////////////////
  155. // Keep track of time
  156. jsw_timer timer;
  157. timer.begin();
  158. clock_t launch = clock();
  159. EmEarth->CalculateWireAntennaFields(true); // true=status bar
  160. Real paTime = timer.end();
  161. std::cout << "\n\n===========================================\ncalc. real time: " << paTime/60. << "\t[m]\n";
  162. std::cout << "calc. user time: " << (clock()-launch)/CLOCKS_PER_SEC/60. << "\t[CPU m]"
  163. << std::endl;
  164. ////////////////////////////////////
  165. // Report
  166. std::fstream hrep("hfield.yaml", std::ios::out);
  167. std::fstream hreal("hfield.dat", std::ios::out);
  168. hrep << *EmEarth << std::endl;
  169. hrep.close();
  170. //hreal << *trans << std::endl;
  171. //hreal << *earth << std::endl;
  172. hreal << "// Right hand coordinate system, z is positive down\n";
  173. hreal << "// x[m]\ty[m]\tz[m]\tHx[A/m]\tHy[A/m]\tHz[A/m]\n";
  174. hreal.precision(8);
  175. int i=0;
  176. for (int iz=0; iz<nz; ++iz) {
  177. for (int iy=0; iy<ny; ++iy) {
  178. for (int ix=0; ix<nx; ++ix) {
  179. hreal << receivers->GetLocation(i).transpose() << "\t";
  180. hreal << receivers->GetHfield(0, i).transpose() << "\n";
  181. ++i;
  182. }
  183. }
  184. }
  185. hreal.close();
  186. // Clean up
  187. }
  188. std::vector<Real> readinpfile(const std::string& fname) {
  189. std::string buf;
  190. char dump[255];
  191. std::vector<Real> vals;
  192. std::fstream input(fname.c_str(), std::ios::in);
  193. if (input.fail()) {
  194. std::cerr << "Input file " << fname << " failed to open\n";
  195. exit(EXIT_FAILURE);
  196. }
  197. while (input >> buf) {
  198. if (buf.substr(0,2) == "//") {
  199. input.getline(dump, 255);
  200. } else {
  201. vals.push_back( atof(buf.c_str() ));
  202. }
  203. }
  204. return vals;
  205. }
  206. std::vector<std::string> readinpfile2(const std::string& fname) {
  207. std::string buf;
  208. char dump[255];
  209. std::vector<std::string> vals;
  210. std::fstream input(fname.c_str(), std::ios::in);
  211. if (input.fail()) {
  212. std::cerr << "Input file " << fname << " failed to open\n";
  213. exit(EXIT_FAILURE);
  214. }
  215. while (input >> buf) {
  216. if (buf.substr(0,2) == "//") {
  217. input.getline(dump, 255);
  218. } else {
  219. vals.push_back( std::string(buf.c_str() ));
  220. }
  221. }
  222. return vals;
  223. }