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.

pyFDEM1D.cpp 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 22/04/19 14:06:32
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@utah.edu
  14. * @copyright Copyright (c) 2019, University of Utah
  15. * @copyright Copyright (c) 2019, Lemma Software, LLC
  16. */
  17. #include <pybind11/pybind11.h>
  18. #include <pybind11/iostream.h>
  19. #include <pybind11/eigen.h>
  20. #include "FDEM1D"
  21. namespace py = pybind11;
  22. PYBIND11_MODULE(FDEM1D, m) {
  23. py::add_ostream_redirect(m, "ostream_redirect");
  24. m.doc() = "Python binding of Lemma::FDEM1D, additional details can be found at https://lemmasoftware.org";
  25. py::class_<Lemma::WireAntenna, std::shared_ptr<Lemma::WireAntenna> > WireAntenna(m, "WireAntenna");
  26. // lifecycle
  27. WireAntenna.def(py::init(&Lemma::WireAntenna::NewSP))
  28. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::WireAntenna::DeSerialize),
  29. "Construct object from yaml representation")
  30. // print
  31. .def("Serialize", &Lemma::WireAntenna::Print, "YAML representation of the class")
  32. .def("__repr__", &Lemma::WireAntenna::Print)
  33. // modifiers
  34. .def("SetNumberOfPoints", &Lemma::WireAntenna::SetNumberOfPoints,
  35. "Sets the number of points comprising the antenna")
  36. .def("SetPoint", py::overload_cast<const int&, const Lemma::Real&, const Lemma::Real&, const Lemma::Real&>(&Lemma::WireAntenna::SetPoint),
  37. "Sets a point in the antenna")
  38. .def("SetPoint", py::overload_cast<const int&, const Lemma::Vector3r&>(&Lemma::WireAntenna::SetPoint),
  39. "Sets a point in the antenna")
  40. .def("SetNumberOfTurns", &Lemma::WireAntenna::SetNumberOfTurns, "Sets the number of turns of the antenna")
  41. .def("SetNumberOfFrequencies", &Lemma::WireAntenna::SetNumberOfFrequencies,
  42. "Sets the number of frequencies of the transmitter")
  43. .def("SetFrequency", &Lemma::WireAntenna::SetFrequency, "Sets a single frequency of the transmitter")
  44. .def("SetCurrent", &Lemma::WireAntenna::SetCurrent, "Sets the current of the transmitter in amps")
  45. // accessors
  46. .def("GetCurrent", &Lemma::WireAntenna::GetCurrent, "Returns the current of the transmitter in amps")
  47. .def("GetPoints", &Lemma::WireAntenna::GetPoints, "Returns the points defining the transmitter")
  48. .def("GetNumberOfDipoles", &Lemma::WireAntenna::GetNumberOfDipoles,
  49. "Returns the number of dipoles defining the transmitter")
  50. .def("GetNumberOfFrequencies", &Lemma::WireAntenna::GetNumberOfFrequencies,
  51. "Returns the number of frequencies for the transmitter")
  52. .def("IsHorizontallyPlanar", &Lemma::WireAntenna::IsHorizontallyPlanar, "Returns true if the transmitter is flat")
  53. .def("GetName", &Lemma::WireAntenna::GetName, "Returns the class name of the object")
  54. // operations
  55. .def("ApproximateWithElectricDipoles", &Lemma::WireAntenna::ApproximateWithElectricDipoles,
  56. "Approximates loop with electric dipoles")
  57. ;
  58. py::class_<Lemma::PolygonalWireAntenna, std::shared_ptr<Lemma::PolygonalWireAntenna> > PolygonalWireAntenna(m,
  59. "PolygonalWireAntenna", WireAntenna);
  60. // lifecycle
  61. PolygonalWireAntenna.def(py::init(&Lemma::PolygonalWireAntenna::NewSP))
  62. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::PolygonalWireAntenna::DeSerialize),
  63. "Construct object from yaml representation")
  64. // print
  65. .def("__repr__", &Lemma::PolygonalWireAntenna::Print)
  66. .def("Serialize", &Lemma::PolygonalWireAntenna::Print, "YAML representation of the class")
  67. // accessors
  68. .def("GetName", &Lemma::PolygonalWireAntenna::GetName, "Returns the name of the class")
  69. // operations
  70. .def("ApproximateWithElectricDipoles", &Lemma::PolygonalWireAntenna::ApproximateWithElectricDipoles,
  71. "Approximates loop with series of electric dipoles around loop")
  72. // modifiers
  73. .def("SetMinDipoleRatio", &Lemma::PolygonalWireAntenna::SetMinDipoleRatio,
  74. "Sets the minimum dipole ratio use, smaller values increase precision")
  75. .def("SetMinDipoleMoment", &Lemma::PolygonalWireAntenna::SetMinDipoleMoment,
  76. "Sets the minimum dipole moment which will be used, smaller values increase precision and computational time")
  77. .def("SetMaxDipoleMoment", &Lemma::PolygonalWireAntenna::SetMaxDipoleMoment,
  78. "Sets the maximum dipole moment which will be used, smaller values increase precision and computational time")
  79. ;
  80. py::class_<Lemma::DipoleSource, std::shared_ptr<Lemma::DipoleSource> > DipoleSource(m, "DipoleSource");
  81. // lifecycle
  82. DipoleSource.def(py::init(&Lemma::DipoleSource::NewSP))
  83. .def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::DipoleSource::DeSerialize),
  84. "Construct object from yaml representation")
  85. // print
  86. .def("Serialize", &Lemma::DipoleSource::Print, "YAML representation of the class")
  87. .def("__repr__", &Lemma::DipoleSource::Print)
  88. // accessors
  89. .def("GetName", &Lemma::DipoleSource::GetName, "Returns the name of the class")
  90. .def("GetNumberOfFrequencies", &Lemma::DipoleSource::GetNumberOfFrequencies,
  91. "Returns the number of frequencies")
  92. .def("GetFrequencies", &Lemma::DipoleSource::GetFrequencies, "Returns an array of frequencies")
  93. .def("GetFrequency", &Lemma::DipoleSource::GetFrequency, "Returns the frequency of the argument index")
  94. .def("GetAngularFrequency", &Lemma::DipoleSource::GetAngularFrequency,
  95. "Returns the angular frequency of the argument index")
  96. .def("GetPhase", &Lemma::DipoleSource::GetPhase, "Returns the phase of the dipole")
  97. .def("GetMoment", &Lemma::DipoleSource::GetMoment, "Returns the moment of the dipole")
  98. .def("GetLocation", py::overload_cast< >(&Lemma::DipoleSource::GetLocation), "Returns the location of the dipole")
  99. .def("GetPolarisation", &Lemma::DipoleSource::GetPolarisation, "Returns the polarisation of the dipole")
  100. // modifiers
  101. .def("SetLocation", py::overload_cast<const Lemma::Vector3r&> (&Lemma::DipoleSource::SetLocation),
  102. "Sets the location of the dipole")
  103. .def("SetPolarisation", py::overload_cast<const Lemma::Vector3r&> (&Lemma::DipoleSource::SetPolarisation),
  104. "Sets the polarisation of the dipole")
  105. .def("SetType", &Lemma::DipoleSource::SetType, "Sets the type")
  106. .def("SetMoment", &Lemma::DipoleSource::SetMoment, "Sets the moment of the dipole")
  107. .def("SetPhase", &Lemma::DipoleSource::SetPhase, "Sets the phase of the dipole")
  108. .def("SetNumberOfFrequencies", &Lemma::DipoleSource::SetNumberOfFrequencies,
  109. "Sets the number of frequencies to calculate for the dipole")
  110. .def("SetFrequency", &Lemma::DipoleSource::SetFrequency,
  111. "Sets a single frequency, first argument is index, second argument is frequency")
  112. .def("SetFrequencies", &Lemma::DipoleSource::SetFrequencies,
  113. "Sets all frequencies, argument is numpy array of frequencies")
  114. ;
  115. py::class_<Lemma::LayeredEarthEM, std::shared_ptr<Lemma::LayeredEarthEM> >
  116. LayeredEarthEM(m, "LayeredEarthEM");
  117. // lifecycle
  118. LayeredEarthEM.def(py::init(&Lemma::LayeredEarthEM::NewSP))
  119. .def_static("DeSerialize", py::overload_cast<const std::string&>
  120. (&Lemma::LayeredEarthEM::DeSerialize),"Construct object from yaml representation")
  121. // print
  122. .def("Serialize", &Lemma::LayeredEarthEM::Print, "YAML representation of the class")
  123. .def("__repr__", &Lemma::LayeredEarthEM::Print)
  124. // accessors
  125. .def("GetName", &Lemma::LayeredEarthEM::GetName, "Returns the name of the class")
  126. .def("GetLayerConductivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerConductivity),
  127. "Returns the conductivity of all layers")
  128. .def("GetLayerConductivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerConductivity),
  129. "Returns the conductivity of the specified layer")
  130. .def("GetLayerSusceptibility", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerSusceptibility),
  131. "Returns the susceptibility of all layers")
  132. .def("GetLayerSusceptibility1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerSusceptibility),
  133. "Returns the susceptibilty of the specified layer")
  134. .def("GetLayerLowFreqSusceptibility", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerLowFreqSusceptibility),
  135. "Returns the low frequqncy permitivity of all layers")
  136. .def("GetLayerLowFreqSusceptibility1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerLowFreqSusceptibility),
  137. "Returns the low frequency permitivity of the specified layer")
  138. .def("GetLayerHighFreqSusceptibility", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerHighFreqSusceptibility),
  139. "Returns the low frequency permitivity of all layers")
  140. .def("GetLayerHighFreqSusceptibility1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerHighFreqSusceptibility),
  141. "Returns the low frequency permitivity of the specified layer")
  142. .def("GetLayerTauSusceptibility", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerTauSusceptibility),
  143. "Returns the tau permitivity of all layers")
  144. .def("GetLayerTauSusceptibility1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerTauSusceptibility),
  145. "Returns the tau permitivity of the specified layer")
  146. .def("GetLayerBreathSusceptibility", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerBreathSusceptibility),
  147. "Returns the breth permitivity of all layers")
  148. .def("GetLayerBreathSusceptibility1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerBreathSusceptibility),
  149. "Returns the breath permitivity of the specified layer")
  150. .def("GetLayerPermitivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerPermitivity),
  151. "Returns the permitivity of all layers")
  152. .def("GetLayerPermitivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerPermitivity),
  153. "Returns the permitivity of the specified layer")
  154. .def("GetLayerLowFreqPermitivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerLowFreqPermitivity),
  155. "Returns the low frequqncy permitivity of all layers")
  156. .def("GetLayerLowFreqPermitivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerLowFreqPermitivity),
  157. "Returns the low frequency permitivity of the specified layer")
  158. .def("GetLayerHighFreqPermitivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerHighFreqPermitivity),
  159. "Returns the low frequency permitivity of all layers")
  160. .def("GetLayerHighFreqPermitivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerHighFreqPermitivity),
  161. "Returns the low frequency permitivity of the specified layer")
  162. .def("GetLayerTauPermitivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerTauPermitivity),
  163. "Returns the tau permitivity of all layers")
  164. .def("GetLayerTauPermitivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerTauPermitivity),
  165. "Returns the tau permitivity of the specified layer")
  166. .def("GetLayerBreathPermitivity", py::overload_cast<>(&Lemma::LayeredEarthEM::GetLayerBreathPermitivity),
  167. "Returns the breth permitivity of all layers")
  168. .def("GetLayerBreathPermitivity1", py::overload_cast<const int&>(&Lemma::LayeredEarthEM::GetLayerBreathPermitivity),
  169. "Returns the breath permitivity of the specified layer")
  170. // modifiers
  171. .def("SetNumberOfLayers", &Lemma::LayeredEarthEM::SetNumberOfLayers,
  172. "Sets the number of layers in the model")
  173. .def("SetLayerConductivity", py::overload_cast< const Lemma::VectorXcr& >(&Lemma::LayeredEarthEM::SetLayerConductivity),
  174. "Sets the conductivity of the layers, the input is a complex array of conductivity")
  175. .def("SetLayerConductivity1", py::overload_cast< const int&, const Lemma::Complex& >(&Lemma::LayeredEarthEM::SetLayerConductivity),
  176. "Sets the conductivity of a single layer, the first input is the layer index, and the secondinput is a complex conductivity")
  177. .def("SetLayerThickness", &Lemma::LayeredEarthEM::SetLayerThickness,
  178. "Sets the thickness of layers, excluding the air and bottom which are infinite")
  179. .def("SetLayerHighFreqSusceptibility", &Lemma::LayeredEarthEM::SetLayerHighFreqSusceptibility,
  180. "Sets the high frequency susceptibility for Cole-COle model")
  181. .def("SetLayerLowFreqSusceptibility", &Lemma::LayeredEarthEM::SetLayerLowFreqSusceptibility,
  182. "Sets the low frequency susceptibility for Cole-COle model")
  183. .def("SetLayerBreathSusceptibility", &Lemma::LayeredEarthEM::SetLayerBreathSusceptibility,
  184. "Sets thesusceptibility breath for Cole-COle model")
  185. .def("SetLayerHighFreqPermitivity", &Lemma::LayeredEarthEM::SetLayerHighFreqPermitivity,
  186. "Sets the high frequency permitivity for Cole-COle model")
  187. .def("SetLayerLowFreqPermitivity", &Lemma::LayeredEarthEM::SetLayerLowFreqPermitivity,
  188. "Sets the low frequency permitivity for Cole-COle model")
  189. .def("SetLayerBreathPermitivity", &Lemma::LayeredEarthEM::SetLayerBreathPermitivity,
  190. "Sets the permitivity breath for Cole-COle model")
  191. // methods
  192. .def("EvaluateColeColeModel", &Lemma::LayeredEarthEM::EvaluateColeColeModel,
  193. "Calculates complex resistivity based on cole-cole parameters")
  194. ;
  195. py::class_<Lemma::EMEarth1D, std::shared_ptr<Lemma::EMEarth1D> >
  196. EMEarth1D(m, "EMEarth1D");
  197. // lifecycle
  198. EMEarth1D.def(py::init(&Lemma::EMEarth1D::NewSP))
  199. //.def_static("DeSerialize", py::overload_cast<const std::string&>
  200. // (&Lemma::EMEarth1D::DeSerialize),"Construct object from yaml representation")
  201. // print
  202. .def("Serialize", &Lemma::EMEarth1D::Print, "YAML representation of the class")
  203. .def("__repr__", &Lemma::EMEarth1D::Print)
  204. // accessors
  205. .def("GetName", &Lemma::EMEarth1D::GetName, "Returns the name of the class")
  206. .def("GetFieldPoints", &Lemma::EMEarth1D::GetFieldPoints, "Returns the FieldPoint class")
  207. // modifiers
  208. .def("AttachWireAntenna", &Lemma::EMEarth1D::AttachWireAntenna,
  209. "Sets the wire antenna to use for calculations")
  210. .def("AttachDipoleSOurce", &Lemma::EMEarth1D::AttachDipoleSource,
  211. "Sets a DipoleSource to use for calculations")
  212. .def("AttachFieldPoints", &Lemma::EMEarth1D::AttachFieldPoints,
  213. "Sets the FieldPoints to use for calculations")
  214. .def("AttachLayeredEarthEM", &Lemma::EMEarth1D::AttachLayeredEarthEM,
  215. "Sets the LayeredEarthEM to use for calculations")
  216. .def("SetFieldToCalculate", &Lemma::EMEarth1D::SetFieldsToCalculate,
  217. "Sets which fields to calculate")
  218. .def("SetHankelTransformMethod", &Lemma::EMEarth1D::SetHankelTransformMethod,
  219. "Sets which Hankel transform to use")
  220. .def("SetTxRxMode", &Lemma::EMEarth1D::SetTxRxMode,
  221. "Sets the TxRx mode flag")
  222. //methods
  223. #ifdef KIHALEE_EM1D
  224. .def("MakeCalc", &Lemma::EMEarth1D::MakeCalc, "Calls KiHa Lee's EM1D FORTRAN77 code")
  225. #endif
  226. .def("MakeCalc3", &Lemma::EMEarth1D::MakeCalc3, "Native Lemma EM calculation")
  227. .def("CalculateWireAntennaFields", &Lemma::EMEarth1D::CalculateWireAntennaFields,
  228. "Native Lemma calculation of a wire antenna")
  229. ;
  230. py::class_<Lemma::FieldPoints, std::shared_ptr<Lemma::FieldPoints> >
  231. FieldPoints(m, "FieldPoints");
  232. // lifecycle
  233. FieldPoints.def(py::init(&Lemma::FieldPoints::NewSP))
  234. .def_static("DeSerialize", py::overload_cast<const std::string&>
  235. (&Lemma::FieldPoints::DeSerialize),"Construct object from yaml representation")
  236. // print
  237. .def("Serialize", &Lemma::FieldPoints::Print, "YAML representation of the class")
  238. .def("__repr__", &Lemma::FieldPoints::Print)
  239. // modifiers
  240. .def("SetNumberOfPoints", &Lemma::FieldPoints::SetNumberOfPoints,
  241. "Sets the number of locations to make calculations on.")
  242. .def("SetLocation", py::overload_cast< const int&, const Lemma::Vector3r& >
  243. (&Lemma::FieldPoints::SetLocation), "Sets the location of the index-specified point." )
  244. .def("SetLocation", py::overload_cast< const int&,
  245. const Lemma::Real&, const Lemma::Real&, const Lemma::Real& >
  246. (&Lemma::FieldPoints::SetLocation),
  247. "Sets the location of the index-specified point with the three coordinates")
  248. // accessors
  249. .def("GetNumberOfPoints", &Lemma::FieldPoints::GetNumberOfPoints,
  250. "Returns the number of locations to make calculations on.")
  251. .def("GetLocations", &Lemma::FieldPoints::GetLocations,
  252. "Returns the locations which calculations are made on.")
  253. .def("GetLocationsMat", &Lemma::FieldPoints::GetLocationsMat,
  254. "Returns a matrix of the locations which calculations are made on.")
  255. .def("GetLocation", &Lemma::FieldPoints::GetLocation,
  256. "Returns the location of the specified index.")
  257. .def("GetLocationX", &Lemma::FieldPoints::GetLocationX,
  258. "Returns the northing (x) location of the specified index.")
  259. .def("GetLocationY", &Lemma::FieldPoints::GetLocationY,
  260. "Returns the easting (y) location of the specified index.")
  261. .def("GetLocationZ", &Lemma::FieldPoints::GetLocationZ,
  262. "Returns the altitude/depth (z) location of the specified index.")
  263. .def("GetEfield", py::overload_cast< > (&Lemma::FieldPoints::GetEfield),
  264. "Returns the electric field for all frequencies.")
  265. .def("GetEfield", py::overload_cast< const int& > (&Lemma::FieldPoints::GetEfield),
  266. "Returns the electric field for the specified frequency index.")
  267. .def("GetEfield", py::overload_cast< const int&, const int& > (&Lemma::FieldPoints::GetEfield),
  268. "Returns the electric field for the specified frequency and location index.")
  269. .def("GetEfieldMat", &Lemma::FieldPoints::GetEfieldMat,
  270. "Returns the electric field for the specified frequency.")
  271. .def("GetHfield", py::overload_cast< > (&Lemma::FieldPoints::GetHfield),
  272. "Returns the H field for all frequencies.")
  273. .def("GetHfield", py::overload_cast< const int& > (&Lemma::FieldPoints::GetHfield),
  274. "Returns the H field for the specified frequency index.")
  275. .def("GetHfield", py::overload_cast< const int&, const int& > (&Lemma::FieldPoints::GetHfield),
  276. "Returns the H field for the specified frequency and location index.")
  277. //.def("GetBfield", py::overload_cast< const int&, const int& > (&Lemma::FieldPoints::GetBfield),
  278. // "Returns the magnetic (B) field for the specified frequency and location index.")
  279. .def("GetHfieldMat", &Lemma::FieldPoints::GetHfieldMat,
  280. "Returns the H field for the specified frequency.")
  281. .def("GetMask", &Lemma::FieldPoints::MaskPoint, "Return the mask boolean value for the specified index")
  282. // methods
  283. .def("ClearFields", &Lemma::FieldPoints::ClearFields, "Clears calculated fields")
  284. .def("MaskPoint", &Lemma::FieldPoints::MaskPoint, "Masks the index resulting in no calculation")
  285. .def("UnMaskPoint", &Lemma::FieldPoints::UnMaskPoint, "Unmasks the index resulting in a calculation")
  286. ;
  287. }