Lemma is an Electromagnetics API
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

lemma.h 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 06/19/2009 09:12:20 AM The Birth of Lemma!
  9. @version $Id: lemma.h 203 2015-01-09 21:19:04Z tirons $
  10. **/
  11. // \image html lemma.png
  12. /** \mainpage Lemma is an ElectroMagnetics Modelling API
  13. \authors Trevor Irons and M. Andrew Kass and others
  14. Originally Lemma was intended as a recursive acronym standing for
  15. <B>L</B>emma is an <B>E</B>lectro<B>M</B>agnetics <B>M</B>odelling <B>A</B>PI.
  16. As the breadth of the project has expanded, the name has remained
  17. appropriate in a more literal sense. Lemma is a flexible cross-platform
  18. library delivering an expressive API that can be used to easily create
  19. versatile programs. Lemma is not itself a program, instead it is a
  20. collection of building blocks to make geophysical applications.
  21. We retain this name because:
  22. - In mathematics a Lemma is a proven proposition which is used as a
  23. stepping stone to a larger result rather than as a statement in-and-of
  24. itself.
  25. - In addition to the electromagnetic modelling, some other facilities are
  26. provided such as numerical optimization and inversion capabilities. These
  27. tools are also considered stepping stones to final products.
  28. We feel that this is a particularly approprate name, as Lemma's
  29. API can be leveraged create powerful applications such as forward
  30. modelling and inverting frequency and time-domain
  31. surveys of arbitrary survey design, sNMR surveys, CSAMT and more.
  32. \section Motivation
  33. Why another Geophysical EM project? For starters, there aren't that many
  34. quality open source packages out there. Those that do exist are generally
  35. specialized to perform a single task and extending them is a major undertaking.
  36. Lemma's approach is much different, by providing a set of general tools users
  37. can easily assemble applications that suite their needs. Furthermore, most are
  38. written in either Fortran or MATLAB, and can be difficult to integrate into
  39. multiphysics applications. To our knowlege, Lemma is the only C++ EM simulation
  40. package freely available.
  41. \section Capabilities Capabilities
  42. In the long term, we have many goals for this software project. Due to its
  43. design, Lemma can be built upon and extended easily. The initial aim is to
  44. provide flexible 1D and 3D EM modelling in the time and frequency domains.
  45. The project is still in beta, but we have made a lot of progress already.
  46. We will release our first non-beta release as soon as the following are
  47. supported.
  48. \subsection FDM Frequency-domain forward modelling
  49. Lemma was initially called EMMODFD: Electromagnetic Modelling in the Frequency
  50. Domain. As such this is the most mature area of Lemma.
  51. \par 1D
  52. Frequency domain solutions to electrical and magnetic dipoles can be computed
  53. quasi-analytically in 1D. Calculations can be made in or above the layered
  54. media, and complex electrical conductivity and magnetic susceptibility are
  55. supported according to the Cole-Cole model. Sources may be embdedded in the
  56. media or in the resisitive air layer. Lemma can also can compute fields due
  57. to arbitrarily shaped ungrounded wire loops, topography of the loops is also
  58. supported. Two separate approaches to solving the Hankel transform, one
  59. based on Anderson's digitial filtering technique, and another based on Gaussian
  60. quadrature.
  61. \par 3D
  62. A fast 3D solver that can modify the 1D results based
  63. on arbitrary electrical conductivity model is nearing completion.
  64. \par future work
  65. We are also planning on supporting grounded wires in the near future.
  66. \subsection TDM Time-domain forward modelling
  67. A 1D time-domain solution has been implemented that utilises both a
  68. dipole source as well as a wire loop. Currently, only one receiver is
  69. modelled at a time, but will be generalised. In addition, utilities
  70. to read in data files for modelling have been implemented.
  71. We would like to offer 3D time domain support, but this will not be
  72. provided before our first stable release.
  73. \subsection DataFormats Data Formats
  74. The EM community is plagued with myriad data formats. Often each equiptment
  75. manufacturer provides their own data format and interoperability is a
  76. constant struggle. We are working on a flexible data format based on the XML
  77. format that can be adapted to many types of data. The template for this
  78. format will be publically released and we hope it catches on in the community.
  79. At the least, it will provide a mechanism to compare datasets and datatypes
  80. within Lemma.
  81. \section Modules Modules
  82. Due to Lemma's design, it is easy to extend the platform. In some cases this
  83. extension results in adding functionality that is not directly related to
  84. ElectroMagnetics. The following modules utilise parts of Lemma to provide
  85. their functionality.
  86. \section Tutorials
  87. - \ref Tutorial - Basic intruduction to Lemma, including aquiring and
  88. compiling the code, class structure, and building your own
  89. applications.
  90. - \ref Extending Tutorial on how to extend Lemma.
  91. \section Development Development and design
  92. Ths package was initially developed by the Center for Gravity, Electrical, and
  93. Magnetic Studies (CGEM) at the Colorado School of Mines (CSM), the United
  94. States Geological Survey (USGS), and Broken Spoke Development, LLC. Where it drew
  95. on work by many others including Ki Ha Lee, and Walt Anderson. All new work and
  96. interfaces are written entirely in C++. Several small external projects are
  97. included, which are written in standard C, and FORTRAN 77. We adapt a
  98. modern, test driven, object oriented, C++ framework.
  99. More recent development has been undertaken at the University of Utah through the Energy
  100. and Geoscience Institute.
  101. \section Legalities
  102. \subsection Copyrights
  103. The following copyrights apply to the source.
  104. Most of the code was developed either by Trevor
  105. Copyright (C) 2008-2010 Trevor Irons <trevor.irons@lemmasoftware.org> or
  106. M. Andrew Kass Copyright (C) 2010 <mkass@usgs.gov>.
  107. The 1D EM solver was derived (but updated heavily) from a Fortran
  108. programme written by Ki Ha Lee in 1984. We have communicated with Ki Ha,
  109. and he assured us that this code is in the public domain.
  110. A Gaussian quadrature hankel transform originally written by Alan Chave was
  111. ported to C++. This code is in the public domain, and the source code was
  112. published in Geophysics.
  113. A digital filtering approach to the Hankel transform written by Walt
  114. Anderson was also rewritten for Lemma. The original Fortran code is also in
  115. the public domain.
  116. Please note that Ki Ha Lee and Walt Anderson had no part in this work, and
  117. the above should not be interpreted as any sort of endorsement by those
  118. parties.
  119. \subsection License
  120. This Source Code Form is subject to the terms of the Mozilla Public
  121. License, v. 2.0. If a copy of the MPL was not distributed with this
  122. file, You can obtain one at http://mozilla.org/MPL/2.0/.
  123. \section Contributing Suggestions and contributions
  124. We welcome contributions and suggestions. Feel free to email the development
  125. team at info@lemmasoftware.org.
  126. Under the terms of the MPL, if you modify a Lemma file, you are obligated to
  127. share those contributions back with the community.
  128. \section Useful Useful links
  129. - Home page https://lemmasoftware.org
  130. - Git repository https://git.lemmasoftware.org
  131. - Broken Spoke Develpment http://numericalgeo.com
  132. - CGEM at the Coloroado School of Mines http://geophysics.mines.edu/cgem/
  133. - EGI at the Eniversity of Utah http://egi.utah.edu/
  134. **/
  135. #pragma once
  136. #ifndef __LEMMA_H
  137. #define __LEMMA_H
  138. #include <LemmaConfig.h>
  139. // Include some basic stuff that will always be needed
  140. #include <iostream>
  141. #include <iomanip>
  142. #include <complex>
  143. #include <fstream>
  144. #include <string>
  145. #include <vector>
  146. #include <stdexcept>
  147. #include <sstream>
  148. #include <Eigen/Core>
  149. #include <cstddef>
  150. #include <Eigen/StdVector>
  151. #include <Eigen/Sparse>
  152. #include <unsupported/Eigen/FFT>
  153. //#include <unsupported/Eigen/SparseExtra>
  154. #include <Eigen/Geometry>
  155. /** \brief The only namespace used by Lemma
  156. *
  157. * \details The rational behind this namespace is that built-in
  158. * types should be used wherever possible, but not
  159. * not built-in names. This allows for code that is better
  160. * enacsulated and easier to modify. The typedefs and constants
  161. * specified here are defined so that
  162. * precision/inplimentation can easily be changed.
  163. * All floating precision types should be typedefed in this file
  164. * and should not be used natively within any code.
  165. * Lemma uses
  166. * the Eigen Matrix/Vector/Linear Algebra library.
  167. * <http://eigen.tuxfamily.org> and a lot of the namespece typedefs
  168. * are specifying Eigen types.
  169. */
  170. namespace Lemma {
  171. /// Real defines precision for the whole API, default is double
  172. #ifdef LEMMA_SINGLE_PRECISION
  173. typedef float Real;
  174. #else // ----- LEMMA_SINGLE_PRECISION -----
  175. typedef double Real;
  176. #endif // ----- not LEMMA_SINGLE_PRECISION -----
  177. /// Complex version of Real.
  178. typedef std::complex<Real> Complex;
  179. /// A 3 component Eigen vector of Reals
  180. typedef Eigen::Matrix<Real, 3, 1> Vector3r;
  181. /// A 3 X Dynamic Component Eigen matrix of Reals
  182. typedef Eigen::Matrix<Real, 3, Eigen::Dynamic> Vector3Xr;
  183. /// Variable length Eigen vector of Reals
  184. typedef Eigen::Matrix<Real, Eigen::Dynamic, 1> VectorXr;
  185. /// Variable length Eigen vector of integers (int)
  186. typedef Eigen::Matrix<int, Eigen::Dynamic, 1> VectorXi;
  187. /// Variable length Eigen vector of Complexes
  188. typedef Eigen::Matrix<Complex, Eigen::Dynamic, 1> VectorXcr;
  189. /// A 3 Component Eigen vector of Complexes
  190. typedef Eigen::Matrix<Complex, 3, 1> Vector3cr;
  191. /// A 3 X Dynamic Component Eigen matrix of Complexes
  192. typedef Eigen::Matrix<Complex, 3, Eigen::Dynamic> Vector3Xcr;
  193. /// Variable length Eigen Matrix of Reals
  194. typedef Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic> MatrixXr;
  195. /// Variable length Eigen Matrix of ints
  196. typedef Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic> MatrixXi;
  197. /// Variable length Eigen vector of Complexes
  198. typedef Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic> MatrixXcr;
  199. ////////////////////////////////////////
  200. // Constants used across the programmes
  201. /// Restating the obvious, this is pi
  202. const Real PI = 4.0*atan(1.0);
  203. /// Permitivity of Free Space
  204. //const Real EPSILON0 = 8.854187817e-12;
  205. const Real EPSILON0 = 8.854187817e-12;
  206. /// Permeability of free space
  207. const Real MU0 = 4.*PI*1e-7;
  208. /// 1/4 of \f$ \pi\f$
  209. const Real QPI = .25/PI;
  210. /// Some functions will convert units from SI (standard) to Gauss
  211. /// This is because NMR calculations are much more natural in Gauss
  212. enum MAGUNITS {TESLA, NANOTESLA, GAUSS};
  213. /// Unit of temperature entered
  214. enum TEMPUNITS {CELCIUS, KELVIN};
  215. /// Unit of time entered
  216. enum TIMEUNITS {SEC, MILLISEC, MICROSEC, NANOSEC, PICOSEC};
  217. /// Unit of time entered
  218. enum FREQUENCYUNITS {HZ, KHZ, MHZ, GHZ};
  219. /// FEM coil relative orientations
  220. enum FEMCOILORIENTATION {COAXIAL, COPLANAR};
  221. /// General orientation relative to coordinate system
  222. enum ORIENTATION {X, Y, Z, NX, NY, NZ};
  223. /// Type of field
  224. enum FIELDTYPE {HFIELDREAL, HFIELDIMAG, EFIELDREAL, EFIELDIMAG};
  225. /// Compenent of vector field
  226. enum FIELDCOMPONENT {XCOMPONENT=0, YCOMPONENT=1, ZCOMPONENT=2};
  227. /// Spatial component of vector
  228. enum SPATIALCOORDINANT {XCOORD=0, YCOORD=1, ZCOORD=2};
  229. /** Evaluation method for Hankel integrals.
  230. * ANDERSON801 Walt Anderson's 801 point filter
  231. * CHAVE Alan Chave's gaussian quadrature integration method
  232. * FHTKEY201 Key's 201 point filter
  233. * FHTKEY201 Key's 101 point filter
  234. * FHTKEY51 Key's 51 point filter
  235. * QWEKEY Key's Gaussian quadrature integration method
  236. */
  237. enum HANKELTRANSFORMTYPE { ANDERSON801, CHAVE, FHTKEY201, FHTKEY101, FHTKEY51, QWEKEY,
  238. FHTKONG61, FHTKONG121, FHTKONG241, IRONS };
  239. /** Enum is OK because these are the only physically possible sources.
  240. @param NOSOURCETYPE is default.
  241. @param ELECTRICDIPOLE is an electric dipole
  242. @param MAGNETICDIPOLE is a magnetic dipole
  243. */
  244. enum DipoleSourceType {NOSOURCETYPE, GROUNDEDELECTRICDIPOLE, UNGROUNDEDELECTRICDIPOLE, MAGNETICDIPOLE};
  245. /// Only three polarizations are supported. They may be summed to
  246. /// approximate others
  247. /// @param NOPOLARISATION is uninitialized, default value
  248. /// @param XPOLARISATION is a dipole oriented in the x direction
  249. /// @param YPOLARISATION is a dipole oriented in the y direction
  250. /// @param ZPOLARISATION is a dipole oriented in the z direction
  251. enum DipoleSourcePolarisation {NOPOLARISATION, XPOLARISATION,
  252. YPOLARISATION, ZPOLARISATION};
  253. /// The polarity may be either negative or positinve
  254. enum DipoleSourcePolarity {NEGATIVE, POSITIVE};
  255. /** The fields to make calculations on
  256. */
  257. enum FIELDCALCULATIONS {E, H, BOTH};
  258. /** Windowing function type
  259. */
  260. enum WINDOWTYPE { HAMMING, /*!< A hamming window */
  261. HANNING, /*!< A hanning window */
  262. RECTANGULAR /*!< Rectangular window */
  263. };
  264. }
  265. #endif // __Lemma_H