Main Lemma Repository
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Hantenna.cpp 8.4KB

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